Пример #1
0
        public static RG.NurbsSurface ToRhino(this NurbsSurface surface)
        {
            // Create surface
            var surf = RG.NurbsSurface.Create(
                3,
                false,
                surface.DegreeU + 1, // order is degree+1
                surface.DegreeV + 1,
                surface.ControlPoints.N,
                surface.ControlPoints.M);

            // Assign control points
            for (var i = 0; i < surface.ControlPoints.N; i++)
            {
                for (var j = 0; j < surface.ControlPoints.M; j++)
                {
                    var pt = surface.ControlPoints[i, j];
                    surf.Points.SetPoint(i, j, pt.X, pt.Y, pt.Z, pt.Weight);
                }
            }

            // TODO: Add switch for periodic knots.

            // Create uniform knots.
            surf.KnotsU.CreateUniformKnots(1);
            surf.KnotsV.CreateUniformKnots(1);

            // Update surface interval.
            surf.SetDomain(0, new RG.Interval(0, 1));
            surf.SetDomain(1, new RG.Interval(0, 1));

            return(surf);
        }
Пример #2
0
        public static List <Surface> Get2DElementsAsSurfaces(IMesh mesh)
        {
            List <Surface> faces = new List <Surface>();
            Surface        f;

            foreach (IElement e in mesh.Elements)
            {
                if (e.TopologicDimension == 2)
                {
                    Point3d[] pts = new Point3d[e.VerticesCount];
                    for (int i = 0; i < e.VerticesCount; i++)
                    {
                        pts[i] = mesh.GetVertexWithKey(e.Vertices[i]).RhinoPoint;
                    }

                    if (pts.Length == 4)
                    {
                        f = NurbsSurface.CreateFromCorners(pts[0], pts[1], pts[2], pts[3]);
                    }
                    else if (pts.Length == 3)
                    {
                        f = NurbsSurface.CreateFromCorners(pts[0], pts[1], pts[2]);
                    }
                    else
                    {
                        f = Brep.CreateEdgeSurface(new PolylineCurve[] { new PolylineCurve(pts), new PolylineCurve(new Point3d[] { pts[pts.Length - 1], pts[0] }) }).Surfaces[0];
                    }


                    faces.Add(f);
                }
            }
            return(faces);
        }
Пример #3
0
        protected void DumpNurbsSurface3D(Item item, NurbsSurface nurbsSurface, int?minPolynomialDegree, double?maxElementSize)
        {
            if (minPolynomialDegree.HasValue)
            {
                nurbsSurface = (NurbsSurface)nurbsSurface.Duplicate();

                nurbsSurface.IncreaseDegreeU(minPolynomialDegree.Value);
                nurbsSurface.IncreaseDegreeV(minPolynomialDegree.Value);
            }

            if (maxElementSize.HasValue)
            {
                nurbsSurface = Utility.RefineSurface(nurbsSurface, maxElementSize.Value);
            }

            item.Set("degree_u", nurbsSurface.Degree(0));
            item.Set("degree_v", nurbsSurface.Degree(1));
            item.Set("knots_u", nurbsSurface.KnotsU);
            item.Set("knots_v", nurbsSurface.KnotsV);
            item.Set("nb_poles_u", nurbsSurface.Points.CountU);
            item.Set("nb_poles_v", nurbsSurface.Points.CountV);
            item.Set("poles", nurbsSurface.Points.Select(o => o.Location));

            if (nurbsSurface.IsRational)
            {
                item.Set("weights", nurbsSurface.Points.Select(o => o.Weight));
            }
        }
Пример #4
0
        private void initNurbsSurface()
        {
            // die NurbsSurface brauchen wir hier für die Ableitungen. Die sind nur schwer aus der Kurvendefinition herauszukriegen
            // Hier also erstmal mit NURBS. Besser wäre es, aus der eigentlichen Definition, da muss man aber Gehirnschmalz reinstecken
            // die NURBS Fläche läuft von 0 bis 1, also synchron zu PointAt. PointAt ist aber genauer
            GeoPoint[,] pnts = new CADability.GeoPoint[8, 8];
            double[] uknots = new double[pnts.GetLength(0)];
            double[] vknots = new double[pnts.GetLength(1)];
            for (int i = 0; i < uknots.Length; i++)
            {
                uknots[i] = (double)i / (uknots.Length - 1);
            }
            for (int i = 0; i < vknots.Length; i++)
            {
                vknots[i] = (double)i / (vknots.Length - 1);
            }
            for (int i = 0; i < pnts.GetLength(0); i++)
            {
                for (int j = 0; j < pnts.GetLength(1); j++)
                {
                    pnts[i, j] = PointAt(new GeoPoint2D(uknots[i], vknots[j]));
                }
            }
            try
            {
                forDerivation = new NurbsSurface(pnts, 3, 3, uknots, vknots, false, false);
                forDerivation.ScaleKnots(0, 1, 0, 1);
#if DEBUG
                GeoObjectList dbg = forDerivation.DebugGrid;
#endif
            }
            catch (NurbsException) { }
        }
