]> Creatis software - gdcm.git/commitdiff
Removal of QD patch for Private Sequence + Immplicit VR.
authorjpr <jpr>
Wed, 24 Aug 2005 12:09:12 +0000 (12:09 +0000)
committerjpr <jpr>
Wed, 24 Aug 2005 12:09:12 +0000 (12:09 +0000)
Add a clean solution (Backtracking if an Item Starter is found
    out of any SQItem)

src/gdcmDocEntry.cxx
src/gdcmDocEntry.h
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmElementSet.cxx

index 919913e3ae2fc97d763807273a22f509e9b10964..d8bb77755ae566ff4a39c0cc1c4c2e156b07bdca 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/08/23 12:58:49 $
-  Version:   $Revision: 1.62 $
+  Date:      $Date: 2005/08/24 12:09:12 $
+  Version:   $Revision: 1.63 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -175,6 +175,15 @@ bool DocEntry::IsItemDelimitor()
    return (GetGroup() == 0xfffe && GetElement() == 0xe00d);
 }
 
+/**
+ * \brief   tells us if entry is the first one of an Item 
+ *          (fffe,e000) 
+ */
+bool DocEntry::IsItemStarter()
+{
+   return (GetGroup() == 0xfffe && GetElement() == 0xe000);
+}
+
 /**
  * \brief   tells us if entry is the last one of a 'no length' Sequence 
  *          (fffe,e0dd) 
index 724c9b83465b4adb3531656df504ae3dd631be11..bb94d11b4f8861bf4bfe762a1832751a31f44fe8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/07/11 14:40:40 $
-  Version:   $Revision: 1.47 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.48 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -126,6 +126,7 @@ public:
    bool IsVMUnknown() { return DicomDict->IsVMUnknown(); };
 
    bool IsItemDelimitor();
+   bool IsItemStarter();
    bool IsSequenceDelimitor();   
    
    virtual void Copy(DocEntry *e);
index 19b7d39d15e54d2e2a1eb1ebbe551642e6bc37d6..666b72a100c506ae9fc422eb4a208d88980e14be 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/06/24 10:55:59 $
-  Version:   $Revision: 1.57 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.58 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -30,7 +30,10 @@ namespace gdcm
 {
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
-
+DocEntrySet::DocEntrySet() 
+{ 
+   PreviousDocEntry = 0;
+}
 //-----------------------------------------------------------------------------
 // Public
 /**
index a9a5b0c565588407d7d06445e6a823b683508fdc..5719f4660407bc25b521388e335b434cfa6890cd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2005/07/11 14:40:40 $
-  Version:   $Revision: 1.53 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.54 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -60,7 +60,7 @@ class GDCM_EXPORT DocEntrySet : public Base
 {
 public:
    /// Canonical Constructor
-   DocEntrySet() {};
+   DocEntrySet();
    /// Canonical Destructor
    virtual ~DocEntrySet() {};
 
@@ -130,6 +130,8 @@ protected:
    DictEntry *GetDictEntry(uint16_t group, uint16_t elem);
    DictEntry *GetDictEntry(uint16_t group, uint16_t elem,
                            TagName const &vr);
+   /// To be able to backtrack (Private Sequence, Implicit VR related pb)
+   DocEntry *PreviousDocEntry;
 
 private:
 };
index 4511aab548db6c6a17ba7bf003d49fbf75804b8c..1561e8f9e25767d59e521e936384cbc847b2abf7 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/08/23 14:41:59 $
-  Version:   $Revision: 1.266 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.267 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -906,7 +906,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
    VRKey vr;
    bool used;
    bool delim_mode_intern = delim_mode;
-
+   bool first = true;
    while (true)
    {
       if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
@@ -916,17 +916,31 @@ void Document::ParseDES(DocEntrySet *set, long offset,
 
       newDocEntry = ReadNextDocEntry( );
 
+      // Uncoment this printf line to be able to 'follow' the DocEntries
+      // when something *very* strange happens
+
+      printf( "%04x|%04x %s\n",newDocEntry->GetGroup(), 
+                           newDocEntry->GetElement(),
+                           newDocEntry->GetVR().c_str() );
+
       if ( !newDocEntry )
       {
          break;
       }
 
-      // Uncoment this printf line to be able to 'follow' the DocEntries
-      // when something *very* strange happens
-
-      //printf( "%04x|%04x %s\n",newDocEntry->GetGroup(), 
-      //                     newDocEntry->GetElement(),
-      //                     newDocEntry->GetVR().c_str() );
+       // an Item Starter found elsewhere but the first postition
+       // of a SeqEntry  means previous entry was a Sequence
+       // but we didn't get it (private Sequence + Implicit VR)
+       // we have to backtrack.
+      if ( !first && newDocEntry->IsItemStarter() )
+      {
+         newDocEntry = Backtrack(newDocEntry); 
+      }
+      else
+      { 
+         PreviousDocEntry = newDocEntry; 
+      }
       used = true;
       newValEntry = dynamic_cast<ValEntry*>(newDocEntry);
       newBinEntry = dynamic_cast<BinEntry*>(newDocEntry);
@@ -1038,24 +1052,9 @@ void Document::ParseDES(DocEntrySet *set, long offset,
 
             bool delimitor=newValEntry->IsItemDelimitor();
 
-            // FIXME : Brutal patch, waiting till we find a clever way to guess
-            //         if a doc entry is a Sequence, 
-            //          - when it's odd number
-            //          - and the file is Implicit VR Transfert Syntax
-            //
-            // '&& offset!=132' is a very fierce way to guess
-            //          if we are at zero level (Probabely not enough ...).
-            //          We want to go on parsing.
-            if ( (delimitor && offset!=132) || 
+            if ( (delimitor) || 
                 (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) )
             {
-               if (delimitor && offset!=132)
-               {
-                  gdcmWarningMacro( "in ParseDES : Item found out of a Sequence "
-                                  << newValEntry->GetKey()
-                                  << " (at offset : " 
-                                  << newValEntry->GetOffset() << " )" );
-               }
                if ( !used )
                   delete newDocEntry;
                break;
@@ -1154,6 +1153,7 @@ void Document::ParseDES(DocEntrySet *set, long offset,
       {
          delete newDocEntry;
       }
+      first = false;
    }                               // end While
 }
 
@@ -1233,6 +1233,41 @@ void Document::ParseSQ( SeqEntry *seqEntry,
    }
 }
 
+/**
+ * \brief   When a private Sequence + Implicit VR is encountered
+ *           we cannot guess it's a Sequence till we find the first
+ *           Item Starter. We then backtrack to do the job.
+ * @param   docEntry Item Starter that warned us 
+ */
+DocEntry *Document::Backtrack(DocEntry *docEntry)
+{
+   // delete the Item Starter, built erroneously out of any Sequence
+   // it's not yet in the HTable/chained list
+   delete docEntry;
+
+   // Get all info we can from PreviousDocEntry
+   uint16_t group = PreviousDocEntry->GetGroup();
+   uint16_t elem  = PreviousDocEntry->GetElement();
+   uint32_t lgt   = PreviousDocEntry->GetLength();
+   long offset    = PreviousDocEntry->GetOffset();
+
+   gdcmWarningMacro( "Backtrack :" << std::hex << group 
+                                   << "|" << elem
+                                   << " at offset " << offset );
+   RemoveEntry( PreviousDocEntry );
+
+   // forge the Seq Entry
+   DocEntry *newEntry = NewSeqEntry(group, elem);
+   newEntry->SetLength(lgt);
+   newEntry->SetOffset(offset);
+
+   // Move back to the beginning of the Sequence
+   Fp->seekg( 0, std::ios::beg);
+   Fp->seekg(offset, std::ios::cur);
+
+return newEntry;
+}
+
 /**
  * \brief   Loads the element content if its length doesn't exceed
  *          the value specified with Document::SetMaxSizeLoadEntry()
@@ -2207,7 +2242,7 @@ DocEntry *Document::ReadNextDocEntry()
    }
 
    newEntry->SetOffset(Fp->tellg());  
-
+   
    return newEntry;
 }
 
index c7c6fc71222b7940df5476736b617ecf78f80750..289500ba4ef05a069a3773308debf62ed92c944d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2005/07/30 18:19:44 $
-  Version:   $Revision: 1.118 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.119 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -215,6 +215,7 @@ private:
 
    void HandleBrokenEndian  (uint16_t &group, uint16_t &elem);
    void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem);
+   DocEntry *Backtrack(DocEntry *docEntry);
 
 // Variables
    /// Public dictionary used to parse this header
index 30db948fc89f50800d74bb238341b27e93d327ec..67ff023baf61206c95c6133a5f878439d028fc43 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/11 20:47:00 $
-  Version:   $Revision: 1.62 $
+  Date:      $Date: 2005/08/24 12:09:13 $
+  Version:   $Revision: 1.63 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -97,7 +97,7 @@ bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
       return true;
    }
 
-   gdcmWarningMacro( "Key not present");
+   gdcmWarningMacro( "Key not present : " << key);
    return false ;
 }
 
@@ -115,7 +115,7 @@ bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove)
       return true;
    }
 
-   gdcmWarningMacro( "Key not present");
+   gdcmWarningMacro( "Key not present " << key);
    return false ;
 }