コード例 #1
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.NurbSpline crv)
        {
            var convert = NurbsCurve.ByControlPointsWeightsKnots(crv.CtrlPoints.Select(x => x.ToPoint()).ToArray(),
                                                                 crv.Weights.Cast <double>().ToArray(), crv.Knots.Cast <double>().ToArray(), crv.Degree);

            if (!crv.IsBound)
            {
                return(convert);
            }

            // bound the curve parametric range

            // we first get the full parametric domain from the knots
            // note that some knots be negative and the domain may appear reversed
            var parms = crv.Knots.Cast <double>().ToList();
            var fsp   = parms.First();
            var fep   = parms.Last();

            // obtain the full domain
            var fd = Math.Abs(fsp - fep);

            // these are the start and end parameters of the bound curve
            var sp = crv.get_EndParameter(0);
            var ep = crv.get_EndParameter(1);

            // get the normalized parameters for trim
            var nsp = Math.Abs(fsp - sp) / fd;
            var nep = Math.Abs(fsp - ep) / fd;

            return(convert.ParameterTrim(nsp, nep));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public static NurbsCurve ToRhino(DB.NurbSpline nurb)
        {
            var controlPoints = nurb.CtrlPoints;
            var n             = new NurbsCurve(3, nurb.isRational, nurb.Degree + 1, controlPoints.Count);

            if (nurb.isRational)
            {
                using (var Weights = nurb.Weights)
                {
                    var weights = Weights.Cast <double>().ToArray();
                    int index   = 0;
                    foreach (var pt in controlPoints)
                    {
                        var w = weights[index];
                        n.Points.SetPoint(index++, pt.X * w, pt.Y * w, pt.Z * w, w);
                    }
                }
            }
            else
            {
                int index = 0;
                foreach (var pt in controlPoints)
                {
                    n.Points.SetPoint(index++, pt.X, pt.Y, pt.Z);
                }
            }

            using (var Knots = nurb.Knots)
            {
                int index = 0;
                foreach (var w in Knots.Cast <double>().Skip(1).Take(n.Knots.Count))
                {
                    n.Knots[index++] = w;
                }
            }

            return(n);
        }
コード例 #5
0
 public static Curve ToCurve(this DB.NurbSpline value)
 {
     var rhino = RawDecoder.ToRhino(value); UnitConverter.Scale(rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
コード例 #6
0
ファイル: CurveUtils.cs プロジェクト: hipigod/Dynamo
 private static bool IsLineLikeInternal(Autodesk.Revit.DB.NurbSpline crv)
 {
     return(IsLineLikeInternal(crv.CtrlPoints));
 }
コード例 #7
0
 public static NurbsCurve ToRhino(this DB.NurbSpline nurb) => RawDecoder.ToRhino(nurb);