/// <summary> /// Get knot multiplicity. /// </summary> /// <param name="knots"></param> /// <param name="index">Index of knot to query.</param> /// <param name="tolerance"></param> /// <param name="average"></param> /// <param name="strict"></param> /// <returns>The multiplicity (valence) of the knot.</returns> public static int KnotMultiplicity(NurbsSurfaceKnotList knots, int index, double tolerance, out double average, out bool strict) { var i = index; var value = knots[i++]; average = value; strict = true; while (i < knots.Count && SurfaceKnotEqualTo(value, knots[i], tolerance, out var s)) { strict &= s; average += knots[i]; i++; } var multiplicity = i - index; if (strict) { average = knots[index]; } else { average /= multiplicity; } return(multiplicity); }
static bool ToKinkedSpans(NurbsSurfaceKnotList knots, int degree, out List <double> kinks, double knotTolerance = KnotTolerance) { kinks = default; for (int k = degree; k < knots.Count - degree;) { var multiplicity = KnotMultiplicity(knots, k, knotTolerance, out var _, out var strict); if (multiplicity > degree) { if (kinks is null) { kinks = new List <double>(); } kinks.Add(knots[k]); } if (!strict) { var excess = multiplicity - knots.KnotMultiplicity(k); // Correct multiplicity in case more than degree knots are snapped here multiplicity = Math.Min(multiplicity, degree); // Insert new knot multiplicity knots.InsertKnot(knots[k], multiplicity); // Remove old knots that do not overlap knots[k] if (excess > 0) { knots.RemoveKnots(k + multiplicity, k + multiplicity + excess); } } k += multiplicity; } for (int k = degree; k < knots.Count - degree;) { var m = KnotMultiplicity(knots, k, knotTolerance, out var a, out var s); global::System.Diagnostics.Debug.Assert(m <= degree); k += m; } return(!(kinks is null)); }
public static double[] ToHost(NurbsSurfaceKnotList list) { var count = list.Count; var knots = new double[count + 2]; int j = 0, k = 0; while (j < count) { knots[++k] = list[j++]; } knots[0] = knots[1]; knots[count + 1] = knots[count]; return(knots); }
public static List <double> ConvertRhinoKnotList(NurbsSurfaceKnotList knotList) { List <double> knots = new List <double>(); try { foreach (double knot in knotList) { knots.Add(knot); } } catch (Exception ex) { string message = ex.Message; } return(knots); }
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)); }
static internal IList <double> ToHost(this NurbsSurfaceKnotList knotList) { var knotListCount = knotList.Count; if (knotListCount > 0) { var knots = new List <double>(knotListCount + 2); knots.Add(knotList[0]); foreach (var k in knotList) { knots.Add(k); } knots.Add(knotList[knotListCount - 1]); return(knots); } return(new List <double>()); }
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 IEnumerable<NXOpen.BRepBuilderEdgeGeometry> ToHost(BrepEdge edge) //{ // var edgeCurve = edge.EdgeCurve.Trim(edge.Domain); // if (edge.ProxyCurveIsReversed) // edgeCurve.Reverse(); // switch (edgeCurve) // { // case LineCurve line: // yield return NXOpen.BRepBuilderEdgeGeometry.Create(ToHost(line)); // yield break; // case ArcCurve arc: // yield return NXOpen.BRepBuilderEdgeGeometry.Create(ToHost(arc)); // yield break; // case NurbsCurve nurbs: // yield return NXOpen.BRepBuilderEdgeGeometry.Create(ToHost(nurbs)); // yield break; // default: // Debug.Fail($"{edgeCurve} is not supported as a Solid Edge"); // yield break; // } //} public static double[] ToHost(NurbsSurfaceKnotList list) { //list.CreateUniformKnots(1.0); var count = list.Count; var knots = new double[count + 2]; var minValue = list.First(); var maxValue = list.Last(); var range = maxValue - minValue; int j = 0, k = 0; while (j < count) { knots[++k] = (list[j++] - minValue) / range; } knots[0] = knots[1]; knots[count + 1] = knots[count]; return(knots); }
//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 }