vtkPolyData: RemoveDeletedCells is wrong implemented
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I found a fundamental problem in RemoveDeletedCells of vtkPolyData. Here is the description:
- the implementation assumes that the internal Cells (vtkCellTypes) is sorted by type
- i.e. defined verts, lines, polys and triangle-strips are sequential stored
- when InsertNextCell is used to create a cell of type VTK_POLYGON, the order will be disturbed
- if CellData is present, the method won't work correct
- an extra call of BuildCells is not an option, because it does not sort the associated CellData
Example:
No. Cell Scalar 1 VTK_TRIANGLE_STRIP 1 2 VTK_TRIANGLE_STRIP 2 3 VTK_POLYGON 3 <-- DeleteCell is called for this cell
The expected result after RemoveCeletedCells:
No. Cell Scalar 1 VTK_TRIANGLE_STRIP 1 2 VTK_TRIANGLE_STRIP 2
This is what I get:
No. Cell Scalar 1 VTK_POLYGON 1 2 VTK_TRIANGLE_STRIP 2
You can see that the first cell is not of type VTK_TRIANGLE_STRIP.
The problem is variable c. It is continually incremented by the for-loops. Within a loop it is used to determine the type of the cell at position c in Cells. But that is wrong!!! Who says, that the Cells[c] is or was of the type the for-loop was build on?
Look at my attachment for a compilable example.
A workaround can be found at https://github.com/zippy84/vtkbool/blob/master/GeomHelper.cxx#L80
I can also provide a patch.
Bug is present in all versions of VTK!!!