Пример #1
0
        /***************************************************/

        public static RHG.Curve IToRhino(this BHG.ICurve curve)
        {
            if (curve == null)
            {
                return(null);
            }

            object result = Convert.ToRhino(curve as dynamic);

            if (result is RHG.Curve)
            {
                return((RHG.Curve)result);
            }
            else if (result is RHG.Arc)
            {
                return(new RHG.ArcCurve((RHG.Arc)result));
            }
            else if (result is RHG.Circle)
            {
                return(new RHG.ArcCurve((RHG.Circle)result));
            }
            else if (result is RHG.Ellipse)
            {
                return(((RHG.Ellipse)result).ToNurbsCurve());
            }
            else if (result is RHG.Line)
            {
                return(new RHG.LineCurve((RHG.Line)result));
            }


            return(Convert.ToRhino(curve as dynamic));
        }
Пример #2
0
        /***************************************************/

        private static BHG.PlanarSurface ToBHoMPlanarSurface(this RHG.BrepFace face)
        {
            RHG.Surface rhSurf = face.UnderlyingSurface();
            if (rhSurf == null)
            {
                return(null);
            }

            BHG.PlanarSurface bhs = rhSurf.FromRhino() as BHG.PlanarSurface;
            List <BHG.ICurve> internalBoundaries = new List <BHG.ICurve>();

            BHG.ICurve externalBoundary = bhs.ExternalBoundary;
            foreach (RHG.BrepLoop loop in face.Loops)
            {
                if (loop.LoopType == RHG.BrepLoopType.Inner)
                {
                    internalBoundaries.Add(new BHG.PolyCurve {
                        Curves = loop.Trims.Select(x => rhSurf.Pushup(x, BHG.Tolerance.Distance).FromRhino()).ToList()
                    });
                }
                else if (loop.LoopType == RHG.BrepLoopType.Outer)
                {
                    externalBoundary = new BHG.PolyCurve {
                        Curves = loop.Trims.Select(x => rhSurf.Pushup(x, BHG.Tolerance.Distance).FromRhino()).ToList()
                    }
                }
                ;
            }

            return(BH.Engine.Geometry.Create.PlanarSurface(externalBoundary, internalBoundaries));
        }
Пример #3
0
        /***************************************************/

        public static BHG.ISurface FromRhino(this RHG.NurbsSurface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            if (surface.IsPlanar(BH.oM.Geometry.Tolerance.Distance))
            {
                BHG.ICurve externalEdge = RHG.Curve.JoinCurves(surface.ToBrep().DuplicateNakedEdgeCurves(true, false)).FirstOrDefault().FromRhino();
                return(new BHG.PlanarSurface(externalEdge, new List <BHG.ICurve>()));
            }

            BHG.NurbsSurface bhs = new BHG.NurbsSurface
                                   (
                surface.Points.Select(x => x.Location.FromRhino()).ToList(),
                surface.Points.Select(x => x.Weight).ToList(),
                surface.KnotsU.ToList(),
                surface.KnotsV.ToList(),
                surface.Degree(0),
                surface.Degree(1),
                new List <BHG.SurfaceTrim>(),
                new List <BHG.SurfaceTrim>()
                                   );

            return(bhs);
        }
Пример #4
0
        public static TBD.buildingElement BuildingElement(TBD.Building tbdBuilding, BH.oM.Geometry.ICurve panelCurve)
        {
            /*int index = 0;
             * TBD.buildingElement tbdBuildingElement = null;
             * while ((tbdBuildingElement = tbdBuilding.GetBuildingElement(index)) != null)
             * {
             *  if (tbdBuildingElement. == panelCurve)
             *      return tbdBuildingElement;
             *  index++;
             * }*/

            return(null);
        }
Пример #5
0
        /***************************************************/

        public static BHG.ISurface FromRhino(this RHG.Surface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            if (surface.IsPlanar(BHG.Tolerance.Distance))
            {
                BHG.ICurve externalEdge = RHG.Curve.JoinCurves(surface.ToBrep().DuplicateNakedEdgeCurves(true, false)).FirstOrDefault().FromRhino();
                return(new BHG.PlanarSurface(externalEdge, new List <oM.Geometry.ICurve>()));
            }

            return(surface.ToNurbsSurface().FromRhino());
        }
