Nearest neighbour(closest point) search using vtkKdTree

I am using vtk’s kdtree to search closest point, here is a simple example that, to my surprise, returned a value that was not what I was expecting

import vtk

points = vtk.vtkPoints()
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(0, 1, 0)
points.InsertNextPoint(0, 0, 1)

kdtree = vtk.vtkKdTree()
kdtree.BuildLocatorFromPoints(points)

dist=vtk.reference(0.0)
p = kdtree.FindClosestPoint(0,0,10,dist)

print(p,dist)

The printed result is 0 4.0 and the value I expect is 2 81
Did I make a mistake?

At the top of my head this is a little puzzling for me. If you use the vtkStaticPointLocator which is also much faster, this approach works

import vtk

points = vtk.vtkPoints()
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(0, 1, 0)
points.InsertNextPoint(0, 0, 1)

pd = vtk.vtkPolyData()
pd.SetPoints(points)

locator = vtk.vtkStaticPointLocator()
locator.SetDataSet(pd)

p = locator.FindClosestPoint(0,0,10)
print(pd.GetPoint(p))

Then you can compute distance afterwards. It could be due to the vtkKdtree needs cells to properly build

Thanks, I tried both vtkStaticPointLocator and vtkPointLocator, they are both correct.