mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 07:34:03 -06:00
Use poly2tri for triangulation. This fixes some cases where polyPartition couldn't triangulate successfully. Reported as issue #9 in polyPartition repository. Tested with MotorHalter_0.stl cut at 1.2
This commit is contained in:
parent
60f640f100
commit
edeb0a90dd
19 changed files with 2830 additions and 6 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "Line.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include "polypartition.h"
|
||||
#include "poly2tri/poly2tri.h"
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
@ -312,6 +313,50 @@ ExPolygon::triangulate_pp(Polygons* polygons) const
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::triangulate_p2t(Polygons* polygons) const
|
||||
{
|
||||
ExPolygons expp;
|
||||
simplify_polygons(*this, expp, true);
|
||||
|
||||
for (ExPolygons::const_iterator ex = expp.begin(); ex != expp.end(); ++ex) {
|
||||
p2t::CDT* cdt;
|
||||
|
||||
// TODO: prevent duplicate points
|
||||
|
||||
// contour
|
||||
{
|
||||
std::vector<p2t::Point*> points;
|
||||
for (Points::const_iterator point = ex->contour.points.begin(); point != ex->contour.points.end(); ++point) {
|
||||
points.push_back(new p2t::Point(point->x, point->y));
|
||||
}
|
||||
cdt = new p2t::CDT(points);
|
||||
}
|
||||
|
||||
// holes
|
||||
for (Polygons::const_iterator hole = ex->holes.begin(); hole != ex->holes.end(); ++hole) {
|
||||
std::vector<p2t::Point*> points;
|
||||
for (Points::const_iterator point = hole->points.begin(); point != hole->points.end(); ++point) {
|
||||
points.push_back(new p2t::Point(point->x, point->y));
|
||||
}
|
||||
cdt->AddHole(points);
|
||||
}
|
||||
|
||||
// perform triangulation
|
||||
cdt->Triangulate();
|
||||
std::vector<p2t::Triangle*> triangles = cdt->GetTriangles();
|
||||
|
||||
for (std::vector<p2t::Triangle*>::const_iterator triangle = triangles.begin(); triangle != triangles.end(); ++triangle) {
|
||||
Polygon p;
|
||||
for (int i = 0; i <= 2; ++i) {
|
||||
p2t::Point* point = (*triangle)->GetPoint(i);
|
||||
p.points.push_back(Point(point->x, point->y));
|
||||
}
|
||||
polygons->push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
|
||||
REGISTER_CLASS(ExPolygon, "ExPolygon");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue