Incomplete work for using Boost.Polygon to compute medial axis

This commit is contained in:
Alessandro Ranellucci 2014-01-09 17:26:39 +01:00
parent 11f065ca5e
commit bf91f3096a
1650 changed files with 307148 additions and 9 deletions

View file

@ -1,12 +1,28 @@
#include "ExPolygon.hpp"
#include "Polygon.hpp"
#include "Line.hpp"
#include "ClipperUtils.hpp"
#include "boost/polygon/voronoi.hpp"
using boost::polygon::voronoi_builder;
using boost::polygon::voronoi_diagram;
namespace Slic3r {
ExPolygon::operator Points() const
{
Points points;
Polygons pp = *this;
for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) {
for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point)
points.push_back(*point);
}
return points;
}
ExPolygon::operator Polygons() const
{
Polygons polygons(this->holes.size() + 1);
Polygons polygons;
polygons.push_back(this->contour);
for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) {
polygons.push_back(*it);
@ -119,6 +135,42 @@ ExPolygon::simplify(double tolerance, ExPolygons &expolygons) const
expolygons.insert(expolygons.end(), ep.begin(), ep.end());
}
void
ExPolygon::medial_axis(Polylines* polylines) const
{
// populate list of segments for the Voronoi diagram
Lines lines;
this->contour.lines(&lines);
for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole)
hole->lines(&lines);
// compute the Voronoi diagram
voronoi_diagram<double> vd;
construct_voronoi(lines.begin(), lines.end(), &vd);
// iterate through the diagram
int result = 0;
for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin(); it != vd.edges().end(); ++it) {
if (it->is_primary()) ++result;
Polyline p;
if (!it->is_finite()) {
clip_infinite_edge(*it, &p.points);
} else {
p.points.push_back(Point( it->vertex0()->x(), it->vertex0()->y() ));
p.points.push_back(Point( it->vertex1()->x(), it->vertex1()->y() ));
if (it->is_curved()) {
sample_curved_edge(*it, &p.points);
}
}
polylines->push_back(p);
}
printf("medial axis result = %d\n", result);
// clip segments to our expolygon area
intersection(*polylines, *this, *polylines);
}
#ifdef SLIC3RXS
SV*
ExPolygon::to_AV() {