Multithreaded thumbnail generation
This commit is contained in:
parent
e41b8c7435
commit
2e897ecf0d
2 changed files with 33 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
|||
package Slic3r::GUI::Dashboard;
|
||||
use strict;
|
||||
use warnings;
|
||||
my $have_threads = eval "use threads; 1";
|
||||
use threads::shared;
|
||||
use utf8;
|
||||
|
||||
use File::Basename qw(basename dirname);
|
||||
|
@ -9,9 +11,12 @@ use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 scale unscale);
|
|||
use Slic3r::Geometry::Clipper qw(JT_ROUND);
|
||||
use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxICON_QUESTION
|
||||
wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_PAINT EVT_MOUSE_EVENTS EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED);
|
||||
use Wx::Event qw(EVT_BUTTON EVT_PAINT EVT_MOUSE_EVENTS EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED
|
||||
EVT_COMMAND);
|
||||
use base 'Wx::Panel';
|
||||
|
||||
my $THUMBNAIL_DONE_EVENT : shared = Wx::NewEventType;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent) = @_;
|
||||
|
@ -65,6 +70,13 @@ sub new {
|
|||
$_->SetDropTarget(Slic3r::GUI::Dashboard::DropTarget->new($self))
|
||||
for $self, $self->{canvas}, $self->{list};
|
||||
|
||||
EVT_COMMAND($self, -1, $THUMBNAIL_DONE_EVENT, sub {
|
||||
my ($self, $event) = @_;
|
||||
my ($obj_idx, $thumbnail) = @{$event->GetData};
|
||||
$self->{thumbnails}[$obj_idx] = $thumbnail;
|
||||
$self->{canvas}->Refresh;
|
||||
});
|
||||
|
||||
# calculate scaling factor for preview
|
||||
{
|
||||
# supposing the preview canvas is square, calculate the scaling factor
|
||||
|
@ -379,6 +391,7 @@ sub make_thumbnail {
|
|||
my $self = shift;
|
||||
my ($obj_idx) = @_;
|
||||
|
||||
my $cb = sub {
|
||||
my $object = $self->{print}->objects->[$obj_idx];
|
||||
my @points = map [ @$_[X,Y] ], @{$object->mesh->vertices};
|
||||
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
|
||||
|
@ -386,7 +399,16 @@ sub make_thumbnail {
|
|||
@$_ = map $self->to_pixel($_), @$_;
|
||||
}
|
||||
$convex_hull->simplify(0.3);
|
||||
$self->{thumbnails}->[$obj_idx] = $convex_hull;
|
||||
$self->{thumbnails}->[$obj_idx] = $convex_hull; # ignored in multithread environment
|
||||
|
||||
$have_threads
|
||||
? Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $THUMBNAIL_DONE_EVENT, shared_clone([ $obj_idx, $convex_hull ])))
|
||||
: $self->{canvas}->Refresh;
|
||||
|
||||
threads->exit if $have_threads;
|
||||
};
|
||||
|
||||
$have_threads ? threads->create($cb) : $cb->();
|
||||
}
|
||||
|
||||
sub recenter {
|
||||
|
|
|
@ -19,6 +19,7 @@ my %cli_options = ();
|
|||
'help' => sub { usage() },
|
||||
|
||||
'debug' => \$Slic3r::debug,
|
||||
'gui' => \$opt{gui},
|
||||
'o|output=s' => \$opt{output},
|
||||
|
||||
'save=s' => \$opt{save},
|
||||
|
@ -71,6 +72,7 @@ if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
|
|||
Slic3r::GUI->new->MainLoop;
|
||||
exit;
|
||||
}
|
||||
die $@ if $@ && $opt{gui};
|
||||
|
||||
if (@ARGV) {
|
||||
while (my $input_file = shift @ARGV) {
|
||||
|
|
Loading…
Reference in a new issue