#include <queue>
#include <string>
#include <QFileDialog>
-#include <itkGDCMSeriesFileNames.h>
// -------------------------------------------------------------------------
cpExtensions::QT::DicomSeriesSelectorWidget::
void cpExtensions::QT::DicomSeriesSelectorWidget::
setStartDir( const QString& dir, bool build )
{
+ this->m_Series.clear( );
+
this->m_UI->Directory->setText( dir );
if( !build )
return;
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 );
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( ) )
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 );
}
// -------------------------------------------------------------------------
-#ifndef __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__
-#define __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__
+#ifndef __cpExtensions__QT__DicomSeriesSelectorWidget__H__
+#define __cpExtensions__QT__DicomSeriesSelectorWidget__H__
#include <cpExtensions/Config.h>
#ifdef cpExtensions_QT4
#include <QWidget>
+#include <gdcmSerieHelper.h>
// -------------------------------------------------------------------------
namespace Ui
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( );
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
#endif // cpExtensions_QT4
-#endif // __CPEXTENSIONS__QT__DICOMSERIESSELECTORWIDGET__H__
+#endif // __cpExtensions__QT__DicomSeriesSelectorWidget__H__
// eof - $RCSfile$