diff --git a/Surface_mesh_simplification/test/Surface_mesh_simplification/issue_8213.cpp b/Surface_mesh_simplification/test/Surface_mesh_simplification/issue_8213.cpp index be6b26d0fb7..ca4da904544 100644 --- a/Surface_mesh_simplification/test/Surface_mesh_simplification/issue_8213.cpp +++ b/Surface_mesh_simplification/test/Surface_mesh_simplification/issue_8213.cpp @@ -1,44 +1,75 @@ #include +#include + #include + +#define CGAL_CHECK_EXPENSIVE + +#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_TRACE 5 +#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_LT_TRACE 4 + +void Surface_simplification_external_trace(const std::string& s) +{ + std::cout << s << std::endl; +} + #include #include #include #include #include +#include + #include #include #include namespace SMS = CGAL::Surface_mesh_simplification; +namespace PMP = CGAL::Polygon_mesh_processing; -typedef CGAL::Simple_cartesian Kernel; -typedef CGAL::Surface_mesh Surface_mesh; - -int main() { - - std::string filename("data/issue_8213.off"); - - Surface_mesh surface_mesh; - - std::ifstream in(filename); - in >> surface_mesh; - - const size_t target_number_of_faces = 3; - SMS::Face_count_stop_predicate stop(target_number_of_faces); - - std::cout << "Input mesh number of faces: " << surface_mesh.number_of_faces() << ", target number of faces: " << target_number_of_faces << std::endl; - - SMS::edge_collapse( - surface_mesh, - stop, - CGAL::parameters:: - filter(SMS::Bounded_normal_change_filter<>()) - .get_cost(SMS::LindstromTurk_cost()) - .get_placement(SMS::LindstromTurk_placement()) - ); +using Kernel = CGAL::Simple_cartesian; +// using Kernel = CGAL::Exact_predicates_exact_constructions_kernel; +using Surface_mesh = CGAL::Surface_mesh; +int main(int argc, char** argv) +{ std::cout.precision(17); - std::cout << surface_mesh << std::endl; + std::cerr.precision(17); + + const char* filename = (argc > 1) ? argv[1] : "data/issue_8213.off"; + + Surface_mesh sm; + + if(!CGAL::IO::read_polygon_mesh(filename, sm)) + { + std::cerr << "Error: failed to read input data" << std::endl; + return EXIT_FAILURE; + } + + CGAL::Bbox_3 bbox = PMP::bbox(sm); + + std::cout << "Input mesh has " << num_vertices(sm) << " vertices" << std::endl; + std::cout << "Input mesh has " << num_faces(sm) << " faces" << std::endl; + + SMS::Face_count_stop_predicate stop(1); + SMS::edge_collapse(sm, stop, + CGAL::parameters::filter(SMS::Bounded_normal_change_filter<>()) + .get_cost(SMS::LindstromTurk_cost()) + .get_placement(SMS::LindstromTurk_placement())); + + CGAL::IO::write_OFF(std::cout, sm, CGAL::parameters::stream_precision(17)); + + for(auto v : vertices(sm)) + { + // To be within the bounding box isn't a guarantee, but here it is a sufficient test + // to check if things went awry + if(!CGAL::do_overlap(bbox, sm.point(v).bbox())) + { + std::cerr << "Error: " << sm.point(v) << " is outside the initial bbox" << std::endl; + return EXIT_FAILURE; + } + } + return EXIT_SUCCESS; }