Beispiel #1
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);
        }
        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);
        }
        public NurbsSurface SurfaceToNative(Surface surface)
        {
            var points  = new DS.Point[][] { };
            var weights = new double[][] { };

            var controlPoints = surface.GetControlPoints();

            points = controlPoints.Select(row => row.Select(p => DS.Point.ByCoordinates(
                                                                ScaleToNative(p.x, p.units),
                                                                ScaleToNative(p.y, p.units),
                                                                ScaleToNative(p.z, p.units))).ToArray())
                     .ToArray();

            weights = controlPoints.Select(row => row.Select(p => p.weight).ToArray()).ToArray();

            var knotsU = surface.knotsU;
            var knotsV = surface.knotsV;

            var result = DS.NurbsSurface.ByControlPointsWeightsKnots(points, weights, knotsU.ToArray(), surface.knotsV.ToArray(),
                                                                     surface.degreeU, surface.degreeV);

            return(result);
        }
        public BRepBuilderSurfaceGeometry SurfaceToNative(Surface surface)
        {
            var uvBox   = new DB.BoundingBoxUV(surface.knotsU[0], surface.knotsV[0], surface.knotsU[surface.knotsU.Count - 1], surface.knotsV[surface.knotsV.Count - 1]);
            var surfPts = surface.GetControlPoints();
            var uKnots  = SurfaceKnotsToNative(surface.knotsU);
            var vKnots  = SurfaceKnotsToNative(surface.knotsV);
            var cPts    = ControlPointsToNative(surfPts);

            BRepBuilderSurfaceGeometry result;

            if (!surface.rational)
            {
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, false, uvBox);
            }
            else
            {
                var weights = ControlPointWeightsToNative(surfPts);
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, weights, false, uvBox);
            }

            return(result);
        }