[Insight-users] How to re-use an itk ImageFileReader?

Luis Ibanez luis.ibanez at kitware.com
Thu Oct 2 16:06:27 EDT 2008


Hi Hua-Mei

Thanks for letting us know that this is working for you now.

The DisconnectPipeline() method is not mentioned in the
ITK Software Guide. There are no examples on how to reuse
a reader.

Calling Delete() in VTK classes is fine.

In ITK you don't need to do it, because the SmartPointers
take care of that for you.



    Regards,


        Luis



-------------------
Hua-Mei Chen wrote:
> Luis,
>   Thank you so much. I knew I should not call Delete( ) in ITK, but I 
> could not think of any other way to do it and did not get any help 
> sooner, so I gave it a try. :)
>   May I know where is the DisconnectPipeline( ) method introduced in the 
> software guide? It is exactly what I need.
>   By the way, why is it o.k. to call Delete( ) in many VTK classes like 
> vtkRenderer, vtkActor, ... Are the design principles different?
> 
> Regards,
> 
> Hua-mei
> 
> 
> 
> ----- Original Message ----- From: "Luis Ibanez" <luis.ibanez at kitware.com>
> To: "Hua-Mei Chen" <huameichen0523 at gmail.com>
> Cc: "ITK Users" <insight-users at itk.org>
> Sent: Wednesday, October 01, 2008 8:46 AM
> Subject: Re: [Insight-users] How to re-use an itk ImageFileReader?
> 
> 
>>
>> Hi Hua-Mei,
>>
>>   You should *never* call "Delete()" in an ITK class   :-)
>>
>> SmartPointers take care of the destruction of objects in ITK.
>>
>> If what you want to do is to reuse the ImageFileReader, you simply
>> need to disconnect the first output image before you read a new one.
>>
>> For example
>>
>>
>>     reader->SetFileName("image1.mhd");
>>     reader->Update();
>>     ImageType::ConstPointer image1 = reader->GetOutput();
>>     image1->DisconnectPipeline();
>>
>>     reader->SetFileName("image2.mhd");
>>     reader->Update();
>>     ImageType::ConstPointer image2 = reader->GetOutput();
>>     image2->DisconnectPipeline();
>>
>>
>> Then you can use "image1" and "image2".
>>
>>
>>   Regards,
>>
>>
>>       Luis
>>
>> ------------------
>> Hua-Mei Chen wrote:
>>
>>> Hi,
>>>
>>>  I used the following code to read image data. However, my program 
>>> had an error message "Access violation reading location 0xfeeefefe." 
>>> the second time m_ImageFileReader->Delete( ) was invoked. Can anyone 
>>> tell what goes wrong in my code? Thank you.
>>>
>>> while (continue){
>>>
>>> if (m_ImageFileReader != (void*) 0) m_ImageFileReader->Delete( );
>>> m_ImageFileReader = ImageFileReaderType::New();
>>> m_ImageFileReader->SetFileName( m_InputFileName);
>>> m_InputImage = m_imageFileReader->GetOutput();
>>> m_ImageFileReader->Update();
>>> ...
>>> ...
>>> }
>>>
>>> Chen
>>>
>>>
>>> ----- Original Message ----- From: "Hua-Mei Chen" 
>>> <huameichen0523 at gmail.com>
>>> To: "ITK Users" <insight-users at itk.org>
>>> Sent: Tuesday, September 30, 2008 10:14 AM
>>> Subject: How to re-use an itk ImageFileReader?
>>>
>>>
>>>> Hi,
>>>>
>>>>   I am trying to re-use an itk ImageFileReader to read the same type 
>>>> of images. However, it crashes the second time the Update( ) method 
>>>> is involked. Do I need to New an itkImageFileReader each time I need 
>>>> one? Is it possible to manually delete an existing 
>>>> itkImageFileReader before I New another one? Please help. Thank you.
>>>>
>>>> Chen
>>>
>>>
>>>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
> 
> 


More information about the Insight-users mailing list