]> Creatis software - creaImageIO.git/commitdiff
#3123creaImageIO Bug New Normal - branch changestoITK3and4
authorEduardo DAVILA <davila@localhost.localdomain>
Tue, 5 Sep 2017 09:59:32 +0000 (11:59 +0200)
committerEduardo DAVILA <davila@localhost.localdomain>
Tue, 5 Sep 2017 09:59:32 +0000 (11:59 +0200)
bbtk/src/bbcreaImageIOGetDicomAttributesFromMaps.h
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.cxx
bbtk/src/bbcreaImageIOItkImagesChooserDialogBox.h
src/creaImageIOWxAnySimpleDlg.cpp
src/creaImageIOWxAnySimpleDlg.h
src/creaImageIOWxGimmickReaderDialog.cpp

index 3b98bfd948d83aeb2d7f43046ccf9ce5adce64ae..d099ff2c1e1c91c259b0fdfaca4185c413d7873d 100644 (file)
@@ -32,11 +32,11 @@ class bbcreaImageIO_EXPORT GetDicomAttributesFromMaps
 
 BBTK_BEGIN_DESCRIBE_BLACK_BOX(GetDicomAttributesFromMaps,bbtk::AtomicBlackBox);
 BBTK_NAME("GetDicomAttributesFromMaps");
-BBTK_AUTHOR("Info-Dev, Eduardo DAVIL");
+BBTK_AUTHOR("Info-Dev, Eduardo DAVILA");
 BBTK_DESCRIPTION("eduardo.davila[at]creatis.insa-lyon.fr -");
 BBTK_CATEGORY("empty");
   BBTK_INPUT(GetDicomAttributesFromMaps,In,"Vector of maps with DICOM attributes",std::vector< mapString >,"");
-  BBTK_INPUT(GetDicomAttributesFromMaps,KeyDicom,"Key DICOM",std::string ,"");
+  BBTK_INPUT(GetDicomAttributesFromMaps,KeyDicom,"Key DICOM ex: D0028_0030 ",std::string ,"");
   BBTK_OUTPUT(GetDicomAttributesFromMaps,Out,"Vector of the attribute asked.",std::vector <std::string>,"");
 BBTK_END_DESCRIBE_BLACK_BOX(GetDicomAttributesFromMaps);
 //===== 
index 9c77a1de377b1cd7c416414c1b04e61aa985cd4b..434b71972c177a65d4b494bac8ad207febb88de3 100644 (file)
 #include "bbcreaImageIOItkImagesChooserDialogBox.h"
 #include "bbcreaImageIOPackage.h"
 
+#include "itkImage.h"
+#include "itkImportImageFilter.h"
+
+/*
 // -------------------------------------------------------------------------
 // LFV: avoid itk::Concept check on 4d or superior images
 #define BBCREAIMAGEIO_ChooserDlg_Template( t, ty, di )            \
-  if( t == typeid( itk::Image< ty, di > ) )                       \
+  if( t == typeid( itk::Image< ty, di >* ) )                       \
   {                                                               \
     this->Export< itk::Image< ty, di > >( );                      \
     this->ExportVTK< itk::Image< ty, di > >( );                   \
   }
+*/
+
+// -------------------------------------------------------------------------
+// LFV: avoid itk::Concept check on 4d or superior images
+#define BBCREAIMAGEIO_ChooserDlg_Template( t, ty, di )            \
+  if( t == typeid( itk::Image< ty, di >* ) )                      \
+  {                                                               \
+    this->Export< ty , di  >( );                      \
+    this->ExportVTK< itk::Image< ty, di > >( );                   \
+  }
+
+
 // -------------------------------------------------------------------------
 
 namespace bbcreaImageIO
@@ -97,27 +113,91 @@ void ItkImagesChooserDialogBox::Process()
     delete dlg;
 }
 
