到网格所有点的最短路径
shortest path to all points of mesh
我正在研究水密网格,我正在尝试在网格表面上获得从网格中的每个顶点到网格中每个其他顶点的最短路径。
例如,当网格中有 100 个顶点时,我会得到 100X100 的距离,我想将它们存储在 100x100 距离矩阵中。
我使用CGAL(因此也使用BOOST),我对这两种方法几乎没有经验。
这是我到目前为止所拥有的:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iterator>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Random.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Surface_mesh_shortest_path.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/boost/graph/iterator.h>
#include "boost/multi_array.hpp"
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron_3;
typedef CGAL::Surface_mesh_shortest_path_traits<Kernel, Polyhedron_3> Traits;
typedef CGAL::Surface_mesh_shortest_path<Traits> Surface_mesh_shortest_path;
typedef Surface_mesh_shortest_path::Shortest_path_result Shortest_path_result;
typedef boost::graph_traits<Polyhedron_3> Graph_traits;
typedef Graph_traits::vertex_iterator vertex_iterator;
typedef Graph_traits::vertex_descriptor vertex_desc;
typedef Graph_traits::face_iterator face_iterator;
typedef boost::multi_array<double, 2> distArray;
typedef distArray::index distArrayIndex;
class DistanceMeasure {
public:
static distArray getDistances(Polyhedron_3 p);
};
作为我的头文件,并且:
#include "DistanceMeasure.h"
distArray DistanceMeasure::getDistances(Polyhedron_3 p) {
distArray dists(boost::extents[p.size_of_vertices()][p.size_of_vertices()]);
// pick up a random face
CGAL::set_halfedgeds_items_id(p);
vertex_iterator pit = vertices(p).first;
// construct a shortest path query object and add a source point
Surface_mesh_shortest_path shortest_paths(p);
//add all points from p to the source points
for ( pit = vertices(p).first; pit != vertices(p).end(); pit++)
shortest_paths.add_source_point(*pit);
//for all points in p get distance to all the other points
vertex_iterator vit, vit_end;
for ( boost::tie(vit, vit_end) = vertices(p);
vit != vit_end; ++vit)
{
//get distances
Shortest_path_result res = shortest_paths.shortest_distance_to_source_points(*vit);
//iterate over all query results
Surface_mesh_shortest_path::Source_point_iterator spit;
int count = 0;
for(spit = res.second; spit != shortest_paths.source_points_end(); spit++) {
count++;
}
}
return dists;
}
为我的源文件。
在我的不寻常中,我得到了到res中所有其他点的距离,并且可以在
for(spit = res.second; spit != shortest_paths.source_points_end(); spit++) {
count++;
}
因此,我有2个问题:第一:我做对了吗?我有分辨率中的所有距离吗?第二:我如何在结果中获取顶点的 id 和到它们的距离(以及来自 spit),以便能够识别它们并将它们的距离存储在 dists 数组中。
到目前为止,我的想法是,也许顺序是我把点放入源点的顺序。
当我使用例如 100 个顶点运行它并使用计数来计算我得到的 res 中的顶点数时。
1009998979695..21
我想这可能是因为 CGAL 不会计算两次距离。我仍然不确定索引。
谢谢你的回答斯蒂芬
对于每个有类似问题的人:我无法为我所说的第一个问题给出解决方案,但交叉问题可以在 CGAL 中计算如下:http://doc.cgal.org/latest/AABB_tree/index.html
相关文章:
- 内存效率表示最短路径的方法?
- 用于查找网格中最短路径的算法
- 查找最短路径算法
- BFS 打印最短路径
- 使用 Dijkstra 算法跟踪两个节点之间的最短路径
- 使用C++具有两个数字的最短路径算法.(C++)
- 使用迭代深度优先搜索算法的未加权图的最短路径
- 如何仅在 2 个节点之间获取最短路径,给定邻接列表有向图?
- 如何使用贝尔曼-福特算法返回所有具有捆绑重量的最短路径?
- 使用优先级队列查找所有与 Dijkstra 相同的最短路径
- 尝试在图形中查找最短路径时的无限循环
- C++计算有向图中的最短路径
- 使用BFS存储和打印最短路径
- 如何制作由原始图形的最短路径边组成的新图形
- 有没有一种方法可以使用弗洛伊德-沃歇尔算法给出最短路径,其中存在负权重循环而不允许重叠边缘?
- 加权图的开始和结束的最短路径
- 使 c++11 Dijkstra 实现返回最短路径
- 如何在网格上找到从A到B的最短路径
- 到网格所有点的最短路径
- 4x4 网格 c++ 上的最短路径