CGAL 6.0 - CGAL and the Boost Graph Library
Loading...
Searching...
No Matches
Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/Face_filtered_graph.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
#include <CGAL/mesh_segmentation.h>
#include <iostream>
#include <fstream>
#include <sstream>
typedef boost::graph_traits<SM>::face_descriptor face_descriptor;
int main(int argc, char** argv )
{
const std::string filename = (argc > 1) ? argv[1] : CGAL::data_file_path("meshes/cactus.off");
SM mesh;
{
std::cerr << "Invalid input file." << std::endl;
return EXIT_FAILURE;
}
typedef SM::Property_map<face_descriptor,double> Facet_double_map;
Facet_double_map sdf_property_map;
sdf_property_map = mesh.add_property_map<face_descriptor,double>("f:sdf").first;
CGAL::sdf_values(mesh, sdf_property_map);
// create a property-map for segment-ids
typedef SM::Property_map<face_descriptor, std::size_t> Facet_int_map;
Facet_int_map segment_property_map = mesh.add_property_map<face_descriptor,std::size_t>("f:sid").first;;
// segment the mesh using default parameters for number of levels, and smoothing lambda
// Any other scalar values can be used instead of using SDF values computed using the CGAL function
std::size_t number_of_segments = CGAL::segmentation_from_sdf_values(mesh, sdf_property_map, segment_property_map);
typedef CGAL::Face_filtered_graph<SM> Filtered_graph;
//print area of each segment and then put it in a Mesh and print it in an OFF file
Filtered_graph segment_mesh(mesh);
for(std::size_t id = 0; id < number_of_segments; ++id)
{
segment_mesh.set_selected_faces(id, segment_property_map);
std::cout << "Segment "<<id<<"'s area is : "<<CGAL::Polygon_mesh_processing::area(segment_mesh)<<std::endl;
SM out;
CGAL::copy_face_graph(segment_mesh, out);
std::ostringstream oss;
oss << "Segment_" << id<<".off";
std::ofstream os(oss.str().data());
os<<out;
}
}
bool read_polygon_mesh(const std::string &fname, PolygonMesh &g, const NamedParameters &np=parameters::default_values())
FT area(FaceRange face_range, const TriangleMesh &tmesh, const NamedParameters &np=parameters::default_values())
bool is_triangle_mesh(const FaceGraph &g)
returns true if all faces are triangles.
Definition: helpers.h:685
void copy_face_graph(const SourceMesh &sm, TargetMesh &tm, const NamedParameters1 &np1=parameters::default_values(), const NamedParameters2 &np2=parameters::default_values())
copies a source model of FaceListGraph into a target model of a FaceListGraph.
Definition: copy_face_graph.h:328
std::pair< double, double > sdf_values(const TriangleMesh &triangle_mesh, SDFPropertyMap sdf_values_map, double cone_angle=2.0/3.0 *CGAL_PI, std::size_t number_of_rays=25, bool postprocess=true, PointPropertyMap ppmap=PointPropertyMap(), GeomTraits traits=GeomTraits())
std::size_t segmentation_from_sdf_values(const TriangleMesh &triangle_mesh, SDFPropertyMap sdf_values_map, SegmentPropertyMap segment_ids, std::size_t number_of_clusters=5, double smoothing_lambda=0.26, bool output_cluster_ids=false, PointPropertyMap ppmap=PointPropertyMap(), GeomTraits traits=GeomTraits())
std::string data_file_path(const std::string &filename)
The class Face_filtered_graph is an adaptor that creates a filtered view of a graph by restricting it...
Definition: Face_filtered_graph.h:78