main.cpp 1.4 KB

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