Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /***************************************************/

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

            List <int> uvCount = surface.UVCount();

            RHG.NurbsSurface rhSurface = RHG.NurbsSurface.Create(3, true, surface.UDegree + 1, surface.VDegree + 1, uvCount[0], uvCount[1]);
            for (int i = 0; i < rhSurface.KnotsU.Count; i++)
            {
                rhSurface.KnotsU[i] = surface.UKnots[i];
            }
            for (int i = 0; i < rhSurface.KnotsV.Count; i++)
            {
                rhSurface.KnotsV[i] = surface.VKnots[i];
            }
            for (int i = 0; i < uvCount[0]; i++)
            {
                for (int j = 0; j < uvCount[1]; j++)
                {
                    rhSurface.Points.SetControlPoint(i, j, new RHG.ControlPoint(surface.ControlPoints[j + (uvCount[1] * i)].ToRhino(), surface.Weights[j + (uvCount[1] * i)]));
                }
            }

            if (!rhSurface.IsValid)
            {
                return(null);
            }

            if (surface.OuterTrims.Count == 0 && surface.InnerTrims.Count == 0)
            {
                return(rhSurface);
            }
            else
            {
                RHG.Brep     brep = new RHG.Brep();
                int          srf  = brep.AddSurface(rhSurface);
                RHG.BrepFace face = brep.Faces.Add(srf);

                foreach (BHG.SurfaceTrim trim in surface.OuterTrims)
                {
                    brep.AddBrepTrim(face, trim, RHG.BrepLoopType.Outer);
                }

                foreach (BHG.SurfaceTrim trim in surface.InnerTrims)
                {
                    brep.AddBrepTrim(face, trim, RHG.BrepLoopType.Inner);
                }

                return(brep.IsValid ? brep : null);
            }
        }
