00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039 #ifndef POSE_GRAPH_GRAPH_SEARCH_IMPL_H
00040 #define POSE_GRAPH_GRAPH_SEARCH_IMPL_H
00041
00042 #include <boost/foreach.hpp>
00043 #include <boost/graph/filtered_graph.hpp>
00044 #include <boost/graph/breadth_first_search.hpp>
00045
00046
00047 namespace pose_graph
00048 {
00049
00050 template <class Predicate>
00051 NodeSet filterNearbyNodes (const ConstraintGraph& g, const unsigned n, const Predicate& p)
00052 {
00053 return filterNearbyNodes (g, n, p, AllEdges());
00054 }
00055
00056 template <class G>
00057 class Visitor : public boost::default_bfs_visitor
00058 {
00059 public:
00060 void discover_vertex (const GraphVertex& v, const G& g)
00061 {
00062 ROS_DEBUG_STREAM_NAMED ("graph_search", "Discovering vertex " << g[v].id );
00063 }
00064 };
00065
00066 template <class NodePred, class EdgePred>
00067 NodeSet filterNearbyNodes (const ConstraintGraph& g, const unsigned n, const NodePred& node_pred,
00068 const EdgePred& edge_pred)
00069 {
00070
00071 const GraphVertex v = g.idVertex(n);
00072 typedef boost::filtered_graph<Graph, EdgePred, NodePred> FilteredGraph;
00073 const FilteredGraph filtered(g.graph(), edge_pred, node_pred);
00074
00075
00076 typedef std::map<GraphVertex, boost::default_color_type> ColorMap;
00077 ColorMap cmap;
00078 boost::associative_property_map<ColorMap> color_pmap(cmap);
00079
00080
00081 boost::breadth_first_search(filtered, v, color_map(color_pmap).visitor(Visitor<FilteredGraph>()));
00082
00083
00084 NodeSet nodes;
00085 BOOST_FOREACH (GraphVertex w, vertices(filtered)) {
00086 ROS_ASSERT_MSG(cmap[w] != boost::gray_color, "Unexpectedly found a gray node after graph search");
00087 if (cmap[w] == boost::black_color)
00088 nodes.insert(filtered[w].id);
00089 }
00090 return nodes;
00091 }
00092
00093
00094 }
00095
00096 #endif // include guard