Пример #6
0
        /***************************************************/

        public static BHG.IGeometry FromRhino(this RHG.Brep brep)
        {
            if (brep == null)
            {
                return(null);
            }

            string log;

            if (!brep.IsValidWithLog(out log))
            {
                Reflection.Compute.RecordError("Conversion failed, Rhino Brep is invalid: " + log);
                return(null);
            }

            if (brep.Faces.Count == 0)
            {
                return(null);
            }

            if (brep.IsSolid)
            {
                return(brep.ToBHoMSolid());
            }

            if (brep.IsPlanarSurface())
            {
                BHG.ICurve        externalEdge  = RHG.Curve.JoinCurves(brep.DuplicateNakedEdgeCurves(true, false)).FirstOrDefault().FromRhino();
                List <BHG.ICurve> internalEdges = RHG.Curve.JoinCurves(brep.DuplicateNakedEdgeCurves(false, true)).Select(c => c.FromRhino()).ToList();
                return(new BHG.PlanarSurface(externalEdge, internalEdges));
            }

            if (brep.Faces.Count == 1)
            {
                return(brep.Faces[0].FromRhino());
            }

            // Default case - return open Polysurface
            return(new BHG.PolySurface()
            {
                Surfaces = brep.Faces.Select(s => s.FromRhino()).ToList()
            });
        }
Пример #7
0
        public static global::Topologic.Topology TopologyByGeometry(BH.oM.Geometry.IGeometry geometry, double tolerance = 0.0001)
        {
            BH.oM.Geometry.Point bhomPoint = geometry as BH.oM.Geometry.Point;
            if (bhomPoint != null)
            {
                return(Create.VertexByPoint(bhomPoint));
            }

            // Handle polyline and polycurve first
            BH.oM.Geometry.Polyline bhomPolyline = geometry as BH.oM.Geometry.Polyline;
            if (bhomPolyline != null)
            {
                if (bhomPolyline.ControlPoints.Count < 2)
                {
                    throw new Exception("An invalid polyline with fewer than 2 control points is given.");
                }
                else if (bhomPolyline.ControlPoints.Count == 2)
                {
                    BH.oM.Geometry.Line bhomLine = BH.Engine.Geometry.Create.Line(bhomPolyline.ControlPoints[0], bhomPolyline.ControlPoints[1]);
                    return(Create.EdgeByLine(bhomLine));
                }
                else
                {
                    return(Create.WireByPolyLine(bhomPolyline));
                }
            }

            BH.oM.Geometry.PolyCurve bhomPolyCurve = geometry as BH.oM.Geometry.PolyCurve;
            if (bhomPolyCurve != null)
            {
                if (bhomPolyCurve.Curves.Count == 0)
                {
                    throw new Exception("An invalid polycurve with no curve is given.");
                }
                else if (bhomPolyCurve.Curves.Count == 1)
                {
                    BH.oM.Geometry.ICurve bhomACurve = bhomPolyCurve.Curves[0];
                    return(Create.EdgeByCurve(bhomACurve));
                }
                else
                {
                    return(Create.WireByPolyCurve(bhomPolyCurve));
                }
            }

            // Then curve
            BH.oM.Geometry.ICurve bhomCurve = geometry as BH.oM.Geometry.ICurve;
            if (bhomCurve != null)
            {
                return(Create.EdgeByCurve(bhomCurve));
            }

            // Do polysurface first.
            BH.oM.Geometry.PolySurface bhomPolySurface = geometry as BH.oM.Geometry.PolySurface;
            if (bhomPolySurface != null)
            {
                return(Create.ShellByPolySurface(bhomPolySurface, tolerance));
            }

            // Then surface
            BH.oM.Geometry.ISurface bhomSurface = geometry as BH.oM.Geometry.ISurface;
            if (bhomSurface != null)
            {
                return(Create.FaceBySurface(bhomSurface));
            }

            BH.oM.Geometry.ISolid bhomSolid = geometry as BH.oM.Geometry.ISolid;
            if (bhomSolid != null)
            {
                return(Create.CellBySolid(bhomSolid, tolerance));
            }

            BH.oM.Geometry.BoundingBox bhomBoundingBox = geometry as BH.oM.Geometry.BoundingBox;
            if (bhomBoundingBox != null)
            {
                return(Create.CellByBoundingBox(bhomBoundingBox));
            }

            BH.oM.Geometry.CompositeGeometry bhomCompositeGeometry = geometry as BH.oM.Geometry.CompositeGeometry;
            if (bhomCompositeGeometry != null)
            {
                return(Create.ClusterByCompositeGeometry(bhomCompositeGeometry, tolerance));
            }

            BH.oM.Geometry.Mesh bhomMesh = geometry as BH.oM.Geometry.Mesh;
            if (bhomMesh != null)
            {
                return(Create.TopologyByMesh(bhomMesh));
            }

            throw new NotImplementedException("This BHoM geometry is not yet supported.");
        }
