public NurbsCurve NurbsToNative(Curve curve) { var ptsList = curve.GetPoints().Select(o => PointToNative(o).Location).ToList(); var nurbsCurve = NurbsCurve.Create(false, curve.degree, ptsList); for (int j = 0; j < nurbsCurve.Points.Count; j++) { nurbsCurve.Points.SetPoint(j, ptsList[j], curve.weights[j]); } // check knot multiplicity to match Rhino's standard of (# control points + degree - 1) // skip extra knots at start & end if knot multiplicity is (# control points + degree + 1) int extraKnots = curve.knots.Count - nurbsCurve.Knots.Count; for (int j = 0; j < nurbsCurve.Knots.Count; j++) { if (extraKnots == 2) { nurbsCurve.Knots[j] = curve.knots[j + 1]; } else { nurbsCurve.Knots[j] = curve.knots[j]; } } nurbsCurve.Domain = IntervalToNative(curve.domain ?? new Interval(0, 1)); return(nurbsCurve); }
public Curve NurbsToSpeckle(DB.NurbSpline revitCurve, string units = null) { var points = new List <double>(); foreach (var p in revitCurve.CtrlPoints) { var point = PointToSpeckle(p, units); points.AddRange(new List <double> { point.x, point.y, point.z }); } Curve speckleCurve = new Curve(); speckleCurve.weights = revitCurve.Weights.Cast <double>().ToList(); speckleCurve.points = points; speckleCurve.knots = revitCurve.Knots.Cast <double>().ToList();; speckleCurve.degree = revitCurve.Degree; //speckleCurve.periodic = revitCurve.Period; speckleCurve.rational = revitCurve.isRational; speckleCurve.closed = RevitVersionHelper.IsCurveClosed(revitCurve); speckleCurve.units = units ?? ModelUnits; speckleCurve.domain = new Interval(revitCurve.GetEndParameter(0), revitCurve.GetEndParameter(1)); speckleCurve.length = ScaleToSpeckle(revitCurve.Length); var coords = revitCurve.Tessellate().SelectMany(xyz => PointToSpeckle(xyz, units).ToList()).ToList(); speckleCurve.displayValue = new Polyline(coords, units); return(speckleCurve); }
public Curve NurbsToSpeckle(DB.NurbSpline revitCurve, string units = null) { var points = new List <double>(); foreach (var p in revitCurve.CtrlPoints) { var point = PointToSpeckle(p, units); points.AddRange(new List <double> { point.x, point.y, point.z }); } Curve speckleCurve = new Curve(); speckleCurve.weights = revitCurve.Weights.Cast <double>().ToList(); speckleCurve.points = points; speckleCurve.knots = revitCurve.Knots.Cast <double>().ToList();; speckleCurve.degree = revitCurve.Degree; //speckleCurve.periodic = revitCurve.Period; speckleCurve.rational = revitCurve.isRational; speckleCurve.closed = RevitVersionHelper.IsCurveClosed(revitCurve); speckleCurve.units = units ?? ModelUnits; //speckleCurve.domain = new Interval(revitCurve.StartParameter(), revitCurve.EndParameter()); speckleCurve.length = revitCurve.Length; return(speckleCurve); }
public NurbsCurve CurveToNative(Curve curve) { var points = ArrayToPointList(curve.points, curve.units); var dsKnots = curve.knots; NurbsCurve nurbsCurve = NurbsCurve.ByControlPointsWeightsKnots( points, curve.weights.ToArray(), dsKnots.ToArray(), curve.degree ); return(nurbsCurve.SetDynamoProperties <NurbsCurve>(GetDynamicMembersFromBase(curve))); }
public Curve NurbsToSpeckle(NurbsCurve curve, string units = null) { var u = units ?? ModelUnits; var tolerance = 0.0; curve.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out var poly); Polyline displayValue; if (poly.Count == 2) { displayValue = new Polyline(); displayValue.value = new List <double> { poly[0].X, poly[0].Y, poly[0].Z, poly[1].X, poly[1].Y, poly[1].Z }; } else { displayValue = PolylineToSpeckle(poly, u) as Polyline; } var myCurve = new Curve(displayValue, u); var nurbsCurve = curve.ToNurbsCurve(); // increase knot multiplicity to (# control points + degree + 1) // add extra knots at start & end because Rhino's knot multiplicity standard is (# control points + degree - 1) var knots = nurbsCurve.Knots.ToList(); knots.Insert(0, knots[0]); knots.Insert(knots.Count - 1, knots[knots.Count - 1]); // Hack: Rebuild curve to prevent interior knot multiplicities. //var max = Math.Min(nurbsCurve.Points.Count-1, 3); //nurbsCurve = nurbsCurve.Rebuild(nurbsCurve.Points.Count, max, true); myCurve.weights = nurbsCurve.Points.Select(ctp => ctp.Weight).ToList(); myCurve.points = PointsToFlatArray(nurbsCurve.Points.Select(ctp => ctp.Location)).ToList(); myCurve.knots = knots; myCurve.degree = nurbsCurve.Degree; myCurve.periodic = nurbsCurve.IsPeriodic; myCurve.rational = nurbsCurve.IsRational; myCurve.domain = IntervalToSpeckle(nurbsCurve.Domain); myCurve.closed = nurbsCurve.IsClosed; myCurve.length = nurbsCurve.GetLength(); myCurve.bbox = BoxToSpeckle(new RH.Box(nurbsCurve.GetBoundingBox(true)), u); return(myCurve); }
public DB.Curve CurveToNative(Curve speckleCurve) { var pts = new List <XYZ>(); for (int i = 0; i < speckleCurve.points.Count; i += 3) { //use PointToNative for conversion as that takes into account the Project Base Point var point = new Point(speckleCurve.points[i], speckleCurve.points[i + 1], speckleCurve.points[i + 2], speckleCurve.units); pts.Add(PointToNative(point)); } try { if (speckleCurve.knots != null && speckleCurve.weights != null && speckleCurve.knots.Any() && speckleCurve.weights.Any()) { var weights = speckleCurve.weights.GetRange(0, pts.Count); var speckleKnots = new List <double>(speckleCurve.knots); if (speckleKnots.Count != pts.Count + speckleCurve.degree + 1) { // Curve has rhino knots, repeat first and last. speckleKnots.Insert(0, speckleKnots[0]); speckleKnots.Add(speckleKnots[speckleKnots.Count - 1]); } //var knots = speckleKnots.GetRange(0, pts.Count + speckleCurve.degree + 1); var curve = NurbSpline.CreateCurve(speckleCurve.degree, speckleKnots, pts, weights); return(curve); } else { var weights = speckleCurve.weights.GetRange(0, pts.Count); var curve = NurbSpline.CreateCurve(pts, weights); return(curve); } } catch (Exception e) { if (e is Autodesk.Revit.Exceptions.ArgumentException) { throw e; // prob a closed, periodic curve } return(null); } }
public NurbsCurve NurbsToNative(Curve curve) { var ptsList = PointListToNative(curve.points, curve.units); var nurbsCurve = NurbsCurve.Create(false, curve.degree, ptsList); for (int j = 0; j < nurbsCurve.Points.Count; j++) { nurbsCurve.Points.SetPoint(j, ptsList[j], curve.weights[j]); } for (int j = 0; j < nurbsCurve.Knots.Count; j++) { nurbsCurve.Knots[j] = curve.knots[j]; } nurbsCurve.Domain = IntervalToNative(curve.domain ?? new Interval(0, 1)); return(nurbsCurve); }
public DB.Curve CurveToNative(Curve speckleCurve) { var pts = new List <XYZ>(); for (int i = 0; i < speckleCurve.points.Count; i += 3) { pts.Add(new XYZ( ScaleToNative(speckleCurve.points[i], speckleCurve.units), ScaleToNative(speckleCurve.points[i + 1], speckleCurve.units), ScaleToNative(speckleCurve.points[i + 2], speckleCurve.units))); } try { if (speckleCurve.knots != null && speckleCurve.weights != null && speckleCurve.knots.Any() && speckleCurve.weights.Any()) { var weights = speckleCurve.weights.GetRange(0, pts.Count); var speckleKnots = new List <double>(speckleCurve.knots); if (speckleKnots.Count != pts.Count + speckleCurve.degree + 1) { // Curve has rhino knots, repeat first and last. speckleKnots.Insert(0, speckleKnots[0]); speckleKnots.Add(speckleKnots[speckleKnots.Count - 1]); } //var knots = speckleKnots.GetRange(0, pts.Count + speckleCurve.degree + 1); var curve = NurbSpline.CreateCurve(speckleCurve.degree, speckleKnots, pts, weights); return(curve); } else { var weights = speckleCurve.weights.GetRange(0, pts.Count); var curve = NurbSpline.CreateCurve(pts, weights); return(curve); } } catch (Exception e) { return(null); } }
public Curve NurbsToSpeckle(NurbsCurve curve) { var tolerance = 0.0; curve.ToPolyline(0, 1, 0, 0, 0, 0.1, 0, 0, true).TryGetPolyline(out var poly); Polyline displayValue; if (poly.Count == 2) { displayValue = new Polyline(); displayValue.value = new List <double> { poly[0].X, poly[0].Y, poly[0].Z, poly[1].X, poly[1].Y, poly[1].Z }; } else { displayValue = PolylineToSpeckle(poly) as Polyline; } var myCurve = new Curve(displayValue, ModelUnits); var nurbsCurve = curve.ToNurbsCurve(); // Hack: Rebuild curve to prevent interior knot multiplicities. //var max = Math.Min(nurbsCurve.Points.Count-1, 3); //nurbsCurve = nurbsCurve.Rebuild(nurbsCurve.Points.Count, max, true); myCurve.weights = nurbsCurve.Points.Select(ctp => ctp.Weight).ToList(); myCurve.points = PointsToFlatArray(nurbsCurve.Points.Select(ctp => ctp.Location)).ToList(); myCurve.knots = nurbsCurve.Knots.ToList(); myCurve.degree = nurbsCurve.Degree; myCurve.periodic = nurbsCurve.IsPeriodic; myCurve.rational = nurbsCurve.IsRational; myCurve.domain = IntervalToSpeckle(nurbsCurve.Domain); myCurve.closed = nurbsCurve.IsClosed; return(myCurve); }
public Base CurveToSpeckle(NurbsCurve curve, string units = null) { var u = units ?? ModelUnits; Base speckleCurve; if (curve.IsLinear()) { using (DS.Line line = curve.GetAsLine()) { speckleCurve = LineToSpeckle(line, u); } } else if (curve.IsArc()) { using (DS.Arc arc = curve.GetAsArc()) { speckleCurve = ArcToSpeckle(arc, u); } } else if (curve.IsCircle()) { using (DS.Circle circle = curve.GetAsCircle()) { speckleCurve = CircleToSpeckle(circle, u); } } else if (curve.IsEllipse()) { using (DS.Ellipse ellipse = curve.GetAsEllipse()) { speckleCurve = EllipseToSpeckle(ellipse, u); } } else { // SpeckleCurve DisplayValue DS.Curve[] curves = curve.ApproximateWithArcAndLineSegments(); List <double> polylineCoordinates = curves.SelectMany(c => PointListToFlatArray(new DS.Point[2] { c.StartPoint, c.EndPoint })).ToList(); polylineCoordinates.AddRange(PointToArray(curves.Last().EndPoint)); curves.ForEach(c => c.Dispose()); Polyline displayValue = new Polyline(polylineCoordinates, u); List <double> dsKnots = curve.Knots().ToList(); dsKnots.RemoveAt(dsKnots.Count - 1); dsKnots.RemoveAt(0); Curve spkCurve = new Curve(displayValue, u); spkCurve.weights = curve.Weights().ToList(); spkCurve.points = PointListToFlatArray(curve.ControlPoints()).ToList(); spkCurve.knots = dsKnots; spkCurve.degree = curve.Degree; spkCurve.periodic = curve.IsPeriodic; spkCurve.rational = curve.IsRational; spkCurve.closed = curve.IsClosed; spkCurve.domain = new Interval(curve.StartParameter(), curve.EndParameter()); //spkCurve.Properties //spkCurve.GenerateHash(); spkCurve.length = curve.Length; spkCurve.bbox = BoxToSpeckle(curve.BoundingBox.ToCuboid(), u); speckleCurve = spkCurve; } CopyProperties(speckleCurve, curve); return(speckleCurve); }