Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove consecutive duplicate points, loops with < 3 points, and empty…

… top layers
  • Loading branch information...
commit 3d7757f6e800877c411109c09085c9a0504de716 1 parent cd892fd
Mike Sheldrake authored
Showing with 11 additions and 1 deletion.
  1. +5 −0 lib/Slic3r/Print/Object.pm
  2. +6 −1 lib/Slic3r/TriangleMesh.pm
View
5 lib/Slic3r/Print/Object.pm
@@ -164,6 +164,11 @@ sub slice {
$self->layers->[$i]->id($i);
}
}
+
+ # remove empty layers from top
+ while (@{$self->layers} && !@{$self->layers->[-1]->slices} && !map @{$_->thin_walls}, @{$self->layers->[-1]->regions}) {
+ pop @{$self->layers};
+ }
warn "No layers were detected. You might want to repair your STL file and retry.\n"
if !@{$self->layers};
View
7 lib/Slic3r/TriangleMesh.pm
@@ -296,11 +296,16 @@ sub make_loops {
next CYCLE;
}
- push @points, $next_line->[I_B];
+ push @points, $next_line->[I_B] if !same_point($line->[I_B], $next_line->[I_B]);
$visited_lines{$next_line} = 1;
$line = $next_line;
} while ($first_facet_index != $line->[I_FACET_INDEX]);
+ if (@points <= 2) {
+ Slic3r::debugf " polygon reduced to %d points\n", scalar(@points);
+ next CYCLE;
+ }
+
push @polygons, Slic3r::Polygon->new(@points);
Slic3r::debugf " Discovered %s polygon of %d points\n",
($polygons[-1]->is_counter_clockwise ? 'ccw' : 'cw'), scalar(@points)

3 comments on commit 3d7757f

@mesheldrake
Collaborator

apex barely above slice plane

Slicing the apex of a half disk with a sharp edge, one point is barely above the slice plane. (illustrations not to scale)

six intersections will become six identical points

Six edges emanate from this point and make six intersections with the slice plane (two are on other side of the ridge) within a very small radius region. The floating point edge-plane intersection calculations don't have enough precision, so all these points end up with the same x and y coordinates, though topologically they are still distinct.

At the point of reducing the topology to loop geometry, this commit screens out consecutive duplicates. In the case illustrated, this results in a points list with zero points. The empty list is kept from being returned as an empty Polygon.

Also, in this case, the top layer will end up empty, so it should be removed.

A similar case where only three edges emanate from the apex and two of the plane intersections come out identical would result in the points list having just two points after removing one of the duplicates. So that case and the illustrated case are both screened out by testing points <= 2.

@alexrj
Owner

Mike, that's excellent - does it fix any known issue pending in GitHub?
If so, I'd like to reference it when merging.

@mesheldrake
Collaborator

There were issues mentioning Slic3r "hanging" at different stages, but the ones I looked at when I had this problem weren't caused by the same thing. I came across this as soon as I upgraded to the then-latest Clipper, so I may have been the first to stumble upon it.

Please sign in to comment.
Something went wrong with that request. Please try again.