9 #ifndef MRPT_DIRECTED_TREE_H 10 #define MRPT_DIRECTED_TREE_H 55 template <
class TYPE_EDGES = u
int8_t>
71 TNodeID child_id_,
bool direction_child_to_parent =
false,
72 const TYPE_EDGES& edge_data = TYPE_EDGES())
73 :
id(child_id_),
reverse(direction_child_to_parent),
data(edge_data)
118 const size_t depth_level) = 0;
126 const size_t root_depth_level = 0)
const 128 const size_t next_depth_level = root_depth_level + 1;
132 const TListEdges& children = itChildren->second;
134 itEdge != children.end(); ++itEdge)
136 user_visitor.OnVisitNode(
root, *itEdge, next_depth_level);
138 itEdge->id, user_visitor,
148 const size_t root_depth_level = 0)
const 150 const size_t next_depth_level = root_depth_level + 1;
154 const TListEdges& children = itChildren->second;
156 itEdge != children.end(); ++itEdge)
157 user_visitor.OnVisitNode(
root, *itEdge, next_depth_level);
159 itEdge != children.end(); ++itEdge)
161 itEdge->id, user_visitor,
178 std::ostringstream
s;
182 std::ostringstream& m_s;
183 CMyVisitor(std::ostringstream&
s) : m_s(
s) {}
184 virtual void OnVisitNode(
187 TYPE_EDGES>::Visitor::tree_t::TEdgeInfo& edge_to_child,
188 const size_t depth_level)
override 191 << (edge_to_child.reverse ?
"<-" :
"->")
192 << edge_to_child.id << std::endl;
195 CMyVisitor myVisitor(
s);
196 s <<
root << std::endl;
std::map< TNodeID, TListEdges > TMapNode2ListEdges
TMapNode2ListEdges edges_to_children
The edges of each node.
A special kind of graph in the form of a tree with directed edges and optional edge annotations of te...
std::list< TEdgeInfo > TListEdges
const Scalar * const_iterator
CDirectedTree< TYPE_EDGES > tree_t
Virtual base class for user-defined visitors.
void visitDepthFirst(const TNodeID root, Visitor &user_visitor, const size_t root_depth_level=0) const
Depth-first visit of all children nodes of a given root (itself excluded from the visit)...
bool reverse
True if edge direction is child->parent, false if it's parent->child.
uint64_t TNodeID
The type for node IDs in graphs of different types.
virtual void OnVisitNode(const TNodeID parent, const typename tree_t::TEdgeInfo &edge_to_child, const size_t depth_level)=0
Virtual method to be implemented by the user and which will be called during the visit to a graph wit...
uint64_t TNodeID
The type for node IDs in graphs of different types.
TNodeID root
The root of the tree.
TNodeID id
The ID of the child node.
GLsizei const GLchar ** string
void visitBreadthFirst(const TNodeID root, Visitor &user_visitor, const size_t root_depth_level=0) const
Breadth-first visit of all children nodes of a given root (itself excluded from the visit)...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TEdgeInfo(TNodeID child_id_, bool direction_child_to_parent=false, const TYPE_EDGES &edge_data=TYPE_EDGES())
Edge constructor from data.
TYPE_EDGES data
User data for this edge.
void clear()
Empty all edge data and set "root" to INVALID_NODEID.
GLsizei GLsizei GLenum GLenum const GLvoid * data
std::string getAsTextDescription() const
Return a text representation of the tree spanned in a depth-first view, as in this example: ...