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

Miller, James V (Research) millerjv@crd.ge.com
Wed, 15 May 2002 12:57:20 -0400


In a threaded filter, the pipeline calls a method called AllocateOutputs() 
on your filter. The default implementation of AllocateOutputs() does a 
SetBufferedRegion()/Allocate() sequence.  This method can overloaded if a 
filter works on images where each pixel is a list or vector.

Note that Image has a FillBuffer() method that can be used to clear or 
empty an image.  Can you use FillBuffer() to set all your lists to a default
list?


-----Original Message-----
From: Damion Shelton [mailto:dmshelto@andrew.cmu.edu]
Sent: Wednesday, May 15, 2002 12:37 PM
To: insight-developers@public.kitware.com
Subject: [Insight-developers] clearing the output image in a filter


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-
_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers