From: jpr Date: Tue, 25 Jan 2005 15:21:20 +0000 (+0000) Subject: In ordrer to avoid missbehaviour : X-Git-Tag: Version1.0.bp~196 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7cbed4e7f082b4d2df1edda48bb3fde175a60b6e;p=gdcm.git In ordrer to avoid missbehaviour : gdcm::DocEntry is now specialized in - gdcm::SeqEntry (Dicom Sequence) as opposed to : - gdcm::ContentEntry (Dicom entry with a 'content') gdcm::ValContent is now specialized in - gdcm::ValEntry (Dicom entry with a std::string representable value, i.e. characters value, or integers) - gdcm::BinEntry (Dicom entry with a non strig representable value (user hasn't any longer to thing about the precedence of his dynamic_casts) --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bf808628..29b710f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ INCLUDE_DIRECTORIES( SET(libgdcm_la_SOURCES gdcmBase.cxx gdcmBinEntry.cxx + gdcmContentEntry.cxx gdcmDebug.cxx gdcmDicomDir.cxx gdcmDicomDirElement.cxx diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index 2650076b..a28e9a5a 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/01/24 16:10:52 $ - Version: $Revision: 1.56 $ + Date: $Date: 2005/01/25 15:21:20 $ + Version: $Revision: 1.57 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,6 +17,8 @@ =========================================================================*/ #include "gdcmBinEntry.h" +#include "gdcmContentEntry.h" + #include "gdcmDebug.h" #include @@ -32,7 +34,7 @@ namespace gdcm /** * \brief Constructor from a given BinEntry */ -BinEntry::BinEntry(DictEntry *e) : ValEntry(e) +BinEntry::BinEntry(DictEntry *e) : ContentEntry(e) { BinArea = 0; SelfArea = true; @@ -42,7 +44,7 @@ BinEntry::BinEntry(DictEntry *e) : ValEntry(e) * \brief Constructor from a given BinEntry * @param e Pointer to existing Doc entry */ -BinEntry::BinEntry(DocEntry *e) : ValEntry(e->GetDictEntry()) +BinEntry::BinEntry(DocEntry *e) : ContentEntry(e->GetDictEntry()) { Copy(e); diff --git a/src/gdcmBinEntry.h b/src/gdcmBinEntry.h index 7ff241cb..7e3e9ac9 100644 --- a/src/gdcmBinEntry.h +++ b/src/gdcmBinEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.h,v $ Language: C++ - Date: $Date: 2005/01/21 11:40:55 $ - Version: $Revision: 1.32 $ + Date: $Date: 2005/01/25 15:21:20 $ + Version: $Revision: 1.33 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,7 +19,7 @@ #ifndef GDCMBINENTRY_H #define GDCMBINENTRY_H -#include "gdcmValEntry.h" +#include "gdcmContentEntry.h" #include namespace gdcm @@ -28,13 +28,14 @@ namespace gdcm //----------------------------------------------------------------------------- /** * \brief Any Dicom Document (File or DicomDir) contains - * a set of DocEntry entries - * (when successfuly parsed against a given Dicom dictionary) - * BinEntry is a specialisation of ValEntry (for non std::string - * representable values) + * a set of DocEntry - Dicom entries - + * BinEntry is an elementary DocEntry (i.e. a ContentEntry, + * as opposite to SeqEntry) whose content is non std::string + * representable + * BinEntry is a specialisation of ContentEntry */ -class GDCM_EXPORT BinEntry : public ValEntry +class GDCM_EXPORT BinEntry : public ContentEntry { public: BinEntry( DictEntry *e ); @@ -46,18 +47,18 @@ public: void WriteContent( std::ofstream *fp, FileType ft); /// \brief Returns the area value of the current Dicom Entry - /// when it's not string-translatable (e.g : a LUT table) + /// when it's not string-translatable (e.g : LUT table, overlay, icon) uint8_t *GetBinArea() { return BinArea; } + void SetBinArea( uint8_t *area, bool self = true ); - /// Sets the value (string) of the current Dicom Entry - virtual void SetValue(std::string const &val) { SetValueOnly(val); }; private: - /// \brief unsecure memory area to hold 'non string' values + /// \brief memory area to hold 'non std::string' representable values /// (ie : Lookup Tables, overlays, icons) uint8_t *BinArea; bool SelfArea; }; + } // end namespace gdcm //----------------------------------------------------------------------------- #endif diff --git a/src/gdcmContentEntry.cxx b/src/gdcmContentEntry.cxx new file mode 100644 index 00000000..2e4530c3 --- /dev/null +++ b/src/gdcmContentEntry.cxx @@ -0,0 +1,127 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmContentEntry.cxx,v $ + Language: C++ + Date: $Date: 2005/01/25 15:21:20 $ + 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. + +=========================================================================*/ + +#include "gdcmContentEntry.h" +#include "gdcmVR.h" +#include "gdcmTS.h" +#include "gdcmGlobal.h" +#include "gdcmUtil.h" +#include "gdcmDebug.h" + +#include + +namespace gdcm +{ + +// CLEAN ME +#define MAX_SIZE_PRINT_ELEMENT_VALUE 128 + +//----------------------------------------------------------------------------- +// Constructor / Destructor +/** + * \brief Constructor from a given DictEntry + * @param e Pointer to existing dictionary entry + */ +ContentEntry::ContentEntry(DictEntry *e) : DocEntry(e) +{ +} + +/** + * \brief Constructor from a given DocEntry + * @param e Pointer to existing Doc entry + */ +ContentEntry::ContentEntry(DocEntry *e) + : DocEntry(e->GetDictEntry()) +{ + Copy(e); +} + + +/** + * \brief Canonical destructor. + */ +ContentEntry::~ContentEntry () +{ +} + +//----------------------------------------------------------------------------- +// Public + +/** + * \brief Writes the std::string representable' value of a ContentEntry + * @param fp already open ofstream pointer + * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) + */ +void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype) +{ + DocEntry::WriteContent(fp, filetype); + + if ( GetGroup() == 0xfffe ) + { + return; //delimitors have NO value + } + + const VRKey &vr = GetVR(); + unsigned int lgr = GetLength(); + if (vr == "US" || vr == "SS") + { + // some 'Short integer' fields may be multivaluated + // each single value is separated from the next one by '\' + // we split the string and write each value as a short int + std::vector tokens; + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Util::Tokenize (GetValue(), tokens, "\\"); + for (unsigned int i=0; i tokens; + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Util::Tokenize (GetValue(), tokens, "\\"); + for (unsigned int i=0; i + +namespace gdcm +{ +//----------------------------------------------------------------------------- +/** + * \brief Any Dicom Document (File or DicomDir) contains + * a set of DocEntry - Dicom entries - + * (when successfuly parsed against a given Dicom dictionary) + * ContentEntry is an elementary DocEntry (as opposed to SeqEntry). + * Depending on the type of its content, + * ContentEntry is specialized as a ValEntry or a BinEntry + */ +class GDCM_EXPORT ContentEntry : public DocEntry +{ +public: + virtual void WriteContent(std::ofstream *fp, FileType filetype) = 0; + + // Accessors are protected, not to be invoked by end user + /// Sets the value (string) of the current Dicom entry + virtual void SetValue(std::string const &val) { Value = val; }; + + void SetValueOnly(std::string const &val) { Value = val; }; + + /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted + /// into a 'string', event if it's physically stored on disk as an integer + std::string const &GetValue() const { return Value; }; + +protected: + + // Contructors are protected, not to be invoked by end user. + ContentEntry(DictEntry *e); + ContentEntry(DocEntry *d); + // Destructor is protected, not to be invoked by end user. + ~ContentEntry(); + +private: +// Members : + + /// \brief Dicom entry value, internaly represented as a std::string. + /// The Value Representation (\ref VR) is independently used + /// in order to interpret (decode) this field. + std::string Value; +}; + +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif + diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 03e85e1f..9d30a55d 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:44:54 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/01/25 15:21:20 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,6 +23,8 @@ #include "gdcmDebug.h" #include "gdcmUtil.h" #include "gdcmBinEntry.h" +#include "gdcmValEntry.h" +#include "gdcmContentEntry.h" #include "gdcmFile.h" #include "gdcmPixelReadConvert.h" #include "gdcmPixelWriteConvert.h" @@ -626,16 +628,18 @@ bool FileHelper::CheckWriteIntegrity() case WMODE_RAW : if( decSize!=PixelWriteConverter->GetUserDataSize() ) { - gdcmVerboseMacro( "Data size is incorrect (Raw)" << decSize - << " / " << PixelWriteConverter->GetUserDataSize() ); + gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be " + << decSize << " / Found :" + << PixelWriteConverter->GetUserDataSize() ); return false; } break; case WMODE_RGB : if( rgbSize!=PixelWriteConverter->GetUserDataSize() ) { - gdcmVerboseMacro( "Data size is incorrect (RGB)" << decSize - << " / " << PixelWriteConverter->GetUserDataSize() ); + gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be " + << decSize << " / Found " + << PixelWriteConverter->GetUserDataSize() ); return false; } break; diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index 40a36a6d..ae44be0a 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2005/01/24 16:10:53 $ - Version: $Revision: 1.50 $ + Date: $Date: 2005/01/25 15:21:20 $ + 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 @@ -37,7 +37,7 @@ namespace gdcm * \brief Constructor from a given DictEntry * @param e Pointer to existing dictionary entry */ -ValEntry::ValEntry(DictEntry *e) : DocEntry(e) +ValEntry::ValEntry(DictEntry *e) : ContentEntry(e) { } @@ -46,7 +46,7 @@ ValEntry::ValEntry(DictEntry *e) : DocEntry(e) * @param e Pointer to existing Doc entry */ ValEntry::ValEntry(DocEntry *e) - : DocEntry(e->GetDictEntry()) + : ContentEntry(e->GetDictEntry()) { Copy(e); } diff --git a/src/gdcmValEntry.h b/src/gdcmValEntry.h index 34275c6d..05ae4f18 100644 --- a/src/gdcmValEntry.h +++ b/src/gdcmValEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.h,v $ Language: C++ - Date: $Date: 2005/01/21 11:40:56 $ - Version: $Revision: 1.37 $ + Date: $Date: 2005/01/25 15:21:20 $ + Version: $Revision: 1.38 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,50 +20,51 @@ #define GDCMVALENTRY_H #include "gdcmDocEntry.h" +#include "gdcmContentEntry.h" #include namespace gdcm { //----------------------------------------------------------------------------- + /** - * \brief Any Dicom Document (File header or DicomDir) contains + * \brief Any Dicom Document (File or DicomDir) contains * a set of DocEntry - Dicom entries - - * (when successfuly parsed against a given Dicom dictionary) - * ValEntry is an elementary DocEntry (as opposed to SeqEntry) - */ -class GDCM_EXPORT ValEntry : public DocEntry + * ValEntry is an elementary DocEntry (i.e. a ContentEntry, + * as opposed to SeqEntry) + * whose content is 'std::string representable' : characters, + * or integers (loaded in memory as a std::string) + * ValEntry is a specialisation of ContentEntry + */ + +class GDCM_EXPORT ValEntry : public ContentEntry { public: + + // Contructors and Destructor are public. ValEntry(DictEntry *e); ValEntry(DocEntry *d); + ~ValEntry(); - /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted into a - /// 'string', event if it's physically stored as an integer in the header of the - /// current Document (File or DicomDir) - std::string const &GetValue() const { return Value; }; - - /// Sets the value (string) of the current Dicom entry. - /// The size is updated - virtual void SetValue(std::string const &val); + // Other accessors are inherited from gdcm::ContentEntry - virtual void Print(std::ostream &os = std::cout, std::string const & indent = ""); + void Print(std::ostream &os = std::cout, + std::string const & indent = ""); - virtual void WriteContent(std::ofstream *fp, FileType filetype); + void WriteContent(std::ofstream *fp, FileType filetype); + + /// Sets the value (string) of the current Dicom entry. + /// The size is updated + void SetValue(std::string const &val); protected: - /// Sets the value (string) of the current Dicom entry - void SetValueOnly(std::string const &val) { Value = val; }; private: -// Members : - - /// \brief Dicom entry value, internaly represented as a std::string. - /// The Value Representation (\ref VR) is independently used - /// in order to interpret (decode) this field. - std::string Value; + }; + } // end namespace gdcm //-----------------------------------------------------------------------------