]> Creatis software - gdcm.git/commitdiff
* add shadow dictionary
authorregrain <regrain>
Tue, 20 Jan 2004 15:21:06 +0000 (15:21 +0000)
committerregrain <regrain>
Tue, 20 Jan 2004 15:21:06 +0000 (15:21 +0000)
     * bug fix
     * coding style

16 files changed:
src/gdcm.h
src/gdcmDict.cxx
src/gdcmDict.h
src/gdcmDictSet.cxx
src/gdcmDictSet.h
src/gdcmHeader.cxx
src/gdcmHeaderEntry.cxx
src/gdcmHeaderEntry.h
src/gdcmParser.cxx
src/gdcmParser.h
src/gdcmTS.cxx
src/gdcmTS.h
src/gdcmUtil.cxx
src/gdcmUtil.h
src/gdcmVR.cxx
src/gdcmVR.h

index a3d7ad5ce56ba4f800b89326061327684a0d717b..997001a0ff0e575e7730026e1dc6e1c9dd70a7f5 100644 (file)
@@ -28,5 +28,7 @@
 #include "gdcmHeaderHelper.h"
 #include "gdcmFile.h"
 
+#include "gdcmUtil.h"
+
 //-----------------------------------------------------------------------------
 #endif // #ifndef GDCM_H
index 9f2d3882bb2550405953c26b3b998644dbe223d6..e15c5ded5402c9fd9b3a8e0054f91f29f888ac68 100644 (file)
@@ -2,7 +2,11 @@
 //-----------------------------------------------------------------------------
 #include "gdcmDict.h"
 #include "gdcmUtil.h"
+
 #include <fstream>
+#include <iostream>
+#include <iomanip>
+
 #ifdef GDCM_NO_ANSI_STRING_STREAM
 #  include <strstream>
 #  define  ostringstream ostrstream
  * @param   FileName from which to build the dictionary.
  */
 gdcmDict::gdcmDict(std::string & FileName) {
-   std::ifstream from(FileName.c_str());
-   dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
-                    FileName.c_str());
    guint16 group, element;
-       // CLEANME : use defines for all those constants
    char buff[1024];
-   TagKey key;
    TagName vr;
    TagName fourth;
    TagName name;
 
+   std::ifstream from(FileName.c_str());
+   dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary",
+                    FileName.c_str());
+
    while (!from.eof()) {
       from >> std::hex >> group >> element;
       eatwhite(from);
@@ -39,13 +42,14 @@ gdcmDict::gdcmDict(std::string & FileName) {
       fourth = buff;
       from.getline(buff, 256, '\n');
       name = buff;
+
       gdcmDictEntry * newEntry = new gdcmDictEntry(group, element,
                                                   vr, fourth, name);
-      // FIXME: use AddNewEntry
-      NameHt[name] = newEntry;
-      KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry;
+      AddNewEntry(newEntry);
    }
    from.close();
+
+   filename=FileName;
 }
 
 /**
@@ -74,6 +78,7 @@ gdcmDict::~gdcmDict() {
  * @param   os The output stream to be written to.
  */
 void gdcmDict::Print(std::ostream &os) {
+   os<<"Dict file name : "<<filename<<std::endl;
    PrintByKey(os);
 }
 
@@ -87,9 +92,9 @@ void gdcmDict::PrintByKey(std::ostream &os) {
    std::ostringstream s;
 
    for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){
-      s << "Tag : ";
-      s << "(" << std::hex << tag->second->GetGroup() << ',';
-      s << std::hex << tag->second->GetElement() << ") = " << std::dec;
+      s << "Entry : ";
+      s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ',';
+      s << std::hex << std::setw(4) << tag->second->GetElement() << ") = " << std::dec;
       s << tag->second->GetVR() << ", ";
       s << tag->second->GetFourth() << ", ";
       s << tag->second->GetName() << "."  << std::endl;
@@ -109,12 +114,13 @@ void gdcmDict::PrintByName(std::ostream& os) {
    std::ostringstream s;
 
    for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){
-      s << "Tag : ";
+      s << "Entry : ";
       s << tag->second->GetName() << ",";
       s << tag->second->GetVR() << ", ";
       s << tag->second->GetFourth() << ", ";
-      s << "(" << std::hex << tag->second->GetGroup() << ',';
-      s << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl;
+      s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ',';
+      s << std::hex << std::setw(4) << tag->second->GetElement() << ") = ";
+      s << std::dec << std::endl;
    }
    os << s.str();
 }
index 1e1f0754e17e2e5bce3da000978df99639df9592..b901f57a9b78daef8f7e495fab0055c05570a3c2 100644 (file)
@@ -57,7 +57,6 @@ public:
    inline TagKeyHT & gdcmDict::GetEntries(void)  { return KeyHt; }
  
 private:
-   std::string name;
    std::string filename;
 
    /// Access through TagKey (see alternate access with NameHt)
index 5982f00cf3ec6452331333a78d2c78bd1741fb81..518eb728deebc892d337aa7d1ef36aa6d573c582 100644 (file)
@@ -121,10 +121,11 @@ std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryName
  * @param   Name Symbolic name that be used as identifier of the newly 
  *          created dictionary.
  */
-void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) 
+gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) 
 {
    gdcmDict *NewDict = new gdcmDict(FileName);
    AppendDict(NewDict,Name);
+   return(NewDict);
 }
 
 /**
@@ -163,7 +164,7 @@ gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
                                                 std::string name)
 {
    gdcmDictEntry *entry;
-   std::string tag=gdcmDictEntry::TranslateToKey(group,element)+vr;
+   std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
    std::map<std::string,gdcmDictEntry *>::iterator it;
    
    it=virtualEntry.find(tag);
index a992fc66fc3990b9d33a21fae8998aba39618c3c..e970b80bc899c89117f550cc6ba17c33130a5d23 100644 (file)
@@ -37,7 +37,7 @@ public:
    std::map<std::string, std::list<std::string> > *
        GetPubDictEntryNamesByCategory(void);
 
-   void LoadDictFromFile(std::string FileName, DictKey Name);
+   gdcmDict *LoadDictFromFile(std::string FileName, DictKey Name);
 
    gdcmDict *GetDict(DictKey DictName);
    gdcmDict *GetDefaultPubDict(void);
index 024862ddd77b5e9eec4d304630d8900f5b872216..e9d528117364d0e8927e902852e553ad8072a40a 100644 (file)
@@ -4,21 +4,8 @@
 
 #include <stdio.h>
 #include <cerrno>
-/*// For nthos:
-#ifdef _MSC_VER
-   #include <winsock.h>
-#else
-   #include <netinet/in.h>
-#endif*/
 #include <cctype>    // for isalpha
 
-/*#ifdef GDCM_NO_ANSI_STRING_STREAM
-#  include <strstream>
-#  define  ostringstream ostrstream
-# else
-#  include <sstream>
-#endif*/
-
 #include "gdcmUtil.h"
 #include "gdcmTS.h"
 
index f2e78cb82f5763196731f62d5f659b3c5ded7779..6ce3a9f8f1d6a7f18339923378db82fadb8bc6fd 100644 (file)
@@ -21,7 +21,7 @@
  * @param   in Pointer to existing dictionary entry
  */
 gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) {
-       ImplicitVr = false;
+       ImplicitVR = false;
        entry = in;
 }
 
