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()
u_grid.SetPoints(points)
merger = vtkMergePoints() # Used to insert new point
merger.SetDataSet(u_grid)
merger.InitPointInsertion(u_grid.GetPoints(), u_grid.GetBounds())
merger.Update()
Try to insert exist point:
a = reference(999)
merger.InsertUniquePoint((0, 0, 0), a)
print(a)
print(merger.GetPoints().GetPoint(a))
The result is right:
0
(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)
print(b)
print(merger.GetPoints().GetPoint(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:
print(merger.GetPoints().GetPoint(0))
print(merger.GetPoints().GetPoint(1))
print(merger.GetPoints().GetPoint(2))
# 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.