-template <class TImage>
+
+//template <class TImage>
+template <typename  ty, size_t di>
 void ItkImagesChooserDialogBox::Export()
 {
-   if (dlg->getImagesSelected().size() == 1)
-   { 
+       typedef itk::Image<ty,di> TImage;
+
+printf("EED ItkImagesChooserDialogBox::Export Start \n");
+       if (dlg->getImagesSelected().size() == 1)
+       { 
+printf("EED ItkImagesChooserDialogBox::Export 1\n");
                bbSetOutputOut( dlg->getTemplatedImagesSelected<TImage>().front().GetPointer() ); 
-   } 
-   else if (dlg->getImagesSelected().size() > 1)
-   { 
-      OutputImagesITKType outVect;
-
-      typename  std::vector<typename TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected<TImage>();
-      typename std::vector<typename TImage::Pointer>::iterator it = tempImgs.begin();
-      for(;it != tempImgs.end(); ++it)
-      {
-         outVect.push_back( (*it).GetPointer() );
-      }
-      bbSetOutputOutIImages( outVect); 
-   } 
-   else
-   {
+       } else if (dlg->getImagesSelected().size() > 1){ 
+printf("EED ItkImagesChooserDialogBox::Export 2\n");
+               OutputImagesITKType outVect;
+               typename  std::vector<typename TImage::Pointer> tempImgs= dlg->getTemplatedImagesSelected<TImage>();
+               typename std::vector<typename TImage::Pointer>::iterator it = tempImgs.begin();
+               for(;it != tempImgs.end(); ++it)
+               {
+                       outVect.push_back( (*it).GetPointer() );
+               } // for
+               bbSetOutputOutIImages( outVect); 
+
+//EED creater one 3D image from 2D list
+//             const unsigned int Dimension = 3;
+//             typedef itk::RGBPixel< unsigned char > RGBPixelType;
+//             typedef itk::Image< RGBPixelType, Dimension > RGBImageType;
+//             typedef itk::ImportImageFilter< RGBPixelType, Dimension > ImportFilterType;
+
+//             typedef itk::RGBPixel< ty > RGBPixelType;
+               typedef  ty RGBPixelType;
+               typedef itk::ImportImageFilter< ty , di > ImportFilterType;
+     typename ImportFilterType::Pointer importFilter = ImportFilterType::New();
+
+
+               typename TImage::SizeType imsize;
+//             imsize[0] = img.width();
+//             imsize[1] = img.height();
+               imsize[0] = tempImgs[0].GetPointer()->GetLargestPossibleRegion().GetSize()[0];
+               imsize[1] = tempImgs[0].GetPointer()->GetLargestPossibleRegion().GetSize()[1];
+               imsize[2] = tempImgs.size();
+printf("EED ItkImagesChooserDialogBox::Export 2.10\n");
+
+               typename ImportFilterType::IndexType start;
+               start.Fill( 0 );
+               typename ImportFilterType::RegionType region;
+               region.SetIndex( start );
+               region.SetSize( imsize );
+               importFilter->SetRegion( region );
+
+//             const itk::SpacePrecisionType origin[ di ] = { 0.0, 0.0, 0.0 };
+               const itk::SpacePrecisionType origin[ 3 ] = { 0.0, 0.0, 0.0 };
+               importFilter->SetOrigin( origin );
+
+//             const itk::SpacePrecisionType spacing[ di ] = { 1.0, 1.0, 1.0 };
+               const itk::SpacePrecisionType spacing[ 3 ] = { 1.0, 1.0, 1.0 };
+               importFilter->SetSpacing( spacing );
+               const unsigned long int numberOfPixels2D = imsize[0]*imsize[1];
+               const unsigned long int numberOfPixels3D = imsize[0]*imsize[1]*imsize[2];
+
+               RGBPixelType * localBuffer      = new RGBPixelType[ numberOfPixels3D ];
+               RGBPixelType * tmpLocalBuffer   = localBuffer;
+printf("EED ItkImagesChooserDialogBox::Export 2.20\n");
+
+               it = tempImgs.begin();
+               for(;it != tempImgs.end(); ++it)
+               {               
+printf("EED ItkImagesChooserDialogBox::Export 2.30\n");
+                       memcpy(tmpLocalBuffer, (*it).GetPointer()->GetBufferPointer(), numberOfPixels2D);
+                       tmpLocalBuffer = tmpLocalBuffer + numberOfPixels2D;
+               } // for
+
+               const bool importImageFilterWillOwnTheBuffer = true;
+               importFilter->SetImportPointer( localBuffer , numberOfPixels3D , importImageFilterWillOwnTheBuffer );
+importFilter->Update();
+importFilter->Register();
+printf("EED ItkImagesChooserDialogBox::Export 2.40\n");
+
+//         bbSetOutputOut( (*tempImgs.begin()).GetPointer() ); 
+//         bbSetOutputOut( importFilter->GetOutput().unsafe_get<TImage*>() ); 
+           bbSetOutputOut( importFilter->GetOutput() ); 
+printf("EED ItkImagesChooserDialogBox::Export 2.50\n");
+
+   } else {
+printf("EED ItkImagesChooserDialogBox::Export 3\n");
       // warning: passing NULL to non-pointer 
       //bbSetOutputOut( NULL);
       bbSetOutputOut(0); // JPR
@@ -131,10 +211,17 @@ void ItkImagesChooserDialogBox::Export()
      //   reader->Update(); 
         //reader->GetOutput()->Register();
      //  this->bbSetOutputOut(reader->GetOutput());
+
+printf("EED ItkImagesChooserDialogBox::Export End \n");
+
 }
+
+
 template <class TImage>
 void ItkImagesChooserDialogBox::ExportVTK()
 {
+printf("EED ItkImagesChooserDialogBox::ExportVTK Start \n");
+
        // BBTK can support only a vector with same dimensions image.
         if (dlg->getDims().front() < 4)
         { 
@@ -145,40 +232,35 @@ void ItkImagesChooserDialogBox::ExportVTK()
                        dlg->split3Din3Dvtk<TImage>( (*it) );
                  }
                  bbSetOutputOutVImages( dlg->getVtkImagesSelected() ); 
-        } 
-        else if (dlg->getDims().front() == 4)
-        { 
+        } else if (dlg->getDims().front() == 4) { 
                // To Test
                 //  dlg->split4Din3Dvtk("d:/temp2");
                 // bbSetOutputOutVImages( dlg->getVtkImagesSelected()); 
-         } 
-        else
-        {
-                 // NOT IMPLEMENTED YET FOR DIMENSIONS > 4
-       
-        }
-        
+         } else {
+                 // NOT IMPLEMENTED YET FOR DIMENSIONS > 4     
+        } // if dlg
+printf("EED ItkImagesChooserDialogBox::ExportVTK End \n");
 }
