From c8654724e2aa2fd2f7c224b1c1274a18d1c17a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 13 Jun 2022 12:41:57 +0200 Subject: [PATCH] update test to check we can prevent collapses and flips --- .../test_remove_caps_needles.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_remove_caps_needles.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_remove_caps_needles.cpp index ed99bc0b0b7..b57a3dc8e8d 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_remove_caps_needles.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_remove_caps_needles.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -116,7 +117,49 @@ void test_with_envelope(std::string filename, double eps) std::cout << " Output mesh has self-intersections\n"; } +bool same_meshes(const Mesh& m1, const Mesh& m2) +{ + std::size_t c=0, m1_only=0, m2_only=0; + PMP::match_faces(m1, m2, CGAL::Counting_output_iterator(&c) + , CGAL::Counting_output_iterator(&m1_only) + , CGAL::Counting_output_iterator(&m2_only)); + return m1_only==0 && m2_only==0; +} +void test_parameters_on_pig(std::string filename) +{ + std::ifstream input(filename); + Mesh mesh, bk; + if (!input || !(input >> mesh) || !CGAL::is_triangle_mesh(mesh)) { + std::cerr << "Not a valid input file." << std::endl; + exit(EXIT_FAILURE); + } + + bk=mesh; + + PMP::experimental::remove_almost_degenerate_faces(mesh, + std::cos(160. / 180 * CGAL_PI), + 4, + 9999 /*no_constraints*/); + assert(vertices(mesh).size()!=vertices(bk).size()); + + mesh=bk; + PMP::experimental::remove_almost_degenerate_faces(mesh, + std::cos(160. / 180 * CGAL_PI), + 4, + 0.000000000000001); // no-collapse but flips + assert(vertices(mesh).size()==vertices(bk).size()); + assert(!same_meshes(mesh,bk)); + + mesh=bk; + PMP::experimental::remove_almost_degenerate_faces(mesh, + std::cos(160. / 180 * CGAL_PI), + 4, + 0.000000000000001, + CGAL::parameters::flip_triangle_height_threshold(0.000000000000001)); // no-collapse and no flip + assert(vertices(mesh).size()==vertices(bk).size()); + assert(same_meshes(mesh,bk)); +} int main(int argc, char** argv) { @@ -129,5 +172,9 @@ int main(int argc, char** argv) if (argc==3) test_with_envelope(filename, atof(argv[2])); + // only run that test with pig.off + if (argc==1) + test_parameters_on_pig(filename); + return 0; }