简体   繁体   English

图形硬件上的最近邻搜索

[英]Nearest neighbour search on graphics hardware

Given a huge collection of points (float64) in 2d space...鉴于二维空间中的大量点(float64)......

Is there a way to determine the nearest neighbour using a feature of OpenGL or DirectX?有没有办法使用 OpenGL 或 DirectX 的功能来确定最近的邻居?

I've implemented a kd-tree, which is still not fast enough.我已经实现了一个 kd-tree,它仍然不够快。

A kd-tree should work just fine. kd-tree应该可以正常工作。 But here's some hints.但这里有一些提示。

I implemented a kd-tree once for a million point data set once.我曾经为一百万个点数据集实现了一次 kd-tree。 Here's what I learned out of it:这是我从中学到的:

Did you try profiling your code?您是否尝试分析您的代码? You might find that there are easy optimizations to make such as common helper functions needing to be forced inline.您可能会发现可以进行简单的优化,例如需要强制内联的常见辅助函数。

Did you actually test your code to validate that it was culling out tree branches for partitions that are easily identified as "too far away".您是否真的测试过您的代码以验证它是否正在为容易识别为“太远”的分区剔除树枝。 If you aren't careful, you can easily have a bug that does needless distance computations on points too far away.如果你不小心,你很容易就会有一个错误,对太远的点进行不必要的距离计算。

Easiest thing: Where comparing linear distance between points, you don't need to take the SQRT of (x2-x1)*(y2-y1).最简单的事情:在比较点之间的线性距离时,您不需要采用 (x2-x1)*(y2-y1) 的 SQRT。

Most of the time spent in my code was just building the tree from the original data set, including multiple full sorts on each iteration deciding which axis was the best to partition on.在我的代码中花费的大部分时间只是从原始数据集构建树,包括每次迭代的多个完整排序,决定哪个轴最适合分区。 An easier algorithm would be to just alternate between partitioning on the x and y axis for each tree branch and to cache the sorting order for each axis.一个更简单的算法是在每个树枝的 x 轴和 y 轴上交替分区,并缓存每个轴的排序顺序。 It may not build the most optimal search tree, but the overall savings can be enormous.它可能不会构建最佳搜索树,但总体节省可能是巨大的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM