main.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <igl/boundary_loop.h>
  4. #include <igl/lscm.h>
  5. Eigen::MatrixXd V;
  6. Eigen::MatrixXi F;
  7. Eigen::MatrixXd V_uv;
  8. bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
  9. {
  10. if (key == '1')
  11. // Plot the 3D mesh
  12. viewer.set_mesh(V,F);
  13. else if (key == '2')
  14. // Plot the mesh in 2D using the UV coordinates as vertex coordinates
  15. viewer.set_mesh(V_uv,F);
  16. viewer.compute_normals();
  17. return false;
  18. }
  19. int main(int argc, char *argv[])
  20. {
  21. using namespace Eigen;
  22. using namespace std;
  23. // Load a mesh in OFF format
  24. igl::readOFF("../shared/camelhead.off", V, F);
  25. // Fix two points on the boundary
  26. VectorXi bnd,b(2,1);
  27. igl::boundary_loop(V,F,bnd);
  28. b(0) = bnd(0);
  29. b(1) = bnd(round(bnd.size()/2));
  30. MatrixXd bc(2,2);
  31. bc<<0,0,1,0;
  32. // LSCM parametrization
  33. igl::lscm(V,F,b,bc,V_uv);
  34. // Scale the uv
  35. V_uv *= 5;
  36. // Plot the mesh
  37. igl::Viewer viewer;
  38. viewer.set_mesh(V, F);
  39. viewer.set_uv(V_uv);
  40. viewer.callback_key_down = &key_down;
  41. // Disable wireframe
  42. viewer.options.show_lines = false;
  43. // Draw checkerboard texture
  44. viewer.options.show_texture = true;
  45. // Launch the viewer
  46. viewer.launch();
  47. }