/// <summary> /// Add the 2D projection of the given arc /// to the current element outline union /// </summary> static public bool AddToUnion( Polygons union, VertexLookup vl, Clipper c, Arc arc) { IList <XYZ> pts = arc.Tessellate(); int n = pts.Count; Polygons faces = new Polygons(1); Polygon face2d = new Polygon(n); IntPoint a = vl.GetOrAdd(pts[0]); face2d.Add(a); for (int i = 1; i < n; ++i) { IntPoint b = vl.GetOrAdd(pts[i]); if (b != a) { face2d.Add(b); a = b; } } faces.Add(face2d); return(c.AddPaths(faces, PolyType.ptSubject, true)); }
/// <summary> /// Return the union of the outermost room boundary /// loop projected onto the XY plane. /// </summary> static public bool AddToUnionRoom( Polygons union, List <LineSegment> curves, VertexLookup vl, Clipper c, IList <IList <BoundarySegment> > boundary) { int n = boundary.Count; Debug.Assert(0 < n, "expected at least one room boundary loop"); Polygons faces = new Polygons(n); Polygon face2d = new Polygon(boundary[0].Count); foreach (IList <BoundarySegment> loop in boundary) { // Outer curve loops are counter-clockwise face2d.Clear(); foreach (BoundarySegment s in loop) { IList <XYZ> pts = s.GetCurve().Tessellate(); IntPoint a = vl.GetOrAdd(pts[0]); face2d.Add(a); n = pts.Count; for (int i = 1; i < n; ++i) { IntPoint b = vl.GetOrAdd(pts[i]); if (b != a) { face2d.Add(b); a = b; } } faces.Add(face2d); } } return(c.AddPaths(faces, PolyType.ptSubject, true)); }
/// <summary> /// Add the 2D projection of the given mesh triangles /// to the current element outline union /// </summary> static public bool AddToUnion( Polygons union, VertexLookup vl, Clipper c, Mesh m) { int n = m.NumTriangles; Polygons triangles = new Polygons(n); Polygon triangle = new Polygon(3); for (int i = 0; i < n; ++i) { MeshTriangle mt = m.get_Triangle(i); triangle.Clear(); triangle.Add(vl.GetOrAdd(mt.get_Vertex(0))); triangle.Add(vl.GetOrAdd(mt.get_Vertex(1))); triangle.Add(vl.GetOrAdd(mt.get_Vertex(2))); triangles.Add(triangle); } return(c.AddPaths(triangles, PolyType.ptSubject, true)); }
/// <summary> /// Add the 2D projection of the given face /// to the current element outline union /// </summary> static public bool AddToUnion( Polygons union, VertexLookup vl, Clipper c, Face f) { IList <CurveLoop> loops = f.GetEdgesAsCurveLoops(); // ExporterIFCUtils class can also be used for // non-IFC purposes. The SortCurveLoops method // sorts curve loops (edge loops) so that the // outer loops come first. IList <IList <CurveLoop> > sortedLoops = ExporterIFCUtils.SortCurveLoops(loops); int n = loops.Count; Debug.Assert(0 < n, "expected at least one face loop"); Polygons faces = new Polygons(n); Polygon face2d = new Polygon(loops[0].NumberOfCurves()); //foreach( IList<CurveLoop> loops2 // in sortedLoops ) foreach (CurveLoop loop in loops) { // Outer curve loops are counter-clockwise if (loop.IsCounterclockwise(XYZ.BasisZ)) { face2d.Clear(); foreach (Curve curve in loop) { IList <XYZ> pts = curve.Tessellate(); IntPoint a = vl.GetOrAdd(pts[0]); face2d.Add(a); n = pts.Count; for (int i = 1; i < n; ++i) { IntPoint b = vl.GetOrAdd(pts[i]); if (b != a) { face2d.Add(b); a = b; } } } faces.Add(face2d); } } return(c.AddPaths(faces, PolyType.ptSubject, true)); }
/// <summary> /// Return the union of all outlines projected onto /// the XY plane from the geometry solids and meshes /// </summary> static public bool AddToUnion( Polygons union, List <LineSegment> curves, VertexLookup vl, Clipper c, GeometryElement geoElem) { foreach (GeometryObject obj in geoElem) { // Curve // Edge // Face // GeometryElement // GeometryInstance // Mesh // Point // PolyLine // Profile // Solid // Skip objects that contribute no 2D surface Curve curve = obj as Curve; if (null != curve) { Arc arc = curve as Arc; if (null != arc && arc.IsCyclic) { AddToUnion(union, vl, c, arc); } else if (curve.IsBound) { curves.Add(new LineSegment( vl.GetOrAdd(curve.GetEndPoint(0)), vl.GetOrAdd(curve.GetEndPoint(1)))); } continue; } Solid solid = obj as Solid; if (null != solid) { foreach (Face f in solid.Faces) { // Skip pretty common case: vertical planar face if (f is PlanarFace && Util.IsHorizontal(((PlanarFace)f).FaceNormal)) { continue; } AddToUnion(union, vl, c, f); } continue; } Mesh mesh = obj as Mesh; if (null != mesh) { AddToUnion(union, vl, c, mesh); continue; } GeometryInstance inst = obj as GeometryInstance; if (null != inst) { GeometryElement txGeoElem = inst.GetInstanceGeometry( Transform.Identity); // inst.Transform AddToUnion(union, curves, vl, c, txGeoElem); continue; } Debug.Assert(false, "expected only solid, mesh or instance"); } return(true); }