main.cpp 1.1 KB

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