From cdc2a0e2a1e53f0efef4412a248566e076b1f4c9 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 12 Mar 2004 14:10:46 +0000 Subject: [PATCH] Now, gdcmObject::SetEntryByNumber *adds* a new gdcmHeaderEntry to the cuurent object if the given (group,elem) is not found --- src/gdcmFile.h | 2 +- src/gdcmHeaderEntry.h | 15 +++++------ src/gdcmObject.cxx | 58 +++++++++++++++++++++++++++++++++---------- src/gdcmParser.cxx | 36 +++++++++++++++++---------- src/gdcmParser.h | 13 +++++----- 5 files changed, 83 insertions(+), 41 deletions(-) diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 29287b24..d5c602c8 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -106,7 +106,7 @@ private: /// ==0 if GetImageData was used /// ==-1 if ImageData never read int PixelRead; - . + /// weather already parsed int Parsed; diff --git a/src/gdcmHeaderEntry.h b/src/gdcmHeaderEntry.h index dd228c60..cff9a758 100644 --- a/src/gdcmHeaderEntry.h +++ b/src/gdcmHeaderEntry.h @@ -195,6 +195,7 @@ public: private: // FIXME: In fact we should be more specific and use : // friend gdcmHeaderEntry * gdcmHeader::ReadNextElement(void); + friend class gdcmHeader; // Variables @@ -213,18 +214,18 @@ private: /// *for internal* use only guint32 ReadLength; - /// Even when reading explicit vr files, some - /// elements happen to be implicit. Flag them here - /// since we can't use the entry->vr without breaking - /// the underlying dictionary. + /// Even when reading explicit vr files, some + /// elements happen to be implicit. Flag them here + /// since we can't use the entry->vr without breaking + /// the underlying dictionary. bool ImplicitVR; std::string value; - /// unsecure memory area to hold 'non string' values - /// (ie : Lookup Tables, overlays) + /// unsecure memory area to hold 'non string' values + /// (ie : Lookup Tables, overlays) void *voidArea; - /// Offset from the begining of file for direct user access + /// Offset from the begining of file for direct user access size_t Offset; int printLevel; diff --git a/src/gdcmObject.cxx b/src/gdcmObject.cxx index 66c40a80..3f4b5101 100644 --- a/src/gdcmObject.cxx +++ b/src/gdcmObject.cxx @@ -89,25 +89,57 @@ std::string gdcmObject::GetEntryByName(TagName name) { * \ingroup gdcmParser * \brief Sets Entry (Dicom Element) value of an element, * specified by it's tag (Group, Number) - * and the length, too ... + * and the length, too ... + * If the Element is not found, it's just created ! + * \warning we suppose, right now, the element belongs to a Public Group + * (NOT a shadow one) * @param val string value to set * @param group Group of the searched tag. * @param element Element of the searched tag. - * @return true if element was found, else false + * @return true if element was found or created successfully */ bool gdcmObject::SetEntryByNumber(std::string val,guint16 group, - guint16 element) { - - //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR - for(ListTag::iterator i=beginObj;;++i) { - if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) { + guint16 element) { + + gdcmHeaderEntry *a; + for(ListTag::iterator i=beginObj;;++i) { + if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 ) + continue; + if ( group < (*i)->GetGroup() || + (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){ + // instead of ReplaceOrCreateByNumber + // that is a method of gdcmParser :-( + gdcmHeaderEntry *Entry; + TagKey key = gdcmDictEntry::TranslateToKey(group, element); + if ( ! ptagHT->count(key)) { + // we assume the element is a belongs to a Public Group (not a shadow one) + // we assume a Public Dictionnary *is* loaded + gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); + // we assume the invoqued (group,elem) exists + // inside the Public Dictionary + gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element); + // we assume the constuctor didn't fail + Entry = new gdcmHeaderEntry(DictEntry); + // ---- + // TODO + // ---- + // better we don't assume too much ! + // in the next release, gdcmObject will be used + // to describe any Header Entry ... + } else { + Entry = ptagHT->find(key)->second; + } + Entry->SetValue(val); + Entry->SetLength(val.length()); + plistEntries->insert(i,Entry); + return true; + } + if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) { (*i)->SetValue(val); - (*i)->SetLength(val.length()+1); - return true; - } - if (i == endObj) break; - } - return false; + (*i)->SetLength(val.length()); + return true; + } + } } /** * \ingroup gdcmObject diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 60dd01ba..cea36d4e 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -453,22 +453,28 @@ bool gdcmParser::Write(FILE *fp, FileType type) { * \ingroup gdcmParser * \brief Modifies the value of a given Header Entry (Dicom Element) * if it exists; Creates it with the given value if it doesn't + * \warning : adds the Header Entry to the HTable, NOT to the chained List * @param Value passed as a std::string - * @param Group - * @param Elem - * \return false only if new element creation fails + * @param Group group of the Entry + * @param Elem element of the Entry + * \return pointer to the created Header Entry + * NULL if creation failed */ -bool gdcmParser::ReplaceOrCreateByNumber(std::string Value, +gdcmHeaderEntry * gdcmParser::ReplaceOrCreateByNumber( + std::string Value, guint16 Group, - guint16 Elem ){ - if (CheckIfEntryExistByNumber(Group, Elem) == 0) { + guint16 Elem ){ + gdcmHeaderEntry* a; + a = GetHeaderEntryByNumber( Group, Elem); + if (a == NULL) { gdcmHeaderEntry *a =NewHeaderEntryByNumber(Group, Elem); if (a == NULL) - return false; + return NULL; AddHeaderEntry(a); } - SetEntryByNumber(Value, Group, Elem); - return(true); + //SetEntryByNumber(Value, Group, Elem); + a->SetValue(Value); + return(a); } /** @@ -478,20 +484,24 @@ bool gdcmParser::ReplaceOrCreateByNumber(std::string Value, * @param Value passed as a char* * @param Group group of the Entry * @param Elem element of the Entry - * \return boolean + * \return pointer to the created Header Entry + * NULL if creation failed * */ -bool gdcmParser::ReplaceOrCreateByNumber(char* Value, guint16 Group, guint16 Elem ) { +gdcmHeaderEntry * gdcmParser::ReplaceOrCreateByNumber( + char* Value, + guint16 Group, + guint16 Elem ) { gdcmHeaderEntry* nvHeaderEntry=NewHeaderEntryByNumber(Group, Elem); if(!nvHeaderEntry) - return(false); + return(NULL); AddHeaderEntry(nvHeaderEntry); std::string v = Value; SetEntryByNumber(v, Group, Elem); - return(true); + return(nvHeaderEntry); } /** diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 8767a1d4..10943f5f 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -105,8 +105,8 @@ public: // Write (used in gdcmFile, gdcmDicomDir) virtual bool Write(FILE *, FileType); - bool ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem); - bool ReplaceOrCreateByNumber( char *Value, guint16 Group, guint16 Elem); + gdcmHeaderEntry * ReplaceOrCreateByNumber(std::string Value, guint16 Group, guint16 Elem); + gdcmHeaderEntry * ReplaceOrCreateByNumber( char *Value, guint16 Group, guint16 Elem); bool ReplaceIfExistByNumber ( char *Value, guint16 Group, guint16 Elem); // System access @@ -257,8 +257,7 @@ private: gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, guint16 element); gdcmHeaderEntry *NewHeaderEntryByName (std::string Name); - - + // Deprecated (Not used) --> commented out //gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName, // std::string VR); @@ -296,15 +295,15 @@ private: */ int sw; /** - * \brief Size treshold above which an element value will NOT be loaded in + * \brief Size threshold above which an element value will NOT be loaded in * memory (to avoid loading the image/volume itself). By default, * this upper bound is fixed to 1024 bytes (which might look reasonable - * when one considers the definition of the various VR contents). + * when one considers the definition of the various VR contents). */ guint32 MaxSizeLoadEntry; /** - * \brief Size treshold above which an element value will NOT be *printed* in + * \brief Size threshold above which an element value will NOT be *printed* in * order no to polute the screen output. * By default, this upper bound is fixed to 64 bytes. */ -- 2.48.1