[Insight-developers] clearing the output image in a filter

Damion Shelton dmshelto@andrew.cmu.edu
Wed, 15 May 2002 12:37:22 -0400


Hi,

I'm running into some difficulties "clearing" the output image in an 
ImageToImageFilter. Luis confirmed that this is neccessary when the output 
of the filter is a data type such as a list, stack, etc. We're working with 
an output type of BloxPixel, which derived from the STL list.

The problem is the following: when the output image is not destroyed 
between successive Update() calls, the new data is appended to the old data 
rather than completely replacing the old data (i.e. it's being pushed onto 
the existing list).

Luis suggested that the way around this was to traverse each list (pixel) 
with an iterator, delete the objects on the list, and then call clear() on 
the list. This functionality is now implemented in BloxImage::EmptyImage().

However, I'm still running into problems with crashes, and I suspect that I 
may be calling EmptyImage() at the wrong point in the filter. As an 
example, BloxBoundaryPointToCoreAtomImageFilter::GenerateData() has the 
following first few lines:

  // Get the input and output pointers
  m_InputPtr  = this->GetInput(0);
  m_OutputPtr = this->GetOutput(0);

  // Allocate the output
  m_OutputPtr->SetBufferedRegion( m_OutputPtr->GetRequestedRegion() );
  m_OutputPtr->Allocate();

  // To avoid appending data, empty the output image
  m_OutputPtr->EmptyImage();

Is that the correct point to call EmptyImage()? The crash occurs in the 
following execution order, with modifications being made only to the filter 
mentioned above:

1) Load image
2) First update
3) Change filter
4) Second update
5) Change filter
6) Third update - crash

Any suggestions? In a threaded filter where the image is not allocated 
explicitly, how would the output image be "cleared"?

Thanks,
-Damion-