From f7f4b2e2843f917ac08f9fdc58fc23ca44d8a14d Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 16 Sep 2004 06:47:59 +0000 Subject: [PATCH] gdcmDocument::ReplaceOrCreateByNumber has now an extra parameter, std::string VR (default value : "unkn"), that makes TestCopyDicom code much lighter . --- Testing/TestCopyDicom.cxx | 49 +++++------------------- src/gdcmDocument.cxx | 78 +++++++++++++++++++++++++++++++-------- src/gdcmDocument.h | 12 +++--- 3 files changed, 77 insertions(+), 62 deletions(-) diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index e0478850..5b35c48b 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -41,7 +41,7 @@ bool RemoveFile(const char* source) // Here we load a gdcmFile and then try to create from scratch a copy of it, // copying field by field the dicom image -int TestCopyDicom(int , char* []) +int TestCopyDicom(int argc, char* argv[]) { int i =0; int retVal = 0; //by default this is an error @@ -75,66 +75,37 @@ int TestCopyDicom(int , char* []) // It was commented out by Mathieu, that was a *good* idea // (the user does NOT have to know the way we implemented the Header !) // Waiting for a 'clean' solution, I keep the method ...JPRx - - TagNameHT & nameHt = original->GetHeader()->GetPubDict()->GetEntriesByName(); - (void)nameHt; //not used ? - //gdcmValEntry* v; - //gdcmBinEntry* b; gdcmDocEntry* d; 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 ) - // 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(), b->GetLength(), b->GetGroup(), - b->GetElement() ); + b->GetElement(), + b->GetVR() ); } else if ( gdcmValEntry* v = dynamic_cast(d) ) - { - if ( d->GetGroup()%2 != 1) - { - copy->GetHeader()->ReplaceOrCreateByNumber( - v->GetValue(), - v->GetGroup(), - v->GetElement() ); - } - else - { - copy->GetHeader()->ReplaceOrCreateByNumber( + { + copy->GetHeader()->ReplaceOrCreateByNumber( v->GetValue(), v->GetGroup(), v->GetElement(), v->GetVR() ); - } - } - else - { + } + else + { // We skip pb of SQ recursive exploration //std::cout << "Skipped Sequence " // << "------------- " << d->GetVR() << " "<< std::hex // << d->GetGroup() << " " << d->GetElement() // << std::endl; - } + } } size_t dataSize = original->GetImageDataSize(); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 4f066856..37be3f68 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/15 03:50:48 $ - Version: $Revision: 1.78 $ + Date: $Date: 2004/09/16 06:48:00 $ + Version: $Revision: 1.79 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -598,7 +598,8 @@ void gdcmDocument::Write(FILE* fp,FileType filetype) * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ - + +/* gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( std::string const & value, uint16_t group, @@ -652,6 +653,7 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( return valEntry; } +*/ /** * \brief Modifies the value of a given Header Entry (Dicom Element) @@ -751,26 +753,70 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( void *voidArea, int lgth, uint16_t group, - uint16_t elem) + uint16_t elem, + std::string const & VR ) { - gdcmBinEntry* b = 0; - gdcmDocEntry* a = GetDocEntryByNumber( group, elem); - if (!a) + gdcmBinEntry* binEntry = 0; + gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem); + if (!currentEntry) { - a = NewBinEntryByNumber(group, elem); - if (!a) + + // 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) { - return 0; + currentEntry = NewDocEntryByNumber(group, elem,VR); } - - b = new gdcmBinEntry(a); - AddEntry(b); - b->SetVoidArea(voidArea); - } + else + { + currentEntry = NewDocEntryByNumber(group, elem); + } + if (!currentEntry) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to" + " NewDocEntryByNumber failed."); + return NULL; + } + binEntry = new gdcmBinEntry(currentEntry); + if ( !AddEntry(binEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry" + " failed allthough this is a creation."); + } + } + else + { + binEntry = dynamic_cast< gdcmBinEntry* >(currentEntry); + if ( !binEntry ) // Euuuuh? It wasn't a BinEntry + // then we change it to a BinEntry ? + // Shouldn't it be considered as an error ? + { + // We need to promote the gdcmDocEntry to a gdcmBinEntry: + binEntry = new gdcmBinEntry(currentEntry); + if (!RemoveEntry(currentEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal" + " of previous DocEntry failed."); + return NULL; + } + if ( !AddEntry(binEntry)) + { + dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding" + " promoted BinEntry failed."); + return NULL; + } + } + } SetEntryByNumber(voidArea, lgth, group, elem); - return b; + return binEntry; } diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 7c2ef447..8e63544c 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/14 16:47:08 $ - Version: $Revision: 1.36 $ + Date: $Date: 2004/09/16 06:48:00 $ + Version: $Revision: 1.37 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -132,15 +132,13 @@ public: void Write(FILE* fp, FileType type); - 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); + std::string const & VR ="unkn"); gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth, - uint16_t group, uint16_t elem); + uint16_t group, uint16_t elem, + std::string const & VR="unkn"); gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem); -- 2.48.1