MantisBT - VTK
View Issue Details
0012684VTK(No Category)public2011-10-28 12:022013-12-19 07:24
John Stark 
Bill Lorensen 
normalminorhave not tried
closedfixed 
 
6.1.0 
TBD
incorrect functionality
0012684: vtkImageImport has problems with PipelineMtime and upstream changes.
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 dbb88cda6b6d703b237b431629562ff275aae000 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<vtkImageCast> imCast = vtkSmartPointer<vtkImageCast>::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;
  }
}
No tags attached.
patch ComputePipelineMTime.patch (1,746) 2012-11-06 08:23
https://www.vtk.org/Bug/file/9331/ComputePipelineMTime.patch
cxx sampleCrash.cxx (4,387) 2012-11-06 08:38
https://www.vtk.org/Bug/file/9332/sampleCrash.cxx
txt CMakeLists.txt (637) 2013-12-18 17:13
https://www.vtk.org/Bug/file/9575/CMakeLists.txt
cxx main.cxx (4,392) 2013-12-18 17:13
https://www.vtk.org/Bug/file/9576/main.cxx
Issue History
2011-10-28 12:02John StarkNew Issue
2011-10-28 12:07John StarkNote Added: 0027620
2012-11-06 08:23John StarkFile Added: ComputePipelineMTime.patch
2012-11-06 08:31John StarkNote Added: 0029655
2012-11-06 08:38John StarkNote Edited: 0029655bug_revision_view_page.php?bugnote_id=29655#r519
2012-11-06 08:38John StarkFile Added: sampleCrash.cxx
2012-12-12 07:52John StarkNote Edited: 0029655bug_revision_view_page.php?bugnote_id=29655#r534
2012-12-12 07:55John StarkNote Added: 0029870
2013-12-16 12:57Dave DeMarleAssigned To => Bill Lorensen
2013-12-16 12:57Dave DeMarleStatusbacklog => tabled
2013-12-16 12:58Dave DeMarleStatustabled => backlog
2013-12-16 16:41John StarkNote Edited: 0029870bug_revision_view_page.php?bugnote_id=29870#r690
2013-12-18 17:13John StarkFile Added: CMakeLists.txt
2013-12-18 17:13John StarkFile Added: main.cxx
2013-12-18 17:16John StarkNote Added: 0032026
2013-12-18 17:21John StarkNote Edited: 0032026bug_revision_view_page.php?bugnote_id=32026#r696
2013-12-19 07:24Dave DeMarleNote Added: 0032027
2013-12-19 07:24Dave DeMarleStatusbacklog => closed
2013-12-19 07:24Dave DeMarleResolutionopen => fixed
2013-12-19 07:24Dave DeMarleFixed in Version => 6.1.0

Notes
(0027620)
John Stark   
2011-10-28 12:07   
One possible solution may be to implement vtkAlgorithm::ComputePipelineMTime in vtkImageImport to return this->GetMTime(), but I have not tested this.
(0029655)
John Stark   
2012-11-06 08:31   
(edited on: 2012-12-12 07:52)
I have attached a patch for vtk5.10.0 which indeed fixes this bug as suggested above.

This bug can lead to a crash if the input is changed to a new image, and the old image is deleted. This can leave the down stream pipeline pointing to stale memory, usually causing a seg fault.

A sample of how this can happen is also attached.

I pushed a patch to gerrit : http://review.source.kitware.com/#/c/8885/ [^]

(0029870)
John Stark   
2012-12-12 07:55   
(edited on: 2013-12-16 16:41)
This also fixed problems for other users : http://www.vtk.org/pipermail/vtkusers/2012-November/126372.html [^]

Edit: Update link: http://public.kitware.com/pipermail/vtkusers/2012-November/077414.html [^]

(0032026)
John Stark   
2013-12-18 17:16   
(edited on: 2013-12-18 17:21)
I just uploaded 2 files (CMakeLists.txt & main.cxx) which make it easy to reproduce the bug against a recent master in VTK 6 (efb1793c2215) and ITK v4.5.0.

Running the un-patched master I get the message "FAILED assert *pixelPtr == SecondFillValue" , with the patch applied there is no message.

(0032027)
Dave DeMarle   
2013-12-19 07:24   
patch applied.
thanks John!