main.cpp 1.3 KB

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