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 <creaImageIOTreeAttributeDescriptor.h>
33 #pragma warning(disable: 4996)
37 #include <gdcmGlobal.h>
38 #include <gdcmDictSet.h>
41 #if defined(USE_GDCM2)
42 #include <gdcmGlobal.h>
43 #include <gdcmDicts.h>
47 #include <boost/algorithm/string/replace.hpp>
55 //========================================================================
56 void AttributeDescriptor::CleanName(std::string& str) const
58 // quote must be doubled for SQL
59 // crea::Utils::Replace( str, "'", "''" );
60 boost::algorithm::replace_all(str,"'","''");
61 // Found strange strings which contained NULL char INSIDE string
62 int i,size=(int)str.size();
67 str = str.substr(0,i);
72 //========================================================================
74 //=====================================================================
75 // Ctor with key, name and flags
76 AttributeDescriptor::AttributeDescriptor(const std::string& key,
77 const std::string& name,
79 : mKey(key), mName(name), mGroup(0), mElement(0), mFlags(flags)
83 GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
84 <<"' ["<<flags<<"]"<<std::endl);
85 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
88 //=====================================================================
90 //=====================================================================
91 // Ctor with dicom group, elem and flags
92 // The key is built as 'Dgroup_elem'
93 // The user name is retreived from dicom dictionnary
94 AttributeDescriptor::AttributeDescriptor(unsigned short group,
95 unsigned short element,
97 : mGroup(group), mElement(element), mFlags(flags)
100 //GDCM_NAME_SPACE::TagKey tag(group,element);
102 sprintf(ctag,"D%04x_%04x",group,element);
105 GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
106 <<"' ["<<flags<<"]"<<std::endl);
108 #if defined(USE_GDCM)
109 // Retrieve the name from gdcm dict
110 GDCM_NAME_SPACE::DictEntry* entry =
111 GDCM_NAME_SPACE::Global::GetDicts()
112 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
116 mName = entry->GetName();
118 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
122 GimmickMessage(1,"!! WARNING : tag '"<<mKey
123 <<"' is not in DICOM dictionnary ! "
124 <<"Considering it as a user attribute"
127 mGroup = mElement = 0;
134 #if defined(USE_GDCM2)
135 // Retrieve the name from gdcm dict
136 const gdcm::Global& g = gdcm::Global::GetInstance();
137 const gdcm::Dicts &dicts = g.GetDicts();
138 const gdcm::Dict &dict = dicts.GetPublicDict();
139 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
141 mName = dictentry.GetName();
145 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
149 GimmickMessage(1,"!! WARNING : tag '"<<mKey
150 <<"' is not in DICOM dictionnary ! "
151 <<"Considering it as a user attribute"
154 mGroup = mElement = 0;
159 //=====================================================================
162 //=====================================================================
163 /// Extracts group and element from a key of the form "Dgroup_elem"
164 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
165 unsigned short& group,
166 unsigned short& elem)
169 if ( (key.size()==10) &&
173 sscanf(key.c_str(),"D%04hx_%04hx ",&group,&elem);
174 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : " <<group<<"|"<<elem<<std::endl);
178 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
179 <<" not a DICOM key format"<<std::endl);
184 //=====================================================================
185 /// test if the type is a date
186 bool AttributeDescriptor::isDateEntry() const
190 // Retrieve the name from gdcm dict
191 #if defined(USE_GDCM)
192 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
195 if( entry->GetVR().str() == "DA" )
201 #if defined(USE_GDCM2)
202 const gdcm::Global& g = gdcm::Global::GetInstance();
203 const gdcm::Dicts &dicts = g.GetDicts();
204 const gdcm::Dict &dict = dicts.GetPublicDict();
205 if(mGroup != 0 && mElement != 0)
207 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
208 if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
217 //=====================================================================
218 /// test if the type is a time
219 bool AttributeDescriptor::isTimeEntry() const
223 #if defined(USE_GDCM)
224 // Retrieve the name from gdcm dict
225 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
228 if( entry->GetVR().str() == "TM" )
235 #if defined(USE_GDCM2)
236 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
237 const gdcm::Dicts &dicts = g.GetDicts();
238 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
239 if(mGroup != 0 && mElement != 0)
241 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
242 if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
253 //=====================================================================
254 /// Decodes the type of the attribute
255 void AttributeDescriptor::DecodeType(unsigned int& typ) const
258 #if defined(USE_GDCM)
259 // Retrieve the name from gdcm dict
260 GDCM_NAME_SPACE::DictEntry* entry =
261 GDCM_NAME_SPACE::Global::GetDicts()
262 ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
269 type = entry->GetVR().str();
271 #if defined(USE_GDCM2)
272 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
273 const gdcm::Dicts &dicts = g.GetDicts();
274 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
275 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
276 type = gdcm::VR::GetVRString(dictentry.GetVR());
279 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
301 //=====================================================================
303 } // EO namespace tree
305 } // EO namespace creaImageIO