@@ -39,65 +39,67 @@ void gdcmHeaderEntry::Print(std::ostream & os) {
    guint32 lgth;
    char greltag[10];  //group element tag
       
-      g = GetGroup();
-      e = GetElement();
-      v = GetValue();
-      o = GetOffset();
-      sprintf(greltag,"%04x|%04x ",g,e);           
-      d2 = _CreateCleanString(v);  // replace non printable characters by '.'
-      s << greltag ;
-          
-      if (printLevel>=2) { 
-         s << "lg : ";
-         lgth = GetReadLength();
-         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)) << " ";       
+   g = GetGroup();
+   e = GetElement();
+   v = GetValue();
+   o = GetOffset();
+   sprintf(greltag,"%04x|%04x ",g,e);           
+   d2 = _CreateCleanString(v);  // replace non printable characters by '.'
+   s << greltag ;
+       
+   if (printLevel>=2) { 
+      s << "lg : ";
+      lgth = GetReadLength();
+      if (lgth == 0xffffffff) {
+         sprintf(st,"x(%ff)");
+         s.setf(std::ios::left);
+         s << std::setw(10-strlen(st)) << " ";  
          s << st << " ";
-         s << std::setw(8) << o; 
-      }
-      if (printLevel>=1) {      
-         s << "[" << GetVR()  << "] ";
          s.setf(std::ios::left);
-         s << std::setw(66-GetName().length()) << " ";          
-      } 
-        
-      s << "[" << 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) << "]";   
+         s << std::setw(8) << "-1";      
       } else {
-         if (g == 0x0008) {
-            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();
+         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 << "[" << GetVR()  << "] ";
+
+   if (printLevel>=1) {      
+      s.setf(std::ios::left);
+      s << std::setw(66-GetName().length()) << " ";             
+   } 
+     
+   s << "[" << 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) << "]";   
+   } else {
+      if (g == 0x0008) {
+         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();
 }
 
 //-----------------------------------------------------------------------------
index 01f2bc74548bb6979c72ff1c33699478bf4eef17..20e23cebfe424a3b0c4de7e036b38624590caaa2 100644 (file)
@@ -52,27 +52,21 @@ public:
     * \ingroup gdcmHeaderEntry
     * \brief   Sets to TRUE the ImplicitVr flag of the current Dicom Element
     */
-   inline void gdcmHeaderEntry::SetImplicitVr(void) { 
-      ImplicitVr = true; 
-   };
+   inline void gdcmHeaderEntry::SetImplicitVR(void) { ImplicitVR = true; };
  
    /**
     * \ingroup gdcmHeaderEntry
     * \brief   tells us if the current Dicom Element was checked as ImplicitVr
     * @return true if the current Dicom Element was checked as ImplicitVr
     */ 
-   inline bool  gdcmHeaderEntry::IsImplicitVr(void) { 
-       return ImplicitVr; 
-    };
+   inline bool  gdcmHeaderEntry::IsImplicitVR(void) { return ImplicitVR; };
 
    /**
     * \ingroup gdcmHeaderEntry
     * \brief   tells us if the VR of the current Dicom Element is Unkonwn
     * @return true if the VR is unkonwn
     */ 
-   inline bool   gdcmHeaderEntry::IsVRUnknown(void) { 
-      return entry->IsVRUnknown(); 
-   };
+   inline bool   gdcmHeaderEntry::IsVRUnknown(void) { return entry->IsVRUnknown(); };
 
    /**
     * \ingroup gdcmHeaderEntry
@@ -88,17 +82,15 @@ public:
     * \brief   Gets the DicEntry of the current Dicom Element
     * @return  the DicEntry of the current Dicom Element
     */
-   gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { 
-      return entry;    
-   }; 
+   gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { return entry; }; 
 
    /**
     * \ingroup gdcmHeaderEntry
     * \brief   Sets the print level for the Dicom Header Elements
     * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy
     */
-   void  SetPrintLevel(int level) { printLevel = level; };
-   void                Print (std::ostream & os = std::cout); 
+   void SetPrintLevel(int level) { printLevel = level; };
+   void Print (std::ostream & os = std::cout); 
 
 private:
    // FIXME: In fact we should be more specific and use :
@@ -119,7 +111,7 @@ private:
                           // going on.
                           // *for internal* use only
        
-   bool ImplicitVr;       // Even when reading explicit vr files, some
+   bool ImplicitVR;       // Even when reading explicit vr files, some
                          // elements happen to be implicit. Flag them here
                          // since we can't use the entry->vr without breaking
                          // the underlying dictionary.
index ec1dcb9f06b7d4dcc2085e97aa9fdc7a2689f7e8..054604313d3c2c81bdb39af6b02a91b72f8e1534 100644 (file)
@@ -17,6 +17,7 @@
 # else
 #  include <sstream>
 #endif
+#  include <iomanip>
 
 //-----------------------------------------------------------------------------
 // Refer to gdcmParser::CheckSwap()
@@ -93,7 +94,7 @@ gdcmParser::~gdcmParser (void)
   *          both from the H Table and the chained list
   * @return
   */ 
-void gdcmParser::PrintPubEntry(std::ostream & os) 
+void gdcmParser::PrintEntry(std::ostream & os) 
 {
    std::ostringstream s;   
           
@@ -324,7 +325,6 @@ FILE *gdcmParser::OpenFile(bool exception_on_error)
     dbg.Verbose(0, "gdcmParser::gdcmParser not DICOM/ACR", filename.c_str());
   }
   else {
-    std::cerr<<filename.c_str()<<std::endl;
     dbg.Verbose(0, "gdcmParser::gdcmParser cannot open file", filename.c_str());
   }
   return(NULL);
@@ -760,9 +760,6 @@ bool gdcmParser::SetEntryVoidAreaByNumber(void * area,guint16 group, guint16 ele
  */
 void gdcmParser::UpdateShaEntries(void)
 {
-   if(!RefShaDict)
-      return;
-
    gdcmDictEntry *entry;
    std::string vr;
 
@@ -771,16 +768,33 @@ void gdcmParser::UpdateShaEntries(void)
        ++it)
    {
       // Odd group => from public dictionary
-      if((*it)->GetGroup()%1==0)
+      if((*it)->GetGroup()%2==0)
          continue;
 
       // Peer group => search the corresponding dict entry
-      entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
+      if(RefShaDict)
+         entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
+      else
+         entry=NULL;
+
+      if((*it)->IsImplicitVR())
+         vr="Implicit";
+      else
+         vr=(*it)->GetVR();
+
       if(entry)
       {
+         // Set the new entry and the new value
          (*it)->SetDictEntry(entry);
-         vr=(*it)->GetVR();
          CheckHeaderEntryVR(*it,vr);
+
+         (*it)->SetValue(GetHeaderEntryValue(*it));
+      }
+      else
+      {
+         // Remove precedent value transformation
+         (*it)->SetValue(GetHeaderEntryUnvalue(*it));
+         (*it)->SetDictEntry(NewVirtualDictEntry((*it)->GetGroup(),(*it)->GetElement(),vr));
       }
    }
 }
@@ -1086,6 +1100,17 @@ guint32 gdcmParser::SwapLong(guint32 a)
    return(a);
 }
 
