]> Creatis software - creaImageIO.git/commitdiff
modifications for bbtkItkImageChooserDialogBox
authorFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Thu, 23 Jun 2011 10:17:02 +0000 (10:17 +0000)
committerFrederic Cervenansky <Frederic.Cervenansky@creatis.insa-lyon.fr>
Thu, 23 Jun 2011 10:17:02 +0000 (10:17 +0000)
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h
src/creaImageIOWxAnySimpleDlg.cpp
src/creaImageIOWxAnySimpleDlg.h
src/creaImageIOWxISimpleDlg.hpp
src/creaImageIOWxIsimpleDlg.h
tests/TestDcmDescriptor.cpp

index 1f4d1e657bfeb33419adb3b395690a717b9117f7..2d9074973262fb6015f58e07eac71ddaa57c3634 100644 (file)
@@ -21,7 +21,8 @@ void ItkImagesChooserDialogBox::Process()
 
        bbtk::TypeInfo typ = bbitk::GetITKImagePtrTypeInfoFromPixelTypeInfoAndDimension(*dlg->getTypes().front(), dlg->getDims().front());
        BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, Export);
-       bbSetOutputOutVImages(dlg->getVtkImagesSelected());
+       BBTK_TEMPLATE_ITK_IMAGE_SWITCH(typ, ExportVTK);
+       
        delete dlg;
 }
 template <class TImage>
@@ -34,8 +35,8 @@ void ItkImagesChooserDialogBox::Export()
          else if (dlg->getImagesSelected().size() > 1)
          { 
                  OutputImagesITKType outVect;
-                 typename std::vector< typename TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected<TImage>();  // JPR typename typename
-                 typename std::vector< typename TImage::Pointer>::iterator it = tempImgs.begin(); // JPR typename typename
+                 std::vector<TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected<TImage>();
+                 std::vector<TImage::Pointer>::iterator it = tempImgs.begin();
                  for(;it != tempImgs.end(); ++it)
                  {
                          outVect.push_back( (*it).GetPointer() );
@@ -56,6 +57,33 @@ void ItkImagesChooserDialogBox::Export()
         //reader->GetOutput()->Register();
      //  this->bbSetOutputOut(reader->GetOutput());
 }
+template <class TImage>
+void ItkImagesChooserDialogBox::ExportVTK()
+{
+       // BBTK can support only a vector with same dimensions image.
+        if (dlg->getDims().front() < 4)
+        { 
+                 std::vector<TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected<TImage>();
+                 std::vector<TImage::Pointer>::iterator it = tempImgs.begin();
+                 for(;it != tempImgs.end(); ++it)
+                 {
+                       dlg->split3Din3Dvtk<TImage>( (*it) );
+                 }
+                 bbSetOutputOutVImages( dlg->getVtkImagesSelected() ); 
+        } 
+        else if (dlg->getDims().front() == 4)
+         { 
+               // To Test
+                //  dlg->split4Din3Dvtk("d:/temp2");
+                // bbSetOutputOutVImages( dlg->getVtkImagesSelected()); 
+      } 
+         else
+         {
+                 // NOT IMPLEMENTED YET FOR DIMENSIONS > 4
+               
+         }
+        
+}
 //===== 
 // 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)
 //===== 
index f99b8592f37e9a03bafde92389c15d184d8c86d8..95088c634bd7ff613f0c8f3c3bc0134f6bc3c2cf 100644 (file)
@@ -50,6 +50,10 @@ class bbcreaImageIO_EXPORT ItkImagesChooserDialogBox
     private:
     // Template read method 
     template<class TImage> void Export();
+
+       // Template export vtk Images
+       template<class TImage> void ExportVTK();
+
        itk::Object* mOutput;
 //===== 
 // 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)
index e66d2ba3cecacd8964afb4d5971028c8a0059f9c..ffaccd307d7d0ca87a77257c5d0095e4325bf9d1 100644 (file)
@@ -18,7 +18,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/utility.hpp>
 #include <creaVtkBasicSlicer.h>
-#include "itkImageToVTKImageFilter.h"
+
 
 namespace creaImageIO
 {
@@ -50,7 +50,7 @@ namespace creaImageIO
        Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAnySimpleDlg::OnReadGimmick ); 
 
        /// \TODO  Button to select Bruker directory
-        m_dicom = true;
+        m_dicom = false;
         Layout(); 
     }
 
@@ -515,7 +515,7 @@ namespace creaImageIO
     
       }
 
-      template <typename TImage> 
+  /*    template <typename TImage> 
       void WxAnySimpleDlg::split3Din3Dvtk(TImage* i_Img)
       {
           typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
@@ -527,7 +527,7 @@ namespace creaImageIO
           im->ShallowCopy(connector->GetOutput());
           im->Update();
           m_Vresults.push_back(im);
-      }
+      }*/
 
 
       template <typename TImage> 
