CGAL 6.0 - Triangulated Surface Mesh Segmentation
Loading...
Searching...
No Matches
Surface_mesh_segmentation/segmentation_via_sdf_values_example.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/mesh_segmentation.h>
#include <CGAL/property_map.h>
#include <iostream>
#include <fstream>
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
int main()
{
// create and read Polyhedron
Polyhedron mesh;
std::ifstream input(CGAL::data_file_path("meshes/cactus.off"));
if ( !input || !(input >> mesh) || mesh.empty() || ( !CGAL::is_triangle_mesh(mesh)) )
{
std::cerr << "Input is not a triangle mesh" << std::endl;
return EXIT_FAILURE;
}
// create a property-map for segment-ids
typedef std::map<face_descriptor, std::size_t> Face_int_map;
Face_int_map internal_segment_map;
boost::associative_property_map<Face_int_map> segment_property_map(internal_segment_map);
// calculate SDF values and segment the mesh using default parameters.
std::size_t number_of_segments = CGAL::segmentation_via_sdf_values(mesh, segment_property_map);
std::cout << "Number of segments: " << number_of_segments << std::endl;
// print segment-ids
for(face_descriptor f : faces(mesh) ) {
std::cout << segment_property_map[f] << " ";
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
bool is_triangle_mesh(const FaceGraph &g)
std::size_t segmentation_via_sdf_values(const TriangleMesh &triangle_mesh, SegmentPropertyMap segment_ids, double cone_angle=2.0/3.0 *CGAL_PI, std::size_t number_of_rays=25, std::size_t number_of_clusters=5, double smoothing_lambda=0.26, bool output_cluster_ids=false, PointPropertyMap ppmap=PointPropertyMap(), GeomTraits traits=GeomTraits())
Function computing the segmentation of a surface mesh.
Definition: mesh_segmentation.h:286