mesh_boolean_BACKUP_15219.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <test_common.h>
  2. #include <vector>
  3. #include <igl/copyleft/cgal/mesh_boolean.h>
  4. #include <igl/MeshBooleanType.h>
  5. #include <igl/exterior_edges.h>
  6. #include <igl/is_vertex_manifold.h>
  7. #include <igl/unique_edge_map.h>
  8. #include <igl/is_edge_manifold.h>
  9. namespace {
  10. template<typename DerivedF>
  11. void assert_no_exterior_edges(
  12. const Eigen::PlainObjectBase<DerivedF>& F) {
  13. Eigen::MatrixXi Eb;
  14. igl::exterior_edges(F, Eb);
  15. REQUIRE (Eb.rows() == 0);
  16. }
  17. template<typename DerivedV, typename DerivedF>
  18. void assert_is_manifold(
  19. const Eigen::PlainObjectBase<DerivedV>& V,
  20. const Eigen::PlainObjectBase<DerivedF>& F) {
  21. Eigen::MatrixXi B;
  22. REQUIRE (igl::is_vertex_manifold(F, B));
  23. REQUIRE (igl::is_edge_manifold(F));
  24. }
  25. template<typename DerivedV, typename DerivedF>
  26. void assert_genus_eq(
  27. const Eigen::PlainObjectBase<DerivedV>& V,
  28. const Eigen::PlainObjectBase<DerivedF>& F,
  29. const int genus) {
  30. const int num_vertices = V.rows();
  31. const int num_faces = F.rows();
  32. Eigen::Matrix<
  33. typename DerivedF::Scalar,
  34. Eigen::Dynamic,
  35. Eigen::Dynamic>
  36. E, uE, EMAP;
  37. std::vector<std::vector<size_t> > uE2E;
  38. igl::unique_edge_map(F, E, uE, EMAP, uE2E);
  39. const int num_edges = uE.rows();
  40. const int euler = num_vertices - num_edges + num_faces;
  41. REQUIRE (2 - 2 * genus == euler);
  42. }
  43. <<<<<<< HEAD
  44. TEST(MeshBoolean, TwoCubes) {
  45. Eigen::MatrixXd V1, TC;
  46. =======
  47. }
  48. TEST_CASE("MeshBoolean: TwoCubes", "[igl/copyleft/boolean]") {
  49. Eigen::MatrixXd V1;
  50. >>>>>>> f6b406427400ed7ddb56cfc2577b6af571827c8c
  51. Eigen::MatrixXi F1;
  52. test_common::load_mesh("two-boxes-bad-self-union.ply", V1, F1, TC);
  53. Eigen::MatrixXd V2(0, 3);
  54. Eigen::MatrixXi F2(0, 3);
  55. Eigen::MatrixXd Vo;
  56. Eigen::MatrixXi Fo;
  57. igl::copyleft::cgal::mesh_boolean(V1, F1, V2, F2,
  58. igl::MESH_BOOLEAN_TYPE_UNION,
  59. Vo, Fo);
  60. assert_no_exterior_edges(Fo);
  61. assert_is_manifold(Vo, Fo);
  62. assert_genus_eq(Vo, Fo, 0);
  63. }
  64. TEST_CASE("MeshBoolean: MinusTest", "[igl/copyleft/boolean]") {
  65. // Many thanks to Eric Yao for submitting this test case.
  66. Eigen::MatrixXd V1, V2, Vo, TC;
  67. Eigen::MatrixXi F1, F2, Fo;
  68. test_common::load_mesh("boolean_minus_test_cube.obj", V1, F1, TC);
  69. test_common::load_mesh("boolean_minus_test_green.obj", V2, F2, TC);
  70. igl::copyleft::cgal::mesh_boolean(V1, F1, V2, F2,
  71. igl::MESH_BOOLEAN_TYPE_MINUS,
  72. Vo, Fo);
  73. assert_no_exterior_edges(Fo);
  74. assert_is_manifold(Vo, Fo);
  75. assert_genus_eq(Vo, Fo, 1);
  76. }
  77. <<<<<<< HEAD
  78. TEST(MeshBoolean, IntersectWithSelf) {
  79. Eigen::MatrixXd V1, Vo, TC;
  80. =======
  81. TEST_CASE("MeshBoolean: IntersectWithSelf", "[igl/copyleft/boolean]") {
  82. Eigen::MatrixXd V1, Vo;
  83. >>>>>>> f6b406427400ed7ddb56cfc2577b6af571827c8c
  84. Eigen::MatrixXi F1, Fo;
  85. test_common::load_mesh("cube.obj", V1, F1, TC);
  86. igl::copyleft::cgal::mesh_boolean(V1, F1, V1, F1,
  87. igl::MESH_BOOLEAN_TYPE_INTERSECT,
  88. Vo, Fo);
  89. assert_no_exterior_edges(Fo);
  90. assert_is_manifold(Vo, Fo);
  91. assert_genus_eq(Vo, Fo, 0);
  92. }