Files
igl/tutorial/723_FastFindSelfIntersections/main.cpp
T
Vladimir S. FONOV 1d007f4252 Fast mesh-to-mesh intersection and mesh self intersection without CGAL (#2109)
* Added code for fast triangle-triangle intersection checking and function for fast detection of mesh self-intersections and mesh-to-mesh intersections withoug CGAL

* Fixed auto parameters in lambda helper function

* Replaced cbegin/cend with begin/end

* Fixed auto parameters in lambda helper function

* Added tests for igl::tri_tri_intersection_test_3d

* Added more tests, converted macros in Guigue2003_tri_tri_intersect.cpp to proper c++

* Renamed files and function names to follow IGL guidelines,
added reference to the original license for tri_tri_intersect
2023-03-14 11:37:22 -04:00

59 lines
1.5 KiB
C++
Executable File

#include <igl/readOFF.h>
#include <igl/combine.h>
#include <igl/opengl/glfw/Viewer.h>
//#include <igl/opengl/glfw/imgui/ImGuiPlugin.h>
#include <igl/opengl/glfw/imgui/ImGuiMenu.h>
#include <igl/fast_find_self_intersections.h>
Eigen::MatrixXd V1,V2,V;
Eigen::MatrixXi F1,F2,F;
int main(int argc, char *argv[])
{
// Load two meshes
igl::readOFF(TUTORIAL_SHARED_PATH "/planexy.off", V1, F1);
igl::readOFF(TUTORIAL_SHARED_PATH "/cow.off", V2, F2);
// Combine into one mesh (will produce self-intersections)
igl::combine<Eigen::MatrixXd,Eigen::MatrixXi>({V1,V2},{F1,F2}, V,F);
// Plot the mesh
igl::opengl::glfw::Viewer viewer;
viewer.data().set_mesh(V, F);
Eigen::VectorXi I;
Eigen::MatrixXd edges;
if(igl::fast_find_self_intersections(V,F,I,edges))
{
std::cout<<"Found "<<I.sum()<<" self intersections"<<std::endl;
// plot edge vertices
//viewer.data().add_points(edges, Eigen::RowVector3d(1,0,0));
// Plot the edges of the self intersects
for (unsigned i=0;i<edges.rows(); i+=2)
{
viewer.data().add_edges
(
edges.row(i),
edges.row(i+1),
Eigen::RowVector3d(1,0,0)
);
}
std::cout<<std::endl;
}
viewer.data().set_data(I.cast<double>());
viewer.data().double_sided=true;
igl::opengl::glfw::imgui::ImGuiMenu menu;
//plugin.widgets.push_back(&menu);
menu.callback_draw_viewer_window = [](){};
// Launch the viewer
viewer.launch();
}