Пример #8
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private static void AddBrepTrim(this RHG.Brep brep, RHG.BrepFace face, BHG.SurfaceTrim trim, RHG.BrepLoopType loopType)
        {
            RHG.BrepLoop      loop       = brep.Loops.Add(loopType, face);
            List <BHG.ICurve> subParts3d = trim.Curve3d.ISubParts().ToList();
            List <BHG.ICurve> subParts2d = trim.Curve2d.ISubParts().ToList();

            double rhinoTolerance = Query.DocumentTolerance();

            for (int i = 0; i < subParts3d.Count; i++)
            {
                BHG.ICurve bhc = subParts3d[i];
                RHG.Curve  rhc = bhc.IToRhino();

                int startId = brep.AddVertex(rhc.PointAtStart);
                int endId   = brep.AddVertex(rhc.PointAtEnd);

                RHG.BrepTrim rhTrim;
                RHG.Curve    rhc2d = subParts2d[i].IToRhino();
                rhc2d.ChangeDimension(2);
                int crv2d = brep.Curves2D.Add(rhc2d);
                if (rhc.IsValid)
                {
                    bool         rev3d = true;
                    RHG.BrepEdge edge  = null;
                    foreach (RHG.BrepEdge e in brep.Edges)
                    {
                        if (e.StartVertex.VertexIndex == endId && e.EndVertex.VertexIndex == startId && rhc.IsSameEdge(e))
                        {
                            edge = e;
                            break;
                        }
                    }

                    if (edge == null)
                    {
                        int crv = brep.Curves3D.Add(rhc);
                        edge  = brep.Edges.Add(startId, endId, crv, rhinoTolerance);
                        rev3d = false;
                    }

                    rhTrim = brep.Trims.Add(edge, rev3d, loop, crv2d);
                }
                else
                {
                    rhTrim = brep.Trims.AddSingularTrim(brep.Vertices[startId], loop, RHG.IsoStatus.None, crv2d);
                }

                rhTrim.SetTolerances(rhinoTolerance, rhinoTolerance);

                //TODO: In Rhino 6 this could be replaced with Surface.IsIsoParametric(Curve)
                RHG.Point3d start = rhc2d.PointAtStart;
                RHG.Point3d end   = rhc2d.PointAtEnd;

                if (rhc2d.IsLinear())
                {
                    if (Math.Abs(start.X - end.X) <= rhinoTolerance)
                    {
                        RHG.Interval domainU = brep.Surfaces[face.SurfaceIndex].Domain(0);
                        if (Math.Abs(start.X - domainU.Min) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.West;
                        }
                        else if (Math.Abs(start.X - domainU.Max) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.East;
                        }
                        else
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.X;
                        }
                    }
                    else if (Math.Abs(start.Y - end.Y) <= rhinoTolerance)
                    {
                        RHG.Interval domainV = brep.Surfaces[face.SurfaceIndex].Domain(1);
                        if (Math.Abs(start.Y - domainV.Min) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.South;
                        }
                        else if (Math.Abs(start.Y - domainV.Max) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.North;
                        }
                        else
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.Y;
                        }
                    }
                }
            }
        }
Пример #9
0
 public static Point3dVector ToOSM(this BHG.ICurve crv)
 {
     return(ToOSM(crv as dynamic));
 }
Пример #10
0
        /***************************************************/
        /**** Public Methods  - Interfaces              ****/
        /***************************************************/

        public static bool IIsEqual(this BHG.ICurve bhCurve, RHG.Curve rhCurve, double tolerance = BHG.Tolerance.Distance)
        {
            return(IsEqual(bhCurve as dynamic, rhCurve as dynamic, tolerance));
        }
Пример #11
0
        /***************************************************/

        public static BuildingElement BuildingElementOpening(this BuildingElement be, BHG.ICurve bound)
        {
            return(be.BuildingElementOpening(new List <BHG.ICurve> {
                bound
            }));
        }
Пример #12
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static Opening Opening(BHG.ICurve curve)
        {
            return(Opening(curve as dynamic));
        }