- // WARNING : risque de pb
- // si on est descendu 'a l'interieur' des SQ
- continue;
- //
- //
- if ( (gr != grCourant) /*&& // On arrive sur un nv Groupe
- (el != 0xfffe) */ ) {
-
- if (el != 0x0000) {
- gdcmDictEntry * tagZ = new gdcmDictEntry(gr, 0x0000, "UL");
- elemZ = new gdcmElValue(tagZ); // on le cree
- elemZ->SetLength(4);
- Add(elemZ); // On l'accroche à sa place
- if(DEBUG)printf("ajout elem OOOO pour gr %04x\n",gr);
- } else {
- elemZ=elem;
- if(DEBUG)printf("maj elemZ\n");
- }
-
- ostringstream f;
- f << lgrCalcGroupe;
- //sprintf(str_lgrCalcGroupe,"%d",lgrCalcGroupe);
- elemZPrec->SetValue(f.str());
- if(DEBUG)printf("ecriture lgr (%d, %s) pour gr %04x\n",lgrCalcGroupe, f.str().c_str(), grCourant);
- if(DEBUG)printf ("%04x %04x [%s]\n",elemZPrec->GetGroup(), elemZPrec->GetElement(),
- elemZPrec->GetValue().c_str());
- if(DEBUG)cout << "Addresse elemZPrec " << elemZPrec<< endl;
- elemZPrec=elemZ;
- lgrCalcGroupe = 0;
- grCourant = gr;
- if(DEBUG)printf("init-2 lgr (%d) pour gr %04x\n",lgrCalcGroupe, gr);
- } else { // On n'EST PAS sur un nv Groupe
- lgrCalcGroupe += 2 + 2 + 4 + elem->GetLength(); // Gr + Num + Lgr + LgrElem
- if(DEBUG)printf("increment (%d) el %04x-->lgr (%d) pour gr %04x\n",
- elem->GetLength(), el, lgrCalcGroupe, gr);
- }
- }
+ // WARNING :
+ // --> la descente a l'interieur' des SQ
+ // devrait etre faite avec une liste chainee, pas avec une HTable...
+
+ if ( groupHt.count(key) == 0) { // we just read the first elem of a given group
+ if (el == 0x0000) { // the first elem is 0x0000
+ groupHt[key] = 0; // initialize group length
+ } else {
+ groupHt[key] = 2 + 2 + 4 + elem->GetLength(); // non 0x0000 first group elem
+ }
+ } else { // any elem but the first
+ if (type == ExplicitVR) {
+ if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
+ groupHt[key] += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
+ }
+ }
+ groupHt[key] += 2 + 2 + 4 + elem->GetLength();
+ }
+ }
+
+ unsigned short int gr_bid;
+
+ for (GroupHT::iterator g = groupHt.begin(); // for each group we found
+ g != groupHt.end();
+ ++g){
+ // FIXME: g++ -Wall -Wstrict-prototypes reports on following line:
+ // warning: unsigned int format, different type arg
+ sscanf(g->first.c_str(),"%x",&gr_bid);
+ tk = g->first + "|0000"; // generate the element full tag
+
+ if ( tagHt.count(tk) == 0) { // if element 0x0000 not found
+ gdcmDictEntry * tagZ = new gdcmDictEntry(gr_bid, 0x0000, "UL");
+ elemZ = new gdcmElValue(tagZ);
+ elemZ->SetLength(4);
+ Add(elemZ); // create it
+ } else {
+ elemZ=GetElementByNumber(gr_bid, 0x0000);
+ }
+ sprintf(trash ,"%d",g->second);
+ str_trash=trash;
+ elemZ->SetValue(str_trash);
+ }