diff --git a/src/lscm.cpp b/src/lscm.cpp index d6e1b6c..2d5519f 100644 --- a/src/lscm.cpp +++ b/src/lscm.cpp @@ -1,4 +1,11 @@ #include "lscm.h" +#include "vector_area_matrix.h" +#include +#include +#include +#include +#include +#include void lscm( const Eigen::MatrixXd & V, @@ -6,5 +13,25 @@ void lscm( Eigen::MatrixXd & U) { // Replace with your code - U = V.leftCols(2); + // U = V.leftCols(2); + Eigen::SparseMatrix L,A,Q; + igl::cotmatrix(V,F,L); + vector_area_matrix(F,A); + igl::repdiag(L,2,Q); + Q = Q - A; + Eigen::SparseMatrix M,B; + igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M); + igl::repdiag(M,2,B); + + Eigen::MatrixXd sU; + Eigen::VectorXd sS; + igl::eigs(Q,B,3,igl::EIGS_TYPE_SM,sU,sS); + + U.resize(V.rows(), 2); + U.col(0) = sU.col(2).head(V.rows()); + U.col(1) = sU.col(2).tail(V.rows()); + Eigen::JacobiSVD svd(U.transpose() * U, Eigen::ComputeThinU | Eigen::ComputeThinV); + U = U * svd.matrixU(); + // since U is flipped due to boundary issue, I times -1 to flip the normal. + U.col(0) *= -1; } diff --git a/src/tutte.cpp b/src/tutte.cpp index 6f6109b..9215a58 100644 --- a/src/tutte.cpp +++ b/src/tutte.cpp @@ -1,4 +1,8 @@ #include "tutte.h" +#include +#include +#include +#include void tutte( const Eigen::MatrixXd & V, @@ -6,6 +10,33 @@ void tutte( Eigen::MatrixXd & U) { // Replace with your code - U = V.leftCols(2); -} + // U = V.leftCols(2); + Eigen::VectorXi bnd; + igl::boundary_loop(F,bnd); + Eigen::MatrixXi E; + igl::edges(F,E); + typedef Eigen::Triplet T; + std::vector tlist; + tlist.reserve(E.rows()*2); + for (int i=0; i L; + int L_size = E.maxCoeff() + 1; + L.resize(L_size,L_size); + L.setFromTriplets(tlist.begin(),tlist.end()); + + for(int i=0; i data; + igl::min_quad_with_fixed_precompute(L,bnd,Eigen::SparseMatrix(),false,data); + igl::min_quad_with_fixed_solve(data,B,UV,Eigen::MatrixXd(),U); +} \ No newline at end of file diff --git a/src/vector_area_matrix.cpp b/src/vector_area_matrix.cpp index 1d60ef8..ab49b31 100644 --- a/src/vector_area_matrix.cpp +++ b/src/vector_area_matrix.cpp @@ -1,11 +1,38 @@ #include "vector_area_matrix.h" +#include void vector_area_matrix( const Eigen::MatrixXi & F, Eigen::SparseMatrix& A) { // Replace with your code - int V_size = F.maxCoeff()+1; - A.resize(V_size*2,V_size*2); + int V_size = F.maxCoeff()+1; + A.resize(V_size*2,V_size*2); + + std::vector> bnd; + igl::boundary_loop(F,bnd); + + typedef Eigen::Triplet T; + std::vector tlist; + + for (int i=0; i