Ejemplo n.º 1
0
        private void Convert()
        {
            var cnt = points.Count / 5.0;
            var pts = new List <Vector4>();

            for (int i = 0; i < cnt; i++)
            {
                pts.Add(points[i * 5]);
            }
            if (cyclic)
            {
                pts.Add(points[0]);
            }

            var interp = new BsplineInterpolator(pts.Select(x => scene.CreateCatPoint(P.GetPosition(x.X, x.Y))), scene);

            scene.AddNewModel(interp);
            //scene.RemoveModel(this);
        }
Ejemplo n.º 2
0
        private void ConvertToBSpline(SceneData scene)
        {
            int widthPoints  = UDensity + 3;
            int heightPoints = VDensity + 3;

            if (changed || points.Count < 1)
            {
                GenerateModel();
            }
            var pts = new Vector3[heightPoints - 2, widthPoints - 2];

            for (int i = 0; i < UDensity + 1; i++)
            {
                for (int j = 0; j < VDensity + 1; j++)
                {
                    pts[j, i] = points[i * 3 * (VDensity * 3 + 1) + j * 3];
                }
            }

            var catPoints = new CatPoint[heightPoints, widthPoints];
            var matrix    = GetMatrix(false, new Vector3());

            if (!Curved)
            {
                for (int i = 1; i < widthPoints - 1; i++)
                {
                    for (int j = 1; j < heightPoints - 1; j++)
                    {
                        var pt = pts[(j - 1), (i - 1)];
                        catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                    }
                }

                for (int i = 1; i < widthPoints - 1; i++)
                {
                    int j  = 0;
                    var pt = pts[0, i - 1] * 2 - pts[1, i - 1];
                    catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                    j  = heightPoints - 1;
                    pt = pts[j - 2, i - 1] * 2 - pts[j - 3, i - 1];
                    catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                }
                for (int j = 1; j < heightPoints - 1; j++)
                {
                    int i  = 0;
                    var pt = pts[j - 1, 0] * 2 - pts[j - 1, 1];
                    catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                    i  = widthPoints - 1;
                    pt = pts[j - 1, i - 2] * 2 - pts[j - 1, i - 3];
                    catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                }

                catPoints[0, 0] = scene.CreateCatPoint((matrix * new Vector4(pts[0, 0] * 2 - pts[1, 1])).ClipToVector3());
                catPoints[heightPoints - 1, widthPoints - 1] = scene.CreateCatPoint(
                    (matrix * new Vector4(pts[pts.GetLength(0) - 1, pts.GetLength(1) - 1] * 2 -
                                          pts[pts.GetLength(0) - 2, pts.GetLength(1) - 2])).ClipToVector3());

                catPoints[0, widthPoints - 1] =
                    scene.CreateCatPoint((matrix * new Vector4(pts[0, pts.GetLength(1) - 1] * 2 - pts[1, pts.GetLength(1) - 2]))
                                         .ClipToVector3());
                catPoints[heightPoints - 1, 0] =
                    scene.CreateCatPoint((matrix * new Vector4(pts[pts.GetLength(0) - 1, 0] * 2 - pts[pts.GetLength(0) - 2, 1]))
                                         .ClipToVector3());
            }
            else
            {
                int  curvePoints = widthPoints - (IsCylinder ? 3 : 0);
                Real angleStep   = CurvatureAngle / curvePoints;
                Real heightStep  = Height / (heightPoints - 1);
                //r * (4sqrt(2) / (6n))
                Real newRadius = Radius * (1 + 2 * System.Math.Sqrt(2) / (3.0 * (double)(UDensity - 2)));

                for (int i = 0; i < curvePoints; i++)                //u
                {
                    Real angle = Utils.DegToRad(i * angleStep - CurvatureAngle / 2);
                    Real x     = newRadius * System.Math.Sin(angle);
                    for (int j = 0; j < heightPoints; j++)                    //v
                    {
                        Real y = heightStep * j - Height / 2;
                        Real z = newRadius * System.Math.Cos(angle);
                        catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(x, y, z, 1.0)).ClipToVector3());
                    }
                }

                if (IsCylinder)
                {
                    for (int j = 0; j < heightPoints; j++)
                    {
                        catPoints[j, widthPoints - 3] = catPoints[j, 0];
                        catPoints[j, widthPoints - 2] = catPoints[j, 1];
                        catPoints[j, widthPoints - 1] = catPoints[j, 2];
                    }
                }
            }

            scene.RemoveModel(this);
            var subArray = new CatPoint[4, 4];
            var ptches   = new Patch[VDensity, UDensity];

            for (int i = 0; i < UDensity; i++)            //u
            {
                for (int j = 0; j < VDensity; j++)        //v
                {
                    for (int x = 0; x < 4; x++)
                    {
                        for (int y = 0; y < 4; y++)
                        {
                            subArray[y, x] = catPoints[j + y, i + x];
                        }
                    }
                    var patch = new BSplinePatch(subArray)
                    {
                        UPos = i, VPos = j
                    };
                    scene.AddNewModel(patch);
                    ptches[j, i] = patch;
                }
            }
            var catPointsList = new List <CatPoint>(catPoints.GetLength(0) * catPoints.GetLength(1));

            foreach (var catPoint in catPoints)
            {
                catPointsList.Add(catPoint);
            }
            scene.AddNewModel(new Surface(SurfaceType.BSpline, ptches, catPointsList, scene, IsCylinder, false)
            {
                PatchesU = UDensity, PatchesV = VDensity
            });
        }
