Пример #1
0
        /// <summary>
        /// Barycentric Parameterization
        /// Covers barycentric methods which need a fully defined boundary
        /// A particular method can be chosen by creating an appropriate Laplacian matrix
        /// See also (Floater 2003)
        /// </summary>
        /// <param name="meshin">input mesh, after solving its texture coordinates in vertex traits will be adjusted</param>
        /// <param name="meshout">an flattened output mesh with only X,Y coordinates set, Z is set to 0</param>
        private void BarycentricMapping(TriangleMesh meshin, out TriangleMesh meshout)
        {
            /// init an mesh that serves for output of the 2d parametrized mesh
            meshout = meshin.Copy();
            //meshOut = meshIn;

            /// get lenghts
            var vertexCount      = meshout.Vertices.Count;
            var boundaryVertices = meshout.Vertices.Where(x => x.OnBoundary).ToList();

            /// right hand side (RHS)
            var bu = new double[vertexCount];
            var bv = new double[vertexCount];
            var b0 = new double[vertexCount];

            // TODO : For geometry images, L mapped edges require splitting. Adaptive length parameterization should be sufficient for crack prediction however
            FixBoundaryToShape(boundaryVertices, bu, bv);

            var laplacian = MeshLaplacian.SelectedLaplacian == MeshLaplacian.Type.Harmonic ?
                            MeshLaplacian.CreateBoundedHarmonicLaplacian(meshin, 1d, 0d, true) :
                            MeshLaplacian.SelectedLaplacian == MeshLaplacian.Type.MeanValue ?
                            MeshLaplacian.CreateBoundedMeanLaplacian(meshin, 1d, 0d, true) :
                            MeshLaplacian.CreateBoundedUniformLaplacian(meshin, 1d, 0d, true);

            var qrSolver = QR.Create(laplacian.Compress());
            var success  = qrSolver.Solve(bu) && qrSolver.Solve(bv);

            /// update mesh positions
            MeshLaplacian.UpdateMesh(meshout, bu, bv, b0, bu, bv);
            MeshLaplacian.UpdateMesh(meshin, bu, bv);
        }