Is it a bug in vtkMergePoint of Python?

I have a point set, and I want to insert new point which don’t duplication. So I used vtkMergePoints, but something went wrong, new point overwrite the exist point rather than added.
Code is follow:

## Initial point set and vtkMergePoints
points = vtkPoints()  # My point set
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 1, 1)
points.InsertNextPoint(2, 2, 2)

u_grid = vtkUnstructuredGrid()

merger = vtkMergePoints()  # Used to insert new point
merger.InitPointInsertion(u_grid.GetPoints(), u_grid.GetBounds())

Try to insert exist point:

a = reference(999)
merger.InsertUniquePoint((0, 0, 0), a)

The result is right:

(0.0, 0.0, 0.0)

But try to insert a point that don’t exitst:

b = reference(999)
merger.InsertUniquePoint((3, 3, 3), b)

Something wrong occur:

0 # It should be 3!!! And the point (0, 0, 0) is overwrited
(3.0, 3.0, 3.0)

And try to print the exist points:


# result:
(3.0, 3.0, 3.0) # It should be (0, 0, 0)
(1.0, 1.0, 1.0)
(2.0, 2.0, 2.0)

Is the step of initialization used vtkUnstructuredGrid have question?
I have read the source code of C++, I think in Python, the function ‘InsertNextPoint’ not be called correctly in vtkMergePoints even in vtkPointLocator.

For a merging point locator, when you call InitPointInsertion(points, bounds), the points must be empty.

VTK expects you to add all the points to this locator with InsertUniquePoint(). If you call InsertNextPoint(), even if you do it before InitPointInsertion(), then the internal data structure of vtkMergePoints will be corrupted.