[Insight-users] returning a smart pointer from a function

Ricardo Ferrari rjf.araraquara at gmail.com
Sun Feb 6 11:27:29 EST 2011


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 );
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110206/6bffee87/attachment.htm>


More information about the Insight-users mailing list