+/**
+ * \ingroup gdcmParser
+ * \brief   Unswaps back the bytes of 4-byte long integer accordingly to
+ *          processor order.
+ * @return  The properly unswaped 32 bits integer.
+ */
+guint32 gdcmParser::UnswapLong(guint32 a) 
+{
+   return (SwapLong(a));
+}
+
 /**
  * \ingroup gdcmParser
  * \brief   Swaps the bytes so they agree with the processor order
@@ -1098,6 +1123,16 @@ guint16 gdcmParser::SwapShort(guint16 a)
    return (a);
 }
 
+/**
+ * \ingroup gdcmParser
+ * \brief   Unswaps the bytes so they agree with the processor order
+ * @return  The properly unswaped 16 bits integer.
+ */
+guint16 gdcmParser::UnswapShort(guint16 a) 
+{
+   return (SwapShort(a));
+}
+
 //-----------------------------------------------------------------------------
 // Private
 /**
@@ -1129,8 +1164,8 @@ void gdcmParser::LoadHeaderEntries(void)
       i != GetListEntry().end();
       ++i)
    {
-         LoadHeaderEntry(*i);
-   }   
+      LoadHeaderEntry(*i);
+   }
             
    rewind(fp);
 
@@ -1238,7 +1273,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
       guint32 NewInt;
       std::ostringstream s;
       int nbInt;
-      if (vr == "US" || vr == "SS") 
+      if (vr == "US" || vr == "SS")
       {
          nbInt = length / 2;
          NewInt = ReadInt16();
@@ -1253,7 +1288,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
             }
          }
                        
-      } 
+      }
       else if (vr == "UL" || vr == "SL") 
       {
          nbInt = length / 4;
@@ -1268,7 +1303,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
                s << NewInt;
             }
          }
-      }                                        
+      }
 #ifdef GDCM_NO_ANSI_STRING_STREAM
       s << std::ends; // to avoid oddities on Solaris
 #endif //GDCM_NO_ANSI_STRING_STREAM
@@ -1306,7 +1341,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
  * \        when position to be taken care of     
  * @param   newHeaderEntry
  */
-void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) 
+void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) 
 {
    tagHT.insert( PairHT( newHeaderEntry->GetKey(),newHeaderEntry) );
    listEntries.push_back(newHeaderEntry); 
@@ -1320,7 +1355,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry)
 
  * @return 
  */
- void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry * Entry) 
+ void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry *Entry) 
  {
    guint16 element = Entry->GetElement();
    guint16 group   = Entry->GetGroup();
@@ -1333,7 +1368,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry)
                      "we reached 7fe0 0010");
    }   
    
-   if ( (filetype == ExplicitVR) && ! Entry->IsImplicitVr() ) 
+   if ( (filetype == ExplicitVR) && (! Entry->IsImplicitVR()) ) 
    {
       if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) 
       {
@@ -1421,15 +1456,17 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry)
       FixHeaderEntryFoundLength(Entry, (guint32)length16);
       return;
    }
