diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/gh_statistics.cpp b/Surface_mesh_simplification/examples/Surface_mesh_simplification/gh_statistics.cpp index 26c838687f4..0904636e0ad 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/gh_statistics.cpp +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/gh_statistics.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,8 @@ typedef Kernel::FT FT; typedef Kernel::Point_3 Point_3; typedef CGAL::Surface_mesh Surface_mesh; +typedef typename boost::graph_traits::edge_descriptor edge_descriptor; + namespace SMS = CGAL::Surface_mesh_simplification; namespace PMP = CGAL::Polygon_mesh_processing; @@ -47,22 +50,21 @@ void print_hist(histo h) std::cout << os.str() << std::endl; } -hist edge_length_histo(Surface_mesh mesh) +hist generate_statistics(Surface_mesh mesh, hist histo, std::function f) { - using namespace boost::histogram; - hist histo = make_histogram(axis::regular<>(14, 0.1, 4.0, "length")); - for (auto e : mesh.edges()) { - FT length = PMP::edge_length(mesh.halfedge(e), mesh); - histo(length); + FT value = f(e, mesh); //PMP::edge_length(mesh.halfedge(e), mesh); + histo(value); } - + return histo; } template -hist edge_length_histo(Surface_mesh mesh, Policy p) +hist generate_statistics(Surface_mesh mesh, Policy p, + hist histo, std::function f) { typedef typename Policy::Get_cost Cost; typedef typename Policy::Get_placement Placement; @@ -82,7 +84,7 @@ hist edge_length_histo(Surface_mesh mesh, Policy p) SMS::edge_collapse(mesh, stop, CGAL::parameters::get_cost(cost).get_placement(placement)); - return edge_length_histo(mesh); + return generate_statistics(mesh, histo, f); } int main(int argc, char** argv) @@ -102,24 +104,27 @@ int main(int argc, char** argv) return EXIT_FAILURE; } + using namespace boost::histogram; + hist edge_histo = make_histogram(axis::regular<>(14, 0.1, 4.0, "length")); + + auto edge_length = [] (edge_descriptor e, const Surface_mesh& mesh) { + return PMP::edge_length(mesh.halfedge(e), mesh); + }; + std::cout << "Original mesh histogram:\n"; - print_hist(edge_length_histo(surface_mesh)); - + print_hist(generate_statistics(surface_mesh, edge_histo, edge_length)); + std::cout << "Decimated probabilistic mesh histogram:\n"; - print_hist(edge_length_histo> - (surface_mesh, {surface_mesh, 100})); - - std::cout << "Decimated probabilistic tri mesh histogram:\n"; - print_hist(edge_length_histo> - (surface_mesh, {surface_mesh, 100})); + print_hist(generate_statistics> + (surface_mesh, {surface_mesh, 100}, edge_histo, edge_length)); std::cout << "Decimated classic mesh histogram:\n"; - print_hist(edge_length_histo> - (surface_mesh, {surface_mesh, 100})); - + print_hist(generate_statistics> + (surface_mesh, {surface_mesh, 100}, edge_histo, edge_length)); + std::cout << "Decimated classic tri mesh histogram:\n"; - print_hist(edge_length_histo> - (surface_mesh, {surface_mesh, 100})); - + print_hist(generate_statistics> + (surface_mesh, {surface_mesh, 100}, edge_histo, edge_length)); + return EXIT_SUCCESS; }