points_inside_component.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <test_common.h>
  2. #include <igl/copyleft/cgal/points_inside_component.h>
  3. #include <limits>
  4. namespace PointInsideComponentHelper {
  5. TEST_CASE("PointInsideComponent: simple", "[igl/copyleft/cgal]")
  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. Eigen::MatrixXd V1;
  23. Eigen::MatrixXi F1;
  24. test_common::load_mesh("cube.obj", V1, F1);
  25. const double EPS = std::numeric_limits<double>::epsilon();
  26. Eigen::MatrixXd P(6, 3);
  27. P << 0.5 + EPS, 0.0, 0.0,
  28. 0.0, 0.5 + EPS, 0.0,
  29. 0.0, 0.0, 0.5 + EPS,
  30. 0.5 - EPS, 0.0, 0.0,
  31. 0.0, 0.5 - EPS, 0.0,
  32. 0.0, 0.0, 0.5 - EPS;
  33. Eigen::VectorXi inside;
  34. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P, inside));
  35. REQUIRE (inside[0] == 0);
  36. REQUIRE (inside[1] == 0);
  37. REQUIRE (inside[2] == 0);
  38. REQUIRE (inside[3] == 1);
  39. REQUIRE (inside[4] == 1);
  40. REQUIRE (inside[5] == 1);
  41. }
  42. TEST_CASE("PointInsideComponent: near_corner", "[igl/copyleft/cgal]")
  43. Eigen::MatrixXd V1;
  44. Eigen::MatrixXi F1;
  45. test_common::load_mesh("cube.obj", V1, F1);
  46. const double EPS = std::numeric_limits<double>::epsilon();
  47. Eigen::MatrixXd P_out(8, 3);
  48. P_out << 0.5 + EPS, 0.5 + EPS, 0.5 + EPS,
  49. -0.5 - EPS, 0.5 + EPS, 0.5 + EPS,
  50. 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. Eigen::VectorXi inside;
  57. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P_out, inside));
  58. REQUIRE ((inside.array()==0).all());
  59. Eigen::MatrixXd P_in(8, 3);
  60. P_in << 0.5 - EPS, 0.5 - EPS, 0.5 - EPS,
  61. -0.5 + EPS, 0.5 - EPS, 0.5 - EPS,
  62. 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. CHECK_NOTHROW (igl::copyleft::cgal::points_inside_component(V1, F1, P_in, inside));
  69. REQUIRE ((inside.array()==1).all());
  70. }
  71. }