Ported LayerRegion::make_slices() to XS

This commit is contained in:
Alessandro Ranellucci 2014-11-09 16:23:50 +01:00
parent 948793e570
commit b69caff93c
11 changed files with 78 additions and 77 deletions

View file

@ -28,17 +28,6 @@ sub print { return $_[0]->layer->print; }
sub config { return $_[0]->region->config; }
sub merge_slices {
my ($self) = @_;
my $expolygons = union_ex([ map $_->p, @{$self->slices} ]);
$self->slices->clear;
$self->slices->append(Slic3r::Surface->new(
expolygon => $_,
surface_type => S_TYPE_INTERNAL,
)) for @$expolygons;
}
sub make_perimeters {
my ($self, $slices, $fill_surfaces) = @_;
@ -177,7 +166,7 @@ sub make_perimeters {
);
foreach my $gap_size (@gap_sizes) {
my @gap_fill = $self->_fill_gaps(@$gap_size, \@gaps);
$self->thin_fills->append(@gap_fill);
$self->thin_fills->append($_) for @gap_fill;
# Make sure we don't infill narrow parts that are already gap-filled
# (we only consider this surface's gaps to reduce the diff() complexity).
@ -199,14 +188,13 @@ sub make_perimeters {
# and then we offset back and forth by half the infill spacing to only consider the
# non-collapsing regions
my $min_perimeter_infill_spacing = $ispacing * (1 - &Slic3r::INSET_OVERLAP_TOLERANCE);
$fill_surfaces->append(
map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL), # use a bogus surface type
@{offset2_ex(
[ map @{$_->simplify_p(&Slic3r::SCALED_RESOLUTION)}, @{union_ex(\@last)} ],
-($pspacing/2 + $min_perimeter_infill_spacing/2),
+$min_perimeter_infill_spacing/2,
)}
);
$fill_surfaces->append($_)
for map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL), # use a bogus surface type
@{offset2_ex(
[ map @{$_->simplify_p(&Slic3r::SCALED_RESOLUTION)}, @{union_ex(\@last)} ],
-($pspacing/2 + $min_perimeter_infill_spacing/2),
+$min_perimeter_infill_spacing/2,
)};
}
@ -245,9 +233,8 @@ sub make_perimeters {
# lower layer, so we take lower slices and offset them by half the nozzle diameter used
# in the current layer
my $nozzle_diameter = $self->layer->print->config->get_at('nozzle_diameter', $self->region->config->perimeter_extruder-1);
$lower_slices->append(
@{offset_ex([ map @$_, @{$self->layer->lower_layer->slices} ], scale +$nozzle_diameter/2)},
);
$lower_slices->append($_)
for @{offset_ex([ map @$_, @{$self->layer->lower_layer->slices} ], scale +$nozzle_diameter/2)};
}
my $lower_slices_p = $lower_slices->polygons;
@ -418,7 +405,7 @@ sub make_perimeters {
|| ($self->layer->id == 0 && $self->print->config->brim_width > 0);
# append perimeters
$self->perimeters->append(@loops);
$self->perimeters->append($_) for @loops;
}
sub _fill_gaps {
@ -508,8 +495,8 @@ sub process_external_surfaces {
$angle = $bridge_detector->detect_angle;
if (defined $angle && $self->object->config->support_material) {
$self->bridged->append(@{ $bridge_detector->coverage($angle) });
$self->unsupported_bridge_edges->append(@{ $bridge_detector->unsupported_edges });
$self->bridged->append($_) for @{ $bridge_detector->coverage($angle) };
$self->unsupported_bridge_edges->append($_) for @{ $bridge_detector->unsupported_edges };
}
}
@ -553,7 +540,7 @@ sub process_external_surfaces {
)};
}
$self->fill_surfaces->clear;
$self->fill_surfaces->append(@new_surfaces);
$self->fill_surfaces->append($_) for @new_surfaces;
}
1;

View file

