mesh_intersections.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <test_common.h>
  2. #include <igl/fast_find_mesh_selfintersect.h>
  3. #include <igl/fast_find_mesh_intersect.h>
  4. #include <igl/combine.h>
  5. TEST_CASE("fast_find_mesh_selfintersect: negative", "[igl]")
  6. {
  7. Eigen::MatrixXd V;
  8. Eigen::MatrixXi F;
  9. Eigen::VectorXi I;
  10. igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F);
  11. REQUIRE (! igl::fast_find_mesh_selfintersect(V,F,I) );
  12. REQUIRE ( I.sum()==0);
  13. }
  14. TEST_CASE("fast_find_mesh_selfintersect: positive", "[igl]")
  15. {
  16. Eigen::MatrixXd V;
  17. Eigen::MatrixXi F;
  18. igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F);
  19. auto dims=(V.colwise().maxCoeff()-V.colwise().minCoeff())*2;
  20. auto cz=(V.col(2).minCoeff()+V.col(2).maxCoeff())/2;
  21. // add a triangle intersecting cube
  22. Eigen::MatrixXd Vp(3,3);
  23. Vp << V.col(0).minCoeff()-dims(0), V.col(1).minCoeff()-dims(1), cz,
  24. V.col(0).minCoeff()-dims(0), V.col(1).maxCoeff()+dims(1)*3, cz,
  25. V.col(0).maxCoeff()+dims(0)*3, V.col(1).maxCoeff()-dims(1), cz;
  26. Eigen::MatrixXi Fp(1,3);
  27. Fp << 0,1,2;
  28. Eigen::MatrixXd V_;
  29. Eigen::MatrixXi F_;
  30. igl::combine<Eigen::MatrixXd,Eigen::MatrixXi>({V,Vp},{F,Fp}, V_,F_);
  31. Eigen::VectorXi I;
  32. Eigen::MatrixXd edges;
  33. REQUIRE ( igl::fast_find_mesh_selfintersect(V_,F_,I,edges) );
  34. // should have 9 triangles that are intersecting each other
  35. REQUIRE ( I.sum()==9);
  36. // and 16 line edges
  37. REQUIRE ( edges.rows()==16);
  38. // plane that we added intersects other triangles
  39. REQUIRE ( I(F_.rows()-1)!=0 );
  40. // TODO: check if the edges are at the right place (?)
  41. }
  42. TEST_CASE("fast_find_mesh_intersect:", "[igl]")
  43. {
  44. Eigen::MatrixXd V;
  45. Eigen::MatrixXi F;
  46. igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F);
  47. auto dims=(V.colwise().maxCoeff()-V.colwise().minCoeff())*2;
  48. auto cz=(V.col(2).minCoeff()+V.col(2).maxCoeff())/2;
  49. // add a triangle intersecting cube
  50. Eigen::MatrixXd Vp(3,3);
  51. Vp << V.col(0).minCoeff()-dims(0), V.col(1).minCoeff()-dims(1), cz,
  52. V.col(0).minCoeff()-dims(0), V.col(1).maxCoeff()+dims(1)*3, cz,
  53. V.col(0).maxCoeff()+dims(0)*3, V.col(1).maxCoeff()-dims(1), cz;
  54. Eigen::MatrixXi Fp(1,3);
  55. Fp << 0,1,2;
  56. Eigen::MatrixXi I;
  57. Eigen::MatrixXd edges;
  58. igl::fast_find_mesh_intersect(V,F,Vp,Fp,I,edges);
  59. // should have 8 triangles that are intersecting plane
  60. REQUIRE ( I.rows()==8);
  61. // all triangles from the cube intersect the same plane
  62. REQUIRE( (I.col(1).array()==0).all());
  63. // and 16 line edges
  64. REQUIRE ( edges.rows()==16);
  65. // TODO: check if the edges are at the right place
  66. }