为boost::graph::copy_graph提供顶点映射参数
Provide vertex-mapping parameter to boost::graph::copy_graph
boost函数boost::graph::copy_graph
template <class VertexListGraph, class MutableGraph> void
copy_graph(const VertexListGraph& G, MutableGraph& G_copy,
const bgl_named_params<P, T, R>& params = all defaults)
在其参数说明中列出UTIL/OUT: orig_to_copy(Orig2CopyMap c)
是复制顶点到原始顶点的映射。我需要这张地图!
(滚动到http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/copy_graph.html底部)
如何访问/提供最后一个参数orig_to_copy?你能给我一个代码示例(完成这个代码)吗?
void doSomething(graph_t& g){
graph_t g_copy;
copy_graph(g, g_copy, [...???...]);
// here I would like to access the Orig2CopyMap
}
找到了这个解决方案:http://d.hatena.ne.jp/gununu/20111006/1317880754
void doSomething(graph_t& g){
typedef graph_t::vertex_descriptor vertex_t;
typedef std::map<vertex_t, vertex_t> vertex_map_t;
vertex_map_t vertexMap;
// this boost type is needed around the map
associative_property_map<vertex_map_t> vertexMapWrapper(vertexMap);
graph_t g_copy;
copy_graph(g, g_copy, boost::orig_to_copy(vertexMapWrapper));
std::cout << "mapping from copy to original: " << std::endl;
for(auto& iter : vertexMap){
std::cout << iter.first << " -> " << iter.second << std::endl;
}
}
像这样:
typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t;
typedef boost::property_map<graph_t, boost::vertex_index_t>::type index_map_t;
//for simple adjacency_list<> this type would be more efficient:
typedef boost::iterator_property_map<typename std::vector<vertex_t>::iterator,
index_map_t,vertex_t,vertex_t&> IsoMap;
//maps vertices of g to vertices of g_copy
std::vector<vertex_t> isoValues( num_vertices(g));
IsoMap mapV( isoValues.begin());
boost::copy_graph( g, g_copy, boost::orig_to_copy(mapV) ); //means g_copy += g
相关文章:
- 如何循环打印顶点结构
- Boost Graph Library,修复节点大小
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何将一半传递给顶点着色器?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 创建异构顶点数据数组的可移植方法
- 在Boost Graph库中选择给定顶点的随机进出邻居的有效方法
- 如何使用boost::graph dijkstra的算法,如果顶点属性是指针?
- 使用Boost :: Graph随机访问顶点
- 从Boost Graph中删除多个顶点
- 尝试将顶点添加到自定义Graph数据结构时出现分段错误
- 如何使用boost::graph算法与listS,setS作为顶点/边缘容器
- 为boost::graph::copy_graph提供顶点映射参数
- 具有自定义顶点和边的Boost Graph