vtkDistancePolyDataFilter for point clouds

I naively thought that the vtkDistancePolyDataFilter would work with point clouds, but I’m getting this error message:

2021-11-05 19:05:03.577 (   0.200s) [         9E35740]vtkDistancePolyDataFilt:87     ERR| vtkDistancePolyDataFilter (0x562ec60a9af0): No points/cells to difference from
import numpy as np
import vtk
from vedo import Points

def dist(poly1, poly2):
    df = vtk.vtkDistancePolyDataFilter()
    df.SetInputData(0, poly1)
    df.SetInputData(1, poly2)
    return df.GetOutput()

pts1 = Points(np.random.randn(1000,3))
pts2 = Points(np.random.randn(1000,3))
poly1 = pts1.polydata() # vtkPolyData
poly2 = pts2.polydata()

print(poly1.GetNumberOfPoints(), poly1.GetNumberOfCells()) # 1000,1000

dist(poly1, poly2)

what am I doing wrong?

This filter only works if input on port 0 has polys.

Is there another filter then I should use in this case? or should I loop over the points to find the closest?

If you want to get the closest point to some query, you can directly use a vtkAbstractPointLocator. If your input is kind of evenly dense, then I advise using a vtkStaticPointLocator. If you have small parts that are very dense and others that are more sparse, you should use a vtkKdTreePointLocator.

1 Like

You should add these explanations in the docs.