BGL按键索引顶点
BGL indexing a vertex by keys
我的要求是有一个图结构,其中每个顶点都是由boost::uuids::uuid
唯一标识的。所有顶点都有一个颜色属性,相似类别的顶点将根据颜色属性分组。我不是在静态地图上工作,顶点和边缘将动态创建和删除。
typedef boost::adjacency_list<
boost::listS,
boost::listS,
boost::bidirectionalS,
boost::property<boost::vertex_index_t, boost::uuids::uuid,
boost::property<boost::vertex_color_t, resource_color,
boost::property<boost::vertex_underlying_t, boost::shared_ptr<actual_object*> > > >,
detail::edge_property
> graph_type;
graph_type _graph;
boost::property_map<graph_type, boost::vertex_index_t>::type _index_map;
boost::property_map<graph_type, boost::vertex_color_t>::type _color_map;
boost::property_map<graph_type, boost::vertex_underlying_t>::type _underlying_map;
在构造函数我创建了所有3个地图
_index_map = boost::get(boost::vertex_index_t(), _graph);
_color_map = boost::get(boost::vertex_color_t(), _graph);
_underlying_map = boost::get(boost::vertex_underlying_t(), _graph);
当添加一个顶点
add_resource(resource_color c, actual_object* o){
graph_type::vertex_descriptor v = boost::add_vertex(o->uuid(), _graph);
_color_map[v] = c;
_underlying_map[v] = o;
}
For list一个顶点的UUID
uuid_list list;
boost::graph_traits<graph_type>::vertex_iterator vi, vi_end;
for(boost::tie(vi, vi_end) = boost::vertices(_graph); vi != vi_end; ++vi){
list.push_back(_index_map[*vi]);
}
return list;
这样我总是迭代图的顶点并获得它的属性。但是我也想要另一种方式。从UUID到顶点,就像一个并行的std::map,它将通过添加/删除操作或类似的操作自动更新。
我也不能保持外部std::map
和手动同步,因为boost::adjacency_list<boost::listS, boost::listS>::vertex_descriptor
计算为void*
,我需要序列化支持。
那么下面的事情是可行的吗
- 通过
boost::vertex_index_t
值查找顶点 - 遍历
boost::property_map
- 将
std::map
或bimap
与index
属性同步
我记得库中有一个labeled_graph
实用程序大致支持这一点。它有一个很高的便利系数,我记得它在效率方面不那么有趣。应该有一个使用它的示例:
- http://www.boost.org/doc/libs/1_46_1/libs/graph/example/labeled_graph.cpp
无论如何(并参考您前面的问题),您当然可以使用外部属性映射。这有以下好处:
- 你可以一直保留不在图表中的条目
-
你可以有你需要的反向索引,例如
-
图形的切割集,增强图形库(用于获得颜色地图的反向查找)。
它也包含一个等效的方法,但使用Boost多索引容器,甚至更灵活
-
回答子弹:
-
find vertex through
boost::vertex_index_t
value是的,但是如果你想要高效,你确实需要有一个外部映射的反向查找或使用你自己的数据结构,并适应它来建模你需要的图形概念(更多的工作,显然)
-
遍历
boost::property_map
。使用
boost::get(tag, graph)
获取属性映射,遍历要访问的所有实体,并为每个属性调用属性映射。例如boost::property_map<Graph, boost::vertex_index_t>::type pmap = boost::get(boost::vertex_index, graph); boost::graph_traits<Graph>::vertex_iterator b, e; for (boost::tie(b,e) = boost::vertices(graph); b!=e; ++b) std::cout << "The vertex ID is: " << boost::get(pmap, *b) << "n";
-
使用
index
属性同步外部std::map
或bimap
上面的链接应该给你一些想法
- D3D11-将混合权重和索引传递到顶点着色器
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 使用 glvertex4i 传递网格面索引时的顶点着色器错误
- 使用此网格函数的立方体的正确顶点和索引是什么
- DirectX11只绘制填充索引和顶点缓冲区中的一半顶点
- tiny_obj_loader到 Direct3D 顶点缓冲区和索引缓冲区数组
- 我可以将单个顶点索引与具有所有属性(位置、法线、texCoord)的顶点缓冲区一起使用吗?
- DirectX:如果绑定索引缓冲区但不绑定顶点缓冲区,会发生什么情况
- Directx 11 - 是将顶点缓冲区中的所有顶点推送到顶点着色器,还是仅编制索引
- 可以在同一 VBO 中存储不同的顶点属性和索引
- 通过查找重复顶点从 vec3 对象的向量计算索引
- 如何从顶点/索引缓冲区创建 CGAL Nef_polyhedron_3
- Directx11如何管理多个顶点/索引缓冲区
- 顶点/索引缓冲区混淆,带有OpenGL 3.3
- CGAL - 在德劳奈三角测量后检索顶点索引
- 如何从Subdiv2D Delaunay三角测量中获取顶点索引
- Boost:: Dijkstra 最短路径,如何从路径迭代器获取顶点索引
- 如何读取顶点/索引缓冲区
- (DirectX 11)动态顶点/索引缓冲区实现恒定的场景内容变化
- 将地图转换为顶点索引不起作用