Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static Spatial.Plane Transform(this Transform transform, Spatial.Plane plane, bool convertUnits = true)
        {
            if (transform == null || plane == null)
                return null;

            if (transform.IsIdentity)
                return new Spatial.Plane(plane);

            return new Spatial.Plane(Transform(transform, plane.Origin, convertUnits), Transform(transform, plane.Normal, convertUnits));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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)));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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)));
        }
Esempio n. 8
0
        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]));
        }
Esempio n. 9
0
        public static FilledRegion ToSAM(this Autodesk.Revit.DB.FilledRegion filledRegion, ConvertSettings convertSettings)
        {
            if (filledRegion == null || !filledRegion.IsValidObject)
            {
                return(null);
            }

            FilledRegion result = convertSettings?.GetObject <FilledRegion>(filledRegion.Id);

            if (result != null)
            {
                return(result);
            }

            Document document = filledRegion.Document;

            if (document == null)
            {
                return(result);
            }

            Autodesk.Revit.DB.FilledRegionType filledRegionType_Revit = document.GetElement(filledRegion.GetTypeId()) as Autodesk.Revit.DB.FilledRegionType;
            if (filledRegionType_Revit == null)
            {
                return(null);
            }

            View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View;

            if (view == null)
            {
                return(null);
            }

            Spatial.Plane plane = view.Plane();
            if (plane == null)
            {
                return(null);
            }

            List <Face3D> face3Ds = filledRegion.Face3Ds();

            if (face3Ds == null)
            {
                return(null);
            }

            FilledRegionType     filledRegionType = filledRegionType_Revit.ToSAM(convertSettings);
            List <Planar.Face2D> face2Ds          = face3Ds.ConvertAll(x => Spatial.Query.Convert(plane, x));
            IntegerId            integerId        = Query.IntegerId(view);

            result = new FilledRegion(filledRegionType, integerId, face2Ds);

            if (result != null)
            {
                result.UpdateParameterSets(filledRegion, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(filledRegion.Id, result);
            }

            return(result);
        }
Esempio n. 10
0
        private static List <Face3D> Profiles_FromLocation(this Wall wall, double tolerance_Angle = Core.Tolerance.Angle, double tolerance_Distance = Core.Tolerance.Distance)
        {
            BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null);

            if (boundingBoxXYZ == null)
            {
                return(null);
            }

            LocationCurve locationCurve = wall.Location as LocationCurve;

            if (locationCurve == null)
            {
                return(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
                }
            };

            Vector3D direction = Vector3D.WorldZ;

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS);
#else
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, UnitTypeId.Meters);
#endif

            Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), direction);

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS);
#else
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, UnitTypeId.Meters);
#endif
            Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), direction);

            double height = max - min;

            Document document = wall.Document;

            //List<Face3D> face3Ds_Cutting = new List<Face3D>();

            //Dictionary<ElementId, List<Face3D>> dictionary = GeneratingElementIdDictionary(wall);
            //foreach (KeyValuePair<ElementId, List<Face3D>> keyValuePair in dictionary)
            //{
            //    if (keyValuePair.Value == null || keyValuePair.Value.Count == 0)
            //    {
            //        continue;
            //    }

            //    HostObject hostObject_Cutting = document.GetElement(keyValuePair.Key) as HostObject;
            //    if (hostObject_Cutting == null)
            //    {
            //        continue;
            //    }

            //    if (hostObject_Cutting is Floor || hostObject_Cutting is RoofBase)
            //    {
            //        List<Face3D> face3Ds_Temp = hostObject_Cutting.Profiles();
            //        if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
            //        {
            //            face3Ds_Cutting.AddRange(face3Ds_Temp);
            //        }
            //    }
            //}

            List <Face3D> result = new List <Face3D>();
            foreach (ICurve3D curve3D in curves)
            {
                if (curve3D == null)
                {
                    continue;
                }

                ICurve3D maxCurve = Spatial.Query.Project(plane_max, curve3D);
                ICurve3D minCurve = Spatial.Query.Project(plane_min, curve3D);

                Point3D point3D_1 = minCurve.GetEnd();
                Point3D point3D_2 = maxCurve.GetStart();
                Point3D point3D_3 = maxCurve.GetEnd();
                Point3D point3D_4 = minCurve.GetStart();
                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>()
                {
                    point3D_4, point3D_3, point3D_2, point3D_1
                };
                if (wall.Flipped)
                {
                    point3Ds.Reverse();
                }

                Face3D face3D = new Face3D(new Polygon3D(point3Ds, tolerance_Distance));
                result.Add(face3D);

                //Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance_Distance);
                //if (plane == null)
                //{
                //    continue;
                //}

                //Vector3D vector3D = new Vector3D(point3D_4, point3D_3);

                //Segment2D segment2D = plane.Convert(new Segment3D(point3D_4, point3D_1));

                //List<Segment2D> segment2Ds_Intersection = new List<Segment2D>();
                //foreach (Face3D face3D_Cutting in face3Ds_Cutting)
                //{
                //    PlanarIntersectionResult planarIntersectionResult = Spatial.Create.PlanarIntersectionResult(plane, face3D_Cutting, tolerance_Angle, tolerance_Distance);
                //    if (planarIntersectionResult == null || !planarIntersectionResult.Intersecting)
                //    {
                //        continue;
                //    }

                //    List<Segment2D> segment2Ds_Intersection_Temp = planarIntersectionResult.GetGeometry2Ds<Segment2D>();
                //    if (segment2Ds_Intersection_Temp != null && segment2Ds_Intersection_Temp.Count > 0)
                //    {
                //        segment2Ds_Intersection.AddRange(segment2Ds_Intersection_Temp);
                //    }
                //}

                //List<Face2D> face2Ds = Profiles_From2D(segment2D, plane.Convert(vector3D), segment2Ds_Intersection, tolerance_Distance);
                //if (face2Ds != null && face2Ds.Count > 0)
                //{
                //    result.AddRange(face2Ds.ConvertAll(x => plane.Convert(x)));
                //}
            }

            if (result != null && result.Count > 0)
            {
                return(result);
            }

            return(result);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        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
        }
Esempio n. 13
0
        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);
        }