Пример #5
0
        protected override void OnCreated()
        {
            base.OnCreated();
            Navigating = true;

            TheNurbs = new NurbsSurface();

            _BsplineSurface = CreateBsplineSurface();

            BsplineSurface.AsNurb = _BsplineSurface;
            TheNurbs       = BsplineSurface;
            _Sphere.Center = new xyz(4, 0, 0);
            _Sphere.Radius = 4;

            Sphere.AsNurb      = _Sphere;
            _Torus.InnerRadius = 1;
            _Torus.OuterRadius = 5;
            Torus.AsNurb       = _Torus;

            _Cone.HalfAngle = System.Math.PI / 6;
            _Cone.Radius    = 4;
            _Cone.Height    = 5;
            Cone.AsNurb     = _Cone;

            _Cylinder.Radius = 4;
            _Cylinder.Height = 5;
            Cylinder.AsNurb  = _Cylinder;


            CurrentForm.label1.Text = "BsplineSurface";
            Marked = new System.Drawing.Point(2, 2);
        }
Пример #6
0
        protected void DumpNurbsSurface3D(Item item, NurbsSurface nurbsSurface)
        {
            if (Info.Instance.Settings.GetBool("EnableMinPolynomialDegree", false))
            {
                nurbsSurface = (NurbsSurface)nurbsSurface.Duplicate();

                var minPolynomialDegree = Info.Instance.Settings.GetInteger("MinPolynomialDegree", 1);

                nurbsSurface.IncreaseDegreeU(minPolynomialDegree);
                nurbsSurface.IncreaseDegreeV(minPolynomialDegree);
            }

            if (Info.Instance.Settings.GetBool("EnableMaxElementSize", false))
            {
                var maxElementSize = Info.Instance.Settings.GetDouble("MaxElementSize", 10.0);

                nurbsSurface = Utility.RefineSurface(nurbsSurface, maxElementSize);
            }

            item.Set("degree_u", nurbsSurface.Degree(0));
            item.Set("degree_v", nurbsSurface.Degree(1));
            item.Set("knots_u", nurbsSurface.KnotsU);
            item.Set("knots_v", nurbsSurface.KnotsV);
            item.Set("nb_poles_u", nurbsSurface.Points.CountU);
            item.Set("nb_poles_v", nurbsSurface.Points.CountV);
            item.Set("poles", nurbsSurface.Points.Select(o => o.Location));

            if (nurbsSurface.IsRational)
            {
                item.Set("weights", nurbsSurface.Points.Select(o => o.Weight));
            }
        }
Пример #7
0
        public void It_Creates_A_NurbsSurface_From_Swep()
        {
            // Arrange
            List <Point3> ptsA = new List <Point3>
            {
                new Point3(5, 0, 0),
                new Point3(5, 5, 0),
                new Point3(0, 5, 0),
                new Point3(0, 5, 5),
                new Point3(5, 5, 5)
            };
            List <Point3> ptsB = new List <Point3>
            {
                new Point3(4, 0, 1),
                new Point3(5, 0, 0),
                new Point3(6, 0, 1)
            };
            NurbsCurve rail    = new NurbsCurve(ptsA, 3);
            NurbsCurve profile = new NurbsCurve(ptsB, 2);

            // Act
            NurbsSurface sweepSurface = NurbsSurface.FromSweep(rail, profile);

            // Assert
            (sweepSurface.ControlPointLocations.Last()[1] == ptsA.Last()).Should().BeTrue();
        }
Пример #8
0
        /***************************************************/
        /**** Public Methods - Surfaces                 ****/
        /***************************************************/

        public static Point PointAtParameter(this NurbsSurface surface, double u, double v)
        {
            double a      = 0;
            Point  result = new Point();

            var uv = surface.UVCount();

            List <double> uKnots = surface.UKnots.ToList();
            List <double> vKnots = surface.VKnots.ToList();

            Func <int, int, int> ind = (i, j) => i * uv[1] + j;

            for (int i = 0; i < uv[0]; i++)
            {
                for (int j = 0; j < uv[1]; j++)
                {
                    double basis = BasisFunction(uKnots, i - 1, surface.UDegree, u) *
                                   BasisFunction(vKnots, j - 1, surface.VDegree, v) *
                                   surface.Weights[ind(i, j)];

                    a      += basis;
                    result += basis * surface.ControlPoints[ind(i, j)];
                }
            }

            return(result / a);
        }
Пример #9
0
        public static RG.NurbsSurface ToRhino(this NurbsSurface surface)
        {
            var result = RG.NurbsSurface.Create(3, false, surface.DegreeU + 1, surface.DegreeV + 1,
                                                surface.ControlPoints.M, surface.ControlPoints.N);

            for (var i = 0; i < surface.ControlPoints.M; i++)
            {
                for (var j = 0; j < surface.ControlPoints.N; j++)
                {
                    result.Points.SetPoint(i, j, surface.ControlPoints[i, j].ToRhino());
                }
            }

            var knotsU = surface.KnotsU.GetRange(1, surface.KnotsU.Count - 2);

            for (var i = 0; i < knotsU.Count; i++)
            {
                result.KnotsU[i] = knotsU[i];
            }

            var knotsV = surface.KnotsV.GetRange(1, surface.KnotsV.Count - 2);

            for (var i = 0; i < knotsU.Count; i++)
            {
                result.KnotsV[i] = knotsV[i];
            }

            return(result);
        }
