main.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <igl/readOFF.h>
  2. #include <igl/opengl/glfw/Viewer.h>
  3. #include <igl/opengl/glfw/imgui/ImGuiMenu.h>
  4. #include <sstream>
  5. #include "tutorial_shared_path.h"
  6. Eigen::MatrixXd V;
  7. Eigen::MatrixXi F;
  8. int main(int argc, char *argv[])
  9. {
  10. // Load a mesh in OFF format
  11. igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
  12. // Find the bounding box
  13. Eigen::Vector3d m = V.colwise().minCoeff();
  14. Eigen::Vector3d M = V.colwise().maxCoeff();
  15. // Corners of the bounding box
  16. Eigen::MatrixXd V_box(8,3);
  17. V_box <<
  18. m(0), m(1), m(2),
  19. M(0), m(1), m(2),
  20. M(0), M(1), m(2),
  21. m(0), M(1), m(2),
  22. m(0), m(1), M(2),
  23. M(0), m(1), M(2),
  24. M(0), M(1), M(2),
  25. m(0), M(1), M(2);
  26. // Edges of the bounding box
  27. Eigen::MatrixXi E_box(12,2);
  28. E_box <<
  29. 0, 1,
  30. 1, 2,
  31. 2, 3,
  32. 3, 0,
  33. 4, 5,
  34. 5, 6,
  35. 6, 7,
  36. 7, 4,
  37. 0, 4,
  38. 1, 5,
  39. 2, 6,
  40. 7 ,3;
  41. // Plot the mesh
  42. igl::opengl::glfw::Viewer viewer;
  43. viewer.data().set_mesh(V, F);
  44. // Plot the corners of the bounding box as points
  45. viewer.data().add_points(V_box,Eigen::RowVector3d(1,0,0));
  46. // Plot the edges of the bounding box
  47. for (unsigned i=0;i<E_box.rows(); ++i)
  48. viewer.data().add_edges
  49. (
  50. V_box.row(E_box(i,0)),
  51. V_box.row(E_box(i,1)),
  52. Eigen::RowVector3d(1,0,0)
  53. );
  54. // Plot labels with the coordinates of bounding box vertices
  55. std::stringstream l1;
  56. l1 << m(0) << ", " << m(1) << ", " << m(2);
  57. viewer.data().add_label(m,l1.str());
  58. std::stringstream l2;
  59. l2 << M(0) << ", " << M(1) << ", " << M(2);
  60. viewer.data().add_label(M,l2.str());
  61. // Rendering of text labels is handled by ImGui, so we need to enable the ImGui
  62. // plugin to show text labels.
  63. igl::opengl::glfw::imgui::ImGuiMenu menu;
  64. menu.callback_draw_viewer_window = [](){};
  65. viewer.plugins.push_back(&menu);
  66. // Launch the viewer
  67. viewer.launch();
  68. }