main.cpp 1.6 KB

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