main.cpp 1.3 KB

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