使用CGAL :: K_neighbor_search进行最近邻居搜索时,如何获取最近点的索引? [英] How can I get the index of the Nearest Point when I use CGAL::K_neighbor_search to do the Nearest Neighbor Search?

查看:408
本文介绍了使用CGAL :: K_neighbor_search进行最近邻居搜索时,如何获取最近点的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using CGAL's K_neighbor_search module to do the nearest neighbor search problem. It's nice and easily to use. The example code shows that given a query point, it can find the nearest neighbor point from a set of points as well as the distance. However, I can only get the nearest neighbor point itself. I don't know how to get the index of the point found by the algorithm. For example, I use the following code,

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

Point: 222 129 161

距离:189.307

Distance: 189.307

但是如何获取结果点的索引?至于这个问题的原因,我想获得最近邻点的法线,因此我需要参考该点. 有人可以帮我吗?

But how can I get the index of the result point? As for the reason of this question, I want to get the normal of the nearest neighbor point, so I need to reference the point. Could anybody help me?

推荐答案

如果您想直接在kd树中使用索引,可以查看

If you want to use indices directly in the kd-tree you can look at this example. Points are sorted in an external vector and the kd-tree uses indices to refer to the points internally store.

这篇关于使用CGAL :: K_neighbor_search进行最近邻居搜索时,如何获取最近点的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