main.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <iostream>
  4. #include "tutorial_shared_path.h"
  5. Eigen::MatrixXd V1,V2;
  6. Eigen::MatrixXi F1,F2;
  7. // This function is called every time a keyboard button is pressed
  8. bool key_down(igl::viewer::Viewer& viewer, unsigned char key, int modifier)
  9. {
  10. std::cout<<"Key: "<<key<<" "<<(unsigned int)key<<std::endl;
  11. if (key == '1')
  12. {
  13. // Clear should be called before drawing the mesh
  14. viewer.data.clear();
  15. // Draw_mesh creates or updates the vertices and faces of the displayed mesh.
  16. // If a mesh is already displayed, draw_mesh returns an error if the given V and
  17. // F have size different than the current ones
  18. viewer.data.set_mesh(V1, F1);
  19. viewer.core.align_camera_center(V1,F1);
  20. }
  21. else if (key == '2')
  22. {
  23. viewer.data.clear();
  24. viewer.data.set_mesh(V2, F2);
  25. viewer.core.align_camera_center(V2,F2);
  26. }
  27. return false;
  28. }
  29. int main(int argc, char *argv[])
  30. {
  31. // Load two meshes
  32. igl::readOFF(TUTORIAL_SHARED_PATH "/bumpy.off", V1, F1);
  33. igl::readOFF(TUTORIAL_SHARED_PATH "/fertility.off", V2, F2);
  34. std::cout<<R"(
  35. 1 Switch to bump mesh
  36. 2 Switch to fertility mesh
  37. )";
  38. igl::viewer::Viewer viewer;
  39. // Register a keyboard callback that allows to switch between
  40. // the two loaded meshes
  41. viewer.callback_key_down = &key_down;
  42. viewer.data.set_mesh(V1, F1);
  43. viewer.launch();
  44. }