Пример #10
0
        public void Returns_A_Ruled_Surface_Between_A_Polyline_And_A_Nurbs_Curve(double u, double v, double[] pt)
        {
            // Arrange
            Point3        expectedPt = new Point3(pt[0], pt[1], pt[2]);
            List <Point3> ptsA       = new List <Point3>
            {
                new Point3(0, 0, 0),
                new Point3(0, 0, 5),
                new Point3(5, 0, 5),
                new Point3(5, 0, 0),
                new Point3(10, 0, 0)
            };

            List <Point3> ptsB = new List <Point3>
            {
                new Point3(0, 10, 0),
                new Point3(0, 10, 5),
                new Point3(5, 10, 5),
                new Point3(5, 10, 0),
                new Point3(10, 10, 0)
            };

            PolyLine   poly   = new PolyLine(ptsA);
            NurbsCurve curveB = new NurbsCurve(ptsB, 2);

            // Act
            NurbsSurface ruledSurface = NurbsSurface.Ruled(poly, curveB);
            Point3       pointAt      = ruledSurface.PointAt(u, v);

            // Assert
            pointAt.EpsilonEquals(expectedPt, GSharkMath.MinTolerance).Should().BeTrue();
        }
        /// <summary>
        /// Creates a Brep surface
        /// </summary>
        /// <param name="sw">The first corner point</param>
        /// <param name="se">The second corner point</param>
        /// <param name="ne">The third corner point</param>
        /// <param name="nw">The forth corner point</param>
        /// <returns>The surface if successful, null otherwise</returns>
        private static Surface CreatePlanarSurface(Point3d sw, Point3d se, Point3d ne, Point3d nw)
        {
            var nurb = NurbsSurface.Create(
                3,     // dimension (>= 1)
                false, // not rational
                2,     // "u" order (>= 2)
                2,     // "v" order (>= 2)
                2,     // number of control vertices in "u" dir (>= order)
                2      // number of control vertices in "v" dir (>= order)
                );

            // Corner CVs in counter clockwise order starting in the south west
            nurb.Points.SetControlPoint(0, 0, sw);
            nurb.Points.SetControlPoint(1, 0, se);
            nurb.Points.SetControlPoint(1, 1, ne);
            nurb.Points.SetControlPoint(0, 1, nw);

            // "u" knots
            nurb.KnotsU[0] = 0.0;
            nurb.KnotsU[1] = 1.0;

            // "v" knots
            nurb.KnotsV[0] = 0.0;
            nurb.KnotsV[1] = 1.0;

            return(nurb);
        }
Пример #12
0
 private DGridPath(NurbsSurface refSurface, NurbsSurface actSurface, Transform material, Types type)
 {
     RefSurface = refSurface;
     ActSurface = actSurface;
     Material   = material;
     Type       = type;
 }
Пример #13
0
        static void Main(string[] args)
        {
            ComputeServer.AuthToken = Rhino.Compute.AuthToken.Get();

            Curve curveA = Curve.CreateControlPointCurve(new Point3d[] {
                new Point3d(0.0, 0.0, 0.0),
                new Point3d(0.0, 0.5, -0.5),
                new Point3d(0.0, 1.0, 0.0)
            });
            Curve curveB = Curve.CreateControlPointCurve(new Point3d[] {
                new Point3d(1.0, 0.0, 0.0),
                new Point3d(1.0, 0.3, 0.6),
                new Point3d(1.0, 0.5, 0.0),
                new Point3d(1.0, 0.7, 0.8),
                new Point3d(1.0, 1.0, 0.0)
            });

            NurbsSurface ruled = NurbsSurface.CreateRuledSurface(curveA, curveB);

            Mesh mesh1 = MeshCompute.CreateFromSurface(ruled);

            Rhino.Compute.ObjExport.ExportMeshesToObj("ruled_mesh_default.obj", new Mesh[] { mesh1 });

            MeshingParameters meshingParameters = new MeshingParameters();

            meshingParameters.MaximumEdgeLength = 0.1;
            Mesh mesh2 = MeshCompute.CreateFromSurface(ruled, meshingParameters);

            Rhino.Compute.ObjExport.ExportMeshesToObj("ruled_mesh_refined1.obj", new Mesh[] { mesh2 });

            meshingParameters.MaximumEdgeLength = 0.05;
            Mesh mesh3 = MeshCompute.CreateFromSurface(ruled, meshingParameters);

            Rhino.Compute.ObjExport.ExportMeshesToObj("ruled_mesh_refined2.obj", new Mesh[] { mesh3 });
        }
Пример #14
0
        public static NurbsSurface SurfaceFromPoints()
        {
            List <List <Point3> > pts = new List <List <Point3> >
            {
                new List <Point3> {
                    new Point3(0.0, 0.0, 0.0), new Point3(0.0, 10.0, 4.0)
                },
                new List <Point3> {
                    new Point3(5.0, 0.0, 0.0), new Point3(5.0, 10.0, 5.0)
                },
                new List <Point3> {
                    new Point3(10.0, 0.0, 0.0), new Point3(10.0, 10.0, 2.0)
                }
            };

            List <List <double> > weight = new List <List <double> >
            {
                new List <double> {
                    1, 1
                },
                new List <double> {
                    1, 2
                },
                new List <double> {
                    1, 1
                },
            };

            return(NurbsSurface.FromPoints(2, 1, pts, weight));
        }
