1 #include <creaImageIOWxDumpPanel.h>
2 #include <creaImageIOSystem.h>
3 #include <creaImageIOGimmick.h>
4 #include <boost/algorithm/string.hpp>
6 #include <gdcmGlobal.h>
7 #include <gdcmDictSet.h>
9 #include "gdcmDocument.h"
10 #include "gdcmFileHelper.h"
13 #if defined(USE_GDCM2)
14 #include "gdcmGlobal.h"
16 #include "gdcmDictPrinter.h"
17 #include "gdcmPrinter.h"
18 #include "gdcmReader.h"
19 #include "gdcmSmartPointer.h"
20 #include "gdcmSequenceOfItems.h"
22 #include "icons/save.xpm"
27 WxDumpPanel::WxDumpPanel(wxWindow *parent, std::string i_filename)
28 : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
31 mIcon = new wxImageList(size,size,true);
32 mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
33 wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
34 mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
36 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
42 WxDumpPanel::~WxDumpPanel(){}
44 ///////////////////////////////////////////////////
45 /// Display in a control Text all dicom tags
46 ///////////////////////////////////////////////////
47 void WxDumpPanel::Print()
50 std::string result = "";
51 if ( !filename.empty()) // ====== Deal with a single file ======
55 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
56 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
57 f->SetFileName( filename );
58 f->SetMaxSizeLoadEntry(0xffff);
60 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
61 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
62 fh->SetPrintLevel( 0 );
66 while(std::getline(os, line))
68 result +=clean(line.c_str());
74 #if defined(USE_GDCM2)
76 reader.SetFileName( filename.c_str() );
79 gdcm::Printer printer;
80 printer.SetFile ( reader.GetFile() );
81 printer.SetColor( 0 );
88 //const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
89 // // (5400,0100) SQ (Sequence with undefined length #=1) # u/l, 1 WaveformSequence
90 // gdcm::Tag twsq(0x5400,0x0100);
91 // bool btest = ds.FindDataElement( twsq) ;
92 //const gdcm::DataElement &wsq = ds.GetDataElement( twsq );
93 // gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
94 // int num = sqi->GetNumberOfItems();
96 // const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
97 // const gdcm::DataSet& nestedds = item.GetNestedDataSet();
99 // // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
100 // gdcm::Tag twba(0x5400,0x1004);
101 // if( !nestedds.FindDataElement( twba ) )
105 // const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
107 // //std::cout << wba << std::endl;
108 // // (5400,1006) CS [SS] # 2, 1 WaveformSampleInterpretation
109 // // (5400,1010) OW 00ba\0030\ff76\ff8b\00a2\ffd3\ffae\ff50\0062\00c4\011e\00c2\00ba... # 57600, 1 WaveformData
110 // gdcm::Tag twd(0x5400,0x1010);
111 // if( !nestedds.FindDataElement( twd ) )
115 // const gdcm::DataElement &wd = nestedds.GetDataElement( twd );
116 // const gdcm::ByteValue *bv = wd.GetByteValue();
117 // size_t len = bv->GetLength();
118 // int16_t *p = (int16_t*)bv;
120 // size_t npts = len / 2;
121 // //npts = 10; // DEBUG !
122 // for(size_t i = 0; i < npts; ++i )
128 //// gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
129 ////if( !sqi || !sqi->GetNumberOfItems() )
134 //// const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
135 //// const gdcm::DataSet& nestedds = item.GetNestedDataSet();
137 //// // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
138 //// gdcm::Tag twba(0x5400,0x1004);
139 //// if( !nestedds.FindDataElement( twba ) )
143 //// const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
147 // gdcm::DataElement data = reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(0x5400,0x0100));
148 // std::string seq_old_begin = "(fffe,e000) na (Item with undefined length)";
149 // std::string seq_new_begin = "<SEQ>";
150 // boost::algorithm::replace_all(result, seq_old_begin, seq_new_begin);
151 // std::string seq_old_end = "(fffe,e00d)";
152 // std::string seq_new_end = "<\\SEQ>";
153 // boost::algorithm::replace_all(result, seq_old_end, seq_new_end);
154 //seq_old_end = "(fffe,e0dd)"; boost::algorithm::replace_all(result, seq_old_end, "\n");
156 DumpText->SetValue(crea::std2wx(result));
162 const std::string WxDumpPanel::clean(const std::string &i_line)
165 if (i_line.substr(4,1) == "|")
169 std:string signification;
171 std::string resultat;
173 tag = "(" + i_line.substr(0,9) + ")";
174 line = i_line.substr(14,i_line.size()-10);
175 int pos1 = line.find_first_of("[");
176 int pos2 = line.find_first_of("]");
177 signification = line.substr(pos1+1, pos2-pos1-1);
178 line = line.substr(pos2+1);
179 pos1 = line.find_first_of("[");
180 pos2 = line.find_first_of("]");
181 value = line.substr(pos1+1, pos2-pos1-1);
182 resultat = tag + " " + signification + ": " +value;
191 ///////////////////////////////////////////////////
192 /// wxEvent to save Dicom Tags in a text file //
193 ///////////////////////////////////////////////////
194 void WxDumpPanel::SaveInfos(wxCommandEvent& event)
196 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
197 crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
198 if (FD->ShowModal()==wxID_OK)
201 std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
203 ofs << crea::wx2std(DumpText->GetValue());;
209 ////////////////////////////////////////////////////////////
210 ////////////////////////////////////////////////////////////
211 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
212 EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)