使用提升图 [BGL] 检查add_edge之前顶点是否已存在
Check if vertex already exists before an add_edge using Boost Graph [BGL]
有没有办法检查使用 Boost 创建的图形中的顶点是否已经存在,而不是循环遍历顶点?
如果它已经存在,如何使用其顶点描述符添加新的边?
例:
Graph g;
vertex v;
v = add_vertex(1, g);
vertex_name[v] = "root";
v = add_vertex(2, g);
vertex_name[v] = "vert_2";
v = add_vertex(3, g);
vertex_name[v] = "vert_3";
// This is not possible
edge e1;
if (vertex.find("root") == vertex.end()) {
(boost::add_edge("root", "vert_2", g)).first
}
我想你可能喜欢labeled_graph适配器:
住在科里鲁
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/labeled_graph.hpp>
using namespace boost;
int main()
{
using AdjList = adjacency_list<setS, vecS, directedS>;
using Graph = labeled_graph<AdjList, std::string, hash_mapS>;
Graph g;
for (std::string name : { "root", "vert_2", "vert_3" }) {
add_vertex(name, g);
}
struct { std::string from, to; } edges [] = {
{"root", "vert_2"},
{"vert_2", "vert_3"},
{"vert_2", "vert_3"},
{"vert_2", "new_1"},
{"new_1", "new_2"},
};
for (auto const& addition : edges) {
if (g.vertex(addition.from) == g.null_vertex())
std::cout << "source vertex (" << addition.from << ") not presentn";
else if (g.vertex(addition.to) == g.null_vertex())
std::cout << "target vertex (" << addition.to << ") not presentn";
else {
auto insertion = add_edge_by_label(addition.from, addition.to, g);
std::cout << "Edge: (" << addition.from << " -> " << addition.to << ") "
<< (insertion.second? "inserted":"already exists")
<< "n";
}
}
}
指纹:
Edge: (root -> vert_2) inserted
Edge: (vert_2 -> vert_3) inserted
Edge: (vert_2 -> vert_3) already exists
target vertex (new_1) not present
source vertex (new_1) not present
相关文章:
- 如何循环打印顶点结构
- D3D11-将混合权重和索引传递到顶点着色器
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何将一半传递给顶点着色器?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 创建异构顶点数据数组的可移植方法
- 使用 glvertex4i 传递网格面索引时的顶点着色器错误
- 基于 Chromium Edge 的 WebView2 不起作用
- 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- 如何应用带有cv::cuda和C++的Canny Edge检测器?
- OpenGL 相机移动程序顶点着色器问题
- 使用 std::list 存储顶点并使用 SFML 绘制它们
- 为什么顶点数组对象会导致错误?
- 从 CGAL 3D 网格生成中获取顶点坐标的 -6.27744e+66:mesh_implicit_sphere示例
- 将顶点位置从顶点传递到片段着色器 - 仅在使用 Nsight 进行调试时有效