# vtkDistancePolyDataFilter for point clouds

**URL:** https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088
**Category:** Support
**Created:** [November 5, 2021, 6:10pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088 "2021-11-05T18:10:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [November 5, 2021, 6:10pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088/1 "2021-11-05T18:10:52Z")

</div>

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

```auto
2021-11-05 19:05:03.577 ( 0.200s) [9E35740]vtkDistancePolyDataFilt:87 ERR| vtkDistancePolyDataFilter (0x562ec60a9af0): No points/cells to difference from

```

```python
import numpy as np
import vtk
from vedo import Points

def dist(poly1, poly2):
    df = vtk.vtkDistancePolyDataFilter()
    df.ComputeSecondDistanceOff()
    df.SetInputData(0, poly1)
    df.SetInputData(1, poly2)
    df.SignedDistanceOff()
    df.Update()
    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?

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [November 5, 2021, 6:13pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088/2 "2021-11-05T18:13:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [November 5, 2021, 6:16pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088/3 "2021-11-05T18:16:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [November 5, 2021, 6:30pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088/4 "2021-11-05T18:30:57Z")

</div>

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`.

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [November 5, 2021, 6:43pm UTC](https://discourse.vtk.org/t/vtkdistancepolydatafilter-for-point-clouds/7088/5 "2021-11-05T18:43:33Z")

</div>

You should add these explanations in the docs.
