【问题标题】:How can I get the index of the Nearest Point when I use CGAL::K_neighbor_search to do the Nearest Neighbor Search?使用 CGAL::K_neighbor_search 进行最近邻搜索时,如何获取最近点的索引?
【发布时间】:2016-06-23 11:11:45
【问题描述】:

我正在使用 CGAL 的 K_neighbor_search 模块来解决最近邻搜索问题。它很好用而且很容易使用。示例代码显示,给定一个查询点,它可以从一组点中找到最近的邻居点以及距离。但是,我只能获得最近的邻居点本身。我不知道如何获取算法找到的点的索引。 比如我用下面的代码,

std::list<Point_d> points;
Tree tree(points.begin(), points.end());
Neighbor_search search(tree, query, N);
for(Neighbor_search::iterator it = search.begin(); it != search.end(); ++it)
{
    std::cout << "Point: " << it->first << "\n";
    std::cout << "Distance: " << std::sqrt(it->second) << "\n";
}

结果如下:

点:222 129 161

距离:189.307

但是我怎样才能得到结果点的索引呢?至于这个问题的原因,我想得到最近邻点的法线,所以我需要参考这个点。 有人能帮帮我吗?

【问题讨论】:

    标签: cgal nearest-neighbor


    【解决方案1】:

    如果您想直接在 kd-tree 中使用索引,您可以查看 this example。 点在外部向量中排序,kd-tree 使用索引来引用内部存储的点。

    【讨论】:

      猜你喜欢
      • 2015-03-18
      • 2018-06-16
      • 1970-01-01
      • 2023-03-25
      • 2012-04-15
      • 1970-01-01
      • 2017-10-21
      • 2011-10-21
      • 2012-09-16
      相关资源
      最近更新 更多