|
@@ -34,6 +34,14 @@
|
|
|
#include <Eigen/SparseCholesky>
|
|
|
#include <Eigen/IterativeLinearSolvers>
|
|
|
|
|
|
+#include <igl/Timer.h>
|
|
|
+#include <igl/sparse_cached.h>
|
|
|
+#include <igl/AtA_cached.h>
|
|
|
+
|
|
|
+#ifdef CHOLMOD
|
|
|
+#include <Eigen/CholmodSupport>
|
|
|
+#endif
|
|
|
+
|
|
|
namespace igl
|
|
|
{
|
|
|
namespace slim
|
|
@@ -42,8 +50,8 @@ namespace igl
|
|
|
IGL_INLINE void compute_surface_gradient_matrix(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F,
|
|
|
const Eigen::MatrixXd &F1, const Eigen::MatrixXd &F2,
|
|
|
Eigen::SparseMatrix<double> &D1, Eigen::SparseMatrix<double> &D2);
|
|
|
- IGL_INLINE void buildA(igl::SLIMData& s, Eigen::SparseMatrix<double> &A);
|
|
|
- IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix<double> &At);
|
|
|
+ IGL_INLINE void buildA(igl::SLIMData& s, std::vector<Eigen::Triplet<double> > & IJV);
|
|
|
+ IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix<double> &A);
|
|
|
IGL_INLINE void add_soft_constraints(igl::SLIMData& s, Eigen::SparseMatrix<double> &L);
|
|
|
IGL_INLINE double compute_energy(igl::SLIMData& s, Eigen::MatrixXd &V_new);
|
|
|
IGL_INLINE double compute_soft_const_energy(igl::SLIMData& s,
|
|
@@ -395,8 +403,12 @@ namespace igl
|
|
|
Eigen::SparseMatrix<double> L;
|
|
|
build_linear_system(s,L);
|
|
|
|
|
|
+ igl::Timer t;
|
|
|
+
|
|
|
+ //t.start();
|
|
|
// solve
|
|
|
Eigen::VectorXd Uc;
|
|
|
+#ifndef CHOLMOD
|
|
|
if (s.dim == 2)
|
|
|
{
|
|
|
SimplicialLDLT<Eigen::SparseMatrix<double> > solver;
|
|
@@ -406,13 +418,21 @@ namespace igl
|
|
|
{ // seems like CG performs much worse for 2D and way better for 3D
|
|
|
Eigen::VectorXd guess(uv.rows() * s.dim);
|
|
|
for (int i = 0; i < s.v_num; i++) for (int j = 0; j < s.dim; j++) guess(uv.rows() * j + i) = uv(i, j); // flatten vector
|
|
|
- ConjugateGradient<Eigen::SparseMatrix<double>, Eigen::Lower | Upper> solver;
|
|
|
- solver.setTolerance(1e-8);
|
|
|
- Uc = solver.compute(L).solveWithGuess(s.rhs, guess);
|
|
|
+ ConjugateGradient<Eigen::SparseMatrix<double>, Lower | Upper> cg;
|
|
|
+ cg.setTolerance(1e-8);
|
|
|
+ cg.compute(L);
|
|
|
+ Uc = cg.solveWithGuess(s.rhs, guess);
|
|
|
}
|
|
|
-
|
|
|
+#else
|
|
|
+ CholmodSimplicialLDLT<Eigen::SparseMatrix<double> > solver;
|
|
|
+ Uc = solver.compute(L).solve(s.rhs);
|
|
|
+#endif
|
|
|
for (int i = 0; i < s.dim; i++)
|
|
|
uv.col(i) = Uc.block(i * s.v_n, 0, s.v_n, 1);
|
|
|
+
|
|
|
+ // t.stop();
|
|
|
+ // std::cerr << "solve: " << t.getElapsedTime() << std::endl;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -478,20 +498,60 @@ namespace igl
|
|
|
IGL_INLINE void build_linear_system(igl::SLIMData& s, Eigen::SparseMatrix<double> &L)
|
|
|
{
|
|
|
// formula (35) in paper
|
|
|
+ std::vector<Eigen::Triplet<double> > IJV;
|
|
|
+
|
|
|
+ #ifdef SLIM_CACHED
|
|
|
+ buildA(s,IJV);
|
|
|
+ if (s.A.rows() == 0)
|
|
|
+ {
|
|
|
+ s.A = Eigen::SparseMatrix<double>(s.dim * s.dim * s.f_n, s.dim * s.v_n);
|
|
|
+ igl::sparse_cached_precompute(IJV,s.A,s.A_data);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ igl::sparse_cached(IJV,s.A,s.A_data);
|
|
|
+ #else
|
|
|
Eigen::SparseMatrix<double> A(s.dim * s.dim * s.f_n, s.dim * s.v_n);
|
|
|
- buildA(s,A);
|
|
|
+ buildA(s,IJV);
|
|
|
+ A.setFromTriplets(IJV.begin(),IJV.end());
|
|
|
+ A.makeCompressed();
|
|
|
+ #endif
|
|
|
|
|
|
+ #ifdef SLIM_CACHED
|
|
|
+ #else
|
|
|
Eigen::SparseMatrix<double> At = A.transpose();
|
|
|
At.makeCompressed();
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #ifdef SLIM_CACHED
|
|
|
+ Eigen::SparseMatrix<double> id_m(s.A.cols(), s.A.cols());
|
|
|
+ #else
|
|
|
+ Eigen::SparseMatrix<double> id_m(A.cols(), A.cols());
|
|
|
+ #endif
|
|
|
|
|
|
- Eigen::SparseMatrix<double> id_m(At.rows(), At.rows());
|
|
|
id_m.setIdentity();
|
|
|
|
|
|
// add proximal penalty
|
|
|
+ #ifdef SLIM_CACHED
|
|
|
+ s.AtA_data.W = s.WGL_M;
|
|
|
+ if (s.AtA.rows() == 0)
|
|
|
+ igl::AtA_cached_precompute(s.A,s.AtA,s.AtA_data);
|
|
|
+ else
|
|
|
+ igl::AtA_cached(s.A,s.AtA,s.AtA_data);
|
|
|
+
|
|
|
+ L = s.AtA + s.proximal_p * id_m; //add also a proximal
|
|
|
+ L.makeCompressed();
|
|
|
+
|
|
|
+ #else
|
|
|
L = At * s.WGL_M.asDiagonal() * A + s.proximal_p * id_m; //add also a proximal term
|
|
|
L.makeCompressed();
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #ifdef SLIM_CACHED
|
|
|
+ buildRhs(s, s.A);
|
|
|
+ #else
|
|
|
+ buildRhs(s, A);
|
|
|
+ #endif
|
|
|
|
|
|
- buildRhs(s, At);
|
|
|
Eigen::SparseMatrix<double> OldL = L;
|
|
|
add_soft_constraints(s,L);
|
|
|
L.makeCompressed();
|
|
@@ -657,10 +717,9 @@ namespace igl
|
|
|
return energy;
|
|
|
}
|
|
|
|
|
|
- IGL_INLINE void buildA(igl::SLIMData& s, Eigen::SparseMatrix<double> &A)
|
|
|
+ IGL_INLINE void buildA(igl::SLIMData& s, std::vector<Eigen::Triplet<double> > & IJV)
|
|
|
{
|
|
|
// formula (35) in paper
|
|
|
- std::vector<Eigen::Triplet<double> > IJV;
|
|
|
if (s.dim == 2)
|
|
|
{
|
|
|
IJV.reserve(4 * (s.Dx.outerSize() + s.Dy.outerSize()));
|
|
@@ -780,10 +839,9 @@ namespace igl
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- A.setFromTriplets(IJV.begin(), IJV.end());
|
|
|
}
|
|
|
|
|
|
- IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix<double> &At)
|
|
|
+ IGL_INLINE void buildRhs(igl::SLIMData& s, const Eigen::SparseMatrix<double> &A)
|
|
|
{
|
|
|
Eigen::VectorXd f_rhs(s.dim * s.dim * s.f_n);
|
|
|
f_rhs.setZero();
|
|
@@ -830,7 +888,7 @@ namespace igl
|
|
|
for (int j = 0; j < s.v_n; j++)
|
|
|
uv_flat(s.v_n * i + j) = s.V_o(j, i);
|
|
|
|
|
|
- s.rhs = (At * s.WGL_M.asDiagonal() * f_rhs + s.proximal_p * uv_flat);
|
|
|
+ s.rhs = (f_rhs.transpose() * s.WGL_M.asDiagonal() * A).transpose() + s.proximal_p * uv_flat;
|
|
|
}
|
|
|
|
|
|
}
|