[Insight-users] Releasing a FileReader releases the PixelContainer of already-read images?

Karthik Krishnan Karthik.Krishnan at kitware.com
Mon Jan 16 13:49:58 EST 2006



Gaetan Lehmann wrote:

>>> >>> reader=itk.ImageFileReader[itk.Image[itk.US,2]].New
>>>
>>>(FileName=infile)
>>>
>>> >>> reader.Update()
>>> >>> image=reader.GetOutput()
>>> >>> image.GetPixelContainer() != None #test for null pixel container
>>>
>>>True
>>>
>>> >>> del(reader)
>>> >>> image.GetPixelContainer() != None
>>>
>>>False
>>>
>>>Thus we can see that when I deallocate the reader, something happens
>>>to deallocate the pixel container.
>>>      
>>>
>>Replace
>>  image = reader.GetOutput()
>>with
>>  image = itkImageUS2_Pointer(reader.GetOutput())
>>
>>If image was a smart pointer, this wouldn't happen cause the reference
>>count will prevent it from disappearing when reader is deleted.
>>
>>    
>>
>Ok, but this is not what a python user expect :-(
>With a typemap, it should be possible to return a smart pointer instead of a 
>pointer, and to pass a pointer instead of the smart pointer when it's needed 
>(in SetInput() method for example).
>
>Would there be any problem if I do that ?
>
>  
>
Sounds ok to me to use a typemap to do this for all objects. But this 
might make the Python syntax deviate from the C++ syntax. Is that good ? 
Its just like in C++ you would say.

foo::Pointer  f = ...    ===== f =  foo_Pointer( ... )

instead of

foo * f = ...                 =====  f =...

>Gaetan
>  
>


More information about the Insight-users mailing list