//------------------------------------------------------------------------------ public static Paths OpenPathsFromPolyTree(PolyTree polytree) { Paths result = new Paths(); result.Capacity = polytree.ChildCount; for (int i = 0; i < polytree.ChildCount; i++) if (polytree.Childs[i].IsOpen) result.Add(polytree.Childs[i].Contour); return result; }
//------------------------------------------------------------------------------ public static Paths ClosedPathsFromPolyTree(PolyTree polytree) { Paths result = new Paths(); result.Capacity = polytree.Total; AddPolyNodeToPaths(polytree, NodeType.ntClosed, result); return result; }
public static Paths PolyTreeToPaths(PolyTree polytree) { Paths result = new Paths(); result.Capacity = polytree.Total; AddPolyNodeToPaths(polytree, NodeType.ntAny, result); return result; }
//------------------------------------------------------------------------------ public static void PolyTreeToPolygons(PolyTree polytree, Polygons polys) { polys.Clear(); polys.Capacity = polytree.Total; AddPolyNodeToPaths(polytree, NodeType.ntAny, polys); }
//------------------------------------------------------------------------------ private void BuildResult2(PolyTree polytree) { polytree.Clear(); //add each output polygon/contour to polytree ... polytree.m_AllPolys.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; int cnt = PointCount(outRec.Pts); if ((outRec.IsOpen && cnt < 2) || (!outRec.IsOpen && cnt < 3)) continue; FixHoleLinkage(outRec); PolyNode pn = new PolyNode(); polytree.m_AllPolys.Add(pn); outRec.PolyNode = pn; pn.m_polygon.Capacity = cnt; OutPt op = outRec.Pts.Prev; for (int j = 0; j < cnt; j++) { pn.m_polygon.Add(op.Pt); op = op.Prev; } } //fixup PolyNode links etc ... polytree.m_Childs.Capacity = m_PolyOuts.Count; for (int i = 0; i < m_PolyOuts.Count; i++) { OutRec outRec = m_PolyOuts[i]; if (outRec.PolyNode == null) continue; else if (outRec.IsOpen) { outRec.PolyNode.IsOpen = true; polytree.AddChild(outRec.PolyNode); } else if (outRec.FirstLeft != null) outRec.FirstLeft.PolyNode.AddChild(outRec.PolyNode); else polytree.AddChild(outRec.PolyNode); } }
//------------------------------------------------------------------------------ public bool Execute(ClipType clipType, PolyTree polytree) { return Execute(clipType, polytree, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd); }
//------------------------------------------------------------------------------ public bool Execute(ClipType clipType, PolyTree polytree, PolyFillType subjFillType, PolyFillType clipFillType) { if (m_ExecuteLocked) return false; m_ExecuteLocked = true; m_SubjFillType = subjFillType; m_ClipFillType = clipFillType; m_ClipType = clipType; m_UsingPolyTree = true; bool succeeded = ExecuteInternal(); //build the return polygons ... if (succeeded) BuildResult2(polytree); m_ExecuteLocked = false; return succeeded; }