]> Creatis software - gdcm.git/blobdiff - src/gdcmParser.cxx
* Bug fix on field having a VR = 'UI'. Assume that is a string field
[gdcm.git] / src / gdcmParser.cxx
index 362ca03fc8a9b9d48a40b6270d2210b2f8f362e1..384aa6e045beb73fd36eafe99c6ad616f2a64896 100644 (file)
 #endif
 #  include <iomanip>
 
+#define UI1_2_840_10008_1_2      "1.2.840.10008.1.2"
+#define UI1_2_840_10008_1_2_1    "1.2.840.10008.1.2.1"
+#define UI1_2_840_10008_1_2_2    "1.2.840.10008.1.2.2"
+#define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99"
+
 //-----------------------------------------------------------------------------
 // Refer to gdcmParser::CheckSwap()
 const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
@@ -184,9 +189,7 @@ bool gdcmParser::IsReadable(void)
 {
    std::string res = GetEntryByNumber(0x0028, 0x0005);
    if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) 
-   {
       return false; // Image Dimensions
-   }
 
    if ( !GetHeaderEntryByNumber(0x0028, 0x0100) )
       return false; // "Bits Allocated"
@@ -214,7 +217,7 @@ bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2" )
+   if ( Transfer == UI1_2_840_10008_1_2 )
       return true;
    return false;
 }
@@ -234,7 +237,7 @@ bool gdcmParser::IsExplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.1" )
+   if ( Transfer == UI1_2_840_10008_1_2_1 )
       return true;
    return false;
 }
@@ -254,7 +257,7 @@ bool gdcmParser::IsDeflatedExplicitVRLittleEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.1.99" )
+   if ( Transfer == UI1_2_840_10008_1_2_1_99 )
       return true;
    return false;
 }
@@ -274,7 +277,7 @@ bool gdcmParser::IsExplicitVRBigEndianTransferSyntax(void)
    LoadHeaderEntrySafe(Element);
 
    std::string Transfer = Element->GetValue();
-   if ( Transfer == "1.2.840.10008.1.2.2" )  //1.2.2 ??? A verifier !
+   if ( Transfer == UI1_2_840_10008_1_2_2 )  //1.2.2 ??? A verifier !
       return true;
    return false;
 }
@@ -375,7 +378,7 @@ bool gdcmParser::Write(FILE *fp, FileType type)
 
    if (type == ImplicitVR) 
    {
-      std::string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
+      std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
       ReplaceOrCreateByNumber(implicitVRTransfertSyntax,0x0002, 0x0010);
       
       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
@@ -387,7 +390,7 @@ bool gdcmParser::Write(FILE *fp, FileType type)
 
    if (type == ExplicitVR) 
    {
-      std::string explicitVRTransfertSyntax = "1.2.840.10008.1.2.1";
+      std::string explicitVRTransfertSyntax = UI1_2_840_10008_1_2_1;
       ReplaceOrCreateByNumber(explicitVRTransfertSyntax,0x0002, 0x0010);
       
       //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
@@ -1320,7 +1323,11 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)
       Entry->SetValue("gdcm::UnRead");
       return;
    }
-   Entry->SetValue(NewValue);
+
+   if( (vr == "UI") ) // Because of correspondance with the VR dic
+      Entry->SetValue(NewValue.c_str());
+   else
+      Entry->SetValue(NewValue);
 }
 
 /**
@@ -1603,7 +1610,8 @@ std::string gdcmParser::GetHeaderEntryValue(gdcmHeaderEntry *Entry)
          {
             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= (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;
          }
@@ -1634,7 +1642,6 @@ std::string gdcmParser::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry)
       std::string vr=Entry->GetVR();
       std::ostringstream s;
       std::vector<std::string> tokens;
-      unsigned char *ptr;
 
       if (vr == "US" || vr == "SS") 
       {