main.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #define IGL_HEADER_ONLY
  2. #include <igl/readOFF.h>
  3. #include <igl/viewer/Viewer.h>
  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, unsigned char key, int modifier)
  8. {
  9. if (key == '1')
  10. {
  11. // Clear mesh should be called before drawing the mesh
  12. viewer.clear_mesh();
  13. // Draw_mesh creates or updates the vertices and faces of the displayed mesh.
  14. // If a mesh is already displayed, draw_mesh returns an error if the given V and
  15. // F have size different than the current ones
  16. viewer.set_mesh(V1, F1);
  17. }
  18. else if (key == '2')
  19. {
  20. viewer.clear_mesh();
  21. viewer.set_mesh(V2, F2);
  22. }
  23. return false;
  24. }
  25. int main(int argc, char *argv[])
  26. {
  27. // Load two meshes
  28. igl::readOFF("../shared/bumpy.off", V1, F1);
  29. igl::readOFF("../shared/fertility.off", V2, F2);
  30. igl::Viewer viewer;
  31. // Register a keyboard callback that allows to switch between
  32. // the two loaded meshes
  33. viewer.callback_key_down = &key_down;
  34. viewer.set_mesh(V1, F1);
  35. viewer.launch();
  36. }