Ejemplo n.º 3
0
        //private void ProcessFace(
        //    Wire wire, ref Brep ghBrep, BrepFace ghBrepFace, BrepLoopType ghBrepLoopType, Rhino.Geometry.Surface ghSurface,
        //    Dictionary<Edge, Tuple<int, int>> edge2DIndices, Dictionary<Edge, BrepEdge> edgeIndices)
        //{
        //    List<Edge> edges = wire.Edges;
        //    BrepLoop ghBrepLoop = ghBrep.Loops.Add(ghBrepLoopType, ghBrepFace);

        //    // 2f.For each loop, add a trim(2D edge)
        //    List<BrepEdge> ghEdges = new List<BrepEdge>();
        //    List<Tuple<Curve, int, Curve, int>> gh2DCurves = new List<Tuple<Curve, int, Curve, int>>(); // original curve, index, reverse curve, reverse index
        //    foreach (Edge edge in edges)
        //    {
        //        Tuple<int, int> thisEdge2DIndices = edge2DIndices.
        //            Where(edgeIndexPair => edgeIndexPair.Key.IsSame(edge)).
        //            Select(edgeIndexPair => edgeIndexPair.Value).
        //            FirstOrDefault();

        //        int thisEdge2DIndex = thisEdge2DIndices.Item1;
        //        int thisReverseEdge2DIndex = thisEdge2DIndices.Item2;

        //        Curve ghCurve2D = ghBrep.Curves2D[thisEdge2DIndex];
        //        Curve ghReverseCurve2D = ghBrep.Curves2D[thisReverseEdge2DIndex];
        //        gh2DCurves.Add(Tuple.Create(ghCurve2D, thisEdge2DIndex, ghReverseCurve2D, thisReverseEdge2DIndex));

        //        BrepEdge ghBrepEdge = edgeIndices.
        //            Where(edgeIndexPair => edgeIndexPair.Key.IsSame(edge)).
        //            Select(edgeIndexPair => edgeIndexPair.Value).
        //            FirstOrDefault();

        //        String ghBrepEdgeLog = "";
        //        if (!ghBrepEdge.IsValidWithLog(out ghBrepEdgeLog))
        //        {
        //            throw new Exception("Fails to create a valid Brep with the following message: " + ghBrepEdgeLog);
        //        }

        //        ghEdges.Add(ghBrepEdge);
        //    }

        //    for (int currentEntryID = 0; currentEntryID < gh2DCurves.Count; ++currentEntryID)
        //    {
        //        int previousEntryID = currentEntryID - 1;
        //        if (previousEntryID < 0)
        //        {
        //            previousEntryID = edges.Count - 1;
        //        }

        //        bool isCurrentStartEqualToPreviousStart = gh2DCurves[currentEntryID].Item1.PointAtStart.DistanceTo(
        //                                                    gh2DCurves[previousEntryID].Item1.PointAtStart) < tolerance;
        //        bool isCurrentStartEqualToPreviousEnd = gh2DCurves[currentEntryID].Item1.PointAtStart.DistanceTo(
        //                                                    gh2DCurves[previousEntryID].Item1.PointAtEnd) < tolerance;
        //        bool isTrimReversed = false;
        //        if (!isCurrentStartEqualToPreviousStart && !isCurrentStartEqualToPreviousEnd)
        //        {
        //            // Reverse trim
        //            isTrimReversed = true;
        //        }

        //        BrepTrim ghBrepTrim = ghBrep.Trims.Add(
        //            ghEdges[currentEntryID],       // 3D edge
        //            isTrimReversed,                // is reversed?
        //            ghBrepLoop,                    // 2D loop
        //            isTrimReversed ? gh2DCurves[currentEntryID].Item4 : gh2DCurves[currentEntryID].Item2);  // 2D curve index, use the reversed one if reversed

        //        ghBrepTrim.IsoStatus = ghSurface.IsIsoparametric(gh2DCurves[currentEntryID].Item1);
        //        ghBrepTrim.TrimType = BrepTrimType.Boundary;
        //        ghBrepTrim.SetTolerances(0.0, 0.0);

        //        String ghBrepTrimLog = "";
        //        if (!ghBrepTrim.IsValidWithLog(out ghBrepTrimLog))
        //        {
        //            throw new Exception("Fails to create a valid BrepTrim with the following message: " + ghBrepTrimLog);
        //        }
        //    }

        //    String brepLoopLog = "";
        //    if (!ghBrepLoop.IsValidWithLog(out brepLoopLog))
        //    {
        //        throw new Exception("Fails to create a valid outer BrepLoop with the following message: " + brepLoopLog);
        //    }
        //}

        private Rhino.Geometry.NurbsSurface ToRhinoNurbsSurface(Topologic.NurbsSurface nurbsSurface)
        {
            int  uDegree    = nurbsSurface.UDegree;
            int  vDegree    = nurbsSurface.VDegree;
            bool isRational = nurbsSurface.IsURational && nurbsSurface.IsVRational;
            int  uCount     = nurbsSurface.NumOfUControlVertices;
            int  vCount     = nurbsSurface.NumOfVControlVertices;

            Rhino.Geometry.NurbsSurface ghNurbsSurface = Rhino.Geometry.NurbsSurface.Create(
                3,
                isRational,
                uDegree + 1,
                vDegree + 1,
                uCount,
                vCount
                );

            int i = 0;

            for (int u = 0; u < uCount; ++u)
            {
                for (int v = 0; v < vCount; ++v)
                {
                    Topologic.Vertex controlVertex = nurbsSurface.ControlVertex(u, v);
                    ghNurbsSurface.Points.SetPoint(u, v, ToPoint(controlVertex));
                    ++i;
                }
            }

            List <double> uKnots = nurbsSurface.UKnots;

            uKnots = uKnots.GetRange(1, uKnots.Count - 2);
            for (int u = 0; u < uKnots.Count; u++)
            {
                ghNurbsSurface.KnotsU[u] = uKnots[u];
            }

            List <double> vKnots = nurbsSurface.VKnots;

            vKnots = vKnots.GetRange(1, vKnots.Count - 2);
            for (int v = 0; v < vKnots.Count; v++)
            {
                ghNurbsSurface.KnotsV[v] = vKnots[v];
            }

            if (!ghNurbsSurface.IsValid)
            {
                throw new Exception("A valid surface cannot be created from this Face.");
            }

            return(ghNurbsSurface);
        }
