[Insight-users] returning a smart pointer from a function
Dan Mueller
dan.muel at gmail.com
Sun Feb 6 11:33:35 EST 2011
Hi Ricardo,
I would also add a call to reader->GetOutput()->DisconnectPipeline()
(after the reader->Update() call) to make sure the image is
disconnected from the pipeline... Other than that, this function seem
fine.
HTH
Cheers, Dan
On 6 February 2011 17:27, Ricardo Ferrari <rjf.araraquara at gmail.com> wrote:
> Hi guys,
>
> I am just wondering if is there any disadvantage in using the following
> function to encapsulate the image file reading.
>
> Thank you,
> Ricardo
>
>
> ///
> ************************************************************************************************************
> ///
> ///
> ************************************************************************************************************
> template< typename TImageType >
> typename TImageType::Pointer ReadImage( const std::string fileName )
> {
> typedef itk::ImageFileReader< TImageType > ImageFileReader;
> typename ImageFileReader::Pointer reader = ImageFileReader::New();
> reader->SetFileName( fileName );
>
> try
> {
> reader->Update();
> }
> catch (... )
> {
> std::cout << "Error while reading in image" << fileName <<
> std::endl;
> throw;
> }
>
> return reader->GetOutput();
> }
>
>
> The function is used as follows:
>
> InputImageType::Pointer img = ReadImage< InputImageType >( inputFileName );
More information about the Insight-users
mailing list