points_inside_component.cpp 2.7 KB

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