到网格所有点的最短路径

shortest path to all points of mesh

本文关键字:最短路径 网格      更新时间:2023-10-16

我正在研究水密网格,我正在尝试在网格表面上获得从网格中的每个顶点到网格中每个其他顶点的最短路径。

例如,当网格中有 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