main.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <igl/boundary_loop.h>
  2. #include <igl/readOFF.h>
  3. #include <igl/viewer/Viewer.h>
  4. #include <igl/lscm.h>
  5. #include "tutorial_shared_path.h"
  6. Eigen::MatrixXd V;
  7. Eigen::MatrixXi F;
  8. Eigen::MatrixXd V_uv;
  9. bool key_down(igl::viewer::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. using namespace Eigen;
  29. using namespace std;
  30. // Load a mesh in OFF format
  31. igl::readOFF(TUTORIAL_SHARED_PATH "/camelhead.off", V, F);
  32. // Fix two points on the boundary
  33. VectorXi bnd,b(2,1);
  34. igl::boundary_loop(F,bnd);
  35. b(0) = bnd(0);
  36. b(1) = bnd(round(bnd.size()/2));
  37. MatrixXd bc(2,2);
  38. bc<<0,0,1,0;
  39. // LSCM parametrization
  40. igl::lscm(V,F,b,bc,V_uv);
  41. // Scale the uv
  42. V_uv *= 5;
  43. // Plot the mesh
  44. igl::viewer::Viewer viewer;
  45. viewer.data.set_mesh(V, F);
  46. viewer.data.set_uv(V_uv);
  47. viewer.callback_key_down = &key_down;
  48. // Disable wireframe
  49. viewer.core.show_lines = false;
  50. // Draw checkerboard texture
  51. viewer.core.show_texture = true;
  52. // Launch the viewer
  53. viewer.launch();
  54. }