Hi,
I’m messaging because I believe I came across a bug. I’ve found a hacky fix for it, but I don’t think my fix is the correct long-term solution. Im using vtk==8.2.0 installed from Conda.
If you filter.GetOutput()
from some filter and then try to delete a cell polydata.DeleteCell(idx)
of the outputted polydata you get a seg fault. However, if you simply interact with the cells in some (any?) way and then perform the delete there is no error (e.g., by doing polydata.GetCell(idx)
and then do polydata.DeleteCell(idx)
; note that I don’t think idx has to be the same between these, and .GetCell()
only needs to be done once and then you can iterate over the entire mesh and delete whatever cells you want.
Basic/reproducible example code:
ERROR:
import vtk
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(0.0, 0.0, 0.0)
sphereSource.SetRadius(5.0)
sphereSource.SetPhiResolution(100)
sphereSource.SetThetaResolution(100)
sphereSource.Update()
sphere = vtk.vtkPolyData()
sphere.DeepCopy(sphereSource.GetOutput())
sphere.DeleteCell(1)
RESOLUTION:
import vtk
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(0.0, 0.0, 0.0)
sphereSource.SetRadius(5.0)
sphereSource.SetPhiResolution(100)
sphereSource.SetThetaResolution(100)
sphereSource.Update()
sphere = vtk.vtkPolyData()
sphere.DeepCopy(sphereSource.GetOutput())
sphere.GetCell(1)
sphere.DeleteCell(1)
Note that it doesn’t matter if I DeepCopy
the output of the filter or not.
Clearly, the fix is extremely simple and I can easily include this in any of my code. However, without knowing this is the problem it could be a pain to sort out.
Let me know if any additional information is of use.
Thanks,
Anthony.