]> Creatis software - creaImageIO.git/commitdiff
#3320 ReadImages box
authorEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 7 Jun 2021 15:54:39 +0000 (17:54 +0200)
committerEduardo DAVILA <eduardo.davila@creatis.insa-lyon.fr>
Mon, 7 Jun 2021 15:54:39 +0000 (17:54 +0200)
bbtk/src/bbcreaImageIOReadImages.cxx [new file with mode: 0644]
bbtk/src/bbcreaImageIOReadImages.h [new file with mode: 0644]
src/creaImageIOSimpleView.cpp
src/creaImageIOSimpleView.h
src/creaImageIOWxSimpleDlg.cpp
src/creaImageIOWxSimpleDlg.h

diff --git a/bbtk/src/bbcreaImageIOReadImages.cxx b/bbtk/src/bbcreaImageIOReadImages.cxx
new file mode 100644 (file)
index 0000000..33a7839
--- /dev/null
@@ -0,0 +1,86 @@
+//===== 
+// 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 "bbcreaImageIOReadImages.h"
+#include "bbcreaImageIOPackage.h"
+
+#include "creaImageIOSimpleView.h"
+
+namespace bbcreaImageIO
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaImageIO,ReadImages)
+BBTK_BLACK_BOX_IMPLEMENTATION(ReadImages,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 ReadImages::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+//   Here we simply set the input 'In' value to the output 'Out'
+//   And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+//    void bbSet{Input|Output}NAME(const TYPE&)
+//    const TYPE& bbGet{Input|Output}NAME() const 
+//    Where :
+//    * NAME is the name of the input/output
+//      (the one provided in the attribute 'name' of the tag 'input')
+//    * TYPE is the C++ type of the input/output
+//      (the one provided in the attribute 'type' of the tag 'input')
+//    bbSetOutputOut( bbGetInputIn() );
+//    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+  
+       std::vector<vtkImageData*>                                                      mResults;
+       VectorMapInfoDicom                                                                      mResultsDicomAtr;
+       creaImageIO::SimpleView                                                         mView;
+       if( mView.readFile(bbGetInputLstNameImages() , bbGetInputDicomTags() , mResultsDicomAtr , mResults)==true )
+       {
+               bbSetOutputOut( mView.getVolumeSelected( mResults ) );
+               bbSetOutputOutImages( mResults  );
+               bbSetOutputDicomInfo( mResultsDicomAtr  );
+       } else {
+               bbSetOutputOut( NULL );
+               printf("EED Warning! ReadImages::Process   Files(s) not found. \n");
+       }// if readFile
+}
+//===== 
+// 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 ReadImages::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+//   bbSetInputIn(0);
+  
+}
+//===== 
+// 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 ReadImages::bbUserInitializeProcessing()
+{
+
+//  THE INITIALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should allocate the internal/output pointers 
+//    if any 
+
+  
+}
+//===== 
+// 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 ReadImages::bbUserFinalizeProcessing()
+{
+
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any
+  
+}
+}
+// EO namespace bbcreaImageIO
+
+
diff --git a/bbtk/src/bbcreaImageIOReadImages.h b/bbtk/src/bbcreaImageIOReadImages.h
new file mode 100644 (file)
index 0000000..cb2079e
--- /dev/null
@@ -0,0 +1,60 @@
+//===== 
+// 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 __bbcreaImageIOReadImages_h_INCLUDED__
+#define __bbcreaImageIOReadImages_h_INCLUDED__
+
+#include "bbcreaImageIO_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+#include <vtkImageData.h>
+
+namespace bbcreaImageIO
+{
+
+
+typedef std::map<std::string, std::string> MapInfoDicom;
+typedef std::vector< MapInfoDicom > VectorMapInfoDicom;
+
+class bbcreaImageIO_EXPORT ReadImages
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(ReadImages,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)
+//===== 
+  BBTK_DECLARE_INPUT(DicomTags,std::vector<std::string>);
+  BBTK_DECLARE_INPUT(LstNameImages,std::vector<std::string>);
+  BBTK_DECLARE_OUTPUT(Out,vtkImageData*);
+  BBTK_DECLARE_OUTPUT(OutImages,std::vector<vtkImageData*>);
+  BBTK_DECLARE_OUTPUT(DicomInfo,VectorMapInfoDicom);
+  BBTK_PROCESS(Process);
+  void Process();
+//===== 
+// 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(ReadImages,bbtk::AtomicBlackBox);
+  BBTK_NAME("ReadImages");
+  BBTK_AUTHOR("InfoDev");
+  BBTK_DESCRIPTION("No Description.");
+  BBTK_CATEGORY("empty");
+
+  BBTK_INPUT(ReadImages,DicomTags,"Dicom Tags (vector of Dicom tags ex: D0028_0030  D0020_0037)",std::vector<std::string>,"");
+  BBTK_INPUT(ReadImages,LstNameImages,"List path to images",std::vector<std::string>,"");
+
+  BBTK_OUTPUT(ReadImages,Out,"Output Image",vtkImageData*,"");
+  BBTK_OUTPUT(ReadImages,OutImages,"List of Output Image",std::vector<vtkImageData*>,"");
+  BBTK_OUTPUT(ReadImages,DicomInfo,"vector of maps of Dicom tags",VectorMapInfoDicom,"");
+  
+BBTK_END_DESCRIBE_BLACK_BOX(ReadImages);
+//===== 
+// 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 // __bbcreaImageIOReadImages_h_INCLUDED__
+
index 43bbdf088e346d3a88ed435fcd0199d7eec7af71..0219927b6bdbb4a654a222abfa66aea9dda2c5a7 100644 (file)
@@ -146,4 +146,104 @@ namespace creaImageIO
                        }
                        return bresult;
        }
