6 TagElValueHT & ElValSet::GetTagHt(void) {
10 void ElValSet::Add(ElValue * newElValue) {
11 tagHt [newElValue->GetKey()] = newElValue;
12 NameHt[newElValue->GetName()] = newElValue;
15 void ElValSet::Print(ostream & os) {
16 for (TagElValueHT::iterator tag = tagHt.begin();
19 os << tag->first << ": ";
20 os << "[" << tag->second->GetValue() << "]";
21 os << "[" << tag->second->GetName() << "]";
22 os << "[" << tag->second->GetVR() << "]" << endl;
26 void ElValSet::PrintByName(ostream & os) {
27 for (TagElValueNameHT::iterator tag = NameHt.begin();
30 os << tag->first << ": ";
31 os << "[" << tag->second->GetValue() << "]";
32 os << "[" << tag->second->GetKey() << "]";
33 os << "[" << tag->second->GetVR() << "]" << endl;
37 ElValue* ElValSet::GetElementByNumber(guint32 group, guint32 element) {
38 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
39 if ( ! tagHt.count(key))
41 if (tagHt.count(key) > 1)
42 dbg.Verbose(0, "ElValSet::GetElementByNumber",
43 "multiple entries for this key (FIXME) !");
44 return tagHt.find(key)->second;
47 ElValue* ElValSet::GetElementByName(string TagName) {
48 if ( ! NameHt.count(TagName))
50 if (NameHt.count(TagName) > 1)
51 dbg.Verbose(0, "ElValSet::GetElement",
52 "multipe entries for this key (FIXME) !");
53 return NameHt.find(TagName)->second;
56 string ElValSet::GetElValueByNumber(guint32 group, guint32 element) {
57 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
58 if ( ! tagHt.count(key))
59 return "gdcm::Unfound";
60 if (tagHt.count(key) > 1)
61 dbg.Verbose(0, "ElValSet::GetElValueByNumber",
62 "multiple entries for this key (FIXME) !");
63 return tagHt.find(key)->second->GetValue();
66 string ElValSet::GetElValueByName(string TagName) {
67 if ( ! NameHt.count(TagName))
68 return "gdcm::Unfound";
69 if (NameHt.count(TagName) > 1)
70 dbg.Verbose(0, "ElValSet::GetElValue",
71 "multipe entries for this key (FIXME) !");
72 return NameHt.find(TagName)->second->GetValue();
75 int ElValSet::SetElValueByNumber(string content, guint32 group, guint32 element) {
76 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
77 if ( ! tagHt.count(key))
79 if (tagHt.count(key) > 1) {
80 dbg.Verbose(0, "ElValSet::SetElValueByNumber",
81 "multiple entries for this key (FIXME) !");
84 tagHt[key]->SetValue(content);
85 // Question : m à j LgrElem ?
86 tagHt[key]->SetLength(strlen(content.c_str()));
87 // Ou trouver les fonctions d'une classe donnée?
88 // lgr d'une string, p.ex
93 int ElValSet::SetElValueByName(string content, string TagName) {
94 if ( ! NameHt.count(TagName))
96 if (NameHt.count(TagName) > 1) {
97 dbg.Verbose(0, "ElValSet::SetElValue",
98 "multipe entries for this key (FIXME) !");
101 NameHt.find(TagName)->second->SetValue(content);
102 NameHt.find(TagName)->second->SetLength(strlen(content.c_str()));
108 int ElValSet::Write(FILE * _fp) {
110 // ATTENTION : fonction non terminée (commitée a titre de precaution)
120 string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
122 /* // Utilisées pour le calcul Group Length
124 guint32 lgrCalcGroupe;
125 ElValue * elemZ, *elemZPrec;
126 guint16 grCourant = 0;
131 // Comment pourrait-on tester si on est TRueDicom ou non ,
132 // (FileType est un champ de gdcmHeader ...)
135 // On parcourt la table pour recalculer la longueur des 'elements 0x0000'
136 // au cas ou un tag ai été ajouté par rapport à ce qui a été lu
137 // dans l'image native
139 // cf : code IdDcmWriteFile
142 // Pas le temps de finir
143 // voir libido/src/dcmwrite.c
145 // mais avant ... voir si le 'group length', lorsqu'il est present
146 // sert encore a qq chose
147 // patcher une image DICOM, mettre une lgr erronnée
148 // et voir si e-film la reconnait ...
151 for (TagElValueHT::iterator tag = tagHt.begin();
157 if ( (elemZ->GetGroup() != grCourant) &&
158 (elemZ->GetGroup() != 0xfffe) ) { // On arrive sur un nv Groupe
160 if(elemZ->GetNum != 0x0000) { // pas d'element 'Lgr groupe'
162 gdcmDictEntry * tagZ = IsInDicts(tag->second->GetGroup(), 0);
163 elemZ = new (ElValue(tagZ)); // on le cree
165 Add(elemZ); // On l'accroche à sa place
174 grCourant = elemZ->GetGroup();
175 lgrCalcGroupe = 12; //2 + 2 + 4 + 4; // lgr (Gr + Num + LgrElem + LgrGroupe)
177 } else { // On n'EST PAS sur un nv Groupe
179 lgrCalcGroupe += 2 + 2; // lgr (Gr + Num )
181 if (IsVrUnknowkn()) {
192 // Si on fait de l'implicit VR littele Endian
193 // (pour moins se fairche sur processeur INTEL)
194 // penser a forcer le SYNTAX TRANSFERT UID
196 SetElValueByNumber(implicitVRTransfertSyntax, 0x0002, 0x0010);
198 // restent à tester les echecs en écriture (apres chaque fwrite)
200 for (TagElValueHT::iterator tag = tagHt.begin();
205 // peut-on se passer des affectations?
206 // - passer l'adresse du resultat d'une fonction (???)
207 // - acceder au champ sans passer par un accesseur ?
209 gr = tag->second->GetGroup();
210 el = tag->second->GetElement();
211 lgr = tag->second->GetLength();
212 val = tag->second->GetValue().c_str();
213 vr = tag->second->GetVR();
215 fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group
216 fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element
218 //fwrite ( vr,(size_t)2 ,(size_t)1 ,_fp); //VR
220 // si on n'est pas en IMPLICIT VR voir pb (lgr + VR)
222 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); //lgr
224 if (vr == "US" || vr == "SS") {
225 val_int16 = atoi(val);
227 fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
230 if (vr == "UL" || vr == "SL") {
231 val_int32 = atoi(val);
233 fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
237 // Les pixels ne sont pas chargés dans l'element !
238 if ((gr == 0x7fe0) && (el == 0x0010) ) break;
240 fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); //valeur Elem