mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 15:44:12 -06:00
Finished --cut implementation
This commit is contained in:
parent
fe1691c151
commit
4f5d9ca795
8 changed files with 2009 additions and 10 deletions
|
@ -3,6 +3,9 @@
|
|||
#include "Polygon.hpp"
|
||||
#include "Line.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include "polypartition.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
@ -188,6 +191,54 @@ ExPolygon::triangulate(Polygons* polygons) const
|
|||
polygon->triangulate_convex(polygons);
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::triangulate2(Polygons* polygons) const
|
||||
{
|
||||
// convert polygons
|
||||
std::list<TPPLPoly> input;
|
||||
|
||||
// contour
|
||||
{
|
||||
TPPLPoly p;
|
||||
p.Init(this->contour.points.size());
|
||||
for (Points::const_iterator point = this->contour.points.begin(); point != this->contour.points.end(); ++point) {
|
||||
p[ point-this->contour.points.begin() ].x = point->x;
|
||||
p[ point-this->contour.points.begin() ].y = point->y;
|
||||
}
|
||||
p.SetHole(false);
|
||||
input.push_back(p);
|
||||
}
|
||||
|
||||
// holes
|
||||
for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole) {
|
||||
TPPLPoly p;
|
||||
p.Init(hole->points.size());
|
||||
for (Points::const_iterator point = hole->points.begin(); point != hole->points.end(); ++point) {
|
||||
p[ point-hole->points.begin() ].x = point->x;
|
||||
p[ point-hole->points.begin() ].y = point->y;
|
||||
}
|
||||
p.SetHole(true);
|
||||
input.push_back(p);
|
||||
}
|
||||
|
||||
// perform triangulation
|
||||
std::list<TPPLPoly> output;
|
||||
int res = TPPLPartition().Triangulate_MONO(&input, &output);
|
||||
if (res != 1) CONFESS("Triangulation failed");
|
||||
|
||||
// convert output polygons
|
||||
for (std::list<TPPLPoly>::iterator poly = output.begin(); poly != output.end(); ++poly) {
|
||||
long num_points = poly->GetNumPoints();
|
||||
Polygon p;
|
||||
p.points.resize(num_points);
|
||||
for (long i = 0; i < num_points; ++i) {
|
||||
p.points[i].x = (*poly)[i].x;
|
||||
p.points[i].y = (*poly)[i].y;
|
||||
}
|
||||
polygons->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
SV*
|
||||
ExPolygon::to_AV() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue