Esempio n. 1
0
        public static global::Topologic.Face ToTopologic(this global::Rhino.Geometry.Surface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            SumSurface sumSurface = surface as SumSurface;

            if (sumSurface != null)
            {
                return(sumSurface.ToTopologic());
            }

            RevSurface revSurface = surface as RevSurface;

            if (revSurface != null)
            {
                return(revSurface.ToTopologic());
            }

            PlaneSurface planeSurface = surface as PlaneSurface;

            if (planeSurface != null)
            {
                return(planeSurface.ToTopologic());
            }

            Extrusion ghExtrusion = surface as Extrusion;

            if (ghExtrusion != null)
            {
                return(ghExtrusion.ToTopologic());
            }

            global::Rhino.Geometry.NurbsSurface ghNurbsSurface = surface as global::Rhino.Geometry.NurbsSurface;
            if (ghNurbsSurface != null)
            {
                return(ghNurbsSurface.ToTopologic());
            }


            return(null);
        }
Esempio n. 2
0
        public static Brep ToRhino(global::Topologic.Face face, double tolerance = Core.Tolerance.Distance)
        {
            global::Rhino.Geometry.Surface ghSurface = ToRhino(face);

            double width = 0.0, height = 0.0;
            bool   canGetSurfaceSize = ghSurface.GetSurfaceSize(out width, out height);

            if (!canGetSurfaceSize)
            {
                throw new Exception("Fails to get the surface size.");
            }
            double maxSize          = Math.Max(width, height);
            double maxSizeAndMargin = maxSize + 2;

            ghSurface = ghSurface.Extend(IsoStatus.North, maxSizeAndMargin, true);
            ghSurface = ghSurface.Extend(IsoStatus.South, maxSizeAndMargin, true);
            ghSurface = ghSurface.Extend(IsoStatus.West, maxSizeAndMargin, true);
            ghSurface = ghSurface.Extend(IsoStatus.East, maxSizeAndMargin, true);

            List <GeometryBase> ghGeometryBases = new List <GeometryBase>();

            IList <Edge> outerEdges = face.ExternalBoundary.Edges;
            List <Curve> ghCurves   = new List <Curve>();

            foreach (Edge edge in outerEdges)
            {
                Curve ghCurve3D = ToRhino(edge);
                ghGeometryBases.Add(ghCurve3D);
                ghCurves.Add(ghCurve3D);
            }

            Brep ghBrep2 = Brep.CreatePatch(
                ghGeometryBases,
                ghSurface,
                20,
                20,
                true,
                true,
                tolerance,
                100.0,
                1,
                new Boolean[] { true, true, true, true },
                tolerance);

            BrepFace ghSurfaceAsBrepFace = ghSurface as BrepFace;

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

            IList <Wire> internalBoundaries = face.InternalBoundaries;

            if (internalBoundaries.Count == 0)
            {
                return(ghBrep2);
            }

            BrepFace ghBrepFace = ghBrep2.Faces[0];

            List <Curve> ghInternalCurves = new List <Curve>();

            foreach (Wire internalBoundary in internalBoundaries)
            {
                List <Curve> ghCurvesFromWireAsObjects = ToRhino(internalBoundary);
                foreach (Curve ghCurveFromWireAsObject in ghCurvesFromWireAsObjects)
                {
                    Curve ghCurveFromWire = ghCurveFromWireAsObject as Curve;
                    if (ghCurveFromWire != null)
                    {
                        Curve[] ghPulledCurveFromWire = ghCurveFromWire.PullToBrepFace(ghBrepFace, tolerance);
                        ghInternalCurves.AddRange(ghPulledCurveFromWire);
                    }
                }
            }

            Brep ghBrep3 = ghBrepFace.Split(ghInternalCurves, tolerance);

            return(ghBrep3.Faces.ExtractFace(0));
        }
Esempio n. 3
0
        public static global::Topologic.Face ToTopologic(this BrepFace brepFace)
        {
            global::Rhino.Geometry.Surface ghSurface = brepFace?.UnderlyingSurface();
            if (ghSurface == null)
            {
                return(null);
            }

            global::Topologic.Face untrimmedFace = ghSurface.ToTopologic();

            BrepLoop     ghOuterLoop = brepFace.OuterLoop;
            Wire         outerWire   = null;
            BrepLoopList ghLoops     = brepFace.Loops;
            List <Wire>  innerWires  = new List <Wire>();

            foreach (BrepLoop ghLoop in ghLoops)
            {
                BrepTrimList ghTrims       = ghLoop.Trims;
                List <Edge>  trimmingEdges = new List <Edge>();
                foreach (BrepTrim ghTrim in ghTrims)
                {
                    BrepEdge ghEdge = ghTrim.Edge;
                    if (ghEdge == null)
                    {
                        continue;
                        //throw new Exception("An invalid Rhino edge is encountered.");
                    }

                    Topology topology = ghEdge.DuplicateCurve().ToTopologic();
                    if (topology == null)
                    {
                        continue;
                    }

                    // Edge or Wire?
                    Edge trimmingEdge = topology as Edge;
                    if (trimmingEdge != null)
                    {
                        trimmingEdges.Add(trimmingEdge);
                    }

                    Wire partialTrimmingWire = topology as Wire;
                    if (partialTrimmingWire != null)
                    {
                        IList <Edge> partialTrimmingEdges = partialTrimmingWire.Edges;
                        trimmingEdges.AddRange(partialTrimmingEdges);
                    }
                }

                Wire trimmingWire = Wire.ByEdges(trimmingEdges);
                if (ghLoop == ghOuterLoop)
                {
                    outerWire = trimmingWire;
                }
                else
                {
                    innerWires.Add(trimmingWire);
                }
            }

            global::Topologic.Face outerTrimmedFace = global::Topologic.Utilities.FaceUtility.TrimByWire(untrimmedFace, outerWire, true);
            global::Topologic.Face finalFace        = outerTrimmedFace.AddInternalBoundaries(innerWires);

            return(finalFace);
        }