From: jpr Date: Wed, 12 May 2004 12:55:07 +0000 (+0000) Subject: general commit of (future) new classes. X-Git-Tag: Version0.5.bp~176 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=28e546efc3dc694c93a006529aecad5c4821b432;p=gdcm.git general commit of (future) new classes. PLEASE don't try to use right now --- diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index d7857acb..15110221 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -10,7 +10,7 @@ /** * \brief Constructor from a given gdcmBinEntry */ -gdcmBinEntry::gdcmBinEntry() : gdcmValEntry() { +gdcmBinEntry::gdcmBinEntry(gdcmDictEntry* e) : gdcmValEntry(e) { } diff --git a/src/gdcmBinEntry.h b/src/gdcmBinEntry.h index c3254ad6..2247e529 100644 --- a/src/gdcmBinEntry.h +++ b/src/gdcmBinEntry.h @@ -19,7 +19,7 @@ class GDCM_EXPORT gdcmBinEntry : public gdcmValEntry { public: - gdcmBinEntry(void); + gdcmBinEntry(gdcmDictEntry* e); ~gdcmBinEntry(void); diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 8c50e202..9c553bb1 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -1,6 +1,7 @@ // gdcmDocEntry.cxx //----------------------------------------------------------------------------- // + #include "gdcmDocEntry.h" #include "gdcmTS.h" #include "gdcmGlobal.h" @@ -169,9 +170,24 @@ void gdcmDocEntry::Copy (gdcmDocEntry* e) { this->SQDepthLevel = e->SQDepthLevel; } +bool gdcmDocEntry::isItemDelimitor() { + if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) ) + return true; + else + return false; +} + +bool gdcmDocEntry::isSequenceDelimitor() { + if (GetGroup() == 0xfffe && GetElement() == 0xe0dd) + return true; + else + return false; +} + //----------------------------------------------------------------------------- // Protected + //----------------------------------------------------------------------------- // Private diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index 5f1094ba..37b9aa39 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -19,6 +19,14 @@ class GDCM_EXPORT gdcmDocEntry { public: gdcmDocEntry(gdcmDictEntry*); + /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted into a + /// 'string', if it's stored as an integer in the Dicom Header of the + /// current Dicom Header Entry + /// TODO virtual? + //inline std::string GetValue(void) { return value; }; + // Pour continuer a compiler :-( + inline std::string GetValue(void) { return "value"; }; + /// Returns the Dicom Group number of the current Dicom Header Entry inline guint16 GetGroup(void) { return entry->GetGroup(); }; @@ -82,7 +90,7 @@ public: /// @return true if the current Dicom Element was checked as ImplicitVr inline bool gdcmDocEntry::IsImplicitVR(void) { return ImplicitVR; }; - /// \brief Tells us if the VR of the current Dicom Element is Unkonwn + /// \brief Tells us if the VR of the current Dicom Element is Unknown /// @return true if the VR is unkonwn inline bool gdcmDocEntry::IsVRUnknown(void) { return entry->IsVRUnknown(); }; @@ -100,6 +108,9 @@ public: /// \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy void SetPrintLevel(int level) { printLevel = level; }; + /// \brief Gets the print level for the Dicom Header Elements + int GetPrintLevel(void) { return(printLevel); }; + void Print (std::ostream & os = std::cout); /// Gets the depth level of a Dicom Header Entry embedded in a SeQuence @@ -108,7 +119,10 @@ public: guint32 GetFullLength(void); void Copy(gdcmDocEntry *doc); - + + bool isItemDelimitor(); + bool isSequenceDelimitor(); + private: // FIXME: In fact we should be more specific and use : // friend gdcmDocEntry * gdcmHeader::ReadNextElement(void); @@ -118,8 +132,9 @@ private: inline void SetSQDepthLevel(int depthLevel) { SQDepthLevel = depthLevel; }; // Variables - gdcmDictEntry *entry; + gdcmDictEntry *entry; + /// \brief Updated from ReadLength, by FixFoungLentgh() for fixing a bug /// in the header or helping the parser going on guint32 UsableLength; diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index d60f1dbe..32301489 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -1,13 +1,21 @@ // gdcmDocEntrySet.cxx //----------------------------------------------------------------------------- // +#include +#include "gdcmDebug.h" +#include "gdcmCommon.h" +#include "gdcmGlobal.h" #include "gdcmDocEntrySet.h" #include "gdcmException.h" +#include "gdcmDocEntry.h" +#include "gdcmSeqEntry.h" +#include "gdcmValEntry.h" +#include "gdcmBinEntry.h" //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmDocEntrySEt + * \ingroup gdcmDocEntrySet * \brief Constructor from a given gdcmDocEntrySet */ gdcmDocEntrySet::gdcmDocEntrySet() { @@ -27,11 +35,13 @@ gdcmDocEntrySet::~gdcmDocEntrySet(){ //----------------------------------------------------------------------------- // Public - +//bool gdcmDocEntrySet::AddEntry(gdcmDocEntry *Entry){return true;} //----------------------------------------------------------------------------- // Protected + + //----------------------------------------------------------------------------- // Private @@ -40,6 +50,9 @@ gdcmDocEntrySet::~gdcmDocEntrySet(){ * \ and load element values (a voir !) * @return false anything wrong happens */ + + /* just to keep the code + bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) throw(gdcmFormatError) { (void)exception_on_error; @@ -48,18 +61,18 @@ bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) gdcmValEntry *newValEntry = (gdcmValEntry *)0; gdcmBinEntry *newBinEntry = (gdcmBinEntry *)0; gdcmSeqEntry *newSeqEntry = (gdcmSeqEntry *)0; - //gdcmDictEntry *NewTag = (gdcmDictEntry *)0; - - while (newDocEntry = ReadNextDocEntry())) { + + string vr; + while (newDocEntry = ReadNextDocEntry()) { // TODO (?) : liberation du DocEntry ainsi cree, // apres copie dans un ValEntry, SeqEntry, BinEntry - vr = newDocEntry->getVR(); + vr = newDocEntry->GetVR(); if (vr == "SQ" ) { // --- SeqEntry - newSeqEntry = (gdcmSeqEntry *)0; - if (!NewSeqEntry) { + newSeqEntry = new gdcmSeqEntry((gdcmDictEntry*)NULL); + if (!newSeqEntry) { dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet", "failed to allocate gdcmSeqEntry"); return false; @@ -70,43 +83,62 @@ bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) // (ensemble d' ITEMs, en fait, // chaque ITEM etant chargé avec LoadDocEntrySet) - SkipDocEntry(newSeqEntry); // voir ce qu'on fait pour une SeQuence - AddDocEntry(newSeqEntry); + //SkipDocEntry(newSeqEntry); // voir ce qu'on fait pour une SeQuence + AddEntry(newSeqEntry); // on appele la fonction generique, + // ou une fonction spécialisée ? } else if (vr == "AE" || vr == "AS" || vr == "DA" || vr == "PN" || - vr == "UI" || vr == "TM" ) { + vr == "UI" || vr == "TM" || vr == "SH" || vr == "LO" || + vr == "CS" || vr == "IS" || vr == "LO" || vr == "LT" || + vr == "SH" || vr == "ST" || + vr == "SL" || vr == "SS" || vr == "UL" || vr == "US" + ) { // --- ValEntry - newValEntry = (gdcmValEntry *)0; - if (!NewValEntry) { + newValEntry = new gdcmValEntry((gdcmDictEntry*)NULL); + if (!newValEntry) { dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet", "failed to allocate gdcmValEntry"); return false; } newValEntry->Copy(newDocEntry); - SkipDocEntry(newValEntry); - AddDocEntry(newValEntry); - - } else { + //SkipDocEntry(newValEntry); //le skip devrait etre fait dans le Read + AddEntry(newValEntry); // on appele la fonction generique, + // ou une fonction spécialisée ? + + // Maybe the following VR do correspond to a BinEntry + + //AT Attribute Tag; // OK // 2 16-bit unsigned short integers + //FL Floating Point Single; // 32-bit IEEE 754:1985 float + //FD Floating Point Double; // 64-bit IEEE 754:1985 double + //UN Unknown; // Any length of bytes + //UT Unlimited Text; // At most 2^32 -1 chars + //OB Other Byte String; // String of bytes (VR independant) + //OW Other Word String; // String of 16-bit words (VR dependant) + } else { // --- BinEntry - NewBinEntry = new gdcmBinEntry(DictEntry); - if (!NewValEntry) { + newBinEntry = new gdcmBinEntry((gdcmDictEntry*)NULL); + if (!newBinEntry) { dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet", "failed to allocate gdcmBinEntry"); return false; } newBinEntry->Copy(newDocEntry); - SkipDocEntry(newBinEntry); - AddDocEntry(newBinEntry); + // SkipDocEntry(newBinEntry); //le skip devrait etre fait dans le Read + AddEntry(newBinEntry); // on appele la fonction generique, + // ou une fonction spécialisée ? } } - rewind(fp); + // TODO : il n'y a plus de Chained List qui contient toutes les Entries // Le chargement des valeurs devra se faire à la volée // Be carefull : merging this two loops may cause troubles ... + +/* + rewind(fp); for (ListTag::iterator i = GetListEntry().begin(); i != GetListEntry().end(); ++i) @@ -114,7 +146,11 @@ bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) LoadDocEntry(*i); } rewind(fp); - + + */ + + /* TO DO : deporter den fin de parsing du DOCUMENT (pas du EntrySet) + // -------------------------------------------------------------- // Special Patch to allow gdcm to read ACR-LibIDO formated images // @@ -133,89 +169,15 @@ bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) SetEntryByNumber(columns, 0x0028, 0x0010); SetEntryByNumber(rows , 0x0028, 0x0011); } - // ----------------- End of Special Patch ---------------- + // ----------------- End of Special Patch ---------------- + */ + + /* return true; } - - -/** - * \brief Check the correspondance between the VR of the header entry - * and the taken VR. If they are different, the header entry is - * updated with the new VR. - * @param Entry Header Entry to check - * @param vr Dicom Value Representation - * @return false if the VR is incorrect of if the VR isn't referenced - * otherwise, it returns true */ -// NE MARCHE PAS EN L'ETAT : -// On a besoin de VR pour 'fabriquer', au choix ValEntry, BinEntry, ou SeqEntry. -// - -bool gdcmDocEntrySet::CheckEntryVR(gdcmHeaderEntry *Entry, VRKey vr) -{ - char msg[100]; // for sprintf - bool RealExplicit = true; - - // Assume we are reading a falsely explicit VR file i.e. we reached - // a tag where we expect reading a VR but are in fact we read the - // first to bytes of the length. Then we will interogate (through find) - // the dicom_vr dictionary with oddities like "\004\0" which crashes - // both GCC and VC++ implementations of the STL map. Hence when the - // expected VR read happens to be non-ascii characters we consider - // we hit falsely explicit VR tag. - - if ( (!isalpha(vr[0])) && (!isalpha(vr[1])) ) - RealExplicit = false; - - // CLEANME searching the dicom_vr at each occurence is expensive. - // PostPone this test in an optional integrity check at the end - // of parsing or only in debug mode. - if ( RealExplicit && !gdcmGlobal::GetVR()->Count(vr) ) - RealExplicit= false; - - if ( !RealExplicit ) - { - // We thought this was explicit VR, but we end up with an - // implicit VR tag. Let's backtrack. - sprintf(msg,"Falsely explicit vr file (%04x,%04x)\n", - Entry->GetGroup(),Entry->GetElement()); - dbg.Verbose(1, "gdcmParser::FindVR: ",msg); - if (Entry->GetGroup()%2 && Entry->GetElement() == 0x0000) { // Group length is UL ! - gdcmDictEntry* NewEntry = NewVirtualDictEntry( - Entry->GetGroup(),Entry->GetElement(), - "UL","FIXME","Group Length"); - Entry->SetDictEntry(NewEntry); - } - return(false); - } - - if ( Entry->IsVRUnknown() ) - { - // When not a dictionary entry, we can safely overwrite the VR. - if (Entry->GetElement() == 0x0000) { // Group length is UL ! - Entry->SetVR("UL"); - } else { - Entry->SetVR(vr); - } - } - else if ( Entry->GetVR() != vr ) - { - // The VR present in the file and the dictionary disagree. We assume - // the file writer knew best and use the VR of the file. Since it would - // be unwise to overwrite the VR of a dictionary (since it would - // compromise it's next user), we need to clone the actual DictEntry - // and change the VR for the read one. - gdcmDictEntry* NewEntry = NewVirtualDictEntry( - Entry->GetGroup(),Entry->GetElement(), - vr,"FIXME",Entry->GetName()); - Entry->SetDictEntry(NewEntry); - } - return(true); -} - - //----------------------------------------------------------------------------- diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 7ecee4e8..ff309a33 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -5,7 +5,7 @@ #include "gdcmException.h" #include "gdcmDocEntry.h" - + //----------------------------------------------------------------------------- class GDCM_EXPORT gdcmDocEntrySet @@ -16,14 +16,28 @@ public: gdcmDocEntrySet(void); ~gdcmDocEntrySet(void); - void FindDocEntryLength (gdcmDocEntry *Entry); - + void FindDocEntryLength (gdcmDocEntry *Entry, FileType filetype, FILE* fp); + virtual bool AddEntry(gdcmDocEntry *Entry) =0; // pure virtual + bool CheckEntryVR(gdcmDocEntry *Entry, std::string vr); + gdcmDictEntry *NewVirtualDictEntry(guint16 group, + guint16 element, + std::string vr = "unkn", + std::string fourth = "unkn", + std::string name = "unkn"); + protected: + void gdcmDocEntrySet::FindDocEntryLength (gdcmDocEntry *Entry); + private: - - bool LoadDocEntrySet(bool exception_on_error = false) - throw(gdcmFormatError); + + // DocEntry related utilities + + virtual gdcmDocEntry *NewDocEntryByNumber(guint16 group, + guint16 element)=0; // pure virtual + virtual gdcmDocEntry *NewDocEntryByName (std::string Name)=0; // pure virtual + + }; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 7f87beac..db729329 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -2,6 +2,10 @@ //----------------------------------------------------------------------------- #include "gdcmDocument.h" +#include "gdcmValEntry.h" +#include "gdcmBinEntry.h" +#include "gdcmSeqEntry.h" + #include "gdcmGlobal.h" #include "gdcmUtil.h" #include "gdcmDebug.h" @@ -68,13 +72,11 @@ gdcmDocument::gdcmDocument(const char *inFilename, if ( !OpenFile(exception_on_error)) return; - rewind(fp); - if (!CheckSwap()) - return NULL; // Du menage à faire avant de sortir ? - LoadDocEntries(); + //LoadHeaderEntries(); + long l=ParseES( (gdcmDocEntrySet *)this, 120L, 0x7fffffff, false); + // TODO : find the right values CloseFile(); - wasUpdated = 0; // will be set to 1 if user adds an entry printLevel = 1; // 'Medium' print level by default } @@ -89,7 +91,6 @@ gdcmDocument::gdcmDocument(bool exception_on_error) { SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); Initialise(); - wasUpdated = 0; // will be set to 1 if user adds an entry printLevel = 1; // 'Medium' print level by default } @@ -104,7 +105,7 @@ gdcmDocument::~gdcmDocument (void) { //----------------------------------------------------------------------------- // Print /** - * \brief Prints the Doc Entries (Dicom Elements) + * \brief Prints the Header Entries (Dicom Elements) * from the chained list * @return */ @@ -195,10 +196,10 @@ bool gdcmDocument::IsReadable(void) { * @return True when ImplicitVRLittleEndian found. False in all other cases. */ bool gdcmDocument::IsImplicitVRLittleEndianTransferSyntax(void) { - gdcmHeaderEntry *Element = GetHeaderEntryByNumber(0x0002, 0x0010); + gdcmDocEntry *Element = GetDocEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; - LoadHeaderEntrySafe(Element); + LoadDocEntrySafe(Element); std::string Transfer = Element->GetValue(); if ( Transfer == UI1_2_840_10008_1_2 ) @@ -212,10 +213,10 @@ bool gdcmDocument::IsImplicitVRLittleEndianTransferSyntax(void) { * @return True when ExplicitVRLittleEndian found. False in all other cases. */ bool gdcmDocument::IsExplicitVRLittleEndianTransferSyntax(void) { - gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010); + gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; - LoadHeaderEntrySafe(Element); + LoadDocEntrySafe(Element); std::string Transfer = Element->GetValue(); if ( Transfer == UI1_2_840_10008_1_2_1 ) @@ -229,10 +230,10 @@ bool gdcmDocument::IsExplicitVRLittleEndianTransferSyntax(void) { * @return True when DeflatedExplicitVRLittleEndian found. False in all other cases. */ bool gdcmDocument::IsDeflatedExplicitVRLittleEndianTransferSyntax(void) { - gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010); + gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; - LoadHeaderEntrySafe(Element); + LoadDocEntrySafe(Element); std::string Transfer = Element->GetValue(); if ( Transfer == UI1_2_840_10008_1_2_1_99 ) @@ -246,10 +247,10 @@ bool gdcmDocument::IsDeflatedExplicitVRLittleEndianTransferSyntax(void) { * @return True when big endian found. False in all other cases. */ bool gdcmDocument::IsExplicitVRBigEndianTransferSyntax(void) { - gdcmHeaderEntry* Element = GetHeaderEntryByNumber(0x0002, 0x0010); + gdcmDocEntry* Element = GetDocEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; - LoadHeaderEntrySafe(Element); + LoadDocEntrySafe(Element); std::string Transfer = Element->GetValue(); if ( Transfer == UI1_2_840_10008_1_2_2 ) //1.2.2 ??? A verifier ! @@ -319,7 +320,7 @@ bool gdcmDocument::CloseFile(void) { } /** - * \brief Writes in a file all the Doc Entries (Dicom Elements) + * \brief Writes in a file all the Header Entries (Dicom Elements) * of the Chained List * @param fp file pointer on an already open file * @param type Type of the File to be written @@ -400,20 +401,22 @@ bool gdcmDocument::Write(FILE *fp, FileType type) { * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ -gdcmHeaderEntry * gdcmDocument::ReplaceOrCreateByNumber( + + +gdcmDocEntry * gdcmDocument::ReplaceOrCreateByNumber( std::string Value, guint16 Group, guint16 Elem ){ - gdcmHeaderEntry* a; - a = GetHeaderEntryByNumber( Group, Elem); + gdcmDocEntry* a; + a = GetDocEntryByNumber( Group, Elem); if (a == NULL) { - a =NewHeaderEntryByNumber(Group, Elem); + a =NewDocEntryByNumber(Group, Elem); if (a == NULL) return NULL; - AddHeaderEntry(a); + AddDocEntry(a); } - //CLEANME SetEntryByNumber(Value, Group, Elem); - a->SetValue(Value); + SetEntryByNumber(Value, Group, Elem); + //a->SetValue(Value); return(a); } @@ -448,7 +451,7 @@ int gdcmDocument::CheckIfEntryExistByNumber(guint16 group, guint16 element ) { } /** - * \brief Searches within Doc Entries (Dicom Elements) parsed with + * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value of a given tag. * \warning Don't use any longer : use GetPubEntryByName @@ -465,7 +468,7 @@ std::string gdcmDocument::GetEntryByName(std::string tagName) { } /** - * \brief Searches within Doc Entries (Dicom Elements) parsed with + * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value representation of a given tag. * @@ -482,14 +485,14 @@ std::string gdcmDocument::GetEntryVRByName(std::string tagName) { if( dictEntry == NULL) return GDCM_UNFOUND; - gdcmHeaderEntry* elem = GetHeaderEntryByNumber(dictEntry->GetGroup(), + gdcmDocEntry* elem = GetDocEntryByNumber(dictEntry->GetGroup(), dictEntry->GetElement()); return elem->GetVR(); } /** - * \brief Searches within Doc Entries (Dicom Elements) parsed with + * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value representation of a given tag. * @param group Group of the searched tag. @@ -505,7 +508,7 @@ std::string gdcmDocument::GetEntryByNumber(guint16 group, guint16 element){ } /** - * \brief Searches within Doc Entries (Dicom Elements) parsed with + * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value representation of a given tag.. * @@ -519,14 +522,14 @@ std::string gdcmDocument::GetEntryByNumber(guint16 group, guint16 element){ * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. */ std::string gdcmDocument::GetEntryVRByNumber(guint16 group, guint16 element) { - gdcmHeaderEntry* elem = GetHeaderEntryByNumber(group, element); + gdcmDocEntry* elem = GetDocEntryByNumber(group, element); if ( !elem ) return GDCM_UNFOUND; return elem->GetVR(); } /** - * \brief Searches within Doc Entries (Dicom Elements) parsed with + * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the value length of a given tag.. * @param group Group of the searched tag. @@ -534,7 +537,7 @@ std::string gdcmDocument::GetEntryVRByNumber(guint16 group, guint16 element) { * @return Corresponding element length; -2 if not found */ int gdcmDocument::GetEntryLengthByNumber(guint16 group, guint16 element) { - gdcmHeaderEntry* elem = GetHeaderEntryByNumber(group, element); + gdcmDocEntry* elem = GetDocEntryByNumber(group, element); if ( !elem ) return -2; return elem->GetLength(); @@ -555,10 +558,9 @@ bool gdcmDocument::SetEntryByName(std::string content,std::string tagName) { } /** - * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) + * \brief Accesses an existing gdcmDocEntry (i.e. a Dicom Element) * through it's (group, element) and modifies it's content with * the given value. - * \warning Don't use any longer : use SetPubEntryByNumber * @param content new value to substitute with * @param group group of the Dicom Element to modify * @param element element of the Dicom Element to modify @@ -577,18 +579,20 @@ bool gdcmDocument::SetEntryByNumber(std::string content, content = content + '\0'; } - gdcmHeaderEntry * a; + gdcmDocEntry * a; IterHT p; - TagHeaderEntryHT::iterator p2; + TagDocEntryHT::iterator p2; // DO NOT remove the following lines : they explain the stuff //p= tagHT.equal_range(key); // get a pair of iterators first-last synonym //p2=p.first; // iterator on the first synonym //a=p2->second; // H Table target column (2-nd col) // or, easier : + + // Oops ! this was for multimap, right ? a = ((tagHT.equal_range(key)).first)->second; - a-> SetValue(content); + ((gdcmValEntry*)a)->SetValue(content); std::string vr = a->GetVR(); @@ -605,8 +609,8 @@ bool gdcmDocument::SetEntryByNumber(std::string content, } /** - * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element) - * in the PubHeaderEntrySet of this instance + * \brief Accesses an existing gdcmDocEntry (i.e. a Dicom Element) + * in the PubDocEntrySet of this instance * through it's (group, element) and modifies it's length with * the given value. * \warning Use with extreme caution. @@ -637,11 +641,11 @@ bool gdcmDocument::SetEntryLengthByNumber(guint32 l, */ size_t gdcmDocument::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) { - gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); + gdcmDocEntry* Entry = GetDocEntryByNumber(Group, Elem); if (!Entry) { - dbg.Verbose(1, "gdcmDocument::GetHeaderEntryByNumber", - "failed to Locate gdcmHeaderEntry"); + dbg.Verbose(1, "gdcmDocument::GetDocEntryByNumber", + "failed to Locate gdcmDocEntry"); return (size_t)0; } return Entry->GetOffset(); @@ -656,14 +660,14 @@ size_t gdcmDocument::GetEntryOffsetByNumber(guint16 Group, guint16 Elem) */ void * gdcmDocument::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem) { - gdcmHeaderEntry* Entry = GetHeaderEntryByNumber(Group, Elem); + gdcmDocEntry* Entry = GetDocEntryByNumber(Group, Elem); if (!Entry) { - dbg.Verbose(1, "gdcmDocument::GetHeaderEntryByNumber", - "failed to Locate gdcmHeaderEntry"); + dbg.Verbose(1, "gdcmDocument::GetDocEntryByNumber", + "failed to Locate gdcmDocEntry"); return (NULL); } - return Entry->GetVoidArea(); + return ((gdcmBinEntry *)Entry)->GetVoidArea(); } /** @@ -674,7 +678,7 @@ void * gdcmDocument::GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem) */ void *gdcmDocument::LoadEntryVoidArea(guint16 Group, guint16 Elem) { - gdcmHeaderEntry * Element= GetHeaderEntryByNumber(Group, Elem); + gdcmDocEntry * Element= GetDocEntryByNumber(Group, Elem); if ( !Element ) return NULL; size_t o =(size_t)Element->GetOffset(); @@ -710,7 +714,9 @@ bool gdcmDocument::SetEntryVoidAreaByNumber(void * area, TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) return false; - ( ((tagHT.equal_range(key)).first)->second )->SetVoidArea(area); + // This was for multimap ? + (( gdcmBinEntry *)( ((tagHT.equal_range(key)).first)->second ))->SetVoidArea(area); + return true; } @@ -741,13 +747,16 @@ void gdcmDocument::UpdateShaEntries(void) { else vr=(*it)->GetVR(); - (*it)->SetValue(GetHeaderEntryUnvalue(*it)); + //(*it)->SetValue(GetDocEntryUnvalue(*it)); + // to go on compiling if(entry){ // Set the new entry and the new value (*it)->SetDictEntry(entry); - CheckHeaderEntryVR(*it,vr); + CheckDocEntryVR(*it,vr); - (*it)->SetValue(GetHeaderEntryValue(*it)); + //(*it)->SetValue(GetDocEntryValue(*it)); + // to go on compiling + } else { @@ -758,18 +767,18 @@ void gdcmDocument::UpdateShaEntries(void) { } /** - * \brief Searches within the Doc Entries for a Dicom Element of + * \brief Searches within the Header Entries for a Dicom Element of * a given tag. * @param tagName name of the searched Dicom Element. * @return Corresponding Dicom Element when it exists, and NULL * otherwise. */ - gdcmHeaderEntry *gdcmDocument::GetHeaderEntryByName(std::string tagName) { + gdcmDocEntry *gdcmDocument::GetDocEntryByName(std::string tagName) { gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName); if( dictEntry == NULL) return NULL; - return(GetHeaderEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement())); + return(GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement())); } /** @@ -782,7 +791,7 @@ void gdcmDocument::UpdateShaEntries(void) { * @param element Element number of the searched Dicom Element * @return */ -gdcmHeaderEntry* gdcmDocument::GetHeaderEntryByNumber(guint16 group, guint16 element) +gdcmDocEntry* gdcmDocument::GetDocEntryByNumber(guint16 group, guint16 element) { TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) @@ -797,7 +806,7 @@ gdcmHeaderEntry* gdcmDocument::GetHeaderEntryByNumber(guint16 group, guint16 ele * @return a range (i.e.pair<,>) containing all elements whose key is group|element) */ -IterHT gdcmDocument::GetHeaderEntrySameNumber(guint16 group, guint16 element){ +IterHT gdcmDocument::GetDocEntrySameNumber(guint16 group, guint16 element){ TagKey key = gdcmDictEntry::TranslateToKey(group, element); return (tagHT.equal_range(key)); } @@ -805,13 +814,13 @@ IterHT gdcmDocument::GetHeaderEntrySameNumber(guint16 group, guint16 element){ /** * \brief Loads the element while preserving the current * underlying file position indicator as opposed to - * to LoadHeaderEntry that modifies it. + * to LoadDocEntry that modifies it. * @param entry Header Entry whose value shall be loaded. * @return */ -void gdcmDocument::LoadHeaderEntrySafe(gdcmHeaderEntry * entry) { +void gdcmDocument::LoadDocEntrySafe(gdcmDocEntry * entry) { long PositionOnEntry = ftell(fp); - LoadHeaderEntry(entry); + LoadDocEntry(entry); fseek(fp, PositionOnEntry, SEEK_SET); } @@ -823,11 +832,14 @@ void gdcmDocument::LoadHeaderEntrySafe(gdcmHeaderEntry * entry) { * @param SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files) * @param type Type of the File (ExplicitVR,ImplicitVR, ACR, ...) */ + + /* Probabely useless, now ! + void gdcmDocument::UpdateGroupLength(bool SkipSequence, FileType type) { guint16 gr, el; std::string vr; - gdcmHeaderEntry *elem; + gdcmDocEntry *elem; char trash[10]; std::string str_trash; @@ -837,11 +849,11 @@ void gdcmDocument::UpdateGroupLength(bool SkipSequence, FileType type) { // remember : // typedef std::map GroupHT; - gdcmHeaderEntry *elemZ; + gdcmDocEntry *elemZ; // for each Tag in the DCM Header - for (TagHeaderEntryHT::iterator tag2 = tagHT.begin(); + for (TagDocEntryHT::iterator tag2 = tagHT.begin(); tag2 != tagHT.end(); ++tag2) { @@ -907,29 +919,31 @@ void gdcmDocument::UpdateGroupLength(bool SkipSequence, FileType type) { if ( tagHT.count(tk) == 0) // if element 0x0000 not found { gdcmDictEntry * tagZ = new gdcmDictEntry(gr_bid, 0x0000, "UL"); - elemZ = new gdcmHeaderEntry(tagZ); + elemZ = new gdcmDocEntry(tagZ); elemZ->SetLength(4); - AddHeaderEntry(elemZ); // create it + AddDocEntry(elemZ); // create it } else { - elemZ=GetHeaderEntryByNumber(gr_bid, 0x0000); + elemZ=GetDocEntryByNumber(gr_bid, 0x0000); } sprintf(trash ,"%d",g->second); str_trash=trash; - elemZ->SetValue(str_trash); + //elemZ->SetValue(str_trash); // to go on compiling } } +*/ + /** * \brief Writes in a file (according to the requested format) * the group, the element, the value representation and the length - * of a single gdcmHeaderEntry passed as argument. - * @param tag pointer on the gdcmHeaderEntry to be written + * of a single gdcmDocEntry passed as argument. + * @param tag pointer on the gdcmDocEntry to be written * @param _fp already open file pointer * @param type type of the File to be written */ -void gdcmDocument::WriteEntryTagVRLength(gdcmHeaderEntry *tag, +void gdcmDocument::WriteEntryTagVRLength(gdcmDocEntry *tag, FILE *_fp, FileType type) { @@ -985,12 +999,15 @@ void gdcmDocument::WriteEntryTagVRLength(gdcmHeaderEntry *tag, /** * \brief Writes in a file (according to the requested format) - * the value of a single gdcmHeaderEntry passed as argument. - * @param tag Pointer on the gdcmHeaderEntry to be written + * the value of a single gdcmDocEntry passed as argument. + * @param tag Pointer on the gdcmDocEntry to be written * @param _fp Already open file pointer * @param type type of the File to be written */ -void gdcmDocument::WriteEntryValue(gdcmHeaderEntry *tag, FILE *_fp,FileType type) + + // TODO : to be re -written recursively ! + +void gdcmDocument::WriteEntryValue(gdcmDocEntry *tag, FILE *_fp,FileType type) { (void)type; guint16 group = tag->GetGroup(); @@ -1005,7 +1022,8 @@ void gdcmDocument::WriteEntryValue(gdcmHeaderEntry *tag, FILE *_fp,FileType type return; void *voidArea; - voidArea = tag->GetVoidArea(); + // voidArea = tag->GetVoidArea(); + // to go on compiling if (voidArea != NULL) { // there is a 'non string' LUT, overlay, etc fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value @@ -1051,14 +1069,14 @@ void gdcmDocument::WriteEntryValue(gdcmHeaderEntry *tag, FILE *_fp,FileType type /** * \brief Writes in a file (according to the requested format) - * a single gdcmHeaderEntry passed as argument. + * a single gdcmDocEntry passed as argument. * \sa WriteEntryValue, WriteEntryTagVRLength. - * @param tag Pointer on the gdcmHeaderEntry to be written + * @param tag Pointer on the gdcmDocEntry to be written * @param _fp Already open file pointer * @param type type of the File to be written */ -bool gdcmDocument::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) +bool gdcmDocument::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type) { guint32 length = tag->GetLength(); @@ -1066,7 +1084,8 @@ bool gdcmDocument::WriteEntry(gdcmHeaderEntry *tag, FILE *_fp,FileType type) // bytes. When this is not the case, pad with an additional byte: if(length%2==1) { - tag->SetValue(tag->GetValue()+"\0"); +// tag->SetValue(tag->GetValue()+"\0"); +// to go on compiling tag->SetLength(tag->GetReadLength()+1); } @@ -1136,7 +1155,7 @@ void gdcmDocument::WriteEntriesDeprecated(FILE *_fp,FileType type) { // restent a tester les echecs en ecriture (apres chaque fwrite) - for (TagHeaderEntryHT::iterator tag2=tagHT.begin(); + for (TagDocEntryHT::iterator tag2=tagHT.begin(); tag2 != tagHT.end(); ++tag2){ if ( type == ACR ){ @@ -1208,12 +1227,150 @@ guint16 gdcmDocument::UnswapShort(guint16 a) { //----------------------------------------------------------------------------- // Private + + +/** + * \brief Parses a DocEntrySet (Zero-level DocEntries or SQ Item DocEntries) + * @return false if file is not ACR-NEMA / PAPYRUS / DICOM + */ + +long gdcmDocument::ParseES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode) { + + gdcmDocEntry *NewDocEntry = (gdcmDocEntry *)0; + gdcmValEntry *vl; + gdcmSeqEntry *sq; + long l; + while (true) { + NewDocEntry = ReadNextDocEntry( ); + if (!NewDocEntry) + break; + if (NewDocEntry->GetVR() !="SQ") { + vl= new gdcmValEntry(NewDocEntry->GetDictEntry()); + vl->Copy(NewDocEntry); + delete NewDocEntry; + set->AddEntry(vl); + if (!delim_mode && vl->isItemDelimitor()) + break; + + } else { // VR = "SQ" + l=NewDocEntry->GetReadLength(); + if (l == 0xffffffff) + delim_mode = true; + else + delim_mode = false; + sq = new gdcmSeqEntry(NewDocEntry->GetDictEntry()); + sq->Copy(NewDocEntry); + long lgt = ParseSQ((gdcmDocEntrySet *)sq, offset, l, delim_mode); + set->AddEntry(sq); + if ( !delim_mode && ftell(fp)-offset >= l_max) + break; + } + } + return l; // ?? +} + + + + +long gdcmDocument::ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode) { + + gdcmDocEntry *NewDocEntry = (gdcmDocEntry *)0; + gdcmSQItem *itemSQ; + bool dlm_mod; + int lgr, l, lgth; + + while (true) { + if(delim_mode) { + NewDocEntry = ReadNextDocEntry(); + if (NewDocEntry->isSequenceDelimitor()) + // =====> ATTENTION : il faudra tout de meme ajouter + // le Sequence Delimiter ?!? + //set.Add(???); + break; + } + if (!delim_mode && (ftell(fp)-offset) >= l_max){ + break; + } + itemSQ = new gdcmSQItem(); + + l= NewDocEntry->GetLength(); + if (l ==0xffffffff) + dlm_mod = true; + else + dlm_mod=false; + + lgr=ParseES(itemSQ, offset, l, dlm_mod); + ((gdcmSeqEntry *)set)->AddEntry(itemSQ); + } + //Update(lgth); // TODO // to go on compiling + return(lgth); +} + + +/** + * \brief Parses the header of the file and load element values. + * @return false if file is not ACR-NEMA / PAPYRUS / DICOM + */ + +/* ======================================================================= +// Replaced by ParseSQ + +bool gdcmDocument::LoadHeaderEntries(bool exception_on_error) throw(gdcmFormatError) { + (void)exception_on_error; + rewind(fp); + if (!CheckSwap()) + return false; + + gdcmDocEntry *newDocEntry = (gdcmDocEntry *)0; + while ( (newDocEntry = ReadNextDocEntry()) ) { + SkipDocEntry(newDocEntry); + if ( (ignoreShadow==0) || (newDocEntry->GetGroup()%2) == 0) { + AddDocEntry(newDocEntry); + } + } + rewind(fp); + // Be carefull : merging this two loops may cause troubles ... + for (ListTag::iterator i = GetListEntry().begin(); + i != GetListEntry().end(); + ++i) + { + LoadDocEntry(*i); + } + rewind(fp); + + // Load 'non string' values + + + // -------------------------------------------------------------- + // Special Patch to allow gdcm to read ACR-LibIDO formated images + // + // if recognition code tells us we deal with a LibIDO image + // we switch lineNumber and columnNumber + // + std::string RecCode; + RecCode = GetEntryByNumber(0x0008, 0x0010); // recognition code + if (RecCode == "ACRNEMA_LIBIDO_1.1" || + RecCode == "CANRME_AILIBOD1_1." ) // for brain-damaged softwares + // with "little-endian strings" + { + filetype = ACR_LIBIDO; + std::string rows = GetEntryByNumber(0x0028, 0x0010); + std::string columns = GetEntryByNumber(0x0028, 0x0011); + SetEntryByNumber(columns, 0x0028, 0x0010); + SetEntryByNumber(rows , 0x0028, 0x0011); + } + // ----------------- End of Special Patch ---------------- + return true; +} +======================================================================= */ + + /** * \brief Loads the element content if its length doesn't exceed * the value specified with gdcmDocument::SetMaxSizeLoadEntry() * @param Entry Header Entry (Dicom Element) to be dealt with */ -void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { +void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) { size_t item_read; guint16 group = Entry->GetGroup(); std::string vr= Entry->GetVR(); @@ -1226,13 +1383,16 @@ void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { // (fffe e00d) tells us an Element just ended // (fffe e0dd) tells us the current SeQuence just ended if( group == 0xfffe ) { - Entry->SetValue("gdcm::Skipped"); + // NO more value field for SQ ! + //Entry->SetValue("gdcm::Skipped"); + // appel recursif de Load Value + // (meme pb que pour le parsing) return; } // When the length is zero things are easy: if ( length == 0 ) { - Entry->SetValue(""); + ((gdcmValEntry *)Entry)->SetValue(""); return; } @@ -1245,12 +1405,12 @@ void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { s << " Address:" << (long)Entry->GetOffset(); s << " Length:" << Entry->GetLength(); s << " x(" << std::hex << Entry->GetLength() << ")"; - Entry->SetValue(s.str()); + ((gdcmValEntry *)Entry)->SetValue(s.str()); return; } // Any compacter code suggested (?) - if ( IsHeaderEntryAnInteger(Entry) ) { + if ( IsDocEntryAnInteger(Entry) ) { guint32 NewInt; std::ostringstream s; int nbInt; @@ -1290,7 +1450,7 @@ void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { s << std::ends; // to avoid oddities on Solaris #endif //GDCM_NO_ANSI_STRING_STREAM - Entry->SetValue(s.str()); + ((gdcmValEntry *)Entry)->SetValue(s.str()); return; } @@ -1299,14 +1459,14 @@ void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp); if ( item_read != 1 ) { dbg.Verbose(1, "gdcmDocument::LoadElementValue","unread element value"); - Entry->SetValue("gdcm::UnRead"); + ((gdcmValEntry *)Entry)->SetValue("gdcm::UnRead"); return; } if( (vr == "UI") ) // Because of correspondance with the VR dic - Entry->SetValue(NewValue.c_str()); + ((gdcmValEntry *)Entry)->SetValue(NewValue.c_str()); else - Entry->SetValue(NewValue); + ((gdcmValEntry *)Entry)->SetValue(NewValue); } /** @@ -1316,19 +1476,18 @@ void gdcmDocument::LoadHeaderEntry(gdcmHeaderEntry *Entry) { * \todo something to allow further Elements addition, * (at their right place in the chained list) * when position to be taken care of - * @param newHeaderEntry + * @param newDocEntry */ -void gdcmDocument::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { - tagHT.insert( PairHT( newHeaderEntry->GetKey(),newHeaderEntry) ); - listEntries.push_back(newHeaderEntry); - wasUpdated = 1; +void gdcmDocument::AddDocEntry(gdcmDocEntry *newDocEntry) { + tagHT.insert( PairHT( newDocEntry->GetKey(),newDocEntry) ); + listEntries.push_back(newDocEntry); } /** * \brief Find the value Length of the passed Header Entry * @param Entry Header Entry whose length of the value shall be loaded. */ - void gdcmDocument::FindHeaderEntryLength (gdcmHeaderEntry *Entry) { + void gdcmDocument::FindDocEntryLength (gdcmDocEntry *Entry) { guint16 element = Entry->GetElement(); //guint16 group = Entry->GetGroup(); //FIXME std::string vr = Entry->GetVR(); @@ -1347,10 +1506,10 @@ void gdcmDocument::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { if ( (vr == "OB") && (length32 == 0xffffffff) ) { - Entry->SetLength(FindHeaderEntryLengthOB()); + Entry->SetLength(FindDocEntryLengthOB()); return; } - FixHeaderEntryFoundLength(Entry, length32); + FixDocEntryFoundLength(Entry, length32); return; } @@ -1419,7 +1578,7 @@ void gdcmDocument::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { // Actually, length= 0xffff means that we deal with // Unknown Sequence Length } - FixHeaderEntryFoundLength(Entry, (guint32)length16); + FixDocEntryFoundLength(Entry, (guint32)length16); return; } else @@ -1431,7 +1590,7 @@ void gdcmDocument::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { // not coexist in a Data Set and Data Sets nested within it".] // Length is on 4 bytes. - FixHeaderEntryFoundLength(Entry, ReadInt32()); + FixDocEntryFoundLength(Entry, ReadInt32()); return; } } @@ -1440,7 +1599,7 @@ void gdcmDocument::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { * \brief Find the Value Representation of the current Dicom Element. * @param Entry */ -void gdcmDocument::FindHeaderEntryVR( gdcmHeaderEntry *Entry) +void gdcmDocument::FindDocEntryVR( gdcmDocEntry *Entry) { if (filetype != ExplicitVR) return; @@ -1458,7 +1617,7 @@ void gdcmDocument::FindHeaderEntryVR( gdcmHeaderEntry *Entry) (void)fread (&VR, (size_t)2,(size_t)1, fp); VR[2]=0; - if(!CheckHeaderEntryVR(Entry,VR)) + if(!CheckDocEntryVR(Entry,VR)) { fseek(fp, PositionOnEntry, SEEK_SET); // When this element is known in the dictionary we shall use, e.g. for @@ -1481,7 +1640,7 @@ void gdcmDocument::FindHeaderEntryVR( gdcmHeaderEntry *Entry) * @return false if the VR is incorrect of if the VR isn't referenced * otherwise, it returns true */ -bool gdcmDocument::CheckHeaderEntryVR(gdcmHeaderEntry *Entry, VRKey vr) +bool gdcmDocument::CheckDocEntryVR(gdcmDocEntry *Entry, VRKey vr) { char msg[100]; // for sprintf bool RealExplicit = true; @@ -1550,9 +1709,9 @@ bool gdcmDocument::CheckHeaderEntryVR(gdcmHeaderEntry *Entry, VRKey vr) * @param Entry * @return Transformed entry value */ -std::string gdcmDocument::GetHeaderEntryValue(gdcmHeaderEntry *Entry) +std::string gdcmDocument::GetDocEntryValue(gdcmDocEntry *Entry) { - if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) + if ( (IsDocEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) { std::string val=Entry->GetValue(); std::string vr=Entry->GetVR(); @@ -1620,9 +1779,9 @@ std::string gdcmDocument::GetHeaderEntryValue(gdcmHeaderEntry *Entry) * @param Entry * @return Reverse transformed entry value */ -std::string gdcmDocument::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry) +std::string gdcmDocument::GetDocEntryUnvalue(gdcmDocEntry *Entry) { - if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) + if ( (IsDocEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) { std::string vr=Entry->GetVR(); std::ostringstream s; @@ -1670,7 +1829,7 @@ std::string gdcmDocument::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry) * \warning NOT end user intended method ! * @param entry */ -void gdcmDocument::SkipHeaderEntry(gdcmHeaderEntry *entry) +void gdcmDocument::SkipDocEntry(gdcmDocEntry *entry) { SkipBytes(entry->GetLength()); } @@ -1680,7 +1839,7 @@ void gdcmDocument::SkipHeaderEntry(gdcmHeaderEntry *entry) * the parser went Jabberwocky) one can hope improving things by * applying this heuristic. */ -void gdcmDocument::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 FoundLength) +void gdcmDocument::FixDocEntryFoundLength(gdcmDocEntry *Entry, guint32 FoundLength) { Entry->SetReadLength(FoundLength); // will be updated only if a bug is found if ( FoundLength == 0xffffffff) { @@ -1745,7 +1904,7 @@ void gdcmDocument::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Fou * @param Entry The element value on which to apply the predicate. * @return The result of the heuristical predicate. */ -bool gdcmDocument::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { +bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *Entry) { guint16 element = Entry->GetElement(); guint16 group = Entry->GetGroup(); std::string vr = Entry->GetVR(); @@ -1773,7 +1932,7 @@ bool gdcmDocument::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { // instead of giving up with an error message //std::cout << s.str().c_str() << std::endl; - // dbg.Error("gdcmDocument::IsHeaderEntryAnInteger", + // dbg.Error("gdcmDocument::IsDocEntryAnInteger", // s.str().c_str()); } } @@ -1788,7 +1947,7 @@ bool gdcmDocument::IsHeaderEntryAnInteger(gdcmHeaderEntry *Entry) { * @return */ - guint32 gdcmDocument::FindHeaderEntryLengthOB(void) { + guint32 gdcmDocument::FindDocEntryLengthOB(void) { // See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data. guint16 g; guint16 n; @@ -2201,31 +2360,31 @@ gdcmDictEntry *gdcmDocument::GetDictEntryByNumber(guint16 group,guint16 element) /** * \brief Read the next tag but WITHOUT loading it's value - * @return On succes the newly created HeaderEntry, NULL on failure. + * @return On succes the newly created DocEntry, NULL on failure. */ -gdcmHeaderEntry *gdcmDocument::ReadNextHeaderEntry(void) { +gdcmDocEntry *gdcmDocument::ReadNextDocEntry(void) { guint16 g,n; - gdcmHeaderEntry *NewEntry; + gdcmDocEntry *NewEntry; g = ReadInt16(); n = ReadInt16(); if (errno == 1) // We reached the EOF (or an error occured) therefore // header parsing has to be considered as finished. - return (gdcmHeaderEntry *)0; + return (gdcmDocEntry *)0; -// Pb : how to propagate the element length (used in SkipHeaderEntry) +// Pb : how to propagate the element length (used in SkipDocEntry) // direct call to SkipBytes ? // if (ignoreShadow == 1 && g%2 ==1) // if user wants to skip shadow groups // and current element *is* a shadow element // we don't create anything -// return (gdcmHeaderEntry *)1; // to tell caller it's NOT finished +// return (gdcmDocEntry *)1; // to tell caller it's NOT finished - NewEntry = NewHeaderEntryByNumber(g, n); - FindHeaderEntryVR(NewEntry); - FindHeaderEntryLength(NewEntry); + NewEntry = NewDocEntryByNumber(g, n); + FindDocEntryVR(NewEntry); + FindDocEntryLength(NewEntry); if (errno == 1) { // Call it quits @@ -2241,18 +2400,18 @@ gdcmHeaderEntry *gdcmDocument::ReadNextHeaderEntry(void) { * a default one when absent. * @param Name Name of the underlying DictEntry */ -gdcmHeaderEntry *gdcmDocument::NewHeaderEntryByName(std::string Name) +gdcmDocEntry *gdcmDocument::NewDocEntryByName(std::string Name) { gdcmDictEntry *NewTag = GetDictEntryByName(Name); if (!NewTag) NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "unkn", Name); - gdcmHeaderEntry* NewEntry = new gdcmHeaderEntry(NewTag); + gdcmDocEntry* NewEntry = new gdcmDocEntry(NewTag); if (!NewEntry) { - dbg.Verbose(1, "gdcmDocument::ObtainHeaderEntryByName", - "failed to allocate gdcmHeaderEntry"); - return (gdcmHeaderEntry *)0; + dbg.Verbose(1, "gdcmDocument::ObtainDocEntryByName", + "failed to allocate gdcmDocEntry"); + return (gdcmDocEntry *)0; } return NewEntry; } @@ -2280,18 +2439,18 @@ gdcmDictEntry *gdcmDocument::NewVirtualDictEntry(guint16 group, guint16 element, * @param Group group of the underlying DictEntry * @param Elem element of the underlying DictEntry */ -gdcmHeaderEntry *gdcmDocument::NewHeaderEntryByNumber(guint16 Group, guint16 Elem) +gdcmDocEntry *gdcmDocument::NewDocEntryByNumber(guint16 Group, guint16 Elem) { // Find out if the tag we encountered is in the dictionaries: gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem); if (!DictEntry) DictEntry = NewVirtualDictEntry(Group, Elem); - gdcmHeaderEntry *NewEntry = new gdcmHeaderEntry(DictEntry); + gdcmDocEntry *NewEntry = new gdcmDocEntry(DictEntry); if (!NewEntry) { - dbg.Verbose(1, "gdcmDocument::NewHeaderEntryByNumber", - "failed to allocate gdcmHeaderEntry"); + dbg.Verbose(1, "gdcmDocument::NewDocEntryByNumber", + "failed to allocate gdcmDocEntry"); return NULL; } return NewEntry; @@ -2300,17 +2459,17 @@ gdcmHeaderEntry *gdcmDocument::NewHeaderEntryByNumber(guint16 Group, guint16 Ele /// \todo Never used; commented out, waiting for removal. /** * \brief Small utility function that creates a new manually crafted - * (as opposed as read from the file) gdcmHeaderEntry with user + * (as opposed as read from the file) gdcmDocEntry with user * specified name and adds it to the public tag hash table. * \note A fake TagKey is generated so the PubDict can keep it's coherence. * @param NewTagName The name to be given to this new tag. * @param VR The Value Representation to be given to this new tag. * @return The newly hand crafted Element Value. */ -//gdcmHeaderEntry *gdcmDocument::NewManualHeaderEntryToPubDict(std::string NewTagName, +//gdcmDocEntry *gdcmDocument::NewManualDocEntryToPubDict(std::string NewTagName, // std::string VR) //{ -// gdcmHeaderEntry *NewEntry = NULL; +// gdcmDocEntry *NewEntry = NULL; // guint32 StuffGroup = 0xffff; // Group to be stuffed with additional info // guint32 FreeElem = 0; // gdcmDictEntry *DictEntry = NULL; @@ -2318,15 +2477,15 @@ gdcmHeaderEntry *gdcmDocument::NewHeaderEntryByNumber(guint16 Group, guint16 Ele // FreeElem = GenerateFreeTagKeyInGroup(StuffGroup); // if (FreeElem == UINT32_MAX) // { -// dbg.Verbose(1, "gdcmHeader::NewManualHeaderEntryToPubDict", +// dbg.Verbose(1, "gdcmHeader::NewManualDocEntryToPubDict", // "Group 0xffff in Public Dict is full"); // return NULL; // } // // DictEntry = NewVirtualDictEntry(StuffGroup, FreeElem, // VR, "GDCM", NewTagName); -// NewEntry = new gdcmHeaderEntry(DictEntry); -// AddHeaderEntry(NewEntry); +// NewEntry = new gdcmDocEntry(DictEntry); +// AddDocEntry(NewEntry); // return NewEntry; //} diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 7fc5c143..88abb074 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -10,6 +10,7 @@ #include "gdcmException.h" #include "gdcmDictSet.h" #include "gdcmDocEntry.h" +#include "gdcmDocEntrySet.h" #include #include @@ -21,7 +22,7 @@ typedef std::string VRKey; typedef std::string VRAtr; typedef std::map VRHT; // Value Representation Hash Table -typedef std::multimap TagDocEntryHT; +typedef std::map TagDocEntryHT; typedef std::pair PairHT; typedef std::pair IterHT; /// for linking together the Elements @@ -34,7 +35,7 @@ typedef std::map GroupHT; /** * \brief used by both gdcmHeader and gdcmDicomDir */ -class GDCM_EXPORT gdcmDocument : public gdcmElementSet +class GDCM_EXPORT gdcmDocument { private: /// Public dictionary used to parse this header @@ -43,9 +44,6 @@ private: /// \brief Optional "shadow dictionary" (private elements) used to parse /// this header gdcmDict *RefShaDict; - - /// Equals 1 if a gdcmDocEntry was added post parsing - int wasUpdated; /// \brief Equals =1 if user wants to skip shadow groups while parsing /// (to save space) @@ -64,7 +62,7 @@ private: protected: /// Refering underlying filename. - std::string filename; + std::string filename; /// \brief SWap code (e.g. Big Endian, Little Endian, Bad Big Endian, /// Bad Little Endian) according to the processor Endianity and @@ -86,6 +84,9 @@ protected: /// \brief Elements whose value is longer than MAX_SIZE_PRINT_ELEMENT_VALUE /// are NOT printed. + /// \todo Currently not used since collides with #define in + /// \ref gdcmDocEntry.cxx. See also + /// \ref gdcmDocument::SetMaxSizePrintEntry() static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE; /// Hash Table (multimap), to provide fast access @@ -144,7 +145,9 @@ public: gdcmDocEntry * ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem); bool ReplaceIfExistByNumber (char *Value, guint16 Group, guint16 Elem); - + + virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element); + // System access guint16 SwapShort(guint16); // needed by gdcmFile guint32 SwapLong(guint32); // needed by gdcmFile @@ -177,7 +180,6 @@ protected: virtual size_t GetEntryOffsetByNumber (guint16 Group, guint16 Elem); virtual void *GetEntryVoidAreaByNumber(guint16 Group, guint16 Elem); - virtual void *LoadEntryVoidArea (guint16 Group, guint16 Element); virtual bool SetEntryVoidAreaByNumber(void *a, guint16 Group, guint16 Elem); virtual void UpdateShaEntries(void); @@ -185,21 +187,28 @@ protected: // Header entry gdcmDocEntry *GetDocEntryByNumber (guint16 group, guint16 element); gdcmDocEntry *GetDocEntryByName (std::string Name); - IterHT GetDocEntrySameNumber(guint16 group, guint16 element); -// IterHT GetDocEntrySameName (std::string Name); + IterHT GetDocEntrySameNumber(guint16 group, guint16 element); +// IterHT GetDocEntrySameName (std::string Name); void LoadDocEntrySafe(gdcmDocEntry *); - void UpdateGroupLength(bool SkipSequence = false, - FileType type = ImplicitVR); + // Probabely useless + //void UpdateGroupLength(bool SkipSequence = false, + // FileType type = ImplicitVR); void AddDocEntry (gdcmDocEntry *); private: // Read - bool LoadDocEntries(bool exception_on_error = false) throw(gdcmFormatError); - + //bool LoadHeaderEntries(bool exception_on_error = false) throw(gdcmFormatError); + // remplacé par ParseES. + // What about exception_on_error ? + + long ParseES(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode); + long ParseSQ(gdcmDocEntrySet *set, long offset, long l_max, bool delim_mode); + + void LoadDocEntry (gdcmDocEntry *); void FindDocEntryLength(gdcmDocEntry *); void FindDocEntryVR (gdcmDocEntry *); @@ -238,12 +247,12 @@ private: gdcmDocEntry *ReadNextDocEntry (void); gdcmDocEntry *NewDocEntryByNumber(guint16 group, - guint16 element); + guint16 element); gdcmDocEntry *NewDocEntryByName (std::string Name); // Deprecated (Not used) --> commented out //gdcmDocEntry *NewManualDocEntryToPubDict(std::string NewTagName, - // std::string VR); + // std::string VR); guint32 GenerateFreeTagKeyInGroup(guint16 group); @@ -266,6 +275,10 @@ public: /// 'Swap code' accessor (see \ref sw ) inline int GetSwapCode(void) { return sw; } + + /// File pointer + inline FILE * GetFP(void) { return fp; } + }; //----------------------------------------------------------------------------- diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 33325c3f..067896c8 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -2,8 +2,7 @@ //----------------------------------------------------------------------------- // #include "gdcmElementSet.h" -#include "gdcmTS.h" - +#include "gdcmDebug.h" //----------------------------------------------------------------------------- // Constructor / Destructor @@ -11,8 +10,10 @@ * \ingroup gdcmElementSet * \brief Constructor from a given gdcmElementSet */ -gdcmDocEntrySet::gdcmDocEntrySet() { - +gdcmElementSet::gdcmElementSet() { + //TagDocEntryHT tagHT est un champ de gdcmElementSet. + // inutile de faire new ? + } /** @@ -21,132 +22,52 @@ gdcmDocEntrySet::gdcmDocEntrySet() { */ gdcmElementSet::~gdcmElementSet() { -/* for(tous les DocEntry) + gdcmDocEntry* EntryToDelete; + for(TagDocEntryHT::iterator cc = tagHT.begin();cc != tagHT.end();++cc) { - delete *cc; + EntryToDelete = cc->second; + if ( EntryToDelete ) + delete EntryToDelete; // TODO : a verifier } - */ + tagHT.clear(); } //----------------------------------------------------------------------------- // Public +bool gdcmElementSet::AddEntry( gdcmDocEntry *NewEntry) { + TagKey key; + key = NewEntry->GetKey(); + + if(tagHT.count(key) == 1) + { + dbg.Verbose(1, "gdcmElementSet::AddEntry key already present: ", key.c_str()); + return(false); + } + else + { + tagHT[NewEntry->GetKey()] = NewEntry; + return(true); + } +} + +// end-user intended : the guy *wants* to create his own SeQuence ?!? +gdcmDocEntry *gdcmElementSet::NewDocEntryByNumber(guint16 group, + guint16 element) { +// TODO + gdcmDocEntry *a; + return a; +} + +gdcmDocEntry *gdcmElementSet::NewDocEntryByName (std::string Name) { +// TODO : + gdcmDocEntry *a; + return a; +} //----------------------------------------------------------------------------- // Protected //----------------------------------------------------------------------------- // Private - -/** - * \brief Find the value Length of the passed Header Entry - * @param Entry Header Entry whose length of the value shall be loaded. - */ - void gdcmElementSet::FindDocEntryLength (gdcmDocEntry *Entry) { - guint16 element = Entry->GetElement(); - //guint16 group = Entry->GetGroup(); //FIXME - std::string vr = Entry->GetVR(); - guint16 length16; - - - if ( (filetype == ExplicitVR) && (! Entry->IsImplicitVR()) ) - { - if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) - { - // The following reserved two bytes (see PS 3.5-2001, section - // 7.1.2 Data element structure with explicit vr p27) must be - // skipped before proceeding on reading the length on 4 bytes. - fseek(fp, 2L, SEEK_CUR); - guint32 length32 = ReadInt32(); - - if ( (vr == "OB") && (length32 == 0xffffffff) ) - { - Entry->SetLength(FindHeaderEntryLengthOB()); - return; - } - FixHeaderEntryFoundLength(Entry, length32); - return; - } - - // Length is encoded on 2 bytes. - length16 = ReadInt16(); - - // We can tell the current file is encoded in big endian (like - // Data/US-RGB-8-epicard) when we find the "Transfer Syntax" tag - // and it's value is the one of the encoding of a big endian file. - // In order to deal with such big endian encoded files, we have - // (at least) two strategies: - // * when we load the "Transfer Syntax" tag with value of big endian - // encoding, we raise the proper flags. Then we wait for the end - // of the META group (0x0002) among which is "Transfer Syntax", - // before switching the swap code to big endian. We have to postpone - // the switching of the swap code since the META group is fully encoded - // in little endian, and big endian coding only starts at the next - // group. The corresponding code can be hard to analyse and adds - // many additional unnecessary tests for regular tags. - // * the second strategy consists in waiting for trouble, that shall - // appear when we find the first group with big endian encoding. This - // is easy to detect since the length of a "Group Length" tag (the - // ones with zero as element number) has to be of 4 (0x0004). When we - // encounter 1024 (0x0400) chances are the encoding changed and we - // found a group with big endian encoding. - // We shall use this second strategy. In order to make sure that we - // can interpret the presence of an apparently big endian encoded - // length of a "Group Length" without committing a big mistake, we - // add an additional check: we look in the already parsed elements - // for the presence of a "Transfer Syntax" whose value has to be "big - // endian encoding". When this is the case, chances are we have got our - // hands on a big endian encoded file: we switch the swap code to - // big endian and proceed... - if ( (element == 0x0000) && (length16 == 0x0400) ) - { - if ( ! IsExplicitVRBigEndianTransferSyntax() ) - { - dbg.Verbose(0, "gdcmDocument::FindLength", "not explicit VR"); - errno = 1; - return; - } - length16 = 4; - SwitchSwapToBigEndian(); - // Restore the unproperly loaded values i.e. the group, the element - // and the dictionary entry depending on them. - guint16 CorrectGroup = SwapShort(Entry->GetGroup()); - guint16 CorrectElem = SwapShort(Entry->GetElement()); - gdcmDictEntry * NewTag = GetDictEntryByNumber(CorrectGroup, - CorrectElem); - if (!NewTag) - { - // This correct tag is not in the dictionary. Create a new one. - NewTag = NewVirtualDictEntry(CorrectGroup, CorrectElem); - } - // FIXME this can create a memory leaks on the old entry that be - // left unreferenced. - Entry->SetDictEntry(NewTag); - } - - // Heuristic: well some files are really ill-formed. - if ( length16 == 0xffff) - { - length16 = 0; - //dbg.Verbose(0, "gdcmDocument::FindLength", - // "Erroneous element length fixed."); - // Actually, length= 0xffff means that we deal with - // Unknown Sequence Length - } - FixHeaderEntryFoundLength(Entry, (guint32)length16); - return; - } - else - { - // Either implicit VR or a non DICOM conformal (see note below) explicit - // VR that ommited the VR of (at least) this element. Farts happen. - // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25 - // on Data elements "Implicit and Explicit VR Data Elements shall - // not coexist in a Data Set and Data Sets nested within it".] - // Length is on 4 bytes. - - FixHeaderEntryFoundLength(Entry, ReadInt32()); - return; - } -} diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index cd3bbd7d..f4003e57 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,6 +3,14 @@ #ifndef GDCMELEMENTSET_H #define GDCMELEMENTSET_H +#include "gdcmDocEntrySet.h" +#include "gdcmDocEntry.h" + +#include +typedef std::string TagKey; +typedef std::map TagDocEntryHT; + + //----------------------------------------------------------------------------- class GDCM_EXPORT gdcmElementSet : public gdcmDocEntrySet @@ -10,13 +18,25 @@ class GDCM_EXPORT gdcmElementSet : public gdcmDocEntrySet public: gdcmElementSet(void); ~gdcmElementSet(void); - + virtual bool AddEntry(gdcmDocEntry *Entry); // add to the H Table + + protected: private: -}; + // DocEntry related utilities + virtual gdcmDocEntry *NewDocEntryByNumber(guint16 group, + guint16 element); + virtual gdcmDocEntry *NewDocEntryByName (std::string Name); + + +// Variables + /// Hash Table (map), to provide fast access + TagDocEntryHT tagHT; + +}; //----------------------------------------------------------------------------- #endif diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 16d30ef9..f0ed2598 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -12,9 +12,8 @@ * \ingroup gdcmSQItem * \brief Constructor from a given gdcmSQItem */ -gdcmSQItem::gdcmSQItem() : gdcmDocEntry( ) { - - +gdcmSQItem::gdcmSQItem( ) + : gdcmDocEntrySet() { } /** @@ -37,15 +36,43 @@ gdcmSQItem::~gdcmSQItem() * \ingroup gdcmSQItem * \brief canonical Printer */ - + void gdcmSQItem::Print(std::ostream & os) { + + for (ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); + ++i) + { + //(*i)->SetPrintLevel(printLevel); //self->GetPrintLevel() ? + (*i)->Print(os); + } +} //----------------------------------------------------------------------------- // Public +bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) { + docEntries.push_back(entry); + //TODO : check if it worked + return true; +} + //----------------------------------------------------------------------------- // Protected //----------------------------------------------------------------------------- // Private +// end-user intended : the guy *wants* to create his own SeQuence ?!? +gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group, + guint16 element) { +// TODO + gdcmDocEntry *a; + return a; +} + +gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) { +// TODO : + gdcmDocEntry *a; + return a; +} //----------------------------------------------------------------------------- diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index 675492d5..af91b145 100644 --- a/src/gdcmSQItem.h +++ b/src/gdcmSQItem.h @@ -26,11 +26,19 @@ public: /// \brief adds the passed DocEntry to the DocEntry chained List for this SQ Item. inline void AddDocEntry(gdcmDocEntry *e) {docEntries.push_back(e);}; - + + virtual bool AddEntry(gdcmDocEntry *Entry); // add to the List + protected: private: + // DocEntry related utilities + + + virtual gdcmDocEntry *NewDocEntryByNumber(guint16 group, + guint16 element); + virtual gdcmDocEntry *NewDocEntryByName (std::string Name); // Variables diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 06246c1a..c2864f04 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -2,30 +2,32 @@ //----------------------------------------------------------------------------- // #include "gdcmSeqEntry.h" +#include "gdcmSQItem.h" #include "gdcmTS.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" - +#include +#include //----------------------------------------------------------------------------- // Constructor / Destructor /** * \ingroup gdcmSeqEntry * \brief Constructor from a given gdcmSeqEntry - * @param in Pointer to existing dictionary entry */ -gdcmSeqEntry::gdcmSeqEntry() : gdcmDocEntry( ) { - - +gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e) + : gdcmDocEntry(e) +{ + //ListSQItem items est un *champ* de gdcmSeqEntry. + // inutile de faire new ? + } - /** * \ingroup gdcmSeqEntry * \brief Canonical destructor. */ -gdcmSeqEntry::~gdcmSeqEntry() -{ +gdcmSeqEntry::~gdcmSeqEntry() { for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc) { delete *cc; @@ -38,15 +40,91 @@ gdcmSeqEntry::~gdcmSeqEntry() * \ingroup gdcmSeqEntry * \brief canonical Printer */ +void gdcmSeqEntry::Print(std::ostream &os){ + + std::ostringstream s; + string vr; + unsigned short int g, e; + long lgth; + size_t o; + char greltag[10]; //group element tag + char st[20]; + + // First, Print the Dicom Element itself. + g = GetGroup(); + e = GetElement(); + o = GetOffset(); + vr = GetVR(); + sprintf(greltag,"%04x|%04x ",g,e); + s << greltag ; + if (GetPrintLevel()>=2) { + s << "lg : "; + lgth = GetReadLength(); // ReadLength, as opposed to UsableLength + if (lgth == 0xffffffff) { + sprintf(st,"x(ffff)"); // I said : "x(ffff)" ! + s.setf(std::ios::left); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s.setf(std::ios::left); + s << std::setw(8) << "-1"; + } else { + sprintf(st,"x(%x)",lgth); + s.setf(std::ios::left); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s.setf(std::ios::left); + s << std::setw(8) << lgth; + } + s << " Off.: "; + sprintf(st,"x(%x)",o); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s << std::setw(8) << o; + } + + s << "[" << vr << "] "; + if (GetPrintLevel()>=1) { + s.setf(std::ios::left); + s << std::setw(66-GetName().length()) << " "; + } + + s << "[" << GetName()<< "]"; + s << std::endl; + os << s.str(); + // Then, Print each SQ Item + for(ListSQItem::iterator cc = items.begin();cc != items.end();++cc) + { + //(*cc)->SetPrintLevel(GetPrintLevel()); aurait-ce un sens ? + (*cc)->Print(os); + } + + } //----------------------------------------------------------------------------- // Public + /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence. +void gdcmSeqEntry::AddEntry(gdcmSQItem *sqItem) { + items.push_back(sqItem); +} //----------------------------------------------------------------------------- // Protected //----------------------------------------------------------------------------- // Private +// end-user intended : the guy *wants* to create his own SeQuence ?!? +gdcmDocEntry *gdcmSeqEntry::NewDocEntryByNumber(guint16 group, + guint16 element) { +// TODO + gdcmDocEntry *a; + return a; +} + +gdcmDocEntry *gdcmSeqEntry::NewDocEntryByName (std::string Name) { +// TODO : + gdcmDocEntry *a; + return a; +} //----------------------------------------------------------------------------- diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 2c02597a..1d52a936 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -15,7 +15,7 @@ typedef std::list ListSQItem; class GDCM_EXPORT gdcmSeqEntry : public gdcmDocEntry { public: - gdcmSeqEntry(void); + gdcmSeqEntry(gdcmDictEntry* e); ~gdcmSeqEntry(void); virtual void Print(std::ostream &os = std::cout); @@ -24,13 +24,14 @@ public: inline ListSQItem &GetSQItems() {return items;}; - /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence. - inline void AddSQItem(gdcmSQItem *it) - {items.push_back(it);}; + void AddEntry(gdcmSQItem *it); /// \brief creates a new SQITEM for this SeQuence. gdcmSQItem * NewItem(void); - + + gdcmDocEntry *NewDocEntryByNumber(guint16 group, guint16 element); + gdcmDocEntry *NewDocEntryByName (std::string Name); + protected: private: diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index e1dad038..f568133f 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -14,12 +14,17 @@ * \brief Constructor from a given gdcmDictEntry * @param in Pointer to existing dictionary entry */ -gdcmValEntry::gdcmValEntry() : gdcmDocEntry( ) { +gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) { } +/** + * \brief Canonical destructor. + */ +gdcmValEntry::~gdcmValEntry (void) { +} //----------------------------------------------------------------------------- diff --git a/src/gdcmValEntry.h b/src/gdcmValEntry.h index c87f9e85..1ff269f4 100644 --- a/src/gdcmValEntry.h +++ b/src/gdcmValEntry.h @@ -18,7 +18,7 @@ class GDCM_EXPORT gdcmValEntry : public gdcmDocEntry { public: - gdcmValEntry(void); + gdcmValEntry(gdcmDictEntry* e); ~gdcmValEntry(void); /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted into a @@ -35,16 +35,11 @@ private: // Variables - /// \brief Header Entry value, stores as a std::string (VR will be used, + /// \brief Header Entry value, stored as a std::string (VR will be used, /// later, to decode) std::string value; - - - - - }; //-----------------------------------------------------------------------------