X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPlugins%2FIO%2FImageReader.cxx;h=a7c6687c199b1cbc9c80f8695f4843e3971f1f41;hb=d6f15d4cb764982e2b09060a9c0f38636891590c;hp=64bec97ee509f757048622affe663c5896f4d9f4;hpb=f2f39f66027a98bd8dac50bade5618e0136bbefa;p=cpPlugins.git diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index 64bec97..a7c6687 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,29 +9,39 @@ #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -bool cpPlugins::IO::ImageReader:: +cpPlugins::IO::ImageReader:: +DialogResult cpPlugins::IO::ImageReader:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 + QStringList filters; + filters + << "Image files (*.bmp *.png *.jpg *.jpeg *.dcm *.mhd *.nhdr *.nrrd *.tiff)" + << "Any files (*)"; + + std::vector< std::string > names; + this->m_Parameters->GetStringList( names, "FileNames" ); + std::string name = ( names.size( ) > 0 )? names[ 0 ]: "."; + // Show dialog and check if it was accepted QFileDialog dialog( parent ); dialog.setFileMode( QFileDialog::ExistingFiles ); - dialog.setDirectory( QFileDialog::tr( "." ) ); - dialog.setNameFilter( QFileDialog::tr( "All files (*)" ) ); + dialog.setDirectory( QFileDialog::tr( name.c_str( ) ) ); + dialog.setNameFilters( filters ); + dialog.setAcceptMode( QFileDialog::AcceptOpen ); if( dialog.exec( ) ) { - this->m_Parameters = this->m_DefaultParameters; QStringList names = dialog.selectedFiles( ); QStringList::const_iterator qIt = names.begin( ); for( ; qIt != names.end( ); ++qIt ) - this->m_Parameters.AddValueToStringList( + this->m_Parameters->AddToStringList( "FileNames", qIt->toStdString( ) ); - this->m_Parameters.SetValueAsBool( "VectorType", false ); - r = true; + this->m_Parameters->SetBool( "VectorType", false ); + r = Self::DialogResult_NoModal; } // fi @@ -47,14 +55,10 @@ cpPlugins::IO::ImageReader:: ImageReader( ) : Superclass( ) { - this->SetNumberOfOutputs( 1 ); - this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); + this->_MakeOutput< 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->ConfigureAsStringList( "FileNames" ); + this->m_Parameters->ConfigureAsBool( "VectorType", false ); } // ------------------------------------------------------------------------- @@ -69,7 +73,7 @@ _GenerateData( ) { // Get filenames TStringList names; - this->m_Parameters.GetValueAsStringList( names, "FileNames" ); + this->m_Parameters->GetStringList( names, "FileNames" ); std::string r = ""; if( names.size( ) >= 1 ) @@ -344,7 +348,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 ) ); @@ -356,7 +360,7 @@ std::string cpPlugins::IO::ImageReader:: _RealGD( const TStringList& names ) { cpPlugins::Interface::Image* out = - this->GetOutput< cpPlugins::Interface::Image >( 0 ); + this->GetOutput< cpPlugins::Interface::Image >( "Output" ); if( out == NULL ) return( "ImageReader: No output object properly created." ); @@ -371,35 +375,34 @@ _RealGD( const TStringList& names ) { reader->Update( ); out->SetITK< I >( reader->GetOutput( ) ); + out->SetName( names[ 0 ] ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); out->SetITK< I >( NULL ); + out->SetName( "" ); } // 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 = this->_CreateITK< _MR >( ); - std::set< std::string >::const_iterator fnIt = ordered_names.begin( ); - for( ; fnIt != ordered_names.end( ); ++fnIt ) - reader->AddFileName( *fnIt ); + for( unsigned int i = 0; i < names.size( ); ++i ) + reader->AddFileName( names[ i ] ); try { reader->Update( ); out->SetITK< I >( reader->GetOutput( ) ); + out->SetName( names[ 0 ] ); } catch( itk::ExceptionObject& err ) { r = "ImageReader: " + std::string( err.GetDescription( ) ); out->SetITK< I >( NULL ); + out->SetName( "" ); } // yrt }