private Topologic.Edge ByNurbsCurve(Rhino.Geometry.NurbsCurve ghNurbsCurve) { int degree = ghNurbsCurve.Degree; bool isClosed = ghNurbsCurve.IsClosed; bool isPeriodic = ghNurbsCurve.IsPeriodic; bool isRational = ghNurbsCurve.IsRational; NurbsCurveKnotList ghKnots = ghNurbsCurve.Knots; List <double> knots = ghKnots.ToList(); // OCCT-compatible knots.Insert(0, knots[0]); knots.Add(knots.Last()); NurbsCurvePointList ghControlPoints = ghNurbsCurve.Points; List <Topologic.Vertex> controlPoints = new List <Topologic.Vertex>(); List <double> weights = new List <double>(); for (int i = 0; i < ghControlPoints.Count; ++i) { controlPoints.Add(ByPoint(ghControlPoints[i].Location)); weights.Add(ghControlPoints[i].Weight); } return(Topologic.Edge.ByNurbsParameters(controlPoints, weights, knots, isRational, isPeriodic, degree)); }
/// <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(NurbsCurveKnotList 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 && CurveKnotEqualTo(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 double[] ToDoubleArray(NurbsCurveKnotList list, int degree) { var count = list.Count; var knots = new double[count + 2]; var min = list[0]; var max = list[count - 1]; var mid = 0.5 * (min + max); var factor = 1.0 / (max - min); // normalized // End knot knots[count + 1] = /*(list[count - 1] - max) * factor +*/ 1.0; for (int k = count - 1; k >= count - degree; --k) { knots[k + 1] = /*(list[k] - max) * factor +*/ 1.0; } // Interior knots (in reverse order) int multiplicity = degree + 1; for (int k = count - degree - 1; k >= degree; --k) { double current = list[k] <= mid ? (list[k] - min) * factor + 0.0: (list[k] - max) * factor + 1.0; double next = knots[k + 2]; if (KnotAlmostEqualTo(next, current)) { multiplicity++; if (multiplicity > degree - 2) { current = KnotPrevNotEqual(next); } else { current = next; } } else { multiplicity = 1; } knots[k + 1] = current; } // Start knot for (int k = degree - 1; k >= 0; --k) { knots[k + 1] = /*(list[k] - min) * factor +*/ 0.0; } knots[0] = /*(list[0] - min) * factor +*/ 0.0; return(knots); }
public static double[] ToHost(NurbsCurveKnotList 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(NurbsCurveKnotList 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); }
static internal IList <double> ToHost(this NurbsCurveKnotList 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>()); }