+
+       
+       vtkImageData* SimpleView::getVolumeSelected( std::vector<vtkImageData*> lstImages)
+       {
+               vtkImageData *result;
+
+//        creaImageIO::WxSimpleDlg dlg(0,crea::std2wx(bbGetInputTitle()),"localdatabase_Descriptor.dscp","Local Database"); 
+//             dlg.SetAttrDicomTags( bbGetInputDicomTags() );
+//             dlg.ShowModal(); 
+//             bbSetOutputDicomInfo( dlg.getDicomInfoImagesSelected() );
+
+               if (lstImages.size()!=0){ 
+//               bbSetOutputFileName( std::string( dlg.getInfoImage().mb_str() ) );
+                 if(lstImages.size() ==1)
+                 {
+                       result = lstImages[0] ;  
+                 } else {
+                               // FCY: it will be a big problem if we have several kind of data in the same folder.
+                               // creation of a huge vtkImageData!!!!
+                               vtkImageData* first = lstImages[0];
+                               int dim[3];
+                               first->GetDimensions(dim);
+                               if (dim[2]==1)
+                               {
+                                       vtkImageData *out = vtkImageData::New();
+                                       int ext[6];
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+                                       first->GetWholeExtent(ext); 
+#else
+                                       first->GetExtent(ext); 
+#endif
+                                       if(ext[5] == 0)
+                                       {
+                                          ext[5] = lstImages.size()-1;
+                                        } else {
+                                               ext[5] = ext[5] * lstImages.size()-1; // to deal with multiframes 
+                                       } // ext
+                                       out->SetExtent(ext);
+                                       double spac[3];
+                                       first->GetDimensions(dim);
+                                       first->GetSpacing(spac);
+                                       if (spac[0]==spac[1])
+                                       {
+                                               spac[2]=spac[0];  
+                               }
+                                       out->SetSpacing(spac);
+                                       out->SetDimensions(dim[0], dim[1], lstImages.size() );
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+
+                                       out->SetScalarType(first->GetScalarType());
+                                       out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
+                                       out->AllocateScalars();
+                                       out->Update();
+#else
+                                       out->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
+#endif
+
+
+                                       unsigned long imsize = dim[0] * dim[1];
+                                       imsize = imsize * dim[2];  // deal with multiframes here
+                                       // differents formats char , short, etc...
+                                       // differents components 1..3  ex. jpg ->RGB 3
+                                       imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
+                               int slice,sizeImageVector=lstImages.size();
+                                       for (slice=0 ; slice<sizeImageVector ; slice++)
+                                       {
+                                               vtkImageData *img = lstImages[slice];
+                                               memcpy(out->GetScalarPointer(0,0,slice), img->GetScalarPointer(0,0,0), imsize);
+                                               //img->Delete();
+                                       } // for slice  
+                                       out->Modified();
+//EED This is NOT working. The iteration over the pointer vtkImageData
+//                             int slice=0;
+//                             std::vector<vtkImageData*>::iterator it;
+//                             for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) 
+//                                     {
+//                                               memcpy(out->GetScalarPointer(0,0,slice), (*it)->GetScalarPointer(0,0,0), imsize);
+//                                               slice++;
+//                                     }       
+//                             //for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) 
+//                                     //{
+//                                     //              (*it)->Delete();
+//                                     //}
+
+                                       result =out;
+
+                               } else {
+                                       result = first;
+                               } // dim
+                       } // if getImagesSelected size
+               } else { 
+               result = NULL;  
+               } // getImagesSelected().size()!=0
+                       result->Modified();
+               return result;
+       }
+       
+       
 }
