1 #include "DicomSeriesReader.h"
3 #ifdef cpPlugins_Interface_QT4
9 #include <QApplication>
10 #include <QDialogButtonBox>
12 #include <QFileDialog>
13 #include <QGridLayout>
15 #include <QTreeWidget>
16 #include <QVBoxLayout>
18 #endif // cpPlugins_Interface_QT4
20 #include <itkGDCMSeriesFileNames.h>
22 // -------------------------------------------------------------------------
23 cpPlugins::IO::DicomSeriesReader::
24 DialogResult cpPlugins::IO::DicomSeriesReader::
25 ExecConfigurationDialog( QWidget* parent )
27 DialogResult r = Self::DialogResult_Cancel;
29 #ifdef cpPlugins_Interface_QT4
31 // DICOM series analyzer
32 itk::GDCMSeriesFileNames::GlobalWarningDisplayOff( );
33 itk::GDCMSeriesFileNames::Pointer series =
34 itk::GDCMSeriesFileNames::New( );
36 // Show dialog and check if it was accepted
37 QFileDialog dialog( parent );
38 dialog.setFileMode( QFileDialog::DirectoryOnly );
39 dialog.setDirectory( QFileDialog::tr( "." ) );
41 return( Self::DialogResult_Cancel );
44 QApplication::setOverrideCursor( Qt::WaitCursor );
46 parent->setEnabled( false );
48 QDialog* tree_dialog = new QDialog( parent );
49 QTreeWidget* tree_widget = new QTreeWidget( tree_dialog );
50 QList< QTreeWidgetItem* > tree_items;
51 std::map< std::string, std::map< std::string, TStringList > > found_files;
53 std::string main_dir_name =
54 dialog.selectedFiles( ).begin( )->toStdString( );
55 std::queue< std::string > q;
56 q.push( main_dir_name );
57 while( !( q.empty( ) ) )
59 std::string dir_name = q.front( );
62 // Get DICOM information
63 series->SetUseSeriesDetails( true );
64 series->AddSeriesRestriction( "0008|0021" );
65 series->SetDirectory( dir_name );
66 const TStringList& seriesUID = series->GetSeriesUIDs( );
67 if( seriesUID.size( ) > 0 )
69 QTreeWidgetItem* new_item = new QTreeWidgetItem(
70 ( QTreeWidgetItem* )( NULL ),
71 QStringList( dir_name.c_str( ) )
73 QTreeWidgetItem* new_leaf = NULL;
74 TStringList::const_iterator sIt = seriesUID.begin( );
75 for( ; sIt != seriesUID.end( ); ++sIt )
77 TStringList filenames = series->GetFileNames( *sIt );
78 if( filenames.size( ) > 0 )
81 ss << "(" << filenames.size( ) << "): " << *sIt;
84 new_item, QStringList( ss.str( ).c_str( ) )
86 new_item->addChild( new_leaf );
87 found_files[ dir_name ][ *sIt ] = filenames;
93 if( new_leaf != NULL )
94 tree_items.append( new_item );
101 QDir dir( dir_name.c_str( ) );
102 QFileInfoList contents = dir.entryInfoList( );
103 QFileInfoList::const_iterator i = contents.begin( );
104 for( ; i != contents.end( ); ++i )
108 std::string new_dir_name = i->absoluteFilePath( ).toStdString( );
109 if( new_dir_name.size( ) > dir_name.size( ) )
110 q.push( new_dir_name );
118 // Show second dialog
119 if( tree_items.size( ) == 0 )
123 return( Self::DialogResult_Cancel );
127 QLabel* title = new QLabel( tree_dialog );
128 title->setText( "Choose a DICOM series" );
129 QGridLayout* mainLayout = new QGridLayout( tree_dialog );
130 QVBoxLayout* toolsLayout = new QVBoxLayout( );
131 toolsLayout->addWidget( title );
132 mainLayout->addLayout( toolsLayout, 0, 0, 1, 1 );
134 tree_widget->insertTopLevelItems( 0, tree_items );
135 toolsLayout->addWidget( tree_widget );
137 QDialogButtonBox* bb = new QDialogButtonBox(
138 QDialogButtonBox::Ok | QDialogButtonBox::Cancel
140 tree_dialog->connect(
141 bb, SIGNAL( accepted( ) ), tree_dialog, SLOT( accept( ) )
143 tree_dialog->connect(
144 bb, SIGNAL( rejected( ) ), tree_dialog, SLOT( reject( ) )
146 toolsLayout->addWidget( bb );
148 QApplication::restoreOverrideCursor( );
150 parent->setEnabled( true );
152 if( tree_dialog->exec( ) == 0 )
153 return( Self::DialogResult_Cancel );
155 QTreeWidgetItem* item = tree_widget->currentItem( );
158 QTreeWidgetItem* item_parent = item->parent( );
159 if( item_parent != NULL )
161 QApplication::setOverrideCursor( Qt::WaitCursor );
163 parent->setEnabled( false );
165 std::string serie_dir = item_parent->text( 0 ).toStdString( );
166 std::string serie_id = item->text( 0 ).toStdString( );
167 serie_id = serie_id.substr( serie_id.find_first_of( " " ) + 1 );
168 this->m_Parameters->ClearStringList( "FileNames" );
169 const TStringList& names = found_files[ serie_dir ][ serie_id ];
170 for( unsigned int f = 0; f < names.size( ); ++f )
171 this->m_Parameters->AddToStringList( "FileNames", names[ f ] );
173 r = Self::DialogResult_NoModal;
175 QApplication::restoreOverrideCursor( );
177 parent->setEnabled( true );
183 itk::GDCMSeriesFileNames::GlobalWarningDisplayOn( );
185 #endif // cpPlugins_Interface_QT4
190 // -------------------------------------------------------------------------
191 cpPlugins::IO::DicomSeriesReader::
197 // -------------------------------------------------------------------------
198 cpPlugins::IO::DicomSeriesReader::
199 ~DicomSeriesReader( )