public static Face3D Transform(this Transform transform, Face3D face3D, bool convertUnits = true) { if (transform == null || face3D == null) return null; if (transform.IsIdentity) return new Face3D(face3D); Spatial.Plane plane = Transform(transform, face3D.GetPlane()); if (plane == null) return null; Planar.IClosed2D externalEdge2D = plane.Convert(Transform(transform, face3D.GetExternalEdge3D(), convertUnits)); if (externalEdge2D == null) return null; List<Planar.IClosed2D> internalEdges2D = null; List<IClosedPlanar3D> internalEdges3D = face3D.GetInternalEdge3Ds(); if(internalEdges3D != null) { internalEdges2D = new List<Planar.IClosed2D>(); foreach (IClosedPlanar3D internalEdge3D in internalEdges3D) { Planar.IClosed2D internalEdge2D = plane.Convert(Transform(transform, internalEdge3D, convertUnits)); if (internalEdge2D == null) continue; internalEdges2D.Add(internalEdge2D); } } return Face3D.Create(plane, externalEdge2D, internalEdges2D, EdgeOrientationMethod.Undefined); }
public static List <Face3D> Face3Ds(this Autodesk.Revit.DB.FilledRegion filledRegion, double tolerance = Core.Tolerance.Distance) { if (filledRegion == null) { return(null); } IList <CurveLoop> curveLoops = filledRegion.GetBoundaries(); if (curveLoops == null) { return(null); } View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View; if (view == null) { return(null); } Vector3D normal = view.ViewDirection.ToSAM_Vector3D(false); if (normal == null) { return(null); } Spatial.Plane plane = view.Plane(); List <Planar.Polygon2D> polygon2Ds = new List <Planar.Polygon2D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D(view.ViewDirection, tolerance); if (polygon3D == null) { continue; } polygon2Ds.Add(plane.Convert(polygon3D)); } List <Planar.Face2D> face2Ds = Planar.Create.Face2Ds(polygon2Ds, tolerance); if (face2Ds == null) { return(null); } return(face2Ds.ConvertAll(x => plane.Convert(x))); }
public static IClosedPlanar3D Profile(this MEPCurve mEPCurve) { Spatial.Plane plane = mEPCurve?.Plane(); if (plane == null) { return(null); } switch (mEPCurve.ConnectorProfileType()) { case Autodesk.Revit.DB.ConnectorProfileType.Rectangular: double width = Units.Convert.ToSI(mEPCurve.Width, Units.UnitType.Feet); double height = Units.Convert.ToSI(mEPCurve.Height, Units.UnitType.Feet); Planar.Point2D origin = new Planar.Point2D(-width / 2, -height / 2); Planar.Vector2D heightDirection = plane.Convert(plane.AxisY); return(new Rectangle3D(plane, new Planar.Rectangle2D(origin, width, height, heightDirection))); case Autodesk.Revit.DB.ConnectorProfileType.Round: double diameter = Units.Convert.ToSI(mEPCurve.Diameter, Units.UnitType.Feet); double radius = diameter / 2; return(new Circle3D(plane, radius)); case Autodesk.Revit.DB.ConnectorProfileType.Oval: throw new System.NotImplementedException(); } return(null); }
public static List <Segment3D> Segment3Ds(this IClosedPlanar3D closedPlanar3D, double tolerance_Distance = Core.Tolerance.Distance, double tolerance_Angle = Core.Tolerance.Angle) { if (closedPlanar3D == null) { return(null); } if (!(closedPlanar3D is ICurvable3D)) { return(null); } List <ICurve3D> curve3Ds = Spatial.Query.Explode(((ICurvable3D)closedPlanar3D).GetCurves()); if (curve3Ds == null) { return(null); } List <Segment3D> segment3Ds = curve3Ds.ConvertAll(x => x as Segment3D); if (segment3Ds.Contains(null)) { return(null); } Spatial.Plane plane = closedPlanar3D.GetPlane(); if (plane == null) { return(null); } List <Planar.Segment2D> segment2Ds = segment3Ds.ConvertAll(x => plane.Convert(x)); segment2Ds.RemoveAll(x => x.GetLength() <= tolerance_Distance); Planar.Query.SimplifyBySAM_Angle(segment2Ds, tolerance_Distance, tolerance_Angle); segment2Ds = Planar.Query.Snap(segment2Ds); return(segment2Ds.ConvertAll(x => plane.Convert(x))); }
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 }