index 24fc81eb89d17df4dd3bb0c5d0bb9dae29481f30..4cc3d824ad89419af65e68ec5e3042b734e569c7 100644 (file)
@@ -43,26 +43,19 @@ namespace creaImageIO
        public:
                /// Ctor
                SimpleView(){}
-
                ///Dtor
                ~SimpleView(){}
-               
                /// read file(s) and return a vector of vtkImageData 
                bool readFile( std::vector<std::string> i_filenames,                                                                                            // in information names
                                                                                std::vector<std::string> i_attr,                                                                                        // in information attributes names
                                                                                std::vector<std::map <std::string,std::string> > &i_imgAttr,    // out information attributes names-values
                                                                                std::vector< vtkImageData *> &i_img);                                                                   // out information vtkImageData
-
                /// read a directory and return a vector of vtkImageData 
                bool readDirectory(     const std::string i_pathname,                                                                                   // in information names
                                                                        std::vector<std::string> i_attr,                                                                                        // in information attributes names
                                                                        std::vector<std::map <std::string , std::string> > &i_imgAttr,  // out information attributes names-values
                                                                        std::vector<vtkImageData *> &i_imgs);                                                                   // out information vtkImageData
-
-
-
-
-       };
+               vtkImageData* getVolumeSelected( std::vector<vtkImageData*> images);
+       };      
 }
-
 #endif
