user3798903
user3798903

Reputation: 31

Breadth first search from multiple sources using Boost Graph Library

I want to be able to use bfs in BGL to find all the trees of a forest, which is basically finding connected components using multiple source vertices. For example, it may be used to find different connected regions of an image to enable image segmentation (this is just one of the cases). How can I use the breadth_first_search in BGL to do this? Any pointers to examples/sources would be greatly appreciated! I have surveyed BGL documentation and have not been successful in finding what I want to do.

Upvotes: 0

Views: 542

Answers (1)

pbible
pbible

Reputation: 1259

Just use the connected components that already exists in boost. There is a useful example. Afterwards all vertices in the graph will have a mapping to their component. If you really want to use BFS on individual parts, just use a visitor and push nodes into a vector.

You can specify your start node with:

breadth_first_search(graph, visitor(vis).root_vertex(root_vertex_descriptor));

Upvotes: 1

Related Questions