在知道连通性的情况下,在boost邻接图中构建相邻顶点
Build neighboring vertices in a boost adjacency graph knowing the connectivity
我对boost图库有问题。
在初始化步骤,我想在这个邻接图中存储一个图像:
typedef boost::adjacency_list<boost::vecS,
boost::vecS,
boost::undirectedS,
boost::property<boost::vertex_bundle_t, unsigned int>,
boost::property<boost::edge_bundle_t, float>,
boost::no_property> GraphType
我做了第一个循环,为图像的每个像素创建一个顶点(使用OTB库来处理图像,in_iter只是图像像素上的迭代器):
unsigned long int curr_id = 0;
for(in_iter.GoToBegin(); !in_iter.IsAtEnd(); ++in_iter)
{
boost::add_vertex(curr_id, *_graph);
curr_id++;
}
现在我想为顶点创建它与邻居的连接(4连接):我试过了,但不起作用:
curr_id = 0;
long int neighbors[4];
auto iterBounds = boost::vertices(*_graph);
for(auto v_iter = iterBounds.first; v_iter != iterBounds.second; v_iter++)
{
FindNeighboring(curr_id, neighbors, rows, cols);
for(short j = 0; j<4; j++)
{
if(neighbors[j] > -1)
{
boost::add_vertex(*_graph->m_vertices[curr_id],
*_graph->m_vertices[neighbors[j]],
std::numeric_limits<float>::max();
*_graph);
}
}
}
我想访问顶点描述符,知道它的位置。有可能在BGL中做到这一点吗?
谢谢你的帮助!
答案是"是和否"。
如果您对图使用通用adjacency_list
,那么,当然,您必须自己维护对应关系<coords> <--> <vertex>
。您可以将其保留为boost提供的映射::unordered_map<点,vertex_descriptor>或作为boost::bimap,甚至std::map。填充地图并使其与图形保持一致将是您的责任。
或者,您可以考虑BGL内置类grid_graph
。它为您提供了从坐标到顶点描述符的映射:
// Get the vertex associated with vertex_index
Traits::vertex_descriptor
vertex(Traits::vertices_size_type vertex_index,
const Graph& graph);
// Get the index associated with vertex
Traits::vertices_size_type
get(boost::vertex_index_t,
const Graph& graph,
Traits::vertex_descriptor vertex);
(以及用于边的类似功能)。
在这里,您不需要创建单独的顶点,它们是在您指定图的维度时由图构造函数中的BGL创建的。
您可能希望使用某种自定义特性映射将像素与每个顶点相关联,但这是一个单独的故事。
相关文章:
- 如何循环打印顶点结构
- C++为构建时间获取QDateTime的可靠方法
- 无法在 CLion 中构建 C++ 项目
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用ndk-build.cmd构建Android.so文件
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 构建一个由C和C++文件组成的库
- llvm构建器向基本块添加终止符
- D3D11-将混合权重和索引传递到顶点着色器
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 如何跨平台将二进制资源构建到程序中?
- 如何从 2 个向量构建顶点矩阵?
- C++ 提升图形库:构建在无向图形搜索中访问的顶点的向量
- 在知道连通性的情况下,在boost邻接图中构建相邻顶点