[Insight-users] `Image Memory Management

David Holmes holmesd3@yahoo.com
Tue, 10 Dec 2002 15:05:39 -0800 (PST)


Luis-

thank you for your quick response.  I was actually
looking into the ImportImageContainer when I received
your note.  I implemented your suggestions, but I
think that I still have a problem.  Now the data is
limited to the scope of the ImportImageContainer
Pointer.  Because I am simply grabbing the container
out of the Image, the flag that controls memory
management has already been set to TRUE (presumably by
the filter object), so the data will still be
destroyed outside the scope of the
ImportImageContainer Pointer.  As such, when I try and
access the array (by way of the pointer to the data
outside the function), it core dumps.  I've tried to
find a way to reset that flag, but haven't found it
yet.

does this make sense?

I don't know, but if you can help me, I'd appreciate
it.

Thanks

david



--- Luis Ibanez <luis.ibanez@kitware.com> wrote:
> 
> Hi David,
> 
> The pixel data in an image is stored in an object
> of class
> 
>     ImportImageContainer.
> 
>
http://www.itk.org/Doxygen/html/classitk_1_1ImportImageContainer.html
> 
> This seems to be the object you want.
> 
> The ImportImageContainer derives from itk::Object
> and defines an interface to a C-like array of
> pixels.
> 
> If you get the pointer to the ImportImageContainer
> from
> an image and assign this pointer to a SmartPointer
> this
> will prevent the memory from being released and
> destroyed
> when the image is destroyed.
> 
> As you are taking this from the pipeline,
> you may want to do something like:
> 
> // define the smart pointer to the container
> // outside of the scope of the pipeline.
> 
> ImageType::PixelContainerPointer pixelContainer;
> 
> { // start filter/pipeline scope
> 
>     FilterType::Pointer filter = FilterType::New();
>     ....
>     filter->Update();
>     pixelContainer =
> filter->GetOutput()->GetPixelContainer();
> 
> } // end of filter scope, the filter will be
> destroyed here
> 
> 
> 
> // here the pixelContainer SmartPointer will still
> // hold the memory containing pixel data.
> // data can be used here:
> 
> ImageType::PixelType * pixels =
> pixelContainer->GetImportPointer();
> 
> 
> 
> Please let us know if you have further questions,
> 
> 
>    Thanks
> 
> 
>     Luis
> 
> 
> ====================
> 
> David Holmes wrote:
> 
> > I thought that I'd add one more thing.  I would
> > actually prefer to keep this seperate from the
> filters
> > in the fact that I'd much prefer to set a flag for
> the
> > ITK Image which is similar to that of the Image
> > container that says that the image object does not
> > need to manage the memory and so therefore it can
> > exist beyond the scope of the image.
> > 
> > I couldn't find an appropriate method to do so. 
> Any
> > help would be appreciated.
> > 
> > Thanks
> > 
> > david
> > 
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
>
http://public.kitware.com/mailman/listinfo/insight-users


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com