Hello I have a polydata and I need to find the closest point of that polydata to a given plane. One way to do this is to go through all the points and calculate their distance to the plane, but it is inefficient. Does Someone know of an efficient way to do that?

I think at least once you will have to go through all the points either to compute their distances or to compute their local coordinates relative to the plane and sort them by local Z or to populate a spatial index to find the closet point, etc. I think the only way to improve performance is to do this in parallel (e.g. multithreading).

I write geoscience software that often have to deal with clouds with tens of millions of points. I use Boost’s spatial index API (Spatial Indexes - 1.64.0) for spatial queries and they’re quite efficient. However, the somewhat constly step to populate it (bulk load) is inevitable. But this is done just once.

Are you performing this closest point operation more than once? say in an interactive loop while the plane is repeatedly repositioned? If so, it’s worth making this work with a point locator (some coding would be required).

If you are performing this operation just once, then it’s almost trivial (using vtkSMPTools) to write a threaded loop to evaluate the plane equation and find the closest point. (If you look at a class like vtkPlaneCutter.cxx, you will see some code used to evaluate the plane equation for example).