]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 11 Nov 2016 14:25:57 +0000 (09:25 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Fri, 11 Nov 2016 14:25:57 +0000 (09:25 -0500)
lib/cpExtensions/QT/DicomSeriesSelectorWidget.cxx
lib/cpExtensions/QT/DicomSeriesSelectorWidget.h
plugins/IO/DicomSeriesReader.cxx

index bb81a84c69aa66e85d9715f2e17670262fa0edd3..2cfbbc17b77c7ab1d967570c1eb34b7eb8de4a61 100644 (file)
@@ -6,7 +6,6 @@
 #include <queue>
 #include <string>
 #include <QFileDialog>
-#include <itkGDCMSeriesFileNames.h>
 
 // -------------------------------------------------------------------------
 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 );
 }
 
 // -------------------------------------------------------------------------
index b30df8e2cd83ec54bfd36e56ed13629a52442820..172d545746269e960902a6c51d45abd0748350c7 100644 (file)
@@ -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 <cpExtensions/Config.h>
 
 #ifdef cpExtensions_QT4
 
 #include <QWidget>
+#include <gdcmSerieHelper.h>
 
 // -------------------------------------------------------------------------
 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$
index a93759db9ff2eb5aa380e6becc5c5eb415672abd..9fe2dccb997552666e0eb486cbe773ba0672aea5 100644 (file)
@@ -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