public static List <Polygon3D> ToSAM_Polygon3Ds(this PlanarFace planarFace, double tolerance = Core.Tolerance.Distance) { if (planarFace == null) { return(null); } XYZ normal = planarFace.FaceNormal; if (normal == null) { return(null); } IEnumerable <CurveLoop> curveLoops = planarFace.GetEdgesAsCurveLoops(); if (curveLoops == null || curveLoops.Count() == 0) { return(null); } List <Polygon3D> result = new List <Polygon3D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = ToSAM_Polygon3D(curveLoop, normal, tolerance); if (!Spatial.Query.IsValid(polygon3D)) { continue; } List <Polygon3D> polygon3Ds_Intersection = Spatial.Query.SelfIntersectionPolygon3Ds(polygon3D, tolerance); if (polygon3Ds_Intersection != null) { result.AddRange(polygon3Ds_Intersection); } else { result.Add(polygon3D); } } if (result != null && result.Count > 1) { Spatial.Plane plane = result[0].GetPlane(); for (int i = 1; i < result.Count; i++) { result[i] = plane.Project(result[i]); } } return(result); }
private static List <Face3D> Profiles_RoofBase(this RoofBase roofBase) { List <Face3D> face3Ds = TopProfiles(roofBase); IEnumerable <ElementId> elementIds = roofBase.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Windows)); if (elementIds == null || elementIds.Count() == 0) { return(face3Ds); } foreach (ElementId elementId in elementIds) { Element element = roofBase.Document.GetElement(elementId); if (element == null) { continue; } BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null); Point3D point3D = ((boundingBoxXYZ.Max + boundingBoxXYZ.Min) / 2).ToSAM(); foreach (Face3D face3D in face3Ds) { List <Planar.IClosed2D> internalEdges = face3D.InternalEdge2Ds; if (internalEdges == null || internalEdges.Count == 0) { continue; } Spatial.Plane plane = face3D.GetPlane(); Point3D point3D_Projected = plane.Project(point3D); Planar.Point2D point2D = plane.Convert(point3D_Projected); for (int i = 0; i < internalEdges.Count; i++) { Planar.IClosed2D internalEdge = internalEdges[i]; if (internalEdge.Inside(point2D)) { face3D.RemoveInternalEdge(i); break; } } } } return(face3Ds); }
public static Polygon3D ToSAM_Polygon3D(this CurveLoop curveLoop, double tolerance = Core.Tolerance.Distance) { List <Segment3D> segment3Ds = new List <Segment3D>(); foreach (Curve curve in curveLoop) { ICurve3D curve3D = curve.ToSAM(); if (curve3D is ISegmentable3D) { List <Segment3D> segment3Ds_Temp = ((ISegmentable3D)curve3D).GetSegments(); if (segment3Ds_Temp == null || segment3Ds_Temp.Count == 0) { continue; } segment3Ds.AddRange(segment3Ds_Temp); } } if (segment3Ds.Count < 3) { return(null); } int count = segment3Ds.Count; segment3Ds.Add(segment3Ds[0]); bool oriented = true; for (int i = 0; i < count; i++) { if (segment3Ds[i][1].Distance(segment3Ds[i + 1][0]) > tolerance) { oriented = false; break; } } segment3Ds.RemoveAt(count); if (oriented) { return(Spatial.Create.Polygon3D(segment3Ds.ConvertAll(x => x.GetStart()))); } List <Point3D> point3Ds = new List <Point3D>(); foreach (Segment3D segment3D in segment3Ds) { Spatial.Modify.Add(point3Ds, segment3D.GetStart(), tolerance); Spatial.Modify.Add(point3Ds, segment3D.GetEnd(), tolerance); } if (point3Ds == null || point3Ds.Count < 3) { return(null); } Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance); if (plane == null) { return(null); } List <Planar.Segment2D> segment2Ds = segment3Ds.ConvertAll(x => plane.Convert(plane.Project(x))); if (segment2Ds == null || segment2Ds.Count < 3) { return(null); } List <Planar.Polygon2D> polygon2Ds = Planar.Create.Polygon2Ds(segment2Ds, tolerance); if (polygon2Ds == null || polygon2Ds.Count == 0) { //Extra case for situation where segment2Ds does not are not properly sorted List <Planar.Point2D> point2Ds = new List <Planar.Point2D>(); List <Planar.Segment2D> segment2Ds_Temp = new List <Planar.Segment2D>(segment2Ds); point2Ds.Add(segment2Ds_Temp[0][0]); point2Ds.Add(segment2Ds_Temp[0][1]); segment2Ds_Temp.RemoveAt(0); while (segment2Ds_Temp.Count > 0) { Point2D point2D = point2Ds.Last(); segment2Ds_Temp.SortByDistance(point2D); Segment2D segment2D = segment2Ds_Temp[0]; if (segment2D[0].Distance(point2D) > segment2D[1].Distance(point2D)) { point2Ds.Add(segment2D[0]); } else { point2Ds.Add(segment2D[1]); } segment2Ds_Temp.RemoveAt(0); } return(plane.Convert(new Polygon2D(point2Ds))); } if (polygon2Ds.Count > 1) { polygon2Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea())); } return(plane.Convert(polygon2Ds[0])); }
private static List <Face3D> Profiles_CurtainSystem(this CurtainSystem curtainSystem) { Document document = curtainSystem?.Document; if (document == null) { return(null); } CurtainGridSet curtainGridSet = curtainSystem?.CurtainGrids; if (curtainGridSet == null) { return(null); } List <Face3D> result = new List <Face3D>(); foreach (CurtainGrid curtainGrid in curtainGridSet) { IEnumerable <CurtainCell> curtainCells = curtainGrid.GetCurtainCells(); if (curtainCells == null || curtainCells.Count() == 0) { continue; } List <CurveArrArray> curveArrArrays = new List <CurveArrArray>(); foreach (CurtainCell curtainCell in curtainCells) { CurveArrArray curveArrArray = curtainCell?.PlanarizedCurveLoops; if (curveArrArray == null || curveArrArray.Size == 0) { continue; } curveArrArrays.Add(curveArrArray); } List <Segment3D> segment3Ds = new List <Segment3D>(); List <ISegmentable3D> segmentable3Ds_U = new List <ISegmentable3D>(); List <ISegmentable3D> segmentable3Ds_V = new List <ISegmentable3D>(); ICollection <ElementId> elementIds = null; elementIds = curtainGrid.GetUGridLineIds(); if (elementIds != null) { foreach (ElementId elementId in elementIds) { CurtainGridLine curtainGridLine = document.GetElement(elementId) as CurtainGridLine; if (curtainGridLine == null) { continue; } ISegmentable3D segmentable3D = curtainGridLine.FullCurve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } segmentable3Ds_U.Add(segmentable3D); segment3Ds.AddRange(segmentable3D.GetSegments()); } } elementIds = curtainGrid.GetVGridLineIds(); if (elementIds != null) { foreach (ElementId elementId in elementIds) { CurtainGridLine curtainGridLine = document.GetElement(elementId) as CurtainGridLine; if (curtainGridLine == null) { continue; } ISegmentable3D segmentable3D = curtainGridLine.FullCurve.ToSAM() as ISegmentable3D; if (segmentable3D == null) { continue; } segmentable3Ds_V.Add(segmentable3D); segment3Ds.AddRange(segmentable3D.GetSegments()); } } List <ISegmentable3D> segmentable3Ds = null; segmentable3Ds = ExtremeSegmentable3Ds(segmentable3Ds_U, segmentable3Ds_V); if (segmentable3Ds != null && segmentable3Ds.Count > 0) { foreach (ISegmentable3D segmentable3D in segmentable3Ds) { List <Segment3D> segment3Ds_Temp = segmentable3D?.GetSegments(); if (segment3Ds_Temp != null && segment3Ds_Temp.Count != 0) { segment3Ds.AddRange(segment3Ds_Temp); } } } segmentable3Ds = ExtremeSegmentable3Ds(segmentable3Ds_V, segmentable3Ds_U); if (segmentable3Ds != null && segmentable3Ds.Count > 0) { foreach (ISegmentable3D segmentable3D in segmentable3Ds) { List <Segment3D> segment3Ds_Temp = segmentable3D?.GetSegments(); if (segment3Ds_Temp != null && segment3Ds_Temp.Count != 0) { segment3Ds.AddRange(segment3Ds_Temp); } } } List <List <Face3D> > face3Ds = Enumerable.Repeat <List <Face3D> >(null, curveArrArrays.Count).ToList(); Parallel.For(0, curveArrArrays.Count, (int i) => { CurveArrArray curveArrArray = curveArrArrays[i]; if (curveArrArray == null || curveArrArray.Size == 0) { return; } face3Ds[i] = new List <Face3D>(); foreach (CurveArray curveArray in curveArrArray) { Polygon3D polygon3D = curveArray?.ToSAM_Polygon3D(); if (polygon3D == null && !polygon3D.IsValid()) { continue; } Spatial.Plane plane = polygon3D.GetPlane(); if (plane == null) { continue; } Polygon2D polygon2D = plane.Convert(polygon3D); if (polygon2D != null) { List <Segment2D> segment2Ds = segment3Ds.ConvertAll(x => plane.Convert(plane.Project(x))); segment2Ds.RemoveAll(x => x == null || x.GetLength() < Core.Tolerance.MacroDistance); segment2Ds = segment2Ds.Split(); List <Polygon2D> polygon2Ds = Planar.Create.Polygon2Ds(segment2Ds); if (polygon2Ds != null) { polygon2Ds = polygon2Ds.FindAll(x => x.Inside(polygon2D)); if (polygon2Ds != null && polygon2Ds.Count > 0) { polygon2Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea())); polygon3D = plane.Convert(polygon2Ds[0]); } } } face3Ds[i].Add(new Face3D(polygon3D)); } }); foreach (List <Face3D> face3Ds_Temp in face3Ds) { if (face3Ds_Temp != null && face3Ds_Temp.Count > 0) { result.AddRange(face3Ds_Temp); } } } return(result); }
private static List <Face3D> Profiles_RoofBase(this RoofBase roofBase) { #if Revit2017 return(null); #else List <Face3D> face3Ds = TopProfiles(roofBase); IEnumerable <ElementId> elementIds = roofBase.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Windows)); if (elementIds == null || elementIds.Count() == 0) { return(face3Ds); } List <Tuple <BoundingBox3D, Face3D> > tuples = face3Ds.ConvertAll(x => new Tuple <BoundingBox3D, Face3D>(x.GetBoundingBox(), x)); foreach (ElementId elementId in elementIds) { Element element = roofBase.Document.GetElement(elementId); if (element == null) { continue; } BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null); Point3D point3D = ((boundingBoxXYZ.Max + boundingBoxXYZ.Min) / 2).ToSAM(); List <Face3D> face3Ds_Temp = tuples.FindAll(x => x.Item1.InRange(point3D)).ConvertAll(x => x.Item2); foreach (Face3D face3D in face3Ds_Temp) { List <IClosed2D> internalEdges = face3D.InternalEdge2Ds; if (internalEdges == null || internalEdges.Count == 0) { continue; } Spatial.Plane plane = face3D.GetPlane(); Point3D point3D_Projected = plane.Project(point3D); Point2D point2D = plane.Convert(point3D_Projected); bool @break = false; for (int i = 0; i < internalEdges.Count; i++) { IClosed2D internalEdge = internalEdges[i]; if (internalEdge.Inside(point2D)) { face3D.RemoveInternalEdge(i); @break = true; break; } } if (@break) { break; } } } return(face3Ds); #endif }
public static List <Face3D> Profiles_Wall(this Wall wall) { if (wall == null) { return(null); } List <Face3D> result = Profiles_FromSketch(wall, !wall.Flipped); if (result != null && result.Count > 0) { return(result); } BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null); if (boundingBoxXYZ != null) { LocationCurve locationCurve = wall.Location as LocationCurve; if (locationCurve != null) { ICurve3D curve3D_Location = Convert.ToSAM(locationCurve); IEnumerable <ICurve3D> curves = null; if (curve3D_Location is ISegmentable3D) { curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>(); } else { curves = new List <ICurve3D>() { curve3D_Location } }; double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS); Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), new Vector3D(0, 0, 1)); double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS); Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), new Vector3D(0, 0, 1)); result = new List <Face3D>(); foreach (ICurve3D curve3D in curves) { if (curve3D == null) { continue; } ICurve3D maxCurve = plane_max.Project(curve3D); ICurve3D minCurve = plane_min.Project(curve3D); Point3D point3D_1 = minCurve.GetEnd(); Point3D point3D_2 = maxCurve.GetStart(); Point3D point3D_3 = maxCurve.GetEnd(); if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2)) { Point3D point_Temp = point3D_2; maxCurve.Reverse(); point3D_2 = point3D_3; point3D_3 = point_Temp; } List <Point3D> point3Ds = new List <Point3D>() { minCurve.GetStart(), point3D_3, point3D_2, point3D_1 }; if (wall.Flipped) { point3Ds.Reverse(); } result.Add(new Face3D(new Polygon3D(point3Ds))); } if (result != null && result.Count > 0) { return(result); } } } if (!ExporterIFCUtils.HasElevationProfile(wall)) { return(null); } IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall); if (curveLoops == null) { return(null); } result = new List <Face3D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D(); if (polygon3D != null) { result.Add(new Face3D(polygon3D)); } } return(result); }