points_inside_component.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <test_common.h>
  2. #include <igl/copyleft/cgal/points_inside_component.h>
  3. #include <limits>
  4. TEST_CASE("PointInsideComponent: simple", "[igl/copyleft/cgal]")
  5. {
  6. Eigen::MatrixXd V1;
  7. Eigen::MatrixXi F1;
  8. test_common::load_mesh("cube.obj", V1, F1);
  9. Eigen::MatrixXd P(4, 3);
  10. P << 0.0, 0.0, 0.0,
  11. 1.0, 0.0, 0.0,
  12. 0.0, 1.0, 0.0,
  13. 0.0, 0.0, 1.0;
  14. Eigen::VectorXi inside;
  15. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P, inside));
  16. REQUIRE (inside[0] == 1);
  17. REQUIRE (inside[1] == 0);
  18. REQUIRE (inside[2] == 0);
  19. REQUIRE (inside[3] == 0);
  20. }
  21. TEST_CASE("PointInsideComponent: near_boundary", "[igl/copyleft/cgal]")
  22. {
  23. Eigen::MatrixXd V1;
  24. Eigen::MatrixXi F1;
  25. test_common::load_mesh("cube.obj", V1, F1);
  26. const double EPS = std::numeric_limits<double>::epsilon();
  27. Eigen::MatrixXd P(6, 3);
  28. P << 0.5 + EPS, 0.0, 0.0,
  29. 0.0, 0.5 + EPS, 0.0,
  30. 0.0, 0.0, 0.5 + EPS,
  31. 0.5 - EPS, 0.0, 0.0,
  32. 0.0, 0.5 - EPS, 0.0,
  33. 0.0, 0.0, 0.5 - EPS;
  34. Eigen::VectorXi inside;
  35. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P, inside));
  36. REQUIRE (inside[0] == 0);
  37. REQUIRE (inside[1] == 0);
  38. REQUIRE (inside[2] == 0);
  39. REQUIRE (inside[3] == 1);
  40. REQUIRE (inside[4] == 1);
  41. REQUIRE (inside[5] == 1);
  42. }
  43. TEST_CASE("PointInsideComponent: near_corner", "[igl/copyleft/cgal]")
  44. {
  45. Eigen::MatrixXd V1;
  46. Eigen::MatrixXi F1;
  47. test_common::load_mesh("cube.obj", V1, F1);
  48. const double EPS = std::numeric_limits<double>::epsilon();
  49. Eigen::MatrixXd P_out(8, 3);
  50. P_out << 0.5 + EPS, 0.5 + EPS, 0.5 + EPS,
  51. -0.5 - EPS, 0.5 + EPS, 0.5 + EPS,
  52. 0.5 + EPS,-0.5 - EPS, 0.5 + EPS,
  53. -0.5 - EPS,-0.5 - EPS, 0.5 + EPS,
  54. 0.5 + EPS, 0.5 + EPS,-0.5 - EPS,
  55. -0.5 - EPS, 0.5 + EPS,-0.5 - EPS,
  56. 0.5 + EPS,-0.5 - EPS,-0.5 - EPS,
  57. -0.5 - EPS,-0.5 - EPS,-0.5 - EPS;
  58. Eigen::VectorXi inside;
  59. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P_out, inside));
  60. REQUIRE ((inside.array()==0).all());
  61. Eigen::MatrixXd P_in(8, 3);
  62. P_in << 0.5 - EPS, 0.5 - EPS, 0.5 - EPS,
  63. -0.5 + EPS, 0.5 - EPS, 0.5 - EPS,
  64. 0.5 - EPS,-0.5 + EPS, 0.5 - EPS,
  65. -0.5 + EPS,-0.5 + EPS, 0.5 - EPS,
  66. 0.5 - EPS, 0.5 - EPS,-0.5 + EPS,
  67. -0.5 + EPS, 0.5 - EPS,-0.5 + EPS,
  68. 0.5 - EPS,-0.5 + EPS,-0.5 + EPS,
  69. -0.5 + EPS,-0.5 + EPS,-0.5 + EPS;
  70. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P_in, inside));
  71. REQUIRE ((inside.array()==1).all());
  72. }