From 1d9ac5cec02b9daa18b16835882b531731b125ad Mon Sep 17 00:00:00 2001 From: regrain Date: Tue, 18 Oct 2005 12:58:23 +0000 Subject: [PATCH] * Correctly use the VRKey for all vr variables... instead of TagName or std::string * Replace the definition of VRKey from std::string to a class containing a char[2]. All methods are inline to have no speed low * Create the GDCM_VRUNKNOWN = " " for the VR values -- BeNours --- ChangeLog | 7 ++ Example/exReadWriteFile.cxx | 6 +- Testing/TestVR.cxx | 84 ++++++++++++++++++------ gdcmPython/gdcm.i | 15 +++-- src/gdcmCommon.h | 45 ++++++++----- src/gdcmDebug.h | 5 +- src/gdcmDict.cxx | 8 +-- src/gdcmDictEntry.cxx | 12 ++-- src/gdcmDictEntry.h | 16 ++--- src/gdcmDictSet.cxx | 14 ++-- src/gdcmDictSet.h | 10 +-- src/gdcmDocEntry.cxx | 16 ++--- src/gdcmDocEntry.h | 6 +- src/gdcmDocEntrySet.cxx | 39 +++-------- src/gdcmDocEntrySet.h | 17 ++--- src/gdcmDocument.cxx | 43 +++++++------ src/gdcmDocument.h | 8 +-- src/gdcmFile.cxx | 6 +- src/gdcmFileHelper.cxx | 8 +-- src/gdcmFileHelper.h | 6 +- src/gdcmGlobal.cxx | 7 +- src/gdcmSystem.h | 15 +---- src/gdcmVR.h | 7 +- src/gdcmVRKey.h | 125 ++++++++++++++++++++++++++++++++++++ 24 files changed, 348 insertions(+), 177 deletions(-) create mode 100644 src/gdcmVRKey.h diff --git a/ChangeLog b/ChangeLog index b8fb98f3..95344efe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Oct 18 10:27:49 2005 by regrain + * Correctly use the VRKey for all vr variables... instead of TagName + or std::string + * Replace the definition of VRKey from std::string to a class + containing a char[2]. All methods are inline to have no speed low + * Create the GDCM_VRUNKNOWN = " " for the VR values + Mon Oct 18 10:27:49 2005 by regrain * Remove useless constructor of gdcm::Document * Remove useless parameter in the constructor of gdcm::ElementSet diff --git a/Example/exReadWriteFile.cxx b/Example/exReadWriteFile.cxx index 3666c6ee..37f5b6e2 100644 --- a/Example/exReadWriteFile.cxx +++ b/Example/exReadWriteFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exReadWriteFile.cxx,v $ Language: C++ - Date: $Date: 2005/10/18 08:35:44 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/10/18 12:58:24 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -81,7 +81,7 @@ std::cout << " --- WARNING --- WARNING --- WARNING --- WARNING ---" <Print(); - // std::cout << "----- end Test Default VR Dictionary : -----" << std::endl; - - // Lets delete it. - delete tempVrDict; - + int error = 0; gdcm::VR *vr = new gdcm::VR(); // There should be 16 entries ... vr->Print( std::cout ); - vr->IsVROfStringRepresentable( "PN" ); - vr->IsVROfStringRepresentable( "FD" ); + // Valid VR + if( !vr->IsValidVR( "PN" ) ) + { + std::cerr << "'PN' is not a valid VR" << std::endl; + error++; + } + if( !vr->IsValidVR( "FD" ) ) + { + std::cerr << "'FD' is not a valid VR" << std::endl; + error++; + } + if( vr->IsValidVR( "" ) ) + { + std::cerr << "'' is a valid VR" << std::endl; + error++; + } + if( vr->IsValidVR( " " ) ) + { + std::cerr << "' ' is a valid VR" << std::endl; + error++; + } + if( vr->IsValidVR( gdcm::GDCM_VRUNKNOWN ) ) + { + std::cerr << "' ' is a valid VR" << std::endl; + error++; + } + + // String representable + if( !vr->IsVROfStringRepresentable( "PN" ) ) + { + std::cerr << "'PN' is not a string representable" << std::endl; + error++; + } + if( vr->IsVROfStringRepresentable( "FD" ) ) + { + std::cerr << "'FD' is a string representable" << std::endl; + error++; + } + + // Binary representable + if( !vr->IsVROfBinaryRepresentable( "FD" ) ) + { + std::cerr << "FD is not a binary representable" << std::endl; + error++; + } + if( vr->IsVROfBinaryRepresentable( "PN" ) ) + { + std::cerr << "'PN' is a binary representable" << std::endl; + error++; + } - vr->IsVROfBinaryRepresentable( "FD" ); - vr->IsVROfBinaryRepresentable( "PN" ); + // Sequence + if( vr->IsVROfSequence( "" ) ) + { + std::cerr << "'' is a sequence" << std::endl; + error++; + } + if( !vr->IsVROfSequence( "SQ" ) ) + { + std::cerr << "'SQ' is not a sequence" << std::endl; + error++; + } - vr->IsVROfSequence( "" ); - vr->IsVROfSequence( "SQ" ); delete vr; - return 0; + return error; } diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 303719e0..817e7c6c 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -216,14 +216,17 @@ typedef unsigned long long uint64_t; %ignore GDCM_NOTASCII; %ignore GDCM_PIXELDATA; %ignore GDCM_LEGACY; +%ignore GDCM_VRUNKNOWN; -%constant const char *UNKNOWN = "gdcm::Unknown"; -%constant const char *UNFOUND = "gdcm::Unfound"; -%constant const char *BINLOADED = "gdcm::Binary data loaded"; -%constant const char *NOTLOADED = "gdcm::NotLoaded"; -%constant const char *UNREAD = "gdcm::UnRead"; -%constant const char *GDCM_NOTASCII = "gdcm::NotAscii"; +%constant const char *UNKNOWN = "gdcm::Unknown"; +%constant const char *UNFOUND = "gdcm::Unfound"; +%constant const char *BINLOADED = "gdcm::Binary data loaded"; +%constant const char *NOTLOADED = "gdcm::NotLoaded"; +%constant const char *UNREAD = "gdcm::UnRead"; +%constant const char *GDCM_NOTASCII = "gdcm::NotAscii"; %constant const char *GDCM_PIXELDATA = "gdcm::Pixel Data to be loaded"; +%constant const char *VRUNKNOWN = " "; + //////////////////////////////////////////////////////////////////////////// // Warning: Order matters ! %include "gdcmCommon.h" diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index 27c4e90a..b6fdd0bf 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmCommon.h,v $ Language: C++ - Date: $Date: 2005/10/18 09:17:08 $ - Version: $Revision: 1.94 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.95 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,6 +22,18 @@ #include "gdcmConfigure.h" #include "gdcmSystem.h" +#define FASTTAGKEY 0 + +// FIXME: Should rewrite this: +#if FASTTAGKEY + #include + #include +#endif + #if defined(_MSC_VER) && (_MSC_VER == 1200) + /* ostream operator for std::string since VS6 does not provide it*/ + #include +#endif + //----------------------------------------------------------------------------- /// \brief namespace for Grass root DiCoM namespace gdcm @@ -45,6 +57,9 @@ GDCM_EXPORT extern const std::string GDCM_NOTLOADED; GDCM_EXPORT extern const std::string GDCM_UNREAD; GDCM_EXPORT extern const std::string GDCM_NOTASCII; GDCM_EXPORT extern const std::string GDCM_PIXELDATA; + +GDCM_EXPORT extern const std::string GDCM_VRUNKNOWN; + /// \brief TagKey is made to hold the standard Dicom Tag /// (Group number, Element number) /// Instead of using the two '16 bits integers' as the Hask Table key, we @@ -61,25 +76,25 @@ typedef union { /* ostream operator for TagKey */ inline std::ostream& operator<<(std::ostream& _O, TagKey _val) { - _O.setf( std::ios::right); - return (_O << std::hex << std::setw( 4 ) << std::setfill( '0' ) - << _val.tab[0] << '|' << std::setw( 4 ) << std::setfill( '0' ) - << _val.tab[1] << std::setfill( ' ' ) << std::dec); + _O.setf( std::ios::right); + return (_O << std::hex << std::setw( 4 ) << std::setfill( '0' ) + << _val.tab[0] << '|' << std::setw( 4 ) << std::setfill( '0' ) + << _val.tab[1] << std::setfill( ' ' ) << std::dec); } inline bool operator==(TagKey _self, TagKey _val) { - return _self.tagkey == _val.tagkey; + return _self.tagkey == _val.tagkey; } inline bool operator<(TagKey _self, TagKey _val) { - // This expression is a tad faster but PrintFile output - // is more difficult to read - //return _self.tagkey < _val.tagkey; - - // More usal order of dicom tags: - if( _self.tab[0] == _val.tab[0] ) - return _self.tab[1] < _val.tab[1]; - return _self.tab[0] < _val.tab[0]; + // This expression is a tad faster but PrintFile output + // is more difficult to read + //return _self.tagkey < _val.tagkey; + + // More usal order of dicom tags: + if( _self.tab[0] == _val.tab[0] ) + return _self.tab[1] < _val.tab[1]; + return _self.tab[0] < _val.tab[0]; } #else typedef std::string TagKey; diff --git a/src/gdcmDebug.h b/src/gdcmDebug.h index c7f7d65f..d3144f6a 100644 --- a/src/gdcmDebug.h +++ b/src/gdcmDebug.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDebug.h,v $ Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.42 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.43 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -21,6 +21,7 @@ #include "gdcmCommon.h" +#include #include #include #include diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 5744e790..321f168a 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.cxx,v $ Language: C++ - Date: $Date: 2005/09/02 07:00:04 $ - Version: $Revision: 1.79 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.80 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -279,7 +279,7 @@ void Dict::DoTheLoadingJob(std::ifstream &from) { uint16_t group; uint16_t elem; - TagName vr; + VRKey vr; TagName vm; TagName name; @@ -293,7 +293,7 @@ void Dict::DoTheLoadingJob(std::ifstream &from) from >> std::ws; //remove white space std::getline(from, name); - const DictEntry newEntry(group, elem, vr, vm, name); + DictEntry newEntry(group, elem, vr, vm, name); AddEntry(newEntry); } from.close(); diff --git a/src/gdcmDictEntry.cxx b/src/gdcmDictEntry.cxx index 3e88c55f..ed1052af 100644 --- a/src/gdcmDictEntry.cxx +++ b/src/gdcmDictEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.cxx,v $ Language: C++ - Date: $Date: 2005/07/11 15:20:46 $ - Version: $Revision: 1.51 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.52 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,7 +38,7 @@ namespace gdcm */ DictEntry::DictEntry(uint16_t group, uint16_t elem, - TagName const &vr, + VRKey const &vr, TagName const &vm, TagName const &name) { @@ -57,7 +57,7 @@ DictEntry::DictEntry(uint16_t group, uint16_t elem, * \ is unset then overwrite it. * @param vr New V(alue) R(epresentation) to be set. */ -void DictEntry::SetVR(TagName const &vr) +void DictEntry::SetVR(VRKey const &vr) { if ( IsVRUnknown() ) { @@ -127,11 +127,11 @@ TagKey DictEntry::TranslateToKey(uint16_t group, uint16_t elem) */ void DictEntry::Print(std::ostream &os, std::string const & ) { - std::string vr; + VRKey vr; std::ostringstream s; vr = GetVR(); - if ( vr==GDCM_UNKNOWN ) + if ( IsVRUnknown() ) vr=" "; s << DictEntry::TranslateToKey(GetGroup(),GetElement()); diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 11425127..2b651f2b 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.h,v $ Language: C++ - Date: $Date: 2005/10/18 08:35:49 $ - Version: $Revision: 1.36 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.37 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,10 +20,10 @@ #define GDCMDICTENTRY_H #include "gdcmBase.h" +#include "gdcmVRKey.h" namespace gdcm { - //----------------------------------------------------------------------------- /** * \brief @@ -41,7 +41,7 @@ class GDCM_EXPORT DictEntry : public Base public: DictEntry(uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN, + VRKey const &vr = GDCM_VRUNKNOWN, TagName const &vm = GDCM_UNKNOWN, TagName const &name = GDCM_UNKNOWN); @@ -49,12 +49,12 @@ public: void Print(std::ostream &os = std::cout, std::string const &indent = ""); // Content of DictEntry - void SetVR(TagName const &vr); + void SetVR(VRKey const &vr); void SetVM(TagName const &vm); /// \brief tells if the V(alue) R(epresentation) is known (?!) /// @return - bool IsVRUnknown() const { return VR == GDCM_UNKNOWN; } + bool IsVRUnknown() const { return VR == GDCM_VRUNKNOWN; } /// \brief tells if the V(alue) M(ultiplicity) is known (?!) /// @return @@ -71,7 +71,7 @@ public: /// \brief Returns the Dicom Value Representation of the current /// DictEntry /// @return the Dicom Value Representation - const TagName &GetVR() const { return VR; } + const VRKey &GetVR() const { return VR; } /// \brief sets the key of the current DictEntry /// @param k New key to be set. @@ -112,7 +112,7 @@ private: /// of the data represented e.g. /// "FD" short for "Floating Point Double"(see \ref VR) /// "PN" short for "Person Name" - TagName VR; + VRKey VR; /* * . diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index ecef7934..ec3301a4 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.cxx,v $ Language: C++ - Date: $Date: 2005/07/11 20:44:52 $ - Version: $Revision: 1.68 $ + Date: $Date: 2005/10/18 12:58:27 $ + Version: $Revision: 1.69 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -106,9 +106,9 @@ Dict *DictSet::GetDict(DictKey const &dictName) */ DictEntry *DictSet::NewVirtualDictEntry( uint16_t group, uint16_t elem, - TagName vr, - TagName vm, - TagName name) + const VRKey &vr, + const TagName &vm, + const TagName &name) { DictEntry *entry; @@ -125,9 +125,9 @@ DictEntry *DictSet::NewVirtualDictEntry( uint16_t group, char res[10]; sprintf(res,"%04x|%04x", group, elem); ExtendedTagKey tag = res; - tag += "#" + vr + "#" + vm + "#" + name; + tag += "#" + vr.str() + "#" + vm + "#" + name; #endif - + ExtendedTagKeyHT::iterator it; it = VirtualEntries.find(tag); diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 3cc5eca7..c05e1b5c 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.h,v $ Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.45 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.46 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -64,9 +64,9 @@ public: // Dict *GetVirtualDict() { return &VirtualEntries; } DictEntry *NewVirtualDictEntry(uint16_t group, uint16_t elem, - TagName vr = GDCM_UNKNOWN, - TagName vm = GDCM_UNKNOWN, - TagName name = GDCM_UNKNOWN); + const VRKey &vr = GDCM_VRUNKNOWN, + const TagName &vm = GDCM_UNKNOWN, + const TagName &name = GDCM_UNKNOWN); Dict *GetFirstEntry(); Dict *GetNextEntry(); diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 729fe8cc..8c117fb0 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/10/18 08:35:49 $ - Version: $Revision: 1.70 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.71 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -97,9 +97,9 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) uint16_t zero = 0; uint16_t shortLgr = (uint16_t)lgth; - if (vr == GDCM_UNKNOWN) + if( IsVRUnknown() ) { - // GDCM_UNKNOWN was stored in the Entry VR; + // GDCM_VRUNKNOWN was stored in the Entry VR; // deal with Entry as if TS were Implicit VR // FIXME : troubles expected on big endian processors : @@ -113,8 +113,7 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) } else { - binary_write(*fp, vr); - gdcmAssertMacro( vr.size() == 2 ); + binary_write(*fp, vr.str()); if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") /*|| (vr == "UN")*/ ) { @@ -232,13 +231,14 @@ void DocEntry::Print(std::ostream &os, std::string const & ) size_t o; std::string st; TSKey v; - std::string d2, vr; + std::string d2; + VRKey vr; std::ostringstream s; uint32_t lgth; o = GetOffset(); vr = GetVR(); - if ( vr==GDCM_UNKNOWN ) + if ( vr == GDCM_VRUNKNOWN ) vr=" "; s << DictEntry::TranslateToKey(GetGroup(),GetElement()); diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index d7fecfc3..2310a70b 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/10/18 08:35:49 $ - Version: $Revision: 1.50 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -68,7 +68,7 @@ public: /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name, /// "SL" : Signed Long), found in the Dicom header or in the Dicom /// Dictionnary, of the current Dicom entry - std::string const &GetVR() const { return DicomDict->GetVR(); } + VRKey const &GetVR() const { return DicomDict->GetVR(); } /// \brief Returns the 'Value Multiplicity' (e.g. "1", "1-n", "6"), /// found in the Dicom entry or in the Dicom Dictionnary diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index 8aa79663..0b4ff26d 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/10/18 08:35:49 $ - Version: $Revision: 1.60 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.61 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -125,27 +125,6 @@ int DocEntrySet::GetEntryLength(uint16_t group, uint16_t elem) return -1; } -/** - * \brief Searches within Header Entries (Dicom Elements) parsed with - * the public [and private dictionaries] - * for the element value representation of a given tag.. - * Obtaining the VR (Value Representation) might be needed by caller - * to convert the string typed content to caller's native type - * (think of C++ vs Python). The VR is actually of a higher level - * of semantics than just the native C++ type. - * @param group Group number of the searched tag. - * @param elem Element number of the searched tag. - * @return Corresponding element value representation when it exists, - * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. - */ -std::string DocEntrySet::GetEntryVR(uint16_t group, uint16_t elem) -{ - DocEntry *entry = GetDocEntry(group, elem); - if ( entry ) - return entry->GetVR(); - return GDCM_UNFOUND; -} - /** * \brief Same as \ref Document::GetDocEntry except it only * returns a result when the corresponding entry is of type @@ -274,7 +253,7 @@ bool DocEntrySet::SetEntryBinArea(uint8_t *content, int lgth, DataEntry *entry) */ DataEntry *DocEntrySet::InsertEntryString(std::string const &value, uint16_t group, uint16_t elem, - TagName const &vr ) + VRKey const &vr ) { DataEntry *dataEntry = 0; DocEntry *currentEntry = GetDocEntry( group, elem ); @@ -332,7 +311,7 @@ DataEntry *DocEntrySet::InsertEntryString(std::string const &value, */ DataEntry *DocEntrySet::InsertEntryBinArea(uint8_t *binArea, int lgth, uint16_t group, uint16_t elem, - TagName const &vr ) + VRKey const &vr ) { DataEntry *dataEntry = 0; DocEntry *currentEntry = GetDocEntry( group, elem ); @@ -466,7 +445,7 @@ bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem ) * @param vr V(alue) R(epresentation) of the new Entry */ DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem, - TagName const &vr) + VRKey const &vr) { DictEntry *dictEntry = GetDictEntry(group, elem, vr); gdcmAssertMacro(dictEntry); @@ -510,7 +489,7 @@ SeqEntry* DocEntrySet::NewSeqEntry(uint16_t group, uint16_t elem) * @param name english name */ DictEntry* DocEntrySet::NewVirtualDictEntry( uint16_t group, uint16_t elem, - TagName const &vr, + VRKey const &vr, TagName const &vm, TagName const &name ) { @@ -553,18 +532,18 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem) * @return Corresponding DictEntry when it exists, NULL otherwise. */ DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem, - TagName const &vr) + VRKey const &vr) { DictEntry *dictEntry = GetDictEntry(group,elem); DictEntry *goodEntry = dictEntry; - std::string goodVR = vr; + VRKey goodVR = vr; if (elem == 0x0000) goodVR="UL"; if ( goodEntry ) { if ( goodVR != goodEntry->GetVR() - && goodVR != GDCM_UNKNOWN ) + && goodVR != GDCM_VRUNKNOWN ) { goodEntry = NULL; } diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 4502a78a..99ce356a 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/10/18 08:35:49 $ - Version: $Revision: 1.57 $ + Date: $Date: 2005/10/18 12:58:28 $ + 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 @@ -20,6 +20,8 @@ #define GDCMDOCENTRYSET_H #include "gdcmBase.h" +#include "gdcmVRKey.h" + #include namespace gdcm @@ -82,7 +84,6 @@ public: virtual std::string GetEntryString(uint16_t group, uint16_t elem); virtual void *GetEntryBinArea(uint16_t group, uint16_t elem); virtual int GetEntryLength(uint16_t group, uint16_t elem); - virtual std::string GetEntryVR(uint16_t group, uint16_t elem); virtual std::string GetEntryForcedAsciiValue(uint16_t group, uint16_t elem); /// \brief Gets any type of DocEntry, identified by its (group,elem) @@ -101,10 +102,10 @@ public: DataEntry *InsertEntryString(std::string const &value, uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); + VRKey const &vr = GDCM_VRUNKNOWN); DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth, uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); + VRKey const &vr = GDCM_VRUNKNOWN); SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem); /// tells us if the set contains no entry virtual bool IsEmpty() = 0; @@ -112,12 +113,12 @@ public: // DocEntry related utilities DataEntry *NewDataEntry(uint16_t group,uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); + VRKey const &vr = GDCM_VRUNKNOWN); SeqEntry *NewSeqEntry(uint16_t group, uint16_t elem); // DictEntry related utilities DictEntry *NewVirtualDictEntry(uint16_t group,uint16_t elem, - TagName const &vr = GDCM_UNKNOWN, + VRKey const &vr = GDCM_VRUNKNOWN, TagName const &vm = GDCM_UNKNOWN, TagName const &name = GDCM_UNKNOWN ); @@ -125,7 +126,7 @@ protected: // DictEntry related utilities DictEntry *GetDictEntry(uint16_t group, uint16_t elem); DictEntry *GetDictEntry(uint16_t group, uint16_t elem, - TagName const &vr); + VRKey const &vr); /// To be able to backtrack (Private Sequence, Implicit VR related pb) DocEntry *PreviousDocEntry; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 94de7cae..d9d70e0b 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/10/18 11:35:31 $ - Version: $Revision: 1.293 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.294 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -875,7 +875,7 @@ void Document::SkipBytes(uint32_t nBytes) int Document::ComputeGroup0002Length( ) { uint16_t gr; - std::string vr; + VRKey vr; int groupLength = 0; bool found0002 = false; @@ -1275,7 +1275,7 @@ void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) { uint16_t group = entry->GetGroup(); uint16_t elem = entry->GetElement(); - std::string vr = entry->GetVR(); + const VRKey &vr = entry->GetVR(); uint32_t length = entry->GetLength(); Fp->seekg((long)entry->GetOffset(), std::ios::beg); @@ -1337,7 +1337,7 @@ void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) void Document::FindDocEntryLength( DocEntry *entry ) throw ( FormatError ) { - std::string vr = entry->GetVR(); + const VRKey &vr = entry->GetVR(); uint16_t length16; if ( Filetype == ExplicitVR && !entry->IsImplicitVR() ) @@ -1478,10 +1478,10 @@ uint32_t Document::FindDocEntryLengthOBOrOW() * \brief Find the Value Representation of the current Dicom Element. * @return Value Representation of the current Entry */ -std::string Document::FindDocEntryVR() +VRKey Document::FindDocEntryVR() { if ( Filetype != ExplicitVR ) - return GDCM_UNKNOWN; + return GDCM_VRUNKNOWN; long positionOnEntry = Fp->tellg(); // Warning: we believe this is explicit VR (Value Representation) because @@ -1492,14 +1492,16 @@ std::string Document::FindDocEntryVR() // is in explicit VR and try to fix things if it happens not to be // the case. - char vr[3]; - Fp->read (vr, (size_t)2); - vr[2] = 0; + VRKey vr; + Fp->read(&(vr[0]),(size_t)2); + gdcmWarningMacro( "--> VR: " << vr ) if ( !CheckDocEntryVR(vr) ) { + Global::GetVR()->Print(std::cerr); + gdcmWarningMacro( "Unknown VR '" << vr << "'" ) Fp->seekg(positionOnEntry, std::ios::beg); - return GDCM_UNKNOWN; + return GDCM_VRUNKNOWN; } return vr; } @@ -1512,12 +1514,9 @@ std::string Document::FindDocEntryVR() * @return false if the VR is incorrect or if the VR isn't referenced * otherwise, it returns true */ -bool Document::CheckDocEntryVR(VRKey vr) +bool Document::CheckDocEntryVR(const VRKey &vr) { - if ( !Global::GetVR()->IsValidVR(vr) ) - return false; - - return true; + return Global::GetVR()->IsValidVR(vr); } /** @@ -1634,7 +1633,7 @@ bool Document::IsDocEntryAnInteger(DocEntry *entry) { uint16_t elem = entry->GetElement(); uint16_t group = entry->GetGroup(); - const std::string &vr = entry->GetVR(); + const VRKey &vr = entry->GetVR(); uint32_t length = entry->GetLength(); // When we have some semantics on the element we just read, and if we @@ -1950,10 +1949,11 @@ DocEntry *Document::ReadNextDocEntry() if ( HasDCMPreamble ) HandleOutOfGroup0002(group, elem); - std::string vr = FindDocEntryVR(); - std::string realVR = vr; + VRKey vr = FindDocEntryVR(); + + VRKey realVR = vr; - if ( vr == GDCM_UNKNOWN ) + if ( vr == GDCM_VRUNKNOWN ) { if ( elem == 0x0000 ) // Group Length { @@ -1974,6 +1974,7 @@ DocEntry *Document::ReadNextDocEntry() } } } + gdcmWarningMacro( "Found VR: " << vr << " / Real VR: " << realVR ); DocEntry *newEntry; if ( Global::GetVR()->IsVROfSequence(realVR) ) @@ -1984,7 +1985,7 @@ DocEntry *Document::ReadNextDocEntry() static_cast(newEntry)->SetState(DataEntry::STATE_NOTLOADED); } - if ( vr == GDCM_UNKNOWN ) + if ( vr == GDCM_VRUNKNOWN ) { if ( Filetype == ExplicitVR ) { diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index dc04ee29..764160ab 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/10/18 09:17:08 $ - Version: $Revision: 1.124 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.125 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -190,8 +190,8 @@ private: void LoadDocEntry (DocEntry *e, bool forceLoad = false); void FindDocEntryLength (DocEntry *e) throw ( FormatError ); uint32_t FindDocEntryLengthOBOrOW() throw( FormatUnexpected ); - std::string FindDocEntryVR(); - bool CheckDocEntryVR (VRKey k); + VRKey FindDocEntryVR(); + bool CheckDocEntryVR (const VRKey &k); void SkipDocEntry (DocEntry *entry); void SkipToNextDocEntry (DocEntry *entry); diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 066959ab..fe54402e 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/10/18 08:35:50 $ - Version: $Revision: 1.276 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.277 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -219,7 +219,7 @@ bool File::DoTheLoadingJob( ) DataEntry *oldEntry = dynamic_cast(entry); if (oldEntry) { - std::string PixelVR; + VRKey PixelVR; // 8 bits allocated is a 'O Bytes' , as well as 24 (old ACR-NEMA RGB) // more than 8 (i.e 12, 16) is a 'O Words' if ( GetBitsAllocated() == 8 || GetBitsAllocated() == 24 ) diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index bc5fe663..1b454c60 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/10/18 12:49:55 $ - Version: $Revision: 1.61 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.62 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1121,8 +1121,8 @@ DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem, DocEntry *oldE = FileInternal->GetDocEntry(group, elem); DataEntry *newE; - if ( oldE && vr != GDCM_UNKNOWN ) - if ( oldE->GetVR()!=vr ) + if ( oldE && vr != GDCM_VRUNKNOWN ) + if ( oldE->GetVR() != vr ) oldE = NULL; if ( oldE ) diff --git a/src/gdcmFileHelper.h b/src/gdcmFileHelper.h index 1c1d0d8d..448afcc0 100644 --- a/src/gdcmFileHelper.h +++ b/src/gdcmFileHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.h,v $ Language: C++ - Date: $Date: 2005/10/18 08:35:50 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -165,7 +165,7 @@ protected: void RestoreWriteOfLibido(); DataEntry *CopyDataEntry(uint16_t group, uint16_t elem, - const TagName &vr = GDCM_UNKNOWN); + const TagName &vr = GDCM_VRUNKNOWN); void CheckMandatoryElements(); void CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value); void SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value); diff --git a/src/gdcmGlobal.cxx b/src/gdcmGlobal.cxx index c9ccd9d9..b2864d5d 100644 --- a/src/gdcmGlobal.cxx +++ b/src/gdcmGlobal.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmGlobal.cxx,v $ Language: C++ - Date: $Date: 2005/10/11 08:24:10 $ - Version: $Revision: 1.26 $ + Date: $Date: 2005/10/18 12:58:28 $ + Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -42,6 +42,9 @@ const std::string GDCM_NOTLOADED = "gdcm::NotLoaded"; const std::string GDCM_UNREAD = "gdcm::UnRead"; const std::string GDCM_NOTASCII = "gdcm::NotAscii"; const std::string GDCM_PIXELDATA = "gdcm::Pixel Data to be loaded"; + +const std::string GDCM_VRUNKNOWN = " "; + //----------------------------------------------------------------------------- DictSet *Global::Dicts = (DictSet *)0; VR *Global::ValRes = (VR *)0; diff --git a/src/gdcmSystem.h b/src/gdcmSystem.h index dabf98ee..0e136994 100644 --- a/src/gdcmSystem.h +++ b/src/gdcmSystem.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSystem.h,v $ Language: C++ - Date: $Date: 2005/10/18 09:17:08 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/10/18 12:58:29 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -86,17 +86,6 @@ typedef unsigned int uint32_t; #endif #include -#define FASTTAGKEY 0 - -// FIXME: Should rewrite this: -#if FASTTAGKEY -#include -#include -#endif -#if defined(_MSC_VER) && (_MSC_VER == 1200) -/* ostream operator for std::string since VS6 does not provide it*/ -#include -#endif //----------------------------------------------------------------------------- #endif diff --git a/src/gdcmVR.h b/src/gdcmVR.h index 9b74d486..f3fca668 100644 --- a/src/gdcmVR.h +++ b/src/gdcmVR.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVR.h,v $ Language: C++ - Date: $Date: 2005/10/18 08:35:51 $ - Version: $Revision: 1.20 $ + Date: $Date: 2005/10/18 12:58:29 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,8 @@ #define GDCMVR_H #include "gdcmCommon.h" +#include "gdcmVRKey.h" + #include #include #include @@ -28,7 +30,6 @@ namespace gdcm { //----------------------------------------------------------------------------- -typedef std::string VRKey; typedef std::string VRAtr; /// Value Representation Hash Table typedef std::map VRHT; diff --git a/src/gdcmVRKey.h b/src/gdcmVRKey.h new file mode 100644 index 00000000..71449375 --- /dev/null +++ b/src/gdcmVRKey.h @@ -0,0 +1,125 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmVRKey.h,v $ + Language: C++ + Date: $Date: 2005/10/18 12:58:29 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef GDCMVRKEY_H +#define GDCMVRKEY_H + +#include "gdcmCommon.h" +#include "gdcmDebug.h" + +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +class VRKey +{ +public : + inline VRKey() { key[0] = key[1] = ' ';} + inline VRKey(const char *_key) { key[0] = _key[0]; key[1] = _key[1];} + inline VRKey(const std::string &_key) { key[0] = _key[0]; key[1] = _key[1];} + + inline std::string str() const { return std::string(key,2); } + + friend std::ostream& operator<<(std::ostream& _os, const VRKey &_val); + friend std::istream& operator>>(std::istream& _is, VRKey &_val); + + inline VRKey &operator=(const VRKey &_val) + { + key[0] = _val.key[0]; + key[1] = _val.key[1]; + return *this; + } + inline VRKey &operator=(const std::string &_val) + { + key[0] = _val[0]; + key[1] = _val[1]; + return *this; + } + inline VRKey &operator=(const char *_val) + { + key[0] = _val[0]; + key[1] = _val[1]; + return *this; + } + + inline const char &operator[](const unsigned int &_id) const + { + assert(_id<2); + return key[_id]; + } + inline char &operator[](const unsigned int &_id) + { + assert(_id<2); + return key[_id]; + } + + inline bool operator==(const VRKey &_val) const + { + return key[0] == _val.key[0] && key[1] == _val.key[1]; + } + inline bool operator==(const std::string &_val) const + { + return key[0] == _val[0] && key[1] == _val[1]; + } + inline bool operator==(const char *_val) const + { + return key[0] == _val[0] && key[1] == _val[1]; + } + + inline bool operator!=(const VRKey &_val) const + { + return key[0] != _val.key[0] || key[1] != _val.key[1]; + } + inline bool operator!=(const std::string &_val) const + { + return key[0] != _val[0] || key[1] != _val[1]; + } + inline bool operator!=(const char *_val) const + { + return key[0] != _val[0] || key[1] != _val[1]; + } + + inline bool operator<(const VRKey &_val) const + { + return key[0] < _val[0] || (key[0] == _val[0] && key[1] < _val[1]); + } + +private : + char key[2]; +}; + +//----------------------------------------------------------------------------- +inline std::ostream& operator<<(std::ostream& _os, const VRKey &_val) +{ + _os << _val.key[0] << _val[1]; + return _os; +} + +inline std::istream& operator>>(std::istream& _is, VRKey &_val) +{ + _is >> _val.key[0] >> _val[1]; + return _is; +} + +//----------------------------------------------------------------------------- + +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif -- 2.45.1