From: frog Date: Mon, 13 Sep 2004 12:10:52 +0000 (+0000) Subject: * Preparation of writing a gdcmHeader iterator: generalisation of gdcmTagKey X-Git-Tag: Version0.6.bp~205 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=44a9814938a6824d3a66b932429084517da6dadf;p=gdcm.git * Preparation of writing a gdcmHeader iterator: generalisation of gdcmTagKey - The following is the doxygen comment of the typedef declaration of gdcmagKey in src/gdcmCommon.h: gdcmTagKey is made to old an "universal" (as in URL, Universal Ressource Locator) key to a gdcmDocEntry i.e. a dicom tag. A dicom tag allways has a group and an element, but a set of tags embeded in various (optionally nested) sequences and sharing the same group and element all share the same (group, element) "identifier". Hence the (group, element) cannot be used as an identifier (in gdcm we shall refer to a "TagKey") of a tag. In order to construct a proper tag identifier (i.e. a key) we consider the following definition of a TagKey: - let Group, Element be the string representation of the group and element dicom tag members, - let ItemNumber be the string representation of the integer index of the considered item number of a sequence, Let the key of a tag embeded in a sequence, noted SeqTag, be the form: /ItemNumber#Group|Element where "/", "#" and "|" are characters acting as separators. Then the general form of a gdcmTagKey is given by: Group|Element where means NO or many instances of SeqTag. Hence the gdcmTagKey of a tag not "leaving" in a sequence is the string e.g. 0028|1201 but the gdcmTagKey of a tag "embeded" is the first item of a sequence, itself nested in the third item of a sequence is the string e.g. 0004|1220/2#0008|0082/0#0008|0090 - src/gdcmDocEntry.h: added a new Key (of type gdcmTagKey) member, in order to hold the new sequence compatible key. Previously, the GetKey() method would look in the underlying gdcmDictEntry. - src/gdcmDocEntry.cxx: -- constructor now copies the underlying DictEntry key, in the local Key member. -- ::Print: displays the member Key, instead of the (group, element). - src/gdcmCommon.h: added some comments on typedef gdcmTagKey. - src/gdcmDocEntrySet.h:xi -- ::ParseDES() now setups the gdcmTagKey of the sequence it is parsing. -- now has a new BaseTagKey member. -- STYLE. * src/gdcmValEntry.[h|cxx], src/gdcmBinEntry.[h|cxx]: the member VoidArea, previously a member of gdcmValEntry, moved to gdcmBinEntry were is truly belongs. This poses the problem with the semantics of the following lines LoadEntryVoidArea(0x0028,0x1201); // R LUT LoadEntryVoidArea(0x0028,0x1202); // G LUT LoadEntryVoidArea(0x0028,0x1203); // B LUT in gdcmDocument::gdcmDocument(std::string const & ). Please refer to the long FIXME note for what the problem is. Nevertheless in order to get things working the dicom dictionary was altered ! Please fix things urgently... * Dicts/dicomV3.dic WRONGLY altered (this means we introduced a uncorrect information), see above note on moving the member VoidArea. Nevertheless the following entries previously correctly set as US are now inproperly set to OW: 0028 1201 OW IMG Red Palette Color Lookup Table Data 0028 1202 OW IMG Green Palette Color Lookup Table Data 0028 1203 OW IMG Blue Palette Color Lookup Table Data * src/gdcmDocEntry.[h|cxx], src/gdcmSeqEntry.h: SQDepthLevel member of gdcmDocEntry moved to gdcmSeqEntry. * src/gdcmSeqEntry.cxx: STYLE. --- diff --git a/ChangeLog b/ChangeLog index b63416ec..36d6ee4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,68 @@ +2004-09-13 Eric Boix + * Preparation of writing a gdcmHeader iterator: generalisation of gdcmTagKey + - The following is the doxygen comment of the typedef declaration + of gdcmagKey in src/gdcmCommon.h: + gdcmTagKey is made to old an "universal" (as in URL, Universal + Ressource Locator) key to a gdcmDocEntry i.e. a dicom tag. + A dicom tag allways has a group and an element, but a set of tags + embeded in various (optionally nested) sequences and sharing + the same group and element all share the same (group, element) + "identifier". Hence the (group, element) cannot be used as an + identifier (in gdcm we shall refer to a "TagKey") of a tag. + In order to construct a proper tag identifier (i.e. a key) we + consider the following definition of a TagKey: + - let Group, Element be the string representation of the + group and element dicom tag members, + - let ItemNumber be the string representation of the integer + index of the considered item number of a sequence, + Let the key of a tag embeded in a sequence, noted SeqTag, be + the form: + /ItemNumber#Group|Element + where "/", "#" and "|" are characters acting as separators. + Then the general form of a gdcmTagKey is given by: + Group|Element + where means NO or many instances of SeqTag. + Hence the gdcmTagKey of a tag not "leaving" in a sequence is the + string e.g. + 0028|1201 + but the gdcmTagKey of a tag "embeded" is the first item of + a sequence, itself nested in the third item of a sequence is the + string e.g. + 0004|1220/2#0008|0082/0#0008|0090 + - src/gdcmDocEntry.h: added a new Key (of type gdcmTagKey) member, in + order to hold the new sequence compatible key. Previously, the + GetKey() method would look in the underlying gdcmDictEntry. + - src/gdcmDocEntry.cxx: + -- constructor now copies the underlying DictEntry key, in the local + Key member. + -- ::Print: displays the member Key, instead of the (group, element). + - src/gdcmCommon.h: added some comments on typedef gdcmTagKey. + - src/gdcmDocEntrySet.h:xi + -- ::ParseDES() now setups the gdcmTagKey of the sequence it is parsing. + -- now has a new BaseTagKey member. + -- STYLE. + * src/gdcmValEntry.[h|cxx], src/gdcmBinEntry.[h|cxx]: the member VoidArea, + previously a member of gdcmValEntry, moved to gdcmBinEntry were is + truly belongs. + This poses the problem with the semantics of the following lines + LoadEntryVoidArea(0x0028,0x1201); // R LUT + LoadEntryVoidArea(0x0028,0x1202); // G LUT + LoadEntryVoidArea(0x0028,0x1203); // B LUT + in gdcmDocument::gdcmDocument(std::string const & ). Please refer + to the long FIXME note for what the problem is. Nevertheless in + order to get things working the dicom dictionary was altered ! + Please fix things urgently... + * Dicts/dicomV3.dic WRONGLY altered (this means we introduced a uncorrect + information), see above note on moving the member VoidArea. Nevertheless + the following entries previously correctly set as US are now inproperly + set to OW: + 0028 1201 OW IMG Red Palette Color Lookup Table Data + 0028 1202 OW IMG Green Palette Color Lookup Table Data + 0028 1203 OW IMG Blue Palette Color Lookup Table Data + * src/gdcmDocEntry.[h|cxx], src/gdcmSeqEntry.h: SQDepthLevel member + of gdcmDocEntry moved to gdcmSeqEntry. + * src/gdcmSeqEntry.cxx: STYLE. + 2004-08-04 Eric Boix * Test/TestAllEntryVerify.cxx minor fix and added comments. diff --git a/Dicts/dicomV3.dic b/Dicts/dicomV3.dic index e5657fd3..1e6c3cd0 100644 --- a/Dicts/dicomV3.dic +++ b/Dicts/dicomV3.dic @@ -841,9 +841,9 @@ 0028 1103 US IMG Blue Palette Color Lookup Table Descriptor 0028 1199 UI IMG Palette Color Lookup Table UID 0028 1200 US IMG Gray Lookup Table Data (RET) -0028 1201 US IMG Red Palette Color Lookup Table Data -0028 1202 US IMG Green Palette Color Lookup Table Data -0028 1203 US IMG Blue Palette Color Lookup Table Data +0028 1201 OW IMG Red Palette Color Lookup Table Data +0028 1202 OW IMG Green Palette Color Lookup Table Data +0028 1203 OW IMG Blue Palette Color Lookup Table Data 0028 1221 OW IMG Segmented Red Palette Color Lookup Table Data 0028 1222 OW IMG Segmented Green Palette Color Lookup Table Data 0028 1223 OW IMG Segmented Blue Palette Color Lookup Table Data diff --git a/TODO b/TODO index a891bf9f..4673dc10 100644 --- a/TODO +++ b/TODO @@ -16,6 +16,7 @@ Convert the C-like IO to C++ IO: binary IO are available at http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html ----------------------------------------------------------------------------- +* Clean up src/gdcmValEntry.[h|cxx] from VoidArea * vtk/vtkGdcmHeader.cxx: if speed becomes a concern some changes can be made at the cost of memory consumption (refer to header of vtk/vtkGdcmHeader.cxx) diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index cee3120f..a010ff72 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2004/09/10 14:32:04 $ - Version: $Revision: 1.25 $ + Date: $Date: 2004/09/13 12:10:53 $ + 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 @@ -28,7 +28,7 @@ */ gdcmBinEntry::gdcmBinEntry(gdcmDictEntry* e) : gdcmValEntry(e) { - VoidArea = NULL; + VoidArea = 0; } /** @@ -42,7 +42,8 @@ gdcmBinEntry::gdcmBinEntry(gdcmDocEntry* e) : gdcmValEntry(e->GetDictEntry()) ImplicitVR = e->IsImplicitVR(); Offset = e->GetOffset(); PrintLevel = e->GetPrintLevel(); - SQDepthLevel = e->GetDepthLevel(); + //FIXME + //SQDepthLevel = e->GetDepthLevel(); VoidArea = 0; // let's be carefull ! } @@ -119,7 +120,7 @@ void gdcmBinEntry::Write(FILE *fp, FileType filetype) /// \brief Sets the value (non string) of the current Dicom Header Entry -void gdcmBinEntry::SetVoidArea(void* area) +void gdcmBinEntry::SetVoidArea( void* area ) { if (VoidArea) free(VoidArea); diff --git a/src/gdcmBinEntry.h b/src/gdcmBinEntry.h index 8ba66fdd..bbc8451d 100644 --- a/src/gdcmBinEntry.h +++ b/src/gdcmBinEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.h,v $ Language: C++ - Date: $Date: 2004/09/10 14:32:04 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/09/13 12:10:53 $ + 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 @@ -45,8 +45,8 @@ public: /// \brief Returns the area value of the current Dicom Header Entry /// when it's not string-translatable (e.g : a LUT table) - void* GetVoidArea() { return VoidArea; }; - void SetVoidArea(void* area); + void* GetVoidArea() { return VoidArea; } + void SetVoidArea( void* area ); protected: @@ -55,8 +55,8 @@ private: // Variables /// \brief unsecure memory area to hold 'non string' values - /// (ie : Lookup Tables, overlays, icons) - // void *VoidArea; + /// (ie : Lookup Tables, overlays, icons) + void *VoidArea; }; diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index e36b21e3..08bf07a0 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmCommon.h,v $ Language: C++ - Date: $Date: 2004/09/09 17:49:24 $ - Version: $Revision: 1.30 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.31 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -96,6 +96,33 @@ const std::string GDCM_BINLOADED = "gdcm::Binary data loaded"; const std::string GDCM_NOTLOADED = "gdcm::NotLoaded"; const std::string GDCM_UNREAD = "gdcm::UnRead"; +/// \brief gdcmTagKey is made to old an "universal" (as in URL, Universal +/// Ressource Locator) key to a gdcmDocEntry i.e. a dicom tag. +/// A dicom tag allways has a group and an element, but a set of tags +/// embeded in various (optionally nested) sequences and sharing +/// the same group and element all share the same (group, element) +/// "identifier". Hence the (group, element) cannot be used as an +/// identifier (in gdcm we shall refer to a "TagKey") of a tag. +/// In order to construct a proper tag identifier (i.e. a key) we +/// consider the following definition of a TagKey: +/// - let Group, Element be the string representation of the +/// group and element dicom tag members, +/// - let ItemNumber be the string representation of the integer +/// index of the considered item number of a sequence, +/// Let the key of a tag embeded in a sequence, noted SeqTag, be +/// the form: +/// /ItemNumber#Group|Element +/// where "/", "#" and "|" are characters acting as separators. +/// Then the general form of a gdcmTagKey is given by: +/// Group|Element +/// where means NO or many instances of SeqTag. +/// Hence the gdcmTagKey of a tag not "leaving" in a sequence is the +/// string e.g. +/// 0028|1201 +/// but the gdcmTagKey of a tag "embeded" is the first item of +/// a sequence, itself nested in the third item of a sequence is the +/// string e.g. +/// 0004|1220/2#0008|0082/0#0008|0090 typedef std::string gdcmTagKey; typedef std::string TagName; diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 54c7ed04..5f313486 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2004/09/09 17:49:24 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/09/13 12:10:53 $ + 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 @@ -37,6 +37,7 @@ gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) { ImplicitVR = false; DictEntry = in; + SetKey( in->GetKey( ) ); Offset = 0 ; // To avoid further missprinting } @@ -58,14 +59,13 @@ void gdcmDocEntry::Print(std::ostream & os) std::string d2, vr; std::ostringstream s; uint32_t lgth; - char greltag[10]; //group element tag g = GetGroup(); e = GetElement(); o = GetOffset(); vr = GetVR(); - sprintf(greltag,"%04x|%04x ",g,e); - s << greltag ; + + s << GetKey(); if (PrintLevel >= 2) { diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index e3162589..734a9f83 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.h,v $ Language: C++ - Date: $Date: 2004/09/03 20:27:44 $ - Version: $Revision: 1.19 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,7 +47,10 @@ public: uint16_t GetElement() { return DictEntry->GetElement();}; /// Returns the 'key' of the current Dicom Header Entry - std::string GetKey() { return DictEntry->GetKey(); }; + void SetKey( gdcmTagKey key ) { Key = key; } + + /// Returns the 'key' of the current Dicom Header Entry + std::string GetKey() { return Key; } /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom /// Dictionnary of the current Dicom Header Entry @@ -132,14 +135,6 @@ public: bool IsItemDelimitor(); bool IsSequenceDelimitor(); - /// \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; } - private: // FIXME: In fact we should be more specific and use : // friend gdcmDocEntry * gdcmHeader::ReadNextElement(void); @@ -170,9 +165,10 @@ protected: /// How many details are to be printed (value : 0,1,2) int PrintLevel; - - /// Gives the depth level of elements inside SeQuences - int SQDepthLevel; + + /// \brief Generalized key (i.e. a gdcmBaseTagKey prepending a gdcmTagKey) + /// of this gdcmDocEntry + gdcmTagKey Key; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 26fd1269..982e0286 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/08/26 15:29:52 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.16 $ 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,7 @@ #include "gdcmException.h" #include "gdcmDocEntry.h" +typedef std::string gdcmBaseTagKey; //----------------------------------------------------------------------------- class GDCM_EXPORT gdcmDocEntrySet @@ -48,6 +49,9 @@ public: /// 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); @@ -78,6 +82,10 @@ protected: /// 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 cdcdd9cb..9976959e 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/13 07:49:36 $ - Version: $Revision: 1.75 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.76 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -109,8 +109,7 @@ gdcmDocument::gdcmDocument( std::string const & filename ) SQDepthLevel = 0; - long l = ParseDES( this, beg, lgt, false); // le Load sera fait a la volee - (void)l; //is l used anywhere ? + (void)ParseDES( this, beg, lgt, false); // le Load sera fait a la volee rewind(Fp); @@ -120,13 +119,31 @@ gdcmDocument::gdcmDocument( std::string const & filename ) if( PhotometricInterpretation == "PALETTE COLOR " ) { LoadEntryVoidArea(0x0028,0x1200); // gray LUT + /// FIXME FIXME FIXME + /// The tags refered by the three following lines used to be CORRECTLY + /// defined as having an US Value Representation in the public + /// dictionnary. BUT the semantics implied by the three following + /// lines state that the corresponding tag contents are in fact + /// the ones of a gdcmBinEntry. + /// In order to fix things "Quick and Dirty" the dictionnary was + /// altered on PURPOUS but now contains a WRONG value. + /// In order to fix things and restore the dictionary to its + /// correct value, one needs to decided of the semantics by deciding + /// wether the following tags are either: + /// - multivaluated US, and hence loaded as gdcmValEntry, but afterwards + /// also used as gdcmBinEntry, which requires the proper conversion, + /// - OW, and hence loaded as gdcmBinEntry, but afterwards also used + /// as gdcmValEntry, which requires the proper conversion. LoadEntryVoidArea(0x0028,0x1201); // R LUT LoadEntryVoidArea(0x0028,0x1202); // G LUT LoadEntryVoidArea(0x0028,0x1203); // B LUT - LoadEntryVoidArea(0x0028,0x1221); // Segmented Red Palette Color LUT Data - LoadEntryVoidArea(0x0028,0x1222); // Segmented Green Palette Color LUT Data - LoadEntryVoidArea(0x0028,0x1223); // Segmented Blue Palette Color LUT Data + // Segmented Red Palette Color LUT Data + LoadEntryVoidArea(0x0028,0x1221); + // Segmented Green Palette Color LUT Data + LoadEntryVoidArea(0x0028,0x1222); + // Segmented Blue Palette Color LUT Data + LoadEntryVoidArea(0x0028,0x1223); } //FIXME later : how to use it? LoadEntryVoidArea(0x0028,0x3006); //LUT Data (CTX dependent) @@ -1017,7 +1034,7 @@ void * gdcmDocument::GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem) * @param group group number of the Entry * @param elem element number of the Entry */ -void *gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) +void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) { gdcmDocEntry *docElement = GetDocEntryByNumber(group, elem); if ( !docElement ) @@ -1040,7 +1057,10 @@ void *gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) return NULL; } /// \TODO Drop any already existing void area! JPR - SetEntryVoidAreaByNumber(a, group, elem); + if( !SetEntryVoidAreaByNumber( a, group, elem ) ); + { + dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea setting failed."); + } return a; } @@ -1083,15 +1103,16 @@ bool gdcmDocument::SetEntryVoidAreaByNumber(void * area, uint16_t group, uint16_t element) { - gdcmTagKey key = gdcmDictEntry::TranslateToKey(group, element); - if ( !TagHT.count(key)) + gdcmDocEntry* currentEntry = GetDocEntryByNumber(group, element); + if ( !currentEntry ) { return false; } - - // This was for multimap ? - (( gdcmBinEntry *)( ((TagHT.equal_range(key)).first)->second ))->SetVoidArea(area); - + if ( gdcmBinEntry* binEntry = dynamic_cast(currentEntry) ) + { + binEntry->SetVoidArea( area ); + return true; + } return true; } @@ -1296,7 +1317,6 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, bool delim_mode) { gdcmDocEntry *newDocEntry = 0; - gdcmValEntry *newValEntry = 0; unsigned long l = 0; int depth = set->GetDepthLevel(); @@ -1319,11 +1339,12 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, if ( gdcmGlobal::GetVR()->IsVROfGdcmStringRepresentable(vr) ) { /////// ValEntry - newValEntry = new gdcmValEntry(newDocEntry->GetDictEntry()); - newValEntry->Copy(newDocEntry); - newValEntry->SetDepthLevel(depth); - set->AddEntry(newValEntry); - LoadDocEntry(newValEntry); + gdcmValEntry* newValEntry = + new gdcmValEntry( newDocEntry->GetDictEntry() ); + newValEntry->Copy( newDocEntry ); + newValEntry->SetKey( set->GetBaseTagKey() + newValEntry->GetKey() ); + set->AddEntry( newValEntry ); + LoadDocEntry( newValEntry ); if (newValEntry->IsItemDelimitor()) { break; @@ -1343,10 +1364,12 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, } ////// BinEntry or UNKOWN VR: - gdcmBinEntry *bn = new gdcmBinEntry(newDocEntry->GetDictEntry()); - bn->Copy(newDocEntry); - set->AddEntry(bn); - LoadDocEntry(bn); + gdcmBinEntry* newBinEntry = + new gdcmBinEntry( newDocEntry->GetDictEntry() ); + newBinEntry->Copy( newDocEntry ); + newBinEntry->SetKey( set->GetBaseTagKey() + newBinEntry->GetKey() ); + set->AddEntry( newBinEntry ); + LoadDocEntry( newBinEntry ); } if (newDocEntry->GetGroup() == 0x7fe0 && @@ -1387,20 +1410,21 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, } } // no other way to create it ... - gdcmSeqEntry *sq = new gdcmSeqEntry(newDocEntry->GetDictEntry(), - set->GetDepthLevel()); - sq->Copy(newDocEntry); - sq->SetDelimitorMode(delim_mode); - sq->SetDepthLevel(depth); + gdcmSeqEntry* newSeqEntry = + new gdcmSeqEntry( newDocEntry->GetDictEntry(), + set->GetDepthLevel() ); + newSeqEntry->Copy( newDocEntry ); + newSeqEntry->SetDelimitorMode( delim_mode ); + newSeqEntry->SetDepthLevel( depth ); + newSeqEntry->SetKey( set->GetBaseTagKey() + newSeqEntry->GetKey() ); if ( l != 0 ) { // Don't try to parse zero-length sequences - long lgt = ParseSQ( sq, - newDocEntry->GetOffset(), - l, delim_mode); - (void)lgt; //not used... + (void)ParseSQ( newSeqEntry, + newDocEntry->GetOffset(), + l, delim_mode); } - set->AddEntry(sq); + set->AddEntry( newSeqEntry ); if ( !delim_mode && (ftell(Fp)-offset) >= l_max) { break; @@ -1415,17 +1439,15 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, * \brief Parses a Sequence ( SeqEntry after SeqEntry) * @return parsed length for this level */ -long gdcmDocument::ParseSQ(gdcmSeqEntry *set, - long offset, long l_max, bool delim_mode) +long gdcmDocument::ParseSQ( gdcmSeqEntry* seqEntry, + long offset, long l_max, bool delim_mode) { int SQItemNumber = 0; bool dlm_mod; - //int depth = set->GetDepthLevel(); - //(void)depth; //not used while (true) { - gdcmDocEntry *newDocEntry = ReadNextDocEntry(); + gdcmDocEntry* newDocEntry = ReadNextDocEntry(); if ( !newDocEntry ) { // FIXME Should warn user @@ -1435,7 +1457,7 @@ long gdcmDocument::ParseSQ(gdcmSeqEntry *set, { if ( newDocEntry->IsSequenceDelimitor() ) { - set->SetSequenceDelimitationItem( newDocEntry ); + seqEntry->SetSequenceDelimitationItem( newDocEntry ); break; } } @@ -1444,8 +1466,13 @@ long gdcmDocument::ParseSQ(gdcmSeqEntry *set, break; } - gdcmSQItem *itemSQ = new gdcmSQItem(set->GetDepthLevel()); - itemSQ->AddEntry(newDocEntry); + gdcmSQItem *itemSQ = new gdcmSQItem( seqEntry->GetDepthLevel() ); + std::ostringstream newBase; + newBase << seqEntry->GetKey() + << "/" + << SQItemNumber + << "#"; + itemSQ->SetBaseTagKey( newBase.str() ); unsigned int l = newDocEntry->GetReadLength(); if ( l == 0xffffffff ) @@ -1457,12 +1484,11 @@ long gdcmDocument::ParseSQ(gdcmSeqEntry *set, dlm_mod = false; } - int lgr = ParseDES(itemSQ, newDocEntry->GetOffset(), l, dlm_mod); - (void)lgr; //FIXME not used + (void)ParseDES(itemSQ, newDocEntry->GetOffset(), l, dlm_mod); - set->AddEntry(itemSQ, SQItemNumber); + seqEntry->AddEntry( itemSQ, SQItemNumber ); SQItemNumber++; - if ( !delim_mode && (ftell(Fp)-offset) >= l_max) + if ( !delim_mode && ( ftell(Fp) - offset ) >= l_max ) { break; } @@ -1554,7 +1580,6 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry) if ( IsDocEntryAnInteger(entry) ) { uint32_t NewInt; - //std::ostringstream s; //shadow previous declaration int nbInt; // When short integer(s) are expected, read and convert the following // n *two characters properly i.e. consider them as short integers as diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index ca6e1305..d31c2b10 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/08/31 14:24:47 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/09/13 12:10:53 $ + 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 @@ -33,11 +33,12 @@ gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) : gdcmDocEntry(e) { - delimitor_mode = false; - seq_term = NULL; - SQDepthLevel = depth; UsableLength = 0; ReadLength = 0xffffffff; + SQDepthLevel = depth; + + delimitor_mode = false; + seq_term = NULL; } /** @@ -45,15 +46,17 @@ gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) * @param e Pointer to existing Doc entry * @param depth depth level of the current Seq entry */ -gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDictEntry()) +gdcmSeqEntry::gdcmSeqEntry( gdcmDocEntry* e, int depth ) + : gdcmDocEntry( e->GetDictEntry() ) { this->UsableLength = 0; this->ReadLength = 0xffffffff; + SQDepthLevel = depth; + this->ImplicitVR = e->IsImplicitVR(); this->Offset = e->GetOffset(); - //this->printLevel = e->GetPrintLevel(); // no longer exists ?!? - this->SQDepthLevel = depth; } + /** * \brief Canonical destructor. */ @@ -66,11 +69,11 @@ gdcmSeqEntry::~gdcmSeqEntry() { delete seq_term; } -/* +/** * \brief canonical Printer */ -void gdcmSeqEntry::Print(std::ostream &os){ - +void gdcmSeqEntry::Print(std::ostream &os) +{ // First, Print the Dicom Element itself. SetPrintLevel(2); gdcmDocEntry::Print(os); @@ -119,8 +122,8 @@ void gdcmSeqEntry::Write(FILE *fp, FileType filetype) (*cc)->Write(fp, filetype); } - //we force the writting of a Sequence Delimitation item - // because we wrote the Sequence as a 'no Length' sequence + // we force the writting of a Sequence Delimitation item + // because we wrote the Sequence as a 'no Length' sequence fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp); fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp); fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp); @@ -129,22 +132,21 @@ void gdcmSeqEntry::Write(FILE *fp, FileType filetype) //----------------------------------------------------------------------------- // Public - /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence. -void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) { +/// \brief adds the passed ITEM to the ITEM chained List for this SeQuence. +void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem, int itemNumber) +{ sqItem->SetSQItemNumber(itemNumber); items.push_back(sqItem); } -/// \brief Sets the depth level of a Sequence Entry embedded in a SeQuence -void gdcmSeqEntry::SetDepthLevel(int depth) { - SQDepthLevel = depth; -} - -/// \brief return a pointer to the SQItem referenced by its ordinal number -/// (returns the first one if ordinal number is <0 -/// returns the last one if ordinal number is > item number - -gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) { +/** + * \brief return a pointer to the SQItem referenced by its ordinal number. + * Returns the first item when argument is negative. + * Returns the last item when argument is bigget than the total + * item number. + */ +gdcmSQItem *gdcmSeqEntry::GetSQItemByOrdinalNumber(int nb) +{ if (nb<0) return (*(items.begin())); int count = 0 ; diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 61c7d8b6..a0b0d67b 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/08/26 15:29:53 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -50,8 +50,11 @@ public: void AddEntry(gdcmSQItem *it, int itemNumber); gdcmSQItem *GetSQItemByOrdinalNumber(int itemNumber); - void SetDepthLevel(int depth); - + /// Gets the depth level + int GetDepthLevel() { return SQDepthLevel; } + + /// Sets the depth level of a Sequence Entry embedded in a SeQuence + void SetDepthLevel(int depth) { SQDepthLevel = depth; } protected: private: @@ -65,6 +68,9 @@ private: /// sequence terminator item gdcmDocEntry *seq_term; + + /// Gives the depth level of elements inside SeQuences + int SQDepthLevel; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index c1018fca..82d27436 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2004/09/10 18:54:39 $ - Version: $Revision: 1.24 $ + Date: $Date: 2004/09/13 12:10:53 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,23 +32,20 @@ */ gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) { - VoidArea = NULL; // will be in BinEntry ? } /** * \brief Constructor from a given gdcmDocEntry * @param e Pointer to existing Doc entry */ -gdcmValEntry::gdcmValEntry(gdcmDocEntry* e) : gdcmDocEntry(e->GetDictEntry()) +gdcmValEntry::gdcmValEntry(gdcmDocEntry* e) + : gdcmDocEntry(e->GetDictEntry()) { UsableLength = e->GetLength(); ReadLength = e->GetReadLength(); ImplicitVR = e->IsImplicitVR(); Offset = e->GetOffset(); PrintLevel = e->GetPrintLevel(); - SQDepthLevel = e->GetDepthLevel(); - - VoidArea = NULL; // will be in BinEntry ? } @@ -57,11 +54,6 @@ gdcmValEntry::gdcmValEntry(gdcmDocEntry* e) : gdcmDocEntry(e->GetDictEntry()) */ gdcmValEntry::~gdcmValEntry () { - if (!VoidArea) // will be in BinEntry - { - free(VoidArea); - VoidArea = NULL; // let's be carefull ! - } } //----------------------------------------------------------------------------- diff --git a/src/gdcmValEntry.h b/src/gdcmValEntry.h index f2811f75..4abc7eff 100644 --- a/src/gdcmValEntry.h +++ b/src/gdcmValEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.h,v $ Language: C++ - Date: $Date: 2004/09/03 20:27:44 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/09/13 12:10:53 $ + 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 @@ -45,15 +45,10 @@ public: /// Sets the value (string) of the current Dicom Document Entry void SetValue(std::string const & val) { Value = val; }; - /// Sets the value (void *) of the current Dicom Document Entry - void SetVoidArea(void * val) { VoidArea = val; }; - virtual void Print(std::ostream &os = std::cout); virtual void Write(FILE *fp, FileType filetype); protected: - /// \brief for 'non string' values. Will be move to gdcmBinEntry, later - void* VoidArea; // clean it out later private: // Members :