Ejemplo n.º 4
0
        /// <summary> btnNewDwgPlane creates new drawing plane perpedicular to camera centered around chosed origin </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewDwgPlane_Click(object sender, EventArgs e)
        {
            Rhino.Geometry.Point3d pt1 = org;

            Rhino.Geometry.Transform move1 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraX);
            Rhino.Geometry.Transform move2 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraY);

            var xRev = view3.MainViewport.CameraX;
            var yRev = view3.MainViewport.CameraY;

            xRev.Reverse();
            yRev.Reverse();

            Rhino.Geometry.Transform move3 = Rhino.Geometry.Transform.Translation(xRev);
            Rhino.Geometry.Transform move4 = Rhino.Geometry.Transform.Translation(yRev);

            Rhino.Geometry.Point3d pt2 = org;
            Rhino.Geometry.Point3d pt3 = org;
            Rhino.Geometry.Point3d pt4 = org;
            Rhino.Geometry.Point3d pt5 = org;

            //Rhino.Geometry.Vector3d.l

            pt2.Transform(move1);
            pt2.Transform(move2);

            pt3.Transform(move3);
            pt3.Transform(move4);

            pt4.Transform(move1);
            pt4.Transform(move4);

            pt5.Transform(move3);
            pt5.Transform(move2);

            srf1   = Rhino.Geometry.NurbsSurface.CreateFromCorners(pt2, pt4, pt3, pt5);
            plane1 = new Plane(org, view3.MainViewport.CameraX, view3.MainViewport.CameraY);
            Rhino.Geometry.Transform scale1 = Rhino.Geometry.Transform.Scale(org, 400);
            srf1.Transform(scale1);

            mRhinoDoc.Objects.AddPoint(pt1);
            mRhinoDoc.Objects.AddPoint(pt2);
            mRhinoDoc.Objects.AddPoint(pt3);
            mRhinoDoc.Objects.AddPoint(pt4);
            mRhinoDoc.Objects.AddPoint(pt5);

            mRhinoDoc.Objects.AddSurface(srf1);

            mRhinoDoc.Views.Redraw();
        }
Ejemplo n.º 5
0
        private Topologic.Face BySurface(Rhino.Geometry.Surface ghSurface)
        {
            SumSurface ghSumSurface = ghSurface as SumSurface;

            if (ghSumSurface != null)
            {
                return(BySumSurface(ghSumSurface));
            }

            RevSurface ghRevSurface = ghSurface as RevSurface;

            if (ghRevSurface != null)
            {
                return(ByRevSurface(ghRevSurface));
            }

            PlaneSurface ghPlaneSurface = ghSurface as PlaneSurface;

            if (ghPlaneSurface != null)
            {
                return(ByPlaneSurface(ghPlaneSurface));
            }

            //ClippingPlaneSurface ghClippingPlaneSurface = ghSurface as ClippingPlaneSurface;
            //if (ghClippingPlaneSurface != null)
            //{
            //    return ByClippingPlaneSurface(ghClippingPlaneSurface);
            //}

            Extrusion ghExtrusion = ghSurface as Extrusion;

            if (ghExtrusion != null)
            {
                return(ByExtrusion(ghExtrusion));
            }

            Rhino.Geometry.NurbsSurface ghNurbsSurface = ghSurface as Rhino.Geometry.NurbsSurface;
            if (ghNurbsSurface != null)
            {
                return(ByNurbsSurface(ghNurbsSurface));
            }

            //BrepFace ghBrepFace = ghSurface as BrepFace;
            //if (ghBrepFace != null)
            //{
            //    return ByBrepFace(ghBrepFace);
            //}

            throw new Exception("This type of surface is not yet supported.");
        }
Ejemplo n.º 6
0
        public static NurbsSurface ToCore(this RG.NurbsSurface surface)
        {
            var controlPoints = new Matrix <Point4d>(surface.Points.CountU, surface.Points.CountV);

            for (int i = 0; i < surface.Points.CountU; i++)
            {
                for (int j = 0; j < surface.Points.CountV; j++)
                {
                    surface.Points.GetPoint(i, j, out RG.Point4d pt);
                    controlPoints[i, j] = pt.ToCore();
                }
            }

            return(new NurbsSurface(controlPoints, surface.OrderU - 1, surface.OrderV - 1));
        }
