main.cpp 1.5 KB

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