Populate a tree from vectors with BGL

Home / Uncategorized / Populate a tree from vectors with BGL

I have three different vectors of objects that I need to make a tree structure from them. Let’s assume we have vector parents, vector children, and vector leaves. Therefore, each member of vector children has several children that sits at the end of the tree as leaves, and has one parent that sits as parents. What I am using is defining Vertex properties and Edges properties as below, and then define a bidirectional graph:struct VertexData
std::string obj_name; // concatenation of labels
std::string obj_class_num;
int num;
vector segments_list;
bool is_leaf=false;

struct EdgeData
std::string edge_name;
double confidence;

typedef boost::adjacency_list > Graph;

Graph graph;

What I am doing currently, is looping through the vector leaves, for each member, I find the parent and make an edge. Then assign properties to the edge and vertices. But then for next leaf, I should check if already it has a parent in the tree or I should add a new vertex for its parent. Another thing that I tried, was looping through the vector children, and for each member try to make its leaves and parent. But I am not sure what is the correct way to do this. Here is a link: adding custom vertices to a boost graph that I try to do the same but with iterations.


Read more

Leave a Reply

Your email address will not be published. Required fields are marked *