]> Creatis software - creaImageIO.git/commitdiff
Add Analyze Reader to creaImageIO
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Mon, 23 May 2011 15:33:58 +0000 (15:33 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Mon, 23 May 2011 15:33:58 +0000 (15:33 +0000)
Add black box to read analyze files

appli/TestWxItkView/main.cxx
bbtk/CMakeLists.txt
bbtk/src/bbcreaImageIOImagesChooserDialogBox.xml
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx [new file with mode: 0644]
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h [new file with mode: 0644]
src/CMakeLists.txt
src/creaImageIOWxAnySimpleDlg.cpp [new file with mode: 0644]
src/creaImageIOWxAnySimpleDlg.h [new file with mode: 0644]

index 60898b99ee1b52dc21d188c50b18820c02b59836..fb21ace51602a07fb57540011b0716afa625106c 100644 (file)
@@ -1,11 +1,12 @@
 #include <creaImageIOSystem.h>
 #include <creaWx.h>
-#include <creaImageIOWxISimpleDlg.h>
-#include <creaImageIOWxISimpleDlg.hpp>
+//#include <creaImageIOWxISimpleDlg.h>
+//#include <creaImageIOWxISimpleDlg.hpp>
 #include <itkImageBase.h>
 #include <creaVtkBasicSlicer.h>
+#include <creaImageIOWxAnySimpleDlg.h>
 
-#define ITK_DIM_TO_TEST 4
+#define ITK_DIM_TO_TEST 3
 
 // Just to test the selection of file(s), directory or from creaImageIO database.
 class myApp : public wxApp
@@ -30,45 +31,64 @@ bool myApp::OnInit( )
    std::vector <vtkImageData*> vtktest;
    std::vector<std::string> exts;
    vtkImageData* im = vtkImageData::New();
-  if(ITK_DIM_TO_TEST == 3)
-   {
+                       creaImageIO::WxAnySimpleDlg w(0);
+                       w.ShowModal();
+                       std::vector <boost::any> Wtest = w.getImagesSelected();
+   
+                       typedef itk::Image<short, ITK_DIM_TO_TEST >  ImageType;
+                       ImageType::Pointer img = ImageType::New();
+                       img = boost::any_cast<ImageType*>(Wtest[0]);
+                       //int count = boost::unsafe_any_cast<ImageType*>(Wtest[0]).GetReferenceCount();
+                       std::vector <ImageType::Pointer> test;
+                       //test.push_back( (ImageType::Pointer)(
+                               
+                       //      w.getImage<ImageType>(Wtest.front());
+               test = w.getTemplatedImagesSelected<ImageType>();
+  
+   
    
-          typedef itk::Image<short, ITK_DIM_TO_TEST >  ImageType;
-          creaImageIO::WxISimpleDlg<ImageType> x(0);
-          // files extension to take in count
-       exts.push_back(".hdr");
-       x.setExts(exts);
-       x.ShowModal();
-          // get itkImage vector
-          std::vector <ImageType::Pointer> test = x.getImagesSelected();
-          // convert 3D itk to 3D vtk
-          x.split3Din3Dvtk();
-          vtktest = x.getVtkImagesSelected();
-         if(vtktest.size() >0)
-         {
-               crea::VtkBasicSlicer(vtktest.front());
-         }
-  }
-  else if (ITK_DIM_TO_TEST == 4)
-  {
-         typedef itk::Image<short, ITK_DIM_TO_TEST >  ImageType;
-      creaImageIO::WxISimpleDlg<ImageType> x(0);
-         x.ShowModal();
-         // get itkImage vector
-         std::vector <ImageType::Pointer> test = x.getImagesSelected();
-         // convert 4D itk to 3D vtk  with a directory to create tempory vtk files.
-      x.split4Din3Dvtk("d:/temp2");
-         // get vtkImageData* vector
-         vtktest = x.getVtkImagesSelected();
-         if(vtktest.size() >0)
-         {
-               crea::VtkBasicSlicer(vtktest.front());
-         }
-       }
    
-  else{}
+ //  if(ITK_DIM_TO_TEST == 3)
+ //  {
+ //  
+       //   typedef itk::Image<short, ITK_DIM_TO_TEST >  ImageType;
+       //   creaImageIO::WxISimpleDlg<ImageType> x(0);
+       //   // files extension to take in count
+ //      exts.push_back(".hdr");
+ //      x.setExts(exts);
+ //      x.ShowModal();
+       //   // get itkImage vector
+       //   std::vector <ImageType::Pointer> test = x.getImagesSelected();
+       //   // convert 3D itk to 3D vtk
+       //   x.split3Din3Dvtk();
+       //   vtktest = x.getVtkImagesSelected();
+       //  if(vtktest.size() >0)
+       //  {
+       //      crea::VtkBasicSlicer(vtktest.front());
+       //  }
+ // }
+ // else if (ITK_DIM_TO_TEST == 4)
+ // {
+       //  typedef itk::Image<short, ITK_DIM_TO_TEST >  ImageType;
+ //     creaImageIO::WxISimpleDlg<ImageType> x(0);
+       //  x.ShowModal();
+       //  // get itkImage vector
+       //  std::vector <ImageType::Pointer> test = x.getImagesSelected();
+       //  // convert 4D itk to 3D vtk  with a directory to create tempory vtk files.
+ //     x.split4Din3Dvtk("d:/temp2");
+       //  // get vtkImageData* vector
+       //  vtktest = x.getVtkImagesSelected();
+       //  if(vtktest.size() >0)
+       //  {
+       //      crea::VtkBasicSlicer(vtktest.front());
+       //  }
+       //}
+ //  
+ // else{}
 
+ //
   
    return false;
 }
