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

Luis Ibanez luis.ibanez at kitware.com
Wed Oct 1 09:46:52 EDT 2008


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