]> Creatis software - gdcm.git/blobdiff - src/gdcmHeaderEntrySet.cxx
* src/gdcmDicSet.[h|cxx] : add virtual entries to have a reference of
[gdcm.git] / src / gdcmHeaderEntrySet.cxx
index acbefa4243b112e236565a416d8a61ea1ab225b0..b83a4e878ed5bbda3e559e19a80a191822ae17d6 100644 (file)
@@ -10,6 +10,8 @@
 #  include <sstream>
 #endif
 
+#include <iomanip> // for std::ios::left, ...
+
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
@@ -23,7 +25,6 @@ gdcmHeaderEntrySet::~gdcmHeaderEntrySet() {
          delete EntryToDelete;
       tag->second=NULL;
    }
-
    tagHT.clear();
 }
 
@@ -44,6 +45,8 @@ void gdcmHeaderEntrySet::Print(std::ostream & os) {
    gdcmTS * ts = gdcmGlobal::GetTS();
 
    std::ostringstream s;
+/*
+// DO NOT remove this code right now.
    
    // Tag HT
    s << "------------- using tagHT ---------------------" << std::endl; 
@@ -76,14 +79,14 @@ void gdcmHeaderEntrySet::Print(std::ostream & os) {
       }              
       s << std::endl;
    }
-
+*/
    // List element
    guint32 lgth;
    char greltag[10];  //group element tag
-   
-
-   s << "------------ using listEntries -------------------" << std::endl; 
+   s << "------------ using listEntries ----------------" << std::endl; 
 
+   char st[11];
    for (ListTag::iterator i = listEntries.begin();  
           i != listEntries.end();
           ++i){
@@ -93,17 +96,35 @@ void gdcmHeaderEntrySet::Print(std::ostream & os) {
       o = (*i)->GetOffset();
       sprintf(greltag,"%04x|%04x",g,e);           
       d2 = _CreateCleanString(v);  // replace non printable characters by '.'
-      s << greltag << ": lgth : ";
+      s << greltag << " lg : ";
+      //lgth = (*i)->GetLength(); 
       lgth = (*i)->GetReadLength();
-      
-      s << std::hex << "x(" << lgth << ") "<< std::dec << lgth;         
-      s << ",\t Offset : " << o;
-      s << " x(" << std::hex << o << std::dec << ") ";
-      s << "\t[" << (*i)->GetVR()    << "]";
-      s << "\t[" << (*i)->GetName()  << "]";       
-      s << "\t[" << d2 << "]";
-      
-      // Display the UID value (instead of displaying the rough code)  
+      if (lgth == 0xffffffff) {
+         sprintf(st,"x(%ff)");
+         s.setf(std::ios::left);
+         s << std::setw(10-strlen(st)) << " ";  
+         s << st << " ";
+         s.setf(std::ios::left);
+         s << std::setw(8) << "-1";      
+      } else {
+         sprintf(st,"x(%x)",lgth);
+         s.setf(std::ios::left);
+         s << std::setw(10-strlen(st)) << " ";  
+         s << st << " ";
+         s.setf(std::ios::left);
+         s << std::setw(8) << lgth; 
+      }
+      s << " Off.: ";
+      sprintf(st,"x(%x)",o); 
+      s << std::setw(10-strlen(st)) << " ";       
+      s << st << " ";
+      s << std::setw(8) << o; 
+      s << "[" << (*i)->GetVR()  << "] ";
+      s.setf(std::ios::left);
+      s << std::setw(66-(*i)->GetName().length()) << " ";
+      s << "[" << (*i)->GetName()<< "] ";       
+      s << "[" << d2 << "]";
+       // Display the UID value (instead of displaying the rough code)  
       if (g == 0x0002) {  // Any more to be displayed ?
          if ( (e == 0x0010) || (e == 0x0002) )            
             s << "  ==>\t[" << ts->GetValue(v) << "]";   
@@ -112,9 +133,16 @@ void gdcmHeaderEntrySet::Print(std::ostream & os) {
             if ( (e == 0x0016) || (e == 0x1150)  )        
                s << "  ==>\t[" << ts->GetValue(v) << "]"; 
          }
-      }              
+      } 
+      if (e == 0x0000) {        // elem 0x0000 --> group length 
+        if (v == "4294967295") // to avoid troubles in convertion 
+           sprintf (st," x(ffffffff)");
+        else   
+            sprintf(st," x(%08x)",atoi(v.c_str()));
+         s << st;
+      }                     
       s << std::endl;
-   }
+   } 
    os<<s.str();
 } 
 
