Ejemplo n.º 1
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.HermiteSpline crv)
        {
            var convert = HermiteToNurbs.ConvertExact(crv);

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

            // bound the curve parametric range

            // we first get the full parametric domain from the parameters
            // note that some knots be negative and the domain may appear reversed
            var parms = crv.Parameters.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));
        }
Ejemplo n.º 2
0
        private static NurbsCurve ElevateBezierDegreeBy1(NurbsCurve crv)
        {
            var cpts = crv.ControlPoints();
            var n    = crv.Degree + 1;

            var cptsFinal = new List <Point>();

            cptsFinal.Add(cpts.First());

            for (var i = 1; i < cpts.Length; i++)
            {
                cptsFinal.Add(Interp(cpts[i - 1], cpts[i], (double)i / n));
            }

            cptsFinal.Add(cpts.Last());

            var oldKnots = crv.Knots();

            var knots   = HermiteToNurbs.Clamp(new[] { oldKnots.First(), oldKnots.Last() }, n);
            var weights = Enumerable.Repeat(1.0, cptsFinal.Count).ToArray();

            return(NurbsCurve.ByControlPointsWeightsKnots(cptsFinal, weights, knots, n));
        }
Ejemplo n.º 3
0
        public static Surface ExtractSurface(Autodesk.Revit.DB.HermiteFace face, IEnumerable <PolyCurve> edgeLoops)
        {
            // The number of interpolating points in the u direction is given by get_Params
            var uParams = face.get_Params(0).Cast <double>().ToArray();
            var vParams = face.get_Params(1).Cast <double>().ToArray();

            var numU = uParams.Length;
            var numV = vParams.Length;

            // unpack the points
            var points = face.Points;

            // structure the points as 2d array - numU x numV
            var ptArr = new Autodesk.DesignScript.Geometry.Point[numV][];
            var count = 0;

            for (var i = 0; i < numV; i++)
            {
                ptArr[i] = new Autodesk.DesignScript.Geometry.Point[numU];

                for (var j = 0; j < numU; j++)
                {
                    ptArr[i][j] = points[count++].ToPoint(false);
                }
            }

            // unpack the tangents
            var uTangents = face.get_Tangents(0);
            var vTangents = face.get_Tangents(1);

            // structure the tangents as 2d array - numU x numV
            var uTangentsArr = new Vector[numV][];
            var vTangentsArr = new Vector[numV][];

            count = 0;
            for (var i = 0; i < numV; i++)
            {
                uTangentsArr[i] = new Vector[numU];
                vTangentsArr[i] = new Vector[numU];

                for (var j = 0; j < numU; j++)
                {
                    uTangentsArr[i][j] = uTangents[count].ToVector(false);
                    vTangentsArr[i][j] = vTangents[count].ToVector(false);
                    count++;
                }
            }

            // u tangents run in increasing column direction
            var uStartTangents = uTangentsArr.Select(x => x[0]).ToArray();
            var uEndTangents   = uTangentsArr.Select(x => x[numU - 1]).ToArray();

            // v tangents run in increasing row direction
            var vStartTangents = vTangentsArr[0];
            var vEndTangents   = vTangentsArr[numV - 1];

            // The mixed derivs are the twist vectors - dP / dUdV
            var md = face.MixedDerivs;

            Vector[] mds =
            {
                md[0].ToVector(false),
                md[numU - 1].ToVector(false),
                md[(md.Count - 1) - (numU - 1)].ToVector(false),
                md[md.Count - 1].ToVector(false)
            };

            return(NurbsSurface.ByPointsTangentsKnotsDerivatives(ptArr,
                                                                 uStartTangents,
                                                                 uEndTangents,
                                                                 vStartTangents,
                                                                 vEndTangents,
                                                                 HermiteToNurbs.Clamp(uParams),
                                                                 HermiteToNurbs.Clamp(vParams),
                                                                 mds));
        }