make histogram generation generic

This commit is contained in:
Julian Komaromy 2021-07-19 13:27:21 +02:00
parent 8d73dc6343
commit 82a2f3622e
1 changed files with 28 additions and 23 deletions

View File

@ -13,6 +13,7 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <functional>
#include <boost/histogram.hpp>
#include <boost/format.hpp>
#include <CGAL/Polygon_mesh_processing/measure.h>
@ -22,6 +23,8 @@ typedef Kernel::FT FT;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Surface_mesh;
typedef typename boost::graph_traits<Surface_mesh>::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<FT(edge_descriptor,
const Surface_mesh&)> 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<typename Policy>
hist edge_length_histo(Surface_mesh mesh, Policy p)
hist generate_statistics(Surface_mesh mesh, Policy p,
hist histo, std::function<FT(edge_descriptor, const Surface_mesh&)> 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<SMS::GarlandHeckbert_probabilistic_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}));
std::cout << "Decimated probabilistic tri mesh histogram:\n";
print_hist(edge_length_histo<SMS::GarlandHeckbert_probabilistic_tri_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}));
print_hist(generate_statistics<SMS::GarlandHeckbert_probabilistic_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}, edge_histo, edge_length));
std::cout << "Decimated classic mesh histogram:\n";
print_hist(edge_length_histo<SMS::GarlandHeckbert_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}));
print_hist(generate_statistics<SMS::GarlandHeckbert_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}, edge_histo, edge_length));
std::cout << "Decimated classic tri mesh histogram:\n";
print_hist(edge_length_histo<SMS::GarlandHeckbert_triangle_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}));
print_hist(generate_statistics<SMS::GarlandHeckbert_triangle_policies<Surface_mesh, Kernel>>
(surface_mesh, {surface_mesh, 100}, edge_histo, edge_length));
return EXIT_SUCCESS;
}