]> Creatis software - creaImageIO.git/blobdiff - src/creaImageIOWxAnySimpleDlg.cpp
Merge remote-tracking branch 'origin/changeWx28to30' into vtk7itk4wx3
[creaImageIO.git] / src / creaImageIOWxAnySimpleDlg.cpp
index 7020ffee6929221b9ac22a830f7b2e1189a8566a..4a31cbe9de72e7d4cae819d5c03abaf8f7dc0afb 100644 (file)
@@ -1,17 +1,50 @@
+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
+#                        pour la Santé)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and 
+#  abiding by the rules of distribution of free software. You can  use, 
+#  modify and/ or redistribute the software under the terms of the CeCILL-B 
+#  license as circulated by CEA, CNRS and INRIA at the following URL 
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability. 
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+*/
+
+
 #include "creaImageIOWxAnySimpleDlg.h"
 
 #include "creaImageIOWxGimmickReaderDialog.h"
-#include <itkAnalyzeImageIO.h>
+
+#if ITK_VERSION_MAJOR < 4 //  : WARNING: deprecated in ITK 4.0
+#  include <itkAnalyzeImageIO.h>
+#  include <itkDICOMSeriesFileNames.h>
+#else // ITK_VERSION_MAJOR < 4
+#  include <itkGDCMSeriesFileNames.h>
+#endif // ITK_VERSION_MAJOR < 4
+
 #include <itkImageFileReader.h>
 #include <itkImageSeriesReader.h>
 #include <itkImage.h>
 #include <itkImageSeriesWriter.h>
 #include <itkGDCMImageIO.h>
-#include <itkDICOMSeriesFileNames.h>
 #include <itkNumericSeriesFileNames.h>
 #include <itkVectorImage.h>
 #include <itkMetaImageIO.h>
-#include <itkOrientedImage.h>
 #include <vtkImageReader2.h>
 #include <vtkMetaImageReader.h>
 #include <boost/filesystem/path.hpp>
@@ -61,7 +94,12 @@ namespace creaImageIO
      void WxAnySimpleDlg::OnReadFile(wxCommandEvent& event)
       {
           int resultShowModal;
+//EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
+#if wxMAJOR_VERSION <= 2
           wxFileDialog* fileDlg = new wxFileDialog( 0,  _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition);
+#else
+          wxFileDialog* fileDlg = new wxFileDialog( 0,  _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxFD_OPEN |wxFD_MULTIPLE, wxDefaultPosition);
+#endif
     
           resultShowModal = fileDlg->ShowModal();
           if ( resultShowModal==wxID_OK )
@@ -75,25 +113,28 @@ namespace creaImageIO
                         std::string name = crea::wx2std(wxArray[i]);
                         // FOR THE MOMENT ONLY short 3D et short 4D
                         readImg(name);
-                    }
-                } 
-                else {
+                    } // for
+                } else {
                     // TO DO WARNING MESSAGES
-                }
-          }
+                } // if
+          } // if
           SetReturnCode( resultShowModal );
 //         Close();
           EndModal( resultShowModal );
       }
         
+
+/////////////////////////////////////////////////////////////////////
+//                                                                  //
+//////////////////////////////////////////////////////////////////////
      void WxAnySimpleDlg::setExts(std::vector<std::string> i_exts)
      {
          m_exts = i_exts;
      }
- /////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////
 //                                                                  //
 //////////////////////////////////////////////////////////////////////
-
       void WxAnySimpleDlg::OnReadDirectory(wxCommandEvent &event)
       {
          int resultShowModal;
@@ -105,33 +146,55 @@ namespace creaImageIO
          if ( resultShowModal==wxID_OK )
          {  
             std::string path = crea::wx2std(dirDlg->GetPath());
+
+/*
             typedef boost::filesystem::directory_iterator dir_it;
             dir_it itr(path);
             dir_it end_itr;
-            /*if (boost::filesystem::exists(path))
-            {*/
+//            if (boost::filesystem::exists(path))
+//            {
                 for(;itr != end_itr; ++itr)
                 {
-                       bvalid = m_exts.size() == 0? true : false;
-                       std::vector<std::string>::iterator it = m_exts.begin();
-                       std::string ext = itr->filename().substr(itr->filename().find_last_of("."));
-                       for(; it != m_exts.end(); it++)
-                       {
-                           if(ext == (*it) )
-                           {
-                               bvalid = true;
-                               break;
-                           }
-                       }
+//EED 
+// All files have the same extention
+//                      bvalid = m_exts.size() == 0? true : false;
+//                      std::vector<std::string>::iterator it = m_exts.begin();
+//                                        std::string ext = itr->path().filename().string().substr(itr->path().filename().string().find_last_of("."));
+//                       for(; it != m_exts.end(); it++)
+//                       {
+//                           if(ext == (*it) )
+//                           {
+//                               bvalid = true;
+//                               break;
+//                           }
+//                       } // for 
+bvalid=true;
                        if (!boost::filesystem::is_directory(itr->status()) && bvalid)
                        {
-                           readImg(itr->string().c_str());
-                       }
-                }
-         }
+printf("EED WxAnySimpleDlg::OnReadDirectory  Each file %s \n", itr->path().string().c_str() );
+                           readImg( itr->path().string().c_str() );
+                       } // if 
+                } // for itr
+*/
+
+                               typedef vector<boost::filesystem::path> vec;             // store paths
+                               vec v;                                // so we can sort them later
+                               copy(boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(), back_inserter(v));
+                               sort(v.begin(), v.end());             // sort, since directory iteration
+                                                                     // is not ordered on some file systems
+                               for (vec::const_iterator it (v.begin()); it != v.end(); ++it)
+                               {
+                           readImg( it->string().c_str() );
+                               } // for
+
+
+
+
+         } // if OK
          SetReturnCode( resultShowModal );
 //         Close();
          EndModal( resultShowModal );
+
       }
 
 //////////////////////////////////////////////////////////////////////
@@ -203,9 +266,11 @@ namespace creaImageIO
             return imageIO->GetNumberOfDimensions();
      }
 
+
      void WxAnySimpleDlg::readImg(const std::string &i_name)
      {
           size_t dims = getNumberOfDimensions(i_name);
+
           //const std::type_info  *type= &getType(i_name);
           switch(dims)
           {
@@ -312,6 +377,7 @@ namespace creaImageIO
               }
               else
               {
+                               printf("EED WxAnySimpleDlg::readImg Not type found   for DIM 3 \n");
                   //????FCY, so what the type????
               }
               break;
@@ -454,6 +520,7 @@ namespace creaImageIO
                }
                else
                {
+                               printf("EED WxAnySimpleDlg::readImg Not type found   for DIM 4 \n");
                   //????FCY, so what the type????
                }
                break;
@@ -486,7 +553,11 @@ namespace creaImageIO
       {
           typedef itk::Image<short,3> TImage;
           typedef itk::GDCMImageIO GDCMType;
+#if ITK_VERSION_MAJOR < 4
           typedef itk::DICOMSeriesFileNames dicnames;
+#else // ITK_VERSION_MAJOR < 4
+          typedef itk::GDCMSeriesFileNames dicnames;
+#endif // ITK_VERSION_MAJOR < 4
           GDCMType::Pointer gdcmIO = GDCMType::New(); 
           dicnames::Pointer generator = dicnames::New();