[Insight-developers] Confused about persistance of filter outputs

Luis Ibanez luis.ibanez@kitware.com
Sat, 26 Apr 2003 18:22:13 -0400


Hi Hans,

Your code looks good.

By creating the STL list of SmartPointer to images
before the for() loop, you should be safely assuring
the survival of the images.

The destruction of the gradient filters will only
decrement the reference count of the output images.


Luis


----------------------------

Hans J. Johnson wrote:
> Filter and Pipeline experts:
> 
> I am trying to create a list of gradient images from a list of images. 
> Does the following code produce a list of SmartPointers to gradient
> images that persist outside the for loop, or are all the SmartPointers
> invalid outside the for loop?
>  
> 
> std::list<GradImageType::Pointer > ImageCache;
> ...read in images...
> 
> std::list<GradImageType::Pointer > GradientsCache;
> for (std::list<itk::Image<unsigned char,3>::Pointer >::const_iterator it
> = ImageCache.begin();
> it != ImageCache.end();   it++)
> {
>         typedef itk::GradientImageFilter<itk::Image<unsigned char,3> >
> myGradType;
>         myGradType::Pointer myGrad=myGradType::New();
>         myGrad->SetInput(*it);
>         GradientsCache.push_back(myGrad->GetOutput());
> }
> 
> Thanks,
> Hans
> 
>