Пример #15
0
        // Default Constructor.
        public SurfaceEnvironmentType()
        {
            Point3d pt1 = new Point3d(0, 0, 0);
            Point3d pt2 = new Point3d(RS.boxBoundsDefault, 0, 0);
            Point3d pt3 = new Point3d(0, RS.boxBoundsDefault, 0);

            environment = NurbsSurface.CreateFromCorners(pt1, pt2, pt3);
            Interval u = environment.Domain(0);
            Interval v = environment.Domain(1);

            pt1            = new Point3d(u.Min, v.Min, 0);
            pt2            = new Point3d(u.Max, v.Min, 0);
            pt3            = new Point3d(u.Min, v.Max, 0);
            RefEnvironment = NurbsSurface.CreateFromCorners(pt1, pt2, pt3);

            Interval uDom = RefEnvironment.Domain(0);
            Interval vDom = RefEnvironment.Domain(1);

            minX = uDom.Min;
            maxX = uDom.Max;
            minY = vDom.Min;
            maxY = vDom.Max;

            Width  = maxX - minX;
            Height = maxY - minY;
        }
Пример #16
0
        public void Setup(
            int deg,
            int ucnt, int vcnt,
            VertexList vl,
            int[] ctrlOrder,
            int uDivCnt, int vDivCnt,
            bool uedge  = true, bool vedge   = true,
            bool uclose = false, bool vclose = false)
        {
            Nurbs = new NurbsSurface(deg, ucnt, vcnt, uDivCnt, vDivCnt, uedge, vedge, uclose, vclose);

            Nurbs.CtrlPoints = vl;

            mPointList = vl;

            if (ctrlOrder == null)
            {
                Nurbs.SetupDefaultCtrlOrder();
            }
            else
            {
                Nurbs.CtrlOrder = ctrlOrder;
            }

            NurbsPointList = new VertexList(Nurbs.UOutCnt * Nurbs.VOutCnt);
        }
Пример #17
0
        /// <summary>
        /// The VerbTest function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A VerbTestOutputs instance containing computed results and the model with any new elements.</returns>
        public static VerbTestOutputs Execute(Dictionary <string, Model> inputModels, VerbTestInputs input)
        {
            /// Your code here.
            var            output = new VerbTestOutputs();
            var            sphere = new SphericalSurface(input.SphereCenter.ToVPt(), input.SphereRadius);
            List <Vector3> pts    = new List <Vector3>();

            for (double u = 0; u < 1.0; u += 0.05)
            {
                for (double v = 0; v < 1.0; v += 0.05)
                {
                    var pt = sphere.point(u, v).ToVector3();
                    pts.Add(pt);
                }
            }
            var mesh = sphere.tessellate(new AdaptiveRefinementOptions
            {
                minDivsU = 50,
                minDivsV = 50,
                refine   = false
            }).ToMesh();

            mesh.Material = new Material("White", Colors.White);
            output.Model.AddElement(new MeshElement(mesh, new Material("Shiny", Colors.Red, 0.9, 0.6)));
            output.Model.AddElement(new ModelPoints(pts, BuiltInMaterials.Black));

            var Random = new Random(5);
            var curves = new Array <object>();

            for (var u = 0; u < 4; u++)
            {
                var points  = new Array <object>();
                var ctrlPts = new List <Vector3>();
                for (var v = 0; v < 4; v++)
                {
                    var pt = new Vector3(u * input.Width / 4, v * input.Length / 4, Random.NextDouble() * input.Height);
                    points.push(pt.ToVPt());
                    ctrlPts.Add(pt);
                }
                // output.Model.AddElement(new ModelCurve(new Polyline(ctrlPts)));
                var curve = NurbsCurve.byPoints(points, new haxe.lang.Null <int>(3, true));
                curves.push(curve);
            }
            Console.WriteLine("Done making curves");
            var nurbsSrf = NurbsSurface.byLoftingCurves(curves, new haxe.lang.Null <int>(3, true));

            Console.WriteLine("Done making srf");

            var srfMesh = nurbsSrf.tessellate(new AdaptiveRefinementOptions
            {
                minDivsU = 50,
                minDivsV = 50,
                refine   = false
            }).ToMesh();

            Console.WriteLine("Done making mesh");

            output.Model.AddElement(new MeshElement(srfMesh, new Material("Shiny Blue", Colors.Blue, 0.9, 0.6, null, false, true)));
            return(output);
        }
