Files
igl/tutorial/306_EigenDecomposition/main.cpp
T
b0fd49d598 CMake refactor (#1805)
* Start CMake refactoring.

* WIP on instlal().

* Handle install + hunter setup.

* Handle module options + igl_include helper.

* Build all tutorials again.

* Update CMake for unit tests.

* Update triangle lib.

* Update Hunter integration.

* Fix for header-only mode.

* Fix Windows compilation + add GMP/MPFR find_package + set VS folders.

* Fix CGAL build.

* Add copy dll for Windows + improve find gmp/mpfr.

* Update Github Actions.

* Update README.

* Fixes for CMake 3.18

* Fix include option.

* Rename libigl_imgui_front to avoid conflicts.

* Fix when disabling unit tests.

* Build imguizmo with C++11.

* Update CMake option comments.

* Rename nonfree -> restricted.

* Update triangle and tetgen versions.

* Fix compilation issue.

* Update continuous.yml

* remove cork

* finding matlab with default

* mosek module compiles; default detected; osx dylib hack

* Reduce build parallelism.

* Fix find GMP/MPFR on Windows + cleanup CGAL changes.

* Update readme.

Co-authored-by: Alec Jacobson <alecjacobson@adobe.com>
Co-authored-by: Alec Jacobson <alecjacobson@gmail.com>
2022-02-09 18:58:40 -08:00

75 lines
1.8 KiB
C++

#include <igl/eigs.h>
#include <igl/cotmatrix.h>
#include <igl/massmatrix.h>
#include <igl/opengl/glfw/Viewer.h>
#include <igl/parula.h>
#include <igl/read_triangle_mesh.h>
#include <Eigen/Sparse>
#include <iostream>
#include <queue>
Eigen::MatrixXd V,U;
Eigen::MatrixXi F;
int c=0;
double bbd = 1;
bool twod = 0;
int main(int argc, char * argv[])
{
using namespace Eigen;
using namespace std;
using namespace igl;
VectorXd D;
if(!read_triangle_mesh(
argc>1?argv[1]: TUTORIAL_SHARED_PATH "/beetle.off",V,F))
{
cout<<"failed to load mesh"<<endl;
}
twod = V.col(2).minCoeff()==V.col(2).maxCoeff();
bbd = (V.colwise().maxCoeff()-V.colwise().minCoeff()).norm();
SparseMatrix<double> L,M;
cotmatrix(V,F,L);
L = (-L).eval();
massmatrix(V,F,MASSMATRIX_TYPE_DEFAULT,M);
const size_t k = 5;
if(!eigs(L,M,k+1,EIGS_TYPE_SM,U,D))
{
cout<<"failed."<<endl;
}
// Normalize
U = ((U.array()-U.minCoeff())/(U.maxCoeff()-U.minCoeff())).eval();
igl::opengl::glfw::Viewer viewer;
viewer.callback_key_down = [&](igl::opengl::glfw::Viewer & viewer,unsigned char key,int)->bool
{
switch(key)
{
default:
return false;
case ' ':
{
U = U.rightCols(k).eval();
// Rescale eigen vectors for visualization
VectorXd Z =
bbd*0.5*U.col(c);
if(twod)
{
V.col(2) = Z;
viewer.data().set_mesh(V,F);
viewer.data().compute_normals();
}
viewer.data().set_data(U.col(c).eval());
c = (c+1)%U.cols();
return true;
}
}
};
viewer.data().set_mesh(V,F);
viewer.callback_key_down(viewer,' ',0);
viewer.data().show_lines = false;
std::cout<<
R"(
[space] Cycle through eigen modes
)";
viewer.launch();
}