コード例 #1
0
ファイル: IsEqual.cs プロジェクト: BHoM/Rhinoceros_Toolkit
        /***************************************************/

        public static bool IsEqual(this BHG.PolyCurve bhCurve, RHG.PolyCurve rhCurve, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhCurve == null & rhCurve == null)
            {
                return(true);
            }

            bool equal = true;
            List <BHG.ICurve> bhCurves = bhCurve.Curves;

            rhCurve.RemoveNesting();
            RHG.Curve[] rhCurves = rhCurve.Explode();

            if (bhCurves.Count != rhCurves.Length)
            {
                return(false);
            }

            for (int i = 0; i < bhCurves.Count; i++)
            {
                equal &= bhCurves[i].IIsEqual(rhCurves[i], tolerance);
            }

            return(equal);
        }
コード例 #2
0
        /***************************************************/

        public static Opening Opening(BHG.PolyCurve pCurve)
        {
            return(new Opening
            {
                OpeningCurve = pCurve
            });
        }
コード例 #3
0
ファイル: FromRhino.cs プロジェクト: BHoM/Rhinoceros_Toolkit
        /***************************************************/

        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));
        }
コード例 #4
0
ファイル: FromRhino.cs プロジェクト: BHoM/Rhinoceros_Toolkit
        /***************************************************/

        public static BHG.SurfaceTrim FromRhino(this RHG.BrepLoop loop)
        {
            BHG.PolyCurve curve2d = new BHG.PolyCurve();
            BHG.PolyCurve curve3d = new BHG.PolyCurve();
            foreach (RHG.BrepTrim trim in loop.Trims)
            {
                curve2d.Curves.Add(trim.ToBHoMTrimCurve());
                RHG.Curve trim3d = loop.Face.Pushup(trim, BHG.Tolerance.Distance);
                curve3d.Curves.Add(trim3d.ToBHoMTrimCurve());
            }

            return(new BHG.SurfaceTrim(curve3d, curve2d));
        }
