コード例 #1
0
        public void FlattenProcess()
        {
            SparseMatrixComplex Lc = BuildEnergy();

            SparseMatrixComplex star0 = DECComplex.Instance.cBuildHodgeStar0Form(mesh);

            Lc += new Complex(1.0e-8, 0) * star0; //[Reconsider: Complex(1.0e-8)]

            //Compute parameterization
            DenseMatrixComplex x = new DenseMatrixComplex(Lc.RowCount, 1);

            x.Randomize();  //Initial guesses

            DenseMatrixComplex result = LinearSystemDEC.Instance.smallestEigPositiveDefinite(ref Lc, ref star0, ref x);

            //Assign sultion
            foreach (TriMesh.Vertex v in mesh.Vertices)
            {
                Complex value = result[v.Index, 0];

                v.Traits.Position.x = value.RealPart;
                v.Traits.Position.y = value.ImagePart;
                v.Traits.Position.z = 0;
            }

            TriMeshUtil.ScaleToUnit(mesh, 1.0);
            TriMeshUtil.MoveToCenter(mesh);
        }
コード例 #2
0
        public static TriMesh ReadFile(string fileName)
        {
            TriMesh mesh = null;

            if (fileName.EndsWith("obj"))
            {
                mesh = TriMeshIO.FromObjFile(fileName);
            }
            if (fileName.EndsWith("off"))
            {
                mesh = TriMeshIO.FromOffFile(fileName);
            }
            if (fileName.EndsWith("ply"))
            {
                mesh = TriMeshIO.FromPlyFile(fileName);
            }
            if (fileName.EndsWith("npts"))
            {
                PointsetsFile = fileName;
            }
            if (mesh != null)
            {
                TriMeshUtil.ScaleToUnit(mesh, 1.0);
                TriMeshUtil.MoveToCenter(mesh);

                TriMeshUtil.SetUpNormalVertex(mesh);
            }
            return(mesh);
        }
コード例 #3
0
        private void comboBoxCurveComplexType_SelectedValueChanged(object sender, EventArgs e)
        {
            EnumCurveComplex curveType = (EnumCurveComplex)this.comboBoxCurveComplexType.SelectedItem;

            ParameterCurve.Instance.currentCurve = curveType;

            switch (curveType)
            {
            case EnumCurveComplex.FourPointBezier:

                Mesh = ParameterCurve.Instance.CreateFourBezierControlPoint();
                break;

            case EnumCurveComplex.ThreePointBezier:

                Mesh = ParameterCurve.Instance.CreateThreeBezierControlPoint();
                break;

            case EnumCurveComplex.NPointBezier:

                Mesh = ParameterCurve.Instance.CreateNBezierControlPoint();
                break;

            case EnumCurveComplex.NURBS:

                Mesh = ParameterCurve.Instance.CreateNURBSControlPoint();
                break;

            case EnumCurveComplex.NPointBSpline:

                Mesh = ParameterCurve.Instance.CreateNBSpineControlPoint();
                break;

            case EnumCurveComplex.FourPointBSpline:

                Mesh = ParameterCurve.Instance.CreateFourPointBSpline();
                break;

            case EnumCurveComplex.NURBSCicle:

                Mesh = ParameterCurve.Instance.CreateNURBSCicleControlPoint();
                break;

            case EnumCurveComplex.NURBSEllipse:

                Mesh = ParameterCurve.Instance.CreateNURBSEllipseControlPoint();
                break;
            }

            TriMeshUtil.ScaleToUnit(Mesh, 0.9);
            TriMeshUtil.MoveToCenter(Mesh);

            GlobalSetting.DisplaySetting.DisplayMode = EnumDisplayMode.PointsWithLine;
            ToolPool.Instance.Tool = new ToolCurveComplex(ToolPool.Instance.Width, ToolPool.Instance.Height, Mesh);
            OnChanged(EventArgs.Empty);
        }
コード例 #4
0
        private void DrawCurve()
        {
            EnumCurveSimple curveType = (EnumCurveSimple)this.comboBoxCurve.SelectedItem;

            Mesh = ParameterCurve.Instance.CreateCurve(curveType);
            TriMeshUtil.ScaleToUnit(Mesh, 0.9);
            TriMeshUtil.MoveToCenter(Mesh);
            GlobalSetting.DisplaySetting.DisplayMode = EnumDisplayMode.Vertex;
            OnChanged(EventArgs.Empty);
        }
