From 8277f73a2c524c41f336828eddd1d1cbf04b5897 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 13 Feb 2015 18:08:52 +0100 Subject: [PATCH] Add connected_components without EdgeConstraintMap --- .../PackageDescription.txt | 3 +- .../connected_component.cpp | 2 +- .../Connected_components.h | 30 +++++++++++++++++-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index f0802ee646c..b5f68d43179 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -61,7 +61,8 @@ ## Other Classes and Functions ## - `CGAL::Polygon_mesh_slicer` - `CGAL::Polygon_Mesh_processing::keep_largest_connected_components()` -- `CGAL::Polygon_Mesh_processing::discover_connected_component()` +- `CGAL::Polygon_Mesh_processing::connected_component()` +- `CGAL::Polygon_Mesh_processing::connected_components()` \todo remove FairWeightCalculator and replace it by a property map. Note that the default property map should be documented \todo make template parameter names uniform in other packages using BGL. Here we chose PolygonMesh as template parameter. diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp index 47b80ac16f5..627a81e093f 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp @@ -49,7 +49,7 @@ int main(int, char* argv[]) Mesh::Property_map fccmap; fccmap = sm.add_property_map("f:CC").first; int num = CGAL::Polygon_mesh_processing::connected_components(sm, - Constraint(sm), + //Constraint(sm), fccmap); std::cerr << "The graph has " << num << " connected components (face connectivity)" << std::endl; 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 8531c71800c..f115078ce19 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 @@ -398,7 +398,8 @@ template struct No_constraint { No_constraint() { } - No_constraint(G & g) : g(&g) { } + No_constraint(G & g) + : g(&g) { } template bool operator[](const T & ) const { @@ -408,12 +409,13 @@ struct No_constraint { G* g; }; -template + template > struct No_border { No_border() {} - No_border(G & g, EdgeConstraintMap ecm) : g(&g), ecm(ecm) + No_border(G & g, EdgeConstraintMap ecm = EdgeConstraintMap()) + : g(&g), ecm(ecm) { } bool operator()(typename boost::graph_traits::edge_descriptor e) const { @@ -427,6 +429,8 @@ struct No_border { EdgeConstraintMap ecm; }; + + }// namespace internal @@ -474,6 +478,26 @@ struct No_border { return boost::connected_components(finite_dual, fim); } + /*! + * \ingroup PkgPolygonMeshProcessing + * computes for each face the index of the connected components to which it belongs. + * Two faces are considered to be in the same connected component if they share an edge. + * \tparam PolygonMesh a model of `FaceGraph` + * \tparam FaceIndexMap the property map with the face index as value type, and the index of its connected component + * \returns the number of connected components. + */ + template + typename boost::graph_traits::faces_size_type + connected_components(PolygonMesh& pmesh, + FaceIndexMap& fim) + { + typedef Dual Dual; + typedef boost::filtered_graph > FiniteDual; + + Dual dual(pmesh); + FiniteDual finite_dual(dual,internal::No_border(pmesh)); + return boost::connected_components(finite_dual, fim); + } } // namespace Polygon_mesh_processing } // namespace CGAL