More unfinished work

This commit is contained in:
Alessandro Ranellucci 2013-11-22 02:16:10 +01:00
parent 518798beb3
commit df8d889481
16 changed files with 74 additions and 48 deletions

View File

@ -44,23 +44,6 @@ sub bounding_box {
return $self->contour->bounding_box;
}
sub simplify_as_polygons {
my $self = shift;
my ($tolerance) = @_;
# it would be nice to have a multilinestring_simplify method in B::G::U
return @{Slic3r::Geometry::Clipper::simplify_polygons(
[ map Boost::Geometry::Utils::linestring_simplify($_, $tolerance), @{$self->pp} ],
)};
}
sub simplify {
my $self = shift;
my ($tolerance) = @_;
return @{ Slic3r::Geometry::Clipper::union_ex([ $self->simplify_as_polygons($tolerance) ]) };
}
# this method only works for expolygons having only a contour or
# a contour and a hole, and not being thicker than the supplied
# width. it returns a polyline or a polygon
@ -205,6 +188,7 @@ sub _medial_axis_voronoi {
}
my @result = ();
my $simplify_tolerance = $width / 7;
foreach my $polyline (@polylines) {
next unless @$polyline >= 2;
@ -213,11 +197,11 @@ sub _medial_axis_voronoi {
if ($points[0]->coincides_with($points[-1])) {
next if @points == 2;
push @result, Slic3r::Polygon->new(@points[0..$#points-1]);
push @result, @{Slic3r::Polygon->new(@points[0..$#points-1])->simplify($simplify_tolerance)};
} else {
push @result, Slic3r::Polyline->new(@points);
$result[-1]->simplify($simplify_tolerance);
}
$result[-1]->simplify($width / 7);
}
return @result;

View File

@ -38,7 +38,7 @@ sub BUILD {
my $crossing_edges = $self->_crossing_edges;
# simplify islands
$_->simplify($self->_inner_margin) for @{$self->islands};
@{$self->islands} = map @{$_->simplify($self->_inner_margin)}, @{$self->islands};
# process individual islands
for my $i (0 .. $#{$self->islands}) {

View File

@ -217,7 +217,7 @@ sub make_perimeters {
# non-collapsing regions
$self->fill_surfaces->append(
@{offset2_ex(
[ map $_->simplify_as_polygons(&Slic3r::SCALED_RESOLUTION), @{union_ex(\@last)} ],
[ map @{$_->simplify_p(&Slic3r::SCALED_RESOLUTION)}, @{union_ex(\@last)} ],
-($pspacing/2 + $ispacing/2),
+$ispacing/2,
)}

View File

@ -83,21 +83,32 @@ ExPolygon::contains_point(const Point* point) const
}
Polygons
ExPolygon::simplify(double tolerance) const
ExPolygon::simplify_p(double tolerance) const
{
Polygons p;
this->contour.simplify(tolerance, p);
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it)
it->simplify(tolerance, p);
simplify_polygons(p, p);
return p;
Polygons pp(this->holes.size() + 1);
// contour
Polygon p = this->contour;
p.points = MultiPoint::_douglas_peucker(p.points, tolerance);
pp.push_back(p);
// holes
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
p = *it;
p.points = MultiPoint::_douglas_peucker(p.points, tolerance);
pp.push_back(p);
}
simplify_polygons(pp, pp);
return pp;
}
ExPolygons
ExPolygon::simplify(double tolerance) const
{
Polygons p = this->simplify(tolerance);
return union_(p);
Polygons pp = this->simplify_p(tolerance);
ExPolygons expp;
union_(pp, expp);
return expp;
}
void

View File

@ -6,6 +6,9 @@
namespace Slic3r {
class ExPolygon;
typedef std::vector<ExPolygon> ExPolygons;
class ExPolygon
{
public:
@ -19,7 +22,7 @@ class ExPolygon
bool is_valid() const;
bool contains_line(const Line* line) const;
bool contains_point(const Point* point) const;
Polygons simplify(double tolerance) const;
Polygons simplify_p(double tolerance) const;
ExPolygons simplify(double tolerance) const;
void simplify(double tolerance, ExPolygons &expolygons) const;
@ -33,8 +36,6 @@ class ExPolygon
#endif
};
typedef std::vector<ExPolygon> ExPolygons;
}
#endif

View File

@ -50,11 +50,11 @@ ExPolygonCollection::contains_point(const Point* point) const
void
ExPolygonCollection::simplify(double tolerance)
{
ExPolygons t;
ExPolygons expp;
for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) {
it->simplify_and_append_to(tolerance, t);
it->simplify(tolerance, expp);
}
this->expolygons = t;
this->expolygons = expp;
}
}

View File

@ -55,12 +55,6 @@ MultiPoint::is_valid() const
return this->points.size() >= 2;
}
void
MultiPoint::simplify(double tolerance)
{
this->points = MultiPoint::_douglas_peucker(this->points, tolerance);
}
Points
MultiPoint::_douglas_peucker(Points &points, double tolerance)
{

View File

@ -21,7 +21,7 @@ class MultiPoint
virtual Lines lines() const = 0;
double length() const;
bool is_valid() const;
void simplify(double tolerance);
static Points _douglas_peucker(Points &points, double tolerance);
#ifdef SLIC3RXS
void from_SV(SV* poly_sv);
@ -29,9 +29,6 @@ class MultiPoint
SV* to_AV();
SV* to_SV_pureperl() const;
#endif
private:
static Points _douglas_peucker(Points &points, double tolerance);
};
}

View File

@ -128,7 +128,21 @@ Polygon::contains_point(const Point* point) const
Polygons
Polygon::simplify(double tolerance) const
{
Polygon p = *this;
p.points = MultiPoint::_douglas_peucker(p.points, tolerance);
Polygons pp;
pp.push_back(p);
simplify_polygons(pp, pp);
return pp;
}
void
Polygon::simplify(double tolerance, Polygons &polygons) const
{
Polygons pp = this->simplify(tolerance);
polygons.reserve(polygons.size() + pp.size());
polygons.insert(polygons.end(), pp.begin(), pp.end());
}
#ifdef SLIC3RXS

View File

@ -9,6 +9,9 @@
namespace Slic3r {
class Polygon;
typedef std::vector<Polygon> Polygons;
class Polygon : public MultiPoint {
public:
Point* last_point() const;
@ -33,8 +36,6 @@ class Polygon : public MultiPoint {
#endif
};
typedef std::vector<Polygon> Polygons;
}
#endif

View File

@ -87,6 +87,12 @@ Polyline::equally_spaced_points(double distance) const
return pts;
}
void
Polyline::simplify(double tolerance)
{
this->points = MultiPoint::_douglas_peucker(this->points, tolerance);
}
#ifdef SLIC3RXS
SV*

View File

@ -17,6 +17,7 @@ class Polyline : public MultiPoint {
void clip_end(double distance);
void clip_start(double distance);
Points equally_spaced_points(double distance) const;
void simplify(double tolerance);
#ifdef SLIC3RXS
SV* to_SV_ref();

View File

@ -0,0 +1,13 @@
#include "SurfaceCollection.hpp"
namespace Slic3r {
void
simplify(double tolerance)
{
for (Surfaces::iterator it = this->surfaces.begin(); it != this->surfaces.end(); ++it) {
throw "Unimplemented";
}
}
}

View File

@ -9,6 +9,7 @@ class SurfaceCollection
{
public:
Surfaces surfaces;
void simplify(double tolerance);
};
}

View File

@ -23,6 +23,8 @@
bool is_valid();
bool contains_line(Line* line);
bool contains_point(Point* point);
ExPolygons simplify(double tolerance);
Polygons simplify_p(double tolerance);
%{
ExPolygon*

View File

@ -11,6 +11,7 @@
%code{% THIS->surfaces.clear(); %};
int count()
%code{% RETVAL = THIS->surfaces.size(); %};
void simplify(double tolerance);
%{
SurfaceCollection*