2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #include <creaImageIOWxDumpPanel.h>
31 #include <creaImageIOGimmick.h>
32 #include <boost/algorithm/string.hpp>
34 #include <gdcmGlobal.h>
35 #include <gdcmDictSet.h>
37 #include "gdcmDocument.h"
38 #include "gdcmFileHelper.h"
41 #if defined(USE_GDCM2)
42 #include "gdcmGlobal.h"
44 #include "gdcmDictPrinter.h"
45 #include "gdcmPrinter.h"
46 #include "gdcmReader.h"
47 #include "gdcmSmartPointer.h"
48 #include "gdcmSequenceOfItems.h"
50 #include "icons/save.xpm"
55 WxDumpPanel::WxDumpPanel(wxWindow *parent, std::string i_filename)
56 : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
59 mIcon = new wxImageList(size,size,true);
60 mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
61 wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
62 mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
65 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
66 #if wxMAJOR_VERSION <= 2
67 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
69 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY | wxTE_MULTILINE | wxTE_RICH );
77 WxDumpPanel::~WxDumpPanel(){}
79 ///////////////////////////////////////////////////
80 /// Display in a control Text all dicom tags
81 ///////////////////////////////////////////////////
82 void WxDumpPanel::Print()
85 std::string result = "";
86 if ( !filename.empty()) // ====== Deal with a single file ======
90 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
91 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
92 f->SetFileName( filename );
93 f->SetMaxSizeLoadEntry(0xffff);
95 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
96 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
97 fh->SetPrintLevel( 0 );
101 while(std::getline(os, line))
103 result +=clean(line.c_str());
109 #if defined(USE_GDCM2)
111 reader.SetFileName( filename.c_str() );
114 gdcm::Printer printer;
115 printer.SetFile ( reader.GetFile() );
116 printer.SetColor( 0 );
123 //const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
124 // // (5400,0100) SQ (Sequence with undefined length #=1) # u/l, 1 WaveformSequence
125 // gdcm::Tag twsq(0x5400,0x0100);
126 // bool btest = ds.FindDataElement( twsq) ;
127 //const gdcm::DataElement &wsq = ds.GetDataElement( twsq );
128 // gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
129 // int num = sqi->GetNumberOfItems();
131 // const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
132 // const gdcm::DataSet& nestedds = item.GetNestedDataSet();
134 // // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
135 // gdcm::Tag twba(0x5400,0x1004);
136 // if( !nestedds.FindDataElement( twba ) )
140 // const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
142 // //std::cout << wba << std::endl;
143 // // (5400,1006) CS [SS] # 2, 1 WaveformSampleInterpretation
144 // // (5400,1010) OW 00ba\0030\ff76\ff8b\00a2\ffd3\ffae\ff50\0062\00c4\011e\00c2\00ba... # 57600, 1 WaveformData
145 // gdcm::Tag twd(0x5400,0x1010);
146 // if( !nestedds.FindDataElement( twd ) )
150 // const gdcm::DataElement &wd = nestedds.GetDataElement( twd );
151 // const gdcm::ByteValue *bv = wd.GetByteValue();
152 // size_t len = bv->GetLength();
153 // int16_t *p = (int16_t*)bv;
155 // size_t npts = len / 2;
156 // //npts = 10; // DEBUG !
157 // for(size_t i = 0; i < npts; ++i )
163 //// gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
164 ////if( !sqi || !sqi->GetNumberOfItems() )
169 //// const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
170 //// const gdcm::DataSet& nestedds = item.GetNestedDataSet();
172 //// // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
173 //// gdcm::Tag twba(0x5400,0x1004);
174 //// if( !nestedds.FindDataElement( twba ) )
178 //// const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
182 // gdcm::DataElement data = reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(0x5400,0x0100));
183 // std::string seq_old_begin = "(fffe,e000) na (Item with undefined length)";
184 // std::string seq_new_begin = "<SEQ>";
185 // boost::algorithm::replace_all(result, seq_old_begin, seq_new_begin);
186 // std::string seq_old_end = "(fffe,e00d)";
187 // std::string seq_new_end = "<\\SEQ>";
188 // boost::algorithm::replace_all(result, seq_old_end, seq_new_end);
189 //seq_old_end = "(fffe,e0dd)"; boost::algorithm::replace_all(result, seq_old_end, "\n");
191 DumpText->SetValue(crea::std2wx(result));
197 const std::string WxDumpPanel::clean(const std::string &i_line)
200 if (i_line.substr(4,1) == "|")
204 std::string signification;
206 std::string resultat;
208 tag = "(" + i_line.substr(0,9) + ")";
209 line = i_line.substr(14,i_line.size()-10);
210 int pos1 = (int)line.find_first_of("[");
211 int pos2 = (int)line.find_first_of("]");
212 signification = line.substr(pos1+1, pos2-pos1-1);
213 line = line.substr(pos2+1);
214 pos1 = (int)line.find_first_of("[");
215 pos2 = (int)line.find_first_of("]");
216 value = line.substr(pos1+1, pos2-pos1-1);
217 resultat = tag + " " + signification + ": " +value;
226 ///////////////////////////////////////////////////
227 /// wxEvent to save Dicom Tags in a text file //
228 ///////////////////////////////////////////////////
229 void WxDumpPanel::SaveInfos(wxCommandEvent& event)
231 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
232 #if wxMAJOR_VERSION <= 2
233 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
234 crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
236 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
237 crea::std2wx("*.txt"), wxFD_OPEN, wxDefaultPosition);
239 if (FD->ShowModal()==wxID_OK)
242 std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
244 ofs << crea::wx2std(DumpText->GetValue());;
250 ////////////////////////////////////////////////////////////
251 ////////////////////////////////////////////////////////////
252 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
253 EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)