-
-   // Either implicit VR or a non DICOM conformal (see not below) explicit
-   // VR that ommited the VR of (at least) this element. Farts happen.
-   // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25
-   // on Data elements "Implicit and Explicit VR Data Elements shall
-   // not coexist in a Data Set and Data Sets nested within it".]
-   // Length is on 4 bytes.
-   FixHeaderEntryFoundLength(Entry, ReadInt32());
-   return;
+   else
+   {
+      // Either implicit VR or a non DICOM conformal (see not below) explicit
+      // VR that ommited the VR of (at least) this element. Farts happen.
+      // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25
+      // on Data elements "Implicit and Explicit VR Data Elements shall
+      // not coexist in a Data Set and Data Sets nested within it".]
+      // Length is on 4 bytes.
+      FixHeaderEntryFoundLength(Entry, ReadInt32());
+      return;
+   }
 }
 
 /**
@@ -1466,7 +1503,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *Entry)
       // avoid  .
       if ( Entry->IsVRUnknown() )
          Entry->SetVR("Implicit");
-      Entry->SetImplicitVr();
+      Entry->SetImplicitVR();
    }
 }
 
@@ -1480,7 +1517,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *Entry)
  * @return    false if the VR is incorrect of if the VR isn't referenced
  *            otherwise, it returns true
 */
