main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <igl/boundary_loop.h>
  2. #include <igl/harmonic.h>
  3. #include <igl/map_vertices_to_circle.h>
  4. #include <igl/readOFF.h>
  5. #include <igl/viewer/Viewer.h>
  6. #include "tutorial_shared_path.h"
  7. Eigen::MatrixXd V;
  8. Eigen::MatrixXi F;
  9. Eigen::MatrixXd V_uv;
  10. bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
  11. {
  12. if (key == '1')
  13. {
  14. // Plot the 3D mesh
  15. viewer.data.set_mesh(V,F);
  16. viewer.core.align_camera_center(V,F);
  17. }
  18. else if (key == '2')
  19. {
  20. // Plot the mesh in 2D using the UV coordinates as vertex coordinates
  21. viewer.data.set_mesh(V_uv,F);
  22. viewer.core.align_camera_center(V_uv,F);
  23. }
  24. viewer.data.compute_normals();
  25. return false;
  26. }
  27. int main(int argc, char *argv[])
  28. {
  29. // Load a mesh in OFF format
  30. igl::readOFF(TUTORIAL_SHARED_PATH "/camelhead.off", V, F);
  31. // Find the open boundary
  32. Eigen::VectorXi bnd;
  33. igl::boundary_loop(F,bnd);
  34. // Map the boundary to a circle, preserving edge proportions
  35. Eigen::MatrixXd bnd_uv;
  36. igl::map_vertices_to_circle(V,bnd,bnd_uv);
  37. // Harmonic parametrization for the internal vertices
  38. igl::harmonic(V,F,bnd,bnd_uv,1,V_uv);
  39. // Scale UV to make the texture more clear
  40. V_uv *= 5;
  41. // Plot the mesh
  42. igl::viewer::Viewer viewer;
  43. viewer.data.set_mesh(V, F);
  44. viewer.data.set_uv(V_uv);
  45. viewer.callback_key_down = &key_down;
  46. // Disable wireframe
  47. viewer.core.show_lines = false;
  48. // Draw checkerboard texture
  49. viewer.core.show_texture = true;
  50. // Launch the viewer
  51. viewer.launch();
  52. }