Finished porting convex_hull() to XS and removed dependency on Math::ConvexHull::MonotoneChain
This commit is contained in:
parent
5309e3ef22
commit
de9d5403e8
5 changed files with 21 additions and 7 deletions
|
@ -176,7 +176,6 @@ sub validate {
|
||||||
{
|
{
|
||||||
my @points = map Slic3r::Point->new(@$_[X,Y]), map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes};
|
my @points = map Slic3r::Point->new(@$_[X,Y]), map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes};
|
||||||
my $convex_hull = convex_hull(\@points);
|
my $convex_hull = convex_hull(\@points);
|
||||||
use XXX; YYY ($convex_hull->pp);
|
|
||||||
($clearance) = @{offset([$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND)};
|
($clearance) = @{offset([$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND)};
|
||||||
}
|
}
|
||||||
for my $copy (@{$self->objects->[$obj_idx]->copies}) {
|
for my $copy (@{$self->objects->[$obj_idx]->copies}) {
|
||||||
|
@ -590,7 +589,7 @@ sub make_skirt {
|
||||||
return if @points < 3; # at least three points required for a convex hull
|
return if @points < 3; # at least three points required for a convex hull
|
||||||
|
|
||||||
# find out convex hull
|
# find out convex hull
|
||||||
my $convex_hull = convex_hull([ map $_->arrayref, @points ]);
|
my $convex_hull = convex_hull(\@points);
|
||||||
|
|
||||||
my @extruded_length = (); # for each extruder
|
my @extruded_length = (); # for each extruder
|
||||||
|
|
||||||
|
@ -606,7 +605,7 @@ sub make_skirt {
|
||||||
my $distance = scale $Slic3r::Config->skirt_distance;
|
my $distance = scale $Slic3r::Config->skirt_distance;
|
||||||
for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) {
|
for (my $i = $Slic3r::Config->skirts; $i > 0; $i--) {
|
||||||
$distance += scale $spacing;
|
$distance += scale $spacing;
|
||||||
my $loop = Slic3r::Geometry::Clipper::offset([$convex_hull], $distance, 0.0001, JT_ROUND)->[0];
|
my $loop = offset([$convex_hull], $distance, 0.0001, JT_ROUND)->[0];
|
||||||
$self->skirt->append(Slic3r::ExtrusionLoop->new(
|
$self->skirt->append(Slic3r::ExtrusionLoop->new(
|
||||||
polygon => Slic3r::Polygon->new(@$loop),
|
polygon => Slic3r::Polygon->new(@$loop),
|
||||||
role => EXTR_ROLE_SKIRT,
|
role => EXTR_ROLE_SKIRT,
|
||||||
|
@ -777,7 +776,7 @@ sub write_gcode {
|
||||||
my @islands = ();
|
my @islands = ();
|
||||||
foreach my $obj_idx (0 .. $#{$self->objects}) {
|
foreach my $obj_idx (0 .. $#{$self->objects}) {
|
||||||
my $convex_hull = convex_hull([
|
my $convex_hull = convex_hull([
|
||||||
map @{$_->contour->pp}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
|
map @{$_->contour}, map @{$_->slices}, @{$self->objects->[$obj_idx]->layers},
|
||||||
]);
|
]);
|
||||||
# discard layers only containing thin walls (offset would fail on an empty polygon)
|
# discard layers only containing thin walls (offset would fail on an empty polygon)
|
||||||
if (@$convex_hull) {
|
if (@$convex_hull) {
|
||||||
|
@ -797,13 +796,13 @@ sub write_gcode {
|
||||||
|
|
||||||
# calculate wiping points if needed
|
# calculate wiping points if needed
|
||||||
if ($self->config->ooze_prevention) {
|
if ($self->config->ooze_prevention) {
|
||||||
my $outer_skirt = Slic3r::Polygon->new(@{convex_hull([ map $_->pp, map @$_, @{$self->skirt} ])});
|
my $outer_skirt = convex_hull([ map @$_, @{$self->skirt} ]);
|
||||||
my @skirts = ();
|
my @skirts = ();
|
||||||
foreach my $extruder (@{$self->extruders}) {
|
foreach my $extruder (@{$self->extruders}) {
|
||||||
push @skirts, my $s = $outer_skirt->clone;
|
push @skirts, my $s = $outer_skirt->clone;
|
||||||
$s->translate(map scale($_), @{$extruder->extruder_offset});
|
$s->translate(map scale($_), @{$extruder->extruder_offset});
|
||||||
}
|
}
|
||||||
my $convex_hull = Slic3r::Polygon->new(@{convex_hull([ map @$_, map $_->pp, @skirts ])});
|
my $convex_hull = convex_hull([ map @$_, @skirts ]);
|
||||||
$gcodegen->standby_points([ map $_->clone, map @$_, map $_->subdivide(scale 10), @{offset([$convex_hull], scale 3)} ]);
|
$gcodegen->standby_points([ map $_->clone, map @$_, map $_->subdivide(scale 10), @{offset([$convex_hull], scale 3)} ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ src/PolylineCollection.hpp
|
||||||
src/ppport.h
|
src/ppport.h
|
||||||
src/Surface.cpp
|
src/Surface.cpp
|
||||||
src/Surface.hpp
|
src/Surface.hpp
|
||||||
|
src/SurfaceCollection.cpp
|
||||||
src/SurfaceCollection.hpp
|
src/SurfaceCollection.hpp
|
||||||
src/SVG.cpp
|
src/SVG.cpp
|
||||||
src/SVG.hpp
|
src/SVG.hpp
|
||||||
|
|
|
@ -9,6 +9,9 @@ sort_points (Point a, Point b)
|
||||||
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
|
return (a.x < b.x) || (a.x == b.x && a.y < b.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This implementation is based on Steffen Mueller's work for
|
||||||
|
the Perl module Math::ConvexHull::MonotoneChain (available
|
||||||
|
on CPAN under the GPL terms) */
|
||||||
void
|
void
|
||||||
convex_hull(Points points, Polygon &hull)
|
convex_hull(Points points, Polygon &hull)
|
||||||
{
|
{
|
||||||
|
@ -40,6 +43,10 @@ convex_hull(Points points, Polygon &hull)
|
||||||
hull.points.push_back(*(out_hull[i]));
|
hull.points.push_back(*(out_hull[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not sure why this happens randomly
|
||||||
|
if (hull.points.front().coincides_with(hull.points.back()))
|
||||||
|
hull.points.pop_back();
|
||||||
|
|
||||||
free(out_hull);
|
free(out_hull);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,13 @@ Point::rotate(double angle, Point* center)
|
||||||
bool
|
bool
|
||||||
Point::coincides_with(const Point* point) const
|
Point::coincides_with(const Point* point) const
|
||||||
{
|
{
|
||||||
return this->x == point->x && this->y == point->y;
|
return this->coincides_with(*point);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Point::coincides_with(const Point &point) const
|
||||||
|
{
|
||||||
|
return this->x == point.x && this->y == point.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Point
|
||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
void translate(double x, double y);
|
void translate(double x, double y);
|
||||||
void rotate(double angle, Point* center);
|
void rotate(double angle, Point* center);
|
||||||
|
bool coincides_with(const Point &point) const;
|
||||||
bool coincides_with(const Point* point) const;
|
bool coincides_with(const Point* point) const;
|
||||||
int nearest_point_index(const Points points) const;
|
int nearest_point_index(const Points points) const;
|
||||||
Point* nearest_point(Points points) const;
|
Point* nearest_point(Points points) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue