mirror of https://github.com/CGAL/cgal
Update examples
This commit is contained in:
parent
d964ca4e48
commit
c06b0d9dc2
|
|
@ -45,7 +45,7 @@ int main(int argc, char** argv)
|
|||
SMS::Count_ratio_stop_predicate<Surface_mesh> stop(ratio);
|
||||
|
||||
// Garland&Heckbert simplification policies
|
||||
typedef typename SMS::GarlandHeckbert_policies<Surface_mesh, Kernel> GH_policies;
|
||||
typedef typename SMS::GarlandHeckbert_plane_policies<Surface_mesh, Kernel> GH_policies;
|
||||
typedef typename GH_policies::Get_cost GH_cost;
|
||||
typedef typename GH_policies::Get_placement GH_placement;
|
||||
typedef SMS::Bounded_normal_change_placement<GH_placement> Bounded_GH_placement;
|
||||
|
|
|
|||
|
|
@ -4,24 +4,23 @@
|
|||
#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_probabilistic_tri_policies.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_plane_policies.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_triangle_policies.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_policies.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_probabilistic_plane_policies.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/GarlandHeckbert_probabilistic_triangle_policies.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <CGAL/Polygon_mesh_processing/measure.h>
|
||||
#include <CGAL/Polygon_mesh_processing/distance.h>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <CGAL/Polygon_mesh_processing/measure.h>
|
||||
#include <CGAL/Polygon_mesh_processing/distance.h>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* this is a largely undocumented file that was used to gather most statistics
|
||||
|
|
@ -40,10 +39,10 @@ namespace SMS = CGAL::Surface_mesh_simplification;
|
|||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
typedef SMS::GarlandHeckbert_policies<Surface_mesh, Kernel> Classic_plane;
|
||||
typedef SMS::GarlandHeckbert_probabilistic_policies<Surface_mesh, Kernel> Prob_plane;
|
||||
typedef SMS::GarlandHeckbert_plane_policies<Surface_mesh, Kernel> Classic_plane;
|
||||
typedef SMS::GarlandHeckbert_triangle_policies<Surface_mesh, Kernel> Classic_tri;
|
||||
typedef SMS::GarlandHeckbert_probabilistic_tri_policies<Surface_mesh, Kernel> Prob_tri;
|
||||
typedef SMS::GarlandHeckbert_probabilistic_plane_policies<Surface_mesh, Kernel> Prob_plane;
|
||||
typedef SMS::GarlandHeckbert_probabilistic_triangle_policies<Surface_mesh, Kernel> Prob_tri;
|
||||
|
||||
// settings for benchmarking - throw away the first n_burns results and keep the n_samples
|
||||
// samples
|
||||
|
|
@ -56,7 +55,8 @@ constexpr std::size_t classic_tri_index = 2;
|
|||
constexpr std::size_t prob_tri_index = 3;
|
||||
|
||||
template <typename Policy>
|
||||
Surface_mesh edge_collapse(Surface_mesh& mesh, double ratio = 0.2)
|
||||
Surface_mesh edge_collapse(Surface_mesh& mesh,
|
||||
const double ratio = 0.2)
|
||||
{
|
||||
typedef typename Policy::Get_cost Cost;
|
||||
typedef typename Policy::Get_placement Placement;
|
||||
|
|
@ -73,17 +73,15 @@ Surface_mesh edge_collapse(Surface_mesh& mesh, double ratio = 0.2)
|
|||
SMS::Count_ratio_stop_predicate<Surface_mesh> stop(ratio);
|
||||
|
||||
// collapse edges ignoring result code
|
||||
SMS::edge_collapse(mesh, stop,
|
||||
CGAL::parameters::get_cost(cost).get_placement(placement));
|
||||
SMS::edge_collapse(mesh, stop, CGAL::parameters::get_cost(cost).get_placement(placement));
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
template <typename Policy>
|
||||
void time_all_vector(const std::vector<Surface_mesh>& meshes, const fs::path& output_file)
|
||||
void time_all_vector(const fs::path& output_file,
|
||||
const std::vector<Surface_mesh>& meshes)
|
||||
{
|
||||
namespace time = std::chrono;
|
||||
|
||||
fs::ofstream out_stream { output_file };
|
||||
|
||||
// always decimate meshes in this vector to avoid timing the
|
||||
|
|
@ -93,28 +91,24 @@ void time_all_vector(const std::vector<Surface_mesh>& meshes, const fs::path& ou
|
|||
for(int i=0; i<n_burns; ++i)
|
||||
{
|
||||
for(Surface_mesh& mesh : temp_meshes)
|
||||
{
|
||||
edge_collapse<Policy>(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
temp_meshes = meshes;
|
||||
|
||||
// measure each run
|
||||
for(int i=0; i<n_samples; ++i)
|
||||
{
|
||||
// measure time taken by the edge_collapse function over each mesh individually
|
||||
time::time_point start_time = time::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now();
|
||||
|
||||
for(Surface_mesh& mesh : temp_meshes)
|
||||
{
|
||||
edge_collapse<Policy>(mesh);
|
||||
}
|
||||
|
||||
time::time_point end_time = time::steady_clock::now();
|
||||
std::chrono::time_point<std::chrono::steady_clock> end_time = std::chrono::steady_clock::now();
|
||||
|
||||
// get elapsed time in nanoseconds
|
||||
unsigned long elapsed_ns = time::duration_cast<time::nanoseconds>
|
||||
(end_time - start_time).count();
|
||||
unsigned long elapsed_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count();
|
||||
|
||||
// add the elapsed time as data point
|
||||
out_stream << std::to_string(elapsed_ns) << '\n';
|
||||
|
|
@ -123,7 +117,8 @@ void time_all_vector(const std::vector<Surface_mesh>& meshes, const fs::path& ou
|
|||
}
|
||||
}
|
||||
|
||||
bool read_from_file(Surface_mesh& mesh, const fs::path& p)
|
||||
bool read_from_file(const fs::path& p,
|
||||
Surface_mesh& mesh)
|
||||
{
|
||||
fs::ifstream in { p };
|
||||
|
||||
|
|
@ -131,9 +126,7 @@ bool read_from_file(Surface_mesh& mesh, const fs::path& p)
|
|||
mesh.clear();
|
||||
|
||||
if(!in || !(in >> mesh))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -153,17 +146,16 @@ std::vector<std::pair<Surface_mesh, std::string>> get_all_meshes(const fs::path&
|
|||
for(fs::directory_iterator dir_iter(dir); dir_iter != end_iter; ++dir_iter)
|
||||
{
|
||||
// look for .off files
|
||||
if (fs::is_regular_file(dir_iter->status())
|
||||
&& dir_iter->path().extension() == ".off")
|
||||
if(fs::is_regular_file(dir_iter->status()) &&
|
||||
dir_iter->path().extension() == ".off")
|
||||
{
|
||||
const fs::path& path = dir_iter->path();
|
||||
|
||||
// try to read the file into the surface mesh, upon failure, we continue looping
|
||||
// iterating through the directory
|
||||
if (!read_from_file(mesh, path))
|
||||
if(!read_from_file(path, mesh))
|
||||
{
|
||||
std::cerr << "Failed to read input mesh " << path
|
||||
<< " in directory " << dir << "." << std::endl;
|
||||
std::cerr << "Failed to read input mesh " << path << " in directory " << dir << "." << std::endl;
|
||||
}
|
||||
else if(!CGAL::is_triangle_mesh(mesh))
|
||||
{
|
||||
|
|
@ -186,18 +178,16 @@ std::vector<std::pair<Surface_mesh, std::string>> get_all_meshes(const fs::path&
|
|||
void time_policy(const fs::path& dir, const fs::path& output_file)
|
||||
{
|
||||
auto vec = get_all_meshes(dir);
|
||||
std::vector<Surface_mesh> meshes { };
|
||||
std::vector<Surface_mesh> meshes;
|
||||
|
||||
for(const auto& p : vec) {
|
||||
for(const auto& p : vec)
|
||||
std::cout << p.second << '\n';
|
||||
}
|
||||
|
||||
// keep the first values from the pair (we don't need the names)(we don't need the names)
|
||||
std::transform(vec.begin(), vec.end(), std::back_inserter(meshes),
|
||||
[] (const std::pair<Surface_mesh, std::string>& p) { return p.first; }
|
||||
);
|
||||
[] (const std::pair<Surface_mesh, std::string>& p) { return p.first; } );
|
||||
|
||||
return time_all_vector<Policy>(meshes, output_file);
|
||||
return time_all_vector<Policy>(output_file, meshes);
|
||||
}
|
||||
|
||||
template <typename Policy>
|
||||
|
|
@ -210,12 +200,10 @@ double hausdorff_error(const Surface_mesh& mesh, double ratio = 0.2)
|
|||
Surface_mesh temp = mesh;
|
||||
|
||||
edge_collapse<Policy>(temp, ratio);
|
||||
return PMP::bounded_error_symmetric_Hausdorff_distance<CGAL::Sequential_tag>
|
||||
(mesh, temp, error_bound);
|
||||
return PMP::bounded_error_symmetric_Hausdorff_distance<CGAL::Parallel_if_available_tag>(mesh, temp, error_bound);
|
||||
}
|
||||
|
||||
// calculate approximate Hausdorff errors for all different policies at
|
||||
// the same decimation ratio
|
||||
// calculate approximate Hausdorff errors for all different policies at the same decimation ratio
|
||||
std::array<FT, 4> hausdorff_errors(const Surface_mesh& mesh, double ratio)
|
||||
{
|
||||
std::array<FT, 4> ret { {0, 0, 0, 0} };
|
||||
|
|
@ -229,7 +217,7 @@ std::array<FT, 4> hausdorff_errors(const Surface_mesh& mesh, double ratio)
|
|||
}
|
||||
|
||||
template <typename InputIt>
|
||||
void hausdorff_errors_mesh(const Surface_mesh& mesh, const fs::path& out, InputIt begin, InputIt end)
|
||||
void hausdorff_errors_mesh(const fs::path& out, const Surface_mesh& mesh, InputIt begin, InputIt end)
|
||||
{
|
||||
fs::ofstream out_stream { out };
|
||||
|
||||
|
|
@ -240,26 +228,20 @@ void hausdorff_errors_mesh(const Surface_mesh& mesh, const fs::path& out, InputI
|
|||
out_stream << "ratio: " << *it << '\n';
|
||||
|
||||
for(double e : errs)
|
||||
{
|
||||
out_stream << std::to_string(e) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename InputIt>
|
||||
void hausdorff_errors_mesh(const fs::path& in, const fs::path& out, InputIt begin, InputIt end)
|
||||
void hausdorff_errors_mesh(const fs::path& out, const fs::path& in, InputIt begin, InputIt end)
|
||||
{
|
||||
fs::ifstream is {in};
|
||||
Surface_mesh mesh;
|
||||
|
||||
if (!read_from_file(mesh, in))
|
||||
{
|
||||
if(!read_from_file(in, mesh))
|
||||
std::cerr << "Failed to read input mesh " << in << '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
hausdorff_errors_mesh(mesh, out, begin, end);
|
||||
}
|
||||
hausdorff_errors_mesh(out, mesh, begin, end);
|
||||
}
|
||||
|
||||
void hausdorff_errors_dir(const fs::path& dir, const fs::path& out, double ratio = 0.2)
|
||||
|
|
@ -276,19 +258,15 @@ void hausdorff_errors_dir(const fs::path& dir, const fs::path& out, double ratio
|
|||
|
||||
out_stream << p.second << '\n';
|
||||
for(double err : errors)
|
||||
{
|
||||
out_stream << std::to_string(err) << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write_aspect_ratios(fs::ofstream& out, const Surface_mesh& mesh)
|
||||
{
|
||||
for(auto face : faces(mesh))
|
||||
{
|
||||
out << std::to_string(PMP::face_aspect_ratio(face, mesh)) << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void gather_face_aspect_ratio(const fs::path& file, const fs::path& out)
|
||||
{
|
||||
|
|
@ -297,10 +275,10 @@ void gather_face_aspect_ratio(const fs::path& file, const fs::path& out)
|
|||
Surface_mesh pp { };
|
||||
Surface_mesh pt { };
|
||||
|
||||
read_from_file(cp, file);
|
||||
read_from_file(ct, file);
|
||||
read_from_file(pp, file);
|
||||
read_from_file(pt, file);
|
||||
read_from_file(file, cp);
|
||||
read_from_file(file, ct);
|
||||
read_from_file(file, pp);
|
||||
read_from_file(file, pt);
|
||||
|
||||
edge_collapse<Classic_plane>(cp);
|
||||
edge_collapse<Prob_plane>(pp);
|
||||
|
|
@ -321,28 +299,20 @@ void gather_face_aspect_ratio(const fs::path& file, const fs::path& out)
|
|||
|
||||
enum class Mode { time, hausdorff_ratio, hausdorff_mesh, run, apect_ratio };
|
||||
|
||||
void time_policy_string(const fs::path& in, const fs::path& out, const std::string& policy) {
|
||||
void time_policy_string(const fs::path& in, const fs::path& out, const std::string& policy)
|
||||
{
|
||||
if(policy == "classic_plane")
|
||||
{
|
||||
time_policy<Classic_plane>(in, out);
|
||||
}
|
||||
else if(policy == "prob_plane")
|
||||
{
|
||||
time_policy<Prob_plane>(in, out);
|
||||
}
|
||||
else if(policy == "classic_tri")
|
||||
{
|
||||
time_policy<Classic_tri>(in, out);
|
||||
}
|
||||
else if(policy == "prob_tri")
|
||||
{
|
||||
time_policy<Prob_tri>(in, out);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
// default is time
|
||||
Mode m = Mode::time;
|
||||
|
||||
|
|
@ -379,19 +349,19 @@ int main(int argc, char* argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
// default init empty mesh
|
||||
Surface_mesh m { };
|
||||
Surface_mesh sm;
|
||||
|
||||
FT ratio = 0.2;
|
||||
if(argc == 4) {
|
||||
ratio = std::stod(argv[3]);
|
||||
}
|
||||
|
||||
read_from_file(m, argv[2]);
|
||||
read_from_file(argv[2], sm);
|
||||
|
||||
Surface_mesh cp = m;
|
||||
Surface_mesh pp = m;
|
||||
Surface_mesh ct = m;
|
||||
Surface_mesh pt = m;
|
||||
Surface_mesh cp = sm;
|
||||
Surface_mesh pp = sm;
|
||||
Surface_mesh ct = sm;
|
||||
Surface_mesh pt = sm;
|
||||
|
||||
edge_collapse<Classic_plane>(cp, ratio);
|
||||
edge_collapse<Prob_plane>(pp, ratio);
|
||||
|
|
|
|||
Loading…
Reference in New Issue