Пример #18
0
        public static Brep GetBrepFromElement(IMesh mesh, int eKey)
        {
            Brep     brep = new Brep();
            IElement e    = mesh.GetElementWithKey(eKey);

            if (e.TopologicDimension == 2)
            {
                Surface   f;
                Point3d[] pts = new Point3d[e.VerticesCount];
                for (int i = 0; i < e.VerticesCount; i++)
                {
                    pts[i] = mesh.GetVertexWithKey(e.Vertices[i]).RhinoPoint;
                }

                if (pts.Length == 4)
                {
                    f = NurbsSurface.CreateFromCorners(pts[0], pts[1], pts[2], pts[3]);
                }
                else if (pts.Length == 3)
                {
                    f = NurbsSurface.CreateFromCorners(pts[0], pts[1], pts[2]);
                }
                else
                {
                    f = Brep.CreateEdgeSurface(new PolylineCurve[] { new PolylineCurve(pts), new PolylineCurve(new Point3d[] { pts[pts.Length - 1], pts[0] }) }).Surfaces[0];
                }
                brep = f.ToBrep();
            }
            else
            {
                Brep[] faces = new Brep[e.HalfFacetsCount];

                for (int i = 1; i <= e.HalfFacetsCount; i++)
                {
                    int[] hf;
                    e.GetHalfFacetWithPrincipalNodesOnly(i, out hf);

                    Point3d[] pts = new Point3d[hf.Length];

                    for (int j = 0; j < hf.Length; j++)
                    {
                        pts[j] = mesh.GetVertexWithKey(hf[j]).RhinoPoint;
                    }

                    if (pts.Length == 4)
                    {
                        faces[i - 1] = Brep.CreateFromCornerPoints(pts[0], pts[1], pts[2], pts[3], RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                    }
                    else
                    {
                        faces[i - 1] = Brep.CreateFromCornerPoints(pts[0], pts[1], pts[2], RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                    }
                }

                brep = Brep.JoinBreps(faces, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)[0];
            }

            return(brep);
        }
Пример #19
0
        //CONSTRUCTOR
        public Design(RadicalComponent component)
        {
            //Access the component
            this.MyComponent = component;

            this.Variables   = new List <IVariable>();
            this.Geometries  = new List <IDesignGeometry>();
            this.Constraints = new List <Constraint>();

            // ADD VARIABLES
            //Sliders
            foreach (IGH_Param param in MyComponent.Params.Input[2].Sources)
            {
                SliderVariable s = new SliderVariable(param);
                if (s.CurrentValue == 0)
                {
                    if (s.Max >= 0.001)
                    {
                        s.UpdateValue(0.001);
                    }
                    else
                    {
                        s.UpdateValue(-0.001);
                    }
                }
                this.Variables.Add(new SliderVariable(param));
            }
            Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false, Grasshopper.Kernel.GH_SolutionMode.Silent);

            //Surfaces
            for (int i = 0; i < MyComponent.Params.Input[3].Sources.Count; i++)
            {
                IGH_Param    param = MyComponent.Params.Input[3].Sources[i];
                NurbsSurface surf  = MyComponent.SrfVariables[i];
                Geometries.Add(new DesignSurface(param, surf));
            }
            //Curves
            for (int i = 0; i < MyComponent.Params.Input[4].Sources.Count; i++)
            {
                IGH_Param  param = MyComponent.Params.Input[4].Sources[i];
                NurbsCurve curv  = MyComponent.CrvVariables[i];
                this.Geometries.Add(new DesignCurve(param, curv));
            }

            // Add geometries to variables list
            // not the cleanest way to do it, review code structure
            if (Geometries.Any())
            {
                this.Variables.AddRange(Geometries.Select(x => x.Variables).SelectMany(x => x).ToList());
            }

            // ADD CONSTRAINTS
            for (int i = 0; i < component.Constraints.Count; i++)
            {
                this.Constraints.Add(new Constraint(MyComponent, Constraint.ConstraintType.morethan, i));
            }

            MyComponent.numVars = this.Variables.Where(var => var.IsActive).Count();
        }
Пример #20
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static List <int> UVCount(this NurbsSurface surf)
        {
            List <int> degrees = surf.Degrees();

            return(new List <int> {
                surf.UKnots.Count - degrees[0] + 1, surf.VKnots.Count - degrees[1] + 1
            });
        }
Пример #21
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static Plane PlaneAtParameter(this NurbsSurface surface, double u, double v, double tolerance = Tolerance.Distance)
        {
            var vectors = TangentAtParameter(surface, u, v, tolerance);

            return(Create.Plane(
                       PointAtParameter(surface, u, v),
                       vectors.Item1.CrossProduct(vectors.Item2)));
        }
Пример #22
0
        public void Returns_True_If_Surface_Is_Close()
        {
            // Act
            NurbsSurface surface = NurbsSurface.FromLoft(NurbsCurveCollection.ClosedCurves(), LoftType.Loose);

            // Assert
            surface.IsClosed(SurfaceDirection.V).Should().BeTrue();
        }
Пример #23
0
        protected NurbsSurface GetNurbsSurface3D(JObject data)
        {
            var degreeU    = data["degree_u"].As <int>();
            var degreeV    = data["degree_v"].As <int>();
            var nbPolesU   = data["nb_poles_u"].As <int>();
            var nbPolesV   = data["nb_poles_v"].As <int>();
            var knotsU     = data["knots_u"].AsList <double>();
            var knotsV     = data["knots_v"].AsList <double>();
            var poles      = data["poles"].AsListOfPoint3d();
            var isRational = data.ContainsKey("weights");

            var nurbs = NurbsSurface.Create(3, isRational, degreeU + 1, degreeV + 1, nbPolesU, nbPolesV);

            for (int i = 0; i < knotsU.Count; i++)
            {
                nurbs.KnotsU[i] = knotsU[i];
            }

            for (int i = 0; i < knotsV.Count; i++)
            {
                nurbs.KnotsV[i] = knotsV[i];
            }

            if (isRational)
            {
                var weights = data["weights"].AsList <double>();

                for (int i = 0; i < weights.Count; i++)
                {
                    var u = i / nbPolesV;
                    var v = i % nbPolesV;

                    var weight = weights[i];
                    var pole   = poles[i] * weight;

                    nurbs.Points.SetPoint(u, v, pole[0], pole[1], pole[2], weight);
                }
            }
            else
            {
                for (int i = 0; i < poles.Count; i++)
                {
                    var u = i / nbPolesV;
                    var v = i % nbPolesV;

                    var pole = poles[i];

                    nurbs.Points.SetPoint(u, v, pole[0], pole[1], pole[2]);
                }
            }

            if (!nurbs.IsValidWithLog(out var log))
            {
                throw new Exception($"Invalid NurbsSurface: {log}");
            }

            return(nurbs);
        }
Пример #24
0
        public static NurbsSurface ToRhinoSurface(DB.HermiteFace face, double relativeTolerance)
        {
            NurbsSurface nurbsSurface = default;

            try
            {
#if REVIT_2021
                using (var surface = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface()))
                    nurbsSurface = ToRhino(surface, face.GetBoundingBox());
#else
                using (var surface = DB.ExportUtils.GetNurbsSurfaceDataForFace(face))
                    nurbsSurface = ToRhino(surface, face.GetBoundingBox());
#endif
            }
            catch (Autodesk.Revit.Exceptions.ApplicationException) { }

            if (nurbsSurface is null)
            {
                using (var paramsU = face.get_Params(0))
                    using (var paramsV = face.get_Params(1))
                    {
                        nurbsSurface = FromHermiteSurface
                                       (
                            paramsU,
                            paramsV,
                            face.Points,
                            face.MixedDerivs,
                            face.get_Tangents(0),
                            face.get_Tangents(1)
                                       );
                    }
            }

            using (var bboxUV = face.GetBoundingBox())
            {
                nurbsSurface = nurbsSurface.Trim
                               (
                    new Interval(bboxUV.Min.U, bboxUV.Max.U),
                    new Interval(bboxUV.Min.V, bboxUV.Max.V)
                               ) as NurbsSurface;
            }

            if (nurbsSurface is object)
            {
                double ctol = relativeTolerance * Revit.ShortCurveTolerance * 5.0;
                if (ctol != 0.0)
                {
                    // Extend using smooth way avoids creating C2 discontinuities
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.West, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.East, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.South, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.North, ctol, true) as NurbsSurface ?? nurbsSurface;
                }
            }

            return(nurbsSurface);
        }