index 226f55fafddaca2251545fc7dea6fdce75b7b1cf..5ee7649e489a5758ada7efb056ca598e55318b11 100644 (file)
@@ -214,104 +214,8 @@ namespace creaImageIO
 //-----------------------------------------------------------------------------   
        vtkImageData*  WxSimpleDlg::getVolumeSelected()
        {
-               vtkImageData *result;
-
-//        creaImageIO::WxSimpleDlg dlg(0,crea::std2wx(bbGetInputTitle()),"localdatabase_Descriptor.dscp","Local Database"); 
-//             dlg.SetAttrDicomTags( bbGetInputDicomTags() );
-//             dlg.ShowModal(); 
-//             bbSetOutputDicomInfo( dlg.getDicomInfoImagesSelected() );
-
-               if (getImagesSelected().size()!=0){ 
-//               bbSetOutputFileName( std::string( dlg.getInfoImage().mb_str() ) );
-                 if(getImagesSelected().size() ==1)
-                 {
-                       result = getImagesSelected()[0] ;  
-                 } else {
-                               // FCY: it will be a big problem if we have several kind of data in the same folder.
-                               // creation of a huge vtkImageData!!!!
-                               vtkImageData* first = getImagesSelected()[0];
-                               int dim[3];
-                               first->GetDimensions(dim);
-                               if (dim[2]==1)
-                               {
-                                       vtkImageData *out = vtkImageData::New();
-                                       int ext[6];
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
-                                       first->GetWholeExtent(ext); 
-#else
-                                       first->GetExtent(ext); 
-#endif
-                                       if(ext[5] == 0)
-                                       {
-                                          ext[5] = getImagesSelected().size()-1;
-                                        } else {
-                                               ext[5] = ext[5] * getImagesSelected().size()-1; // to deal with multiframes 
-                                       } // ext
-                                       out->SetExtent(ext);
-                                       double spac[3];
-                                       first->GetDimensions(dim);
-                                       first->GetSpacing(spac);
-                                       if (spac[0]==spac[1])
-                                       {
-                                               spac[2]=spac[0];  
-                               }
-                                       out->SetSpacing(spac);
-                                       out->SetDimensions(dim[0], dim[1], getImagesSelected().size() );
-//EED 2017-01-01 Migration VTK7
-#if VTK_MAJOR_VERSION <= 5
-
-                                       out->SetScalarType(first->GetScalarType());
-                                       out->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents());
-                                       out->AllocateScalars();
-                                       out->Update();
-#else
-                                       out->AllocateScalars(first->GetScalarType(),first->GetNumberOfScalarComponents());
-#endif
-
-
-                                       unsigned long imsize = dim[0] * dim[1];
-                                       imsize = imsize * dim[2];  // deal with multiframes here
-                                       // differents formats char , short, etc...
-                                       // differents components 1..3  ex. jpg ->RGB 3
-                                       imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents();
-                               int slice,sizeImageVector=getImagesSelected().size();
-                                       for (slice=0 ; slice<sizeImageVector ; slice++)
-                                       {
-                                               vtkImageData *img = getImagesSelected()[slice];
-                                               memcpy(out->GetScalarPointer(0,0,slice), img->GetScalarPointer(0,0,0), imsize);
-                                               //img->Delete();
-                                       } // for slice  
-                                       out->Modified();
-//EED This is NOT working. The iteration over the pointer vtkImageData
-//                             int slice=0;
-//                             std::vector<vtkImageData*>::iterator it;
-//                             for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) 
-//                                     {
-//                                               memcpy(out->GetScalarPointer(0,0,slice), (*it)->GetScalarPointer(0,0,0), imsize);
-//                                               slice++;
-//                                     }       
-//                             //for (it=dlg.getImagesSelected().begin(); it!=dlg.getImagesSelected().end(); ++it) 
-//                                     //{
-//                                     //              (*it)->Delete();
-//                                     //}
-
-                                       result =out;
-
-                               } else {
-                                       result = first;
-                               } // dim
-                       } // if getImagesSelected size
-               } else { 
-               result = NULL;  
-               } // getImagesSelected().size()!=0
-
-                       result->Modified();
-               return result;
-
-               }
-
-
+               return m_view.getVolumeSelected( getImagesSelected() );
+       }
 
 } // namespace creaImageIO
 
index 2ccd2e35b5cdf10d7753d249d0dd6e4c3ed0f184..499e25652deab85ded4d8df35f6070192928c7e4 100644 (file)
@@ -10,7 +10,7 @@
 #  This software is governed by the CeCILL-B license under French law and 
 #  abiding by the rules of distribution of free software. You can  use, 
 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
-#  license as circulated by CEA, CNRS and INRIA at the following URL 
+#  license as circulated by CEA, CNRS and INRIA at the following URL m_view
 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
 #  or in the file LICENSE.txt.
 #
@@ -80,16 +80,12 @@ namespace creaImageIO
                std::string                                                                             namedb;
                wxString                                                                                        infoimage;
                wxString                                                                                        infoimageSource;
-
                /// interface to read data
                SimpleView                                                                                      m_view;
-
                /// vtkImageData vector
                std::vector<vtkImageData*>                                                      m_results;
                std::vector< std::map<std::string,std::string> >        m_resultsDicomAtr;
                std::vector<std::string>                                                        m_attrDicomTags;    // DXXXX_YYYY DAAAA_BBBB ...
-
-               std::vector<creaImageIO::OutStrGimmick> m_resultsInfo;
-               
+               std::vector<creaImageIO::OutStrGimmick>                         m_resultsInfo;
        };
 }