main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <igl/boundary_loop.h>
  2. #include <igl/harmonic.h>
  3. #include <igl/map_vertices_to_circle.h>
  4. #include <igl/read_triangle_mesh.h>
  5. #include <igl/opengl/glfw/Viewer.h>
  6. #include "tutorial_shared_path.h"
  7. int main(int argc, char *argv[])
  8. {
  9. Eigen::MatrixXd V, V_uv;
  10. Eigen::MatrixXi F;
  11. // Load a mesh in OFF format
  12. igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/camelhead.off", V, F);
  13. // Find the open boundary
  14. Eigen::VectorXi bnd;
  15. igl::boundary_loop(F,bnd);
  16. // Map the boundary to a circle, preserving edge proportions
  17. Eigen::MatrixXd bnd_uv;
  18. igl::map_vertices_to_circle(V,bnd,bnd_uv);
  19. // Harmonic parametrization for the internal vertices
  20. igl::harmonic(V,F,bnd,bnd_uv,1,V_uv);
  21. // Scale UV to make the texture more clear
  22. V_uv *= 5;
  23. // Plot the mesh
  24. igl::opengl::glfw::Viewer viewer;
  25. viewer.data().set_mesh(V, F);
  26. viewer.data().set_uv(V_uv);
  27. // Attach callback to allow toggling between 3D and 2D view
  28. viewer.callback_key_pressed =
  29. [&V,&V_uv,&F](igl::opengl::glfw::Viewer& viewer, unsigned int key, int /*mod*/)
  30. {
  31. if(key == '3' || key == '2')
  32. {
  33. // Plot the 3D mesh or 2D UV coordinates
  34. viewer.data().set_vertices(key=='3'?V:V_uv);
  35. viewer.data().compute_normals();
  36. viewer.core().align_camera_center(key=='3'?V:V_uv,F);
  37. // key press was used
  38. return true;
  39. }
  40. // key press not used
  41. return false;
  42. };
  43. // Disable wireframe
  44. viewer.data().show_lines = false;
  45. // Draw default checkerboard texture
  46. viewer.data().show_texture = true;
  47. std::cout<<R"(
  48. 3 Show 3D model
  49. 2 Show 2D parametrization
  50. )";
  51. // Launch the viewer
  52. viewer.launch();
  53. }