CGAL 6.2 - Boolean Operations on Meshes: PMP_Boolean_operations/snap_polygon_soup.cpp

CGAL 6.2 - Boolean Operations on Meshes

Loading...
Searching...
No Matches
PMP_Boolean_operations/snap_polygon_soup.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/autorefinement.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <CGAL/Real_timer.h>
#include <boost/container/small_vector.hpp>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char** argv)
{
const std::string filename = argc == 1 ? CGAL::data_file_path("meshes/elephant.off")
: std::string(argv[1]);
const int grid_size = argc <= 2 ? 23
: std::stoi(std::string(argv[2]));
const std::string out_file = "rounded_soup.off";
std::vector<typename Kernel::Point_3> points;
std::vector<boost::container::small_vector<std::size_t, 3>> triangles;
std::cout << "Snap rounding on " << filename << "\n";
if (!CGAL::IO::read_polygon_soup(filename, points, triangles))
{
std::cerr << "Cannot read " << filename << "\n";
return 1;
}
PMP::repair_polygon_soup(points, triangles);
PMP::triangulate_polygons(points, triangles);
std::cout << "#points = " << points.size() << " and #triangles = " << triangles.size() << std::endl;
std::cout << "Is 2-manifold: " << PMP::is_polygon_soup_a_polygon_mesh(triangles) << std::endl;
std::vector<std::pair<std::size_t, std::size_t>> pairs_of_intersecting_triangles;
PMP::triangle_soup_self_intersections(points, triangles, std::back_inserter(pairs_of_intersecting_triangles));
std::cout << "Nb of pairs of intersecting triangles: " << pairs_of_intersecting_triangles.size() << std::endl;
CGAL::Real_timer t;
t.start();
using Erase_policy = PMP::Duplicate_polygon_erase_policy;
bool success=PMP::autorefine_triangle_soup(points, triangles, CGAL::parameters::apply_iterative_snap_rounding(true).erase_policy(Erase_policy::ERASE_ALL).concurrency_tag(CGAL::Parallel_if_available_tag()).snap_grid_size(grid_size).number_of_iterations(15));
t.stop();
std::cout << "\nOutput:" << std::endl;
std::cout << "#points = " << points.size() << " and #triangles = " << triangles.size() << " in " << t.time() << " sec." << std::endl;
if(success)
std::cout << "Does self-intersect: " << PMP::does_triangle_soup_self_intersect<CGAL::Parallel_if_available_tag>(points, triangles) << std::endl;
else
std::cout << "ROUNDING FAILED" << std::endl;
CGAL::IO::write_polygon_soup(out_file, points, triangles, CGAL::parameters::stream_precision(17));
std::cout << "Is 2-manifold: " << PMP::orient_polygon_soup(points, triangles) << "\n\n" << std::endl;
return 0;
}
CGAL::Exact_predicates_inexact_constructions_kernel
CGAL::IO::write_polygon_soup
bool write_polygon_soup(const std::string &fname, const PointRange &points, const PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
CGAL::IO::read_polygon_soup
bool read_polygon_soup(const std::string &fname, PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
CGAL::Polygon_mesh_processing::repair_polygon_soup
void repair_polygon_soup(PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh
bool is_polygon_soup_a_polygon_mesh(const PolygonRange &polygons)
CGAL::Polygon_mesh_processing::Duplicate_polygon_erase_policy
Duplicate_polygon_erase_policy
CGAL::Polygon_mesh_processing::autorefine_triangle_soup
bool autorefine_triangle_soup(PointRange &soup_points, TriangleRange &soup_triangles, const NamedParameters &np=parameters::default_values())
refines a soup of triangles so that no pair of triangles intersects.
Definition: autorefinement.h:1725
CGAL::Polygon_mesh_processing::triangle_soup_self_intersections
TriangleIdPairOutputIterator triangle_soup_self_intersections(const PointRange &points, const TriangleRange &triangles, TriangleIdPairOutputIterator out, const NamedParameters &np=parameters::default_values())
CGAL::Polygon_mesh_processing::triangulate_polygons
bool triangulate_polygons(const PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
CGAL::Polygon_mesh_processing::orient_polygon_soup
bool orient_polygon_soup(PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())
Kernel
CGAL::Parallel_if_available_tag