-bool gdcmParser::CheckHeaderEntryVR   (gdcmHeaderEntry *Entry, VRKey vr)
+bool gdcmParser::CheckHeaderEntryVR(gdcmHeaderEntry *Entry, VRKey vr)
 {
    char msg[100]; // for sprintf
    bool RealExplicit = true;
@@ -1525,22 +1562,131 @@ bool gdcmParser::CheckHeaderEntryVR   (gdcmHeaderEntry *Entry, VRKey vr)
       // be unwise to overwrite the VR of a dictionary (since it would
       // compromise it's next user), we need to clone the actual DictEntry
       // and change the VR for the read one.
-      gdcmDictEntry* NewTag = NewVirtualDictEntry(Entry->GetGroup(),
-                                 Entry->GetElement(),
-                                 vr,
-                                 "FIXME",
-                                 Entry->GetName());
-      Entry->SetDictEntry(NewTag);
+      gdcmDictEntry* NewEntry = NewVirtualDictEntry(
+                                 Entry->GetGroup(),Entry->GetElement(),
+                                 vr,"FIXME",Entry->GetName());
+      Entry->SetDictEntry(NewEntry);
    }
    return(true); 
 }
 
 /**
  * \ingroup gdcmParser
- * \brief  Skip a given Header Entry 
+ * \brief   Get the transformed value of the header entry. The VR value 
+ *          is used to define the transformation to operate on the value
  * \warning NOT end user intended method !
- * @param entry 
- * @return 
+ * @param   Entry 
+ * @return  Transformed entry value
+ */
+std::string gdcmParser::GetHeaderEntryValue(gdcmHeaderEntry *Entry)
+{
+   if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) )
+   {
+      std::string val=Entry->GetValue();
+      std::string vr=Entry->GetVR();
+      guint32 length = Entry->GetLength();
+      std::ostringstream s;
+      int nbInt;
+
+      if (vr == "US" || vr == "SS")
+      {
+         guint16 NewInt16;
+
+         nbInt = length / 2;
+         for (int i=0; i < nbInt; i++) 
+         {
+            if(i!=0)
+               s << '\\';
+            NewInt16 = (val[2*i+0]&0xFF)+((val[2*i+1]&0xFF)<<8);
+            NewInt16 = SwapShort(NewInt16);
+            s << NewInt16;
+         }
+      }
+
+      else if (vr == "UL" || vr == "SL")
+      {
+         guint32 NewInt32;
+
+         nbInt = length / 4;
+         for (int i=0; i < nbInt; i++) 
+         {
+            if(i!=0)
+               s << '\\';
+            NewInt32=(val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24);
+            NewInt32=SwapLong(NewInt32);
+            s << NewInt32;
+         }
+      }
+
+#ifdef GDCM_NO_ANSI_STRING_STREAM
+      s << std::ends; // to avoid oddities on Solaris
+#endif //GDCM_NO_ANSI_STRING_STREAM
+      return(s.str());
+   }
+
+   return(Entry->GetValue());
+}
+
+/**
+ * \ingroup gdcmParser
+ * \brief   Get the reverse transformed value of the header entry. The VR 
+ *          value is used to define the reverse transformation to operate on
+ *          the value
+ * \warning NOT end user intended method !
+ * @param   Entry 
+ * @return  Reverse transformed entry value
+ */
+std::string gdcmParser::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry)
+{
+   if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) )
+   {
+      std::string vr=Entry->GetVR();
+      std::ostringstream s;
+      std::vector<std::string> tokens;
+      unsigned char *ptr;
+
+      if (vr == "US" || vr == "SS") 
+      {
+         guint16 NewInt16;
+
+         tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+         Tokenize (Entry->GetValue(), tokens, "\\");
+         for (unsigned int i=0; i<tokens.size();i++) 
+         {
+            NewInt16 = atoi(tokens[i].c_str());
+            s<<(NewInt16&0xFF)<<((NewInt16>>8)&0xFF);
+         }
+         tokens.clear();
+      }
+      if (vr == "UL" || vr == "SL") 
+      {
+         guint32 NewInt32;
+
+         tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+         Tokenize (Entry->GetValue(), tokens, "\\");
+         for (unsigned int i=0; i<tokens.size();i++) 
+         {
+            NewInt32 = atoi(tokens[i].c_str());
+            s<<(char)(NewInt32&0xFF)<<(char)((NewInt32>>8)&0xFF)
+               <<(char)((NewInt32>>16)&0xFF)<<(char)((NewInt32>>24)&0xFF);
+         }
+         tokens.clear();
+      }
+
+#ifdef GDCM_NO_ANSI_STRING_STREAM
+      s << std::ends; // to avoid oddities on Solaris
+#endif //GDCM_NO_ANSI_STRING_STREAM
+      return(s.str());
+   }
+
+   return(Entry->GetValue());
+}
+
+/**
+ * \ingroup gdcmParser
+ * \brief   Skip a given Header Entry 
+ * \warning NOT end user intended method !
+ * @param   entry 
  */
 void gdcmParser::SkipHeaderEntry(gdcmHeaderEntry *entry) 
 {
@@ -2145,11 +2291,11 @@ gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element,
 gdcmHeaderEntry *gdcmParser::NewHeaderEntryByNumber(guint16 Group, guint16 Elem) 
 {
    // Find out if the tag we encountered is in the dictionaries:
-   gdcmDictEntry *NewTag = GetDictEntryByNumber(Group, Elem);
-   if (!NewTag)
-      NewTag = NewVirtualDictEntry(Group, Elem);
+   gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
+   if (!DictEntry)
+      DictEntry = NewVirtualDictEntry(Group, Elem);
 
-   gdcmHeaderEntry* NewEntry = new gdcmHeaderEntry(NewTag);
+   gdcmHeaderEntry *NewEntry = new gdcmHeaderEntry(DictEntry);
    if (!NewEntry) 
    {
       dbg.Verbose(1, "gdcmParser::NewHeaderEntryByNumber",
index 54c6636cb8cdc536684059d71d320c9c3d973145..2ca4a793f1c21136b6854d139f9b4a474644fcf4 100644 (file)
@@ -48,7 +48,7 @@ public:
     * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
     */
    void SetPrintLevel(int level) { printLevel = level; };
-   virtual void PrintPubEntry(std::ostream &os = std::cout);
+   virtual void PrintEntry(std::ostream &os = std::cout);
    virtual void PrintPubDict (std::ostream &os = std::cout);
    virtual void PrintShaDict (std::ostream &os = std::cout);
 
@@ -98,7 +98,9 @@ public:
 // System access
    inline int GetSwapCode(void) { return sw; }
    guint16 SwapShort(guint16); // needed by gdcmFile
-   guint32 SwapLong(guint32);  // for JPEG Files
+   guint32 SwapLong(guint32);  // needed by gdcmFile
+   guint16 UnswapShort(guint16); // needed by gdcmFile
+   guint32 UnswapLong(guint32);  // needed by gdcmFile
 
 protected:
 // Entry
@@ -123,7 +125,7 @@ protected:
    gdcmHeaderEntry *GetHeaderEntryByName  (std::string Name);
    gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element); 
 
-   void LoadHeaderEntrySafe  (gdcmHeaderEntry *);
+   void LoadHeaderEntrySafe(gdcmHeaderEntry *);
 
    void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR);
    void WriteEntries(FileType type, FILE *);
@@ -146,6 +148,9 @@ private:
    void FindHeaderEntryVR    (gdcmHeaderEntry *);
    bool CheckHeaderEntryVR   (gdcmHeaderEntry *, VRKey);
 
+   std::string GetHeaderEntryValue  (gdcmHeaderEntry *);
+   std::string GetHeaderEntryUnvalue(gdcmHeaderEntry *);
+
    void SkipHeaderEntry          (gdcmHeaderEntry *);
    void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32);
    bool IsHeaderEntryAnInteger   (gdcmHeaderEntry *);
@@ -173,6 +178,7 @@ private:
                                       std::string vr = "Unknown",
                                       std::string fourth = "Unknown",
                                       std::string name   = "Unknown");
