From 1a775ff8f973db58e2d7dd38f8ae87d7c75516ce Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 25 Jun 2015 09:58:08 +0200 Subject: [PATCH] add keep_connected_components (doc only) --- .../PackageDescription.txt | 3 +- .../Polygon_mesh_processing.txt | 5 ++ .../connected_components.h | 72 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index a294830832c..5e768ca0b3c 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -71,9 +71,10 @@ and provides a list of the parameters that are used in this package. ## Other Classes and Functions ## - `CGAL::Polygon_mesh_slicer` -- `CGAL::Polygon_mesh_processing::keep_largest_connected_components()` - `CGAL::Polygon_mesh_processing::connected_component()` - `CGAL::Polygon_mesh_processing::connected_components()` +- `CGAL::Polygon_mesh_processing::keep_largest_connected_components()` +- `CGAL::Polygon_mesh_processing::keep_connected_components()` \todo make template parameter names uniform in other packages using BGL. Here we chose PolygonMesh as template parameter. It can be made short to PM. And TriangleMesh (or TM) specifies when the parameter should be a triangle mesh. diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt index b73cdc265bb..5fa2c314aff 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/Polygon_mesh_processing.txt @@ -382,6 +382,11 @@ Then, `CGAL::Polygon_mesh_processing::connected_components()` collects all the connected components, and fills a property map with the indices of the different connected components. +The function `CGAL::Polygon_mesh_processing::keep_connected_components()` +enables the user to keep only a selection of connected components, +provided as a range of faces that belong to the desired connected components +(one or more per connected component). + Finally, `CGAL::Polygon_mesh_processing::keep_largest_connected_components()` enables the user to keep only the largest connected components. This feature can for example be useful for noisy data were small connected components diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h index 39e42cb5e75..1ce228740bc 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/connected_components.h @@ -757,6 +757,78 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh, CGAL::Polygon_mesh_processing::parameters::all_default()); } +/*! +* \ingroup PkgPolygonMeshProcessing +* keeps the connected components designated by the faces in `components_to_keep`, +* and erases the other connected components and all the isolated vertices. +* Two faces are considered in the same connected component if they share an edge that is not marked as constrained. +* +* \tparam PolygonMesh a model of `FaceListGraph` +* \tparam NamedParameters a sequence of \ref namedparameters +* +* \param pmesh the polygon mesh +* \param components_to_keep a face range, including one face or more on each component to be keep +* \param np optional \ref namedparameters described below +* +* \cgalNamedParamsBegin +* \cgalParamBegin{edge_is_constrained_map} a property map containing the constrained-or-not status of each edge of `pmesh` \cgalParamEnd +* \cgalParamBegin{face_index_map} a property map containing the index of each face of `pmesh` \cgalParamEnd +* \cgalParamBegin{vertex_index_map} a property map containing the index of each vertex of `pmesh` \cgalParamEnd +* \cgalNamedParamsEnd +* +* \todo CODE +*/ +template +void keep_connected_components(PolygonMesh& pmesh + , const FaceRange& components_to_keep + , const NamedParameters& np) +{ + typedef PolygonMesh PM; + using boost::choose_param; + using boost::get_param; + using boost::choose_const_pmap; + + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::vertex_iterator vertex_iterator; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::face_iterator face_iterator; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::graph_traits::edge_descriptor edge_descriptor; + typedef typename boost::graph_traits::edge_iterator edge_iterator; + + //EdgeConstraintMap + typedef typename boost::lookup_named_param_def < + CGAL::edge_is_constrained_t, + NamedParameters, + internal::No_constraint//default + > ::type EdgeConstraintMap; + EdgeConstraintMap ecmap = choose_param(get_param(np, edge_is_constrained), + EdgeConstraintMap()); + + //FaceIndexMap + typedef typename GetFaceIndexMap::type FaceIndexMap; + FaceIndexMap fim = choose_const_pmap(get_param(np, boost::face_index), + pmesh, + boost::face_index); + + //vector_property_map + boost::vector_property_map face_cc(fim); + + //VertexIndexMap + typedef typename GetVertexIndexMap::type VertexIndexMap; + VertexIndexMap vim = choose_const_pmap(get_param(np, boost::vertex_index), + pmesh, + boost::vertex_index); + + std::size_t num = connected_components(pmesh, face_cc, + CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(ecmap). + face_index_map(fim)); + + + +} + } // namespace Polygon_mesh_processing