Ejemplo n.º 7
0
        public static global::Topologic.Face ToTopologic(this Rhino.Geometry.NurbsSurface nurbsSurface)
        {
            if (nurbsSurface == null)
            {
                return(null);
            }

            int  uDegree     = nurbsSurface.Degree(0);
            int  vDegree     = nurbsSurface.Degree(1);
            bool isUPeriodic = nurbsSurface.IsPeriodic(0);
            bool isVPeriodic = nurbsSurface.IsPeriodic(1);
            bool isRational  = nurbsSurface.IsRational;
            NurbsSurfaceKnotList ghUKnots = nurbsSurface.KnotsU;
            List <double>        uKnots   = ghUKnots.ToList();

            NurbsSurfaceKnotList ghVKnots = nurbsSurface.KnotsV;
            List <double>        vKnots   = ghVKnots.ToList();

            // OCCT-compatible
            uKnots.Insert(0, uKnots[0]);
            uKnots.Add(uKnots.Last());
            vKnots.Insert(0, vKnots[0]);
            vKnots.Add(vKnots.Last());

            NurbsSurfacePointList  ghControlPoints = nurbsSurface.Points;
            List <IList <Vertex> > controlPoints   = new List <IList <Vertex> >();
            List <IList <double> > weights         = new List <IList <double> >();

            for (int i = 0; i < ghControlPoints.CountU; ++i)
            {
                List <Vertex> controlPoints1D = new List <Vertex>();
                List <double> weights1D       = new List <double>();
                for (int j = 0; j < ghControlPoints.CountV; ++j)
                {
                    ControlPoint ghControlPoint = ghControlPoints.GetControlPoint(i, j);
                    controlPoints1D.Add(ghControlPoint.Location.ToTopologic());
                    weights1D.Add(ghControlPoint.Weight);
                }
                controlPoints.Add(controlPoints1D);
                weights.Add(weights1D);
            }

            return(global::Topologic.Face.ByNurbsParameters(controlPoints, weights, uKnots, vKnots, isRational, isUPeriodic, isVPeriodic, uDegree, vDegree));
        }
Ejemplo n.º 8
0
        public static global::Topologic.Face ToTopologic(this 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());
            }

            Rhino.Geometry.Extrusion ghExtrusion = surface as Rhino.Geometry.Extrusion;
            if (ghExtrusion != null)
            {
                return(ghExtrusion.ToTopologic());
            }

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


            return(null);
        }
Ejemplo n.º 9
0
        private Face ByNurbsSurface(Rhino.Geometry.NurbsSurface ghNurbsSurface)
        {
            int  uDegree     = ghNurbsSurface.Degree(0);
            int  vDegree     = ghNurbsSurface.Degree(1);
            bool isUClosed   = ghNurbsSurface.IsClosed(0);
            bool isVClosed   = ghNurbsSurface.IsClosed(1);
            bool isUPeriodic = ghNurbsSurface.IsPeriodic(0);
            bool isVPeriodic = ghNurbsSurface.IsPeriodic(1);
            bool isRational  = ghNurbsSurface.IsRational;
            NurbsSurfaceKnotList ghUKnots = ghNurbsSurface.KnotsU;
            List <double>        uKnots   = ghUKnots.ToList();

            NurbsSurfaceKnotList ghVKnots = ghNurbsSurface.KnotsV;
            List <double>        vKnots   = ghVKnots.ToList();

            // OCCT-compatible
            uKnots.Insert(0, uKnots[0]);
            uKnots.Add(uKnots.Last());
            vKnots.Insert(0, vKnots[0]);
            vKnots.Add(vKnots.Last());

            NurbsSurfacePointList           ghControlPoints = ghNurbsSurface.Points;
            List <List <Topologic.Vertex> > controlPoints   = new List <List <Topologic.Vertex> >();
            List <List <double> >           weights         = new List <List <double> >();

            for (int i = 0; i < ghControlPoints.CountU; ++i)
            {
                List <Topologic.Vertex> controlPoints1D = new List <Topologic.Vertex>();
                List <double>           weights1D       = new List <double>();
                for (int j = 0; j < ghControlPoints.CountV; ++j)
                {
                    ControlPoint ghControlPoint = ghControlPoints.GetControlPoint(i, j);
                    controlPoints1D.Add(ByPoint(ghControlPoint.Location));
                    weights1D.Add(ghControlPoint.Weight);
                }
                controlPoints.Add(controlPoints1D);
                weights.Add(weights1D);
            }

            return(Topologic.Face.ByNurbsParameters(controlPoints, weights, uKnots, vKnots, isRational, isUPeriodic, isVPeriodic, uDegree, vDegree));
        }
