X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=plugins%2FIO%2FImageReader.cxx;h=ffd3e8b807642fe871d3f14a32831eea14737a79;hb=560b80db4e0253bef4a1b7ff3afb63fd04591551;hp=a54a5409601fae920ee66e4b419aed07f8e8efc1;hpb=db0a767418f78b371c1e4fb0db00e6b75df74ff3;p=cpPlugins.git diff --git a/plugins/IO/ImageReader.cxx b/plugins/IO/ImageReader.cxx index a54a540..ffd3e8b 100644 --- a/plugins/IO/ImageReader.cxx +++ b/plugins/IO/ImageReader.cxx @@ -1,75 +1,13 @@ #include -#include #include +#include #include #include #include #ifdef cpPlugins_QT4 - -#include -#include - -// ------------------------------------------------------------------------- -cpPluginsIO::ImageReaderQDialog:: -ImageReaderQDialog( QWidget* parent ) - : QFileDialog( parent ), - m_ProcessObject( NULL ) -{ - this->connect( - this, SIGNAL( accepted( ) ), this, SLOT( _dlg_Accepted( ) ) - ); - this->setWindowTitle( "Open an(some) image(s)" ); -} - -// ------------------------------------------------------------------------- -cpPluginsIO::ImageReaderQDialog:: -~ImageReaderQDialog( ) -{ -} - -// ------------------------------------------------------------------------- -void cpPluginsIO::ImageReaderQDialog:: -setProcessObject( cpPlugins::BaseObjects::ProcessObject* obj ) -{ - if( obj == NULL ) - return; - this->m_ProcessObject = obj; - auto param = this->m_ProcessObject->GetParameters( ); - auto extensions = param->GetAcceptedFileExtensions( "FileNames" ); - auto files = param->GetOpenFileNameList( "FileNames" ); - - QStringList filters; - if( extensions != "" ) - filters << extensions.c_str( ); - filters << "Any file (*)"; - this->setFileMode( QFileDialog::ExistingFiles ); - this->setNameFilters( filters ); - this->setAcceptMode( QFileDialog::AcceptOpen ); - if( files.size( ) > 0 ) - { - QFileInfo info( files[ 0 ].c_str( ) ); - this->setDirectory( info.canonicalPath( ) ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpPluginsIO::ImageReaderQDialog:: -_dlg_Accepted( ) -{ - if( this->m_ProcessObject != NULL ) - { - auto param = this->m_ProcessObject->GetParameters( ); - auto files = this->selectedFiles( ); - param->ClearOpenFileNameList( "FileNames" ); - for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt ) - param->AddToOpenFileNameList( "FileNames", fIt->toStdString( ) ); - - } // fi -} - +# include #endif // cpPlugins_QT4 // ------------------------------------------------------------------------- @@ -77,11 +15,11 @@ QDialog* cpPluginsIO::ImageReader:: CreateQDialog( ) { #ifdef cpPlugins_QT4 - ImageReaderQDialog* dlg = NULL; + cpPlugins::QT::OpenFileDialog* dlg = NULL; if( QApplication::instance( ) != NULL ) { - dlg = new ImageReaderQDialog( ); - dlg->setProcessObject( this ); + dlg = new cpPlugins::QT::OpenFileDialog( ); + dlg->SetParameters( &( this->m_Parameters ), "FileNames" ); } // fi return( dlg ); @@ -116,38 +54,37 @@ _GenerateData( ) { // Get filenames auto fnames = this->m_Parameters.GetOpenFileNameList( "FileNames" ); - if( fnames.size( ) >= 1 ) + if( fnames.size( ) > 1 ) { + std::stringstream fname_str; + fname_str << fnames[ 0 ] << cpPlugins_PATH_SEPARATOR << fnames[ 1 ]; + std::string fname = fname_str.str( ); + // Guess image properties itk::ImageIOBase::Pointer io = itk::ImageIOFactory::CreateImageIO( - fnames[ 0 ].c_str( ), - itk::ImageIOFactory::ReadMode + fname.c_str( ), itk::ImageIOFactory::ReadMode ); if( io.IsNotNull( ) ) { - io->SetFileName( fnames[ 0 ] ); + io->SetFileName( fname ); io->ReadImageInformation( ); - if( fnames.size( ) >= 1 ) - { - bool success = false; - unsigned int dim = io->GetNumberOfDimensions( ); + bool success = false; + unsigned int dim = io->GetNumberOfDimensions( ); #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 - if( dim == 1 ) success = this->_GD0< 1 >( io ); + if( dim == 1 ) success = this->_GD0< 1 >( io ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 - if( dim == 2 ) success = this->_GD0< 2 >( io ); + if( dim == 2 ) success = this->_GD0< 2 >( io ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 - if( dim == 3 ) success = this->_GD0< 3 >( io ); + if( dim == 3 ) success = this->_GD0< 3 >( io ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3 #ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 - if( dim == 4 ) success = this->_GD0< 4 >( io ); + if( dim == 4 ) success = this->_GD0< 4 >( io ); #endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4 - if( !success ) - this->_Error( "Image dimension not supported." ); - - } // fi + if( !success ) + this->_Error( "Image dimension not supported." ); } else this->_Error( @@ -192,12 +129,12 @@ _GD0( itk::ImageIOBase* io ) if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< long, _Dim >( io ); if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< ulong, _Dim >( io ); #endif // cpPlugins_CONFIG_INTEGER_TYPES_long -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< float, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< double, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::RGB ) { @@ -218,12 +155,12 @@ _GD0( itk::ImageIOBase* io ) if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< itk::RGBPixel< long >, _Dim >( io ); if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< itk::RGBPixel< ulong >, _Dim >( io ); # endif // cpPlugins_CONFIG_INTEGER_TYPES_long -# ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +# ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::RGBPixel< float >, _Dim >( io ); -# endif // cpPlugins_CONFIG_INTEGER_TYPES_float -# ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +# endif // cpPlugins_CONFIG_REAL_TYPES_float +# ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< itk::RGBPixel< double >, _Dim >( io ); -# endif // cpPlugins_CONFIG_INTEGER_TYPES_double +# endif // cpPlugins_CONFIG_REAL_TYPES_double #endif // cpPlugins_CONFIG_COLOR_PIXELS_RGBPixel } else if( pt == itk::ImageIOBase::RGBA ) @@ -245,81 +182,81 @@ _GD0( itk::ImageIOBase* io ) if( ct == itk::ImageIOBase::LONG ) success = this->_GD1< itk::RGBAPixel< long >, _Dim >( io ); if( ct == itk::ImageIOBase::ULONG ) success = this->_GD1< itk::RGBAPixel< ulong >, _Dim >( io ); # endif // cpPlugins_CONFIG_INTEGER_TYPES_long -# ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +# ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::RGBAPixel< float >, _Dim >( io ); -# endif // cpPlugins_CONFIG_INTEGER_TYPES_float -# ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +# endif // cpPlugins_CONFIG_REAL_TYPES_float +# ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< itk::RGBAPixel< double >, _Dim >( io ); -# endif // cpPlugins_CONFIG_INTEGER_TYPES_double +# endif // cpPlugins_CONFIG_REAL_TYPES_double #endif // cpPlugins_CONFIG_COLOR_PIXELS_RGBAPixel } else if( pt == itk::ImageIOBase::COMPLEX ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< std::complex< float >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::DOUBLE ) success = this->_GD1< std::complex< double >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::COVARIANTVECTOR ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::CovariantVector< float, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::CovariantVector< double, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::POINT ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Point< float, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Point< double, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::VECTOR ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Vector< float, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Vector< double, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::SYMMETRICSECONDRANKTENSOR ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::SymmetricSecondRankTensor< float, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::SymmetricSecondRankTensor< double, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::DIFFUSIONTENSOR3D ) { if( _Dim == 3 ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::DiffusionTensor3D< float >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::DiffusionTensor3D< double >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else this->_Error( "DiffusionTensor3D dimension not supported." ); } else if( pt == itk::ImageIOBase::MATRIX ) { -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_float if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Matrix< float, _Dim, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_float -#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double if( ct == itk::ImageIOBase::FLOAT ) success = this->_GD1< itk::Matrix< double, _Dim, _Dim >, _Dim >( io ); -#endif // cpPlugins_CONFIG_INTEGER_TYPES_double +#endif // cpPlugins_CONFIG_REAL_TYPES_double } else if( pt == itk::ImageIOBase::OFFSET ) { @@ -340,10 +277,13 @@ _GD1( itk::ImageIOBase* io ) // Get filenames auto fnames = this->m_Parameters.GetOpenFileNameList( "FileNames" ); - if( fnames.size( ) == 1 ) + if( fnames.size( ) == 2 ) { + std::stringstream fname_str; + fname_str << fnames[ 0 ] << cpPlugins_PATH_SEPARATOR << fnames[ 1 ]; + auto f = this->_CreateITK< itk::ImageFileReader< _TImage > >( ); - f->SetFileName( fnames[ 0 ] ); + f->SetFileName( fname_str.str( ) ); f->SetImageIO( io ); try { @@ -361,8 +301,12 @@ _GD1( itk::ImageIOBase* io ) else // if( fnames.size( ) > 1 ) { auto f = this->_CreateITK< itk::ImageSeriesReader< _TImage > >( ); - for( auto i = fnames.begin( ); i != fnames.end( ); ++i ) - f->AddFileName( *i ); + auto i = fnames.begin( ); + std::stringstream dir; + dir << *i << cpPlugins_PATH_SEPARATOR; + i++; + for( ; i != fnames.end( ); ++i ) + f->AddFileName( dir.str( ) + *i ); f->SetImageIO( io ); try {