+
 //===== 
 // 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
+
+// EO namespace bbcreaImageIO
index fa1d9106742b27a8d1609938d79bedd597f5c5fe..b4923903438d91be628acfb1466026dfd64b18af 100644 (file)
@@ -75,7 +75,9 @@ class bbcreaImageIO_EXPORT ItkImagesChooserDialogBox
 
     private:
     // Template read method 
-    template<class TImage> void Export();
+
+//EED    template<class TImage> void Export();
+template <typename  ty, size_t di> void Export();
 
        // Template export vtk Images
        template<class TImage> void ExportVTK();
index 58b7d95c0fd57e42fed654352c35bd22bde14f6f..11d5fa92d60a79d6b4e5436c66ada2cd8deaeaa6 100644 (file)
@@ -108,27 +108,31 @@ 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)
       {
+printf("EED WxAnySimpleDlg::OnReadDirectory Start\n");
          int resultShowModal;
          bool bvalid = false;
          long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
@@ -138,33 +142,58 @@ namespace creaImageIO
          if ( resultShowModal==wxID_OK )
          {  
             std::string path = crea::wx2std(dirDlg->GetPath());
+printf("EED WxAnySimpleDlg::OnReadDirectory path %s\n", path.c_str() );
+
+/*
             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->path().filename().string().substr(itr->path().filename().string().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->path().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() );
+                                 cout << "   " << *it << '\n';
+                               }
+
+
+
+
+         } // if OK
          SetReturnCode( resultShowModal );
 //         Close();
          EndModal( resultShowModal );
+printf("EED WxAnySimpleDlg::OnReadDirectory End\n");
+
       }
 
 //////////////////////////////////////////////////////////////////////
@@ -236,9 +265,13 @@ namespace creaImageIO
             return imageIO->GetNumberOfDimensions();
      }
 
+
      void WxAnySimpleDlg::readImg(const std::string &i_name)
      {
           size_t dims = getNumberOfDimensions(i_name);
+
+printf("EED WxAnySimpleDlg::readImg dims=%d \n",dims);
+
           //const std::type_info  *type= &getType(i_name);
           switch(dims)
           {
@@ -345,6 +378,7 @@ namespace creaImageIO
               }
               else
               {
+                               printf("EED WxAnySimpleDlg::readImg Not type found   for DIM 3 \n");
                   //????FCY, so what the type????
               }
               break;
@@ -487,6 +521,7 @@ namespace creaImageIO
                }
                else
                {
+                               printf("EED WxAnySimpleDlg::readImg Not type found   for DIM 4 \n");
                   //????FCY, so what the type????
                }
                break;
index 51674d3f6ac4b5136f0e919ee2327ea2793e942f..df655a4ce7369a28490eda436f3d81fbb911728a 100644 (file)
@@ -102,13 +102,13 @@ namespace creaImageIO
              for(; it != m_AnyImages.end(); it++)
              {
                  imgs.push_back(boost::any_cast<TImage*> (*it));
-             }
+             } // for
              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);
@@ -119,14 +119,11 @@ namespace creaImageIO
                        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        
         std::vector</*const*/ size_t>           m_AnyDims;   //comment out const JPR
         std::vector</*const*/ std::type_info *> m_AnyType;   //comment out const JPR
@@ -137,7 +134,6 @@ namespace creaImageIO
         wxString infoimage;
         std::string m_dir;
 
-
        bool m_dicom;
         /// interface to read data
         SimpleView m_view;
@@ -149,6 +145,5 @@ namespace creaImageIO
         const std::type_info & getType(const std::string &i_name);
     };
 
-
 }// namespace creaImageIO
 #endif //__creaImageWxAnySimpleDlg_h_INCLUDED__
index bce7fc7f4ca08de141d1f1d87bd33b49d4e551e9..1dff6b3fd0246dd09fa8e90d14a8012aec7dca2a 100644 (file)
@@ -80,8 +80,7 @@ namespace creaImageIO
                                threads);
       mView->Initialize();
           // Connect the AddProgress callback
-      mView->ConnectValidationObserver
-               ( boost::bind( &WxGimmickReaderDialog::OnValid , this, _1 ) );
+      mView->ConnectValidationObserver( boost::bind( &WxGimmickReaderDialog::OnValid , this, _1 ) );
     }
     catch (crea::Exception e)
     {