Enhance example

This commit is contained in:
Mael Rouxel-Labbé 2024-05-30 14:46:49 +02:00
parent 24e1c96f62
commit c40da70441
1 changed files with 57 additions and 26 deletions

View File

@ -1,44 +1,75 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#define CGAL_CHECK_EXPENSIVE
#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_TRACE 5
#define CGAL_SURFACE_SIMPLIFICATION_ENABLE_LT_TRACE 4
void Surface_simplification_external_trace(const std::string& s)
{
std::cout << s << std::endl;
}
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Bounded_normal_change_filter.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Face_count_stop_predicate.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_cost.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/LindstromTurk_placement.h>
#include <CGAL/Polygon_mesh_processing/bbox.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
namespace SMS = CGAL::Surface_mesh_simplification;
namespace PMP = CGAL::Polygon_mesh_processing;
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Surface_mesh;
int main() {
std::string filename("data/issue_8213.off");
Surface_mesh surface_mesh;
std::ifstream in(filename);
in >> surface_mesh;
const size_t target_number_of_faces = 3;
SMS::Face_count_stop_predicate<Surface_mesh> stop(target_number_of_faces);
std::cout << "Input mesh number of faces: " << surface_mesh.number_of_faces() << ", target number of faces: " << target_number_of_faces << std::endl;
SMS::edge_collapse(
surface_mesh,
stop,
CGAL::parameters::
filter(SMS::Bounded_normal_change_filter<>())
.get_cost(SMS::LindstromTurk_cost<Surface_mesh>())
.get_placement(SMS::LindstromTurk_placement<Surface_mesh>())
);
using Kernel = CGAL::Simple_cartesian<double>;
// using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;
using Surface_mesh = CGAL::Surface_mesh<Kernel::Point_3>;
int main(int argc, char** argv)
{
std::cout.precision(17);
std::cout << surface_mesh << std::endl;
std::cerr.precision(17);
const char* filename = (argc > 1) ? argv[1] : "data/issue_8213.off";
Surface_mesh sm;
if(!CGAL::IO::read_polygon_mesh(filename, sm))
{
std::cerr << "Error: failed to read input data" << std::endl;
return EXIT_FAILURE;
}
CGAL::Bbox_3 bbox = PMP::bbox(sm);
std::cout << "Input mesh has " << num_vertices(sm) << " vertices" << std::endl;
std::cout << "Input mesh has " << num_faces(sm) << " faces" << std::endl;
SMS::Face_count_stop_predicate<Surface_mesh> stop(1);
SMS::edge_collapse(sm, stop,
CGAL::parameters::filter(SMS::Bounded_normal_change_filter<>())
.get_cost(SMS::LindstromTurk_cost<Surface_mesh>())
.get_placement(SMS::LindstromTurk_placement<Surface_mesh>()));
CGAL::IO::write_OFF(std::cout, sm, CGAL::parameters::stream_precision(17));
for(auto v : vertices(sm))
{
// To be within the bounding box isn't a guarantee, but here it is a sufficient test
// to check if things went awry
if(!CGAL::do_overlap(bbox, sm.point(v).bbox()))
{
std::cerr << "Error: " << sm.point(v) << " is outside the initial bbox" << std::endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}