X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FIO%2FImageReader.cxx;h=900940bfcaf97c7a9d0e22149e1a56065d55b700;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=38739df3807d90b273cea6bad1a9a79b76f7211b;hpb=b23970017af98ef6617ddf40f225d4d15fa65854;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index 38739df..900940b 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -1,8 +1,6 @@ #include "ImageReader.h" #include -#include - #include #include @@ -11,17 +9,15 @@ cpPlugins::IO::ImageReader:: ImageReader( ) : Superclass( ) { - this->m_ClassName = "cpPlugins::IO::ImageReader"; - this->m_ClassCategory = "ImageReader"; - - this->SetNumberOfOutputs( 1 ); - this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); + this->_AddOutput< cpPlugins::Interface::Image >( "Output" ); - using namespace cpPlugins::Interface; - this->m_DefaultParameters.Configure( Parameters::StringList, "FileNames" ); - this->m_DefaultParameters.Configure( Parameters::Bool, "VectorType" ); - this->m_DefaultParameters.SetValueAsBool( "VectorType", false ); - this->m_Parameters = this->m_DefaultParameters; + this->m_Parameters->ConfigureAsOpenFileNameList( "FileNames" ); + this->m_Parameters->ConfigureAsBool( "VectorType" ); + this->m_Parameters->SetBool( "VectorType", false ); + this->m_Parameters->SetAcceptedFileExtensions( + "FileNames", + "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff)" + ); } // ------------------------------------------------------------------------- @@ -35,8 +31,7 @@ std::string cpPlugins::IO::ImageReader:: _GenerateData( ) { // Get filenames - TStringList names; - this->m_Parameters.GetValueAsStringList( names, "FileNames" ); + TStringList names = this->m_Parameters->GetOpenFileNameList( "FileNames" ); std::string r = ""; if( names.size( ) >= 1 ) @@ -69,7 +64,7 @@ _GenerateData( ) r = "ImageReader: Could not CreateImageIO for \"" + names[ 0 ] + "\""; } else - r = "No image files given"; + r = "ImageReader: No image files given"; return( r ); } @@ -311,7 +306,7 @@ template< class P, unsigned int D > std::string cpPlugins::IO::ImageReader:: _GD1( const TStringList& names ) { - if( this->m_Parameters.GetValueAsBool( "VectorType" ) ) + if( this->m_Parameters->GetBool( "VectorType" ) ) return( this->_RealGD< itk::VectorImage< P, D > >( names ) ); else return( this->_RealGD< itk::Image< P, D > >( names ) ); @@ -322,69 +317,42 @@ template< class I > std::string cpPlugins::IO::ImageReader:: _RealGD( const TStringList& names ) { - cpPlugins::Interface::Image* out = - this->GetOutput< cpPlugins::Interface::Image >( 0 ); - if( out == NULL ) - return( "ImageReader: No output object properly created." ); - + auto out = this->GetOutputData< cpPlugins::Interface::Image >( "Output" ); std::string r = ""; if( names.size( ) == 1 ) { // Read single image typedef itk::ImageFileReader< I > _SR; - _SR* reader = - dynamic_cast< _SR* >( this->m_RealProcessObject.GetPointer( ) ); - if( reader == NULL ) - { - this->m_RealProcessObject = _SR::New( ); - reader = - dynamic_cast< _SR* >( this->m_RealProcessObject.GetPointer( ) ); - - } // fi + _SR* reader = this->_CreateITK< _SR >( ); reader->SetFileName( names[ 0 ] ); try { reader->Update( ); - out->SetITKImage< I >( reader->GetOutput( ) ); + out->SetITK( reader->GetOutput( ) ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); - out->SetITKImage< I >( NULL ); + out->SetITK( NULL ); } // yrt } else if( names.size( ) > 1 ) { // Read image series - std::set< std::string > ordered_names; - for( unsigned int i = 0; i < names.size( ); ++i ) - ordered_names.insert( names[ i ] ); - typedef itk::ImageSeriesReader< I > _MR; - _MR* reader = - dynamic_cast< _MR* >( this->m_RealProcessObject.GetPointer( ) ); - if( reader == NULL ) - { - this->m_RealProcessObject = _MR::New( ); - reader = - dynamic_cast< _MR* >( this->m_RealProcessObject.GetPointer( ) ); - - } // fi - std::set< std::string >::const_iterator fnIt = ordered_names.begin( ); - for( ; fnIt != ordered_names.end( ); ++fnIt ) - { - reader->AddFileName( *fnIt ); - } + _MR* reader = this->_CreateITK< _MR >( ); + for( unsigned int i = 0; i < names.size( ); ++i ) + reader->AddFileName( names[ i ] ); try { reader->Update( ); - out->SetITKImage< I >( reader->GetOutput( ) ); + out->SetITK( reader->GetOutput( ) ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); - out->SetITKImage< I >( NULL ); + out->SetITK( NULL ); } // yrt }