From 64eb2d09c698a6e2602bc0c77811d2cda1308cae Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 3 May 2017 14:38:41 +0200 Subject: [PATCH] Change doc for default index maps and add an example to Surface_mesh_segmentation using area() and Connected_components_graphs. --- .../boost/graph/Connected_components_graph.h | 49 ++++++++++++----- .../Surface_Mesh_Segmentation.txt | 6 +++ .../Surface_mesh_segmentation/examples.txt | 1 + .../Surface_mesh_segmentation/CMakeLists.txt | 3 ++ ...extract_segmentation_into_mesh_example.cpp | 54 +++++++++++++++++++ 5 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 Surface_mesh_segmentation/examples/Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp diff --git a/BGL/include/CGAL/boost/graph/Connected_components_graph.h b/BGL/include/CGAL/boost/graph/Connected_components_graph.h index f4b44d128ca..0f31b4a796f 100644 --- a/BGL/include/CGAL/boost/graph/Connected_components_graph.h +++ b/BGL/include/CGAL/boost/graph/Connected_components_graph.h @@ -42,14 +42,13 @@ namespace CGAL * For example, calling `vertices(graph)` will return an iterator range of all but only the vertices that belong to the selected connected components. * * \tparam Graph must be a model of a `FaceListGraph` and `HalfedgeListGraph`. - * \tparam FIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%face_descriptor` as key and `graph_traits::faces_size_type` - * \tparam VIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key and `graph_traits::vertices_size_type` - * \tparam HIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%halfedge_descriptor` as key and `graph_traits::halfedges_size_type` + * \tparam FIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%face_descriptor` as key and `graph_traits::%faces_size_type` as value + * \tparam VIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` as key and `graph_traits::%vertices_size_type` as value + * \tparam HIMap a model of `ReadablePropertyMap` with `boost::graph_traits::%halfedge_descriptor` as key and `graph_traits::%halfedges_size_type` as value * * \cgalModels `FaceListGraph` * \cgalModels `HalfedgeListGraph` */ - template::type, typename VIMap = typename boost::property_map::type, @@ -125,14 +124,20 @@ struct Connected_components_graph * \tparam FaceComponentMap a model of `ReadablePropertyMap` with `boost::graph_traits::%face_descriptor` as key type and - `graph_traits::faces_size_type` as value type. + `graph_traits::%faces_size_type` as value type. * \param graph the graph containing the wanted patches. * \param fcmap the property_map that assigns a connected component to each face, with `boost::graph_traits::%face_descriptor` as key type and - `graph_traits::faces_size_type` as value type. + `graph_traits::%faces_size_type` as value type. * \param begin an interator to the beginning of a range of connected components indices of interest. * \param end an interator to the element past the end of a range of connected components indices of interest. + * \param fimap the property map that assigns an index to each face, + * with boost::graph_traits::%face_descriptor as key type and boost::graph_traits::%faces_size_type as value type + * \param vimap the property map that assigns an index to each vertex, + * with boost::graph_traits::%vertex_descriptor as key type and boost::graph_traits::%vertices_size_type as value type + * \param himap the property map that assigns an index to each halfedge, + * with boost::graph_traits::%halfedge_descriptor as key type and boost::graph_traits::%halfedges_size_type as value type */ template @@ -140,9 +145,16 @@ struct Connected_components_graph FaceComponentMap fcmap, IndexRangeIterator begin, IndexRangeIterator end, + #ifdef DOXYGEN_RUNNING + FIMap fimap = get(CGAL::face_index, graph), + VIMap vimap = get(boost::vertex_index, graph), + HIMap himap = get(CGAL::halfedge_index, graph) + #else FIMap fimap, VIMap vimap, - HIMap himap) + HIMap himap + #endif + ) : _graph(const_cast(graph)), fimap(fimap), vimap(vimap), himap(himap) { base_iterator_constructor(begin, end, fcmap); @@ -165,20 +177,33 @@ struct Connected_components_graph * * \tparam FaceComponentMap a model of `ReadablePropertyMap` with `boost::graph_traits::%face_descriptor` as key type and - `graph_traits::faces_size_type` as value type. + `graph_traits::%faces_size_type` as value type. * \param graph the graph containing the wanted patch. * \param fcmap the property_map that assigns a connected component's index to each face, with `boost::graph_traits::%face_descriptor` as key type and - `graph_traits::faces_size_type` as value type. + `graph_traits::%faces_size_type` as value type. * \param pid the index of the connected component of interest. + * \param fimap the property map that assigns an index to each face, + * with boost::graph_traits::%face_descriptor as key type and boost::graph_traits::%faces_size_type as value type + * \param vimap the property map that assigns an index to each vertex, + * with boost::graph_traits::%vertex_descriptor as key type and boost::graph_traits::%vertices_size_type as value type + * \param himap the property map that assigns an index to each halfedge, + * with boost::graph_traits::%halfedge_descriptor as key type and boost::graph_traits::%halfedges_size_type as value type */ template Connected_components_graph(const Graph& graph, FaceComponentMap fcmap, typename boost::property_traits::value_type pid, + #ifdef DOXYGEN_RUNNING + FIMap fimap = get(CGAL::face_index, graph), + VIMap vimap = get(boost::vertex_index, graph), + HIMap himap = get(CGAL::halfedge_index, graph) + #else FIMap fimap, VIMap vimap, - HIMap himap) + HIMap himap + #endif + ) : _graph(const_cast(graph)), fimap(fimap), vimap(vimap), himap(himap) { base_constructor(fcmap, pid); @@ -195,9 +220,9 @@ struct Connected_components_graph himap = get(CGAL::halfedge_index, graph); base_constructor(fcmap, pid); } - ///returns the graph of the Connected_components_graph. + ///returns a const reference to the graph of the Connected_components_graph. const Graph& graph()const{ return _graph; } - + ///returns a reference to the graph of the Connected_components_graph. Graph& graph(){ return _graph; } struct Is_simplex_valid diff --git a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Surface_Mesh_Segmentation.txt b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Surface_Mesh_Segmentation.txt index 506ec1a5dfb..3646fc34818 100644 --- a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Surface_Mesh_Segmentation.txt +++ b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/Surface_Mesh_Segmentation.txt @@ -200,11 +200,17 @@ The main advantage is to decrease from log to constant the complexity for access \cgalExample{Surface_mesh_segmentation/segmentation_with_facet_ids_example.cpp} + \subsection Surface_mesh_segmentationUsingapolyhedron Using a Surface_mesh When using a `Surface_mesh`, you can use the built-in property mechanism. \cgalExample{Surface_mesh_segmentation/segmentation_from_sdf_values_SM_example.cpp} +\subsection Surface_mesh_segmentationIndependantmeshpersegment Independant TriangleMesh per Segment + It is possible to consider each segment as an independant triangle mesh, like in the following example, where the area of each segment is computed. + +\cgalExample{Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp} +
\section Performances Performances diff --git a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/examples.txt b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/examples.txt index 20ebc1fe599..4dca4c1a63a 100644 --- a/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/examples.txt +++ b/Surface_mesh_segmentation/doc/Surface_mesh_segmentation/examples.txt @@ -3,3 +3,4 @@ /// \example Surface_mesh_segmentation/segmentation_from_sdf_values_SM_example.cpp /// \example Surface_mesh_segmentation/segmentation_via_sdf_values_example.cpp /// \example Surface_mesh_segmentation/segmentation_with_facet_ids_example.cpp +/// \example Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp diff --git a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt index 95d98601c9b..581a03e756b 100644 --- a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt +++ b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/CMakeLists.txt @@ -64,8 +64,11 @@ create_single_source_cgal_program( "segmentation_from_sdf_values_example.cpp" ) create_single_source_cgal_program( "segmentation_via_sdf_values_example.cpp" ) create_single_source_cgal_program( "segmentation_with_facet_ids_example.cpp" ) + create_single_source_cgal_program( "segmentation_from_sdf_values_SM_example.cpp") +create_single_source_cgal_program( "extract_segmentation_into_mesh_example.cpp") + if(OpenMesh_FOUND) create_single_source_cgal_program( "segmentation_from_sdf_values_OpenMesh_example.cpp" ) target_link_libraries( segmentation_from_sdf_values_OpenMesh_example ${OPENMESH_LIBRARIES} ) diff --git a/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp new file mode 100644 index 00000000000..699cf816331 --- /dev/null +++ b/Surface_mesh_segmentation/examples/Surface_mesh_segmentation/extract_segmentation_into_mesh_example.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef CGAL::Surface_mesh SM; +typedef boost::graph_traits::face_descriptor face_descriptor; + +int main(int argc, char** argv ) +{ + SM mesh; + if (argc==2){ + std::ifstream input(argv[1]); + input >> mesh; + } else { + std::ifstream cactus("data/cactus.off"); + cactus >> mesh; + } + typedef SM::Property_map Facet_double_map; + Facet_double_map sdf_property_map; + + sdf_property_map = mesh.add_property_map("f:sdf").first; + + CGAL::sdf_values(mesh, sdf_property_map); + + // create a property-map for segment-ids + typedef SM::Property_map Facet_int_map; + Facet_int_map segment_property_map = mesh.add_property_map("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::Connected_components_graph Cc_graph; + //print area of each segment and then put it in a Mesh and print it in an OFF file + for(std::size_t id = 0; id < number_of_segments; ++id) + { + Cc_graph segment_mesh(mesh, segment_property_map, id); + std::cout << "Segment "<