1 #include <creaImageIOTreeAttributeDescriptor.h>
2 #include <creaImageIOSystem.h>
4 #include <gdcmGlobal.h>
5 #include <gdcmDictSet.h>
7 #include <boost/algorithm/string/replace.hpp>
15 //========================================================================
16 void AttributeDescriptor::CleanName(std::string& str) const
18 // quote must be doubled for SQL
19 // crea::Utils::Replace( str, "'", "''" );
20 boost::algorithm::replace_all(str,"'","''");
21 // Found strange strings which contained NULL char INSIDE string
22 int i,size=str.size();
27 str = str.substr(0,i);
32 //========================================================================
34 //=====================================================================
35 // Ctor with key, name and flags
36 AttributeDescriptor::AttributeDescriptor(const std::string& key,
37 const std::string& name,
39 : mKey(key), mName(name), mGroup(0), mElement(0), mFlags(flags)
43 GimmickDebugMessage(3,"AttributeDescriptor : '"<<key
44 <<"' ["<<flags<<"]"<<std::endl);
45 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
49 //=====================================================================
51 //=====================================================================
52 // Ctor with dicom group, elem and flags
53 // The key is built as 'Dgroup_elem'
54 // The user name is retreived from dicom dictionnary
55 AttributeDescriptor::AttributeDescriptor(unsigned short group,
56 unsigned short element,
58 : mGroup(group), mElement(element), mFlags(flags)
61 //GDCM_NAME_SPACE::TagKey tag(group,element);
63 sprintf(ctag,"D%04x_%04x",group,element);
66 GimmickDebugMessage(3,"AttributeDescriptor : '"<<mKey
67 <<"' ["<<flags<<"]"<<std::endl);
69 // Retrieve the name from gdcm dict
70 GDCM_NAME_SPACE::DictEntry* entry =
71 GDCM_NAME_SPACE::Global::GetDicts()
72 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
76 mName = entry->GetName();
79 GimmickDebugMessage(3,"='"<<mName<<"'"<<std::endl);
83 GimmickMessage(1,"!! WARNING : tag '"<<mKey
84 <<"' is not in DICOM dictionnary ! "
85 <<"Considering it as a user attribute"
88 mGroup = mElement = mType = 0;
93 //=====================================================================
96 //=====================================================================
97 /// Extracts group and element from a key of the form "Dgroup_elem"
98 void AttributeDescriptor::GetDicomGroupElementFromKey(const std::string& key,
99 unsigned short& group,
100 unsigned short& elem)
103 if ( (key.size()==10) &&
107 std::string g = key.substr(1,4);
108 sscanf(key.c_str(),"D %04x _ %04x ",&group,&elem);
109 sscanf(g.c_str(),"%04x",&group);
110 GimmickDebugMessage(3,"GetDicomGroupElementFromKey '"<<g<<"' : "
111 <<group<<"|"<<elem<<std::endl);
115 GimmickMessage(5,"GetDicomGroupElementFromKey '"<<key<<"' : "
116 <<" not a DICOM key format"<<std::endl);
120 //=====================================================================
121 ///Decodes the type of attribute into the valid groups
122 void AttributeDescriptor::DecodeType()
124 // Retrieve the name from gdcm dict
125 GDCM_NAME_SPACE::DictEntry* entry =
126 GDCM_NAME_SPACE::Global::GetDicts()
127 ->GetDefaultPubDict()->GetEntry(mGroup,mElement);
129 std::string type = entry->GetVR().str();
131 GimmickDebugMessage(3,"VR Value is "<<type<<"!"<<std::endl);
152 } // EO namespace tree
154 } // EO namespace creaImageIO