index 17656da3f6a15e3fe6da8b486475176bff18f442..49218a14213b83f2c962e6352e4ef73c415c93b0 100644 (file)
@@ -1,7 +1,5 @@
-
-
-#ifndef __creaImageIOWxAnySimpleDlg_h_INCLUDED__
-#define __creaImageIOWxAnySimpleDlg_h_INCLUDED__
+#ifndef __creaImageWxAnySimpleDlg_h_INCLUDED__
+#define __creaImageWxAnySimpleDlg_h_INCLUDED__
 
 
 
@@ -10,6 +8,8 @@
 #include <itkImageFileReader.h>
 #include <boost/any.hpp>
 #include <typeinfo>
+#include "itkImageToVTKImageFilter.h"
+
 namespace creaImageIO
 {
  /**
@@ -80,6 +80,25 @@ namespace creaImageIO
              return imgs;
           }
           bool AllSameType();
+                 template <class TImage> 
+                 void split3Din3Dvtk(TImage* i_Img)
+                {
+                       typedef itk::ImageToVTKImageFilter< TImage > ConnectorType;
+                        typename 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 split4Din3Dvtk(TImage* i_Img);
+
     private:
 
         // strange compile error with gcc 4.5.1-4 //JPR        
@@ -91,13 +110,9 @@ namespace creaImageIO
         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;
+       bool m_dicom;
         /// interface to read data
         SimpleView m_view;
         void readImg(const std::string &i_name);
@@ -108,7 +123,6 @@ namespace creaImageIO
         const std::type_info & getType(const std::string &i_name);
     };
 
-}
-
 
-#endif //__creaImageIOWxAnySimpleDlg_h_INCLUDED__
+}// namespace creaImageIO
+#endif //__creaImageWxAnySimpleDlg_h_INCLUDED__
index dbbbf8d310fbbb7ffa1b27128aab61ce912acd96..40553c38f78410d102af4dd2bc57e7c05f0714fa 100644 (file)
@@ -220,156 +220,162 @@ namespace creaImageIO
     //////////////////////////////////////////////////////////////////////
     // Return the results vector                                        //
     //////////////////////////////////////////////////////////////////////
-     template <typename TImage>  
-     std::vector<typename TImage::Pointer> WxISimpleDlg<TImage>::getImagesSelected()
-      {
-          return m_Iresults;
-      }
-
-      template <typename TImage> 
-      void WxISimpleDlg<TImage>::readImg(const std::string &i_name)
-      {
-            // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images
-            // uncomment to test
-              /*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();
-            ScalarPixelType pixelType = imageIO->GetComponentType();
-            const size_t dims =  imageIO->GetNumberOfDimensions();*/
-
-            typedef itk::ImageFileReader<TImage> ReaderType;
-            typename 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; 
-            } 
-            m_Iresults.push_back(reader->GetOutput());
-      }
-
-
-
-      template <typename TImage> 
-      void WxISimpleDlg<TImage>::readDicomImg(const std::vector<std::string> &i_names)
-      {
-            typedef itk::GDCMImageIO GDCMType;
-            typedef itk::DICOMSeriesFileNames dicnames;
-            GDCMType::Pointer gdcmIO = GDCMType::New(); 
-            dicnames::Pointer generator = dicnames::New();
-//          generator->SetInput(i_names);
-            typedef itk::ImageSeriesReader<TImage> ReaderType; 
-            typename 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 WxISimpleDlg<TImage>::split3Din3Dvtk()
-      {
-          if ((m_Iresults).size() != 0)
-          {
-              typedef itk::ImageToVTKImageFilter<  TImage > ConnectorType;
-              ConnectorType::Pointer       connector = ConnectorType::New();
-               for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
-              {
-                    connector->SetInput(m_Iresults[i]);
-                    connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
-                    connector->Update();
-                    vtkImageData *im = vtkImageData::New();
-                    im->ShallowCopy(connector->GetOutput());
-                    im->Update();
-                    m_Vresults.push_back(im);
-             }
-          }
-      }
-
-
-
-      template <typename TImage> 
-      void WxISimpleDlg<TImage>::split4Din3Dvtk(const std::string &i_dir)
-      {
-            if ((m_Iresults).size() != 0)
-            {
-                typename TImage::Pointer image = m_Iresults[0];
-            
-                 if(image->GetImageDimension() == 4)
-                 {
-                     // size of fourth dimension 
-                     int dsize = image->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 = i_dir;
-                     format += "/image%03d.mhd";
-                     namesGenerator->SetSeriesFormat( format.c_str() );
-                    
-                     const std::vector<std::string> names = namesGenerator->GetFileNames();
-                     seriesWriter->SetFileNames( names );
-                     seriesWriter->SetInput(image);
-                     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;
-                    }
-                 }
-              }
-      }
+        template <typename TImage>  
+        std::vector<typename TImage::Pointer> WxISimpleDlg<TImage>::getImagesSelected()
+         {
+                 return m_Iresults;
+         }
+
+         template <typename TImage> 
+         void WxISimpleDlg<TImage>::readImg(const std::string &i_name)
+         {
+                   // FCY : just to check but not needed, we hardly suppose that we load only same type and dim of images
+                   // uncomment to test
+                       /*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();
+                       ScalarPixelType pixelType = imageIO->GetComponentType();
+                       const size_t dims =  imageIO->GetNumberOfDimensions();*/
+
+                       typedef itk::ImageFileReader<TImage> ReaderType; 
+                   typename 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; 
+                       } 
+                       m_Iresults.push_back(reader->GetOutput()); 
+    
+         }
+
+
+
+         template <typename TImage> 
+         void WxISimpleDlg<TImage>::readDicomImg(const std::vector<std::string> &i_names)
+         {
+                 typedef itk::GDCMImageIO GDCMType;
+                 typedef itk::DICOMSeriesFileNames dicnames;
+                 GDCMType::Pointer gdcmIO = GDCMType::New(); 
+                 dicnames::Pointer generator = dicnames::New();
+//               generator->SetInput(i_names);
+                       typedef itk::ImageSeriesReader<TImage> ReaderType; 
+                   typename 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 WxISimpleDlg<TImage>::split3Din3Dvtk()
+         {
+                 if ((m_Iresults).size() != 0)
+                 {
+                         typedef itk::ImageToVTKImageFilter<  TImage > ConnectorType;
+                         ConnectorType::Pointer          connector = ConnectorType::New();
+             for(unsigned int i = 0 ;i < m_Iresults.size(); i++)
+                     {
+                                       connector->SetInput(m_Iresults[i]);
+                                       connector->GetImporter()->SetDataScalarTypeToUnsignedChar();
+                                       connector->Update();
+                                       vtkImageData *im = vtkImageData::New();
+                                       im->ShallowCopy(connector->GetOutput());
+                                       im->Update();
+                                       m_Vresults.push_back(im);
+                    }
+                 }
+         }
+
+
+
+         template <typename TImage> 
+         void WxISimpleDlg<TImage>::split4Din3Dvtk(const std::string &i_dir)
+         {
+                       if ((m_Iresults).size() != 0)
+                       {
+                           typename TImage::Pointer image = m_Iresults[0];
+                       
+                                if(image->GetImageDimension() == 4)
+                                {
+                                                       boost::any a1(image);
+                                                       m_AnyImages.push_back(a1);
+                                        // size of fourth dimension 
+                                        int dsize = image->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 = i_dir;
+                                        format += "/image%03d.mhd";
+                                        namesGenerator->SetSeriesFormat( format.c_str() );
+                                       
+                                        const std::vector<std::string> names = namesGenerator->GetFileNames();
+                                        seriesWriter->SetFileNames( names );
+                                        seriesWriter->SetInput(image);
+                                        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;
+                                       }
+                                }
+                         }
+
+         }
 
  }// namespace end
 
