From a16d21efe1eeb91888000310de90293c7d7b2fc3 Mon Sep 17 00:00:00 2001 From: Frederic Cervenansky Date: Wed, 12 May 2010 14:01:19 +0000 Subject: [PATCH] additional document for output --- src/creaImageIOOutputModel.cpp | 402 +++++++++++++++++++++++++++++++++ src/creaImageIOOutputModel.h | 138 +++++++++++ src/creaImageIOWxDumpPanel.cpp | 73 ++++++ src/creaImageIOWxOutputDlg.cpp | 147 ++++++++++++ src/creaImageIOWxOutputDlg.h | 44 ++++ 5 files changed, 804 insertions(+) create mode 100644 src/creaImageIOOutputModel.cpp create mode 100644 src/creaImageIOOutputModel.h create mode 100644 src/creaImageIOWxOutputDlg.cpp create mode 100644 src/creaImageIOWxOutputDlg.h diff --git a/src/creaImageIOOutputModel.cpp b/src/creaImageIOOutputModel.cpp new file mode 100644 index 0000000..e072ea2 --- /dev/null +++ b/src/creaImageIOOutputModel.cpp @@ -0,0 +1,402 @@ +#include + +#include +#include "boost/algorithm/string.hpp" + +#if defined(USE_GDCM) +#include +#include +#endif + +#if defined(USE_GDCM2) +#include +#include +#include +#endif + + +#if defined(USE_XERCES) +#include +#include +#include +#include +using namespace xercesc; +#endif + + +namespace creaImageIO +{ + + + OutputModel::~OutputModel() + { + } + + #if defined(USE_GDCM) + double OutputModel::orderFilesWithZspacing(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) + { + ///\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()) + { + fileVector.push_back(f); + } else { + lstAux.push_back(*it); + } + } // for + + + if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector ))) + { + sh->OrderFileList(&fileVector); + spacing= sh->GetZSpacing(); + im.clear(); + int i; + for (i=0; iGetFileName() ); + } + for (i=0; i &im) + { + return 1; + } +#endif + + + +#if defined(USE_XERCES) + + OutputModel::OutputModel(OutputModelParser *i_outparser) : m_outparser(i_outparser) + { + // Init + b_db = false; + } + + //OutputModel::setOutputModel(std::vector< std::map> i_outputs) + //{ + // std::vector< std::map>::iterator it = i_outputs.begin(); + // for(; it != i_outputs.end(); it++) + // { + // checkModel((*it)); + // } + //} + + bool OutputModel::checkModel(std::map i_model, const std::string i_val) + { + bool bres = false; + if( i_model.find(i_val) != i_model.end() ) + { + bres = true; + } + + return bres; + + } + + OutputModel::~OutputModel() + { + } + void OutputModel::setDB(const std::string i_db, const std::string i_table) + { + b_db = true; + m_db = i_db; + m_table = i_table; + } + + const std::string OutputModel::getTag() + { + char key[12]; + if (!m_tag.empty()) + { + return m_tag; + } + else + { +#if defined(USE_GDCM) + sprintf(key,"D%04x_%04x", m_tag1.GetGroup(), m_tag1.GetElement()); +#endif +#if defined(USE_GDCM2) + sprintf(key,"D%04x_%04x", m_tag2.GetGroup(), m_tag2.GetElement()); +#endif + return key; + } + } +/* void OutputModel::sort(const std::vector i_filenames, std::vector &o_sort) + { + std::vector values; + if(bDicom) + { + if(b_db) + { + getDBValues(i_filenames, values); + } + else + { + getValues(i_filenames, values); + } + } + else + { + for(int i = 0; i ::iterator it_val = values.begin(); + std::vector::const_iterator it = i_filenames.begin(); + for(;it != i_filenames.end(); it_val++, it++) + { + if((*it_val) == index) + { + o_sort.push_back((*it)); + break; + } + } + } + if(m_model != NULL) + m_model->sort(i_filenames, o_sort); + }*/ + template + void OutputModel::getDBValues(const std::vector i_filenames, const std::string i_stag, std::map &o_val) + { + } + + + //template + //T OutputModel::getTypeTag() + //{ + // GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement()); + // entry->GetVR().GetVRType( entry->GetVR()); + // + //} + + template + void OutputModel::getValues(const std::vector i_filenames,const std::string i_tag, std::map< std::string, T> &o_val) + { +#if defined(USE_GDCM) + getReadValues(i_filenames, o_val); +#endif +#if defined(USE_GDCM2) + getScanValues(i_filenames, i_tag,o_val); +#endif + } + +#if defined(USE_GDCM2) + // TO DO if some file don't provide this value, we are lost so return a map! + template + void OutputModel::getScanValues(const std::vector i_filenames, const std::string i_stag, std::map &o_val) + { + uint16_t gr, el; + sscanf(i_stag.c_str(),"D%04hx_%04hx ",&gr,&el); + gdcm::Tag tag(gr, el); + if (!tag.IsIllegal()) + { + std::vector names(i_filenames); + gdcm::Scanner scan; + scan.ClearTags(); + scan.AddTag(tag); + + std::vector::iterator it = names.begin(); + for(;it != names.end(); it++) + boost::algorithm::replace_all((*it),"\\", "/"); + scan.Scan(i_filenames); +// const gdcm::Scanner::TagToValue &mapping = + std::vector::const_iterator it_file = i_filenames.begin(); + for(; it_file != i_filenames.end(); it++) + { + if( scan.GetMapping((*it_file).c_str()).begin() != scan.GetMapping((*it_file).c_str()).end()) + { + o_val[(*it)] = scan.GetMapping((*it_file).c_str()).begin()->second; + } + else + { + o_val[(*it)] = ""; + } + } + } + + } + + //const gdcm::VR::VRType OutputModel::getType(const std::string i_tag) + //{ + // uint16_t gr, el; + // sscanf(itag.c_str(),"D%04hx_%04hx ",&gr,&el); + // const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge ! + // const gdcm::Dicts &dicts = g.GetDicts(); + // const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6 + // gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(gr, el)); + // return dictentry.GetVR(); + //} +#endif + + + +#if defined(USE_GDCM) + double OutputModel::orderFiles(std::vector im, std::vector &out) +{ + double spacing = 1; + std::vector > fileVector; + std::vector lstAux; + GDCM_NAME_SPACE::SerieHelper *sh = GDCM_NAME_SPACE::SerieHelper::New(); + std::vector::iterator it = im.begin(); + for (; it!=im.end(); ++it) + { + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); + f->SetFileName(*it); + f->Load(); + if (f->IsReadable()) + { + fileVector.push_back(f); + } + else + { + lstAux.push_back((*it)); + } + } + if ((fileVector.size()>1) && (sh->IsCoherent( &fileVector ))) + { + sh->OrderFileList(&fileVector); + spacing= sh->GetZSpacing(); + out.clear(); + int i; + for (i=0; iGetFileName() ); + } + for (i=0; i i_filenames, std::vector &o_sort, int level) + { +#if defined(USE_XERCES) + int tags[3]; + tags[0] = 0; + + int tag_end = i_filenames.size(); + int tag_step = 1; + std::map model = m_outparser->getLevel(level); + std::map values; + + if( checkModel(model, OUTPUTMODEL_TAG(3)) && !b_db) + { +#if defined (USE_GDCM2) + + //OutputSort< getType(model[OUTPUTMODEL_TAG(3)] > osort; + + getValues(i_filenames, model[OUTPUTMODEL_TAG(3)], values); +#endif + } + else + { + OutputSort osort; + for(int i = 0; i < 3; i++) + { + if ( checkModel(model, OUTPUTMODEL_TAG(i))) + { + osort.setTag(model[OUTPUTMODEL_TAG(i)],OUTPUTMODEL_TAG(i)); + } + } + + if(b_db) + { + getDBValues(i_filenames,model[OUTPUTMODEL_TAG(3)], values); + } + else + { + for(int i = 0; i (i_filenames,model[OUTPUTMODEL_TAG(3)], values); + } + else + { + getValues(i_filenames, model[OUTPUTMODEL_TAG(3)], values); + } + } + else + { + for(int i = 0; i ::iterator it_val = values.begin(); + for(;it_val != values.end(); it_val++) + { + if(it_val->second.c_str() )// == index) + { + o_sort.push_back(it_val->first.c_str()); + break; + } + } + } + if(checkModel(model, OUTPUTMODEL_TAG(4))) + { + int lv; + sscanf(model[OUTPUTMODEL_TAG(4)].c_str(), "%d", lv); + sort(i_filenames,o_sort,lv); + } +#endif + } + +#endif + + +} \ No newline at end of file diff --git a/src/creaImageIOOutputModel.h b/src/creaImageIOOutputModel.h new file mode 100644 index 0000000..ada72a3 --- /dev/null +++ b/src/creaImageIOOutputModel.h @@ -0,0 +1,138 @@ +#ifndef __creaImageIOoutputModel_h_INCLUDED__ +#define __creaImageIOoutputModel_h_INCLUDED__ +#if defined (USE_XERCES) +#include +#endif +#if defined(USE_GDCM2) +#include +#endif + + +#define OUTPUTMODEL_TAG_i "" +#define OUTPUTMODEL_TAG_0 "TAG_BEGIN" +#define OUTPUTMODEL_TAG_1 "TAG_END" +#define OUTPUTMODEL_TAG_2 "TAG_STEP" +#define OUTPUTMODEL_TAG_3 "DICOM_TAG" +#define OUTPUTMODEL_TAG_4 "ANCHOR" +#define OUTPUTMODEL_TAG(i) OUTPUTMODEL_TAG_ ## i + + + + +namespace creaImageIO +{ + class OutputModel + { + public: + OutputModel(){} + virtual ~OutputModel(); + double orderFilesWithZspacing(std::vector &im); + +#if defined(USE_XERCES) + OutputModel(OutputModelParser *i_outparser); + + + + + // Test if we need to check the "dicom" tag if it exists on database + void setDB(const std::string i_db, const std::string i_table); + + const std::string getTag(); + + + private: + + OutputModelParser *m_outparser; + + // dimensions of output + int dim; + + // index to indicate if one model is available to perform sorting + bool bmodel; + + // index to indicate of a "DICOM" tag is selected to perform sorting + // not necessary a dicom tag + // for the moment only Gimmick Tag format accepted but should be GDCM2 format or GDCM1.3 too + bool bDicom; + + // database name + std::string m_dbname; + + std::string m_tag; +#if defined(USE_GDCM) + //m_tag1; + template + //void getReadValues(const std::vector i_filenames, std::vector &o_val); + double orderFiles(std::vector im, std::vector &out); + +#endif +#if defined(USE_GDCM2) + gdcm::Tag m_tag2; + + template + void getScanValues(const std::vector i_filenames, const std::string i_stag, std::map &o_val); + + /*template + T getTypeTag();*/ +#endif + + // the initial value to start sorting + int tag_begin; + + // the final value to end sorting + int tag_end; + + // step for the values + int tag_step; + + // if the sorting is not the same for the set of data, we include another OutputModel + // ex : if we want a step = 20 for the 100 first values, next a step = 10 for the next 100 and step = 1 for the lastest value + OutputModel *m_model; + + // indicates if the sorting tag is present in database or not + bool b_db; + + std::string m_db; + + std::string m_table; + + template + void getValues(const std::vector i_filenames,const std::string i_tag, std::map< std::string, T> &o_val); + template + void getDBValues(const std::vector i_filenames, const std::string i_stag, std::map &o_val); + + void sort(const std::vector i_filenames, std::vector &o_sort, int level); + + bool checkModel(std::map i_model, const std::string i_val); +#endif + }; + template + class OutputSort + { + public : + std::map values; + std::map tags; + + void setTag(T i_tag, const std::string name) + { + tags[name] = i_tag; + } + + void sort (const std::map i_values, std::vector &o_sort) + { + for(T index = tags[OUTPUTMODEL_TAG(0)]; index <= tags[OUTPUTMODEL_TAG(1)]; index += tags[OUTPUTMODEL_TAG(2)]) + { + std::map::const_iterator it_val = i_values.begin(); + for(;it_val != values.end(); it_val++) + { + if(it_val->second.c_str() == index) + { + o_sort.push_back(it_val->first.c_str()); + break; + } + } + } + } + }; +} // namespace creaImageIO +#endif //__creaImageIOoutputModel_h_INCLUDED__ \ No newline at end of file diff --git a/src/creaImageIOWxDumpPanel.cpp b/src/creaImageIOWxDumpPanel.cpp index 05b2da9..a820960 100644 --- a/src/creaImageIOWxDumpPanel.cpp +++ b/src/creaImageIOWxDumpPanel.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #if defined(USE_GDCM) #include #include @@ -15,6 +16,8 @@ #include "gdcmDictPrinter.h" #include "gdcmPrinter.h" #include "gdcmReader.h" +#include "gdcmSmartPointer.h" +#include "gdcmSequenceOfItems.h" #endif #include "icons/save.xpm" @@ -79,6 +82,76 @@ namespace creaImageIO printer.Print( os ); result = os.str(); } + + + + //const gdcm::DataSet& ds = reader.GetFile().GetDataSet(); + // // (5400,0100) SQ (Sequence with undefined length #=1) # u/l, 1 WaveformSequence + // gdcm::Tag twsq(0x5400,0x0100); + // bool btest = ds.FindDataElement( twsq) ; + //const gdcm::DataElement &wsq = ds.GetDataElement( twsq ); + // gdcm::SmartPointer sqi = wsq.GetValueAsSQ(); + // int num = sqi->GetNumberOfItems(); + // + // const gdcm::Item & item = sqi->GetItem(1); // Item start at #1 + // const gdcm::DataSet& nestedds = item.GetNestedDataSet(); + + // // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated + // gdcm::Tag twba(0x5400,0x1004); + // if( !nestedds.FindDataElement( twba ) ) + // { + // + // } + // const gdcm::DataElement &wba= nestedds.GetDataElement( twba ); + + // //std::cout << wba << std::endl; + // // (5400,1006) CS [SS] # 2, 1 WaveformSampleInterpretation + // // (5400,1010) OW 00ba\0030\ff76\ff8b\00a2\ffd3\ffae\ff50\0062\00c4\011e\00c2\00ba... # 57600, 1 WaveformData + // gdcm::Tag twd(0x5400,0x1010); + // if( !nestedds.FindDataElement( twd ) ) + // { + + // } + // const gdcm::DataElement &wd = nestedds.GetDataElement( twd ); + // const gdcm::ByteValue *bv = wd.GetByteValue(); + // size_t len = bv->GetLength(); + // int16_t *p = (int16_t*)bv; + // + // size_t npts = len / 2; + // //npts = 10; // DEBUG ! + // for(size_t i = 0; i < npts; ++i ) + // { + // float x; + // x = (float)p[i]; + // } + //// + //// gdcm::SmartPointer sqi = wsq.GetValueAsSQ(); + ////if( !sqi || !sqi->GetNumberOfItems() ) + //// { + //// + //// } + + //// const gdcm::Item & item = sqi->GetItem(1); // Item start at #1 + //// const gdcm::DataSet& nestedds = item.GetNestedDataSet(); + + //// // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated + //// gdcm::Tag twba(0x5400,0x1004); + //// if( !nestedds.FindDataElement( twba ) ) + //// { + //// return 0; + //// } + //// const gdcm::DataElement &wba= nestedds.GetDataElement( twba ); + + + + // gdcm::DataElement data = reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(0x5400,0x0100)); + // std::string seq_old_begin = "(fffe,e000) na (Item with undefined length)"; + // std::string seq_new_begin = ""; + // boost::algorithm::replace_all(result, seq_old_begin, seq_new_begin); + // std::string seq_old_end = "(fffe,e00d)"; + // std::string seq_new_end = "<\\SEQ>"; + // boost::algorithm::replace_all(result, seq_old_end, seq_new_end); + //seq_old_end = "(fffe,e0dd)"; boost::algorithm::replace_all(result, seq_old_end, "\n"); #endif DumpText->SetValue(crea::std2wx(result)); diff --git a/src/creaImageIOWxOutputDlg.cpp b/src/creaImageIOWxOutputDlg.cpp new file mode 100644 index 0000000..a927191 --- /dev/null +++ b/src/creaImageIOWxOutputDlg.cpp @@ -0,0 +1,147 @@ +#include + +namespace creaImageIO +{ + // CTor + WxOutputDlg::WxOutputDlg(wxWindow *parent, const std::vector filenames, int i_dim, bool single) + : wxDialog(parent, -1,_T("OUTPUT FORMAT"), wxDefaultPosition, wxSize(350,450)) + { + + int size = filenames.size(); + + int deflt = 1; + + std::string sentence; + sentence = "You select"; + std::string sentence2 = "You have the possibility to select output format :"; + int nbsent= 0; + std::vector outsentences; + if (size == 1) + { + sentence += " 1 "; + } + else + { + sentence += " n "; + } + if(single) + { + sentence += " single frames"; + } + else + { + sentence += " multi-frames"; + } + sentence += " as output"; + + + if (size == 1) + { + if(single) + { + outsentences.push_back("It shall be a single file with a single 2D frmae"); + } + else + { + outsentences.push_back("It shall be multiple files with 2D frames"); + outsentences.push_back("It shall be a single file with 3D frames"); + } + } + else + { + if(single) + { + outsentences.push_back("It shall be a single file with 3D frames"); + outsentences.push_back("It shall be multiple files with 2D frames"); + } + else + { + outsentences.push_back("It shall be a single file with (3D+t) frames"); + outsentences.push_back("It shall be multiple (n+t) files with 2D frames"); + outsentences.push_back("It shall be multiple (n) files with (2D+t) frames"); + outsentences.push_back("It shall be a multiple (t) files with (2D+n) frames"); + deflt = 3; + } + + } + if(i_dim != -1) + { + deflt = i_dim; + } + + + int start_point = 45; + wxStaticText * ExportText=new wxStaticText(this,-1,_T(sentence), wxPoint(5,10)); + + std::vector::iterator it = outsentences.begin(); + for(int i = 0;it != outsentences.end(); it++, i++, start_point += 45) + { + wxCheckBox *check = new wxCheckBox(this, -1, _T((*it)), wxPoint(5,start_point) ); + if(i == deflt) + check->SetValue(true); + else + check->SetValue(false); + Connect( check->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WxOutputDlg::OnChange ); + checkOut.push_back(check); + } + + checkAsking = new wxCheckBox(this, -1, _T(("Do you want to save this output and no more asking")), wxPoint(5,start_point) ); + + // VALIDATION BUTTON + wxButton *Ok = new wxButton(this, -1,_T("OK"), wxPoint(5,start_point+20) ); + Connect( Ok->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxOutputDlg::OnOk ); + + wxButton *Cancel = new wxButton(this, wxID_CANCEL,_T("CANCEL"), wxPoint(100,start_point+20) ); + Layout(); + + } + + WxOutputDlg::~WxOutputDlg(){} + + void WxOutputDlg::OnOk(wxCommandEvent &event) + { + Close(); + SetReturnCode(wxID_OK); + } + + void WxOutputDlg::OnChange(wxCommandEvent& event) + { + std::vector::iterator it = checkOut.begin(); + + for(int i = 0;it != checkOut.end(); it++, i++) + { + if( (*it)->GetId() == event.GetId()) + { + } + else + { + (*it)->SetValue(false); + } + } + } + + const std::string WxOutputDlg::getDim() + { + char res[2]; + std::vector::iterator it = checkOut.begin(); + for(int i = 1;it != checkOut.end(); it++, i++) + { + if( (*it)->GetValue() ) + { + sprintf(res,"%d", i); + } + else + { + + } + } + return res; + } + const std::string WxOutputDlg::getAsking() + { + if(checkAsking->GetValue()) + return "false"; + else + return "true"; + } +} diff --git a/src/creaImageIOWxOutputDlg.h b/src/creaImageIOWxOutputDlg.h new file mode 100644 index 0000000..19cac52 --- /dev/null +++ b/src/creaImageIOWxOutputDlg.h @@ -0,0 +1,44 @@ +#ifndef __creaImageIOWxOutputDlg_h_INCLUDED__ +#define __creaImageIOOutputtDlg_h_INCLUDED__ + +#ifdef USE_WXWIDGETS +#include +#include + + + +namespace creaImageIO{ + /** + * \ingroup GUI + */ + //===================================================================== + //===================================================================== + /// WxOutputDlg allows to select the different output format + /// + class WxOutputDlg : public wxDialog + { + public: + ///CTor + WxOutputDlg (wxWindow *parent, const std::vector filenames, int i_dim, bool single); + ///DTor + ~WxOutputDlg(); + + /// Get selected storage + const std::string getAsking(); + const std::string getDim(); + + private: + + ///Validate selected storage + void OnOk(wxCommandEvent &event); + + std::vector checkOut; + void OnChange(wxCommandEvent& event); + + wxCheckBox *checkAsking; + + }; +} +#endif // USE_WIDGETS +// EOF +#endif// __creaImageIOWxOutputDlg_h_INCLUDED__ -- 2.45.1