X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FQT%2FDicomSeriesSelectorWidget.cxx;h=2cfbbc17b77c7ab1d967570c1eb34b7eb8de4a61;hb=c47085fea4e329aac217e38d402876d78c52ed5d;hp=bb81a84c69aa66e85d9715f2e17670262fa0edd3;hpb=03d87a8f1acbcd697ca7a18a124fe3b659f7b045;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 ); } // -------------------------------------------------------------------------