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>
30 #include <creaImageIOSystem.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"));
64 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
70 WxDumpPanel::~WxDumpPanel(){}
72 ///////////////////////////////////////////////////
73 /// Display in a control Text all dicom tags
74 ///////////////////////////////////////////////////
75 void WxDumpPanel::Print()
78 std::string result = "";
79 if ( !filename.empty()) // ====== Deal with a single file ======
83 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
84 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
85 f->SetFileName( filename );
86 f->SetMaxSizeLoadEntry(0xffff);
88 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
89 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
90 fh->SetPrintLevel( 0 );
94 while(std::getline(os, line))
96 result +=clean(line.c_str());
102 #if defined(USE_GDCM2)
104 reader.SetFileName( filename.c_str() );
107 gdcm::Printer printer;
108 printer.SetFile ( reader.GetFile() );
109 printer.SetColor( 0 );
116 //const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
117 // // (5400,0100) SQ (Sequence with undefined length #=1) # u/l, 1 WaveformSequence
118 // gdcm::Tag twsq(0x5400,0x0100);
119 // bool btest = ds.FindDataElement( twsq) ;
120 //const gdcm::DataElement &wsq = ds.GetDataElement( twsq );
121 // gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
122 // int num = sqi->GetNumberOfItems();
124 // const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
125 // const gdcm::DataSet& nestedds = item.GetNestedDataSet();
127 // // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
128 // gdcm::Tag twba(0x5400,0x1004);
129 // if( !nestedds.FindDataElement( twba ) )
133 // const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
135 // //std::cout << wba << std::endl;
136 // // (5400,1006) CS [SS] # 2, 1 WaveformSampleInterpretation
137 // // (5400,1010) OW 00ba\0030\ff76\ff8b\00a2\ffd3\ffae\ff50\0062\00c4\011e\00c2\00ba... # 57600, 1 WaveformData
138 // gdcm::Tag twd(0x5400,0x1010);
139 // if( !nestedds.FindDataElement( twd ) )
143 // const gdcm::DataElement &wd = nestedds.GetDataElement( twd );
144 // const gdcm::ByteValue *bv = wd.GetByteValue();
145 // size_t len = bv->GetLength();
146 // int16_t *p = (int16_t*)bv;
148 // size_t npts = len / 2;
149 // //npts = 10; // DEBUG !
150 // for(size_t i = 0; i < npts; ++i )
156 //// gdcm::SmartPointer<gdcm::SequenceOfItems> sqi = wsq.GetValueAsSQ();
157 ////if( !sqi || !sqi->GetNumberOfItems() )
162 //// const gdcm::Item & item = sqi->GetItem(1); // Item start at #1
163 //// const gdcm::DataSet& nestedds = item.GetNestedDataSet();
165 //// // (5400,1004) US 16 # 2, 1 WaveformBitsAllocated
166 //// gdcm::Tag twba(0x5400,0x1004);
167 //// if( !nestedds.FindDataElement( twba ) )
171 //// const gdcm::DataElement &wba= nestedds.GetDataElement( twba );
175 // gdcm::DataElement data = reader.GetFile().GetDataSet().GetDataElement(gdcm::Tag(0x5400,0x0100));
176 // std::string seq_old_begin = "(fffe,e000) na (Item with undefined length)";
177 // std::string seq_new_begin = "<SEQ>";
178 // boost::algorithm::replace_all(result, seq_old_begin, seq_new_begin);
179 // std::string seq_old_end = "(fffe,e00d)";
180 // std::string seq_new_end = "<\\SEQ>";
181 // boost::algorithm::replace_all(result, seq_old_end, seq_new_end);
182 //seq_old_end = "(fffe,e0dd)"; boost::algorithm::replace_all(result, seq_old_end, "\n");
184 DumpText->SetValue(crea::std2wx(result));
190 const std::string WxDumpPanel::clean(const std::string &i_line)
193 if (i_line.substr(4,1) == "|")
197 std::string signification;
199 std::string resultat;
201 tag = "(" + i_line.substr(0,9) + ")";
202 line = i_line.substr(14,i_line.size()-10);
203 int pos1 = line.find_first_of("[");
204 int pos2 = line.find_first_of("]");
205 signification = line.substr(pos1+1, pos2-pos1-1);
206 line = line.substr(pos2+1);
207 pos1 = line.find_first_of("[");
208 pos2 = line.find_first_of("]");
209 value = line.substr(pos1+1, pos2-pos1-1);
210 resultat = tag + " " + signification + ": " +value;
219 ///////////////////////////////////////////////////
220 /// wxEvent to save Dicom Tags in a text file //
221 ///////////////////////////////////////////////////
222 void WxDumpPanel::SaveInfos(wxCommandEvent& event)
224 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
225 crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
226 if (FD->ShowModal()==wxID_OK)
229 std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
231 ofs << crea::wx2std(DumpText->GetValue());;
237 ////////////////////////////////////////////////////////////
238 ////////////////////////////////////////////////////////////
239 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
240 EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)