From: Leonardo Flórez-Valencia Date: Fri, 11 Nov 2016 14:25:57 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~49 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c47085fea4e329aac217e38d402876d78c52ed5d;p=cpPlugins.git ... --- diff --git a/lib/cpExtensions/QT/DicomSeriesSelectorWidget.cxx b/lib/cpExtensions/QT/DicomSeriesSelectorWidget.cxx index bb81a84..2cfbbc1 100644 --- a/lib/cpExtensions/QT/DicomSeriesSelectorWidget.cxx +++ b/lib/cpExtensions/QT/DicomSeriesSelectorWidget.cxx @@ -6,7 +6,6 @@ #include #include #include -#include // ------------------------------------------------------------------------- cpExtensions::QT::DicomSeriesSelectorWidget:: @@ -40,6 +39,8 @@ startDir( ) const void cpExtensions::QT::DicomSeriesSelectorWidget:: setStartDir( const QString& dir, bool build ) { + this->m_Series.clear( ); + this->m_UI->Directory->setText( dir ); if( !build ) return; @@ -53,7 +54,6 @@ setStartDir( const QString& dir, bool build ) labels << "Images count" << "Series UID" << "Series path"; this->m_UI->Series->setHorizontalHeaderLabels( labels ); - itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( ); std::string main_dir_name = dir.toStdString( ); std::queue< std::string > q; q.push( main_dir_name ); @@ -62,38 +62,11 @@ setStartDir( const QString& dir, bool build ) std::string dir_name = q.front( ); q.pop( ); - // Get series - itk::GDCMSeriesFileNames::Pointer series = - itk::GDCMSeriesFileNames::New( ); - series->SetUseSeriesDetails( true ); - series->AddSeriesRestriction( "0008|0021" ); - series->SetDirectory( dir_name ); - const std::vector< std::string >& seriesUID = series->GetSeriesUIDs( ); - for( auto sIt = seriesUID.begin( ); sIt != seriesUID.end( ); ++sIt ) - { - unsigned long rows = this->m_UI->Series->rowCount( ); - this->m_UI->Series->insertRow( rows ); - std::stringstream str_count; - str_count << series->GetFileNames( *sIt ).size( ); - QTableWidgetItem* count_item = - new QTableWidgetItem( str_count.str( ).c_str( ) ); - QTableWidgetItem* uid_item = - new QTableWidgetItem( sIt->c_str( ) ); - QTableWidgetItem* dir_item = - new QTableWidgetItem( dir_name.substr( dir.size( ) + 1 ).c_str( ) ); - count_item->setFlags( count_item->flags( ) & ~Qt::ItemIsEditable ); - uid_item->setFlags( uid_item->flags( ) & ~Qt::ItemIsEditable ); - dir_item->setFlags( dir_item->flags( ) & ~Qt::ItemIsEditable ); - this->m_UI->Series->setItem( rows, 0, count_item ); - this->m_UI->Series->setItem( rows, 1, uid_item ); - this->m_UI->Series->setItem( rows, 2, dir_item ); - - } // rof - // Update queue QDir dir( dir_name.c_str( ) ); QFileInfoList contents = dir.entryInfoList( ); QFileInfoList::const_iterator i = contents.begin( ); + std::set< std::string > files; for( ; i != contents.end( ); ++i ) { if( i->isDir( ) ) @@ -101,46 +74,93 @@ setStartDir( const QString& dir, bool build ) std::string new_dir_name = i->absoluteFilePath( ).toStdString( ); if( new_dir_name.size( ) > dir_name.size( ) ) q.push( new_dir_name ); - - } // fi + } + else + files.insert( i->absoluteFilePath( ).toStdString( ) ); } // rof + if( files.size( ) > 0 ) + { + this->m_GDCMHelper.Clear( ); + this->m_GDCMHelper.SetUseSeriesDetails( true ); + this->m_GDCMHelper.SetLoadMode( 0 ); + this->m_GDCMHelper.AddRestriction( "0008|0021" ); + this->m_GDCMHelper.SetFileNames( files.begin( ), files.end( ) ); + + gdcm::FileList* flist = + this->m_GDCMHelper.GetFirstSingleSerieUIDFileSet( ); + while( flist != NULL ) + { + if( flist->size( ) > 0 ) + { + this->m_GDCMHelper.OrderFileList( flist ); + gdcm::File* file = ( *flist )[ 0 ]; + std::string id = + this->m_GDCMHelper.CreateUniqueSeriesIdentifier( file ).c_str( ); + + gdcm::FileList::iterator it; + for( it = flist->begin( ); it != flist->end( ); ++it ) + if( *it != NULL ) + this->m_Series[ id ].push_back( ( *it )->filename ); + + } // fi + flist = this->m_GDCMHelper.GetNextSingleSerieUIDFileSet( ); + + } // elihw + + } // fi + } // elihw + // Show series + for( auto sIt = this->m_Series.begin( ); sIt != this->m_Series.end( ); ++sIt ) + { + if( sIt->second.size( ) > 0 ) + { + QFileInfo fdir( sIt->second[ 0 ].c_str( ) ); + + unsigned long rows = this->m_UI->Series->rowCount( ); + this->m_UI->Series->insertRow( rows ); + std::stringstream str_count; + str_count << sIt->second.size( ); + QTableWidgetItem* count_item = + new QTableWidgetItem( str_count.str( ).c_str( ) ); + QTableWidgetItem* uid_item = + new QTableWidgetItem( sIt->first.c_str( ) ); + QTableWidgetItem* dir_item = + new QTableWidgetItem( fdir.dir( ).canonicalPath( ) ); + count_item->setFlags( count_item->flags( ) & ~Qt::ItemIsEditable ); + uid_item->setFlags( uid_item->flags( ) & ~Qt::ItemIsEditable ); + dir_item->setFlags( dir_item->flags( ) & ~Qt::ItemIsEditable ); + this->m_UI->Series->setItem( rows, 0, count_item ); + this->m_UI->Series->setItem( rows, 1, uid_item ); + this->m_UI->Series->setItem( rows, 2, dir_item ); + + } // fi + + } // rof + // Restore cursor QApplication::restoreOverrideCursor( ); - itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( ); } // ------------------------------------------------------------------------- -std::vector< std::string > cpExtensions::QT::DicomSeriesSelectorWidget:: +std::vector< std::string >* cpExtensions::QT::DicomSeriesSelectorWidget:: selectedFilenames( ) { - std::vector< std::string > filenames; auto items = this->m_UI->Series->selectedItems( ); if( items.size( ) > 0 ) { - std::string dir = + std::string uid = this->m_UI->Series-> - item( items[ 0 ]->row( ), 2 )->text( ).toStdString( ); - dir = this->startDir( ).toStdString( ) + "/" + dir; - itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( ); - - itk::GDCMSeriesFileNames::Pointer series = - itk::GDCMSeriesFileNames::New( ); - series->SetUseSeriesDetails( true ); - series->AddSeriesRestriction( "0008|0021" ); - series->SetDirectory( dir ); - filenames = series->GetFileNames( - this->m_UI->Series->item( - items[ 0 ]->row( ), 1 - )->text( ).toStdString( ) - ); - itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( ); + item( items[ 0 ]->row( ), 1 )->text( ).toStdString( ); + auto sIt = this->m_Series.find( uid ); + if( sIt != this->m_Series.end( ) ) + return( &( sIt->second ) ); } // fi - return( filenames ); + return( NULL ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/DicomSeriesSelectorWidget.h b/lib/cpExtensions/QT/DicomSeriesSelectorWidget.h index b30df8e..172d545 100644 --- a/lib/cpExtensions/QT/DicomSeriesSelectorWidget.h +++ b/lib/cpExtensions/QT/DicomSeriesSelectorWidget.h @@ -1,11 +1,12 @@ -#ifndef __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__ -#define __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__ +#ifndef __cpExtensions__QT__DicomSeriesSelectorWidget__H__ +#define __cpExtensions__QT__DicomSeriesSelectorWidget__H__ #include #ifdef cpExtensions_QT4 #include +#include // ------------------------------------------------------------------------- namespace Ui @@ -28,6 +29,27 @@ namespace cpExtensions public: typedef DicomSeriesSelectorWidget Self; + protected: + /** + */ + class _GDCMSerieHelper + : public gdcm::SerieHelper + { + public: + _GDCMSerieHelper( ) + { + } + virtual ~_GDCMSerieHelper( ) + { + } + template< class _TIt > + void SetFileNames( _TIt b, _TIt e ) + { + for( _TIt i = b; i != e; ++i ) + this->AddFileName( *i ); + } + }; + public: explicit DicomSeriesSelectorWidget( QWidget* parent = 0 ); virtual ~DicomSeriesSelectorWidget( ); @@ -35,13 +57,15 @@ namespace cpExtensions QString startDir( ) const; void setStartDir( const QString& dir, bool build = true ); - std::vector< std::string > selectedFilenames( ); + std::vector< std::string >* selectedFilenames( ); protected slots: void _Choose( ); protected: Ui::DicomSeriesSelectorWidget* m_UI; + _GDCMSerieHelper m_GDCMHelper; + std::map< std::string, std::vector< std::string > > m_Series; }; } // ecapseman @@ -50,6 +74,6 @@ namespace cpExtensions #endif // cpExtensions_QT4 -#endif // __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__ +#endif // __cpExtensions__QT__DicomSeriesSelectorWidget__H__ // eof - $RCSfile$ diff --git a/plugins/IO/DicomSeriesReader.cxx b/plugins/IO/DicomSeriesReader.cxx index a93759d..9fe2dcc 100644 --- a/plugins/IO/DicomSeriesReader.cxx +++ b/plugins/IO/DicomSeriesReader.cxx @@ -54,7 +54,7 @@ _dlg_Accepted( ) auto param = this->m_ProcessObject->GetParameters( ); auto files = this->m_UI->Selector->selectedFilenames( ); param->ClearOpenFileNameList( "FileNames" ); - for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt ) + for( auto fIt = files->begin( ); fIt != files->end( ); ++fIt ) param->AddToOpenFileNameList( "FileNames", *fIt ); } // fi