1 #include "DicomSeriesReader.h"
3 #ifdef cpPlugins_Interface_QT4
8 #include <QDialogButtonBox>
10 #include <QFileDialog>
11 #include <QGridLayout>
13 #include <QTreeWidget>
14 #include <QVBoxLayout>
16 #endif // cpPlugins_Interface_QT4
18 #include <itkGDCMSeriesFileNames.h>
20 // -------------------------------------------------------------------------
21 bool cpPlugins::IO::DicomSeriesReader::
22 ExecConfigurationDialog( QWidget* parent )
26 #ifdef cpPlugins_Interface_QT4
28 // DICOM series analyzer
29 itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( );
30 itk::GDCMSeriesFileNames::Pointer series =
31 itk::GDCMSeriesFileNames::New( );
33 typedef std::map< std::string, TStringList > _TSeries;
34 typedef std::map< std::string, _TSeries > _TFilenames;
35 _TSeries found_series;
36 _TFilenames found_filenames;
38 // Show dialog and check if it was accepted
39 QFileDialog dialog( parent );
40 dialog.setFileMode( QFileDialog::DirectoryOnly );
41 dialog.setDirectory( QFileDialog::tr( "." ) );
44 std::string dir_name = dialog.selectedFiles( ).begin( )->toStdString( );
45 std::queue< std::string > q;
47 while( !( q.empty( ) ) )
49 dir_name = q.front( );
52 // Get DICOM information
53 series->SetUseSeriesDetails( true );
54 series->AddSeriesRestriction( "0008|0021" );
55 series->SetDirectory( dir_name );
56 const TStringList& seriesUID = series->GetSeriesUIDs( );
57 if( seriesUID.size( ) > 0 )
59 TStringList::const_iterator sIt = seriesUID.begin( );
60 for( ; sIt != seriesUID.end( ); ++sIt )
62 TStringList filenames = series->GetFileNames( *sIt );
63 if( filenames.size( ) > 0 )
65 found_series[ dir_name ].push_back( *sIt );
66 found_filenames[ dir_name ][ *sIt ] = filenames;
75 QDir dir( dir_name.c_str( ) );
76 QFileInfoList contents = dir.entryInfoList( );
77 QFileInfoList::const_iterator i = contents.begin( );
78 for( ; i != contents.end( ); ++i )
82 std::string new_dir_name = i->absoluteFilePath( ).toStdString( );
83 if( new_dir_name.size( ) > dir_name.size( ) )
84 q.push( new_dir_name );
95 if( found_series.size( ) > 0 )
97 QDialog* tree_dialog = new QDialog( parent );
99 QLabel* title = new QLabel( tree_dialog );
100 title->setText( "Choose a DICOM series" );
101 QGridLayout* mainLayout = new QGridLayout( tree_dialog );
102 QVBoxLayout* toolsLayout = new QVBoxLayout( );
103 toolsLayout->addWidget( title );
104 mainLayout->addLayout( toolsLayout, 0, 0, 1, 1 );
106 QTreeWidget* tree = new QTreeWidget( tree_dialog );
107 QList< QTreeWidgetItem* > tree_items;
109 _TSeries::const_iterator fsIt = found_series.begin( );
110 for( ; fsIt != found_series.end( ); ++fsIt )
112 QTreeWidgetItem* new_item =
114 ( QTreeWidgetItem* )( NULL ), QStringList( fsIt->first.c_str( ) )
116 TStringList::const_iterator sId = fsIt->second.begin( );
117 for( ; sId != fsIt->second.end( ); ++sId )
119 QTreeWidgetItem* new_leaf =
120 new QTreeWidgetItem( new_item, QStringList( sId->c_str( ) ) );
121 new_item->addChild( new_leaf );
124 tree_items.append( new_item );
127 tree->insertTopLevelItems( 0, tree_items );
128 toolsLayout->addWidget( tree );
130 QDialogButtonBox* bb = new QDialogButtonBox(
131 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
133 tree_dialog->connect( bb, SIGNAL( accepted( ) ), tree_dialog, SLOT( accept( ) ) );
134 tree_dialog->connect( bb, SIGNAL( rejected( ) ), tree_dialog, SLOT( reject( ) ) );
135 toolsLayout->addWidget( bb );
137 if( tree_dialog->exec( ) == 1 )
139 QTreeWidgetItem* item = tree->currentItem( );
140 QTreeWidgetItem* parent = item->parent( );
143 std::string serie_dir = parent->text( 0 ).toStdString( );
144 std::string serie_id = item->text( 0 ).toStdString( );
146 this->m_Parameters->ClearStringList( "FileNames" );
147 const TStringList& filenames = found_filenames[ serie_dir ][ serie_id ];
148 for( unsigned int f = 0; f < filenames.size( ); ++f )
149 this->m_Parameters->AddToStringList( "FileNames", filenames[ f ] );
159 itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( );
161 #endif // cpPlugins_Interface_QT4
166 // -------------------------------------------------------------------------
167 cpPlugins::IO::DicomSeriesReader::
173 // -------------------------------------------------------------------------
174 cpPlugins::IO::DicomSeriesReader::
175 ~DicomSeriesReader( )