Пример #25
0
        public void Lofted_Surface_Throws_An_Exception_If_The_Curves_Are_Null()
        {
            // Act
            Func <NurbsSurface> func = () => NurbsSurface.FromLoft(null);

            // Assert
            func.Should().Throw <Exception>()
            .WithMessage("An invalid number of curves to perform the loft.");
        }
Пример #26
0
        public void Returns_True_If_Two_Surfaces_Are_Equals()
        {
            // Arrange
            NurbsSurface surface0 = NurbsSurfaceCollection.SurfaceFromPoints();
            NurbsSurface surface1 = NurbsSurfaceCollection.SurfaceFromPoints();

            // Assert
            surface0.Equals(surface1).Should().BeTrue();
        }
        ///////////
        //methods//
        ///////////

        //一番目のSurfaceを作る
        public void MakeStartSrf()
        {
            a = new Point3d(0, 0, 0);
            b = new Point3d(100, 0, 0);
            c = new Point3d(100, 200, 0);
            d = new Point3d(0, 200, 0);

            srf = NurbsSurface.CreateFromCorners(a, b, c, d);
        }
Пример #28
0
    NurbsSurface Srf3Pt(Point3d A, Point3d B, Point3d C)
    {
        Point3d D = new Point3d(0, 0, 0);

        D = Point3d.Add(D, (B + C - A));
        NurbsSurface srf = NurbsSurface.CreateFromCorners(A, B, D, C);

        return(srf);
    }
Пример #29
0
        private void AppendSurfaceGeometry(StringBuilder sb, NurbsSurface ns)
        {
            if (ns == null)
            {
                return;
            }

            double ulength;
            double vlength;

            // reparametrize to real world length to minimize distortion in the map from parameter space to 3D
            if (ns.GetSurfaceSize(out ulength, out vlength))
            {
                ns.SetDomain(0, new Interval(0, ulength));
                ns.SetDomain(1, new Interval(1, vlength));
            }

            // write knot vectors
            bool first = true;

            foreach (var ku in ns.KnotsU)
            {
                sb.AppendFormat(" SARN S {0:F8}", ku);
                if (first)
                {
                    sb.AppendFormat(" DEGS {0}", ns.OrderU - 1);
                    first = false;
                }
                sb.AppendLine();
            }

            first = true;
            foreach (var kv in ns.KnotsV)
            {
                sb.AppendFormat(" SARN T {0:F8}", kv);
                if (first)
                {
                    sb.AppendFormat(" DEGT {0}", ns.OrderV - 1);
                    first = false;
                }
                sb.AppendLine();
            }

            // write control points
            for (int i = 0; i < ns.Points.CountV; ++i)
            {
                for (int j = 0; j < ns.Points.CountU; ++j)
                {
                    var    cpt = ns.Points.GetControlPoint(j, i);
                    double w   = cpt.Weight;

                    sb.AppendFormat(" SARP NURB {0} {1}", j + 1, i + 1);
                    sb.AppendFormat(" X {0:F8} {1:F8} {2:F8} {3:F8}", cpt.X / w, cpt.Y / w, cpt.Z / w, w);
                    sb.AppendLine();
                }
            }
        }
 public DesignSurface(IGH_Param param, NurbsSurface surf, double min = -1.0, double max = 1.0)
 {
     this.Parameter = param;
     this.Parameter.RemoveAllSources();
     this.Surface         = surf;
     this.OriginalSurface = new NurbsSurface(surf);
     BuildVariables(min, max);
     List <GeoVariable> myVars = Variables;
 }
