diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp index f92c252014a..b1ed89019f6 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/edge_collapse_garland_heckbert.cpp @@ -1,14 +1,14 @@ #include #include -#include #include #include #include +#include #include -#include #include +#include #include typedef CGAL::Simple_cartesian Kernel; @@ -18,45 +18,31 @@ typedef CGAL::Surface_mesh Surface_mesh; namespace SMS = CGAL::Surface_mesh_simplification; -int main(int argc, char** argv) +typedef SMS::GarlandHeckbert_plane_policies Classic_plane; +typedef SMS::GarlandHeckbert_probabilistic_plane_policies Prob_plane; +typedef SMS::GarlandHeckbert_triangle_policies Classic_tri; +typedef SMS::GarlandHeckbert_probabilistic_triangle_policies Prob_tri; + +template +void collapse_gh(Surface_mesh& mesh, + const double ratio) { - Surface_mesh surface_mesh; - const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cube-meshed.off"); - std::ifstream is(filename); - if(!is || !(is >> surface_mesh)) - { - std::cerr << "Failed to read input mesh: " << filename << std::endl; - return EXIT_FAILURE; - } - - if(!CGAL::is_triangle_mesh(surface_mesh)) - { - std::cerr << "Input geometry is not triangulated." << std::endl; - return EXIT_FAILURE; - } - - std::cout << "Input mesh has " << num_vertices(surface_mesh) << " nv " - << num_edges(surface_mesh) << " ne " - << num_faces(surface_mesh) << " nf" << std::endl; - std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); - const double ratio = (argc > 2) ? std::stod(argv[2]) : 0.2; SMS::Count_ratio_stop_predicate stop(ratio); // Garland&Heckbert simplification policies - typedef typename SMS::GarlandHeckbert_plane_policies GH_policies; - typedef typename GH_policies::Get_cost GH_cost; - typedef typename GH_policies::Get_placement GH_placement; + + typedef typename GHPolicies::Get_cost GH_cost; + typedef typename GHPolicies::Get_placement GH_placement; typedef SMS::Bounded_normal_change_placement Bounded_GH_placement; - GH_policies gh_policies(surface_mesh); + GHPolicies gh_policies(mesh); const GH_cost& gh_cost = gh_policies.get_cost(); const GH_placement& gh_placement = gh_policies.get_placement(); Bounded_GH_placement placement(gh_placement); - std::cout << "Collapsing edges of mesh: " << filename << ", aiming for " << 100 * ratio << "% of the input edges..." << std::endl; - int r = SMS::edge_collapse(surface_mesh, stop, + int r = SMS::edge_collapse(mesh, stop, CGAL::parameters::get_cost(gh_cost) .get_placement(placement)); @@ -66,9 +52,47 @@ int main(int argc, char** argv) << std::chrono::duration_cast(end_time - start_time).count() << "ms" << std::endl; - std::cout << "\nFinished!\n" << r << " edges removed.\n" << surface_mesh.number_of_edges() << " final edges.\n"; + std::cout << "\nFinished!\n" << r << " edges removed.\n" << edges(mesh).size() << " final edges.\n"; +} - CGAL::IO::write_polygon_mesh((argc > 3) ? argv[3] : "out.off", surface_mesh, CGAL::parameters::stream_precision(17)); +// Usage: +// ./command [input] [ratio] [policy] [outpout] +// policy can be "cp" (classic plane), "ct" (classic triangle), "pp" (probabilistic plane), "pt" (probabilistic triangle) +int main(int argc, char** argv) +{ + Surface_mesh mesh; + const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cube-meshed.off"); + + if(CGAL::IO::read_polygon_mesh(filename, mesh)) + { + std::cerr << "Failed to read input mesh: " << filename << std::endl; + return EXIT_FAILURE; + } + + if(!CGAL::is_triangle_mesh(mesh)) + { + std::cerr << "Input geometry is not triangulated." << std::endl; + return EXIT_FAILURE; + } + + std::cout << "Input mesh has " << num_vertices(mesh) << " nv " + << num_edges(mesh) << " ne " + << num_faces(mesh) << " nf" << std::endl; + + const double ratio = (argc > 2) ? std::stod(argv[2]) : 0.2; + std::cout << "Collapsing edges of mesh: " << filename << ", aiming for " << 100 * ratio << "% of the input edges..." << std::endl; + + const std::string policy = (argc > 3) ? argv[3] : "cp"; + if(policy == "cp") + collapse_gh(mesh, ratio); + else if(policy == "ct") + collapse_gh(mesh, ratio); + else if(policy == "pp") + collapse_gh(mesh, ratio); + else + collapse_gh(mesh, ratio); + + CGAL::IO::write_polygon_mesh((argc > 4) ? argv[4] : "out.off", mesh, CGAL::parameters::stream_precision(17)); return EXIT_SUCCESS; }