How can I get the index of the Nearest Point when I use CGAL::K_neighbor_search to do the Nearest Neighbor Search?

风格不统一 提交于 2019-12-08 13:07:30

问题


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";
}

the result is as follows:

Point: 222 129 161

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?


回答1:


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.



来源:https://stackoverflow.com/questions/35885470/how-can-i-get-the-index-of-the-nearest-point-when-i-use-cgalk-neighbor-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!