Ejemplo n.º 10
0
        /***************************************************/

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

            RHG.NurbsSurface       rhNurbsSurf = rhSurf.ToNurbsSurface();
            List <BHG.SurfaceTrim> innerTrims  = new List <BHG.SurfaceTrim>();
            List <BHG.SurfaceTrim> outerTrims  = new List <BHG.SurfaceTrim>();

            foreach (RHG.BrepLoop loop in face.Loops)
            {
                if (loop.LoopType == RHG.BrepLoopType.Outer)
                {
                    outerTrims.Add(loop.FromRhino());
                }
                else
                {
                    innerTrims.Add(loop.FromRhino());
                }
            }

            return(new BHG.NurbsSurface
                   (
                       rhNurbsSurf.Points.Select(x => x.Location.FromRhino()).ToList(),
                       rhNurbsSurf.Points.Select(x => x.Weight).ToList(),
                       rhNurbsSurf.KnotsU.ToList(),
                       rhNurbsSurf.KnotsV.ToList(),
                       rhNurbsSurf.Degree(0),
                       rhNurbsSurf.Degree(1),
                       innerTrims,
                       outerTrims
                   ));
        }
Ejemplo n.º 11
0
        /***************************************************/

        public static void RenderRhinoWires(RHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawSurface(surface, bhColour, thickness);
        }
