]> Creatis software - gdcm.git/blobdiff - src/gdcmParser.cxx
Zilch.
[gdcm.git] / src / gdcmParser.cxx
index cea36d4ec8f30adadf59d4497a59077c06882e85..871c8086f4b78cfcf61dd3f1380ba04d0343983d 100644 (file)
@@ -1,8 +1,7 @@
 // gdcmParser.cxx
 //-----------------------------------------------------------------------------
-#include "gdcmParser.h"
-#include "gdcmUtil.h"
 #include <errno.h>
+#include <vector>
 
 // For nthos:
 #ifdef _MSC_VER
 #endif
 #  include <iomanip>
 
+#include "gdcmParser.h"
+#include "gdcmUtil.h"
+#include "gdcmDebug.h"
+
 #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"
@@ -112,7 +115,7 @@ gdcmParser::gdcmParser(const char *inFilename,
    enableSequences=enable_sequences;
    ignoreShadow   =ignore_shadow;
    
-   SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
+   SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); 
    filename = inFilename;
    Initialise();
 
@@ -183,7 +186,7 @@ void gdcmParser::PrintPubDict(std::ostream & os) {
 
 /**
   * \ingroup gdcmParser
-  * \brief   Prints The Dict Entries of THE shadow Dicom Dictionnry
+  * \brief   Prints The Dict Entries of THE shadow Dicom Dictionnary
   * @return
   */
 void gdcmParser::PrintShaDict(std::ostream & os) {
@@ -437,7 +440,7 @@ bool gdcmParser::Write(FILE *fp, FileType type) {
       SetEntryLengthByNumber(20, 0x0002, 0x0010);
    }
 
-/* TODO : rewrite later
+/* TODO : rewrite later, if really usefull
 
    if ( (type == ImplicitVR) || (type == ExplicitVR) )
       UpdateGroupLength(false,type);
@@ -818,7 +821,7 @@ bool gdcmParser::SetEntryVoidAreaByNumber(void * area,
 /**
  * \ingroup gdcmParser
  * \brief   Update the entries with the shadow dictionary. 
- *          Only non even entries are  analyzed       
+ *          Only non even entries are analyzed       
  */
 void gdcmParser::UpdateShaEntries(void) {
    gdcmDictEntry *entry;
@@ -1056,14 +1059,6 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
    // TODO (?) tester les echecs en ecriture (apres chaque fwrite)
    int compte =0;
    itsTimeToWritePixels = false;
-     
-      // === Deal with the length
-      //     --------------------
-      if((tag->GetLength())%2==1)
-      { 
-         tag->SetValue(tag->GetValue()+"\0");
-         tag->SetLength(tag->GetReadLength()+1);
-      }
 
       gr    = tag->GetGroup();
       el    = tag->GetElement();
@@ -1071,6 +1066,14 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
       val   = tag->GetValue().c_str();
       vr    = tag->GetVR();
       voidArea = tag->GetVoidArea();
+           
+      // === Deal with the length
+      //     --------------------
+      if((tag->GetLength())%2==1)
+      { 
+         tag->SetValue(tag->GetValue()+"\0");
+         tag->SetLength(tag->GetReadLength()+1);
+      }
       
       if ( type == ACR ) 
       { 
@@ -1090,7 +1093,14 @@ void gdcmParser::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type)
          guint16 z=0, shortLgr;
         
          if (gr == 0xfffe) { // NO Value Representation for 'delimiters'
-               // no length : write ffffffff           
+                             // no length : write ffffffff
+                                                    
+                                        // special patch to make some MR PHILIPS
+             if (el == 0x0000) return;  // images e-film readable                                      // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm
+                                       // from Hospital Guy de Chauliac,
+                                        // Montpellier
+                                       // we just ignore spurious fffe|0000 tag !
+                       
             fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp);
             return;       // NO value for 'delimiters'                     
         }
@@ -1466,7 +1476,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry)  {
    }
 
    if( (vr == "UI") ) // Because of correspondance with the VR dic
-      Entry->SetValue(NewValue.c_str()); // ??? JPR ???
+      Entry->SetValue(NewValue.c_str());
    else
       Entry->SetValue(NewValue);
 }
@@ -1891,25 +1901,14 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found
    } 
     
    // a SeQuence Element is beginning                                          
-   // Let's forget it's length                                                 
-   // (we want to 'go inside')  
-
-   // Pb : *normaly*  fffe|e000 is just a marker, its length *should be* zero
-   // in gdcm-MR-PHILIPS-16-Multi-Seq.dcm we find lengthes as big as 28800
-   // if we set the length to zero IsHeaderEntryAnInteger() breaks...
-   // if we don't, we lost 28800 characters from the Header :-(
-                                                 
+   // fffe|e000 is just a marker, its length *should be* zero                                               
    else if(Entry->GetGroup() == 0xfffe)
    { 
-  // cout << "ReadLength " <<Entry->GetReadLength() << " UsableLength " << FoundLength << endl;  
-  //   Entry->Print();                                                           
-                       // sometimes, length seems to be wrong                                      
-      FoundLength =0;  // some more clever checking to be done !
-                       // I give up!
-                      // only  gdcm-MR-PHILIPS-16-Multi-Seq.dcm
-                      // causes troubles :-(                  
-   }     
-    
+                                         // *normally, fffe|0000 doesn't exist ! 
+     if( Entry->GetElement() != 0x0000 ) // gdcm-MR-PHILIPS-16-Multi-Seq.dcm
+                                        // causes extra troubles :-(                                                        
+         FoundLength =0;
+   }         
    Entry->SetUsableLength(FoundLength);
 }
 
@@ -1982,7 +1981,7 @@ bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) {
          return 0;
       TotalLength += 4;  // We even have to decount the group and element 
      
-      if ( g != 0xfffe && g!=0xb00c ) /*for bogus header */ 
+      if ( g != 0xfffe && g!=0xb00c ) //for bogus header  
       {
          char msg[100]; // for sprintf. Sorry
          sprintf(msg,"wrong group (%04x) for an item sequence (%04x,%04x)\n",g, g,n);
@@ -1990,7 +1989,7 @@ bool gdcmParser::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) {
          errno = 1;
          return 0;
       }
-      if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) /* for bogus header  */ 
+      if ( n == 0xe0dd || ( g==0xb00c && n==0x0eb6 ) ) // for bogus header 
          FoundSequenceDelimiter = true;
       else if ( n != 0xe000 )
       {
@@ -2407,15 +2406,15 @@ gdcmHeaderEntry *gdcmParser::ReadNextHeaderEntry(void) {
       // header parsing has to be considered as finished.
       return (gdcmHeaderEntry *)0;
 
-/ Pb : how to propagate the element length (used in SkipHeaderEntry)
+// Pb : how to propagate the element length (used in SkipHeaderEntry)
 //       direct call to SkipBytes ?
    
-   if (ignoreShadow == 1 && g%2 ==1)  //JPR
+//   if (ignoreShadow == 1 && g%2 ==1)
       // if user wants to skip shadow groups
       // and current element *is* a shadow element
       // we don't create anything
-      return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished
-*/   
+//      return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished
+  
    NewEntry = NewHeaderEntryByNumber(g, n);
    FindHeaderEntryVR(NewEntry);
    FindHeaderEntryLength(NewEntry);