|
|
@@ -6,48 +6,44 @@
|
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
#include "lscm.h"
|
|
|
-
|
|
|
-#include "vector_area_matrix.h"
|
|
|
-#include "cotmatrix.h"
|
|
|
+#include "lscm_hessian.h"
|
|
|
+#include "massmatrix.h"
|
|
|
#include "repdiag.h"
|
|
|
+#include "eigs.h"
|
|
|
#include "min_quad_with_fixed.h"
|
|
|
#include <iostream>
|
|
|
|
|
|
+
|
|
|
+template <
|
|
|
+ typename DerivedV,
|
|
|
+ typename DerivedF,
|
|
|
+ typename Derivedb,
|
|
|
+ typename Derivedbc,
|
|
|
+ typename DerivedV_uv,
|
|
|
+ typename QScalar>
|
|
|
IGL_INLINE bool igl::lscm(
|
|
|
- const Eigen::MatrixXd& V,
|
|
|
- const Eigen::MatrixXi& F,
|
|
|
- const Eigen::VectorXi& b,
|
|
|
- const Eigen::MatrixXd& bc,
|
|
|
- Eigen::MatrixXd & V_uv,
|
|
|
- Eigen::SparseMatrix<double> & Q)
|
|
|
+ const Eigen::MatrixBase<DerivedV> & V,
|
|
|
+ const Eigen::MatrixBase<DerivedF> & F,
|
|
|
+ const Eigen::MatrixBase<Derivedb> & b,
|
|
|
+ const Eigen::MatrixBase<Derivedbc> & bc,
|
|
|
+ Eigen::PlainObjectBase<DerivedV_uv> & V_uv,
|
|
|
+ Eigen::SparseMatrix<QScalar> & Q)
|
|
|
{
|
|
|
using namespace Eigen;
|
|
|
using namespace std;
|
|
|
-
|
|
|
- // Assemble the area matrix (note that A is #Vx2 by #Vx2)
|
|
|
- SparseMatrix<double> A;
|
|
|
- igl::vector_area_matrix(F,A);
|
|
|
-
|
|
|
- // Assemble the cotan laplacian matrix
|
|
|
- SparseMatrix<double> L;
|
|
|
- igl::cotmatrix(V,F,L);
|
|
|
-
|
|
|
- SparseMatrix<double> L_flat;
|
|
|
- repdiag(L,2,L_flat);
|
|
|
+ igl::lscm_hessian(V,F,Q);
|
|
|
|
|
|
- VectorXi b_flat(b.size()*bc.cols(),1);
|
|
|
- VectorXd bc_flat(bc.size(),1);
|
|
|
+ Eigen::Matrix<typename Derivedb::Scalar,Eigen::Dynamic,1> b_flat(b.size()*bc.cols(),1);
|
|
|
+ Eigen::Matrix<typename Derivedbc::Scalar,Eigen::Dynamic,1> bc_flat(bc.size(),1);
|
|
|
for(int c = 0;c<bc.cols();c++)
|
|
|
{
|
|
|
b_flat.block(c*b.size(),0,b.rows(),1) = c*V.rows() + b.array();
|
|
|
bc_flat.block(c*bc.rows(),0,bc.rows(),1) = bc.col(c);
|
|
|
}
|
|
|
-
|
|
|
- // Minimize the LSCM energy
|
|
|
- Q = -L_flat - 2.*A;
|
|
|
+
|
|
|
const VectorXd B_flat = VectorXd::Zero(V.rows()*2);
|
|
|
- igl::min_quad_with_fixed_data<double> data;
|
|
|
- if(!igl::min_quad_with_fixed_precompute(Q,b_flat,SparseMatrix<double>(),true,data))
|
|
|
+ igl::min_quad_with_fixed_data<QScalar> data;
|
|
|
+ if(!igl::min_quad_with_fixed_precompute(Q,b_flat,SparseMatrix<QScalar>(),true,data))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
@@ -68,17 +64,55 @@ IGL_INLINE bool igl::lscm(
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+template <
|
|
|
+ typename DerivedV,
|
|
|
+ typename DerivedF,
|
|
|
+ typename Derivedb,
|
|
|
+ typename Derivedbc,
|
|
|
+ typename DerivedV_uv>
|
|
|
IGL_INLINE bool igl::lscm(
|
|
|
- const Eigen::MatrixXd& V,
|
|
|
- const Eigen::MatrixXi& F,
|
|
|
- const Eigen::VectorXi& b,
|
|
|
- const Eigen::MatrixXd& bc,
|
|
|
- Eigen::MatrixXd & V_uv)
|
|
|
+ const Eigen::MatrixBase<DerivedV> & V,
|
|
|
+ const Eigen::MatrixBase<DerivedF> & F,
|
|
|
+ const Eigen::MatrixBase<Derivedb> & b,
|
|
|
+ const Eigen::MatrixBase<Derivedbc> & bc,
|
|
|
+ Eigen::PlainObjectBase<DerivedV_uv> & V_uv)
|
|
|
{
|
|
|
- Eigen::SparseMatrix<double> Q;
|
|
|
+ Eigen::SparseMatrix<typename DerivedV_uv::Scalar> Q;
|
|
|
return lscm(V, F, b, bc, V_uv, Q);
|
|
|
}
|
|
|
|
|
|
+template <
|
|
|
+ typename DerivedV,
|
|
|
+ typename DerivedF,
|
|
|
+ typename DerivedV_uv>
|
|
|
+IGL_INLINE bool igl::lscm(
|
|
|
+ const Eigen::MatrixBase<DerivedV> & V,
|
|
|
+ const Eigen::MatrixBase<DerivedF> & F,
|
|
|
+ Eigen::PlainObjectBase<DerivedV_uv> & V_uv)
|
|
|
+{
|
|
|
+ using Scalar = typename DerivedV_uv::Scalar;
|
|
|
+ Eigen::SparseMatrix<Scalar> Q;
|
|
|
+ igl::lscm_hessian(V,F,Q);
|
|
|
+ Eigen::SparseMatrix<Scalar> M;
|
|
|
+ igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_DEFAULT,M);
|
|
|
+ Eigen::SparseMatrix<Scalar> M2;
|
|
|
+ igl::repdiag(M,2,M2);
|
|
|
+ Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> U;
|
|
|
+ Eigen::Matrix<Scalar,Eigen::Dynamic,1> S;
|
|
|
+ bool success = igl::eigs(Q,M2,3,igl::EIGS_TYPE_SM,U,S);
|
|
|
+ if(!success)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ V_uv.resize(V.rows(),2);
|
|
|
+ V_uv<< U.col(0).head(V.rows()),U.col(0).tail(V.rows());
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
// Explicit template instantiation
|
|
|
+// generated by autoexplicit.sh
|
|
|
+template bool igl::lscm<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
+// generated by autoexplicit.sh
|
|
|
+template bool igl::lscm<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
#endif
|