public static NXOpen.Point3d[] ToHost(NurbsSurfacePointList list) { var count = list.CountU * list.CountV; var points = new NXOpen.Point3d[count]; int p = 0; foreach (var point in list) { var location = point.Location; points[p++] = new NXOpen.Point3d(location.X, location.Y, location.Z); } return(points); }
public static List <XYZ> ConvertRhinoControlPoints(NurbsSurfacePointList ctrlPoints, out List <double> weights) { List <XYZ> points = new List <XYZ>(); weights = new List <double>(); try { foreach (Rhino.Geometry.ControlPoint ctrlPoint in ctrlPoints) { points.Add(new XYZ(ctrlPoint.Location.X, ctrlPoint.Location.Y, ctrlPoint.Location.Z)); } } catch (Exception ex) { string message = ex.Message; } return(points); }
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)); }
public List <List <ControlPoint> > ControlPointsToSpeckle(NurbsSurfacePointList controlPoints, string units = null) { var points = new List <List <ControlPoint> >(); for (var i = 0; i < controlPoints.CountU; i++) { var row = new List <ControlPoint>(); for (var j = 0; j < controlPoints.CountV; j++) { var pt = controlPoints.GetControlPoint(i, j); var pos = pt.Location; row.Add(new ControlPoint(pos.X, pos.Y, pos.Z, pt.Weight, units ?? ModelUnits)); } points.Add(row); } return(points); }
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)); }
//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 }