Hi, and thanks again for feedback.
I am building an application where I digitize points with mouse clicks and add them to a polyline PolyData. Adding points is OK.
self is my PolyData-derived subclass in the following, and I have two methods:
def append_point(self, point_vector=None):
"""Appends a single point from Numpy point_vector at the end of the VTK point array"""
point_vector = point_vector.flat[:] # to be sure that point_vector is a row vector
if self.GetNumberOfPoints() == 0:
points = vtk.vtkPoints()
points.InsertPoint(0, point_vector, point_vector, point_vector)
self.GetPoints().InsertNextPoint(point_vector, point_vector, point_vector)
def append_cell(self, cell_array=None):
"""Appends a single line cell from Numpy array with vertex ids."""
cell_array = cell_array.flat[:] # to be sure that point_vector is a row vector
line = vtk.vtkLine()
if self.GetNumberOfCells() == 0:
pline_cells = vtk.vtkCellArray()
Then I am able to incrementally add points and line cells with:
new_cell = np.asarray([[point_n - 1, point_n]]) # point_n is the present number of points
my_polyline.append_point(point_vector=new_point) # new_point is a numpy 3x1 array with point coordinates from mouse interaction
This works flawlessly. I digitize with left clicks and end the digitization with a right click (with some mouse interactions omitted here).
Now I would like to undo the last point with a middle click (very handy when digitizing long lines). For this I need to delete the last point and line cell. I have tried different solutions but none works. I have also tried to delete all cells and points with self.Initialize(), then redefine all, but I always have crashes due to memory problems, or polylines with messed up topology.
Probably the solution is to filter the last cell and point out, but this leaves the problem of substituting the new PolyData obtained as output of the filter to the old one (the one that I am digitizing).
Do you know some example, possibly in Python, from which I could take some inspiration?
Thanks very much!