@@ -124,17 +152,15 @@ void gdcmHeaderEntrySet::Print(std::ostream & os) {
  * \ingroup gdcmHeaderEntrySet
  * \brief  add a new Dicom Element pointer to 
  *         the H Table and to the chained List
+ * \warning  push_bash in listEntries ONLY during ParseHeader
+ * \todo  something to allow further Elements addition,
+ * \      when position to be taken care of     
  * @param   newHeaderEntry
  */
 void gdcmHeaderEntrySet::Add(gdcmHeaderEntry * newHeaderEntry) {
 
-//     tagHT [newHeaderEntry->GetKey()]  = newHeaderEntry;
-
+// tagHT [newHeaderEntry->GetKey()]  = newHeaderEntry;
    tagHT.insert( PairHT( newHeaderEntry->GetKey(),newHeaderEntry) );
-       
-// WARNING : push_bash in listEntries ONLY during ParseHeader
-// TODO : something to allow further Elements addition 
-// position to be taken care of !      
    listEntries.push_back(newHeaderEntry); 
 }
 
@@ -325,6 +351,7 @@ bool gdcmHeaderEntrySet::Write(FILE * _fp, FileType type) {
  * \ingroup gdcmHeaderEntrySet
  * \brief   Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader
  * \warning : to be re-written using the chained list instead of the H table.
+ * \warning : DO NOT use (doesn't work any longer because of the multimap)
  * \todo : to be re-written using the chained list instead of the H table
  * @param   SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files)
  * @param   type Type of the File (ExplicitVR,ImplicitVR, ACR, ...) 
@@ -401,7 +428,7 @@ void gdcmHeaderEntrySet::UpdateGroupLength(bool SkipSequence, FileType type) {
       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");       
+         gdcmDictEntry * tagZ = gdcmGlobal::GetDicts()->NewVirtualDictEntry(gr_bid, 0x0000, "UL");
          elemZ = new gdcmHeaderEntry(tagZ);
          elemZ->SetLength(4);
          Add(elemZ);                           // create it
@@ -424,7 +451,6 @@ void gdcmHeaderEntrySet::UpdateGroupLength(bool SkipSequence, FileType type) {
  * @param   type type of the File to be written 
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  * @param   _fp already open file pointer
- * @return  
  */
 void gdcmHeaderEntrySet::WriteEntries(FileType type, FILE * _fp) {
    guint16 gr, el;
@@ -436,24 +462,24 @@ void gdcmHeaderEntrySet::WriteEntries(FileType type, FILE * _fp) {
    
    std::vector<std::string> tokens;
    
-   // TODO : use listEntries to iterate, not TagHt!
+   //  uses now listEntries to iterate, not TagHt!
+   //
    //        pb : gdcmHeaderEntrySet.Add does NOT update listEntries
-   //        find a trick in STL to do it, at low cost !
+   //       TODO : find a trick (in STL?) to do it, at low cost !
 
    void *ptr;
 
-   // Tout ceci ne marche QUE parce qu'on est sur un proc Little Endian 
-   // restent a tester les echecs en ecriture (apres chaque fwrite)
+   // TODO (?) tester les echecs en ecriture (apres chaque fwrite)
 
-   for (TagHeaderEntryHT::iterator tag2=tagHT.begin();
-        tag2 != tagHT.end();
+   for (ListTag::iterator tag2=listEntries.begin();
+        tag2 != listEntries.end();
         ++tag2){
 
-      gr =  tag2->second->GetGroup();
-      el =  tag2->second->GetElement();
-      lgr = tag2->second->GetLength();
-      val = tag2->second->GetValue().c_str();
-      vr =  tag2->second->GetVR();
+      gr =  (*tag2)->GetGroup();
+      el =  (*tag2)->GetElement();
+      lgr = (*tag2)->GetLength();
+      val = (*tag2)->GetValue().c_str();
+      vr =  (*tag2)->GetVR();
       
       if ( type == ACR ) { 
          if (gr < 0x0008)   continue; // ignore pure DICOM V3 groups
@@ -486,7 +512,7 @@ void gdcmHeaderEntrySet::WriteEntries(FileType type, FILE * _fp) {
 
       if (vr == "US" || vr == "SS") {
          tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
-         Tokenize (tag2->second->GetValue(), tokens, "\\");
+         Tokenize ((*tag2)->GetValue(), tokens, "\\");
          for (unsigned int i=0; i<tokens.size();i++) {
             val_uint16 = atoi(tokens[i].c_str());
             ptr = &val_uint16;
@@ -497,7 +523,7 @@ void gdcmHeaderEntrySet::WriteEntries(FileType type, FILE * _fp) {
       }
       if (vr == "UL" || vr == "SL") {
          tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
-         Tokenize (tag2->second->GetValue(), tokens, "\\");
+         Tokenize ((*tag2)->GetValue(), tokens, "\\");
          for (unsigned int i=0; i<tokens.size();i++) {
             val_uint32 = atoi(tokens[i].c_str());
             ptr = &val_uint32;