From 5a0d183707a94e875a595036f64d0bd506faf618 Mon Sep 17 00:00:00 2001 From: regrain Date: Fri, 14 Jan 2005 11:28:28 +0000 Subject: [PATCH] * src/gdcmDocument.[h|cxx] : comment all methods concerning a flat hash table. * src/gdcmElementSet.[h|cxx] : rename Initialize into InitTraversal * src/gdcmDict.[h|cxx] : add InitTraversal/getNextEntry methods to parse all the dict content. * src/gdcmDictEntry.cxx : add a carriage return at the end of the DictEntry print * Test/TestDict.cxx : add a new test for the dict classes -- BeNours --- ChangeLog | 10 +++++ Example/FlatHashTablePrint.cxx | 9 ++-- Example/TestCopyDicom.cxx | 20 +++------ Example/TestFromScratch.cxx | 9 ++-- Testing/CMakeLists.txt | 7 +-- Testing/TestCopyDicom.cxx | 7 ++- Testing/TestCopyRescaleDicom.cxx | 9 ++-- Testing/TestDict.cxx | 75 ++++++++++++++++++++++++++++++++ gdcmPython/demo/PrintDict.py.in | 17 ++++---- src/gdcmDict.cxx | 54 ++++++++++++++++++++--- src/gdcmDict.h | 18 ++++---- src/gdcmDictEntry.cxx | 6 +-- src/gdcmDocument.cxx | 14 +++--- src/gdcmDocument.h | 10 ++--- src/gdcmElementSet.cxx | 6 +-- src/gdcmElementSet.h | 8 ++-- 16 files changed, 201 insertions(+), 78 deletions(-) create mode 100644 Testing/TestDict.cxx diff --git a/ChangeLog b/ChangeLog index 3854200e..2d27c58a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-01-14 Benoit Regrain + * src/gdcmDocument.[h|cxx] : comment all methods concerning a flat hash + table. + * src/gdcmElementSet.[h|cxx] : rename Initialize into InitTraversal + * src/gdcmDict.[h|cxx] : add InitTraversal/getNextEntry methods to parse + all the dict content. + * src/gdcmDictEntry.cxx : add a carriage return at the end of the DictEntry + print + * Test/TestDict.cxx : add a new test for the dict classes + 2005-01-13 Mathieu Malaterre * src/gdcmDebug.h : Adding an option to redirect debug stream to a file. Debug is yanked if compiled with NDEBUG diff --git a/Example/FlatHashTablePrint.cxx b/Example/FlatHashTablePrint.cxx index 9403d02d..8fc20075 100644 --- a/Example/FlatHashTablePrint.cxx +++ b/Example/FlatHashTablePrint.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: FlatHashTablePrint.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 20:16:55 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/01/14 11:28:28 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) { - if (argc < 2) +/* if (argc < 2) { std::cerr << "Usage :" << std::endl << argv[0] << " input_dicom " << std::endl; @@ -38,7 +38,8 @@ int main(int argc, char* argv[]) { tag->second->Print(); std::cout << std::endl; - } + }*/ + std::cout<<"Usefull example ???\n"; return 0; } diff --git a/Example/TestCopyDicom.cxx b/Example/TestCopyDicom.cxx index 84b1b5e6..bc1313cf 100644 --- a/Example/TestCopyDicom.cxx +++ b/Example/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:57 $ - Version: $Revision: 1.15 $ + Date: $Date: 2005/01/14 11:28:28 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -87,8 +87,6 @@ int main(int argc, char* argv[]) gdcm::File *copy = new gdcm::File( output ); - const gdcm::TagDocEntryHT & Ht = original->GetHeader()->GetTagHT(); - size_t dataSize = original->GetImageDataSize(); uint8_t* imageData = original->GetImageData(); (void)imageData; @@ -101,12 +99,10 @@ int main(int argc, char* argv[]) // (the user does NOT have to know the way we implemented the Header !) // Waiting for a 'clean' solution, I keep the method ...JPRx - gdcm::DocEntry* d; - - for (gdcm::TagDocEntryHT::const_iterator tag = Ht.begin(); tag != Ht.end(); ++tag) + original->GetHeader()->InitTraversal(); + gdcm::DocEntry* d=original->GetHeader()->GetNextEntry(); + while(d) { - d = tag->second; - d->Print(); std::cout << std::endl; if ( gdcm::BinEntry* b = dynamic_cast(d) ) { copy->GetHeader()->ReplaceOrCreate( @@ -132,11 +128,9 @@ int main(int argc, char* argv[]) // << d->GetGroup() << " " << d->GetElement() // << std::endl; } - } - - - + d=original->GetHeader()->GetNextEntry(); + } //copy->GetImageData(); //copy->SetImageData(imageData, dataSize); diff --git a/Example/TestFromScratch.cxx b/Example/TestFromScratch.cxx index 11589526..e9760b86 100644 --- a/Example/TestFromScratch.cxx +++ b/Example/TestFromScratch.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestFromScratch.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:57 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/01/14 11:28:28 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,10 +54,9 @@ int main(int argc, char *argv[]) // Hopefully default to something gdcm::Header *h2 = new gdcm::Header(); - h1->Initialize(); - gdcm::DocEntry* d = h1->GetNextEntry(); - // Copy of the header content + h1->InitTraversal(); + gdcm::DocEntry* d = h1->GetNextEntry(); while(d) { if ( gdcm::ValEntry* v = dynamic_cast(d) ) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 1438a9b2..125cf5ac 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -14,6 +14,7 @@ SET(TEST_SOURCES TestVR.cxx TestUtil.cxx TestDicomString.cxx + TestDict.cxx ) # add tests that require data @@ -24,12 +25,12 @@ IF (GDCM_DATA_ROOT) TestAllReadCompareDicom.cxx # includes generated gdcmDataImages.h TestAllEntryVerify.cxx # includes generated gdcmDataImages.h #TestChangeHeader.cxx - TestDicomDir.cxx # require DICOMDIR - BuildUpDicomDir.cxx # writes a file named "NewDICOMDIR" - makeDicomDir.cxx # writes a file named "NewDICOMDIR" TestCopyDicom.cxx TestCopyRescaleDicom.cxx TestWriteSimple.cxx + TestDicomDir.cxx # require DICOMDIR + BuildUpDicomDir.cxx # writes a file named "NewDICOMDIR" + makeDicomDir.cxx # writes a file named "NewDICOMDIR" ) # add test that require VTK: IF(GDCM_VTK) diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index 45588b36..af7f4d45 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:58 $ - Version: $Revision: 1.28 $ + Date: $Date: 2005/01/14 11:28:29 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -85,9 +85,8 @@ int CopyDicom(std::string const & filename, //////////////// Step 2: std::cout << "2..."; - originalH->Initialize(); + originalH->InitTraversal(); gdcm::DocEntry* d=originalH->GetNextEntry(); - while(d) { if ( gdcm::BinEntry* b = dynamic_cast(d) ) diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index aa1ed72c..975d91c8 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/08 15:03:58 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/01/14 11:28:29 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -56,10 +56,9 @@ int CopyRescaleDicom(std::string const & filename, //////////////// Step 2: std::cout << "2..."; - originalH->Initialize(); - gdcm::DocEntry* d = originalH->GetNextEntry(); - // Copy of the header content + originalH->InitTraversal(); + gdcm::DocEntry* d = originalH->GetNextEntry(); while(d) { if ( gdcm::BinEntry* b = dynamic_cast(d) ) diff --git a/Testing/TestDict.cxx b/Testing/TestDict.cxx new file mode 100644 index 00000000..cd0601e6 --- /dev/null +++ b/Testing/TestDict.cxx @@ -0,0 +1,75 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: TestDict.cxx,v $ + Language: C++ + Date: $Date: 2005/01/14 11:28:29 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "gdcmGlobal.h" +#include "gdcmDictSet.h" +#include "gdcmDict.h" +#include "gdcmDictEntry.h" + +#include +#include + +int TestDict(int argc, char* argv[]) +{ + // Print the DictSet + std::cout<<"#######################################################\n"; + gdcm::DictSet *dicts=gdcm::Global::GetDicts(); + if(!dicts) + { + std::cout<<"The DictSet hasn't be found... Failed\n"; + return(1); + } + std::cout<<"DictSet content :\n"; +// dicts->Print(std::cout); + + // Print the Dict (public) + std::cout<<"#######################################################\n"; + gdcm::Dict *pubDict=dicts->GetDefaultPubDict(); + if(!pubDict) + { + std::cout<<"The public Dict hasn't be found... Failed\n"; + return(1); + } + std::cout<<"Public Dict content :\n"; +// pubDict->Print(std::cout); + + // Print the DictEntry (0x10,0x20) + std::cout<<"#######################################################\n"; + const int ENTRY_GR = 0x10; + const int ENTRY_EL = 0x20; + std::string key=gdcm::DictEntry::TranslateToKey(ENTRY_GR,ENTRY_EL); + gdcm::DictEntry *entry=pubDict->GetDictEntry(ENTRY_GR,ENTRY_EL); + if(!entry) + { + std::cout<<"The DictEntry hasn't be found... Failed\n"; + return(1); + } + std::cout<<"Entry "<Print(std::cout); + + // Print all the DictEntry + std::cout<<"#######################################################\n"; + pubDict->InitTraversal(); + entry=pubDict->GetNextEntry(); + while(entry) + { + entry->Print(std::cout); + entry=pubDict->GetNextEntry(); + } + + return(0); +} diff --git a/gdcmPython/demo/PrintDict.py.in b/gdcmPython/demo/PrintDict.py.in index 4a1eb84a..8adbdd9d 100644 --- a/gdcmPython/demo/PrintDict.py.in +++ b/gdcmPython/demo/PrintDict.py.in @@ -37,13 +37,12 @@ if(not isinstance(entry,gdcm.DictEntry)): print "Entry (%04x|%04x) content :" % (ENTRY_GR,ENTRY_EL) entry.Print() -# Print the DictEntry (0010|0010) -ENTRY_GR = 0x10 -ENTRY_EL = 0x10 -entry=pubDict.GetDictEntry(ENTRY_GR,ENTRY_EL) -if(not isinstance(entry,gdcm.DictEntry)): - raise RuntimeError,"The entry (%04x|%04x) hasn't the good type (%s)" % \ - (ENTRY_GR,ENTRY_EL,type(entry)) -print "Entry (%04x|%04x) content :" % (ENTRY_GR,ENTRY_EL) -entry.Print() +print "#####################################################################" +# Print the public Dict content +print "dict content :" +pubDict.InitTraversal() +entry=pubDict.GetNextEntry() +while(entry): + entry.Print() + entry=pubDict.GetNextEntry() diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 9c3235c7..027ce31a 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.cxx,v $ Language: C++ - Date: $Date: 2005/01/12 15:23:44 $ - Version: $Revision: 1.62 $ + Date: $Date: 2005/01/14 11:28:30 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -29,6 +29,14 @@ namespace gdcm void FillDefaultDataDict(Dict *d); //----------------------------------------------------------------------------- // Constructor / Destructor +/** + * \brief Constructor + */ +Dict::Dict(void) +{ + Filename=""; +} + /** * \brief Constructor * @param filename from which to build the dictionary. @@ -74,9 +82,7 @@ Dict::Dict(std::string const &filename) */ Dict::~Dict() { - // we assume all the pointed DictEntries are already cleaned-up - // when we clean KeyHt. - KeyHt.clear(); + ClearEntry(); } //----------------------------------------------------------------------------- @@ -107,6 +113,17 @@ void Dict::Print(std::ostream &os) //----------------------------------------------------------------------------- // Public +/** + * \ingroup Dict + * \brief Remove all Dicom Dictionary Entries + */ +void Dict::ClearEntry() +{ + // we assume all the pointed DictEntries are already cleaned-up + // when we clean KeyHt. + KeyHt.clear(); +} + /** * \ingroup Dict * \brief adds a new Dicom Dictionary Entry @@ -257,6 +274,33 @@ DictEntry *Dict::GetDictEntry(uint16_t group, uint16_t elem) // return result; //} +/** + * \brief Initialise the visit of the Hash table (KeyHt) + */ +void Dict::InitTraversal() +{ + ItKeyHt = KeyHt.begin(); +} + +/** + * \brief Get the next entry whil visiting the Hash table (KeyHt) + * \return The next DictEntry if found, otherwhise NULL + */ +DictEntry *Dict::GetNextEntry() +{ + if (ItKeyHt != KeyHt.end()) + { + DictEntry *tmp = &(ItKeyHt->second); + ++ItKeyHt; + + return tmp; + } + else + { + return NULL; + } +} + //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDict.h b/src/gdcmDict.h index ab0b99ef..ca31531e 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.h,v $ Language: C++ - Date: $Date: 2005/01/11 15:15:38 $ - Version: $Revision: 1.30 $ + Date: $Date: 2005/01/14 11:28:30 $ + Version: $Revision: 1.31 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -49,6 +49,7 @@ typedef std::map ( set ) ) @@ -2846,7 +2846,7 @@ void Document::BuildFlatHashTableRecurse( TagDocEntryHT &builtHT, } } -} +}*/ /** * \brief Build a \ref TagDocEntryHT (i.e. a std::map<>) from the current @@ -2871,12 +2871,12 @@ void Document::BuildFlatHashTableRecurse( TagDocEntryHT &builtHT, * \ref BuildFlatHashTable again... * @return The flat std::map<> we juste build. */ -TagDocEntryHT *Document::BuildFlatHashTable() +/*TagDocEntryHT *Document::BuildFlatHashTable() { TagDocEntryHT *FlatHT = new TagDocEntryHT; BuildFlatHashTableRecurse( *FlatHT, this ); return FlatHT; -} +}*/ @@ -2961,7 +2961,7 @@ int Document::ComputeGroup0002Length( FileType filetype ) // for each zero-level Tag in the DCM Header DocEntry *entry; - Initialize(); + InitTraversal(); entry = GetNextEntry(); while(entry) { diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 0a74dcf4..7a9a2bf3 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2005/01/13 09:23:27 $ - Version: $Revision: 1.86 $ + Date: $Date: 2005/01/14 11:28:30 $ + Version: $Revision: 1.87 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -120,7 +120,7 @@ public: virtual void LoadEntryBinArea(BinEntry *entry); void LoadDocEntrySafe(DocEntry *entry); - TagDocEntryHT *BuildFlatHashTable(); + /*TagDocEntryHT *BuildFlatHashTable();*/ /// Return the Transfer Syntax as a string std::string GetTransferSyntaxName(); @@ -230,8 +230,8 @@ private: DocEntry *ReadNextDocEntry(); uint32_t GenerateFreeTagKeyInGroup(uint16_t group); - void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT, - DocEntrySet* set ); +/* void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT, + DocEntrySet* set );*/ void HandleBrokenEndian(uint16_t &group, uint16_t &elem); void HandleOutOfGroup0002(uint16_t &group, uint16_t &elem); diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index dade9a06..397e4e1b 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 00:21:48 $ - Version: $Revision: 1.40 $ + Date: $Date: 2005/01/14 11:28:30 $ + Version: $Revision: 1.41 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -165,7 +165,7 @@ bool ElementSet::RemoveEntryNoDestroy(DocEntry *entryToRemove) /** * \brief Initialise the visit of the Hash table (TagHT) */ -void ElementSet::Initialize() +void ElementSet::InitTraversal() { ItTagHT = TagHT.begin(); } diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index cfc921bd..fff8f723 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.h,v $ Language: C++ - Date: $Date: 2005/01/11 15:15:38 $ - Version: $Revision: 1.29 $ + Date: $Date: 2005/01/14 11:28:31 $ + Version: $Revision: 1.30 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -58,9 +58,9 @@ public: /// Accessor to \ref TagHT // Do not expose this to user (public API) ! // A test is using it thus put it in public (matt) - TagDocEntryHT const &GetTagHT() const { return TagHT; }; + //TagDocEntryHT const &GetTagHT() const { return TagHT; }; - void Initialize(); + void InitTraversal(); DocEntry *GetNextEntry(); protected: -- 2.45.1