@ -315,11 +315,10 @@ sub slice {
);
$layerm->slices->clear;
$layerm->slices->append(
map Slic3r::Surface->new
$layerm->slices->append($_)
for map Slic3r::Surface->new
(expolygon => $_, surface_type => S_TYPE_INTERNAL),
@$diff
);
@$diff;
}
# update layer slices after repairing the single regions
@ -542,14 +541,14 @@ sub infill {
my ($i, $region_id) = @$obj_layer;
my $layerm = $self->get_layer($i)->regions->[$region_id];
$layerm->fills->clear;
$layerm->fills->append( $self->fill_maker->make_fill($layerm) );
$layerm->fills->append($_) for $self->fill_maker->make_fill($layerm);
}
},
collect_cb => sub {},
no_threads_cb => sub {
foreach my $layerm (map @{$_->regions}, @{$self->layers}) {
$layerm->fills->clear;
$layerm->fills->append($self->fill_maker->make_fill($layerm));
$layerm->fills->append($_) for $self->fill_maker->make_fill($layerm);
}
},
);
@ -705,7 +704,7 @@ sub detect_surfaces_type {
# save surfaces to layer
$layerm->slices->clear;
$layerm->slices->append(@bottom, @top, @internal);
$layerm->slices->append($_) for (@bottom, @top, @internal);
Slic3r::debugf " layer %d has %d bottom, %d top and %d internal surfaces\n",
$layerm->id, scalar(@bottom), scalar(@top), scalar(@internal) if $Slic3r::debug;
@ -725,9 +724,9 @@ sub detect_surfaces_type {
[ $surface->p ],
$fill_boundaries,
);
$layerm->fill_surfaces->append(map Slic3r::Surface->new
(expolygon => $_, surface_type => $surface->surface_type),
@$intersection);
$layerm->fill_surfaces->append($_)
for map Slic3r::Surface->new(expolygon => $_, surface_type => $surface->surface_type),
@$intersection;
}
}
}
@ -772,7 +771,7 @@ sub clip_fill_surfaces {
)};
$layerm->fill_surfaces->clear;
$layerm->fill_surfaces->append(@new, @other);
$layerm->fill_surfaces->append($_) for (@new, @other);
}
# get this layer's overhangs defined as the full slice minus the internal infill
@ -827,7 +826,7 @@ sub bridge_over_infill {
1,
)};
$layerm->fill_surfaces->clear;
$layerm->fill_surfaces->append(@new_surfaces);
$layerm->fill_surfaces->append($_) for @new_surfaces;
}
# exclude infill from the layers below if needed
@ -855,7 +854,7 @@ sub bridge_over_infill {
)};
}
$lower_layerm->fill_surfaces->clear;
$lower_layerm->fill_surfaces->append(@new_surfaces);
$lower_layerm->fill_surfaces->append($_) for @new_surfaces;
}
$excess -= $self->get_layer($i)->height;
@ -1001,12 +1000,14 @@ sub discover_horizontal_shells {
# assign resulting internal surfaces to layer
$neighbor_fill_surfaces->clear;
$neighbor_fill_surfaces->append(map Slic3r::Surface->new
(expolygon => $_, surface_type => S_TYPE_INTERNAL), @$internal);
$neighbor_fill_surfaces->append($_)
for map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNAL),
@$internal;
# assign new internal-solid surfaces to layer
$neighbor_fill_surfaces->append(map Slic3r::Surface->new
(expolygon => $_, surface_type => S_TYPE_INTERNALSOLID), @$internal_solid);
$neighbor_fill_surfaces->append($_)
for map Slic3r::Surface->new(expolygon => $_, surface_type => S_TYPE_INTERNALSOLID),
@$internal_solid;
# assign top and bottom surfaces to layer
foreach my $s (@{Slic3r::Surface::Collection->new(grep { ($_->surface_type == S_TYPE_TOP) || $_->is_bottom } @neighbor_fill_surfaces)->group}) {
@ -1015,7 +1016,8 @@ sub discover_horizontal_shells {
[ map @$_, @$internal_solid, @$internal ],
1,
);
$neighbor_fill_surfaces->append(map $s->[0]->clone(expolygon => $_), @$solid_surfaces);
$neighbor_fill_surfaces->append($_)
for map $s->[0]->clone(expolygon => $_), @$solid_surfaces;
}
}
}
@ -1129,7 +1131,7 @@ sub combine_infill {
}
$layerm->fill_surfaces->clear;
$layerm->fill_surfaces->append(@new_this_type, @other_types);
$layerm->fill_surfaces->append($_) for (@new_this_type, @other_types);
}
}
}