index e5e67935d2f8ff0956b9b841ca5ecf21a806d784..8c2ae04d64df27ba4e4cd2296bcb2722b734a79b 100644 (file)
@@ -104,7 +104,12 @@ SET(${BBTK_PACKAGE_NAME}_INCLUDE_ALL_BBS_APPLI ON)
 # !! THE PATH MUST BE RELATIVE TO THE bbs FOLDER !!
 #)
 #===========================================================================
-
+IF(USE_ITK)
+SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
+        ${BBTK_DIR}/../../../include/bbitk
+        ${BBTK_DIR}/../packages/itk/src
+       )
+ELSE(USE_ITK)
 #===========================================================================
 SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
   # LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES 
@@ -115,7 +120,7 @@ SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
   #  - the dirs automatically set by other libraries found by FIND_PACKAGE
   )
 #===========================================================================
-
+ENDIF(USE_ITK)
 #===========================================================================
 SET(${BBTK_PACKAGE_NAME}_LIBS 
   # LIST HERE THE ADDITIONAL LIBS TO LINK AGAINST
index 4709dd4f367e40d5cca9a3da993202c465f98d06..8310f1cb7c785024a9fee76d2d967e2c10c26696 100644 (file)
@@ -24,7 +24,7 @@
   </typedef>
 
   <output name="Out" type="vtkImageData*" description="The selected image"/>
-  <output name="OutImages" type="OutputImagesType" description="Vector of elected images"/>
+  <output name="OutImages" type="OutputImagesType" description="Vector of selected images"/>
   
   <!--========================================================================
     PROCESS section -->
diff --git a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx
new file mode 100644 (file)
index 0000000..c1c6e4c
--- /dev/null
@@ -0,0 +1,79 @@
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+
+#include "bbcreaImageIOItkImagesChooserDialogBox.h"
+#include "bbcreaImageIOPackage.h"
+
+namespace bbcreaImageIO
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaImageIO,ItkImagesChooserDialogBox)
+BBTK_BLACK_BOX_IMPLEMENTATION(ItkImagesChooserDialogBox,bbtk::AtomicBlackBox);
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void ItkImagesChooserDialogBox::Process()
+{
+       dlg = new creaImageIO::WxAnySimpleDlg(0,crea::std2wx(bbGetInputTitle()),"localdatabase_Descriptor.dscp","Local Database"); 
+    dlg->ShowModal(); 
+       
+       // FCY to test
+       bbtk::TypeInfo typ = bbitk::GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(*dlg->getTypes().front(), dlg->getDims().front());
+       BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, Export);
+       bbSetOutputOutVImages(dlg->getVtkImagesSelected());
+       delete dlg;
+}
+template <class TImage>
+void ItkImagesChooserDialogBox::Export()
+{
+        if (dlg->getImagesSelected().size() == 1)
+        { 
+               bbSetOutputOut( dlg->getTemplatedImagesSelected<TImage>().front() ); 
+        } 
+         else if (dlg->getImagesSelected().size() > 1)
+         { 
+//             bbSetOutputOutImages( bbSetOutputOutIImages( dlg->getTemplatedImagesSelected<TImage>() )); 
+      } 
+         else
+         {
+               bbSetOutputOut( NULL); 
+         }
+        // FCY To test the Output
+         //typedef itk::Image <short, 3> ImageType;
+        //typedef itk::ImageFileReader< ImageType > itkReaderType;
+     //  typename itkReaderType::Pointer reader = itkReaderType::New();
+     //
+     //  reader->SetFileName("d:\test.hdr");
+     //   reader->Update(); 
+        //reader->GetOutput()->Register();
+     //  this->bbSetOutputOut(reader->GetOutput());
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void ItkImagesChooserDialogBox::bbUserSetDefaultValues()
+{
+  
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void ItkImagesChooserDialogBox::bbUserInitializeProcessing()
+{
+
+}
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+void ItkImagesChooserDialogBox::bbUserFinalizeProcessing()
+{
+
+}
+}
+// EO namespace bbcreaImageIO
+
+
diff --git a/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h b/bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h
new file mode 100644 (file)
index 0000000..368a638
--- /dev/null
@@ -0,0 +1,78 @@
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+#ifndef __bbcreaImageIOItkImagesChooserDialogBox_h_INCLUDED__
+#define __bbcreaImageIOItkImagesChooserDialogBox_h_INCLUDED__
+
+#define BBTK_ITK_IMAGE_DIM_2
+#define BBTK_ITK_IMAGE_DIM_3
+#define BBTK_ITK_IMAGE_DIM_4
+#define BBTK_ITK_IMAGE_TYPE_int8_t
+#define BBTK_ITK_IMAGE_TYPE_uint8_t
+#define BBTK_ITK_IMAGE_TYPE_int16_t
+#define BBTK_ITK_IMAGE_TYPE_uint16_t
+#define BBTK_ITK_IMAGE_TYPE_int32_t
+#define BBTK_ITK_IMAGE_TYPE_uint32_t
+#define BBTK_ITK_IMAGE_TYPE_float
+#define BBTK_ITK_IMAGE_TYPE_double
+
+#include "bbcreaImageIO_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "bbitkImage.h"
+#include "bbtkAny.h"
+#include "creaImageIOWxAnySimpleDlg.h"
+
+namespace bbcreaImageIO
+{
+typedef std::vector<vtkImageData*> OutputImagesVTKType;
+typedef std::vector<bbitk::anyImagePointer> OutputImagesITKType;
+
+class bbcreaImageIO_EXPORT ItkImagesChooserDialogBox
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(ItkImagesChooserDialogBox,bbtk::AtomicBlackBox);
+  
+       creaImageIO::WxAnySimpleDlg *dlg;
+        
+
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+  BBTK_DECLARE_INPUT(Title,std::string);
+  BBTK_DECLARE_OUTPUT(OutVImages,OutputImagesVTKType);
+  BBTK_DECLARE_OUTPUT(OutIImages,OutputImagesITKType);
+  BBTK_DECLARE_OUTPUT(Out,bbitk::anyImagePointer);
+  BBTK_PROCESS(Process);
+  void Process();
+
+    private:
+    // Template read method 
+    template<class TImage> void Export();
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(ItkImagesChooserDialogBox,bbtk::AtomicBlackBox);
+BBTK_NAME("ItkImagesChooserDialogBox");
+BBTK_AUTHOR("cervenansky.frederic@creatis.insa-lyon.fr");
+BBTK_DESCRIPTION("ImagesChooserDialogBox is a simple application to select file(s) or directory or data from Gimmick database, handle them as ITKImage and/or display them. It handles Analayze, DICOM, jpg, tif, png, bmp and mhd.");
+BBTK_CATEGORY("image;reader;dicom;");
+
+
+BBTK_INPUT(ItkImagesChooserDialogBox,Title,"Title of the dialog",std::string,"");
+BBTK_OUTPUT(ItkImagesChooserDialogBox,OutVImages,"The selected Vtkimage",OutputImagesVTKType,"");
+BBTK_OUTPUT(ItkImagesChooserDialogBox,Out,"Output Image",bbitk::anyImagePointer,"");
+BBTK_OUTPUT(ItkImagesChooserDialogBox,OutIImages,"Vector of selected images",OutputImagesITKType,"");
+BBTK_END_DESCRIBE_BLACK_BOX(ItkImagesChooserDialogBox);
+
+//===== 
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//===== 
+}
+// EO namespace bbcreaImageIO
+
+#endif // __bbcreaImageIOItkImagesChooserDialogBox_h_INCLUDED__
+
index ea8d3328a7afd2d896a1286efcf57caaa7b1b95e..27d93ce706eedc70daee54e54cdcdd8f1e0a73a9 100644 (file)
@@ -75,6 +75,8 @@ IF(USE_ITK)
 FILE(GLOB SOURCES_CREAIMAGEIO_ITK_DLG
        creaImageIOWxIsimpleDlg.h
        creaImageIOWxIsimpleDlg.hpp
+       creaImageIOWxAnySimpleDlg.h
+       creaImageIOWxAnySimpleDlg.cpp
        )
 ENDIF(USE_ITK)
          
diff --git a/src/creaImageIOWxAnySimpleDlg.cpp b/src/creaImageIOWxAnySimpleDlg.cpp
new file mode 100644 (file)
index 0000000..b47346a
--- /dev/null
@@ -0,0 +1,606 @@
+#include "creaImageIOWxAnySimpleDlg.h"
+
+#include "creaImageIOWxGimmickReaderDialog.h"
+#include <itkAnalyzeImageIO.h>
+#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>
+#include <boost/filesystem.hpp>
+#include <boost/utility.hpp>
+#include <creaVtkBasicSlicer.h>
+#include "itkImageToVTKImageFilter.h"
+
+namespace creaImageIO
+{
+       
+       ///Ctor
+   WxAnySimpleDlg::WxAnySimpleDlg(wxWindow *parent, 
+                                                       wxString i_title,  
+                                                       const std::string i_namedescp , 
+                                                       const std::string i_namedb)
+    : wxDialog(parent, -1,_T("DISPLAY IMAGES"), wxDefaultPosition, wxSize(230,150))
+   {
+               namedescp       = i_namedescp; 
+               namedb          = i_namedb;
+
+          if(!i_title.empty())
+          {
+                       this->SetTitle(i_title);  
+          }
+          // Button to select file(s)
+          wxButton *fileBut = new wxButton(this, -1,_T("Select a file to display"), wxPoint(10,7) );
+          Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadFile ); 
+
+          // Button to select directory
+          wxButton *directoryBut = new wxButton(this, -1,_T("Select a directory to display"), wxPoint(10,40) );
+          Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadDirectory ); 
+
+          // button to select creaImageIO
+          wxButton *gimmickBut = new wxButton(this, -1,_T("Select Gimmick"), wxPoint(10,70) );
+          Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadGimmick ); 
+
+          /// \TODO  Button to select Bruker directory
+               m_dicom = true;
+       Layout(); 
+       
+       }
+//////////////////////////////////////////////////////////////////////
+//                                                                  //
+//////////////////////////////////////////////////////////////////////
+     
+        void WxAnySimpleDlg::OnReadFile(wxCommandEvent& event)
+         {
+                 int resultShowModal;
+                 wxFileDialog* fileDlg = new wxFileDialog( 0,  _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition);
+    
+                   resultShowModal = fileDlg->ShowModal();
+                       if ( resultShowModal==wxID_OK )
+                       {
+                               wxArrayString wxArray;
+                               fileDlg->GetPaths(wxArray);
+                               if(wxArray.size() >0)
+                               {
+                                       for( int i = 0; i < wxArray.GetCount(); i++)
+                                       {
+                                               std::string name = crea::wx2std(wxArray[i]);
+                                               // FOR THE MOMENT ONLY short 3D et short 4D
+                                               readImg(name);
+                                       }
+                               } 
+                               else {
+                                       // TO DO WARNING MESSAGES
+                               }
+                       }
+                 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;
+                 bool bvalid = false;
+            long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
+                wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style);
+                
+                resultShowModal = dirDlg->ShowModal();
+                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))
+                       {*/
+                               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;
+                                                  }
+                                          }
+                                       if (!boost::filesystem::is_directory(itr->status()) && bvalid)
+                                       {
+                                               readImg(itr->string().c_str());
+                                       }
+                               }
+                }
+                SetReturnCode( resultShowModal );
+//              Close();
+                EndModal( resultShowModal );
+         }
+
+         //////////////////////////////////////////////////////////////////////
+//                                                                                                                                     //
+//////////////////////////////////////////////////////////////////////
+                   
+         void WxAnySimpleDlg::OnReadGimmick(wxCommandEvent &event)
+         {
+                 // Run Gimmick
+                  WxGimmickReaderDialog dlg(0,-1, 
+                                  namedescp,
+                                  namedb, 
+                                  _T("Select image(s)        - Gimmick! (c) CREATIS-LRMN 2008"),
+                   wxDefaultPosition,
+                   wxSize(810,750),
+                   GIMMICK_2D_IMAGE_SELECTION,
+                   GIMMICK_3D_IMAGE_SELECTION,
+                   _3D,
+                                  1);
+                dlg.ShowModal();
+                if (dlg.GetReturnCode() == wxID_OK)
+            {
+                       std::vector<std::string> out;
+                       dlg.stopReading();
+                       dlg.GetSelectedFiles(out);
+                       if(m_dicom)
+                       {
+                               readDicomImg( out);
+                       }
+                       else
+                       {
+                               std::vector<std::string>::iterator ii = out.begin();
+                               for (;ii != out.end();ii++)
+                               {
+                                       readImg( (*ii).c_str() );
+                               }
+                       }
+                       dlg.OnExit();
+                }
+                SetReturnCode( dlg.GetReturnCode() );
+//              Close();
+                EndModal( dlg.GetReturnCode() );
+          }
+
+
+     
+        wxString WxAnySimpleDlg::getInfoImage()
+       {
+               return infoimage;
+       }
+
+
+         // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images
+       const std::type_info & WxAnySimpleDlg::getType(const std::string &i_name)
+        {
+                       typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
+                       itk::ImageIOBase::Pointer imageIO =  itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode);
+                   imageIO->SetFileName(i_name.c_str());
+                       imageIO->ReadImageInformation();
+                       return imageIO->GetComponentTypeInfo();//AsString( imageIO->GetComponentType());
+        }
+
+         const size_t WxAnySimpleDlg::getNumberOfDimensions(const std::string &i_name)
+        {
+                       typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
+                       itk::ImageIOBase::Pointer imageIO =  itk::ImageIOFactory::CreateImageIO(i_name.c_str(), itk::ImageIOFactory::ReadMode);
+                   imageIO->SetFileName(i_name.c_str());
+                       imageIO->ReadImageInformation();
+                       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)
+                 {
+                  case 3:
+                           if (getType(i_name) ==  typeid(unsigned char))
+                          {
+                                   typedef itk::Image<unsigned char, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                          }
+                         else if (getType(i_name) ==  typeid(signed char)) 
+                         {
+                                   typedef itk::Image<signed char, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                          else if (getType(i_name) ==  typeid(short))
+                          {
+                                   typedef itk::Image<short, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                          }
+                         else if (getType(i_name) ==  typeid(unsigned short)) 
+                         {
+                                   typedef itk::Image<unsigned short, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(unsigned int)) 
+                         {
+                                   typedef itk::Image<unsigned int, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(signed int)) 
+                         {
+                                   typedef itk::Image<signed int, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(unsigned long)) 
+                         {
+                                   typedef itk::Image<unsigned long, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(signed long)) 
+                         {
+                                   typedef itk::Image<signed long, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(float)) 
+                         {
+                                   typedef itk::Image<float, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(double)) 
+                         {
+                                   typedef itk::Image<double, 3> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                         }
+                         else
+                         {
+                                 //????FCY, so what the type????
+                         }
+                         break;
+                         //assume that we have only one 4D file
+                       case 4:
+                               if (getType(i_name) ==  typeid(unsigned char))
+                           {
+                                   typedef itk::Image<unsigned char, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                           }
+                          else if (getType(i_name) ==  typeid(signed char)) 
+                          {
+                                   typedef itk::Image<signed char, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                          }
+                          else if (getType(i_name) ==  typeid(unsigned short))
+                           {
+                                   typedef itk::Image<unsigned short, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                           }
+                          else if(getType(i_name) == typeid(short))
+                          {
+                                        typedef itk::Image<short, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       try 
+                                       { 
+                                               reader->Update(); 
+                                       } 
+                                       catch( itk::ExceptionObject & err ) 
+                                       { 
+                                               std::cout << "Caught an exception reading" << i_name << ": " << std::endl; 
+                                               std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; 
+                                               throw err; 
+                                       } 
+                                       catch(...) 
+                                       { 
+                                               std::cout << "Error while reading image " << i_name << std::endl; 
+                                               throw; 
+                                       } 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                          }
+                          else if (getType(i_name) ==  typeid(unsigned short)) 
+                          {
+                                   typedef itk::Image<unsigned short, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(unsigned int)) 
+                         {
+                                   typedef itk::Image<unsigned int, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(signed int)) 
+                         {
+                                   typedef itk::Image<signed int, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(unsigned long)) 
+                         {
+                                   typedef itk::Image<unsigned long, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(signed long)) 
+                         {
+                                   typedef itk::Image<signed long, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(float)) 
+                         {
+                                   typedef itk::Image<float, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else if (getType(i_name) ==  typeid(double)) 
+                         {
+                                   typedef itk::Image<double, 4> TImage;
+                                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                                       ReaderType::Pointer reader = ReaderType::New(); 
+                                       reader->SetFileName( i_name ); 
+                                       reader->Update(); 
+                                       reader->GetOutput()->Register();
+                                       m_AnyImages.push_back(reader->GetOutput());
+                                       split4Din3Dvtk<TImage>(reader->GetOutput());
+                         }
+                         else
+                         {
+                                 //????FCY, so what the type????
+                         }
+                         break;
+                  }
+                  
+                  // Test to know if we have to add new type
+                 bool btest = false;
+                  if( m_AnyDims.size() != 0)
+                  {
+                          btest = true;
+                  }
+                  else
+                  {
+                          m_AnyDims.push_back(dims);
+                          m_AnyType.push_back(&getType(i_name));
+                  }
+                  if (btest)
+                  {
+                          if(m_AnyDims.front() != dims || m_AnyType.front()->before(getType(i_name)))
+                          {
+                                  m_AnyDims.push_back(dims);
+                                  m_AnyType.push_back(&getType(i_name));
+                          }
+                          else{}
+                  }
+                  else  {}
+         }
+
+
+
+
+         void WxAnySimpleDlg::readDicomImg(const std::vector<std::string> &i_names)
+         {
+                 typedef itk::Image<short,3> TImage;
+                 typedef itk::GDCMImageIO GDCMType;
+                 typedef itk::DICOMSeriesFileNames dicnames;
+                 GDCMType::Pointer gdcmIO = GDCMType::New(); 
+                 dicnames::Pointer generator = dicnames::New();
+
+
+                       typedef itk::ImageSeriesReader<TImage> ReaderType; 
+                   ReaderType::Pointer reader = ReaderType::New(); 
+                       reader->SetImageIO(gdcmIO);
+                       reader->SetFileNames(i_names);
+               //      reader->SetFileName( i_name ); 
+                       try 
+                       { 
+                               reader->Update(); 
+                       } 
+                       catch( itk::ExceptionObject & err ) 
+                       { 
+                       //      std::cout << "Caught an exception reading" << i_name << ": " << std::endl; 
+                               std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl; 
+                               throw err; 
+                       } 
+                       catch(...) 
+                       { 
+                               //std::cout << "Error while reading image " << i_name << std::endl; 
+                               throw; 
+                       } 
+                       //m_Iresults.push_back(reader->GetOutput()); 
+    
+         }
+
+
+
+
+         template <typename TImage> 
+         void WxAnySimpleDlg::split3Din3Dvtk(TImage* i_Img)
+         {
+                 typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
+                 ConnectorType::Pointer          connector = ConnectorType::New();
+         connector->SetInput(i_Img);
+                 connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
+                 connector->Update();
+                 vtkImageData *im = vtkImageData::New();
+                 im->ShallowCopy(connector->GetOutput());
+                 im->Update();
+                 m_Vresults.push_back(im);
+         }
+
+
+         template <typename TImage> 
+         void WxAnySimpleDlg::split4Din3Dvtk(TImage* i_Img)
+         {
+                                if(i_Img->GetImageDimension() == 4)
+                                {
+
+                                        // size of fourth dimension 
+                                        int dsize = i_Img->GetLargestPossibleRegion().GetSize(3);
+                                        // Output Type
+                                        typedef itk::Image<unsigned char,3> ImageOutputType;  
+                                        typedef itk::ImageSeriesWriter<TImage, ImageOutputType >  SeriesWriterType;
+                                        typedef itk::MetaImageIO MetaImageType;
+                                        MetaImageType::Pointer metaIO;
+                                        SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
+                       
+                                        // from JPR file to generate output files
+                                        typedef itk::NumericSeriesFileNames NamesGeneratorType;
+                                        NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();
+                                        namesGenerator->SetStartIndex(0);
+                                        namesGenerator->SetEndIndex(dsize-1); 
+                                        namesGenerator->SetIncrementIndex(1);
+                                        std::string format = m_dir;
+                                        format += "/image%03d.mhd";
+                                        namesGenerator->SetSeriesFormat( format.c_str() );
+                                       
+                                        const std::vector<std::string> names = namesGenerator->GetFileNames();
+                                        seriesWriter->SetFileNames( names );
+                                        seriesWriter->SetInput(i_Img);
+                                        seriesWriter->SetImageIO(metaIO);
+                                        try
+                                       {
+                                               seriesWriter->Update();
+                                               vtkMetaImageReader *vReader = vtkMetaImageReader::New();
+                                               std::vector<std::string>::const_iterator it = names.begin();
+                                               for( ;it !=  names.end(); ++it)
+                                               {
+                                                       vReader->SetFileName((*it).c_str());
+                                                       vReader->Update();
+                                                       m_Vresults.push_back(vReader->GetOutput());
+                                                       
+                                               }
+                                       }
+                                       catch( itk::ExceptionObject & excp )
+                                       {
+                                               std::cerr << "Exception thrown while writing the series " << std::endl;
+                                               std::cerr << excp << std::endl;
+                                               //return EXIT_FAILURE;
+                                       }
+                                }
+         }
+
+          bool WxAnySimpleDlg::AllSameType()
+          {
+                  if(m_AnyType.size() == 1)
+                  {
+                          return true;
+                  }
+                  else
+                  {
+                          return false;
+                  }
+
+          }
+
+ }// namespace end
+
diff --git a/src/creaImageIOWxAnySimpleDlg.h b/src/creaImageIOWxAnySimpleDlg.h
new file mode 100644 (file)
index 0000000..08ae0b0
--- /dev/null
@@ -0,0 +1,101 @@
+#include "creaImageIOSimpleView.h"
+#include <creaWx.h>
+#include <itkImageFileReader.h>
+#include <boost/any.hpp>
+namespace creaImageIO
+{
+ /**
+   * \ingroup View
+   */
+
+       /// Simple Wxwidgets interface to select file(s) or directory or from creaImageIO database to display
+       class  __declspec(dllexport) WxAnySimpleDlg : public wxDialog
+       {
+       public:
+                /// Ctor
+                 WxAnySimpleDlg( wxWindow *parent,  
+                         wxString i_title =_T(""),
+                         const std::string i_namedescp = "localdatabase_Descriptor.dscp",   
+                         const std::string i_namedb   = "Local Database"     
+                         );
+
+                 ~WxAnySimpleDlg(){};
+
+                 void setExts(std::vector<std::string>);
+                 /// Callback to read file(s)
+                 void OnReadFile(wxCommandEvent& event);
+
+                 /// Callback to read directory, no recursive
+                  void OnReadDirectory(wxCommandEvent &event);
+             
+                 /// Callback to select from creaImageIO database
+                  void OnReadGimmick(wxCommandEvent &event);
+
+                  /// return a vtkImageData vector of selected images, if available
+                  std::vector<vtkImageData*> getVtkImagesSelected() {return m_Vresults;}
+
+                  wxString getInfoImage();
+
+          
+                  void set(bool i_dicom){m_dicom= i_dicom;}
+                  std::vector <boost::any>& getImagesSelected(){ return m_AnyImages;}
+               
+                  // return the size of readed images
+                  std::vector<const size_t> getDims(){ return m_AnyDims;}
+
+                  // return the type of readed images
+                  std::vector<const std::type_info *> getTypes(){ return m_AnyType;}
+
+                  // get an Image on wanted type
+                  template <typename TImage> 
+              typename TImage::Pointer getImage(boost::any i_AnyImage)
+             {
+                     typedef itk::Image<TImage> ImageOut;
+                    ImageOut::Pointer img = ImageOut::New();
+                    img = boost::any_cast< ImageOut::Pointer>(i_AnyImage);
+                    return img;
+            }
+
+                // get the images on itk type defined by user
+                 template <typename TImage> 
+                 std::vector<typename TImage::Pointer>  getTemplatedImagesSelected()
+                 {
+                        std::vector<typename TImage::Pointer> imgs;
+                        std::vector<boost::any>::iterator it = m_AnyImages.begin();
+                    for(; it != m_AnyImages.end(); it++)
+                    {
+                                imgs.push_back(boost::any_cast<TImage*> (*it));
+                    }
+                        return imgs;
+             }
+                 bool AllSameType();
+       private:
+
+               
+               std::vector<const size_t> m_AnyDims;
+               std::vector<const std::type_info *> m_AnyType;
+               std::vector<boost::any> m_AnyImages;
+               std::vector<std::string> m_exts;
+               std::string namedescp; 
+               std::string namedb;
+               wxString infoimage;
+               std::string m_dir;
+               template <class TImage> 
+                 void split3Din3Dvtk(TImage* i_Img);
+
+               template <typename TImage> 
+                 void split4Din3Dvtk(TImage* i_Img);
+
+               bool m_dicom;
+               /// interface to read data
+               SimpleView m_view;
+                void readImg(const std::string &i_name);
+                void readDicomImg(const std::vector<std::string> &i_names);
+                std::vector <vtkImageData*> m_Vresults;
+                
+         const size_t getNumberOfDimensions(const std::string &i_name);
+         const std::type_info & getType(const std::string &i_name);
+       };
+
+
+}