コード例 #5
0
        //public static Point ClosestPoint(this Curve curve, Point point)
        //{
        //    switch (curve.GeometryType)
        //    {
        //        case GeometryType.Arc:
        //        case GeometryType.Circle:
        //            break;
        //        case GeometryType.Line:
        //            XLine.ClosestPoint(curve as Line, point);
        //            break;
        //        case GeometryType.Polyline:
        //            XPolyline.ClosestPoint(curve as Polyline, point);
        //            break;
        //        case GeometryType.PolyCurve:
        //            XPolyCurve.ClosestPoint(curve as PolyCurve, point);
        //            break;
        //    }
        //    throw new NotImplementedException();
        //}

        //public static bool IsPlanar(this Curve curve)
        //{
        //    return PlaneUtils.PointsInSamePlane(curve.ControlPointVector, curve.Dimensions + 1);
        //}

        //public static bool IsClosed(this Curve curve)
        //{
        //    return ArrayUtils.Equal(curve.EndPoint, curve.StartPoint, 0.0001);
        //}

        //public static bool TryGetPlane(this Curve curve, out Plane plane)
        //{
        //    plane = Create.PlaneFromPointArray(curve.ControlPointVector, curve.Dimensions + 1);
        //    return plane != null;
        //}

        //public static void Transform(Curve curve, Transform t)
        //{
        //    curve.SetControlPoints(ArrayUtils.MultiplyMany(t, curve.ControlPointVector));
        //    curve.Update();
        //}

        //public static void Translate(Curve curve, Vector v)
        //{
        //    curve.SetControlPoints(ArrayUtils.Add(curve.ControlPointVector, v));
        //}

        //public static void Mirror(Curve curve, Plane p)
        //{
        //    curve.SetControlPoints(ArrayUtils.Add(ArrayUtils.Multiply(p.ProjectionVectors(curve.ControlPointVector), 2), curve.ControlPointVector));
        //    curve.Update();
        //}

        //public static void Project(Curve curve, Plane p)
        //{
        //    curve.SetControlPoints(ArrayUtils.Add(p.ProjectionVectors(curve.ControlPointVector), curve.ControlPointVector));
        //    curve.Update();
        //}

        //public static Curve Flip(this Curve curve)
        //{
        //    if (curve.GeometryType == BH.oM.Geometry.GeometryType.PolyCurve)
        //    {
        //        PolyCurve c = curve as PolyCurve;
        //        for (int i = 0; i < c.Curves.Count; i++)
        //        {
        //            c.Curves[i].Flip();
        //        }
        //        c.Curves.Reverse();
        //    }
        //    curve.SetControlPoints(CollectionUtils.Reverse<double>(curve.ControlPointVector, curve.Dimensions + 1));
        //    if (curve.IsNurbForm)
        //    {
        //        double max = curve.Knots.Max();
        //        curve.SetKnots(ArrayUtils.Sub(new double[] { max }, curve.Knots));
        //        curve.SetWeights(curve.Weights.Reverse().ToArray());
        //    }
        //    return curve;
        //}



        public static Curve Append(this Curve curve, Curve other)
        {
            curve.ChangeDegree(other.Degree);
            other.ChangeDegree(curve.Degree);

            List <double> knots   = new List <double>();
            List <double> pnts    = new List <double>();
            List <double> weights = new List <double>();

            knots.AddRange(CollectionUtils.SubArray <double>(curve.Knots, 0, curve.Knots.Length - 1));
            pnts.AddRange(curve.ControlPointVector);
            weights.AddRange(curve.Weights);

            for (int i = 0; i < other.Knots.Length; i++)
            {
                if (other.Knots[i] != 0)
                {
                    knots.Add(other.Knots[i] + curve.Knots[curve.Knots.Length - 1]);
                }
            }

            pnts.AddRange(CollectionUtils.SubArray <double>(other.ControlPointVector, curve.Dimensions + 1, other.ControlPointVector.Length - curve.Dimensions - 1));
            weights.AddRange(CollectionUtils.SubArray <double>(other.Weights, 1, other.Weights.Length - 1));

            if (curve.Degree == 1)
            {
                return(new Polyline(pnts.ToArray(), curve.Dimensions));
            }
            else
            {
                List <Curve> crvs = new List <Curve>();
                crvs.AddRange(curve.Explode());
                crvs.AddRange(other.Explode());

                PolyCurve result = new PolyCurve(crvs);
                result.SetControlPoints(pnts.ToArray());
                result.SetDegree(curve.Order);
                result.SetWeights(weights.ToArray());
                result.SetKnots(knots.ToArray());

                return(result);
            }
        }
コード例 #6
0
ファイル: ToRhino.cs プロジェクト: BHoM/Rhinoceros_Toolkit
        /***************************************************/

        public static RHG.PolyCurve ToRhino(this BHG.PolyCurve bPolyCurve)
        {
            if (bPolyCurve == null)
            {
                return(null);
            }

            IEnumerable <RHG.Curve> parts = bPolyCurve.Curves.Select(x => x.IToRhino());

            // Check if bPolycurve is made of disconnected segments
            if (RHG.Curve.JoinCurves(parts).Length > 1)
            {
                return(null);
            }

            RHG.PolyCurve rPolycurve = new RHG.PolyCurve();
            foreach (RHG.Curve curve in parts)
            {
                rPolycurve.Append(curve);
            }
            return(rPolycurve);
        }
コード例 #7
0
ファイル: Topology.cs プロジェクト: BHoM/Topologic_Toolkit
        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
        /***************************************************/

        public static void RenderMeshes(BHG.PolyCurve polycurve, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            return;
        }
コード例 #9
0
ファイル: Polycurve.cs プロジェクト: BHoM/OpenStudio_Toolkit
 public static Point3dVector ToOSM(this BHG.PolyCurve pCurve)
 {
     return(pCurve.ICollapseToPolyline(BHG.Tolerance.Angle).ToOSM());
 }
コード例 #10
0
        /***************************************************/

        public static void RenderWires(BHG.PolyCurve polycurve, Rhino.Display.DisplayPipeline pipeline, Color bhColour)
        {
            pipeline.DrawCurve(polycurve.ToRhino(), bhColour, 2);
        }