From 2f6d8132a66b142541ed9a6ab21c7ebf800de13c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Sun, 23 Jun 2013 16:30:24 +0200
Subject: [PATCH] Added PolyTreeToExPolygons function form Clipper
documentation and introduced support for Clipper 5.1.x
---
layerPart.h | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/layerPart.h b/layerPart.h
index 1be61f6..ea52eca 100644
--- a/layerPart.h
+++ b/layerPart.h
@@ -15,6 +15,44 @@
*/
+//////////////////////////////////////////////////////////////////////////////////////////
+//
+// old API compatibility
+// polytree to expolygons
+// http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Types/ExPolygons.htm
+
+struct ExPolygon
+{
+ ClipperLib::Polygon outer;
+ ClipperLib::Polygons holes;
+};
+typedef std::vector<ExPolygon> ExPolygons;
+
+void AddOuterPolyNodeToExPolygons(const ClipperLib::PolyNode * polynode, ExPolygons& expolygons)
+{
+ size_t cnt = expolygons.size();
+ expolygons.resize(cnt + 1);
+ expolygons[cnt].outer = polynode->Contour;
+ expolygons[cnt].holes.resize(polynode->ChildCount());
+ for (int i = 0; i < polynode->ChildCount(); ++i)
+ {
+ expolygons[cnt].holes[i] = polynode->Childs[i]->Contour;
+ //Add outer polygons contained by (nested within) holes ...
+ for (int j = 0; j < polynode->Childs[i]->ChildCount(); ++j)
+ AddOuterPolyNodeToExPolygons(polynode->Childs[i]->Childs[j], expolygons);
+ }
+}
+
+void PolyTreeToExPolygons(const ClipperLib::PolyTree * polytree, ExPolygons& expolygons)
+{
+ expolygons.clear();
+ for (int i = 0; i < polytree->ChildCount(); ++i)
+ AddOuterPolyNodeToExPolygons(polytree->Childs[i], expolygons);
+}
+
+//
+//////////////////////////////////////////////////////////////////////////////////////////
+
void createLayerWithParts(SliceLayer& storageLayer, SlicerLayer* layer, int unionAllType)
{
ClipperLib::Polygons polyList;
@@ -31,13 +69,16 @@ void createLayerWithParts(SliceLayer& storageLayer, SlicerLayer* layer, int unio
polyList.push_back(p);
}
- ClipperLib::ExPolygons resultPolys;
+ ExPolygons resultPolys;
+ ClipperLib::PolyTree resultPolyTree;
ClipperLib::Clipper clipper;
clipper.AddPolygons(polyList, ClipperLib::ptSubject);
if (unionAllType)
- clipper.Execute(ClipperLib::ctUnion, resultPolys, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
+ clipper.Execute(ClipperLib::ctUnion, resultPolyTree, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
else
- clipper.Execute(ClipperLib::ctUnion, resultPolys);
+ clipper.Execute(ClipperLib::ctUnion, resultPolyTree);
+
+ PolyTreeToExPolygons(&resultPolyTree, resultPolys);
for(unsigned int i=0; i<resultPolys.size(); i++)
{
--
1.8.1.6