From: Frederic Cervenansky Date: Wed, 12 May 2010 14:00:10 +0000 (+0000) Subject: new Output format and structure for Gimmick. Based on creaImageIO Output document... X-Git-Tag: CREATOOLS.2-0-3~33 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=creaImageIO.git;a=commitdiff_plain;h=bf3660569b1baa8be10fc708f595efc66afe3334 new Output format and structure for Gimmick. Based on creaImageIO Output document discuted(?) with Edouardo and Jean Pierre : - choice of output size (2D, 3D) and format - sorting of files based on XML Model (for future dicom sup 118) - associated informations with selected files --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 49b1019..0432a40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,10 +33,19 @@ SET(USE_GDCM_VTK ON) SET(USE_VTK ON) SET(USE_ITK OFF) SET(USE_BOOST ON) -SET(USE_WXWIDGETS ON) - -OPTION(USE_GDCM "use gdcm" ON) -OPTION(USE_GDCM2 "use gdcm2" OFF) +OPTION(USE_WXWIDGETS "Use WxWidgets GUI" ON) +OPTION(USE_QT4 "USE WxWidgets GUI" OFF) +OPTION(USE_XERCES "USE Xerces if you want to use an beta version of outputModel" OFF) + +IF(USE_QT4) + IF(USE_WXWIDGETS) + MESSAGE(STATUS "CANNOT USE QT WXWIDGETS IN SAME TIME") + ENDIF(USE_WXWIDGETS) +ENDIF(USE_QT4) + + +OPTION(USE_GDCM ON) +OPTION(USE_GDCM2 OFF) MESSAGE(STATUS "GDCM LIB ....= ${GDCM_LIBRARIES}") IF(USE_GDCM2) OPTION(USE_GDCM_ANOM "use gdcm2 anonymizer tool" OFF) diff --git a/appli/TestWxGimmickReaderDialog/main.cxx b/appli/TestWxGimmickReaderDialog/main.cxx index 33157d9..797f46e 100644 --- a/appli/TestWxGimmickReaderDialog/main.cxx +++ b/appli/TestWxGimmickReaderDialog/main.cxx @@ -6,7 +6,7 @@ #include -// + //#pragma comment(lib, "creaImageIO.lib") //#pragma comment(lib, "DelayImp.lib") // @@ -49,7 +49,6 @@ bool myApp::OnInit( ) int output_dim = _3D; int threads = 1; - creaImageIO::WxGimmickReaderDialog w( 0, @@ -87,6 +86,18 @@ bool myApp::OnInit( ) std::vector images; w.GetSelectedImages(images,3); + + + + + std::vector out; + std::vector attr; + //attr.push_back("ALL"); + attr.push_back("D0008_1070"); + w.getSelected(out, attr,true,""); + + + // images[1]->UpdateInformation(); /* vtkMetaImageReader *r= vtkMetaImageReader::New(); r->SetFileName("c:\\toto.mhd"); @@ -137,5 +148,3 @@ bool myApp::OnInit( ) std::cout << "$$$$$$$$$$$$$$$$$$$$ main ended "< &infos, std::vector i_attr){} protected: /// Set the reader's name diff --git a/src/creaImageIODicomImageReader2.cpp b/src/creaImageIODicomImageReader2.cpp index 7361034..713655b 100644 --- a/src/creaImageIODicomImageReader2.cpp +++ b/src/creaImageIODicomImageReader2.cpp @@ -67,8 +67,7 @@ namespace creaImageIO v.push_back("dcm"); v.push_back(""); } - //===================================================================== - + //======================================================================== std::string irclean(const std::string& str) { @@ -91,7 +90,30 @@ namespace creaImageIO return str; } //======================================================================== - + //===================================================================== + + + void DicomImageReader::getAttributes(const std::string filename, + std::map &infos,std::vector i_attr) + { + gdcm::Reader reader; + reader.SetFileName( filename.c_str() ); + if (reader.Read()) + { + std::vector::iterator it = i_attr.begin(); + for(;it != i_attr.end(); it++) + { + unsigned short el; + unsigned short gr; + sscanf((*it).c_str(),"D%04hx_%04hx",&gr,&el); + if ( ( gr!=0 ) && ( el!=0 ) ) + { + infos[(*it)] = ( GetStringValueFromTag(reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(gr,el))) ); + } + } + } + + } //===================================================================== void DicomImageReader::ReadAttributes(const std::string& filename, std::map& attr) diff --git a/src/creaImageIODicomImageReader2.h b/src/creaImageIODicomImageReader2.h index 08b01f3..0cd9056 100644 --- a/src/creaImageIODicomImageReader2.h +++ b/src/creaImageIODicomImageReader2.h @@ -39,6 +39,8 @@ namespace creaImageIO void ReadAttributes2(const std::string& filename, tree::AttributeMapType& attr); + /// Another function to read attributes for a file + void getAttributes(const std::string filename, std::map &infos, std::vector i_attr); private: const std::string GetStringValueFromTag( const gdcm::DataElement& ds); vtkGDCMImageReader *mReader; diff --git a/src/creaImageIOGimmick.cpp b/src/creaImageIOGimmick.cpp index 5edb4ed..fcc38e0 100644 --- a/src/creaImageIOGimmick.cpp +++ b/src/creaImageIOGimmick.cpp @@ -1,9 +1,9 @@ #include - #include #include #include + //#include "io.h" #ifndef PATH_MAX // If not defined yet : do it # define PATH_MAX 2048 @@ -424,6 +424,34 @@ path+= mLocalDescpName; } //======================================================================== + //======================================================================== + // get attributes values from database for a given file from database + //======================================================================== + void Gimmick::GetAttributes(const std::string filename, std::map &i_res, OutputAttr i_attr) + { + if (i_attr.inside.size() > 0) + { + std::map map_attr; + TreeHandler * handler=GetTreeHandler(i_attr.db); + handler->getAllAttributes(filename, map_attr); + if(i_attr.inside.front() == "ALL") // we take all values + { + std::map::iterator it = map_attr.begin(); + for(; it != map_attr.end(); it++) + i_res[it->first] = it->second; + } + else + { + std::vector::iterator it = i_attr.inside.begin(); + for(; it != i_attr.inside.end(); it++) + i_res[(*it)] = map_attr[(*it)]; + } + } + + + } + + //======================================================================== void Gimmick::UpdateSetting(const std::string& name, const std::string& value) @@ -488,4 +516,29 @@ path+= mLocalDescpName; addDB(name, it_path->c_str()); } } + + +/////////////////////////////////////////////////////////////////////////////// +// Fill attributes structure with attributes present in database (inside vector +// and not present (outside) +/////////////////////////////////////////////////////////////////////////////// +void Gimmick::fillVectInfos(std::vector i_attr, OutputAttr &infos) +{ + //test if a tag is present in Database descriptor + TreeHandler * handler=GetTreeHandler(infos.db); + mImageAdder.SetTreeHandler(handler); + std::vector::const_iterator it = i_attr.begin(); + for (;it != i_attr.end(); it++) + { + if( mImageAdder.isAttributeExist((*it)) != "" ) // in DB + { + infos.inside.push_back((*it)); + } + else + { + infos.outside.push_back((*it)); // Need to scan again the files + } + } } + +} \ No newline at end of file diff --git a/src/creaImageIOGimmick.h b/src/creaImageIOGimmick.h index 017d153..49dfae4 100644 --- a/src/creaImageIOGimmick.h +++ b/src/creaImageIOGimmick.h @@ -8,6 +8,7 @@ + #ifdef _DEBUG #include #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__) @@ -69,6 +70,22 @@ namespace creaImageIO //======================================================================= /// Central controler of the gimmick application + + + + /// the selected attributes by end-user + typedef struct + { + // name of database to get attributes + std::string db; + // attributes available in this databse + std::vector inside; + // attributes not available in this databse + std::vector outside; + // + bool mult; + }OutputAttr; + class CREAIMAGEIO_EXPORT Gimmick { public: @@ -181,14 +198,16 @@ namespace creaImageIO const std::vector& params, std::vector& results); - /// + /// get Values for given attributes + void GetAttributes(const std::string filename, std::map &i_res, OutputAttr i_attr); + const std::string& GetHomeDirectory(); const std::string& GetUserSettingsDirectory(); void CreateUserSettingsDirectory(); const std::string& GetLocalDatabasePath(); - - + /// Decide if attributes are available through database + void fillVectInfos(std::vector i_attr, OutputAttr &infos); //============================================= private: SQLiteTreeHandler* mLocalDatabase; diff --git a/src/creaImageIOGimmickView.cpp b/src/creaImageIOGimmickView.cpp index 3132aa6..2b7c85b 100644 --- a/src/creaImageIOGimmickView.cpp +++ b/src/creaImageIOGimmickView.cpp @@ -10,6 +10,11 @@ #if defined(USE_GDCM2) #include +#include "gdcmSystem.h" +#include "gdcmCryptographicMessageSyntax.h" +#include "gdcmUIDGenerator.h" +#include "gdcmAnonymizer.h" +#include "gdcmGlobal.h" #endif @@ -213,10 +218,30 @@ namespace creaImageIO } else { - boost::shared_ptr ie=boost::shared_ptr(new ImageExtent((*sel).GetAttribute("D0028_0010"), - (*sel).GetAttribute("D0028_0011"), - (*sel).GetAttribute("D0028_0012"), - "")); + std::string extentx = (*sel).GetAttribute("D0028_0010"); + std::string extenty = (*sel).GetAttribute("D0028_0011"); + std::string extentz = (*sel).GetAttribute("D0028_0012"); + std::string extentt = (*sel).GetAttribute("D0028_0010"); + if( extentx == "" && extenty == "" && extentz == "") + { + // we try to create a vtkImageData just to get dim informations + // Long method need to improve it! + std::string name = (*sel).GetAttribute("FullFileName"); + if (name != "") + { + int dim[3]; + char c[5]; + mReader.GetImage(name)->GetDimensions(dim); + sprintf(c,"%d", dim[0]); + extentx = c; + sprintf(c,"%d", dim[1]); + extenty = c; + sprintf(c,"%d", dim[2]); + extentz = c; + } + } + + boost::shared_ptr ie=boost::shared_ptr(new ImageExtent(extentx, extenty, extentz,extentt)); if(mImageExtent==0) { mImageExtent=ie; @@ -286,6 +311,7 @@ namespace creaImageIO //====================================================================== void GimmickView::modifyValidationSignal(bool ivalid) { + mValidationSignal(ivalid); } @@ -371,7 +397,11 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect double spc[3]; first->GetSpacing(spc); - spc[2]=OrderTheFileNameVector(im); + + // OrderTheFileNameVector is not here anymore. + // Try orderFilesWithZSpacing from OutputModel FCY + // spc[2]=OrderTheFileNameVector(im); + spc[2] =1; out->SetSpacing(spc); @@ -393,63 +423,286 @@ void GimmickView::ReadImagesNotThreaded(std::vector& s, std::vect } //====================================================================== -#if defined(USE_GDCM) - double GimmickView::OrderTheFileNameVector(std::vector &im) -{ - double spacing=1; - typedef std::vector FileList; - FileList fileVector; - //GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); - GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New(); - std::vector lstAux; - std::vector::iterator it; - for (it=im.begin(); it!=im.end(); ++it) + + + ////////////////////////////////////////////////////////// + // Test if the image is a multiple or single frame. + // For the moment only with the creation of vtkImageDta. + // TO DO with image size and dim!!! + ////////////////////////////////////////////////////////// + bool GimmickView::isSingle(const std::string i_file) { - ///\TODO liberer les GDCM_NAME_SPACE::File a la fin! // JPR - GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); - f->SetFileName(*it); - f->Load(); - if (f->IsReadable()) + bool bres = true; + vtkImageData* first = mReader.GetImage( i_file); + int dim[3]; + first->GetDimensions(dim); + if (dim[3] > 1) { - fileVector.push_back(f); - } else { - lstAux.push_back(*it); + bres = false; } - } // for - + else + { + } + return bres; + } + + ////////////////////////////////////////////////////////// + // get Attributes values for a file + ////////////////////////////////////////////////////////// - if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector ))) + void GimmickView::getAttributes(const std::string i_file, std::map &o_infos, OutputAttr i_attr) { - sh->OrderFileList(&fileVector); - spacing= sh->GetZSpacing(); - im.clear(); - int i; - for (i=0; iGetFileName() ); - } - for (i=0; i0) + { + mGimmick->GetAttributes(i_file,o_infos,i_attr); + } + if(i_attr.outside.size()>0) + { + mReader.getAttributes(i_file,o_infos, i_attr.outside); + } + } + + ////////////////////////////////////////////////////////// + // create an output structure with n entries = n output + ////////////////////////////////////////////////////////// + void GimmickView::readImages1(std::vector& o_output, std::vector im, + OutputAttr i_attr) + { + std::vector::iterator it; + for (it=im.begin(); it!=im.end(); ++it) + { + OutStrGimmick out; + out.img = vtkImageData::New(); + out.img->ShallowCopy(mReader.GetImage(*it)); + if(i_attr.mult) + getAttributes((*it),out.infos,i_attr); + o_output.push_back(out); + } + // If we want only one output information structure, we set it outside the loop + if(!i_attr.mult) + { + getAttributes(im.front(), o_output.front().infos,i_attr); + } + + } + + ////////////////////////////////////////////////////////// + // create an output structure with n entries = 1 output + ////////////////////////////////////////////////////////// + void GimmickView::readImages3(std::vector& o_output, std::vector im, + OutputAttr i_attr, double i_zspc) + { + OutStrGimmick out; + vtkImageData* first = mReader.GetImage( im.front()); + out.img = vtkImageData::New(); + out.img->SetScalarType(first->GetScalarType()); + out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); + int ext[6]; + first->GetWholeExtent(ext); // send also 0,0 in Z + if(ext[5] == 0) + { + ext[5] = im.size()-1; + } + else + { + ext[5] = ext[5] * im.size()-1; // to deal with multiframes + } + out.img->SetExtent(ext); + int dim[3]; + first->GetDimensions(dim); + out.img->SetDimensions(dim[0], dim[1], im.size() ); + out.img->AllocateScalars(); + out.img->Update(); + 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(); + // Order the file name vector already did with the OutputModel!!! + //!!!!out.img->SetSpacing(i_zspc); + int slice = 0; + std::vector::iterator it; + for (it=im.begin(); it!=im.end(); ++it) + { + vtkImageData* cur = mReader.GetImage( (*it) ); + memcpy(out.img->GetScalarPointer(0,0,slice), cur->GetScalarPointer(0,0,0), imsize); + slice++; + } + getAttributes(im.front(),out.infos, i_attr); + o_output.push_back(out); + } + + + // TO DO NO VERY SURE : NEED TO BE TESTED + ////////////////////////////////////////////////////////// + // create an output structure with n entries (T size) = T output (n size) + ////////////////////////////////////////////////////////// + void GimmickView::readImages2(std::vector& o_output, std::vector im, + OutputAttr i_attr, double i_zspc) + { + vtkImageData* first = mReader.GetImage( im.front()); + int dim[3]; + first->GetDimensions(dim); + // differents formats char , short, etc... + // differents components 1..3 ex. jpg ->RGB 3 + unsigned long imsize = dim[0] * dim[1]; + imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents(); + + // Order the file name vector already did with the OutputModel!!! + std::vector::iterator it; + std::vector::iterator it_out = o_output.begin(); + + for (it=im.begin(); it!=im.end(); ++it, it_out += dim[2]) + { + vtkImageData* cur = mReader.GetImage( (*it) ); + for (int slice= 0 ; slice SetScalarType(first->GetScalarType()); + + out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); + int ext[6]; + first->GetWholeExtent(ext); // send also 0,0 in Z + ext[5] = 0; + out.img->SetExtent(ext); + + out.img->SetDimensions(dim[0], dim[1], 1 ); + out.img->AllocateScalars(); + out.img->Update(); + memcpy(out.img->GetScalarPointer(0,0,0), cur->GetScalarPointer(0,0,slice), imsize); + o_output.push_back(out); } - }else { - std::sort( im.begin(), im.end() ); + if(i_attr.mult) + getAttributes((*it),(*it_out).infos,i_attr); + } + if(!i_attr.mult) + { + getAttributes(im.front(), o_output.front().infos,i_attr); + } + } + + ////////////////////////////////////////////////////////// + // create an output structure with n entries (T size) = T + n output + ////////////////////////////////////////////////////////// + void GimmickView::readImages4(std::vector& o_output, std::vector im, + OutputAttr i_attr) + { + std::vector::iterator it; + std::vector::iterator it_out = o_output.begin(); + vtkImageData* first = mReader.GetImage( im.front()); + int dim[3]; + first->GetDimensions(dim); - return spacing; -} + for (int slice= 0 ; slice SetScalarType(first->GetScalarType()); + out.img->SetNumberOfScalarComponents(first->GetNumberOfScalarComponents()); + + int ext[6]; + first->GetWholeExtent(ext); // send also 0,0 in Z + ext[5] = 0; + out.img->SetExtent(ext); + + out.img->SetDimensions(dim[0], dim[1], im.size() ); + out.img->AllocateScalars(); + out.img->Update(); + unsigned long imsize = dim[0] * dim[1]; + imsize = imsize * first->GetScalarSize() * first->GetNumberOfScalarComponents(); + int index = 0; + + for (it=im.begin(); it!=im.end(); ++it, index ++) + { + vtkImageData* cur = mReader.GetImage( (*it) ); + memcpy(out.img->GetScalarPointer(0,0,index), cur->GetScalarPointer(0,0,slice), imsize); + o_output.push_back(out); + } + } + if(!i_attr.mult) // No sense to take informations in all images + { + getAttributes(im.front(), o_output.front().infos,i_attr); + } + } -#endif -#if defined(USE_GDCM2) - // TO DO - double GimmickView::OrderTheFileNameVector(std::vector &im) +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Global function to read Images and create wished output (informations, multiple, type and size of output...) +// In function of type (file, vector) and size, the correct readImages function is selected +////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void GimmickView::readImages(std::vector& o_output, std::vector im, + OutputAttr i_attr, int i_dim, double i_zspc) { - return 1; + int size = im.size(); + if ( size == 0) + { + return; + } + else if (size == 1) + { + // Simplest case + // Only one image : give it + // But take in count multiframe possibility + if ( isSingle(im.front()) || i_dim != 1) + { + readImages1(o_output,im, i_attr); + } + else + { + readImages2(o_output,im, i_attr,i_zspc); + } + + } + else + { + // multiple or single frame + if ( isSingle(im.front()) ) + { + //we deal with 2D images + if(i_dim == 1) + { + // 2D to 3D + readImages3(o_output,im, i_attr,i_zspc); + } + else + { + readImages1(o_output,im, i_attr); + } + } + else + { + // we deal with multiple frames n x (2D x T) + // Differents outputs are avaialable + if(i_dim == 1) + { + // put all in one output + readImages3(o_output,im, i_attr,i_zspc); + + } + else if( i_dim == 2) + { + // put in a vector of n x T (2D) + readImages2(o_output,im, i_attr,i_zspc); + } + else if( i_dim == 3) + { + // put in a vector of n (2D x T) + // No transformations. + readImages1(o_output,im, i_attr); + } + else + { + // put in a vector of T (2D x n) + readImages4(o_output,im, i_attr); + } + } + } } -#endif -//====================================================================== + + void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, std::vector im, int dimension) @@ -591,53 +844,106 @@ void GimmickView::ReadImagesNotThreadedInVector(std::vector& s, s mValidationSignal.connect(callback); } -} // EO namespace creaImageIO -////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// //void GimmickView::Anonymize(std::vector i_filenames, int type) +//{ +// +// gdcm::FileMetaInformation::SetSourceApplicationEntityTitle( "gdcmanon" ); +// gdcm::Global& g = gdcm::Global::GetInstance(); +// //if( !resourcespath ) +// // { +// // const char *xmlpathenv = getenv("GDCM_RESOURCES_PATH"); +// // if( xmlpathenv ) +// // { +// // // Make sure to look for XML dict in user explicitly specified dir first: +// // xmlpath = xmlpathenv; +// // resourcespath = 1; +// // } +// // } +// // if( resourcespath ) +// // { +// // // xmlpath is set either by the cmd line option or the env var +// // if( !g.Prepend( xmlpath.c_str() ) ) +// // { +// // std::cerr << "Specified Resources Path is not valid: " << xmlpath << std::endl; +// // return 1; +// // } +// // } +// // All set, then load the XML files: +// if( !g.LoadResourcesFiles() ) +// { +// return ; +// } +// const gdcm::Defs &defs = g.GetDefs(); (void)defs; +// if( !rootuid ) +// { +// // only read the env var if no explicit cmd line option +// // maybe there is an env var defined... let's check +// const char *rootuid_env = getenv("GDCM_ROOT_UID"); +// if( rootuid_env ) +// { +// rootuid = 1; +// root = rootuid_env; +// } +// } +// if( rootuid ) +// { +// // root is set either by the cmd line option or the env var +// if( !gdcm::UIDGenerator::IsValid( root.c_str() ) ) +// { +// std::cerr << "specified Root UID is not valid: " << root << std::endl; +// return 1; +// } +// gdcm::UIDGenerator::SetRoot( root.c_str() ); +// } +// +// if(type == 0) // { - //if(type == 0) - //{ - // // Get private key/certificate - // gdcm::CryptographicMessageSyntax cms; - //if( !dumb_mode ) - // { - // if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) ) - // { - // return 1; - // } - // cms.SetCipherType( ciphertype ); - // } - - //// Setup gdcm::Anonymizer - //gdcm::Anonymizer anon; - //if( !dumb_mode ) - // anon.SetCryptographicMessageSyntax( &cms ); - - //if( dumb_mode ) - // { - // for(unsigned int i = 0; i < nfiles; ++i) - // { - // const char *in = filenames[i].c_str(); - // const char *out = outfilenames[i].c_str(); - // if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) ) - // { - // //std::cerr << "Could not anonymize: " << in << std::endl; - // return 1; - // } - // } - // } - //else - // { - // for(unsigned int i = 0; i < nfiles; ++i) - // { - // const char *in = filenames[i].c_str(); - // const char *out = outfilenames[i].c_str(); - // if( !AnonymizeOneFile(anon, in, out) ) - // { - // //std::cerr << "Could not anonymize: " << in << std::endl; - // return 1; - // } - // } - // } -// } \ No newline at end of file +// // Get private key/certificate +// gdcm::CryptographicMessageSyntax cms; +// if( !dumb_mode ) +// { +// if( !GetRSAKeys(cms, rsa_path.c_str(), cert_path.c_str() ) ) +// { +// return 1; +// } +// cms.SetCipherType( ciphertype ); +// } +// +// // Setup gdcm::Anonymizer +// gdcm::Anonymizer anon; +// if( !dumb_mode ) +// anon.SetCryptographicMessageSyntax( &cms ); +// +// if( dumb_mode ) +// { +// for(unsigned int i = 0; i < nfiles; ++i) +// { +// const char *in = filenames[i].c_str(); +// const char *out = outfilenames[i].c_str(); +// if( !AnonymizeOneFileDumb(anon, in, out, empty_tags, remove_tags, replace_tags_value) ) +// { +// //std::cerr << "Could not anonymize: " << in << std::endl; +// return 1; +// } +// } +// } +// //else +// // { +// // for(unsigned int i = 0; i < nfiles; ++i) +// // { +// // const char *in = filenames[i].c_str(); +// // const char *out = outfilenames[i].c_str(); +// // if( !AnonymizeOneFile(anon, in, out) ) +// // { +// // //std::cerr << "Could not anonymize: " << in << std::endl; +// // return 1; +// // } +// // } +// // } +// } +//} +// +} // EO namespace creaImageIO \ No newline at end of file diff --git a/src/creaImageIOGimmickView.h b/src/creaImageIOGimmickView.h index beb7bf2..7a0e839 100644 --- a/src/creaImageIOGimmickView.h +++ b/src/creaImageIOGimmickView.h @@ -25,6 +25,14 @@ namespace creaImageIO { + + typedef struct + { + vtkImageData *img; + std::map infos; + }OutStrGimmick; + + /** * \ingroup View */ @@ -95,8 +103,8 @@ namespace creaImageIO { GimmickError("INTERNAL ERROR : EditFields not implemented"); } /// Anonymize or de-anonymize data - void Anonymize(std::vector i_filenames, int type); - + virtual void Anonymize(std::vector i_filenames, int type) + { GimmickError("INTERNAL ERROR : Anonymize not implemented"); } /// Display all Dicom Tags virtual void DumpTags(const std::string filename) @@ -175,9 +183,29 @@ namespace creaImageIO void modifyValidationSignal(bool ivalid); + + void readImages(std::vector& o_output, std::vector im, + OutputAttr i_attr, int i_dim, double i_zspc); + bool isSingle(const std::string i_file); private: - double OrderTheFileNameVector(std::vector &im); + + typedef void (*readXD)(std::vector&, std::vector, OutputAttr, double); + + void getAttributes(const std::string i_file, std::map &o_infos, OutputAttr i_attr); + + virtual void readImages2(std::vector& o_output, std::vector im, + OutputAttr i_attr, double i_zspc); + + virtual void readImages3(std::vector& o_output, std::vector im, + OutputAttr i_attr, double i_zspc); + + virtual void readImages4(std::vector& o_output, std::vector im, + OutputAttr i_attr); + + virtual void readImages1(std::vector& o_output, std::vector im, + OutputAttr i_attr); + /// Controller which manages the interaction with the model boost::shared_ptr< Gimmick> mGimmick; diff --git a/src/creaImageIOImageReader.cpp b/src/creaImageIOImageReader.cpp index d6edb78..d93b186 100644 --- a/src/creaImageIOImageReader.cpp +++ b/src/creaImageIOImageReader.cpp @@ -164,8 +164,19 @@ namespace creaImageIO return i; } //===================================================================== - - + // Another function to read attributes for a file + void ImageReader::getAttributes(const std::string filename, + std::map &infos, std::vector i_attr) + { + if (mLastFilename!=filename) + { + if (!CanRead(filename)) + { + return; + } + } + mLastReader->getAttributes(filename, infos, i_attr); + } //===================================================================== void ImageReader::ReadAttributes(const std::string& filename, std::map& attr) diff --git a/src/creaImageIOImageReader.h b/src/creaImageIOImageReader.h index ab9fbe7..1bf201c 100644 --- a/src/creaImageIOImageReader.h +++ b/src/creaImageIOImageReader.h @@ -37,8 +37,12 @@ namespace creaImageIO /// Exclude specific readers /// TO DO... + /// Another function to read attributes for a file + void getAttributes(const std::string filename, + std::map &infos, std::vector i_attr); + protected: /// Register a reader diff --git a/src/creaImageIOMultiThreadImageReader.cpp b/src/creaImageIOMultiThreadImageReader.cpp index 3ee50de..8e5c716 100644 --- a/src/creaImageIOMultiThreadImageReader.cpp +++ b/src/creaImageIOMultiThreadImageReader.cpp @@ -211,6 +211,12 @@ namespace creaImageIO } } //===================================================================== + // function to read attributes for a file + void MultiThreadImageReader::getAttributes(const std::string filename, + std::map &infos,std::vector i_attr) + { + mReader->getAttributes(filename, infos, i_attr); + } //===================================================================== void MultiThreadImageReader::Request( MultiThreadImageReaderUser* user, diff --git a/src/creaImageIOMultiThreadImageReader.h b/src/creaImageIOMultiThreadImageReader.h index c5a9ef9..461d2c3 100644 --- a/src/creaImageIOMultiThreadImageReader.h +++ b/src/creaImageIOMultiThreadImageReader.h @@ -105,7 +105,10 @@ namespace creaImageIO void OnMultiThreadImageReaderEvent( const std::string& filename, EventType type, vtkImageData* image); - + + /// Function to read attributes for a file + void getAttributes(const std::string filename, std::map &infos, std::vector i_attr); + protected: bool mDone; int GetMaximalPriorityWithoutLocking(); @@ -140,6 +143,8 @@ namespace creaImageIO int& UnloadIndex() { return mUnloadIndex; } vtkImageData* GetImage() const { return mImage; } void SetImage( vtkImageData* i ) { mImage=i; } + + std::map getAttributes(const std::vector i_attr); private: MultiThreadImageReaderUser* mUser; std::string mFilename; diff --git a/src/creaImageIOSQLiteTreeHandler.cpp b/src/creaImageIOSQLiteTreeHandler.cpp index 627db08..7a296e6 100644 --- a/src/creaImageIOSQLiteTreeHandler.cpp +++ b/src/creaImageIOSQLiteTreeHandler.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "CppSQLite3.h" @@ -321,6 +320,7 @@ namespace creaImageIO command += "\n)"; UPDATEDB(command); + GetTree().CopyAttributeDescriptorList(l); // Add Attribute 'ID' to Description GetTree().GetDescriptor().Add @@ -500,6 +500,7 @@ namespace creaImageIO return false; } + GetTree().CopyAttributeDescriptorList(level); } @@ -804,21 +805,10 @@ GimmickDebugMessage(1, "query : '" <GetLevel()).GetName(); - + query += GetTree().GetLevelDescriptor(node->GetLevel()).GetName(); query += " WHERE ID='"+ node->GetAttribute("ID") + "';"; - - UPDATEDB(query); - GimmickDebugMessage(2, - " Deleting '" - <GetLabel()<<"' with ID '" - <GetAttribute("ID") - <<"' in level "<< GetTree().GetLevelDescriptor(node->GetLevel()).GetName() - <GetNumberOfChildren()!=0) { Node::ChildrenListType::iterator i; @@ -954,36 +944,135 @@ GimmickDebugMessage(1, "query : '" < &i_results) { int level=GetTree().GetNumberOfLevels()-1; - std::string sp=searchParam.c_str(); - std::string sv=searchValue.c_str(); + + std::string search = i_filename; + std::string param = "FullFileName"; + std::string name; + std::string id; + std::set pid; + std::vector attr; + std::vector::iterator it_attr; + std::vector values; + std::vector::iterator it_val; + + + + while(level>1) { - std::stringstream out; - std::stringstream results; - out<<"SELECT PARENT_ID FROM "< values; + GetUpLevelNodeId(level, param,search,id); + GetAttributes(name, param,search,attr, values); + for(it_attr = attr.begin(), it_val = values.begin(); it_attr != attr.end(); it_attr++, it_val++) + { + i_results[(*it_attr).GetKey()] = (*it_val).c_str(); + } + search = id; + param = "ID"; + level --; + } + } + + +//===================================================================== +// get selected attributes from database for a given file + void SQLiteTreeHandler::GetAttributes(std::string name, std::string i_id, std::string i_value, tree::LevelDescriptor::AttributeDescriptorListType i_attr, std::vector &i_results) + { + //SELECT t1.ArtistName,CDs.Title FROM Artists t1, CDs WHERE t1.ArtistID=CDs.ArtistID + std::stringstream out; + std::stringstream results; + out<<"SELECT "; + tree::LevelDescriptor::AttributeDescriptorListType::iterator it = i_attr.begin(); + std::string query =""; + for(; it != i_attr.end(); it++) + { + query += (*it).GetKey(); + query +=" ,"; + } + query = query.substr(0, query.size()-1); + out << query; + out << "FROM "<1) + { + GetUpLevelNodeId(level, sp, sv, parent_id); + level--; + sp = "ID"; + sv = parent_id; } - parent_id=sv; +///* +// std::stringstream out; +// std::stringstream results; +// out<<"SELECT PARENT_ID FROM "< +#include class CppSQLite3DB; @@ -135,9 +136,15 @@ namespace creaImageIO const std::string i_val); //==================================================================== - + /// get all attributes from database for a given file + void getAllAttributes(std::string i_filename, std::map &i_results); + + /// get selected attributes from database for a given file + void GetAttributes(std::string name, std::string i_id, std::string i_value, tree::LevelDescriptor::AttributeDescriptorListType i_attr, std::vector &i_results); + + /// get Id for the up level node + void GetUpLevelNodeId(int level, const std::string& searchParam, const std::string& searchValue, std::string& parent_id); - protected: //====================================================================== /// Open the database diff --git a/src/creaImageIOSettings.cpp b/src/creaImageIOSettings.cpp index 770a802..d9d0af3 100644 --- a/src/creaImageIOSettings.cpp +++ b/src/creaImageIOSettings.cpp @@ -40,6 +40,8 @@ namespace creaImageIO Keys.push_back(SETTINGS_SYNC_FREQ); Keys.push_back(SETTINGS_COPY_PATH); Keys.push_back(SETTINGS_REMOVE_PATIENT_DISPLAY); + Keys.push_back(SETTINGS_OUTPUT_ASK); + Keys.push_back(SETTINGS_OUTPUT_DIM); readSettings(Keys, sets); } @@ -63,6 +65,8 @@ namespace creaImageIO m_SettingsMap[SETTINGS_DICOM_LIBRARY] = "gdcm"; m_SettingsMap[SETTINGS_COPY_PATH] = m_SettingsFileName.substr(0,m_SettingsFileName.find_last_of('\\')+1)+"Copied files"; m_SettingsMap[SETTINGS_REMOVE_PATIENT_DISPLAY] = "0"; + m_SettingsMap[SETTINGS_OUTPUT_ASK] ="true"; + m_SettingsMap[SETTINGS_OUTPUT_DIM] = "1"; writeSettingsFile(); } diff --git a/src/creaImageIOSettings.h b/src/creaImageIOSettings.h index 8d13d36..e6a9744 100644 --- a/src/creaImageIOSettings.h +++ b/src/creaImageIOSettings.h @@ -7,6 +7,8 @@ #define SETTINGS_DBPATH "" #define SETTINGS_COPY_PATH "" #define SETTINGS_REMOVE_PATIENT_DISPLAY "" +#define SETTINGS_OUTPUT_ASK "" +#define SETTINGS_OUTPUT_DIM "" namespace creaImageIO diff --git a/src/creaImageIOTree.h b/src/creaImageIOTree.h index de5b94a..c7b65b4 100644 --- a/src/creaImageIOTree.h +++ b/src/creaImageIOTree.h @@ -55,12 +55,27 @@ namespace creaImageIO { return GetDescriptor().GetLevelDescriptor(level); } /// Returns the AttributeDescriptorList of a given level (const ref) + /// type = 0 all attributes + /// type = 1 without ID and PATIENT_ID const LevelDescriptor::AttributeDescriptorListType& - GetAttributeDescriptorList(int level) const - { return GetDescriptor().GetAttributeDescriptorList(level); } + GetAttributeDescriptorList(int level, int type = 0) const + { return GetDescriptor().GetAttributeDescriptorList(level, type); } virtual void Print() const; + + /// Copy descriptor list without ID tag + void CopyAttributeDescriptorList(int level) + { + GetDescriptor().CopyAttributeDescriptorList(level); + } + + /// Test if this attribute is available in this tree description + const std::string isAttributeExist(const std::string i_attr) + { + return mDescriptor.isExist(i_attr); + } + private: Descriptor mDescriptor; diff --git a/src/creaImageIOTreeDescriptor.cpp b/src/creaImageIOTreeDescriptor.cpp index 8524794..6b176c9 100644 --- a/src/creaImageIOTreeDescriptor.cpp +++ b/src/creaImageIOTreeDescriptor.cpp @@ -272,5 +272,28 @@ namespace creaImageIO } } } + + + //================================================================== + // test if an attribute is present in DescriptionList + // return level's name + const std::string Descriptor::isExist(const std::string i_attr) + { + std::string name = ""; + LevelDescriptorListType::const_iterator l = GetLevelDescriptorList().begin(); + for (; l!= GetLevelDescriptorList().end(); ++l) + { + LevelDescriptor::AttributeDescriptorListType::const_iterator a = l->GetAttributeDescriptorList().begin(); + for(;a!= l->GetAttributeDescriptorList().end(); ++a) + { + if (a->GetKey() == i_attr) + { + name = l->GetName(); + break; + } + } + } + return name.c_str(); + } } } diff --git a/src/creaImageIOTreeDescriptor.h b/src/creaImageIOTreeDescriptor.h index a7e5b94..39b4180 100644 --- a/src/creaImageIOTreeDescriptor.h +++ b/src/creaImageIOTreeDescriptor.h @@ -40,10 +40,18 @@ namespace creaImageIO { return mLevelDescriptorList[level]; } /// Returns the AttributeDescriptorList of a given level (const ref) + /// type = 0 all attributes + /// type = 1 without ID and PATIENT_ID const LevelDescriptor::AttributeDescriptorListType& - GetAttributeDescriptorList(int level) const - { return mLevelDescriptorList[level].GetAttributeDescriptorList(); } + GetAttributeDescriptorList(int level, int type = 0) const + { return mLevelDescriptorList[level].GetAttributeDescriptorList(type); } + + /// Copy the AttributeDescriptorList without ID tag + void CopyAttributeDescriptorList(int level) + { + mLevelDescriptorList[level].CopyAttributeDescriptorList(); + } /// Adds a LevelDescriptor at the end of the list void Add(const LevelDescriptor&); @@ -67,6 +75,11 @@ namespace creaImageIO //Create Attribute Descriptors from a file void createDescriptorfromFile(const std::string &i_file); + + /// test if an attribute is present in DescriptionList + /// return level's name + const std::string Descriptor::isExist(const std::string i_attr); + private: LevelDescriptorListType mLevelDescriptorList; /// Creates the mandatory level 0 descriptor called "Root" diff --git a/src/creaImageIOTreeHandler.h b/src/creaImageIOTreeHandler.h index b84d0f9..f603013 100644 --- a/src/creaImageIOTreeHandler.h +++ b/src/creaImageIOTreeHandler.h @@ -147,7 +147,8 @@ namespace creaImageIO const std::string i_val){} //==================================================================== - + /// get all attributes for a file + virtual void getAllAttributes(std::string i_filename, std::map &i_results) =0; private: /// The handled tree diff --git a/src/creaImageIOTreeHandlerImageAdder.cpp b/src/creaImageIOTreeHandlerImageAdder.cpp index f51ef14..34be57a 100644 --- a/src/creaImageIOTreeHandlerImageAdder.cpp +++ b/src/creaImageIOTreeHandlerImageAdder.cpp @@ -234,7 +234,7 @@ namespace creaImageIO INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR); i_sc.ReadAttributes(itr->string(),attr); - mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id); + // mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id); mTreeHandler->AddBranch(attr); mProgress.IncNumberHandledFiles(); std::stringstream removedOn; @@ -291,7 +291,7 @@ namespace creaImageIO { mProgress.IncNumberHandledFiles(); AddFile( itr->string() ); - mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id); + //mTreeHandler->GetTopLevelNodeId("FullFileName",itr->string(),parent_id); std::stringstream removedOn; removedOn<InsertIgnoreFile(addKey, itr->string(),"0",removedOn.str(),mCurrentDB); @@ -688,5 +688,10 @@ namespace creaImageIO } } - + //======================================================================= + const std::string TreeHandlerImageAdder::isAttributeExist(const std::string i_attr) + { + return mTreeHandler->GetTree().isAttributeExist(i_attr); + } + } diff --git a/src/creaImageIOTreeHandlerImageAdder.h b/src/creaImageIOTreeHandlerImageAdder.h index 252e788..4797422 100644 --- a/src/creaImageIOTreeHandlerImageAdder.h +++ b/src/creaImageIOTreeHandlerImageAdder.h @@ -155,7 +155,9 @@ namespace creaImageIO void GetAttributes(const std::vector& params, const std::string& filename, std::vector& results); - + + /// Test if an attribute is referenced for a given treeHandler + const std::string isAttributeExist(const std::string i_attr); diff --git a/src/creaImageIOTreeLevelDescriptor.cpp b/src/creaImageIOTreeLevelDescriptor.cpp index 46eb41a..531b715 100644 --- a/src/creaImageIOTreeLevelDescriptor.cpp +++ b/src/creaImageIOTreeLevelDescriptor.cpp @@ -25,7 +25,30 @@ namespace creaImageIO } } - + // Copy the descriptor List without ID and PATIENT_ID attributes + void LevelDescriptor::CopyAttributeDescriptorList() + { + mAttributeDescriptorListWID = mAttributeDescriptorList; + for(AttributeDescriptorListType::iterator it = mAttributeDescriptorListWID.begin(); + it != mAttributeDescriptorListWID.end(); it++) + { + if((*it).GetKey() == "ID") + { + mAttributeDescriptorListWID.erase(it); + break; + } + } + + for(AttributeDescriptorListType::iterator it = mAttributeDescriptorListWID.begin(); + it != mAttributeDescriptorListWID.end(); it++) + { + if((*it).GetKey() == "PARENT_ID") + { + mAttributeDescriptorListWID.erase(it); + break; + } + } + } } } diff --git a/src/creaImageIOTreeLevelDescriptor.h b/src/creaImageIOTreeLevelDescriptor.h index f947034..be2a3d8 100644 --- a/src/creaImageIOTreeLevelDescriptor.h +++ b/src/creaImageIOTreeLevelDescriptor.h @@ -36,8 +36,17 @@ namespace creaImageIO typedef std::vector AttributeDescriptorListType; /// Returns the list of AttributeDescriptor (const) - const AttributeDescriptorListType& GetAttributeDescriptorList() const - { return mAttributeDescriptorList; } + /// type = 0 all attributes + /// type = 1 without ID and PATIENT_ID + const AttributeDescriptorListType& GetAttributeDescriptorList(int type = 0) const + { if (type == 0) + return mAttributeDescriptorList; + else + return mAttributeDescriptorListWID; + } + + /// Copy the original list of attributes + void CopyAttributeDescriptorList(); /// \return The list of attributes with flag IDENTIFIER set const std::vector& GetIdentifierList() const @@ -48,7 +57,10 @@ namespace creaImageIO private: std::string mName; + // Attributes List for this level AttributeDescriptorListType mAttributeDescriptorList; + // Attributes List for this level without ID and PARENT_ID attributes + AttributeDescriptorListType mAttributeDescriptorListWID; /// The list of attributes with flag IDENTIFIER set std::vector mIdentifierList; /// The list of attributes with flag LABEL set diff --git a/src/creaImageIOUltrasonixImageReader.cpp b/src/creaImageIOUltrasonixImageReader.cpp index 8eb476b..978bb03 100644 --- a/src/creaImageIOUltrasonixImageReader.cpp +++ b/src/creaImageIOUltrasonixImageReader.cpp @@ -41,10 +41,10 @@ namespace creaImageIO fread(header, sizeof(int), HEADER_SIZE, Ultrasonix_file); if (ferror(Ultrasonix_file)) return false; - h.type = header[0]; - h.frame = header[1]; - h.height = header[2]; - h.width = header[3]; + h.type = header[1]; + h.frame = header[2]; + h.height = header[3]; + h.width = header[4]; h.frequency = header[14]; h.samplingRate = header[15]; //free(header); @@ -71,20 +71,25 @@ namespace creaImageIO fseek(Ultrasonix_file,0,SEEK_END); // go to end of file if (h.type == TYPE_RF) size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame) * sizeof(int)) / sizeof(short); - else if (h.type == TYPE_B8) - size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(char); + else if (h.type == 1)//TYPE_B8) + size = (ftell(Ultrasonix_file) - (HEADER_SIZE+h.frame+4) * sizeof(int)) / sizeof(char); else if (h.type == TYPE_B32) size = (ftell(Ultrasonix_file) - HEADER_SIZE * sizeof(int)) / sizeof(int); // check if the data size corresponds to the dimensions of the images if (size == h.width * h.height * h.frame) ok = true; - + fclose(Ultrasonix_file); } return ok; } //===================================================================== + void UltrasonixImageReader::getAttributes(const std::string filename, + std::map &infos, std::vector i_attr) + { + //TO DO + } //===================================================================== vtkImageData* UltrasonixImageReader::ReadImage(const std::string& filename) diff --git a/src/creaImageIOUltrasonixImageReader.h b/src/creaImageIOUltrasonixImageReader.h index c0c9c54..2e33dc0 100644 --- a/src/creaImageIOUltrasonixImageReader.h +++ b/src/creaImageIOUltrasonixImageReader.h @@ -28,6 +28,9 @@ namespace creaImageIO virtual void ReadAttributes(const std::string& filename, tree::AttributeMapType& attr); + virtual void getAttributes(const std::string filename, + std::map &infos, std::vector i_attr); + }; //===================================================================== diff --git a/src/creaImageIOVtkImageReader.cpp b/src/creaImageIOVtkImageReader.cpp index 0d3780a..37f116e 100644 --- a/src/creaImageIOVtkImageReader.cpp +++ b/src/creaImageIOVtkImageReader.cpp @@ -52,7 +52,10 @@ namespace creaImageIO{ }*/ } //===================================================================== - + void VtkImageReader::getAttributes(const std::string filename, + std::map &infos, std::vector i_attr) + { + } //===================================================================== vtkImageData* VtkImageReader::ReadImage(const std::string& filename) { diff --git a/src/creaImageIOVtkImageReader.h b/src/creaImageIOVtkImageReader.h index 44e8f23..ad60149 100644 --- a/src/creaImageIOVtkImageReader.h +++ b/src/creaImageIOVtkImageReader.h @@ -38,6 +38,8 @@ namespace creaImageIO virtual void ReadAttributes(const std::string& filename, tree::AttributeMapType& attr); + virtual void getAttributes(const std::string filename, + std::map &infos, std::vector i_attr); private: vtkImageReader2* mReader; std::string mExtensions; diff --git a/src/creaImageIOWxExportDlg.h b/src/creaImageIOWxExportDlg.h index 6c5c9cd..63c6ed4 100644 --- a/src/creaImageIOWxExportDlg.h +++ b/src/creaImageIOWxExportDlg.h @@ -38,6 +38,7 @@ namespace creaImageIO{ /// Storage name std::string m_name; + }; } #endif // USE_WIDGETS diff --git a/src/creaImageIOWxGimmickPanel.h b/src/creaImageIOWxGimmickPanel.h index ad776dd..0f0c494 100644 --- a/src/creaImageIOWxGimmickPanel.h +++ b/src/creaImageIOWxGimmickPanel.h @@ -61,6 +61,8 @@ namespace creaImageIO mView->GetSelectedImagesInVector(s, dim); } + + void OnSelectedImage(bool t); void AddImagesToDB(std::string dir); diff --git a/src/creaImageIOWxGimmickReaderDialog.h b/src/creaImageIOWxGimmickReaderDialog.h index bac2c14..9750740 100644 --- a/src/creaImageIOWxGimmickReaderDialog.h +++ b/src/creaImageIOWxGimmickReaderDialog.h @@ -47,6 +47,12 @@ namespace creaImageIO void GetSelectedImagesInVector(std::vector& s, int dim) { mView->GetSelectedImagesInVector(s, dim); } + // get selected files in an Output structure + void getSelected(std::vector &outG,std::vector< std::string> i_attr, bool mult, const std::string outmodel) + { + mView->getSelectedFiles(outG, i_attr, mult, outmodel); + } + void GetSelectedFiles(std::vector& s) { mView->GetSelectedFiles(s); } diff --git a/src/creaImageIOWxGimmickView.cpp b/src/creaImageIOWxGimmickView.cpp index 91185a5..f13c5e0 100644 --- a/src/creaImageIOWxGimmickView.cpp +++ b/src/creaImageIOWxGimmickView.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include using namespace crea; // Icons @@ -298,18 +300,117 @@ namespace creaImageIO { std::vector files; GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files); - ReadImagesNotThreaded(s, files, dim); + //ReadImagesNotThreaded(s, files, dim); + + + std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())); + // ReadImagesNotThreadedInfosInVector(db_name,output, files,dim,1); } + + //====================================================================== void WxGimmickView::GetSelectedImagesInVector(std::vector& s, int dim) { std::vector files; + std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())); GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files); + ReadImagesNotThreadedInVector(s, files, dim); } + + + /// By default if out_infos is empty, we dont' provide informations, we return only vtkImageData + /// if out_infos has only one entry "all" we provide all database informations + void WxGimmickView::getSelectedFiles(std::vector &outG, std::vector< std::string> i_attr, + bool mult, const std::string out_model) + { + // First we select the files + std::vector files; + std::string db_name = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())); + GetTreeViewMap()[crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection()))]->GetSelectedAsString(files); + + std::string asking; + std::string dim; + bool bsingle = isSingle(files.front()); + int i_dim_out; + mGimmick->GetSetting(SETTINGS_OUTPUT_ASK, asking); + mGimmick->GetSetting(SETTINGS_OUTPUT_DIM, dim); + + if (asking == "true") + { + // display the output dialog box + // get dim + int idim; + sscanf(dim.c_str(),"%d",&idim); + WxOutputDlg *dlg = new WxOutputDlg(this,files, idim -1, bsingle); + if (dlg->ShowModal() == wxID_OK) + { + dim = dlg->getDim(); + mGimmick->UpdateSetting(SETTINGS_OUTPUT_ASK, dlg->getAsking()); + mGimmick->UpdateSetting(SETTINGS_OUTPUT_DIM, dim); + } + else + { + return; + } + } + else + { + } + sscanf(dim.c_str(),"%d",&i_dim_out); + + + // Next we create the structure for dicom output infos + OutputAttr Oattr; + Oattr.db = crea::wx2std(mNotebook->GetPageText(mNotebook->GetSelection())); + if(i_attr.empty()) + { + // We don't send informations! + } + else if( i_attr.size() == 1 && i_attr.front() == "ALL") + { + // we send all database + Oattr.inside.push_back("ALL"); + } + else if( (i_attr.size() == 1 && i_attr.front() != "ALL") + || (i_attr.size() >1) ) + { + mGimmick->fillVectInfos(i_attr, Oattr); + } + else + { + // nothing + } + + // Next we create model and sort files + std::vector sort_files(files); + double zspacing = 1; + if( !out_model.empty() ) + { + /* OutputModel mod(out_model); + mGimmick->isAttributeExist(db_name, mod); + mod.sort(files, sort_files); + */} + + if ( sort_files.size() > 1 && ( (bsingle && i_dim_out == 1) || (!bsingle && i_dim_out ==3) ) ) + { + OutputModel *mod = new OutputModel(); + zspacing = mod->orderFilesWithZspacing(sort_files); + delete mod; + } + // Now we read and create the waiting output (vtkImageData * or OutGimmickData *) + readImages(outG, sort_files, Oattr, i_dim_out, zspacing); + } + + + + //====================================================================== + //====================================================================== + + //====================================================================== void WxGimmickView::GetSelectedFiles(std::vector& s) { diff --git a/src/creaImageIOWxGimmickView.h b/src/creaImageIOWxGimmickView.h index f676ece..63cddad 100644 --- a/src/creaImageIOWxGimmickView.h +++ b/src/creaImageIOWxGimmickView.h @@ -32,6 +32,7 @@ namespace creaImageIO public: typedef int EventType; + OutStrGimmick m_out; /// Ctor WxGimmickView(boost::shared_ptr, @@ -48,11 +49,15 @@ namespace creaImageIO ///(overloaded from GimmickView) void GetSelectedFiles(std::vector& s); + /// Returns the selected files in output structure + void getSelectedFiles(std::vector &outG, std::vector< std::string> out_infos, bool mult = false, const std::string out_model = ""); + /// Returns the selected Images so that they comply with the /// given parameter(4D) (overloaded from GimmickView) void GetSelectedImages(std::vector& s, int dim); void GetSelectedImagesInVector(std::vector& s, int dim); + /// Returns the images indicated by the filenames in the vector /// so that they comply with the given parameter(dim) //(overloaded from GimmickView) diff --git a/src/creaImageIOWxTreeView.cpp b/src/creaImageIOWxTreeView.cpp index 3b30d4c..01b8ad4 100644 --- a/src/creaImageIOWxTreeView.cpp +++ b/src/creaImageIOWxTreeView.cpp @@ -1145,6 +1145,8 @@ namespace creaImageIO } } + + //================================================================ void WxTreeView::GetFilenamesAsString(const std::vector& nodes, std::vector&s) {