Пример #31
0
    internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobject_index)
    {
      if (IntPtr.Zero == pGeometry)
        return null;

      int type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry);
      if (type < 0)
        return null;
      GeometryBase rc = null;

      switch (type)
      {
        case idxON_Curve: //1
          rc = new Curve(pGeometry, parent, subobject_index);
          break;
        case idxON_NurbsCurve: //2
          rc = new NurbsCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_PolyCurve: // 3
          rc = new PolyCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_PolylineCurve: //4
          rc = new PolylineCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_ArcCurve: //5
          rc = new ArcCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_LineCurve: //6
          rc = new LineCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_Mesh: //7
          rc = new Mesh(pGeometry, parent);
          break;
        case idxON_Point: //8
          rc = new Point(pGeometry, parent);
          break;
        case idxON_TextDot: //9
          rc = new TextDot(pGeometry, parent);
          break;
        case idxON_Surface: //10
          rc = new Surface(pGeometry, parent);
          break;
        case idxON_Brep: //11
          rc = new Brep(pGeometry, parent);
          break;
        case idxON_NurbsSurface: //12
          rc = new NurbsSurface(pGeometry, parent);
          break;
        case idxON_RevSurface: //13
          rc = new RevSurface(pGeometry, parent);
          break;
        case idxON_PlaneSurface: //14
          rc = new PlaneSurface(pGeometry, parent);
          break;
        case idxON_ClippingPlaneSurface: //15
          rc = new ClippingPlaneSurface(pGeometry, parent);
          break;
        case idxON_Annotation2: // 16
          rc = new AnnotationBase(pGeometry, parent);
          break;
        case idxON_Hatch: // 17
          rc = new Hatch(pGeometry, parent);
          break;
        case idxON_TextEntity2: //18
          rc = new TextEntity(pGeometry, parent);
          break;
        case idxON_SumSurface: //19
          rc = new SumSurface(pGeometry, parent);
          break;
        case idxON_BrepFace: //20
          {
            int faceindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex);
            if (pBrep != IntPtr.Zero && faceindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Faces[faceindex];
            }
          }
          break;
        case idxON_BrepEdge: // 21
          {
            int edgeindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex);
            if (pBrep != IntPtr.Zero && edgeindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Edges[edgeindex];
            }
          }
          break;
        case idxON_InstanceDefinition: // 22
          rc = new InstanceDefinitionGeometry(pGeometry, parent);
          break;
        case idxON_InstanceReference: // 23
          rc = new InstanceReferenceGeometry(pGeometry, parent);
          break;
#if USING_V5_SDK
        case idxON_Extrusion: //24
          rc = new Extrusion(pGeometry, parent);
          break;
#endif
        case idxON_LinearDimension2: //25
          rc = new LinearDimension(pGeometry, parent);
          break;
        case idxON_PointCloud: // 26
          rc = new PointCloud(pGeometry, parent);
          break;
        case idxON_DetailView: // 27
          rc = new DetailView(pGeometry, parent);
          break;
        case idxON_AngularDimension2: // 28
          rc = new AngularDimension(pGeometry, parent);
          break;
        case idxON_RadialDimension2: // 29
          rc = new RadialDimension(pGeometry, parent);
          break;
        case idxON_Leader: // 30
          rc = new Leader(pGeometry, parent);
          break;
        case idxON_OrdinateDimension2: // 31
          rc = new OrdinateDimension(pGeometry, parent);
          break;
        case idxON_Light: //32
          rc = new Light(pGeometry, parent);
          break;
        case idxON_PointGrid: //33
          rc = new Point3dGrid(pGeometry, parent);
          break;
        case idxON_MorphControl: //34
          rc = new MorphControl(pGeometry, parent);
          break;
        case idxON_BrepLoop: //35
          {
            int loopindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex);
            if (pBrep != IntPtr.Zero && loopindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Loops[loopindex];
            }
          }
          break;
        case idxON_BrepTrim: // 36
          {
            int trimindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex);
            if (pBrep != IntPtr.Zero && trimindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Trims[trimindex];
            }
          }
          break;
        default:
          rc = new UnknownGeometry(pGeometry, parent, subobject_index);
          break;
      }

      return rc;
    }
Пример #32
0
        public string Mesh2Nurbs(Mesh mesh, out  NurbsSurface s)
        {
            Rhino.Geometry.Collections.MeshTopologyEdgeList el = mesh.TopologyEdges;
            Rhino.Geometry.Collections.MeshTopologyVertexList vs = mesh.TopologyVertices;
            string str = "";
            List<int> firstLoop1;
            str += FirstEdge(mesh, out firstLoop1);
            double column = (double)vs.Count / (double)firstLoop1.Count;
            int Column = (int)column;
            if (column - Column != 0) str += "Points Count error,Please confirm the topo to be quad style";
            int[] energy = new int[vs.Count];
            List<int> indexPt = new List<int>();
            indexPt.AddRange(firstLoop1);
            for (int i = 0; i < firstLoop1.Count; i++) { energy[firstLoop1[i]] = 1; }
            for (int i = 0; i < Column - 1; i++)
            {
                bool sign = true;
                for (int j = 0; j < firstLoop1.Count; j++)
                {
                    int[] index = vs.ConnectedTopologyVertices(firstLoop1[j]);
                    for (int k = 0; k < index.Length; k++)
                    {
                        //Print("j:" + j.ToString() + " k:" + k.ToString() + " energy: " + energy[index[k]].ToString());////////
                        energy[index[k]]++;
                    }
                }
                //Print("///");
                for (int j = 0; j < firstLoop1.Count; j++)
                {

                    int[] index = vs.ConnectedTopologyVertices(firstLoop1[j]);
                    for (int k = 0; k < index.Length; k++)
                    {
                        // Print("j:" + j.ToString() + " k:" + k.ToString() + " energy: " + energy[index[k]].ToString());////////
                        if (energy[index[k]] == 1)
                        {
                            firstLoop1[j] = index[k]; sign = false; break;
                        }
                    }
                }
                if (sign) { str += " Loop false,Not quad topo Or To the end"; }
                else { indexPt.AddRange(firstLoop1); }
            }
            List<Point3d> output1 = new List<Point3d>();
            for (int i = 0; i < indexPt.Count; i++)
            {
                output1.Add(vs[indexPt[i]]);
            }
            s = NurbsSurface.CreateFromPoints(output1, Column, firstLoop1.Count, 3, 3);
            return str;
        }
