From: jpr Date: Tue, 14 Sep 2004 16:47:08 +0000 (+0000) Subject: Now, TestCopyDicom deals with private Entries X-Git-Tag: Version0.6.bp~204 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=62fd402e1fc63c4928ab86195dd66208b072dadb;p=gdcm.git Now, TestCopyDicom deals with private Entries --- diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index bd914c68..f5ded1b2 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -85,23 +85,22 @@ int TestCopyDicom(int , char* []) for (TagDocEntryHT::iterator tag = Ht.begin(); tag != Ht.end(); ++tag) { d = tag->second; + + if ( gdcmBinEntry* b = dynamic_cast(d) ) + { // for private elements, the gdcmDictEntry is unknown // and it's VR is unpredictable ... // ( In *this* case ReplaceOrCreateByNumber // should have a knowledge of the virtual dictionary - // gdcmDictSet::VirtualEntry) - - if ( d->GetGroup()%2 == 1) // Skip private Entries - continue; - - if ( gdcmBinEntry* b = dynamic_cast(d) ) - { - - // std::cout << "BinEntry : " - // << "------------- " << b->GetVR() << " "<< std::hex - // << b->GetGroup() << " " << b->GetElement() << " " - // << " lg=" << b->GetLength() - // << std::endl; + // gdcmDictSet::VirtualEntry ) + // ReplaceOrCreateByNumber may now receive the VR of the source Entry + // as a extra parameter + // + //if ( d->GetGroup()%2 == 1) // Skip private Entries + // continue; + + // TODO :write ReplaceOrCreateByNumber with VR, + // for BinEntries as well! copy->GetHeader()->ReplaceOrCreateByNumber( b->GetVoidArea(), @@ -109,12 +108,23 @@ int TestCopyDicom(int , char* []) b->GetGroup(), b->GetElement() ); } - else if ( gdcmValEntry* v = dynamic_cast(d) ) + else if ( gdcmValEntry* v = dynamic_cast(d) ) { - copy->GetHeader()->ReplaceOrCreateByNumber( + if ( d->GetGroup()%2 != 1) + { + copy->GetHeader()->ReplaceOrCreateByNumber( v->GetValue(), v->GetGroup(), v->GetElement() ); + } + else + { + copy->GetHeader()->ReplaceOrCreateByNumber( + v->GetValue(), + v->GetGroup(), + v->GetElement(), + v->GetVR() ); + } } else { diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index b187140b..ce1c25bf 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2004/09/10 14:32:04 $ - Version: $Revision: 1.20 $ + Date: $Date: 2004/09/14 16:47:08 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -217,6 +217,35 @@ gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group, return newEntry; } + +/** \brief + * Creates a new DocEntry (without any 'value' ...) + * @param group group number of the underlying DictEntry + * @param elem elem number of the underlying DictEntry + * @param VR V(alue) R(epresentation) of the Entry -if private Entry- + + */ +gdcmDocEntry* gdcmDocEntrySet::NewDocEntryByNumber(uint16_t group, + uint16_t elem, + std::string const &VR) +{ + // Find out if the tag we encountered is in the dictionaries: + gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); + gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem); + if (!dictEntry) + { + dictEntry = NewVirtualDictEntry(group, elem, VR); + } + + gdcmDocEntry *newEntry = new gdcmDocEntry(dictEntry); + if (!newEntry) + { + dbg.Verbose(1, "gdcmSQItem::NewDocEntryByNumber", + "failed to allocate gdcmDocEntry"); + return 0; + } + return newEntry; +} /* \brief * Probabely move, as is, to gdcmDocEntrySet, as a non virtual method * an remove gdcmDocument::NewDocEntryByName diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 982e0286..c7775682 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2004/09/13 12:10:53 $ - Version: $Revision: 1.16 $ + Date: $Date: 2004/09/14 16:47:08 $ + 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 @@ -72,6 +72,9 @@ protected: uint16_t element); gdcmDocEntry* NewDocEntryByNumber(uint16_t group, uint16_t element); + gdcmDocEntry* NewDocEntryByNumber(uint16_t group, + uint16_t element, + std::string const & VR); gdcmDocEntry* NewDocEntryByName (std::string const & name); gdcmSeqEntry* NewSeqEntryByNumber(uint16_t group, uint16_t element); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 9976959e..54787ed8 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 12:10:53 $ - Version: $Revision: 1.76 $ + Date: $Date: 2004/09/14 16:47:08 $ + Version: $Revision: 1.77 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -653,6 +653,91 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( return valEntry; } +/** + * \brief Modifies the value of a given Header Entry (Dicom Element) + * when it exists. Create it with the given value when unexistant. + * @param value (string) Value to be set + * @param group Group number of the Entry + * @param elem Element number of the Entry + * @param VR V(alue) R(epresentation) of the Entry -if private Entry- + * \return pointer to the modified/created Header Entry (NULL when creation + * failed). + */ + + // TODO : write something clever, using default value for VR + // to avoid code duplication + // (I don't know how to tell NewDocEntryByNumber + // that ReplaceOrCreateByNumber was called with a default value) + +gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( + std::string const & value, + uint16_t group, + uint16_t elem, + std::string const & VR ) +{ + gdcmValEntry* valEntry = 0; + gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem); + + if (!currentEntry) + { + // check if (group,element) DictEntry exists + // if it doesn't, create an entry in gdcmDictSet::VirtualEntry + // and use it + + // Find out if the tag we received is in the dictionaries: + gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); + gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, elem); + if (!dictEntry) + { + currentEntry = NewDocEntryByNumber(group, elem,VR); + } + else + { + currentEntry = NewDocEntryByNumber(group, elem); + } + + if (!currentEntry) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to" + " NewDocEntryByNumber failed."); + return NULL; + } + valEntry = new gdcmValEntry(currentEntry); + if ( !AddEntry(valEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry" + " failed allthough this is a creation."); + } + } + else + { + valEntry = dynamic_cast< gdcmValEntry* >(currentEntry); + if ( !valEntry ) // Euuuuh? It wasn't a ValEntry + // then we change it to a ValEntry ? + // Shouldn't it be considered as an error ? + { + // We need to promote the gdcmDocEntry to a gdcmValEntry: + valEntry = new gdcmValEntry(currentEntry); + if (!RemoveEntry(currentEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal" + " of previous DocEntry failed."); + return NULL; + } + if ( !AddEntry(valEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding" + " promoted ValEntry failed."); + return NULL; + } + } + } + + SetEntryByNumber(value, group, elem); + + return valEntry; +} + /* * \brief Modifies the value of a given Header Entry (Dicom Element) * when it exists. Create it with the given value when unexistant. @@ -684,7 +769,6 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( } SetEntryByNumber(voidArea, lgth, group, elem); - //b->SetVoidArea(voidArea); //what if b == 0 !! return b; } diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 0ddfb468..7c2ef447 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2004/09/03 15:11:35 $ - Version: $Revision: 1.35 $ + Date: $Date: 2004/09/14 16:47:08 $ + Version: $Revision: 1.36 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -135,9 +135,15 @@ public: gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value, uint16_t group, uint16_t elem); + gdcmValEntry* ReplaceOrCreateByNumber(std::string const & value, + uint16_t group, uint16_t elem, + std::string const & VR); + gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth, uint16_t group, uint16_t elem); + gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem); + bool ReplaceIfExistByNumber ( std::string const & value, uint16_t group, uint16_t elem ); diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 6eb2f39b..5ecbbc98 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2004/09/10 18:54:39 $ - Version: $Revision: 1.185 $ + Date: $Date: 2004/09/14 16:47:08 $ + Version: $Revision: 1.186 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -1259,13 +1259,14 @@ void gdcmHeader::SetImageDataSize(size_t ImageDataSize) */ bool gdcmHeader::AnonymizeHeader() { - gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010); + // If exist, replace by spaces + SetEntryByNumber (" ",0x0010, 0x2154); // Telephone + SetEntryByNumber (" ",0x0010, 0x1040); // Adress + SetEntryByNumber (" ",0x0010, 0x0020); // Patient ID - ReplaceIfExistByNumber (" ",0x0010, 0x2154); // Telephone - ReplaceIfExistByNumber (" ",0x0010, 0x1040); // Adress - ReplaceIfExistByNumber (" ",0x0010, 0x0020); // Patient ID + gdcmDocEntry* patientNameHE = GetDocEntryByNumber (0x0010, 0x0010); - if ( patientNameHE ) + if ( patientNameHE ) // we replace it by Study Instance UID (why not) { std::string studyInstanceUID = GetEntryByNumber (0x0020, 0x000d); if ( studyInstanceUID != GDCM_UNFOUND )