Suppose I have a 3D lattice, identify each cell with its coordinates (x,y,z), and a class Cell
holds its properties. I want to use it as the vertex objects of BGL, first to construct an empty graph, then iterate each cell to insert vertexes and build edges upon some criteria among the neighborhood cells.
Now, I want to count how many isolated interconnected cells (clusters). Said that it is a typical Bread-First-Search problem. People tell me to learn BGL since it is a toolbox for graph/lattice research…
My high level thinking is to go through every cell, if it is not visited and has edge(s), traverses all the connected cells, mark them as a cluster and assign a cluster ID.
The doc said
If you need to perform multiple breadth-first searches on a graph (for example, if there are some disconnected components) then use the breadth_first_visit() function and do your own color initialization.
So, I turn to breadth_first_visit(). It has 2 variants:
template <class IncidenceGraph, class P, class T, class R>
void breadth_first_visit(IncidenceGraph& G,
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
const bgl_named_params<P, T, R>& params);
template <class IncidenceGraph, class Buffer, class BFSVisitor, class ColorMap>
void breadth_first_visit
(const IncidenceGraph& g,
typename graph_traits<IncidenceGraph>::vertex_descriptor s,
Buffer& Q, BFSVisitor vis, ColorMap color)
since I don’t want to add color property into the Cell class, I want to set up a standalone ColorMap
. The Buffer
and BFSVisitor
looks straightforward. However, the ColorMap
is in fact a boost Property Map Library!! Another big blocker. The documentation of the property map library seems even more worse than BGL :~(
Can anyone point me to some effective primer, tutorial or even give me a code fragment to illustrate how to make a minimal colorMap please?