Esempio n. 1
0
        public static NurbsSurface ToRhinoSurface(DB.HermiteFace face, double relativeTolerance)
        {
            NurbsSurface nurbsSurface = default;

            try
            {
#if REVIT_2021
                using (var surface = DB.ExportUtils.GetNurbsSurfaceDataForSurface(face.GetSurface()))
                    nurbsSurface = ToRhino(surface, face.GetBoundingBox());
#else
                using (var surface = DB.ExportUtils.GetNurbsSurfaceDataForFace(face))
                    nurbsSurface = ToRhino(surface, face.GetBoundingBox());
#endif
            }
            catch (Autodesk.Revit.Exceptions.ApplicationException) { }

            if (nurbsSurface is null)
            {
                using (var paramsU = face.get_Params(0))
                    using (var paramsV = face.get_Params(1))
                    {
                        nurbsSurface = FromHermiteSurface
                                       (
                            paramsU,
                            paramsV,
                            face.Points,
                            face.MixedDerivs,
                            face.get_Tangents(0),
                            face.get_Tangents(1)
                                       );
                    }
            }

            using (var bboxUV = face.GetBoundingBox())
            {
                nurbsSurface = nurbsSurface.Trim
                               (
                    new Interval(bboxUV.Min.U, bboxUV.Max.U),
                    new Interval(bboxUV.Min.V, bboxUV.Max.V)
                               ) as NurbsSurface;
            }

            if (nurbsSurface is object)
            {
                double ctol = relativeTolerance * Revit.ShortCurveTolerance * 5.0;
                if (ctol != 0.0)
                {
                    // Extend using smooth way avoids creating C2 discontinuities
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.West, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.East, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.South, ctol, true) as NurbsSurface ?? nurbsSurface;
                    nurbsSurface = nurbsSurface.Extend(IsoStatus.North, ctol, true) as NurbsSurface ?? nurbsSurface;
                }
            }

            return(nurbsSurface);
        }
Esempio n. 2
0
        public static NurbsSurface ToRhinoSurface(this DB.HermiteFace face)
        {
            NurbsSurface nurbsSurface = default;

            try
            {
                using (var surface = DB.ExportUtils.GetNurbsSurfaceDataForFace(face))
                    nurbsSurface = surface.ToRhino(face.GetBoundingBox());
            }
            catch (Autodesk.Revit.Exceptions.ApplicationException) { }

            if (nurbsSurface is null)
            {
                nurbsSurface = FromHermiteSurface
                               (
                    face.Points,
                    face.MixedDerivs,
                    face.get_Params(0).Cast <double>().ToArray(),
                    face.get_Params(1).Cast <double>().ToArray(),
                    face.get_Tangents(0),
                    face.get_Tangents(1)
                               );
            }

            if (nurbsSurface is object)
            {
                double ctol = Revit.ShortCurveTolerance * 5.0;

                // Extend using smooth way avoids creating C2 discontinuities
                nurbsSurface = nurbsSurface.Extend(IsoStatus.West, ctol, true) as NurbsSurface ?? nurbsSurface;
                nurbsSurface = nurbsSurface.Extend(IsoStatus.East, ctol, true) as NurbsSurface ?? nurbsSurface;
                nurbsSurface = nurbsSurface.Extend(IsoStatus.South, ctol, true) as NurbsSurface ?? nurbsSurface;
                nurbsSurface = nurbsSurface.Extend(IsoStatus.North, ctol, true) as NurbsSurface ?? nurbsSurface;
            }

            return(nurbsSurface);
        }
Esempio 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();
                }
            }

            // 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();
                    vTangentsArr[i][j] = vTangents[count].ToVector();
                    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(),
                md[numU - 1].ToVector(),
                md[(md.Count - 1) - (numU - 1)].ToVector(),
                md[md.Count - 1].ToVector()
            };

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