What is the most straight-forward way to determine whether a vtkImageData object is “empty”. In other words, whether or not it contains any pixel/voxel data?
What’s with GetNumberOfCells?
In 3D Slicer, we usually check
(extent <= extent && extent <= extent && extent <= extent) . This is what vtkImageData::GetNumberOfCells() computes, too.
Even if the extent is non-empty, it is still possible that voxel data is not allocated yet, so then we also need to check
(image->GetPointData() != nullptr) && (imageDataScalar->GetPointData()->GetScalars() != nullptr). This is particularly important, because at many places in VTK,
GetPointData()->GetScalars() is called without checking if
GetPointData() != nullptr, leading to crashes if you set an empty image as input.
This is what I was looking for. Thanks Andras!