[Insight-developers] Confused about persistance of filter out puts

Miller, James V (Research) millerjv@crd.ge.com
Mon, 28 Apr 2003 09:15:12 -0400


One additional note.  The gradient filters in your for loop will be 
destructed at the end of the loop (actually they are probably destructed 
at the end of the iteration).  The output of a filter does 
not hold a SmartPointer to the "source" filter creating it. This is
to avoid a cyclic smart pointer reference (which cause objects to 
never be deleted.  You might want to add an Update() call to your loop


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);
	  myGrad->Update();      // ADD THIS LINE:   Execute the gradient
calculation
        GradientsCache.push_back(myGrad->GetOutput());
}


> -----Original Message-----
> From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
> Sent: Saturday, April 26, 2003 6:22 PM
> To: Hans J. Johnson
> Cc: insight-developers@public.kitware.com
> Subject: Re: [Insight-developers] Confused about persistance of filter
> outputs
> 
> 
> 
> 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
> > 
> > 
> 
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>