Skip to content

Commit

Permalink
Keep the full geometries in $layer->slices, including thin walls
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Feb 23, 2013
1 parent 5049627 commit 0634437
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions lib/Slic3r/Layer/Region.pm
Expand Up @@ -87,28 +87,18 @@ sub make_surfaces {
return if !@$loops;
$self->slices([ _merge_loops($loops) ]);

# the contours must be offsetted by half extrusion width inwards
# detect thin walls by offsetting slices by half extrusion inwards
{
my $distance = $self->perimeter_flow->scaled_width / 2;
my @surfaces = @{$self->slices};
@{$self->slices} = ();
foreach my $surface (@surfaces) {
push @{$self->slices}, map Slic3r::Surface->new
(expolygon => $_, surface_type => S_TYPE_INTERNAL),
@{union_ex([
Slic3r::Geometry::Clipper::offset(
[Slic3r::Geometry::Clipper::offset($surface->expolygon, -2*$distance)],
+$distance,
),
])};
}

# now detect thin walls by re-outgrowing offsetted surfaces and subtracting
# them from the original slices
my $outgrown = [ Slic3r::Geometry::Clipper::offset([ map $_->p, @{$self->slices} ], $distance) ];
my $width = $self->perimeter_flow->scaled_width;
my $outgrown = union_ex([
Slic3r::Geometry::Clipper::offset(
[Slic3r::Geometry::Clipper::offset([ map @$_, map $_->expolygon, @{$self->slices} ], -$width)],
+$width,
),
]);
my $diff = diff_ex(
[ map $_->p, @surfaces ],
$outgrown,
[ map $_->p, @{$self->slices} ],
[ map @$_, @$outgrown ],
1,
);

Expand Down Expand Up @@ -223,29 +213,32 @@ sub make_perimeters {

# generate perimeters inwards (loop 0 is the external one)
my $loop_number = $Slic3r::Config->perimeters + ($surface->additional_inner_perimeters || 0);
push @perimeters, [[@last_offsets]] if $loop_number > 0;
push @perimeters, [] if $loop_number > 0;

# do one more loop (<= instead of <) so that we can detect gaps even after the desired
# number of perimeters has been generated
for (my $loop = 1; $loop <= $loop_number; $loop++) {
for (my $loop = 0; $loop <= $loop_number; $loop++) {
my $spacing = $perimeter_spacing;
$spacing /= 2 if $loop == 0;

# offsetting a polygon can result in one or many offset polygons
my @new_offsets = ();
foreach my $expolygon (@last_offsets) {
my @offsets = @{union_ex([
Slic3r::Geometry::Clipper::offset(
[Slic3r::Geometry::Clipper::offset($expolygon, -1.5*$perimeter_spacing)],
+0.5*$perimeter_spacing,
[Slic3r::Geometry::Clipper::offset($expolygon, -1.5*$spacing)],
+0.5*$spacing,
),
])};
push @new_offsets, @offsets;

# where the above check collapses the expolygon, then there's no room for an inner loop
# and we can extract the gap for later processing
my $diff = diff_ex(
[ map @$_, $expolygon->offset_ex(-0.5*$perimeter_spacing) ],
[ map @$_, $expolygon->offset_ex(-0.5*$spacing) ],
# +2 on the offset here makes sure that Clipper float truncation
# won't shrink the clip polygon to be smaller than intended.
[ Slic3r::Geometry::Clipper::offset([map @$_, @offsets], +0.5*$perimeter_spacing + 2) ],
[ Slic3r::Geometry::Clipper::offset([map @$_, @offsets], +0.5*$spacing + 2) ],
);
push @gaps, grep $_->area >= $gap_area_threshold, @$diff;
}
Expand Down

0 comments on commit 0634437

Please sign in to comment.