fast_find_intersections.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "test_common.h"
  2. #include <igl/fast_find_intersections.h>
  3. #include <igl/fast_find_self_intersections.h>
  4. #include <igl/combine.h>
  5. #include <igl/unique.h>
  6. #include <igl/matlab_format.h>
  7. #include <iostream>
  8. TEST_CASE("fast_find_intersections: cube-triangle", "[igl]")
  9. {
  10. Eigen::MatrixXd V;
  11. Eigen::MatrixXi F;
  12. igl::read_triangle_mesh(test_common::data_path("cube.obj"), V, F);
  13. auto dims=(V.colwise().maxCoeff()-V.colwise().minCoeff())*2;
  14. auto cz=(V.col(2).minCoeff()+V.col(2).maxCoeff())/2;
  15. // add a triangle intersecting cube
  16. Eigen::MatrixXd Vp(3,3);
  17. Vp << V.col(0).minCoeff()-dims(0), V.col(1).minCoeff()-dims(1), cz,
  18. V.col(0).minCoeff()-dims(0), V.col(1).maxCoeff()+dims(1)*3, cz,
  19. V.col(0).maxCoeff()+dims(0)*3, V.col(1).maxCoeff()-dims(1), cz;
  20. Eigen::MatrixXi Fp(1,3);
  21. Fp << 0,1,2;
  22. Eigen::MatrixXi IF,EE;
  23. Eigen::MatrixXd EV;
  24. Eigen::VectorXi EI;
  25. igl::fast_find_intersections(V,F,Vp,Fp,false,false,IF,EV,EE,EI);
  26. {
  27. Eigen::VectorXi I;
  28. igl::unique(IF,I);
  29. // should have 8 triangles that are intersecting plane (so 9 unique)
  30. REQUIRE( I.size()== 9 );
  31. }
  32. // all triangles from the cube intersect the same plane
  33. REQUIRE( (IF.col(1).array()==0).all() );
  34. // and 8 line edges
  35. REQUIRE( EE.rows()==8 );
  36. REQUIRE( EV.rows()==2*8 );
  37. REQUIRE( EI.size()==8 );
  38. // TODO: check if the edges are at the right place
  39. }
  40. TEST_CASE("fast_find_intersections: coplanar", "[igl]")
  41. {
  42. }