コード例 #1
0
        public Surface NurbsSurfaceToSpeckle(DB.NurbsSurfaceData surface, DB.BoundingBoxUV uvBox, string units = null)
        {
            var result = new Surface();
            var unit   = units ?? ModelUnits;

            result.units = unit;

            result.degreeU = surface.DegreeU;
            result.degreeV = surface.DegreeV;

            result.domainU = new Interval(0, 1);
            result.domainV = new Interval(0, 1);

            var knotsU = surface.GetKnotsU().ToList();
            var knotsV = surface.GetKnotsV().ToList();

            result.knotsU = knotsU.GetRange(1, knotsU.Count - 2);
            result.knotsV = knotsV.GetRange(1, knotsV.Count - 2);

            var controlPointCountU = knotsU.Count - result.degreeU - 1;
            var controlPointCountV = knotsV.Count - result.degreeV - 1;

            var controlPoints = surface.GetControlPoints();
            var weights       = surface.GetWeights();

            var points = new List <List <ControlPoint> >();

            for (var u = 0; u < controlPointCountU; u++)
            {
                var uOffset = u * controlPointCountV;
                var row     = new List <ControlPoint>();

                for (var v = 0; v < controlPointCountV; v++)
                {
                    var pt    = controlPoints[uOffset + v];
                    var extPt = ToExternalCoordinates(pt);
                    if (surface.IsRational)
                    {
                        var w     = weights[uOffset + v];
                        var point = PointToSpeckle(extPt, unit);
                        row.Add(new ControlPoint(point.x, point.y, point.z, w, unit));
                    }
                    else
                    {
                        var point = PointToSpeckle(extPt, unit);
                        row.Add(new ControlPoint(point.x, point.y, point.z, unit));
                    }
                }
                points.Add(row);
            }

            result.SetControlPoints(points);

            return(result);
        }
コード例 #2
0
        public Surface NurbsSurfaceToSpeckle(DB.NurbsSurfaceData surface, DB.BoundingBoxUV uvBox)
        {
            var result = new Surface();

            result.units = ModelUnits;

            result.degreeU = surface.DegreeU;
            result.degreeV = surface.DegreeV;

            var knotsU = surface.GetKnotsU().ToList();
            var knotsV = surface.GetKnotsV().ToList();

            result.knotsU = knotsU.GetRange(1, knotsU.Count - 2);
            result.knotsV = knotsV.GetRange(1, knotsV.Count - 2);

            var controlPointCountU = knotsU.Count - result.degreeU - 1;
            var controlPointCountV = knotsV.Count - result.degreeV - 1;

            var controlPoints = surface.GetControlPoints();
            var weights       = surface.GetWeights();

            var points = new List <List <ControlPoint> >();

            for (var u = 0; u < controlPointCountU; u++)
            {
                var uOffset = u * controlPointCountV;
                var row     = new List <ControlPoint>();

                for (var v = 0; v < controlPointCountV; v++)
                {
                    var pt    = controlPoints[uOffset + v];
                    var extPt = ToExternalCoordinates(pt);
                    if (surface.IsRational)
                    {
                        var w = weights[uOffset + v];
                        row.Add(new ControlPoint(ScaleToSpeckle(extPt.X), ScaleToSpeckle(extPt.Y), ScaleToSpeckle(extPt.Z), w, ModelUnits));
                    }
                    else
                    {
                        row.Add(new ControlPoint(ScaleToSpeckle(extPt.X), ScaleToSpeckle(extPt.Y), ScaleToSpeckle(extPt.Z), ModelUnits));
                    }
                }
                points.Add(row);
            }
            result.SetControlPoints(points);
            return(result);
        }
コード例 #3
0
        public Surface SurfaceToSpeckle(NurbsSurface surface, string units = null)
        {
            var u      = units ?? ModelUnits;
            var result = new Surface();

            result.units = u;
            // Set control points
            var dsPoints  = surface.ControlPoints();
            var dsWeights = surface.Weights();
            var points    = new List <List <ControlPoint> >();

            for (var i = 0; i < dsPoints.Length; i++)
            {
                var row = new List <ControlPoint>();
                for (var j = 0; j < dsPoints[i].Length; j++)
                {
                    var dsPoint  = dsPoints[i][j];
                    var dsWeight = dsWeights[i][j];
                    row.Add(new ControlPoint(dsPoint.X, dsPoint.Y, dsPoint.Z, dsWeight, null));
                }

                points.Add(row);
            }

            result.SetControlPoints(points);

            // Set degree
            result.degreeU = surface.DegreeU;
            result.degreeV = surface.DegreeV;

            // Set knot vectors
            result.knotsU = surface.UKnots().ToList();
            result.knotsV = surface.VKnots().ToList();

            // Set other
            result.rational = surface.IsRational;
            result.closedU  = surface.ClosedInU;
            result.closedV  = surface.ClosedInV;

            result.area = surface.Area;
            result.bbox = BoxToSpeckle(surface.BoundingBox.ToCuboid(), u);

            return(result);
        }