From: Eduardo DAVILA Date: Mon, 7 Jun 2021 15:54:39 +0000 (+0200) Subject: #3320 ReadImages box X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaImageIO.git;a=commitdiff_plain;h=3aefe04f265639ae28b0db125d2eab5c1b2ac20a #3320 ReadImages box --- diff --git a/bbtk/src/bbcreaImageIOReadImages.cxx b/bbtk/src/bbcreaImageIOReadImages.cxx new file mode 100644 index 0000000..33a7839 --- /dev/null +++ b/bbtk/src/bbcreaImageIOReadImages.cxx @@ -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 = " < 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 index 0000000..cb2079e --- /dev/null +++ b/bbtk/src/bbcreaImageIOReadImages.h @@ -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 + +namespace bbcreaImageIO +{ + + +typedef std::map 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); + BBTK_DECLARE_INPUT(LstNameImages,std::vector); + BBTK_DECLARE_OUTPUT(Out,vtkImageData*); + BBTK_DECLARE_OUTPUT(OutImages,std::vector); + 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,""); + BBTK_INPUT(ReadImages,LstNameImages,"List path to images",std::vector,""); + + BBTK_OUTPUT(ReadImages,Out,"Output Image",vtkImageData*,""); + BBTK_OUTPUT(ReadImages,OutImages,"List of Output Image",std::vector,""); + 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__ + diff --git a/src/creaImageIOSimpleView.cpp b/src/creaImageIOSimpleView.cpp index 43bbdf0..0219927 100644 --- a/src/creaImageIOSimpleView.cpp +++ b/src/creaImageIOSimpleView.cpp @@ -146,4 +146,104 @@ namespace creaImageIO } return bresult; } + + + vtkImageData* SimpleView::getVolumeSelected( std::vector 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 ; sliceGetScalarPointer(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::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; + } + + } diff --git a/src/creaImageIOSimpleView.h b/src/creaImageIOSimpleView.h index 24fc81e..4cc3d82 100644 --- a/src/creaImageIOSimpleView.h +++ b/src/creaImageIOSimpleView.h @@ -43,26 +43,19 @@ namespace creaImageIO public: /// Ctor SimpleView(){} - ///Dtor ~SimpleView(){} - /// read file(s) and return a vector of vtkImageData bool readFile( std::vector i_filenames, // in information names std::vector i_attr, // in information attributes names std::vector > &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 i_attr, // in information attributes names std::vector > &i_imgAttr, // out information attributes names-values std::vector &i_imgs); // out information vtkImageData - - - - - }; + vtkImageData* getVolumeSelected( std::vector images); + }; } - #endif diff --git a/src/creaImageIOWxSimpleDlg.cpp b/src/creaImageIOWxSimpleDlg.cpp index 226f55f..5ee7649 100644 --- a/src/creaImageIOWxSimpleDlg.cpp +++ b/src/creaImageIOWxSimpleDlg.cpp @@ -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 ; sliceGetScalarPointer(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::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 diff --git a/src/creaImageIOWxSimpleDlg.h b/src/creaImageIOWxSimpleDlg.h index 2ccd2e3..499e256 100644 --- a/src/creaImageIOWxSimpleDlg.h +++ b/src/creaImageIOWxSimpleDlg.h @@ -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 m_results; std::vector< std::map > m_resultsDicomAtr; std::vector m_attrDicomTags; // DXXXX_YYYY DAAAA_BBBB ... - - std::vector m_resultsInfo; - + std::vector m_resultsInfo; }; }