コード例 #5
0
        static TriMesh CreateSphere()
        {
            TriMesh sphere = TriMeshIO.ReadFile("sphere.obj");

            TriMeshUtil.ScaleToUnit(sphere, 0.4);
            TriMeshUtil.MoveToCenter(sphere);
            Vector3D move = new Vector3D(-0.2, -0.1, -0.1);

            foreach (var v in sphere.Vertices)
            {
                v.Traits.Position -= move;
            }
            TriMeshUtil.SetUpNormalVertex(sphere);
            return(sphere);
        }
コード例 #6
0
        static TriMesh CreateCube()
        {
            TriMesh cube = TriMeshIO.ReadFile("cube.obj");

            TriMeshUtil.ScaleToUnit(cube, 0.2);
            TriMeshUtil.MoveToCenter(cube);
            Vector3D move = new Vector3D(0.2, 0.1, -0.3);

            foreach (var v in cube.Vertices)
            {
                v.Traits.Position -= move;
            }
            TriMeshUtil.SetUpNormalVertex(cube);
            return(cube);
        }
コード例 #7
0
 private void moveToCenterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TriMeshUtil.MoveToCenter(Mesh);
     OnChanged(EventArgs.Empty);
 }
コード例 #8
0
        public void Run()
        {
            Stopwatch clock = new Stopwatch();

            clock.Start();

            double step = 0.01;

            DECMeshDouble      decMesh = new DECMeshDouble(mesh);
            SparseMatrixDouble laplace = decMesh.Laplace;

            SparseMatrixDouble star0 = decMesh.HodgeStar0Form;

            SparseMatrixDouble star1 = decMesh.HodgeStar1Form;

            SparseMatrixDouble d0 = decMesh.ExteriorDerivative0Form;

            SparseMatrixDouble L = d0.Transpose() * star1 * d0;


            SparseMatrixDouble A = star0 + step * L;

            A.WriteToFile("A.ma");

            double[] xs = new double[mesh.Vertices.Count];
            double[] ys = new double[mesh.Vertices.Count];
            double[] zs = new double[mesh.Vertices.Count];

            foreach (TriMesh.Vertex v in mesh.Vertices)
            {
                xs[v.Index] = v.Traits.Position.x;
                ys[v.Index] = v.Traits.Position.y;
                zs[v.Index] = v.Traits.Position.z;
            }

            double[] rhs1 = star0 * xs;
            double[] rhs2 = star0 * ys;
            double[] rhs3 = star0 * zs;


            //SparseMatrix.WriteVectorToFile("xs.ve", rhs1);
            //SparseMatrix.WriteVectorToFile("ys.ve", rhs2);
            //SparseMatrix.WriteVectorToFile("zs.ve", rhs3);

            DenseMatrixDouble rhsx = new DenseMatrixDouble(mesh.Vertices.Count, 1);
            DenseMatrixDouble rhsy = new DenseMatrixDouble(mesh.Vertices.Count, 1);
            DenseMatrixDouble rhsz = new DenseMatrixDouble(mesh.Vertices.Count, 1);

            for (int i = 0; i < mesh.Vertices.Count; i++)
            {
                rhsx[i, 0] = rhs1[i];
                rhsy[i, 0] = rhs2[i];
                rhsz[i, 0] = rhs3[i];
            }

            DenseMatrixDouble newX = LinearSystemGenericByLib.Instance.SolveLinerSystem(ref A, ref rhsx);
            DenseMatrixDouble newY = LinearSystemGenericByLib.Instance.SolveLinerSystem(ref A, ref rhsy);
            DenseMatrixDouble newZ = LinearSystemGenericByLib.Instance.SolveLinerSystem(ref A, ref rhsz);

            foreach (TriMesh.Vertex v in mesh.Vertices)
            {
                v.Traits.Position.x = newX[v.Index, 0];
                v.Traits.Position.y = newY[v.Index, 0];
                v.Traits.Position.z = newZ[v.Index, 0];
            }

            TriMeshUtil.ScaleToUnit(mesh, 1.0f);
            TriMeshUtil.MoveToCenter(mesh);

            clock.Stop();

            decimal micro = clock.Elapsed.Ticks / 10m;

            Console.WriteLine("Total time cost:{0}", micro);
        }