【发布时间】:2014-04-23 09:51:48
【问题描述】:
我正在使用自己的节点和边属性创建自定义提升图。 我将图表定义如下:
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);
}
我现在要做的是从节点和边属性列表中初始化这个图(在 init 方法中)。 NodeInfo 和 EdgeInfo 是具有原始类型的简单结构。到目前为止,我已经这样做了:
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
}
}
所以,我设法添加了顶点并设置了属性(希望它是正确的)。现在,每个 EdgeInfo 都有一个源和目标 id,它们标识边缘的两个节点。问题是我需要通过 Id 从图中检索它们(使用我之前设置的 nodeIndex 属性),以便我可以调用 add_edge 方法。我真的不知道该怎么做。希望大家能帮帮我。
【问题讨论】:
标签: c++ boost-graph