Upcoming changes to vtkCellArray

Generally these changes to vtkCellArray seem very positive, but there was a regression that led to a bug in SlicerDMRI. In earlier VTK versions, calling this method gave a pointer into the vtkCellArray

vtkIdTypeArray *cellArrayIds = cellArray->GetData();

but with the new API it returns a copy of the data using ExportLegacyFormat in the implementation.

This meant that our code, which operated no the cellArrayIds to add lines to the cell array, had no effect on the vtkPolyData and the lines were missing. After some investigation I was able to fix it with the patch linked below.

Realistically the change in GetData was an API regression because the behavior of the call changed. I’d argue that vtkCellArray::GetData() should have been removed along with GetPointer / WritePointer and replaced with a stub that generated a compile time error with a comment that described the replacement API and how to use it.

In addition, the current implementation of GetData() should have been renamed GetLegacyDataCopy().

It’s probably not good to make such a change to the API now that it’s been released, but I wanted to flag this in case somebody else runs into a similar issue in the future.

Perhaps the best solution would be to mark vtkCellArray::GetData() as deprecated.

1 Like