Ejemplo n.º 12
0
        internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex)
        {
            if (IntPtr.Zero == pGeometry)
            {
                return(null);
            }

            var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry);

            if (type < 0)
            {
                return(null);
            }
            GeometryBase rc = null;

            switch (type)
            {
            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1
                rc = new Curve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2
                rc = new NurbsCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3
                rc = new PolyCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4
                rc = new PolylineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5
                rc = new ArcCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6
                rc = new LineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7
                rc = new Mesh(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8
                rc = new Point(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9
                rc = new TextDot(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10
                rc = new Surface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11
                rc = new Brep(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12
                rc = new NurbsSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13
                rc = new RevSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14
                rc = new PlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15
                rc = new ClippingPlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17
                rc = new Hatch(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19
                rc = new SumSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20
            {
                int    faceindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex);
                if (ptr_brep != IntPtr.Zero && faceindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Faces[faceindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21
            {
                int    edgeindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex);
                if (ptr_brep != IntPtr.Zero && edgeindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Edges[edgeindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23
                rc = new InstanceReferenceGeometry(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24
                rc = new Extrusion(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26
                rc = new PointCloud(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27
                rc = new DetailView(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32
                rc = new Light(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33
                rc = new Point3dGrid(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34
                rc = new MorphControl(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35
            {
                int    loopindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex);
                if (ptr_brep != IntPtr.Zero && loopindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Loops[loopindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36
            {
                int    trimindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex);
                if (ptr_brep != IntPtr.Zero && trimindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Trims[trimindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38
                rc = new Leader(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39
                rc = new SubD(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40
                rc = new LinearDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41
                rc = new AngularDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42
                rc = new RadialDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43
                rc = new OrdinateDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44
                rc = new Centermark(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45
                rc = new TextEntity(pGeometry, parent);
                break;

            default:
                rc = new UnknownGeometry(pGeometry, parent, subobjectIndex);
                break;
            }

            return(rc);
        }
Ejemplo n.º 13
0
 public NurbsSurface ToNurbsSurface()
 {
     return(NurbsSurface.CreateFromCylinder(this));
 }
Ejemplo n.º 14
0
 public NurbsSurface ToNurbsSurface()
 {
     return(NurbsSurface.CreateFromTorus(this));
 }
Ejemplo n.º 15
0
 public static NurbsSurface ToCore(this RG.NurbsSurface surface) =>
 throw new NotImplementedException();
Ejemplo n.º 16
0
 public static global::Topologic.Face ToTopologic(Rhino.Geometry.Extrusion extrusion)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = extrusion?.ToNurbsSurface();
     return(ghNurbsSurface?.ToTopologic());
 }
Ejemplo n.º 17
0
        /***************************************************/

        public static void RenderRhinoMeshes(RHG.NurbsSurface surface, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            pipeline.DrawBrepShaded(surface.ToBrep(), material);
        }
Ejemplo n.º 18
0
 private Topologic.Face BySumSurface(SumSurface ghSumSurface)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = ghSumSurface.ToNurbsSurface();
     return(ByNurbsSurface(ghNurbsSurface));
 }
Ejemplo n.º 19
0
        //public static Parasite_BrepSurface ToParasiteType(this DB.Face face, bool untrimmed = false)
        //{
        //    var surface = face.ToRhinoSurface();
        //    if (surface is null)
        //        return null;

        //    var brep = Brep.CreateFromSurface(surface);
        //    if (brep is null)
        //        return null;


        //    if (untrimmed)
        //        return brep;

        //    var loops = face.GetEdgesAsCurveLoops().ToRhino().ToArray();



        //    try { return brep.TrimFaces(loops); }
        //    finally { brep.Dispose(); }
        //}


        //public static Parasite_BrepSolid ToParasiteType(DB.Solid solid)
        //{
        //    return solid.Faces.
        //           Cast<DB.Face>().
        //           Select(x => x.ToRhino()).
        //           ToArray().
        //           JoinAndMerge(Revit.VertexTolerance);
        //}


        #endregion


        #region NURBS SURFACE

        public static Parasite_NurbsSurface ToParasiteType(Rhino.Geometry.NurbsSurface nurbsSurface, Dictionary <string, string> properties = null)
        {
            Parasite_NurbsSurface parasite_NurbsSurface = null;

            if (!nurbsSurface.IsValid)
            {
                throw new ParasiteArgumentException("Please enter a valid Rhino Nurbs Surface");
            }

            else
            {
                if (nurbsSurface.IsSphere())
                {
                    throw new ParasiteNotImplementedExceptions("There is still no support for Rhino NURBS Spheres");
                }

                else if (nurbsSurface.IsTorus())
                {
                    throw new ParasiteNotImplementedExceptions("There is still no support for Rhino NURBS Torus");
                }

                else
                {
                    NurbsSurfaceKnotList  rhinoKnotsU = nurbsSurface.KnotsU;
                    NurbsSurfaceKnotList  rhinoKnotsV = nurbsSurface.KnotsV;
                    NurbsSurfacePointList cp          = nurbsSurface.Points;

                    double[]   knotsU  = new double[rhinoKnotsU.Count];
                    double[]   knotsV  = new double[rhinoKnotsV.Count];
                    double[][] weights = new double[cp.Count()][];

                    if (cp.Any((x) => !x.Location.IsValid))
                    {
                        throw new ParasiteArgumentException("The Rhino NURBS Surface had an invalid Control Point!");
                    }

                    Parasite_Point3d[][] vertices = new Parasite_Point3d[cp.Count()][];

                    for (int i = 0; i < rhinoKnotsU.Count; i++)
                    {
                        knotsU[i] = rhinoKnotsU[i];
                        knotsV[i] = rhinoKnotsV[i];
                    }


                    //for (int u = 0; u < cp.CountU; u++)
                    //{
                    //    for (int v = 0; v < cp.CountV; v++)
                    //    {
                    //        Point3d controlP = cp.GetControlPoint(u, v).Location;
                    //        double weight = cp.GetWeight(u, v);

                    //    }
                    //}



                    int count = -1;
                    foreach (var item in cp)
                    {
                        count++;
                        if (item.Weight <= 1e-11)
                        {
                            weights[count] = new double[] { 0.0 }
                        }
                        ;

                        weights[count]  = new double[] { item.Weight };
                        vertices[count] = new Parasite_Point3d[] { ToParasiteType(item.Location) };
                    }

                    parasite_NurbsSurface = new Parasite_NurbsSurface(vertices, knotsU, knotsV, weights, nurbsSurface.Degree(0), nurbsSurface.Degree(1));
                }
            }

            return(parasite_NurbsSurface);
        }

        #endregion

        #endregion
    }
Ejemplo n.º 20
0
        /// <summary> btnNewDwgPlane creates new drawing plane perpedicular to camera centered around chosed origin </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewDwgPlane_Click(object sender, EventArgs e)
        {
            Rhino.Geometry.Point3d pt1 = org;

            Rhino.Geometry.Transform move1 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraX);
            Rhino.Geometry.Transform move2 = Rhino.Geometry.Transform.Translation(view3.MainViewport.CameraY);

            var xRev = view3.MainViewport.CameraX;
            var yRev = view3.MainViewport.CameraY;
            xRev.Reverse();
            yRev.Reverse();

            Rhino.Geometry.Transform move3 = Rhino.Geometry.Transform.Translation(xRev);
            Rhino.Geometry.Transform move4 = Rhino.Geometry.Transform.Translation(yRev);

            Rhino.Geometry.Point3d pt2 = org;
            Rhino.Geometry.Point3d pt3 = org;
            Rhino.Geometry.Point3d pt4 = org;
            Rhino.Geometry.Point3d pt5 = org;

            //Rhino.Geometry.Vector3d.l

            pt2.Transform(move1);
            pt2.Transform(move2);

            pt3.Transform(move3);
            pt3.Transform(move4);

            pt4.Transform(move1);
            pt4.Transform(move4);

            pt5.Transform(move3);
            pt5.Transform(move2);

            srf1 = Rhino.Geometry.NurbsSurface.CreateFromCorners(pt2, pt4, pt3, pt5);
            plane1 = new Plane(org, view3.MainViewport.CameraX, view3.MainViewport.CameraY);
            Rhino.Geometry.Transform scale1 = Rhino.Geometry.Transform.Scale(org, 400);
            srf1.Transform(scale1);

            mRhinoDoc.Objects.AddPoint(pt1);
            mRhinoDoc.Objects.AddPoint(pt2);
            mRhinoDoc.Objects.AddPoint(pt3);
            mRhinoDoc.Objects.AddPoint(pt4);
            mRhinoDoc.Objects.AddPoint(pt5);

            mRhinoDoc.Objects.AddSurface(srf1);

            mRhinoDoc.Views.Redraw();
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Constructs a SurfaceGHData object from a Rhino.Geometry.NurbsSurface
 /// </summary>
 /// <param name="surface">A Rhino NurbsSurface</param>
 public SurfaceGhData(RG.NurbsSurface surface)
 {
     // TODO: Handle conversion.
     Value = null;
 }
Ejemplo n.º 22
0
 private Face ByExtrusion(Extrusion ghExtrusion)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = ghExtrusion.ToNurbsSurface();
     return(ByNurbsSurface(ghNurbsSurface));
 }
Ejemplo n.º 23
0
 public static global::Topologic.Face ToTopologic(this PlaneSurface planeSurface)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = planeSurface?.ToNurbsSurface();
     return(ghNurbsSurface?.ToTopologic());
 }
Ejemplo n.º 24
0
 public NurbsSurface ToNurbsSurface()
 {
     return(NurbsSurface.CreateFromSphere(this));
 }
Ejemplo n.º 25
0
        /***************************************************/

        public static RHG.Mesh CreatePreviewMesh(RHG.NurbsSurface surface, RHG.MeshingParameters parameters)
        {
            return(CreatePreviewMesh(surface.ToBrep(), parameters));
        }