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 // FIXME should we really update the element length ?
86 tagHt[key]->SetLength(content.length());
91 int ElValSet::SetElValueByName(string content, string TagName) {
92 if ( ! NameHt.count(TagName))
94 if (NameHt.count(TagName) > 1) {
95 dbg.Verbose(0, "ElValSet::SetElValue",
96 "multipe entries for this key (FIXME) !");
99 NameHt.find(TagName)->second->SetValue(content);
100 NameHt.find(TagName)->second->SetLength(strlen(content.c_str()));
106 int ElValSet::Write(FILE * _fp) {
108 // ATTENTION : fonction non terminée (commitée a titre de precaution)
118 string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
120 /* // Utilisées pour le calcul Group Length
122 guint32 lgrCalcGroupe;
123 ElValue * elemZ, *elemZPrec;
124 guint16 grCourant = 0;
129 // Comment pourrait-on tester si on est TRueDicom ou non ,
130 // (FileType est un champ de gdcmHeader ...)
133 // On parcourt la table pour recalculer la longueur des 'elements 0x0000'
134 // au cas ou un tag ai été ajouté par rapport à ce qui a été lu
135 // dans l'image native
137 // cf : code IdDcmWriteFile
140 // Pas le temps de finir
141 // voir libido/src/dcmwrite.c
143 // mais avant ... voir si le 'group length', lorsqu'il est present
144 // sert encore a qq chose
145 // patcher une image DICOM, mettre une lgr erronnée
146 // et voir si e-film la reconnait ...
149 for (TagElValueHT::iterator tag = tagHt.begin();
155 if ( (elemZ->GetGroup() != grCourant) &&
156 (elemZ->GetGroup() != 0xfffe) ) { // On arrive sur un nv Groupe
158 if(elemZ->GetNum != 0x0000) { // pas d'element 'Lgr groupe'
160 gdcmDictEntry * tagZ = IsInDicts(tag->second->GetGroup(), 0);
161 elemZ = new (ElValue(tagZ)); // on le cree
163 Add(elemZ); // On l'accroche à sa place
172 grCourant = elemZ->GetGroup();
173 lgrCalcGroupe = 12; //2 + 2 + 4 + 4; // lgr (Gr + Num + LgrElem + LgrGroupe)
175 } else { // On n'EST PAS sur un nv Groupe
177 lgrCalcGroupe += 2 + 2; // lgr (Gr + Num )
179 if (IsVrUnknowkn()) {
190 // Si on fait de l'implicit VR littele Endian
191 // (pour moins se fairche sur processeur INTEL)
192 // penser a forcer le SYNTAX TRANSFERT UID
194 SetElValueByNumber(implicitVRTransfertSyntax, 0x0002, 0x0010);
196 // restent à tester les echecs en écriture (apres chaque fwrite)
198 for (TagElValueHT::iterator tag = tagHt.begin();
203 // peut-on se passer des affectations?
204 // - passer l'adresse du resultat d'une fonction (???)
205 // - acceder au champ sans passer par un accesseur ?
207 gr = tag->second->GetGroup();
208 el = tag->second->GetElement();
209 lgr = tag->second->GetLength();
210 val = tag->second->GetValue().c_str();
211 vr = tag->second->GetVR();
213 fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group
214 fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element
216 //fwrite ( vr,(size_t)2 ,(size_t)1 ,_fp); //VR
218 // si on n'est pas en IMPLICIT VR voir pb (lgr + VR)
220 fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp); //lgr
222 if (vr == "US" || vr == "SS") {
223 val_int16 = atoi(val);
225 fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
228 if (vr == "UL" || vr == "SL") {
229 val_int32 = atoi(val);
231 fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
235 // Les pixels ne sont pas chargés dans l'element !
236 if ((gr == 0x7fe0) && (el == 0x0010) ) break;
238 fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); //valeur Elem