main.cpp 1.5 KB

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