Changes after Andreas' review

This commit is contained in:
Andreas Fabri 2017-02-07 09:49:09 +01:00 committed by Maxime Gimeno
parent 5661666782
commit 0707e06cee
5 changed files with 102 additions and 19 deletions

View File

@ -65,31 +65,32 @@ struct Connected_components_graph
/*!
* \brief Creates a Connected_components_graph of the connected components of `graph` that are listed in `pids`.
typedef unspecified_type Indices;
* \param graph the graph containing the wanted patches.
* \param fccmap the property_map that assigns a patch to each face, with
* \param fccmap the property_map that assigns a connected component to each face, with
`boost::graph_traits<Graph>::%face_descriptor` as key type and
`graph_traits<Graph>::faces_size_type` as value type.
* \param pids the indices of the patches of interest.
* \param ir the indices of the connected components of interest.
*/
template <typename IndexRange>
Connected_components_graph(const Graph& graph,
FaceComponentMap fccmap,
const boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type>& pids)
: _graph(graph), _property_map(fccmap), _patch_indices(pids)
{
}
const IndexRange& ir)
: _graph(graph), _property_map(fccmap), _patch_indices(ir.begin(),ir.end())
{}
/*!
* \brief Creates a Connected_components_graph of the connected component `pid` of `graph`.
* \brief Creates a Connected_components_graph of the connected component `id` of `graph`.
* \param graph the graph containing the wanted patch.
* \param fccmap the property_map that assigns a patch to each face
* \param pid the index of the patch of interest.
* \param id the index of the connected component of interest.
*/
Connected_components_graph(const Graph& graph,
FaceComponentMap fccmap,
typename boost::property_traits<FaceComponentMap>::value_type pid)
: _graph(graph), _property_map(fccmap)
{
_patch_indices = boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type>();
_patch_indices.insert(pid);
}
///returns the graph of the Connected_components_graph.
@ -98,9 +99,21 @@ struct Connected_components_graph
///returns the property map of the Connected_components_graph.
FaceComponentMap property_map()const{ return _property_map; }
///returns the unordered set of patch ids of the Connected_components_graph.
boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type> patch_indices()const{ return _patch_indices; }
#ifndef DOXYGEN_RUNNING
const boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type>&
#else
Index_range
#endif
indices()const{ return _patch_indices; }
/// Replaces the current unordered set of patches by `pids`
void change_patch_id(boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type> pids) { _patch_indices = pids;}
template <typename IndexRange>
void set_connected_components(const IndexRange& ir) { _patch_indices = boost::unordered_set<typename boost::property_traits<FaceComponentMap>::value_type>(ir.begin(), ir.end());}
void set_connected_component(typename boost::property_traits<FaceComponentMap>::value_type pid) {
_patch_indices.clear();
_patch_indices.insert(pid);
}
struct Is_simplex_valid
{
@ -194,7 +207,7 @@ bool
in_CC(const typename boost::graph_traits< Connected_components_graph<Graph, FaceComponentMap> >::face_descriptor f,
const Connected_components_graph<Graph, FaceComponentMap> & w)
{
return w.patch_indices().find(boost::get(w.property_map(), f)) != w.patch_indices().end();
return w.indices().find(boost::get(w.property_map(), f)) != w.indices().end();
}
template <class Graph, typename FaceComponentMap >
@ -546,8 +559,7 @@ halfedge(typename boost::graph_traits< Connected_components_graph<Graph, FaceCom
template <class Graph, typename FaceComponentMap >
std::pair<typename boost::graph_traits<Connected_components_graph<Graph, FaceComponentMap> >::face_iterator,
typename boost::graph_traits<Connected_components_graph<Graph, FaceComponentMap> >::face_iterator>
Iterator_range<typename boost::graph_traits<Connected_components_graph<Graph, FaceComponentMap> >::face_iterator>
faces(const Connected_components_graph<Graph, FaceComponentMap> & w)
{
typedef typename boost::graph_traits<Connected_components_graph<Graph, FaceComponentMap> >::face_iterator face_iterator;

View File

@ -598,7 +598,7 @@ should be discarded in favour of major connected components.
\subsection CCExample Connected Components Example
The following example shows how to record the connected
The first example shows how to record the connected
components of a polygon mesh.
In particular, we provide an example for the optional parameter \c EdgeConstraintMap,
a property map that returns information about an edge being a \e constraint or not.
@ -607,6 +607,12 @@ the propagation of a connected component index to cross it.
\cgalExample{Polygon_mesh_processing/connected_components_example.cpp}
The second example shows how to use the class template `Connected_components_graph`
which enables to treat one or several connected components as a face graph.
\cgalExample{Polygon_mesh_processing/connected_components_graph_example.cpp}
\section PMPDistance Approximate Hausdorff Distance
This package provides methods to compute (approximate) distances between meshes and point sets.

View File

@ -7,6 +7,7 @@
\example Polygon_mesh_processing/point_inside_example.cpp
\example Polygon_mesh_processing/triangulate_faces_example.cpp
\example Polygon_mesh_processing/connected_components_example.cpp
\example Polygon_mesh_processing/connected_components_graph_example.cpp
\example Polygon_mesh_processing/polygon_soup_example.cpp
\example Polygon_mesh_processing/triangulate_polyline_example.cpp
\example Polygon_mesh_processing/refine_fair_example.cpp

View File

@ -90,6 +90,7 @@ create_single_source_cgal_program( "compute_normals_example.cpp" CXX_FEATURES cx
create_single_source_cgal_program( "point_inside_example.cpp")
create_single_source_cgal_program( "triangulate_faces_example.cpp")
create_single_source_cgal_program( "connected_components_example.cpp")
create_single_source_cgal_program( "connected_components_graph_example.cpp")
create_single_source_cgal_program( "polygon_soup_example.cpp")
create_single_source_cgal_program( "triangulate_polyline_example.cpp")
create_single_source_cgal_program( "mesh_slicer_example.cpp")

View File

@ -0,0 +1,63 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/connected_components.h>
#include <CGAL/boost/graph/Connected_components_graph.h>
#include <boost/property_map/property_map.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <fstream>
#include <map>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef boost::graph_traits<Mesh>::faces_size_type faces_size_type;
typedef Mesh::Property_map<face_descriptor, faces_size_type> FCCmap;
typedef CGAL::Connected_components_graph<Mesh,FCCmap> CCG;
namespace PMP = CGAL::Polygon_mesh_processing;
int main(int argc, char* argv[])
{
std::ifstream input((argc > 1) ? argv[1] : "data/blobby_3cc.off");
Mesh mesh;
if (!input || !(input >> mesh) || mesh.is_empty()) {
std::cerr << "Not a valid off file." << std::endl;
return 1;
}
FCCmap fccmap = mesh.add_property_map<face_descriptor, faces_size_type>("f:CC").first;
faces_size_type num = PMP::connected_components(mesh,fccmap);
std::cerr << "- The graph has " << num << " connected components (face connectivity)" << std::endl;
CCG ccg(mesh, fccmap, faces_size_type(0));
std::cout << "The faces in component 0 are:" << std::endl;
BOOST_FOREACH(boost::graph_traits<CCG>::face_descriptor f, faces(ccg)){
std::cout << f << std::endl;
}
if(num>1){
std::vector<faces_size_type> components;
components.push_back(0);
components.push_back(1);
ccg.set_connected_components(components);
std::cout << "The faces in components 0 and 1 are:" << std::endl;
BOOST_FOREACH(CCG::face_descriptor f, faces(ccg)){
std::cout << f << std::endl;
}
}
return 0;
}