private Curve ToCurve(Edge edge) { Object edgeGeometry = edge.BasicGeometry; Curve ghCurve = null; Topologic.Line line = edgeGeometry as Topologic.Line; if (line != null) { ghCurve = ToLine(edge); } Topologic.NurbsCurve nurbsCurve = edgeGeometry as Topologic.NurbsCurve; if (nurbsCurve != null) { ghCurve = ToNurbsCurve(nurbsCurve); } if (ghCurve == null) { //throw new Exception("This Edge creates an unrecognized Geometry."); return(null); } bool isReversed = edge.IsReversed; // IF ENABLED, WILL MAKE THE FACE VALID, BUT CELL INVALID //if (isReversed) //{ // bool successful = ghCurve.Reverse(); //} return(ghCurve); }
private Rhino.Geometry.Curve ToNurbsCurve(Topologic.NurbsCurve nurbsCurve) { // Based on https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_Geometry_NurbsCurve_Knots.htm bool isPeriodic = nurbsCurve.IsPeriodic; bool isRational = nurbsCurve.IsRational; int degree = nurbsCurve.Degree; List <Topologic.Vertex> controlVertices = nurbsCurve.ControlVertices; List <Point3d> ghControlPoints = new List <Point3d>(); Rhino.Geometry.NurbsCurve ghNurbsCurve = new Rhino.Geometry.NurbsCurve(3, isRational, degree + 1, controlVertices.Count); int i = 0; foreach (Topologic.Vertex controlVertex in controlVertices) { Point3d ghControlPoint = ToPoint(controlVertex); ghControlPoints.Add(ghControlPoint); ghNurbsCurve.Points.SetPoint(i, ghControlPoint); ++i; } List <double> knots = nurbsCurve.Knots; knots = knots.GetRange(1, knots.Count - 2); i = 0; foreach (double knot in knots) { ghNurbsCurve.Knots[i] = knot; ++i; } double t0 = nurbsCurve.FirstParameter; double t1 = nurbsCurve.LastParameter; Rhino.Geometry.Curve ghTrimmedNurbsCurve = ghNurbsCurve.Trim(t0, t1); String log = ""; if (ghTrimmedNurbsCurve.IsValidWithLog(out log)) { return(ghTrimmedNurbsCurve); } throw new Exception("A valid curve cannot be created from this Edge."); }