CGAL 5.1 - Triangulated Surface Mesh Approximation
Surface_mesh_approximation/vsa_approximation_example.cpp
#include <iostream>
#include <fstream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Surface_mesh_approximation/approximate_triangle_mesh.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>
namespace VSA = CGAL::Surface_mesh_approximation;
int main()
{
// read input surface triangle mesh
Mesh mesh;
std::ifstream file("data/bear.off");
file >> mesh;
// output indexed triangles
std::vector<Kernel::Point_3> anchors;
std::vector<std::array<std::size_t, 3> > triangles; // triplets of indices
// free function interface with named parameters
bool is_manifold = VSA::approximate_triangle_mesh(mesh,
CGAL::parameters::seeding_method(VSA::HIERARCHICAL). // hierarchical seeding
max_number_of_proxies(200). // seeding with maximum number of proxies
number_of_iterations(30). // number of clustering iterations after seeding
anchors(std::back_inserter(anchors)). // anchor vertices
triangles(std::back_inserter(triangles))); // indexed triangles
std::cout << "#anchor vertices: " << anchors.size() << std::endl;
std::cout << "#triangles: " << triangles.size() << std::endl;
if (is_manifold) {
std::cout << "oriented, 2-manifold output." << std::endl;
// convert from soup to surface mesh
PMP::orient_polygon_soup(anchors, triangles);
Mesh output;
PMP::polygon_soup_to_polygon_mesh(anchors, triangles, output);
if (CGAL::is_closed(output) && (!PMP::is_outward_oriented(output)))
std::ofstream out("dump.off");
out << output;
out.close();
}
return EXIT_SUCCESS;
}
CGAL::Exact_predicates_inexact_constructions_kernel
CGAL::Surface_mesh
CGAL::Surface_mesh_approximation::HIERARCHICAL
@ HIERARCHICAL
Hierarchical seeding.
Definition: Variational_shape_approximation.h:70
reverse_face_orientations
void reverse_face_orientations(PolygonMesh &pmesh)
polygon_soup_to_polygon_mesh
void polygon_soup_to_polygon_mesh(const PointRange &points, const PolygonRange &polygons, PolygonMesh &out, const NamedParameters_PS &np_ps, const NamedParameters_PM &np_pm)
CGAL::Surface_mesh_approximation::approximate_triangle_mesh
bool approximate_triangle_mesh(const TriangleMesh &tm, const NamedParameters &np)
approximates the input mesh with plane proxies. This function uses the Variational Shape Approximatio...
Definition: approximate_triangle_mesh.h:192
CGAL::Polygon_mesh_processing
is_closed
bool is_closed(const FaceGraph &g)
Kernel
orient_polygon_soup
bool orient_polygon_soup(PointRange &points, PolygonRange &polygons)
is_outward_oriented
bool is_outward_oriented(const TriangleMesh &tm, const NamedParameters &np)