I'm creating a custom boost graph with my own node and edges properties. I defined the graph as follows:
class NavGraph : public boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, NodeInfo, EdgeInfo > {
public:
typedef boost::graph_traits<NavGraph>::vertex_descriptor Vertex;
typedef boost::graph_traits<NavGraph>::edge_descriptor Edge;
NavGraph(){}
void init(const std::vector<NodeInfo>& nodes, const std::vector<EdgeInfo>& edges);
}
What I'm trying to do now is to initialize this graph from a list of node and edge properties (in the init method). NodeInfo and EdgeInfo are simple structures with primitive types. So far I've done this:
void NavGraph::init(const std::vector<NodeInfo>& nodes, const std::vector<EdgeInfo>& edges){
//Add the Vertices
for (std::vector<NodeInfo>::const_iterator it = nodes.begin() ; it != nodes.end(); ++it){
Vertex u = boost::add_vertex(*this);
(*this)[u].nodeIndex = (*it).nodeIndex;
(*this)[u].x = (*it).x;
(*this)[u].y = (*it).y;
(*this)[u].z = (*it).z;
}
//Add the edges
for (std::vector<EdgeInfo>::const_iterator it = edges.begin() ; it != edges.end(); ++it){
//To be implemented
}
}
So, I manage to add the vertices and set the properties (hope it is right). Now, every EdgeInfo has a source and target id, which identify the two nodes of the edge. The problem is that I need to retrieve them by Id from the graph (with the nodeIndex property that I set before), so that I can call the add_edge method. I don't really know how to do this. Hope you guys can help me.