Ejemplo n.º 3
0
        private void ConvertToBezierPatches(SceneData scene)
        {
            int widthPoints  = UDensity * 3 + 1;
            int heightPoints = VDensity * 3 + 1;

            if (changed || points.Count == 0)
            {
                GenerateModel();
            }
            var catPoints = new CatPoint[heightPoints, widthPoints];
            var matrix    = GetMatrix(false, new Vector3());

            if (!Curved)
            {
                for (int i = 0; i < widthPoints; i++)
                {
                    for (int j = 0; j < heightPoints; j++)
                    {
                        var pt = points[i * heightPoints + j];
                        catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                    }
                }
            }
            else
            {
                bool cylinder = System.Math.Abs(CurvatureAngle - 360) < Utils.Eps;

                for (int i = 0; i < widthPoints - (cylinder ? 1 : 0); i++)
                {
                    for (int j = 0; j < heightPoints; j++)
                    {
                        Vector3 pt;
                        if (i % 3 != 0)
                        {
                            int ai = i - i % 3;
                            int ci = ai + 3;
                            var p  = (points[(ai + 1) * heightPoints + j] + points[(ai + 2) * heightPoints + j]);
                            var b  = p - (points[ai * heightPoints + j] + points[ci * heightPoints + j]) / 2;

                            var pot = i % 3 == 1 ? points[ai * heightPoints + j] : points[ci * heightPoints + j];

                            pt = b * 2 / 3.0 + pot * 1 / 3.0;
                        }
                        else
                        {
                            pt = points[i * heightPoints + j];
                        }
                        catPoints[j, i] = scene.CreateCatPoint((matrix * new Vector4(pt)).ClipToVector3());
                    }
                }
                if (cylinder)
                {
                    for (int j = 0; j < heightPoints; j++)
                    {
                        catPoints[j, widthPoints - 1] = catPoints[j, 0];
                    }
                }
            }
            scene.RemoveModel(this);
            var subArray = new CatPoint[4, 4];
            var ptchs    = new Patch[VDensity, UDensity];

            for (int i = 0; i < UDensity; i++)
            {
                for (int j = 0; j < VDensity; j++)
                {
                    for (int x = 0; x < 4; x++)
                    {
                        for (int y = 0; y < 4; y++)
                        {
                            subArray[y, x] = catPoints[j * 3 + y, i * 3 + x];
                        }
                    }
                    var patch = new BezierPatch(subArray)
                    {
                        UPos = i,
                        VPos = j
                    };
                    scene.AddNewModel(patch);
                    ptchs[j, i] = patch;
                }
            }
            var catPointsList = new List <CatPoint>(catPoints.GetLength(0) * catPoints.GetLength(1));

            foreach (var catPoint in catPoints)
            {
                catPointsList.Add(catPoint);
            }
            scene.AddNewModel(new Surface(SurfaceType.Bezier, ptchs, catPointsList, scene, IsCylinder, false)
            {
                PatchesU = UDensity, PatchesV = VDensity
            });
        }