vtkImageImport has problems with PipelineMtime and upstream changes.
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I have been using the ImageToVTKImageFilter, but have found a bug that the downstream pipeline does not correctly detect changes upstream of the filter.
In the sample below, an ITK image is constructed and filled with the value 127. This value is correctly extracted as float using a vtkImageCast filter. However, when I change the data buffer, filling it with zeros, the output initially reports the image value as unchanged, even after Update() is called. It appears to explicitly require the ITK converter to be updated, which should not be necessary.
I think the bug relates to vtkImageImport, which does not correctly report the PipelineMtime, but I am not sure.
I am using a git version of VTK, based on dbb88cda from July this year.
Code sample:
#include <itkImage.h> #include <itkImageToVTKImageFilter.h>
#include <vtkImageCast.h> #include <vtkImageData.h> #include <vtkSmartPointer.h>
int main() { const int dims[3] = { 64, 64, 64 }; // Image size in pixels
typedef itk::Image<unsigned char, 3> ImageType;
ImageType::RegionType region; for ( int i(0); i<3; ++i ) { region.SetSize(i, dims[i] ); region.SetIndex(i,0); }
ImageType::Pointer image = ImageType::New(); image->SetLargestPossibleRegion(region); image->SetBufferedRegion(region); image->Allocate(); image->FillBuffer( 127 );
typedef itk::ImageToVTKImageFilter< ImageType > ConverterType; ConverterType::Pointer myConverter = ConverterType::New(); myConverter->SetInput ( image ); myConverter->UpdateOutputInformation();
vtkSmartPointer imCast = vtkSmartPointer::New(); imCast->SetOutputScalarTypeToFloat(); imCast->SetInput(myConverter->GetOutput());
vtkImageData * tstImg = imCast->GetOutput(); tstImg->Update(); float fval0 = ((const float*)tstImg->GetScalarPointer())[0];
image->FillBuffer(0); image->Modified(); image->GetPixelContainer()->Modified();
tstImg->Update(); float fval1 = ((const float*)tstImg->GetScalarPointer())[0];
myConverter->GetOutput()->UpdateInformation(); tstImg->Update(); float fval2 = ((const float*)tstImg->GetScalarPointer())[0];
if ( (fval0 == 127.) && (fval1 == 0.) && (fval2 == 0.) ) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } }