コード例 #1
0
        public void Initialize()
        {
            ToMeshV = new int[Mesh.MaxVertexID];
            ToIndex = new int[Mesh.MaxVertexID];
            N       = 0;
            foreach (int vid in Mesh.VertexIndices())
            {
                ToMeshV[N]   = vid;
                ToIndex[vid] = N;
                N++;
            }

            Px         = new double[N];
            Py         = new double[N];
            Pz         = new double[N];
            nbr_counts = new int[N];
            SymmetricSparseMatrix M = new SymmetricSparseMatrix();

            for (int i = 0; i < N; ++i)
            {
                int      vid = ToMeshV[i];
                Vector3d v   = Mesh.GetVertex(vid);
                Px[i]         = v.x; Py[i] = v.y; Pz[i] = v.z;
                nbr_counts[i] = Mesh.GetVtxEdgeCount(vid);
            }

            // construct laplacian matrix
            for (int i = 0; i < N; ++i)
            {
                int vid = ToMeshV[i];
                int n   = nbr_counts[i];

                double sum_w = 0;
                foreach (int nbrvid in Mesh.VtxVerticesItr(vid))
                {
                    int j  = ToIndex[nbrvid];
                    int n2 = nbr_counts[j];

                    // weight options
                    //double w = -1;
                    double w = -1.0 / Math.Sqrt(n + n2);
                    //double w = -1.0 / n;

                    M.Set(i, j, w);
                    sum_w += w;
                }
                sum_w = -sum_w;
                // TODO: Investigate: is this ia bug?
                // Source https://github.com/ZelimDamian/geometry3Sharp/commit/7a50d8de10faad762e726e60956acc4bdc5456b5
                // makes the following line M.Set(i, i, sum_w);
                M.Set(vid, vid, sum_w);
            }

            // transpose(L) * L, but matrix is symmetric...
            if (UseSoftConstraintNormalEquations)
            {
                //M = M.Multiply(M);
                // only works if M is symmetric!!
                PackedM = M.SquarePackedParallel();
            }
            else
            {
                PackedM = new PackedSparseMatrix(M);
            }

            // compute laplacian vectors of initial mesh positions
            MLx = new double[N];
            MLy = new double[N];
            MLz = new double[N];
            PackedM.Multiply(Px, MLx);
            PackedM.Multiply(Py, MLy);
            PackedM.Multiply(Pz, MLz);

            // allocate memory for internal buffers
            Preconditioner = new DiagonalMatrix(N);
            WeightsM       = new DiagonalMatrix(N);
            Cx             = new double[N]; Cy = new double[N]; Cz = new double[N];
            Bx             = new double[N]; By = new double[N]; Bz = new double[N];
            Sx             = new double[N]; Sy = new double[N]; Sz = new double[N];

            need_solve_update = true;
            UpdateForSolve();
        }
コード例 #2
0
        public void Initialize()
        {
            ToMeshV = new int[Mesh.MaxVertexID];
            ToIndex = new int[Mesh.MaxVertexID];
            N       = 0;
            foreach (int vid in Mesh.VertexIndices())
            {
                ToMeshV[N]   = vid;
                ToIndex[vid] = N;
                N++;
            }

            Px         = new double[N];
            Py         = new double[N];
            Pz         = new double[N];
            nbr_counts = new int[N];
            SymmetricSparseMatrix M = new SymmetricSparseMatrix();

            for (int i = 0; i < N; ++i)
            {
                int      vid = ToMeshV[i];
                Vector3d v   = Mesh.GetVertex(vid);
                Px[i]         = v.x; Py[i] = v.y; Pz[i] = v.z;
                nbr_counts[i] = Mesh.GetVtxEdgeCount(vid);
            }

            // construct laplacian matrix
            for (int i = 0; i < N; ++i)
            {
                int vid = ToMeshV[i];
                int n   = nbr_counts[i];

                double sum_w = 0;
                foreach (int nbrvid in Mesh.VtxVerticesItr(vid))
                {
                    int j  = ToIndex[nbrvid];
                    int n2 = nbr_counts[j];

                    // weight options
                    //double w = -1;
                    double w = -1.0 / Math.Sqrt(n + n2);
                    //double w = -1.0 / n;

                    M.Set(i, j, w);
                    sum_w += w;
                }
                sum_w = -sum_w;
                M.Set(vid, vid, sum_w);
            }

            // transpose(L) * L, but matrix is symmetric...
            if (UseSoftConstraintNormalEquations)
            {
                //M = M.Multiply(M);
                // only works if M is symmetric!!
                PackedM = M.SquarePackedParallel();
            }
            else
            {
                PackedM = new PackedSparseMatrix(M);
            }

            // compute laplacian vectors of initial mesh positions
            MLx = new double[N];
            MLy = new double[N];
            MLz = new double[N];
            PackedM.Multiply(Px, MLx);
            PackedM.Multiply(Py, MLy);
            PackedM.Multiply(Pz, MLz);

            // zero out...this is the smoothing bit!
            for (int i = 0; i < Px.Length; ++i)
            {
                MLx[i] = 0;
                MLy[i] = 0;
                MLz[i] = 0;
            }

            // allocate memory for internal buffers
            Preconditioner = new DiagonalMatrix(N);
            WeightsM       = new DiagonalMatrix(N);
            Cx             = new double[N]; Cy = new double[N]; Cz = new double[N];
            Bx             = new double[N]; By = new double[N]; Bz = new double[N];
            Sx             = new double[N]; Sy = new double[N]; Sz = new double[N];

            need_solve_update = true;
            UpdateForSolve();
        }
コード例 #3
0
        public void Initialize()
        {
            int NV = Curve.VertexCount;

            ToCurveV = new int[NV];
            ToIndex  = new int[NV];

            N = 0;
            for (int k = 0; k < NV; k++)
            {
                int vid = k;
                ToCurveV[N]  = vid;
                ToIndex[vid] = N;
                N++;
            }

            Px         = new double[N];
            Py         = new double[N];
            Pz         = new double[N];
            nbr_counts = new int[N];
            SymmetricSparseMatrix M = new SymmetricSparseMatrix();

            for (int i = 0; i < N; ++i)
            {
                int      vid = ToCurveV[i];
                Vector3d v   = Curve.GetVertex(vid);
                Px[i]         = v.x; Py[i] = v.y; Pz[i] = v.z;
                nbr_counts[i] = (i == 0 || i == N - 1) ? 1 : 2;
            }

            // construct laplacian matrix
            for (int i = 0; i < N; ++i)
            {
                int vid = ToCurveV[i];
                int n   = nbr_counts[i];

                Index2i nbrs = Curve.Neighbours(vid);

                double sum_w = 0;
                for (int k = 0; k < 2; ++k)
                {
                    int nbrvid = nbrs[k];
                    if (nbrvid == -1)
                    {
                        continue;
                    }
                    int j  = ToIndex[nbrvid];
                    int n2 = nbr_counts[j];

                    // weight options
                    double w = -1;
                    //double w = -1.0 / Math.Sqrt(n + n2);
                    //double w = -1.0 / n;

                    M.Set(i, j, w);
                    sum_w += w;
                }
                sum_w = -sum_w;
                M.Set(vid, vid, sum_w);
            }

            // transpose(L) * L, but matrix is symmetric...
            if (UseSoftConstraintNormalEquations)
            {
                //M = M.Multiply(M);
                // only works if M is symmetric!!
                PackedM = M.SquarePackedParallel();
            }
            else
            {
                PackedM = new PackedSparseMatrix(M);
            }

            // compute laplacian vectors of initial mesh positions
            MLx = new double[N];
            MLy = new double[N];
            MLz = new double[N];
            PackedM.Multiply(Px, MLx);
            PackedM.Multiply(Py, MLy);
            PackedM.Multiply(Pz, MLz);

            // allocate memory for internal buffers
            Preconditioner = new DiagonalMatrix(N);
            WeightsM       = new DiagonalMatrix(N);
            Cx             = new double[N]; Cy = new double[N]; Cz = new double[N];
            Bx             = new double[N]; By = new double[N]; Bz = new double[N];
            Sx             = new double[N]; Sy = new double[N]; Sz = new double[N];

            need_solve_update = true;
            UpdateForSolve();
        }