index 201c3dc19e71b13dae1c5b3baa6136f10c295906..21555d874e8d2b1709efb6f93ed573cace50ab2b 100644 (file)
@@ -7,7 +7,7 @@
 #include "itkImageToVTKImageFilter.h"
 #include <creaWx.h>
 #include <itkImageFileReader.h>
-
+#include <boost/any.hpp>
 namespace creaImageIO
 {
  /**
@@ -50,8 +50,10 @@ namespace creaImageIO
                   void split4Din3Dvtk(const std::string &i_dir);
                   void split3Din3Dvtk( );
                   void set(bool i_dicom){m_dicom= i_dicom;}
+                  std::vector <boost::any>& getAnyImages(){ return m_AnyImages;}
        private:
 
+               std::vector<boost::any> m_AnyImages;
                std::vector<std::string> m_exts;
                std::string namedescp; 
                std::string namedb;
index 4637c6e2c99faa33b92b81c979d2e694363ac1cf..54c14e3fb8f21963d6813ff4eb88687a6c2d4e53 100644 (file)
@@ -6,7 +6,8 @@
 #include <iostream>
 
 #include <creaImageIOTreeDescriptor.h>
-
+using namespace creaImageIO;
+using namespace creaImageIO::tree;
 /**
 * TestDcmDescriptor
 * \brief Read a descriptor file and check its content.