main.cpp 1.1 KB

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