main.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <igl/readOFF.h>
  2. #include <igl/combine.h>
  3. #include <igl/opengl/glfw/Viewer.h>
  4. //#include <igl/opengl/glfw/imgui/ImGuiPlugin.h>
  5. #include <igl/opengl/glfw/imgui/ImGuiMenu.h>
  6. #include <igl/fast_find_self_intersections.h>
  7. Eigen::MatrixXd V1,V2,V;
  8. Eigen::MatrixXi F1,F2,F;
  9. int main(int argc, char *argv[])
  10. {
  11. // Load two meshes
  12. igl::readOFF(TUTORIAL_SHARED_PATH "/planexy.off", V1, F1);
  13. igl::readOFF(TUTORIAL_SHARED_PATH "/cow.off", V2, F2);
  14. // Combine into one mesh (will produce self-intersections)
  15. igl::combine<Eigen::MatrixXd,Eigen::MatrixXi>({V1,V2},{F1,F2}, V,F);
  16. // Plot the mesh
  17. igl::opengl::glfw::Viewer viewer;
  18. viewer.data().set_mesh(V, F);
  19. Eigen::VectorXi I;
  20. Eigen::MatrixXd edges;
  21. if(igl::fast_find_self_intersections(V,F,I,edges))
  22. {
  23. std::cout<<"Found "<<I.sum()<<" self intersections"<<std::endl;
  24. // plot edge vertices
  25. //viewer.data().add_points(edges, Eigen::RowVector3d(1,0,0));
  26. // Plot the edges of the self intersects
  27. for (unsigned i=0;i<edges.rows(); i+=2)
  28. {
  29. viewer.data().add_edges
  30. (
  31. edges.row(i),
  32. edges.row(i+1),
  33. Eigen::RowVector3d(1,0,0)
  34. );
  35. }
  36. std::cout<<std::endl;
  37. }
  38. viewer.data().set_data(I.cast<double>());
  39. viewer.data().double_sided=true;
  40. igl::opengl::glfw::imgui::ImGuiMenu menu;
  41. //plugin.widgets.push_back(&menu);
  42. menu.callback_draw_viewer_window = [](){};
  43. // Launch the viewer
  44. viewer.launch();
  45. }