2010-12-01 57 views
1

我还有一个关于Boost图形库的问题,我无法通过Google搜索或阅读文档来回答自己。这与我的其他问题没有直接关系,所以我想我最好开始一个新线程。BGL:我如何直接访问节点和边的数据?

我有一个邻接布局的图形,并使用绑定的属性来访问节点和边的数据。为了方便起见,我在Graph中使用了typedef。因此,我可以访问存储的数据,例如用于vertex_descriptor的,通过输入这样的事情:

Graph[my_vertex_descriptor].setX(4); 
Graph[my_vertex_descriptor].setY(10); 

现在我想以定义与数据存储对象的引用,以便能够键入类似的东西:

typedef Graph[vertex_descriptor]::type Vertex; 
Vertex v = Graph[my_vertex_descriptor]; 
v.setX(4); 
v.setY(10); 

通过这种或我试图避免不必要地重新计算通过使用映射的[]operator和特定描述符对象来访问的映射值的类似方法。我的顶点和边缘包含大量数据,所以在某些情况下,我当前的代码会产生许多相同值的重新计算来处理这些数据。这似乎很难看。

有谁知道是否有可能实现我想要做的?

回答

0

关闭我的头顶,这应该工作(假设你使用内置的图形类型有明确的graph_traits之一):

typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; 
Vertex v = Graph[my_vertex_descriptor]; 
v.setX(4); 
v.setY(10); 

实际上你可以访问大量的这种方式,采取看看BGL的图概念的更多信息:http://www.boost.org/doc/libs/1_45_0/libs/graph/doc/graph_concepts.html

1

我用捆绑的属性和:

Bundled_vertex_property prop_v = get(vertex_bundle, my_graph) // or get(vertex_bundle, v, my_graph) 
Bundled_edge_property prop_e = get(edge_bundle, my_graph) // or get(edge_bundle, v, my_graph) 

拿到捆绑的直接财产LY。

+0

上面实际上应该是: `Bundled_vertex_property prop_v = GET(vertex_bundle,my_graph,vertex_descriptor的)`` Bundled_edge_property prop_e = GET(edge_bundle,my_graph,vertex_descriptor的)` 还要注意的是`edge_bundle`和`vertex_bundle`不是变量,它们是预定义的描述符。 – 2012-11-18 00:40:51