BGL :获取带有数据的顶点描述符
BGL : get vertex descriptor with data
我想用顶点的组成来获取顶点描述符,如下所示:
struct WayPoint{
std::pair<float, float> pos; // with this composant
};
附录列表:
typedef boost::adjacency_list<
boost::listS,
boost::vecS,
boost::undirectedS,
WayPoint,
WayPointConnection
> WayPointGraph;
typedef WayPointGraph::vertex_descriptor WayPointID;
typedef WayPointGraph::edge_descriptor WayPointConnectionID;
我构建了我的图形并创建了所有顶点/边....目的是在图形上应用 ASTAR。
void PathFinding::findMeAPath(std::pair<float, float>begin, std::pair<float, float>end)
{
std::vector<WayPointID> p(boost::num_vertices(graphe));
std::vector<float> d(boost::num_vertices(graphe));
WayPointID start = // I want to find the WayPointID with begin
WayPointID goal = //same with end;
shortest_path.clear();
try {
boost::astar_search
(
graphe,
start,
boost::astar_heuristic<WayPointGraph, float>(),
boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(astar_goal_visitor(goal)).weight_map(boost::get(&WayPointConnection::dist, graphe))
);
} catch(found_goal fg) {
for(WayPointID v = goal;; v = p[v]) {
shortest_path.push_front(v);
if(p[v] == v)
break;
}
}
}
你需要编写一个函数来查找给定位置的顶点。您定义的图形类型使用 std::vector 来存储顶点,因此函数必须遍历它并将查询的位置与每个 WayPoint 进行比较。像这样的事情可以做:
std::pair<WayPointID, bool> find_vertex(const WayPoint& wp, const WayPointGraph& graph)
{
for (WayPointID id = 0; id < boost::num_vertices(graph); ++id)
{
if (equal(graph[id], wp))
return std::make_pair(id, true);
}
return std::make_pair(0, false);
}
请注意,该函数返回一对(Id + 布尔标志)以指示搜索是否成功,因此您将按如下方式使用它:
bool vertex_found;
WayPointID start;
std::tie (start, vertex_found) = find_vertex(begin, graphe);
if (!vertex_found)
// do something about it
此外,该函数还使用以下方法来比较位置:
bool equal(const std::pair<float, float>& p1, const std::pair<float, float>& p2)
{
const float EPS = 1e-6;
return (std::fabs(p1.first - p2.first) < EPS &&
std::fabs(p1.second - p2.second) < EPS);
}
相关文章:
- 如何循环打印顶点结构
- 使用VerQueryValue检索应用程序的文件描述
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- D3D11-将混合权重和索引传递到顶点着色器
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 从 Boost ASIO 获取 epoll 描述符 io_service对象
- 从返回的顶点缓冲区查询顶点结构
- Vulkan 中的动态顶点缓冲区格式设置
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 如何将一半传递给顶点着色器?
- 在 DirectX 11 中从 GPU 读回顶点缓冲区(并获取顶点)
- QT QOpenGLWidget:如何在不使用数据块复制的情况下修改VBO中的单个顶点值?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- BGL Adjacency_list:如何使用顶点属性(而不是描述符)对OUT_EDGE进行排序
- C Boost ::如何从顶点描述符创建地图
- BGL :获取带有数据的顶点描述符
- 提升图库中的顶点描述符和索引有什么区别?
- BGL:使用绑定属性来存储另一个顶点的顶点描述符
- BGL:我如何从一个绑定的对象到一个顶点描述符