升压图breath_first_visit中的颜色图
Color map in boost graph breadth_first_visit
我想使用boosts breadth_first_visit
方法,我想为它提供我自己的"外部"颜色图。我将该图定义如下
typedef boost::adjacency_list<boost::setS, boost::listS, boost::undirectedS,
boost::property<boost::vertex_index_t, int,
boost::property<boost::vertex_color_t, boost::default_color_type,
Node_t>>> GraphType;
其中Node_t
是一个结构,定义顶点的属性。然而,我不知道如何为BFS提供我自己的颜色图。我想把顶点颜色存储在一个向量中,所以我的定义看起来像
std::vector<boost::default_color_type> colors;
但是我不知道如何把它用于bfs。
两个
boost::breadth_first_search(g, *boost::vertices(g).first,
boost::color_map(colors));
也不是
boost::breadth_first_search(g, *boost::vertices(g).first,
boost::color_map(&colors[0]));
正在工作。虽然第一个给了我一堆不同的编译器错误(例如,不支持默认int,"boost::color_traits"类类型的使用需要类型参数列表),但第二个只有C2664的编译中止:"boost::put"无法将参数2从"void*"转换为"ptrdif_t"。
所以问题是:我怎样才能使用我自己的颜色映射结构。另一个问题是:如何获得特定顶点描述符的颜色值?
好的,我使用了另一种方法,但解决了我的问题。对于那些像我一样对boost中的彩色地图感到困惑的人或感兴趣的人:
bfs使用的颜色图的类型是:
typedef boost::property_map<GraphType, boost::vertex_color_t>::type color_map_t;
color_map_t colorMap; //Create a color map
这将vertex_descriptor
映射到(在我的情况下)default_color_type
。对助推bfs的适当调用是
boost::breadth_first_visit(g, *boost::vertices(g).first, boost::color_map(colorMap));
给定一个像一样映射颜色编号的color_names结构
const char* color_names[] = {"white", "gray", "green", "red", "black"};
可以通过迭代图中的所有顶点来迭代颜色,并使用当前顶点的顶点描述符作为颜色图中[]运算符的自变量:
GraphType::vertex_iterator it, itEnd;
for (boost::tie(it, itEnd) = boost::vertices(g); it != itEnd; it++)
{
std::cout << "Color of node " << *it << " is " << color_names[colorMap[*it]] << std::endl;
}
相关文章:
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- std::visit无法识别类型
- 如何从SDL_Surface获取特定像素的颜色
- 在c++队列中使用pop和visit实现线程安全
- 列表视图更改选择颜色
- GtkTreeView 交替行颜色
- dx11 渲染到纹理仅显示透明颜色
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 为什么我的 LEGACY OPENGL 颜色反转了?
- 双击更改 mfc 中列表控件中的行的颜色
- std::visit and std::variant usage
- 更改 QT 中按钮的颜色
- 当我使用CHAR_INFO结构时,控制台会无缘无故地改变颜色
- 列表视图项的替代颜色
- GLSL 将 uint 转换为浮点颜色
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- Vec3b:r/g/b 颜色的最大值为 254,而不是 255
- 如何将矢量对象更改为不同的颜色?