Пример #33
0
 public void init(NurbsSurface S,double scaleU,double scaleV)
 {
     /*Point3d P;
     Vector3d[] V;
     S.Evaluate(u, v, 1, out P, out V);
     x = P.X;
     y = P.Y;
     gi2[0][0] = V[0].X * scaleU;
     gi2[0][1] = V[0].Y * scaleU;
     gi2[0][2] = 0;
     gi2[1][0] = V[1].X * scaleV;
     gi2[1][1] = V[1].Y * scaleV;
     gi2[1][2] = 0;
     gij2[0, 0] = gi2[0][0] * gi2[0][0] + gi2[0][1] * gi2[0][1];
     gij2[1, 0] = gi2[1][0] * gi2[0][0] + gi2[1][1] * gi2[0][1];
     gij2[0, 1] = gi2[0][0] * gi2[1][0] + gi2[0][1] * gi2[1][1];
     gij2[1, 1] = gi2[1][0] * gi2[1][0] + gi2[1][1] * gi2[1][1];
     double det = gij2[0, 0] * gij2[1, 1] - gij2[0, 1] * gij2[1, 0];
     Gij2[0, 0] = gij2[1, 1] / det;
     Gij2[1, 1] = gij2[0, 0] / det;
     Gij2[0, 1] = -gij2[0, 1] / det;
     Gij2[1, 0] = -gij2[1, 0] / det;
     Gi2[0][0]=Gij2[0,0]*gi2[0][0]+Gij2[1,0]*gi2[1][0];
     Gi2[0][1]=Gij2[0,0]*gi2[0][1]+Gij2[1,0]*gi2[1][1];
     Gi2[0][2]=0;
     Gi2[1][0]=Gij2[0,1]*gi2[0][0]+Gij2[1,1]*gi2[1][0];
     Gi2[1][1]=Gij2[0,1]*gi2[0][1]+Gij2[1,1]*gi2[1][1];
     Gi2[1][2]=0;
     S.Evaluate(u, v, 2, out P, out V);
     second2[0, 0][0] = V[2][0] * scaleU * scaleU;
     second2[0, 0][1] = V[2][1] * scaleU * scaleU;
     second2[0, 0][2] = 0;
     second2[1, 1][0] = V[4][0] * scaleV * scaleV;
     second2[1, 1][1] = V[4][1] * scaleV * scaleV;
     second2[1, 1][2] = 0;
     second2[0, 1][0] = V[3][0] * scaleU * scaleV;
     second2[0, 1][1] = V[3][1] * scaleU * scaleV;
     second2[0, 1][2] = 0;
     second2[1, 0][0] = V[3][0] * scaleV * scaleU;
     second2[1, 0][1] = V[3][1] * scaleV * scaleU;
     second2[1, 0][2] = 0;
     Gammaijk2[0, 0, 0] = second2[0, 0][0] * Gi2[0][0] + second2[0, 0][1] * Gi2[0][1];
     Gammaijk2[0, 0, 1] = second2[0, 0][0] * Gi2[1][0] + second2[0, 0][1] * Gi2[1][1];
     Gammaijk2[0, 1, 0] = second2[0, 1][0] * Gi2[0][0] + second2[0, 1][1] * Gi2[0][1];
     Gammaijk2[0, 1, 1] = second2[0, 1][0] * Gi2[1][0] + second2[0, 1][1] * Gi2[1][1];
     Gammaijk2[1, 0, 0] = second2[1, 0][0] * Gi2[0][0] + second2[1, 0][1] * Gi2[0][1];
     Gammaijk2[1, 0, 1] = second2[1, 0][0] * Gi2[1][0] + second2[1, 0][1] * Gi2[1][1];
     Gammaijk2[1, 1, 0] = second2[1, 1][0] * Gi2[0][0] + second2[1, 1][1] * Gi2[0][1];
     Gammaijk2[1, 1, 1] = second2[1, 1][0] * Gi2[1][0] + second2[1, 1][1] * Gi2[1][1];*/
 }
        public BezierPatchForeignFace(ForeignShell parent, ControlPoint[,] vertices)
            : base(parent)
        {
            Debug.Assert(vertices != null);
            this.vertices = vertices;

            NurbsData dataU = new NurbsData(4, false, false, new Knot[] { new Knot(0, 4), new Knot(1, 4) });
            NurbsData dataV = new NurbsData(4, false, false, new Knot[] { new Knot(0, 4), new Knot(1, 4) });

            surface = NurbsSurface.Create(dataU, dataV, vertices);
        }