+   gdcmDictEntry *NewVirtualDictEntry(gdcmHeaderEntry *);
 
    // Deprecated (Not used)
    gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
index f3e89ab9b5e166218f10c16332a084eacb0f8212..531c4ee76e04d7781002a7ad2b044261190395ed 100644 (file)
 #endif
 #define DICT_TS "dicomTS.dic"
 
+#include <iostream>
+#ifdef GDCM_NO_ANSI_STRING_STREAM
+#  include <strstream>
+#  define  ostringstream ostrstream
+# else
+#  include <sstream>
+#endif
+
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-gdcmTS::gdcmTS(void) {
+gdcmTS::gdcmTS(void) 
+{
    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_TS);
    std::ifstream from(filename.c_str());
    dbg.Error(!from, "gdcmTS::gdcmTS: can't open dictionary",filename.c_str());
@@ -29,27 +38,46 @@ gdcmTS::gdcmTS(void) {
       from.getline(buff, 1024, '\n');
       name = buff;
 
-      if(key!="") {
+      if(key!="") 
+      {
          ts[key]=name;
       }
    }
    from.close();
 }
 
-gdcmTS::~gdcmTS() {
+gdcmTS::~gdcmTS() 
+{
    ts.clear();
 }
 
 //-----------------------------------------------------------------------------
 // Print
+/**
+ * \ingroup gdcmVR
+ * \brief   Print all 
+ * @param   os The output stream to be written to.
+ */
+void gdcmTS::Print(std::ostream &os) 
+{
+   std::ostringstream s;
+
+   for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it)
+   {
+      s << "TS : "<<it->first<<" = "<<it->second<<std::endl;
+   }
+   os << s.str();
+}
 
 //-----------------------------------------------------------------------------
 // Public
-int gdcmTS::Count(TSKey key) {
+int gdcmTS::Count(TSKey key) 
+{
    return ts.count(key);
 }
 
-std::string gdcmTS::GetValue(TSKey key) {
+std::string gdcmTS::GetValue(TSKey key) 
+{
    if (ts.count(key) == 0) 
       return (GDCM_UNFOUND);
    return ts[key];
index 7cd142bc14362332feca2f7f7048d2c01f7922a7..65b4a35d728e786fa387a5459feef9867d1da3fe 100644 (file)
@@ -6,6 +6,7 @@
 #include "gdcmCommon.h"
 #include <map>
 #include <string>
+#include <iostream>
 
 //-----------------------------------------------------------------------------
 typedef std::string TSKey;
@@ -21,6 +22,9 @@ class GDCM_EXPORT gdcmTS {
 public:
    gdcmTS(void);
    ~gdcmTS();
+
+   void Print(std::ostream &os = std::cout);
+
    int Count(TSKey key);
    std::string GetValue(TSKey key);
 
index 40143310270811fa753301afa7bf6ac6663befc2..b642db190e39a3950a25123f7b6e4b27e2f6d39c 100644 (file)
@@ -52,9 +52,9 @@ void gdcmDebug::Exit(int a) {
 }
 
 //-----------------------------------------------------------------------------
-gdcmVR      * gdcmGlobal::VR    = (gdcmVR*)0;
-gdcmTS      * gdcmGlobal::TS    = (gdcmTS*)0;
-gdcmDictSet * gdcmGlobal::Dicts = (gdcmDictSet*)0;
+gdcmVR      *gdcmGlobal::VR    = (gdcmVR *)0;
+gdcmTS      *gdcmGlobal::TS    = (gdcmTS *)0;
+gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0;
 gdcmGlobal gdcmGlob;
 
 gdcmGlobal::gdcmGlobal(void) {
@@ -71,15 +71,15 @@ gdcmGlobal::~gdcmGlobal() {
    delete Dicts;
 }
 
-gdcmVR * gdcmGlobal::GetVR(void) {
+gdcmVR *gdcmGlobal::GetVR(void) {
    return VR;
 }
 
-gdcmTS * gdcmGlobal::GetTS(void) {
+gdcmTS *gdcmGlobal::GetTS(void) {
    return TS;
 }
 
-gdcmDictSet * gdcmGlobal::GetDicts(void) {
+gdcmDictSet *gdcmGlobal::GetDicts(void) {
    return Dicts;
 }
 
@@ -113,7 +113,7 @@ void Tokenize (const std::string& str,
 
 ///////////////////////////////////////////////////////////////////////////
 // to prevent a flashing screen when non-printable character
-char * _cleanString(char *v) {
+char *_cleanString(char *v) {
    char *d;
    int i, l;
    l = strlen(v);
index 7b35b952b6eb373fcfcc2944059f3cc54bb7ea97..4c552409cfe2f191fbd439f1a60c207dde49d060 100644 (file)
@@ -42,14 +42,14 @@ private:
  * This class contains all globals elements that might be
  * instanciated only one time
  */
-class gdcmGlobal {
+class GDCM_EXPORT gdcmGlobal {
 public:
    gdcmGlobal(void);
    ~gdcmGlobal();
 
-   static gdcmVR * GetVR(void);
-   static gdcmTS * GetTS(void);
-   static gdcmDictSet * GetDicts(void);
+   static gdcmVR *GetVR(void);
+   static gdcmTS *GetTS(void);
+   static gdcmDictSet *GetDicts(void);
 
 private:
    static gdcmVR *VR;
@@ -66,7 +66,7 @@ void Tokenize (const std::string& str,
 
 extern gdcmDebug dbg;
 
-char * _cleanString(char *v);
+char *_cleanString(char *v);
 std::string _CreateCleanString(std::string s);
 
 //-----------------------------------------------------------------------------
index de4f1e1c2d2d46ba33cf484bf1e6c3dd419c195c..f002d0a083aa98525580bd8c0f11e3dfcd0c720b 100644 (file)
@@ -9,9 +9,18 @@
 #endif
 #define DICT_VR "dicomVR.dic"
 
+#include <iostream>
+#ifdef GDCM_NO_ANSI_STRING_STREAM
+#  include <strstream>
+#  define  ostringstream ostrstream
+# else
+#  include <sstream>
+#endif
+
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-gdcmVR::gdcmVR(void) {
+gdcmVR::gdcmVR(void) 
+{
    std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_VR);
    std::ifstream from(filename.c_str());
    dbg.Error(!from, "gdcmVR::gdcmVR: can't open dictionary",filename.c_str());
@@ -20,7 +29,8 @@ gdcmVR::gdcmVR(void) {
    std::string key;
    std::string name;
 
-   while (!from.eof()) {
+   while (!from.eof()) 
+   {
       eatwhite(from);
       from.getline(buff, 1024, ' ');
       key = buff;
@@ -45,10 +55,31 @@ gdcmVR::~gdcmVR() {
 
 //-----------------------------------------------------------------------------
 // Print
+/**
+ * \ingroup gdcmVR
+ * \brief   Print all 
+ * @param   os The output stream to be written to.
+ */
+void gdcmVR::Print(std::ostream &os) 
+{
+   std::ostringstream s;
+
+   for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it)
+   {
+      s << "VR : "<<it->first<<" = "<<it->second<<std::endl;
+   }
+   os << s.str();
+}
 
 //-----------------------------------------------------------------------------
 // Public
-int gdcmVR::Count(VRKey key) {
+/**
+ * \ingroup gdcmVR
+ * \brief   Get the count for an element
+ * @param   Key key to count
+ */
+int gdcmVR::Count(VRKey key) 
+{
    return vr.count(key);
 }
 
index 82663675463063eb3cf0af556e130a25505ec369..11ad35969fe7741a0b50f2a65ff941bde8940511 100644 (file)
@@ -6,6 +6,7 @@
 #include "gdcmCommon.h"
 #include <map>
 #include <string>
+#include <iostream>
 
 //-----------------------------------------------------------------------------
 typedef std::string VRKey;
@@ -17,10 +18,14 @@ typedef std::map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
  * Container for dicom Value Representation Hash Table
  * \note   This is a singleton
  */
-class GDCM_EXPORT gdcmVR {
+class GDCM_EXPORT gdcmVR 
+{
 public:
        gdcmVR(void);
    ~gdcmVR();
+
+   void Print(std::ostream &os = std::cout);
+
    int Count(VRKey key);
 
 private: