diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data_snapping/pig.stl b/Polygon_mesh_processing/test/Polygon_mesh_processing/data_snapping/pig.stl new file mode 100644 index 00000000000..6bc2a5bbe38 Binary files /dev/null and b/Polygon_mesh_processing/test/Polygon_mesh_processing/data_snapping/pig.stl differ diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_non_conforming_snapping.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_non_conforming_snapping.cpp index c89b07283a9..839a1417989 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_non_conforming_snapping.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/test_pmp_non_conforming_snapping.cpp @@ -7,12 +7,17 @@ #include #include +#include +#include #include +#include +#include #include #include #include +#include #include namespace PMP = CGAL::Polygon_mesh_processing; @@ -25,6 +30,41 @@ typedef CGAL::Polyhedron_3 Exact_poly typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::Surface_mesh Surface_mesh; +template +void read_mesh(const char* filename, + Mesh& sm) +{ + typedef typename Kernel::Point_3 Point; + + std::ifstream in(filename); + if(!in.good()) + { + std::cerr << "Error: can't read file: " << filename << std::endl; + std::exit(1); + } + + std::string fn(filename); + if(fn.substr(fn.find_last_of(".") + 1) == "stl") + { + std::vector points; + std::vector > faces; + CGAL::read_STL(in, points, faces); + + if(!CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces)) + std::cerr << "W: File does not describe a polygon mesh" << std::endl; + + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, faces, sm); + } + else // off reading + { + if(!in || !(in >> sm)) + { + std::cerr << "Error: cannot open mesh\n"; + return; + } + } +} + template void test(const char* filename, const double large_tolerance, @@ -34,13 +74,7 @@ void test(const char* filename, typedef typename Kernel::FT FT; Mesh sm; - - std::ifstream in(filename); - if(!in || !(in >> sm)) - { - std::cerr << "Error: cannot open mesh\n"; - return; - } + read_mesh(filename, sm); std::cout << "------------------" << std::endl; std::cout << "num v/f: " << num_vertices(sm) << " " << num_faces(sm) << std::endl; @@ -95,6 +129,7 @@ void test(const char* filename, const double small_tolerance) { std::cout << "######################## TEST FILE: " << filename << " ################## " << std::endl; + std::cout << "~~~~~~~~~~~ TEST EPECK POLYHEDRON ~~~~~~~~~~~" << std::endl; test(filename, large_tolerance, small_tolerance); @@ -115,6 +150,8 @@ int main(int, char**) test("data_snapping/real_data.off", 1., 0.05); test("data_snapping/real_data_2.off", 2, 0.1); + test("data_snapping/pig.stl", 20, 0.01); + return EXIT_SUCCESS; }