add statistics to cmake

This commit is contained in:
Julian Komaromy 2021-07-26 15:39:32 +02:00
parent e2b2ad8acc
commit ab44601917
3 changed files with 8 additions and 137 deletions

View File

@ -28,7 +28,7 @@ endif()
# Creating entries for all .cpp/.C files with "main" routine
# ##########################################################
create_single_source_cgal_program( "edge_collapse_envelope.cpp" )
create_single_source_cgal_program("edge_collapse_envelope.cpp")
create_single_source_cgal_program("edge_collapse_constrain_sharp_edges.cpp")
create_single_source_cgal_program("edge_collapse_constrained_border_polyhedron.cpp")
create_single_source_cgal_program("edge_collapse_enriched_polyhedron.cpp")
@ -45,10 +45,11 @@ find_package(Eigen3 3.1.0 QUIET) #(3.1.0 or greater)
include(CGAL_Eigen3_support)
if(TARGET CGAL::Eigen3_support)
create_single_source_cgal_program("edge_collapse_garland_heckbert.cpp")
create_single_source_cgal_program("gh_statistics.cpp")
target_link_libraries(edge_collapse_garland_heckbert PUBLIC CGAL::Eigen3_support)
create_single_source_cgal_program("garland_heckbert_policy_comparisons.cpp")
target_link_libraries(garland_heckbert_policy_comparisons PUBLIC CGAL::Eigen3_support)
# create_single_source_cgal_program("garland_heckbert_policy_comparisons.cpp")
# target_link_libraries(garland_heckbert_policy_comparisons PUBLIC CGAL::Eigen3_support)
else()
message(
STATUS

View File

@ -1,133 +0,0 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_ratio_stop_predicate.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_normal_change_placement.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_probabilistic_policies.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h>
#include <CGAL/boost/graph/IO/polygon_mesh_io.h>
#include <CGAL/Polygon_mesh_processing/bbox.h>
#include <chrono>
#include <iostream>
#include <fstream>
#include <vector>
#define CGAL_USE_BASIC_VIEWER
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Surface_mesh;
typedef CGAL::Bbox_3 Bbox_3;
namespace PMP = CGAL::Polygon_mesh_processing;
namespace SMS = CGAL::Surface_mesh_simplification;
template<typename Cost, typename Placement>
void collapse(Surface_mesh surface_mesh, std::string outname,
FT ratio, Cost cost, Placement placement)
{
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();
std::cout << "Aiming for " << 100 * ratio << "% of the input edges..." << std::endl;
SMS::Count_ratio_stop_predicate<Surface_mesh> stop(ratio);
int r = SMS::edge_collapse(surface_mesh, stop,
CGAL::parameters::get_cost(cost)
.get_placement(placement));
std::chrono::steady_clock::time_point end_time = std::chrono::steady_clock::now();
std::cout << "Time elapsed: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count()
<< "ms" << std::endl;
std::cout << "\nFinished!\n" << r
<< " edges removed.\n" << surface_mesh.number_of_edges()
<< " final edges.\n";
CGAL::IO::write_polygon_mesh(outname, surface_mesh, CGAL::parameters::stream_precision(17));
}
void normalize(Surface_mesh& mesh)
{
const Bbox_3 bbox = PMP::bbox(mesh);
FT max = std::max(std::max(bbox.xmax(), bbox.ymax()), bbox.zmax());
for (auto v : vertices(mesh))
{
Point_3& p = mesh.point(v);
p = {p.x() / max, p.y() / max, p.z() / max};
}
}
// takes 4 arguments: input mesh, target reduction percent, name of output file (will be formated
// as name_classic, name_prob_1 etc.) and starting variance
//
// then do classic decimation (with bounded placement) and 5 iterations of probabilistic placement
// where we halve the variance each step
int main(int argc, char** argv)
{
Surface_mesh surface_mesh;
// command line arguments
const char* filename = (argc > 1) ? argv[1] : "data/cube-meshed.off";
const double ratio = (argc > 2) ? std::stod(argv[2]) : 0.2;
const std::string outname = (argc > 3) ? argv[3] : "test";
FT variance = (argc > 4) ? std::stod(argv[4]) : 0.05;
if(!CGAL::IO::read_polygon_mesh(filename, surface_mesh) || !CGAL::is_triangle_mesh(surface_mesh))
{
std::cerr << "Failed to read valid input mesh: " << filename << std::endl;
return EXIT_FAILURE;
}
// Garland&Heckbert simplification policies
typedef typename SMS::GarlandHeckbert_policies<Surface_mesh, Kernel> Classic_policies;
typedef typename SMS::GarlandHeckbert_probabilistic_policies<Surface_mesh, Kernel> Prob_policies;
typedef typename Classic_policies::Get_cost Classic_cost;
typedef typename Classic_policies::Get_placement Classic_placement_unbounded;
typedef typename CGAL::Surface_mesh_simplification::Bounded_normal_change_placement<
Classic_placement_unbounded> Classic_placement;
typedef typename Prob_policies::Get_cost Prob_cost;
typedef typename Prob_policies::Get_placement Prob_placement;
Classic_policies classic_policies(surface_mesh, 100);
const Classic_cost& classic_cost = classic_policies.get_cost();
const Classic_placement& classic_placement { classic_policies.get_placement() };
normalize(surface_mesh);
// Classic
collapse(surface_mesh, outname + "_classic.off", ratio, classic_cost, classic_placement);
// Probabilistic
for (int i = 0; i < 5; ++i)
{
Prob_policies prob_policies(surface_mesh, 100, variance, variance);
const Prob_cost& prob_cost = prob_policies.get_cost();
const Prob_placement& prob_placement = prob_policies.get_placement();
std::string filename = outname + "_prob_" + std::to_string(i) + ".off";
std::cout << "Using variance of " << variance << " for both parameters\n";
collapse(surface_mesh, filename, ratio, prob_cost, prob_placement);
variance = variance / 2;
}
return EXIT_SUCCESS;
}

View File

@ -35,6 +35,8 @@ namespace fs = boost::filesystem;
using hist = boost::histogram::histogram<std::tuple<boost::histogram::axis::regular<double,
boost::use_default, boost::use_default, boost::use_default>>>;
// settings for benchmarking - throw away the first n_burns results and keep the n_samples
// samples
constexpr int n_burns = 1;
constexpr int n_samples = 10;
@ -223,6 +225,7 @@ int main(int argc, char** argv)
}
time_policy<Classic_tri_policies>("../data/", output);
/*
Surface_mesh probabilistic = edge_collapse
<SMS::GarlandHeckbert_probabilistic_policies<Surface_mesh, Kernel>>(surface_mesh);
@ -250,7 +253,6 @@ int main(int argc, char** argv)
std::cout << "Decimated probabilistic tri mesh histogram:\n";
print_hist(generate_edge_statistics(probabilistic_tri, edge_histo, f));
hist face_histo = make_histogram(axis::regular<>(10, 1.0, 5.5));
@ -269,6 +271,7 @@ int main(int argc, char** argv)
std::cout << "Probabilistic tri aspect ratio:\n";
print_hist(generate_face_statistics(probabilistic_tri, face_histo, g));
*/
return EXIT_SUCCESS;
}