From 9a1c462c4bd36bd29efc949d74332f3e19bb9638 Mon Sep 17 00:00:00 2001 From: jpr Date: Mon, 29 Aug 2005 13:05:01 +0000 Subject: [PATCH] Add void Document::AddForceLoadElement(uint16_t group, uint16_t elem); method to allow forcing the loading of some elements, even if they exceed the current MAX_SIZE_LOAD_ELEMENT_VALUE (default : 4096) --- src/gdcmBinEntry.cxx | 9 ++-- src/gdcmDocument.cxx | 119 ++++++++++++++++++++++++++++++------------- src/gdcmDocument.h | 14 +++-- src/gdcmFile.cxx | 28 +++++----- src/gdcmFile.h | 6 +-- 5 files changed, 114 insertions(+), 62 deletions(-) diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index fdbda3f1..3e150aaa 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2005/08/25 14:59:49 $ - Version: $Revision: 1.74 $ + Date: $Date: 2005/08/29 13:05:01 $ + Version: $Revision: 1.75 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -170,7 +170,7 @@ void BinEntry::Print(std::ostream &os, std::string const & ) s << "]"; } else - { + { if ( Util::IsCleanArea( GetBinArea(),GetLength() ) ) { std::string cleanString = @@ -181,8 +181,7 @@ void BinEntry::Print(std::ostream &os, std::string const & ) { s << " [" << GetValue() << "; length = " << GetLength() << "]"; - } - + } } } else diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 4f2ad927..8177c017 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/29 09:41:22 $ - Version: $Revision: 1.269 $ + Date: $Date: 2005/08/29 13:05:01 $ + Version: $Revision: 1.270 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -258,6 +258,37 @@ bool Document::DoTheLoadingDocumentJob( ) } } + // Force Loading some more elements if user asked to. + + gdcm::DocEntry *d; + for (ListElements::iterator it = UserForceLoadList.begin(); + it != UserForceLoadList.end(); + ++it) + { + d = GetDocEntry( (*it).Group, (*it).Elem); + + if ( d == NULL) + continue; + + if ( dynamic_cast(d) ) + { + LoadDocEntry(d, true); + continue; + } + + if ( dynamic_cast(d) ) + { + LoadEntryBinArea((*it).Group, (*it).Elem); + continue; + } + + if ( dynamic_cast(d) ) + { + gdcmWarningMacro( "You cannot 'ForceLoad' a SeqEntry "); + continue; + } + } + CloseFile(); // ---------------------------- @@ -283,10 +314,22 @@ bool Document::DoTheLoadingDocumentJob( ) SetValEntry(rows , 0x0028, 0x0011); } // --- End of ACR-LibIDO kludge --- - return true; } + +/** + * \brief Adds a new element we want to load anyway + * @param group Group number of the target tag. + * @param elem Element number of the target tag. + */ +void Document::AddForceLoadElement (uint16_t group, uint16_t elem) +{ + Element el; + el.Group = group; + el.Elem = elem; + UserForceLoadList.push_back(el); +} /** * \brief Get the public dictionary used */ @@ -1270,11 +1313,13 @@ return newEntry; } /** - * \brief Loads the element content if its length doesn't exceed - * the value specified with Document::SetMaxSizeLoadEntry() + * \brief Loads (or not) the element content depending if its length exceeds + * or not the value specified with Document::SetMaxSizeLoadEntry() * @param entry Header Entry (Dicom Element) to be dealt with + * @param forceLoad wheter we want to load its content even if its length + * exceeds the value specified with Document::SetMaxSizeLoadEntry() */ -void Document::LoadDocEntry(DocEntry *entry) +void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) { uint16_t group = entry->GetGroup(); std::string vr = entry->GetVR(); @@ -1304,37 +1349,41 @@ void Document::LoadDocEntry(DocEntry *entry) // the element content and it's length. std::ostringstream s; - if (length > MaxSizeLoadEntry) - { - if (BinEntry *binEntryPtr = dynamic_cast< BinEntry* >(entry) ) - { - s << GDCM_NOTLOADED; - s << " Ad.:" << (long)entry->GetOffset(); - s << " x(" << std::hex << entry->GetOffset() << ")"; - s << std::dec; - s << " Lgt:" << entry->GetLength(); - s << " x(" << std::hex << entry->GetLength() << ")"; - binEntryPtr->SetValue(s.str()); - } - else if (ValEntry *valEntryPtr = dynamic_cast< ValEntry* >(entry) ) - { - s << GDCM_NOTLOADED; - s << " Address:" << (long)entry->GetOffset(); - s << " Length:" << entry->GetLength(); - s << " x(" << std::hex << entry->GetLength() << ")"; - valEntryPtr->SetValue(s.str()); - } - else + + if (!forceLoad) + { + if (length > MaxSizeLoadEntry) { - // fusible - gdcmErrorMacro( "MaxSizeLoadEntry exceeded, neither a BinEntry " - << "nor a ValEntry ?! Should never print that !" ); - } + if (BinEntry *binEntryPtr = dynamic_cast< BinEntry* >(entry) ) + { + s << GDCM_NOTLOADED; + s << " Ad.:" << (long)entry->GetOffset(); + s << " x(" << std::hex << entry->GetOffset() << ")"; + s << std::dec; + s << " Lgt:" << entry->GetLength(); + s << " x(" << std::hex << entry->GetLength() << ")"; + binEntryPtr->SetValue(s.str()); + } + else if (ValEntry *valEntryPtr = dynamic_cast< ValEntry* >(entry) ) + { + s << GDCM_NOTLOADED; + s << " Address:" << (long)entry->GetOffset(); + s << " Length:" << entry->GetLength(); + s << " x(" << std::hex << entry->GetLength() << ")"; + valEntryPtr->SetValue(s.str()); + } + else + { + // fusible + gdcmErrorMacro( "MaxSizeLoadEntry exceeded, neither a BinEntry " + << "nor a ValEntry ?! Should never print that !" ); + } - // to be sure we are at the end of the value ... - Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(), - std::ios::beg); - return; + // to be sure we are at the end of the value ... + Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(), + std::ios::beg); + return; + } } // When we find a BinEntry not very much can be done : diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 289500ba..b89d15c5 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/08/24 12:09:13 $ - Version: $Revision: 1.119 $ + Date: $Date: 2005/08/29 13:05:01 $ + Version: $Revision: 1.120 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -100,6 +100,7 @@ typedef std::list ListElements; virtual void LoadEntryBinArea(BinEntry *entry); void LoadDocEntrySafe(DocEntry *entry); + void AddForceLoadElement(uint16_t group, uint16_t elem); // Ordering of Documents bool operator<(Document &document); @@ -166,8 +167,11 @@ protected: /// are NOT loaded. static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE; - /// List of elements to Anonymize - ListElements AnonymizeList; + /// User supplied list of elements to Anonymize + ListElements UserAnonymizeList; + + /// User supplied list of elements to force Load + ListElements UserForceLoadList; /// \brief Bit string integer (each one considered as a boolean) /// Bit 0 : Skip Sequences, if possible @@ -191,7 +195,7 @@ private: void ParseDES(DocEntrySet *set, long offset, long l_max, bool delim_mode); void ParseSQ (SeqEntry *seq, long offset, long l_max, bool delim_mode); - void LoadDocEntry (DocEntry *e); + void LoadDocEntry (DocEntry *e, bool forceLoad = false); void FindDocEntryLength (DocEntry *e) throw ( FormatError ); uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected ); std::string FindDocEntryVR(); diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index f79b64e7..1e90cccb 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/07/30 18:17:08 $ - Version: $Revision: 1.264 $ + Date: $Date: 2005/08/29 13:05:01 $ + Version: $Revision: 1.265 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1289,7 +1289,7 @@ void File::AddAnonymizeElement (uint16_t group, uint16_t elem, el.Group = group; el.Elem = elem; el.Value = value; - AnonymizeList.push_back(el); + UserAnonymizeList.push_back(el); } /** @@ -1305,8 +1305,8 @@ void File::AnonymizeNoLoad() uint32_t lgth; uint32_t valLgth = 0; std::string *spaces; - for (ListElements::iterator it = AnonymizeList.begin(); - it != AnonymizeList.end(); + for (ListElements::iterator it = UserAnonymizeList.begin(); + it != UserAnonymizeList.end(); ++it) { d = GetDocEntry( (*it).Group, (*it).Elem); @@ -1314,11 +1314,11 @@ void File::AnonymizeNoLoad() if ( d == NULL) continue; - if ( dynamic_cast(d) ) - { - gdcmWarningMacro( "You cannot 'Anonymize a SeqEntry "); - continue; - } + if ( dynamic_cast(d) ) + { + gdcmWarningMacro( "You cannot 'Anonymize' a SeqEntry "); + continue; + } offset = d->GetOffset(); lgth = d->GetLength(); @@ -1344,7 +1344,7 @@ void File::AnonymizeNoLoad() bool File::AnonymizeFile() { // If Anonymisation list is empty, let's perform some basic anonymization - if ( AnonymizeList.begin() == AnonymizeList.end() ) + if ( UserAnonymizeList.begin() == UserAnonymizeList.end() ) { // If exist, replace by spaces SetValEntry (" ",0x0010, 0x2154); // Telephone @@ -1362,15 +1362,15 @@ bool File::AnonymizeFile() } else { - SetValEntry("anonymised", 0x0010, 0x0010); + SetValEntry("anonymized", 0x0010, 0x0010); } } } else { gdcm::DocEntry *d; - for (ListElements::iterator it = AnonymizeList.begin(); - it != AnonymizeList.end(); + for (ListElements::iterator it = UserAnonymizeList.begin(); + it != UserAnonymizeList.end(); ++it) { d = GetDocEntry( (*it).Group, (*it).Elem); diff --git a/src/gdcmFile.h b/src/gdcmFile.h index ef3fac78..57ef7d10 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.h,v $ Language: C++ - Date: $Date: 2005/07/24 02:34:42 $ - Version: $Revision: 1.115 $ + Date: $Date: 2005/08/29 13:05:02 $ + Version: $Revision: 1.116 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -167,7 +167,7 @@ public: void AddAnonymizeElement (uint16_t group, uint16_t elem, std::string const &value); /// Clears the list of elements to be anonymized - void ClearAnonymizeList() { AnonymizeList.clear(); } + void ClearAnonymizeList() { UserAnonymizeList.clear(); } void AnonymizeNoLoad(); /// Replace patient's own information by info from the Anonymization list bool AnonymizeFile(); -- 2.45.1