CGAL 6.2 - Boolean Operations on Meshes

Loading...
Searching...
No Matches
PMP_Boolean_operations/corefinement_mesh_union_and_intersection.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <array>
#include <iostream>
#include <string>
#include <tuple>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
namespace PMP = CGAL::Polygon_mesh_processing;
namespace params = CGAL::parameters;
int main(int argc, char* argv[])
{
const std::string filename1 = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/blobby.off");
const std::string filename2 = (argc > 2) ? argv[2] : CGAL::data_file_path("meshes/eight.off");
Mesh mesh1, mesh2;
if(!PMP::IO::read_polygon_mesh(filename1, mesh1) || !PMP::IO::read_polygon_mesh(filename2, mesh2))
{
std::cerr << "Invalid input." << std::endl;
return 1;
}
Mesh out_union, out_intersection;
std::array<std::optional<Mesh*>, 4> output;
output[PMP::Corefinement::UNION] = &out_union;
output[PMP::Corefinement::INTERSECTION] = &out_intersection;
// for the example, we explicit the named parameters, this is identical to
// PMP::corefine_and_compute_boolean_operations(mesh1, mesh2, output)
std::array<bool, 4> res =
PMP::corefine_and_compute_boolean_operations(
mesh1, mesh2,
output,
params::default_values(), // mesh1 named parameters
params::default_values(), // mesh2 named parameters
std::make_tuple(
params::vertex_point_map(get(boost::vertex_point, out_union)), // named parameters for out_union
params::vertex_point_map(get(boost::vertex_point, out_intersection)), // named parameters for out_intersection
params::default_values(), // named parameters for mesh1-mesh2 not used
params::default_values() )// named parameters for mesh2-mesh1 not used)
);
if (res[PMP::Corefinement::UNION])
{
std::cout << "Union was successfully computed\n";
CGAL::IO::write_polygon_mesh("union.off", out_union, CGAL::parameters::stream_precision(17));
}
else
std::cout << "Union could not be computed\n";
if (res[PMP::Corefinement::INTERSECTION])
{
std::cout << "Intersection was successfully computed\n";
CGAL::IO::write_polygon_mesh("intersection.off", out_intersection, CGAL::parameters::stream_precision(17));
}
else
std::cout << "Intersection could not be computed\n";
return 0;
}
CGAL::Exact_predicates_inexact_constructions_kernel
CGAL::Surface_mesh
CGAL::Polygon_mesh_processing::corefine_and_compute_boolean_operations
std::array< bool, 4 > corefine_and_compute_boolean_operations(TriangleMesh &tm1, TriangleMesh &tm2, const std::array< std::optional< TriangleMesh * >, 4 > &output, const NPIn1 &np1=parameters::default_values(), const NPIn2 &np2=parameters::default_values(), const std::tuple< NPOut0, NPOut1, NPOut2, NPOut3 > &nps_out=std::tuple< NPOut0, NPOut1, NPOut2, NPOut3 >())
corefines tm1 and tm2 and for each triangle mesh tm_out passed as an optional in output different fr...
Definition: corefinement.h:272
CGAL::IO::write_polygon_mesh
bool write_polygon_mesh(const std::string &fname, Graph &g, const NamedParameters &np=parameters::default_values())
CGAL::parameters