main.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <igl/lscm.h>
  4. Eigen::MatrixXd V;
  5. Eigen::MatrixXi F;
  6. Eigen::MatrixXd V_uv;
  7. bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
  8. {
  9. if (key == '1')
  10. // Plot the 3D mesh
  11. viewer.set_mesh(V,F);
  12. else if (key == '2')
  13. // Plot the mesh in 2D using the UV coordinates as vertex coordinates
  14. viewer.set_mesh(V_uv,F);
  15. viewer.compute_normals();
  16. return false;
  17. }
  18. int main(int argc, char *argv[])
  19. {
  20. using namespace Eigen;
  21. using namespace std;
  22. // Load a mesh in OFF format
  23. igl::readOFF("../shared/camelhead.off", V, F);
  24. // LSCM parametrization
  25. V_uv = igl::lscm(V,F,Eigen::VectorXi(),Eigen::MatrixXd());
  26. // Scale the uv
  27. V_uv *= 5;
  28. // Plot the mesh
  29. igl::Viewer viewer;
  30. viewer.set_mesh(V, F);
  31. viewer.set_uv(V_uv);
  32. viewer.callback_key_down = &key_down;
  33. // Disable wireframe
  34. viewer.options.show_lines = false;
  35. // Draw checkerboard texture
  36. viewer.options.show_texture = true;
  37. // Launch the viewer
  38. viewer.launch();
  39. }