From: frog Date: Thu, 16 Sep 2004 19:21:56 +0000 (+0000) Subject: * gdcmDocEntrySet::SQDepthLevel and gdcmDocEntrySet::BaseTagKey attributes X-Git-Tag: Version0.6.bp~199 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0fc486652e88490f7344439111750eb9dcaf7a29;p=gdcm.git * gdcmDocEntrySet::SQDepthLevel and gdcmDocEntrySet::BaseTagKey attributes moved away from gdcmDocEntrySet (since this class is an abstract class acting like an interface). SQDepthLevel and BaseTagKey are now in class - src/gdcmDocEntrySet.[h|cxx] removal of SQDepthLevel and BaseTagKey and associated accessors. Doxygenation of the class. - src/gdcmSQItem.[h|cxx] SQDepthLevel and BaseTagKey and associated accessors added. - src/gdcmSeqEntry.[h|cxx]: constructor doesn't handle depth anymore. Use SQDepthLevel accessor instead. ::Print() adapted. - src/gdcmElementSet.cxx changed according to changes in gdcmSeqEntry. - src/gdcmDocument.cxx changed accordingly. --- diff --git a/ChangeLog b/ChangeLog index 36d6ee4f..bf85521c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-09-16 Eric Boix + * gdcmDocEntrySet::SQDepthLevel and gdcmDocEntrySet::BaseTagKey attributes + moved away from gdcmDocEntrySet (since this class is an abstract class + acting like an interface). SQDepthLevel and BaseTagKey are now + in class + - src/gdcmDocEntrySet.[h|cxx] removal of SQDepthLevel and BaseTagKey + and associated accessors. Doxygenation of the class. + - src/gdcmSQItem.[h|cxx] SQDepthLevel and BaseTagKey and associated + accessors added. + - src/gdcmSeqEntry.[h|cxx]: constructor doesn't handle depth anymore. + Use SQDepthLevel accessor instead. ::Print() adapted. + - src/gdcmElementSet.cxx changed according to changes in gdcmSeqEntry. + - src/gdcmDocument.cxx changed accordingly. + 2004-09-13 Eric Boix * Preparation of writing a gdcmHeader iterator: generalisation of gdcmTagKey - The following is the doxygen comment of the typedef declaration diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index ce1c25bf..d5ca85e2 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2004/09/14 16:47:08 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,35 +26,9 @@ #include "gdcmValEntry.h" #include "gdcmBinEntry.h" -//----------------------------------------------------------------------------- -// Constructor / Destructor -/** - * \ingroup gdcmDocEntrySet - * \brief Constructor from a given gdcmDocEntrySet - */ -gdcmDocEntrySet::gdcmDocEntrySet(int depthLevel) -{ - SQDepthLevel = depthLevel + 1; //magic +1 ! -} -/** - * \brief Canonical destructor. - */ -gdcmDocEntrySet::~gdcmDocEntrySet() -{ -} -//----------------------------------------------------------------------------- -// Print -/* - * \ingroup gdcmDocEntrySet - * \brief canonical Printer - */ - - //----------------------------------------------------------------------------- // Public - - /** * \brief Build a new Val Entry from all the low level arguments. * Check for existence of dictionary entry, and build @@ -117,23 +91,26 @@ gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group, * @param Group group number of the underlying DictEntry * @param Elem element number of the underlying DictEntry */ -gdcmSeqEntry *gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group, +gdcmSeqEntry* gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group, uint16_t Elem) { // Find out if the tag we encountered is in the dictionaries: - gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem); - if (!DictEntry) + gdcmDictEntry* DictEntry = GetDictEntryByNumber( Group, Elem ); + if ( ! DictEntry ) + { DictEntry = NewVirtualDictEntry(Group, Elem); + } - gdcmSeqEntry *NewEntry = new gdcmSeqEntry(DictEntry, 1); // FIXME : 1 - if (!NewEntry) + gdcmSeqEntry *NewEntry = new gdcmSeqEntry( DictEntry ); + if ( !NewEntry ) { dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber", "failed to allocate gdcmSeqEntry"); - return NULL; + return 0; } return NewEntry; } + //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index c7775682..c9e6b234 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2004/09/14 16:47:08 $ - Version: $Revision: 1.17 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.18 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,12 +25,33 @@ typedef std::string gdcmBaseTagKey; //----------------------------------------------------------------------------- +/** + * \ref gdcmDocEntrySet is an abstract base class for \ref gdcmElementSet + * and \ref gdcmSQItem which are both containers for gdcmDocEntries. + * \ref gdcmElementSet is based on the STL map<> container + * (see \ref gdcmElementSet::TagHT), as opposed to \ref gdcmSQItem + * which is based on an STL list container (see \ref gdcmSQItem::docEntries). + * Since the syntax for adding a new element to a map<> or a list<> + * differ, \ref gdcmDocEntrySet is designed as an adapter to unify the + * interfaces of \ref gdcmDocEntrySet and \ref gdcmElementSet. + * As an illustration of this design, please refer to the implementation + * of \ref AddEntry (or any pure virtual method) in both derived classes. + * This adapter unification of interfaces enables the parsing of a + * DICOM header containing (optionaly heavily nested) sequences to be + * written recursively [see \ref gdcmDocument::ParseDES + * which calls \ref gdcmDocument::ParseSQ, which in turns calls + * \ref gdcmDocument::ParseDES ]. + * + * \note Developpers should strongly resist to the temptation of adding + * members to this class since this class is designed as an adapter + * in the form of an abstract base class. + */ class GDCM_EXPORT gdcmDocEntrySet { public: - gdcmDocEntrySet(int depth = 0); - virtual ~gdcmDocEntrySet(); + gdcmDocEntrySet() {} + virtual ~gdcmDocEntrySet() {} /// \brief adds any type of entry to the entry set (pure vitual) virtual bool AddEntry(gdcmDocEntry *Entry) = 0; // pure virtual @@ -41,17 +62,6 @@ public: /// \brief write any type of entry to the entry set virtual void Write (FILE *fp, FileType filetype) = 0;// pure virtual - /// \brief Gets the depth level of a Dicom Header Entry embedded in a - /// SeQuence - int GetDepthLevel() { return SQDepthLevel; } - - /// \brief Sets the depth level of a Dicom Header Entry embedded in a - /// SeQuence - void SetDepthLevel(int depth) { SQDepthLevel = depth; } - - void SetBaseTagKey( gdcmBaseTagKey key ) { BaseTagKey = key; } - gdcmBaseTagKey GetBaseTagKey( ) { return BaseTagKey; } - virtual gdcmDocEntry* GetDocEntryByNumber(uint16_t group, uint16_t element) = 0; gdcmDocEntry *GetDocEntryByName(std::string const & name); @@ -83,13 +93,6 @@ protected: gdcmDictEntry *GetDictEntryByName (std::string const & name); gdcmDictEntry *GetDictEntryByNumber(uint16_t, uint16_t); - /// Gives the depth level of the element set inside SeQuences - int SQDepthLevel; - - /// \brief A TagKey of a gdcmDocEntry nested in a sequence is prepended - /// with this BaseTagKey. - gdcmBaseTagKey BaseTagKey; -private: }; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 37be3f68..95bd1147 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/09/16 06:48:00 $ - Version: $Revision: 1.79 $ + Date: $Date: 2004/09/16 19:21:57 $ + 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 @@ -107,8 +107,6 @@ gdcmDocument::gdcmDocument( std::string const & filename ) long beg = ftell(Fp); lgt -= beg; - SQDepthLevel = 0; - (void)ParseDES( this, beg, lgt, false); // le Load sera fait a la volee rewind(Fp); @@ -1186,7 +1184,7 @@ void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) delete[] a; return NULL; } - /// \TODO Drop any already existing void area! JPR + /// \todo Drop any already existing void area! JPR if( !SetEntryVoidAreaByNumber( a, group, elem ) ); { dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea setting failed."); @@ -1449,7 +1447,6 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, gdcmDocEntry *newDocEntry = 0; unsigned long l = 0; - int depth = set->GetDepthLevel(); while (true) { if ( !delim_mode && (ftell(Fp)-offset) >= l_max) @@ -1468,11 +1465,26 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, if ( gdcmGlobal::GetVR()->IsVROfGdcmStringRepresentable(vr) ) { - /////// ValEntry + /////////////////////// ValEntry gdcmValEntry* newValEntry = new gdcmValEntry( newDocEntry->GetDictEntry() ); newValEntry->Copy( newDocEntry ); - newValEntry->SetKey( set->GetBaseTagKey() + newValEntry->GetKey() ); + + // When "set" is a gdcmDocument, then we are at the top of the + // hierarchy and the Key is simply of the form ( group, elem )... + if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) + { + newValEntry->SetKey( newValEntry->GetKey() ); + } + // ...but when "set" is a gdcmSQItem, we are inserting this new + // valEntry in a sequence item. Hence the key has the + // generalized form (refer to \ref gdcmBaseTagKey): + if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) ) + { + newValEntry->SetKey( parentSQItem->GetBaseTagKey() + + newValEntry->GetKey() ); + } + set->AddEntry( newValEntry ); LoadDocEntry( newValEntry ); if (newValEntry->IsItemDelimitor()) @@ -1493,11 +1505,26 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, "nor BinEntry. Probably unknown VR."); } - ////// BinEntry or UNKOWN VR: + //////////////////// BinEntry or UNKOWN VR: gdcmBinEntry* newBinEntry = new gdcmBinEntry( newDocEntry->GetDictEntry() ); newBinEntry->Copy( newDocEntry ); - newBinEntry->SetKey( set->GetBaseTagKey() + newBinEntry->GetKey() ); + + // When "this" is a gdcmDocument the Key is simply of the + // form ( group, elem )... + if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) + { + newBinEntry->SetKey( newBinEntry->GetKey() ); + } + // but when "this" is a SQItem, we are inserting this new + // valEntry in a sequence item, and the kay has the + // generalized form (refer to \ref gdcmBaseTagKey): + if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) ) + { + newBinEntry->SetKey( parentSQItem->GetBaseTagKey() + + newBinEntry->GetKey() ); + } + set->AddEntry( newBinEntry ); LoadDocEntry( newBinEntry ); } @@ -1541,12 +1568,28 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, } // no other way to create it ... gdcmSeqEntry* newSeqEntry = - new gdcmSeqEntry( newDocEntry->GetDictEntry(), - set->GetDepthLevel() ); + new gdcmSeqEntry( newDocEntry->GetDictEntry() ); newSeqEntry->Copy( newDocEntry ); newSeqEntry->SetDelimitorMode( delim_mode ); - newSeqEntry->SetDepthLevel( depth ); - newSeqEntry->SetKey( set->GetBaseTagKey() + newSeqEntry->GetKey() ); + + // At the top of the hierarchy, stands a gdcmDocument. When "set" + // is a gdcmDocument, then we are building the first depth level. + // Hence the gdcmSeqEntry we are building simply has a depth + // level of one: + if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) + { + newSeqEntry->SetDepthLevel( 1 ); + newSeqEntry->SetKey( newSeqEntry->GetKey() ); + } + // But when "set" is allready a SQItem, we are building a nested + // sequence, and hence the depth level of the new gdcmSeqEntry + // we are building, is one level deeper: + if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) ) + { + newSeqEntry->SetDepthLevel( parentSQItem->GetDepthLevel() + 1 ); + newSeqEntry->SetKey( parentSQItem->GetBaseTagKey() + + newSeqEntry->GetKey() ); + } if ( l != 0 ) { // Don't try to parse zero-length sequences diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index a5017dd6..ee6d9658 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2004/09/03 14:04:02 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,8 +28,9 @@ * \ingroup gdcmElementSet * \brief Constructor from a given gdcmElementSet */ +//BOZ depthLevel is not usefull anymore gdcmElementSet::gdcmElementSet(int depthLevel) - : gdcmDocEntrySet(depthLevel) + : gdcmDocEntrySet() { } diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 2299b946..1dc964c8 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2004/08/27 15:48:44 $ - Version: $Revision: 1.25 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.26 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,9 +33,9 @@ * \brief Constructor from a given gdcmSQItem */ gdcmSQItem::gdcmSQItem(int depthLevel ) - : gdcmDocEntrySet(depthLevel) + : gdcmDocEntrySet( ) { - SQDepthLevel = depthLevel +1; + SQDepthLevel = depthLevel; } /** diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index 946581b4..1b3cdad7 100644 --- a/src/gdcmSQItem.h +++ b/src/gdcmSQItem.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.h,v $ Language: C++ - Date: $Date: 2004/08/31 15:39:48 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -57,9 +57,23 @@ public: /// \brief returns the ordinal position of a given SQItem int GetSQItemNumber() { return SQItemNumber; }; + /// \brief Sets the ordinal position of a given SQItem void SetSQItemNumber(int itemNumber) { SQItemNumber = itemNumber; }; + /// Accessor on \ref SQDepthLevel. + int GetDepthLevel() { return SQDepthLevel; } + + /// Accessor on \ref SQDepthLevel. + void SetDepthLevel(int depth) { SQDepthLevel = depth; } + + /// Accessor on \ref BaseTagKey. + void SetBaseTagKey( gdcmBaseTagKey key ) { BaseTagKey = key; } + + /// Accessor on \ref BaseTagKey. + gdcmBaseTagKey GetBaseTagKey( ) { return BaseTagKey; } + + protected: // Variables @@ -73,9 +87,20 @@ protected: ///\brief pointer to the HTable of the gdcmDocument, /// (because we don't know it within any gdcmObject nor any gdcmSQItem) TagDocEntryHT *PtagHT; + private: + /// \brief Sequences can be nested. This \ref SQDepthLevel represents + /// the level of the nesting of instances of this class. + /// \ref SQDepthLevel and its \ref gdcmSeqEntry::SQDepthLevel + /// counterpart are only defined on printing purposes + /// (see \ref Print). + int SQDepthLevel; + + /// \brief A TagKey of a gdcmDocEntry nested in a sequence is prepended + /// with this BaseTagKey. + gdcmBaseTagKey BaseTagKey; }; diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index d31c2b10..4323f941 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2004/09/13 12:10:53 $ - Version: $Revision: 1.27 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.28 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,12 +30,12 @@ * \ingroup gdcmSeqEntry * \brief Constructor from a given gdcmSeqEntry */ -gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) +gdcmSeqEntry::gdcmSeqEntry( gdcmDictEntry* e ) : gdcmDocEntry(e) { UsableLength = 0; ReadLength = 0xffffffff; - SQDepthLevel = depth; + SQDepthLevel = -1; delimitor_mode = false; seq_term = NULL; @@ -72,7 +72,7 @@ gdcmSeqEntry::~gdcmSeqEntry() { /** * \brief canonical Printer */ -void gdcmSeqEntry::Print(std::ostream &os) +void gdcmSeqEntry::Print( std::ostream &os ) { // First, Print the Dicom Element itself. SetPrintLevel(2); @@ -90,15 +90,20 @@ void gdcmSeqEntry::Print(std::ostream &os) // at end, print the sequence terminator item, if any if (delimitor_mode) { - for (int i=0;iPrint(os); os << std::endl; } else - // fusible + { + // fuse os << " -------------- should have a sequence terminator item"; + } } } diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index a0b0d67b..29381b40 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.h,v $ Language: C++ - Date: $Date: 2004/09/13 12:10:53 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/09/16 19:21:57 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,7 +31,7 @@ typedef std::list ListSQItem; class GDCM_EXPORT gdcmSeqEntry : public gdcmDocEntry { public: - gdcmSeqEntry(gdcmDictEntry* e, int depth); + gdcmSeqEntry( gdcmDictEntry* ); gdcmSeqEntry(gdcmDocEntry* d, int depth); virtual ~gdcmSeqEntry(); @@ -69,7 +69,10 @@ private: /// sequence terminator item gdcmDocEntry *seq_term; - /// Gives the depth level of elements inside SeQuences + /// \brief Defines the depth level of this \ref gdcmSeqEntry inside + /// the (optionaly) nested sequences. \ref SQDepthLevel + /// and its \ref gdcmSQItem::SQDepthLevel counterpart + /// are only defined on printing purposes (see \ref Print). int SQDepthLevel; };