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>
30 #include <creaImageIOSystem.h>
33 #include <gdcmGlobal.h>
34 #include <gdcmDictSet.h>
37 #if defined(USE_GDCM2)
38 #include <gdcmGlobal.h>
39 #include <gdcmDicts.h>
43 #include <boost/algorithm/string/replace.hpp>
51 //========================================================================
52 void AttributeDescriptor::CleanName(std::string& str) const
54 // quote must be doubled for SQL
55 // crea::Utils::Replace( str, "'", "''" );
56 boost::algorithm::replace_all(str,"'","''");
57 // Found strange strings which contained NULL char INSIDE string
58 int i,size=str.size();
63 str = str.substr(0,i);
68 //========================================================================
70 //=====================================================================
71 // Ctor with key, name and flags
72 AttributeDescriptor::AttributeDescriptor(const std::string& key,
73 const std::string& name,
75 : mKey(key), mName(name), mGroup(0), mElement(0), mFlags(flags)
79 GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
80 <<"' ["<<flags<<"]"<<std::endl);
81 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
84 //=====================================================================
86 //=====================================================================
87 // Ctor with dicom group, elem and flags
88 // The key is built as 'Dgroup_elem'
89 // The user name is retreived from dicom dictionnary
90 AttributeDescriptor::AttributeDescriptor(unsigned short group,
91 unsigned short element,
93 : mGroup(group), mElement(element), mFlags(flags)
96 //GDCM_NAME_SPACE::TagKey tag(group,element);
98 sprintf(ctag,"D%04x_%04x",group,element);
101 GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
102 <<"' ["<<flags<<"]"<<std::endl);
104 #if defined(USE_GDCM)
105 // Retrieve the name from gdcm dict
106 GDCM_NAME_SPACE::DictEntry* entry =
107 GDCM_NAME_SPACE::Global::GetDicts()
108 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
112 mName = entry->GetName();
114 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
118 GimmickMessage(1,"!! WARNING : tag '"<<mKey
119 <<"' is not in DICOM dictionnary ! "
120 <<"Considering it as a user attribute"
123 mGroup = mElement = 0;
130 #if defined(USE_GDCM2)
131 // Retrieve the name from gdcm dict
132 const gdcm::Global& g = gdcm::Global::GetInstance();
133 const gdcm::Dicts &dicts = g.GetDicts();
134 const gdcm::Dict &dict = dicts.GetPublicDict();
135 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
137 mName = dictentry.GetName();
141 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
145 GimmickMessage(1,"!! WARNING : tag '"<<mKey
146 <<"' is not in DICOM dictionnary ! "
147 <<"Considering it as a user attribute"
150 mGroup = mElement = 0;
155 //=====================================================================
158 //=====================================================================
159 /// Extracts group and element from a key of the form "Dgroup_elem"
160 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
161 unsigned short& group,
162 unsigned short& elem)
165 if ( (key.size()==10) &&
169 sscanf(key.c_str(),"D%04hx_%04hx ",&group,&elem);
170 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<key<<"' : " <<group<<"|"<<elem<<std::endl);
174 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
175 <<" not a DICOM key format"<<std::endl);
180 //=====================================================================
181 /// test if the type is a date
182 bool AttributeDescriptor::isDateEntry() const
186 // Retrieve the name from gdcm dict
187 #if defined(USE_GDCM)
188 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
191 if( entry->GetVR().str() == "DA" )
197 #if defined(USE_GDCM2)
198 const gdcm::Global& g = gdcm::Global::GetInstance();
199 const gdcm::Dicts &dicts = g.GetDicts();
200 const gdcm::Dict &dict = dicts.GetPublicDict();
201 if(mGroup != 0 && mElement != 0)
203 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(GetGroup(), GetElement()));
204 if( gdcm::VR::GetVRString(dictentry.GetVR()) == "DA")
213 //=====================================================================
214 /// test if the type is a time
215 bool AttributeDescriptor::isTimeEntry() const
219 #if defined(USE_GDCM)
220 // Retrieve the name from gdcm dict
221 GDCM_NAME_SPACE::DictEntry* entry = GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
224 if( entry->GetVR().str() == "TM" )
231 #if defined(USE_GDCM2)
232 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
233 const gdcm::Dicts &dicts = g.GetDicts();
234 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
235 if(mGroup != 0 && mElement != 0)
237 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
238 if(gdcm::VR::GetVRString(dictentry.GetVR()) == "TM")
249 //=====================================================================
250 /// Decodes the type of the attribute
251 void AttributeDescriptor::DecodeType(unsigned int& typ) const
254 #if defined(USE_GDCM)
255 // Retrieve the name from gdcm dict
256 GDCM_NAME_SPACE::DictEntry* entry =
257 GDCM_NAME_SPACE::Global::GetDicts()
258 ->GetDefaultPubDict()->GetEntry(GetGroup(),GetElement());
265 type = entry->GetVR().str();
267 #if defined(USE_GDCM2)
268 const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
269 const gdcm::Dicts &dicts = g.GetDicts();
270 const gdcm::Dict &dict = dicts.GetPublicDict(); // Part 6
271 gdcm::DictEntry dictentry = dict.GetDictEntry(gdcm::Tag(mGroup, mElement));
272 type = gdcm::VR::GetVRString(dictentry.GetVR());
275 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
297 //=====================================================================
299 } // EO namespace tree
301 } // EO namespace creaImageIO