Nearest neighbor problem in the presence of callbacks
Consider the following problem: given a set of triangles T and a point x, find a triangle closest to x.
Current ArborX nearest neighbor algorithm does not support this use case. Instead, it finds the nearest bounding volume to x, and then uses the triangle in it. The main limitation is due to lacking knowledge in ArborX to the correct distance to an object that was bounded.
The only way for the user to pass that distance to us is through changing the callback interface. The simplest approach I can think of is to add a callback tag indicating that the callback returns a distance. Then, during the traversal, we update the radius with that precise distance when encountering a leaf node. This changes the current algorithm in two ways:
- Callback may be called during the traversal
- Callback may be called twice for the same primitive (once during the traversal, second time on the final result).
We could use a dummy output functor during the first call, as we don't need any output.
@dalg24 Do you see any problem with this approach?
/cc @terwin
If we do implement API v2 (see this discussion), we may add a distance wrapper for the primitives, keeping the current signature for the callback.
Will be fixed by APIv2. Closing.