main.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include <igl/readOFF.h>
  2. #include <igl/viewer/Viewer.h>
  3. #include <sstream>
  4. #include "tutorial_shared_path.h"
  5. Eigen::MatrixXd V;
  6. Eigen::MatrixXi F;
  7. int main(int argc, char *argv[])
  8. {
  9. // Load a mesh in OFF format
  10. igl::readOFF(TUTORIAL_SHARED_PATH "/bunny.off", V, F);
  11. // Find the bounding box
  12. Eigen::Vector3d m = V.colwise().minCoeff();
  13. Eigen::Vector3d M = V.colwise().maxCoeff();
  14. // Corners of the bounding box
  15. Eigen::MatrixXd V_box(8,3);
  16. V_box <<
  17. m(0), m(1), m(2),
  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. // Edges of the bounding box
  26. Eigen::MatrixXi E_box(12,2);
  27. E_box <<
  28. 0, 1,
  29. 1, 2,
  30. 2, 3,
  31. 3, 0,
  32. 4, 5,
  33. 5, 6,
  34. 6, 7,
  35. 7, 4,
  36. 0, 4,
  37. 1, 5,
  38. 2, 6,
  39. 7 ,3;
  40. // Plot the mesh
  41. igl::viewer::Viewer viewer;
  42. viewer.data.set_mesh(V, F);
  43. // Plot the corners of the bounding box as points
  44. viewer.data.add_points(V_box,Eigen::RowVector3d(1,0,0));
  45. // Plot the edges of the bounding box
  46. for (unsigned i=0;i<E_box.rows(); ++i)
  47. viewer.data.add_edges
  48. (
  49. V_box.row(E_box(i,0)),
  50. V_box.row(E_box(i,1)),
  51. Eigen::RowVector3d(1,0,0)
  52. );
  53. // Plot labels with the coordinates of bounding box vertices
  54. std::stringstream l1;
  55. l1 << m(0) << ", " << m(1) << ", " << m(2);
  56. viewer.data.add_label(m,l1.str());
  57. std::stringstream l2;
  58. l2 << M(0) << ", " << M(1) << ", " << M(2);
  59. viewer.data.add_label(M,l2.str());
  60. // Launch the viewer
  61. viewer.launch();
  62. }