From: jpr Date: Wed, 24 Aug 2005 12:09:12 +0000 (+0000) Subject: Removal of QD patch for Private Sequence + Immplicit VR. X-Git-Tag: Version1.2.bp~205 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=b0f62020f3423bf7663fdf856000dc245e417d9a;p=gdcm.git Removal of QD patch for Private Sequence + Immplicit VR. Add a clean solution (Backtracking if an Item Starter is found out of any SQItem) --- diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 919913e3..d8bb7775 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -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) diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index 724c9b83..bb94d11b 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -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); diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index 19b7d39d..666b72a1 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -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 /** diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index a9a5b0c5..5719f466 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -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: }; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 4511aab5..1561e8f9 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -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(newDocEntry); newBinEntry = dynamic_cast(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; } diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index c7c6fc71..289500ba 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -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 diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 30db948f..67ff023b 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -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 ; }