mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-06 21:44:08 -06:00
Thread-safe integration of ExtrusionPath::Collection
This commit is contained in:
parent
c030e38908
commit
1b285f3f46
12 changed files with 81 additions and 104 deletions
|
@ -42,12 +42,15 @@ sub cleanup {
|
|||
my $self = shift;
|
||||
|
||||
# split paths at angles that are too acute to be printed as they will cause blobs
|
||||
@{$self->paths} = map $_->split_at_acute_angles, @{$self->paths};
|
||||
my @paths = map $_->split_at_acute_angles, @$self;
|
||||
$self->clear;
|
||||
$self->append(@paths);
|
||||
}
|
||||
|
||||
sub detect_arcs {
|
||||
my $self = shift;
|
||||
@{$self->paths} = map $_->detect_arcs(@_), @{$self->paths};
|
||||
|
||||
return map $_->detect_arcs(@_), @$self;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -211,11 +211,7 @@ sub extrude_loop {
|
|||
$extrusion_path->intersect_expolygons($self->_layer_overhangs);
|
||||
|
||||
# reapply the nearest point search for starting point
|
||||
{
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new;
|
||||
$collection->append(@paths);
|
||||
@paths = $collection->chained_path($start_at, 1);
|
||||
}
|
||||
@paths = Slic3r::ExtrusionPath::Collection->new(@paths)->chained_path($start_at, 1);
|
||||
} else {
|
||||
push @paths, $extrusion_path;
|
||||
}
|
||||
|
|
|
@ -29,19 +29,19 @@ has 'slices' => (is => 'rw', default => sub { Slic3r::Surface::Collection->new }
|
|||
|
||||
# collection of polygons or polylines representing thin walls contained
|
||||
# in the original geometry
|
||||
has 'thin_walls' => (is => 'rw', default => sub { [] });
|
||||
has 'thin_walls' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
|
||||
|
||||
# collection of extrusion paths/loops filling gaps
|
||||
has 'thin_fills' => (is => 'rw', default => sub { [] });
|
||||
has 'thin_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
|
||||
|
||||
# collection of surfaces for infill generation
|
||||
has 'fill_surfaces' => (is => 'rw', default => sub { Slic3r::Surface::Collection->new });
|
||||
|
||||
# ordered collection of extrusion paths/loops to build all perimeters
|
||||
has 'perimeters' => (is => 'rw', default => sub { [] });
|
||||
has 'perimeters' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
|
||||
|
||||
# ordered collection of extrusion paths to fill surfaces
|
||||
has 'fills' => (is => 'rw', default => sub { [] });
|
||||
has 'fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
|
||||
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
|
@ -100,13 +100,11 @@ sub make_surfaces {
|
|||
1,
|
||||
);
|
||||
|
||||
$self->thin_walls([]);
|
||||
$self->thin_walls->clear;
|
||||
if (@$diff) {
|
||||
my $area_threshold = $self->perimeter_flow->scaled_spacing ** 2;
|
||||
@$diff = grep $_->area > ($area_threshold), @$diff;
|
||||
|
||||
@{$self->thin_walls} = map $_->medial_axis($self->perimeter_flow->scaled_width), @$diff;
|
||||
|
||||
$self->thin_walls->append(map $_->medial_axis($self->perimeter_flow->scaled_width), @$diff);
|
||||
Slic3r::debugf " %d thin walls detected\n", scalar(@{$self->thin_walls}) if @{$self->thin_walls};
|
||||
}
|
||||
}
|
||||
|
@ -156,9 +154,9 @@ sub make_perimeters {
|
|||
my $infill_spacing = $self->solid_infill_flow->scaled_spacing;
|
||||
my $gap_area_threshold = $self->perimeter_flow->scaled_width ** 2;
|
||||
|
||||
$self->perimeters([]);
|
||||
$self->perimeters->clear;
|
||||
$self->fill_surfaces->clear;
|
||||
$self->thin_fills([]);
|
||||
$self->thin_fills->clear;
|
||||
|
||||
my @contours = (); # array of Polygons with ccw orientation
|
||||
my @holes = (); # array of Polygons with cw orientation
|
||||
|
@ -278,7 +276,7 @@ sub make_perimeters {
|
|||
|| ($self->layer->id == 0 && $Slic3r::Config->brim_width > 0);
|
||||
|
||||
# append perimeters
|
||||
push @{ $self->perimeters }, @loops;
|
||||
$self->perimeters->append(@loops);
|
||||
|
||||
# add thin walls as perimeters
|
||||
push @{ $self->perimeters }, Slic3r::ExtrusionPath::Collection->new(
|
||||
|
@ -333,11 +331,11 @@ sub _fill_gaps {
|
|||
role => EXTR_ROLE_SOLIDFILL,
|
||||
flow_spacing => $flow->spacing,
|
||||
);
|
||||
push @{ $self->thin_fills }, map {
|
||||
$self->thin_fills->append(map {
|
||||
$_->isa('Slic3r::Polygon')
|
||||
? Slic3r::ExtrusionLoop->new(polygon => $_, %path_args)->split_at_first_point # we should keep these as loops
|
||||
: Slic3r::ExtrusionPath->new(polyline => $_, %path_args),
|
||||
} map $_->medial_axis($flow->scaled_width), @this_width;
|
||||
} map $_->medial_axis($flow->scaled_width), @this_width);
|
||||
|
||||
Slic3r::debugf " %d gaps filled with extrusion width = %s\n", scalar @this_width, $width
|
||||
if @{ $self->thin_fills };
|
||||
|
|
|
@ -395,33 +395,17 @@ sub export_gcode {
|
|||
thread_cb => sub {
|
||||
my $q = shift;
|
||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
||||
my $fills = {};
|
||||
while (defined (my $obj_layer = $q->dequeue)) {
|
||||
my ($obj_idx, $layer_id, $region_id) = @$obj_layer;
|
||||
my $object = $self->objects->[$obj_idx];
|
||||
$fills->{$obj_idx} ||= {};
|
||||
$fills->{$obj_idx}{$layer_id} ||= {};
|
||||
$fills->{$obj_idx}{$layer_id}{$region_id} = [
|
||||
$object->fill_maker->make_fill($object->layers->[$layer_id]->regions->[$region_id]),
|
||||
];
|
||||
}
|
||||
return $fills;
|
||||
},
|
||||
collect_cb => sub {
|
||||
my $fills = shift;
|
||||
foreach my $obj_idx (keys %$fills) {
|
||||
my $object = $self->objects->[$obj_idx];
|
||||
foreach my $layer_id (keys %{$fills->{$obj_idx}}) {
|
||||
my $layer = $object->layers->[$layer_id];
|
||||
foreach my $region_id (keys %{$fills->{$obj_idx}{$layer_id}}) {
|
||||
$layer->regions->[$region_id]->fills($fills->{$obj_idx}{$layer_id}{$region_id});
|
||||
}
|
||||
}
|
||||
my $layerm = $object->layers->[$layer_id]->regions->[$region_id];
|
||||
$layerm->fills->append( $object->fill_maker->make_fill($layerm) );
|
||||
}
|
||||
},
|
||||
collect_cb => sub {},
|
||||
no_threads_cb => sub {
|
||||
foreach my $layerm (map @{$_->regions}, map @{$_->layers}, @{$self->objects}) {
|
||||
$layerm->fills([ $layerm->layer->object->fill_maker->make_fill($layerm) ]);
|
||||
$layerm->fills->append($layerm->layer->object->fill_maker->make_fill($layerm));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -587,7 +571,7 @@ sub make_skirt {
|
|||
my @layer_points = (
|
||||
(map @$_, map @$_, map @{$_->slices}, @layers),
|
||||
(map @$_, map @{$_->thin_walls}, map @{$_->regions}, @layers),
|
||||
(map @{$_->polyline}, map @{$_->support_fills->paths}, grep $_->support_fills, @layers),
|
||||
(map @{$_->polyline}, map @{$_->support_fills}, grep $_->support_fills, @layers),
|
||||
);
|
||||
push @points, map move_points($_, @layer_points), @{$self->objects->[$obj_idx]->copies};
|
||||
}
|
||||
|
@ -647,7 +631,7 @@ sub make_brim {
|
|||
my @object_islands = (
|
||||
(map $_->contour, @{$layer0->slices}),
|
||||
(map { $_->isa('Slic3r::Polygon') ? $_ : $_->grow($grow_distance) } map @{$_->thin_walls}, @{$layer0->regions}),
|
||||
(map $_->polyline->grow($grow_distance), map @{$_->support_fills->paths}, grep $_->support_fills, $layer0),
|
||||
(map $_->polyline->grow($grow_distance), map @{$_->support_fills}, grep $_->support_fills, $layer0),
|
||||
);
|
||||
foreach my $copy (@{$self->objects->[$obj_idx]->copies}) {
|
||||
push @islands, map $_->clone->translate(@$copy), @object_islands;
|
||||
|
|
|
@ -315,31 +315,11 @@ sub make_perimeters {
|
|||
thread_cb => sub {
|
||||
my $q = shift;
|
||||
$Slic3r::Geometry::Clipper::clipper = Math::Clipper->new;
|
||||
my $result = {};
|
||||
while (defined (my $layer_id = $q->dequeue)) {
|
||||
my $layer = $self->layers->[$layer_id];
|
||||
$layer->make_perimeters;
|
||||
$result->{$layer_id} ||= {};
|
||||
foreach my $region_id (0 .. $#{$layer->regions}) {
|
||||
my $layerm = $layer->regions->[$region_id];
|
||||
$result->{$layer_id}{$region_id} = {
|
||||
perimeters => $layerm->perimeters,
|
||||
fill_surfaces => $layerm->fill_surfaces,
|
||||
thin_fills => $layerm->thin_fills,
|
||||
};
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
},
|
||||
collect_cb => sub {
|
||||
my $result = shift;
|
||||
foreach my $layer_id (keys %$result) {
|
||||
foreach my $region_id (keys %{$result->{$layer_id}}) {
|
||||
$self->layers->[$layer_id]->regions->[$region_id]->$_($result->{$layer_id}{$region_id}{$_})
|
||||
for qw(perimeters fill_surfaces thin_fills);
|
||||
}
|
||||
$self->layers->[$layer_id]->make_perimeters;
|
||||
}
|
||||
},
|
||||
collect_cb => sub {},
|
||||
no_threads_cb => sub {
|
||||
$_->make_perimeters for @{$self->layers};
|
||||
},
|
||||
|
@ -988,9 +968,6 @@ sub generate_support_material {
|
|||
};
|
||||
return @paths;
|
||||
};
|
||||
my %layer_paths = ();
|
||||
my %layer_contact_paths = ();
|
||||
my %layer_islands = ();
|
||||
my $process_layer = sub {
|
||||
my ($layer_id) = @_;
|
||||
my $layer = $self->layers->[$layer_id];
|
||||
|
@ -1026,6 +1003,9 @@ sub generate_support_material {
|
|||
}
|
||||
return ($paths, $contact_paths, $islands);
|
||||
};
|
||||
my %layer_paths = ();
|
||||
my %layer_contact_paths = ();
|
||||
my %layer_islands = ();
|
||||
Slic3r::parallelize(
|
||||
items => [ keys %layers ],
|
||||
thread_cb => sub {
|
||||
|
@ -1051,8 +1031,8 @@ sub generate_support_material {
|
|||
$layer->support_islands($layer_islands{$layer_id});
|
||||
$layer->support_fills(Slic3r::ExtrusionPath::Collection->new);
|
||||
$layer->support_contact_fills(Slic3r::ExtrusionPath::Collection->new);
|
||||
push @{$layer->support_fills->paths}, @{$layer_paths{$layer_id}};
|
||||
push @{$layer->support_contact_fills->paths}, @{$layer_contact_paths{$layer_id}};
|
||||
$layer->support_fills->append(@{$layer_paths{$layer_id}});
|
||||
$layer->support_contact_fills->append(@{$layer_contact_paths{$layer_id}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue