public void UpdateDeformation(String imagePath, double scale) { TGAImage image = new TGAImage(imagePath); //double[] rho = IOHuiZhao.Instance.ReadVectorFromMatlab("A.vector"); double[] rho = SetCurvatureChange(image, 10); SparseMatrixQuaternion E = BuildEigenValueProblem(rho); DenseMatrixQuaternion lamda = LinearSystemDEC.Instance.SolveEigen(ref E); SparseMatrixQuaternion Laplace = BuildCotLaplace(); DenseMatrixQuaternion omega = BuildOmega(lamda); LinearSystemGenericByLib.Instance.FactorizationLU(ref Laplace); DenseMatrixQuaternion newV = LinearSystemGenericByLib.Instance.SolveByFactorizedLU(ref omega); NormalizeSolution(ref newV); UpdatePosition(ref newV); }
public double[] SetCurvatureChange(TGAImage image, double scale) { double[] rho = new double[mesh.Faces.Count]; double w = (double)image.Image.Width; double h = (double)image.Image.Height; foreach (TriMesh.Face face in mesh.Faces) { rho[face.Index] = 0; for (int i = 0; i < 3; i++) { TriMesh.HalfEdge faceVertex = face.FindHalfedgeTo(face.GetVertex(i)); Vector2D uv = faceVertex.Traits.TextureCoordinate; rho[face.Index] += image.Sample(uv.x * w, uv.y * h) / 3; } //Shrink to [-scale,scale] rho[face.Index] = (2 * (rho[face.Index] - 0.5)) * scale; } return(rho); }
public double[] SetCurvatureChange(TGAImage image, double scale) { double[] rho = new double[mesh.Faces.Count]; double w = (double)image.Image.Width; double h = (double)image.Image.Height; foreach (TriMesh.Face face in mesh.Faces) { rho[face.Index] = 0; for (int i = 0; i < 3; i++) { TriMesh.HalfEdge faceVertex = face.FindHalfedgeTo(face.GetVertex(i)); Vector2D uv = faceVertex.Traits.TextureCoordinate; rho[face.Index] += image.Sample(uv.x * w, uv.y * h) / 3; } //Shrink to [-scale,scale] rho[face.Index] = (2 * (rho[face.Index] - 0.5)) * scale; } return rho; }