From: regrain Date: Fri, 3 Dec 2004 17:13:17 +0000 (+0000) Subject: * Remove memory leaks on the DicomDir X-Git-Tag: Version1.0.bp~543 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=233c8b3ebb1aee6b1be6723d842eb2241b9ffb91;p=gdcm.git * Remove memory leaks on the DicomDir * Remove some useless datas in DicomDirObject * Add usefull methods in SQItem, to be complient withe the ElementSet -- BeNours --- diff --git a/ChangeLog b/ChangeLog index 30933f92..39408951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-12-03 Benoit Regrain + * Remove memory leaks on the DicomDir + * Remove some useless datas in DicomDirObject + * Add usefull methods in SQItem, to be complient withe the ElementSet + 2004-12-03 Benoit Regrain * src/gdcmFile.[h|cxx] : now use FileType instead of TWriteType. diff --git a/Testing/TestAllEntryVerify.cxx b/Testing/TestAllEntryVerify.cxx index 0490f352..089a8ad7 100644 --- a/Testing/TestAllEntryVerify.cxx +++ b/Testing/TestAllEntryVerify.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAllEntryVerify.cxx,v $ Language: C++ - Date: $Date: 2004/11/16 04:28:20 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/12/03 17:13:17 $ + Version: $Revision: 1.15 $ 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,15 @@ std::string ParserException::Indent = " "; class ReferenceFileParser { +public: + ReferenceFileParser(); + bool Open( std::string& referenceFileName ); + void Print(); + void SetDataPath(std::string&); + bool Check(); + bool Check( std::string fileName ); + +private: bool AddKeyValuePairToMap( std::string& key, std::string& value ); std::istream& eatwhite(std::istream& is); @@ -56,6 +65,7 @@ class ReferenceFileParser std::string ExtractFirstString(std::string& toSplit); void CleanUpLine( std::string& line ); + bool Check( MapFileValuesType::iterator &fileIt ); std::string ExtractValue(std::string& toSplit) throw ( ParserException ); void ParseRegularLine( std::string& line ) throw ( ParserException ); void FirstPassReferenceFile() throw ( ParserException ); @@ -64,12 +74,6 @@ class ReferenceFileParser void HandleKey( std::string& line ) throw ( ParserException ); bool HandleValue( std::string& line ) throw ( ParserException ); static uint16_t axtoi( char* ); -public: - ReferenceFileParser(); - bool Open( std::string& referenceFileName ); - void Print(); - void SetDataPath(std::string&); - bool Check(); private: /// The directory containing the images to check: std::string DataPath; @@ -138,7 +142,8 @@ void ReferenceFileParser::SetDataPath( std::string& inDataPath ) DataPath = inDataPath; } -bool ReferenceFileParser::AddKeyValuePairToMap( std::string& key, std::string& value ) +bool ReferenceFileParser::AddKeyValuePairToMap( std::string& key, + std::string& value ) { if ( !CurrentMapEntryValuesPtr ) return false; @@ -173,63 +178,79 @@ void ReferenceFileParser::Print() bool ReferenceFileParser::Check() { + int ret = true; for (MapFileValuesType::iterator i = ProducedMap.begin(); i != ProducedMap.end(); ++i) { - std::string fileName = DataPath + i->first; - std::cout << Indent << "FileName: " << fileName << std::endl; - gdcm::Header* tested = new gdcm::Header( fileName.c_str() ); - if( !tested->IsReadable() ) - { - std::cerr << Indent << "Image not gdcm compatible:" + ret &= Check(i); + } + std::cout << Indent << std::endl; + return ret; +} + +bool ReferenceFileParser::Check( std::string fileName ) +{ + MapFileValuesType::iterator it = ProducedMap.find(fileName); + if( it != ProducedMap.end() ) + { + return Check(it); + } + std::cerr << Indent << "Failed\n" + << Indent << "Image not found :" << fileName << std::endl; - delete tested; - return false; - } + return false; +} - MapEntryValuesPtr KeyValues = i->second; - for (MapEntryValues::iterator j = KeyValues->begin(); - j != KeyValues->end(); - ++j) - { - std::string key = j->first; +bool ReferenceFileParser::Check( MapFileValuesType::iterator &fileIt ) +{ + std::string fileName = DataPath + fileIt->first; + std::cout << Indent << "FileName: " << fileName << std::endl; + gdcm::Header* tested = new gdcm::Header( fileName.c_str() ); + if( !tested->IsReadable() ) + { + std::cerr << Indent << "Failed\n" + << Indent << "Image not gdcm compatible:" + << fileName << std::endl; + delete tested; + return false; + } - std::string groupString = key.substr( 0, 4 ); - char* groupCharPtr; - groupCharPtr = new char(groupString.length() + 1); - strcpy( groupCharPtr, groupString.c_str() ); + MapEntryValuesPtr KeyValues = fileIt->second; + for (MapEntryValues::iterator j = KeyValues->begin(); + j != KeyValues->end(); + ++j) + { + std::string key = j->first; - std::string groupElement = key.substr( key.find_first_of( "|" ) + 1, 4 ); - char* groupElementPtr; - groupElementPtr = new char(groupElement.length() + 1); - strcpy( groupElementPtr, groupElement.c_str() ); + std::string groupString = key.substr( 0, 4 ); + std::string groupElement = key.substr( key.find_first_of( "|" ) + 1, 4 ); - uint16_t group = axtoi( groupCharPtr ); - uint16_t element = axtoi( groupElementPtr ); + uint16_t group = axtoi( &(groupString[0]) ); + uint16_t element = axtoi( &(groupElement[0]) ); - std::string testedValue = tested->GetEntryByNumber(group, element); - if ( testedValue != j->second ) + std::string testedValue = tested->GetEntryByNumber(group, element); + if ( testedValue != j->second ) + { + // Oops make sure this is only the \0 that differ + if( testedValue[j->second.size()] != '\0' || + strncmp(testedValue.c_str(), + j->second.c_str(), j->second.size()) != 0) { - // Oops make sure this is only the \0 that differ - if( testedValue[j->second.size()] != '\0' || - strncmp(testedValue.c_str(), - j->second.c_str(), j->second.size()) != 0) - { - std::cout << Indent << "Uncorrect value for key " - << key << std::endl - << Indent << " read value [" - << testedValue << "]" << std::endl - << Indent << " reference value [" - << j->second << "]" << std::endl; + std::cout << Indent << "Failed\n" + << Indent << "Uncorrect value for key " + << key << std::endl + << Indent << " read value [" + << testedValue << "]" << std::endl + << Indent << " reference value [" + << j->second << "]" << std::endl; return false; - } } } - delete tested; - std::cout << Indent << " OK" << std::endl; } - std::cout << Indent << std::endl; + delete tested; + std::cout << Indent << " OK" << std::endl; + return true; } @@ -274,8 +295,10 @@ std::string ReferenceFileParser::ExtractValue( std::string& toSplit ) std::string::size_type endPos = toSplit.find_last_of( '"' ); // Make sure we have at most two " in toSplit: - std::string noQuotes = toSplit.substr( beginPos + 1, endPos - beginPos - 1); - if ( noQuotes.find_first_of( '"' ) != std::string::npos ) + //std::string noQuotes = toSplit.substr( beginPos + 1, endPos - beginPos - 1); + //if ( noQuotes.find_first_of( '"' ) != std::string::npos ) + // throw ParserException( "more than two quote character" ); + if ( toSplit.find_first_of( '"',beginPos+1 ) != endPos ) throw ParserException( "more than two quote character" ); // No leading quote means this is not a value: @@ -610,10 +633,10 @@ bool ReferenceFileParser::SecondPassReferenceFile() int TestAllEntryVerify(int argc, char* argv[]) { - if ( argc > 1 ) + if ( argc > 2 ) { std::cerr << " Usage: " << argv[0] - << " (no arguments needed)." << std::endl; + << " fileName" << std::endl; return 1; } @@ -629,7 +652,8 @@ int TestAllEntryVerify(int argc, char* argv[]) std::cout << " apply the following tests : "<< std::endl; std::cout << " step 1: parse the image and call IsReadable(). " << std::endl; std::cout << " step 2: look for the entry corresponding to the image" << std::endl; - std::cout << " in the reference file: " << referenceFilename << std::endl; + std::cout << " in the reference file: \n" + << " " << referenceFilename << std::endl; std::cout << " step 3: check that each reference tag value listed for this" << std::endl; std::cout << " entry matches the tag encountered at parsing step 1." @@ -638,13 +662,24 @@ int TestAllEntryVerify(int argc, char* argv[]) ReferenceFileParser Parser; if ( !Parser.Open(referenceFilename) ) { - std::cout << " Corrupted reference file name: " - << referenceFilename << std::endl; + std::cout << " failed" + << " Corrupted reference file name: " + << referenceFilename << std::endl; return 1; } Parser.SetDataPath(referenceDir); // Parser.Print(); - if ( Parser.Check() ) - return 0; - return 1; + std::cout << "Reference fil loaded -->\n" + << "Check files : \n"; + + int ret; + if ( argc >= 2 ) + { + ret = Parser.Check( argv[1] ); + } + else + { + ret = Parser.Check(); + } + return !ret; } diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index ee3b95c1..8394a498 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2004/11/30 17:04:01 $ - Version: $Revision: 1.83 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.84 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -61,7 +61,6 @@ DicomDir::DicomDir() :Document( ) { Initialize(); // sets all private fields to NULL - std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ... MetaElems = NewMeta(); } @@ -86,7 +85,6 @@ DicomDir::DicomDir(std::string const & fileName, bool parseDir ): Initialize(); // sets all private fields to NULL // if user passed a root directory, sure we didn't get anything - if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse { dbg.Verbose(0, "DicomDir::DicomDir : entry HT empty"); @@ -140,7 +138,6 @@ DicomDir::~DicomDir() SetProgressMethod(NULL); SetEndMethod(NULL); - TagHT.clear(); for(ListDicomDirPatient::iterator cc = Patients.begin(); cc!= Patients.end(); ++cc) @@ -221,7 +218,7 @@ void DicomDir::Initialize() Progress = 0.0; Abort = false; - MetaElems = 0; + MetaElems = NULL; } @@ -390,6 +387,8 @@ bool DicomDir::WriteDicomDir(std::string const& fileName) } fp->close(); + delete fp; + return true; } @@ -420,6 +419,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path) break; } +std::cerr<<"File : "<c_str()<c_str() ); if( !header ) { @@ -427,6 +427,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path) "DicomDir::CreateDicomDirChainedList: " "failure in new Header ", it->c_str() ); + continue; } if( header->IsReadable() ) @@ -436,7 +437,6 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path) dbg.Verbose( 1, "DicomDir::CreateDicomDirChainedList: readable ", it->c_str() ); - } else { @@ -451,6 +451,13 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path) //for each Header of the chained list, add/update the Patient/Study/Serie/Image info SetElements(tmp, list); CallEndMethod(); + + for(VectDocument::iterator it=list.begin(); + it!=list.end(); + ++it) + { + delete dynamic_cast
(*it); + } } /** @@ -460,7 +467,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const & path) DicomDirMeta * DicomDir::NewMeta() { - DicomDirMeta *m = new DicomDirMeta( &TagHT ); + DicomDirMeta *m = new DicomDirMeta(); if ( TagHT.begin() != TagHT.end() ) // after Document Parsing { @@ -497,7 +504,7 @@ DicomDirPatient * DicomDir::NewPatient() ListDicomDirPatientElem const & elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements(); - SQItem *s = new SQItem(0); + DicomDirPatient *p = new DicomDirPatient(); // for all the DicomDirPatient Elements for( it = elemList.begin(); it != elemList.end(); ++it ) @@ -531,10 +538,9 @@ DicomDirPatient * DicomDir::NewPatient() { entry->SetLength( entry->GetValue().length() ); } - s->AddDocEntry( entry ); + p->AddDocEntry( entry ); } - DicomDirPatient *p = new DicomDirPatient(s, &TagHT); Patients.push_front( p ); return p; @@ -557,30 +563,57 @@ void DicomDir::SetElement(std::string const & path, DicomDirType type, DictEntry *dictEntry; ValEntry *entry; std::string val; - SQItem *si = new SQItem(0); // all the items will be at level 1 + SQItem *si; switch( type ) { case GDCM_DICOMDIR_IMAGE: elemList = Global::GetDicomDirElements()->GetDicomDirImageElements(); + si = new DicomDirImage(); + if( !AddDicomDirImageToEnd(static_cast(si)) ) + { + dbg.Verbose(0,"DicomDir::SetElement:", + "Add DicomDirImageToEnd failed"); + } break; - case GDCM_DICOMDIR_SERIE: elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements(); + si = new DicomDirSerie(); + if( !AddDicomDirSerieToEnd(static_cast(si)) ) + { + dbg.Verbose(0,"DicomDir::SetElement:", + "Add DicomDirSerieToEnd failed"); + } break; - case GDCM_DICOMDIR_STUDY: elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements(); + si = new DicomDirStudy(); + if( !AddDicomDirStudyToEnd(static_cast(si)) ) + { + dbg.Verbose(0,"DicomDir::SetElement:", + "Add DicomDirStudyToEnd failed"); + } break; - case GDCM_DICOMDIR_PATIENT: elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements(); + si = new DicomDirPatient(); + if( !AddDicomDirPatientToEnd(static_cast(si)) ) + { + dbg.Verbose(0,"DicomDir::SetElement:", + "Add DicomDirPatientToEnd failed"); + } break; - case GDCM_DICOMDIR_META: elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements(); + si = new DicomDirMeta(); + if( MetaElems ) + { + dbg.Verbose(0,"DicomDir::SetElement:", + "MetaElements already exist, they will be destroyed"); + delete MetaElems; + } + MetaElems = static_cast(si); break; - default: return; } @@ -682,30 +715,6 @@ void DicomDir::SetElement(std::string const & path, DicomDirType type, } si->AddEntry(entry); } - switch( type ) - { - case GDCM_DICOMDIR_IMAGE: - AddDicomDirImageToEnd(si); - break; - - case GDCM_DICOMDIR_SERIE: - AddDicomDirSerieToEnd(si); - break; - - case GDCM_DICOMDIR_STUDY: - AddDicomDirStudyToEnd(si); - break; - - case GDCM_DICOMDIR_PATIENT: - AddDicomDirPatientToEnd(si); - break; - - default: - return; - } - //int count=1; // find a trick to increment - //s->AddEntry(si, count); // Seg Faults - } //----------------------------------------------------------------------------- @@ -790,6 +799,7 @@ void DicomDir::CreateDicomDir() DocEntry * d; std::string v; + SQItem * si; for( ListSQItem::iterator i = listItems.begin(); i !=listItems.end(); ++i ) { @@ -806,22 +816,26 @@ void DicomDir::CreateDicomDir() if( v == "PATIENT " ) { - AddDicomDirPatientToEnd( *i ); + si = new DicomDirPatient(); + AddDicomDirPatientToEnd( static_cast(si) ); type = DicomDir::GDCM_DICOMDIR_PATIENT; } else if( v == "STUDY " ) { - AddDicomDirStudyToEnd( *i ); + si = new DicomDirStudy(); + AddDicomDirStudyToEnd( static_cast(si) ); type = DicomDir::GDCM_DICOMDIR_STUDY; } else if( v == "SERIES" ) { - AddDicomDirSerieToEnd( *i ); + si = new DicomDirSerie(); + AddDicomDirSerieToEnd( static_cast(si) ); type = DicomDir::GDCM_DICOMDIR_SERIE; } else if( v == "IMAGE " ) { - AddDicomDirImageToEnd( *i ); + si = new DicomDirImage(); + AddDicomDirImageToEnd( static_cast(si) ); type = DicomDir::GDCM_DICOMDIR_IMAGE; } else @@ -830,20 +844,23 @@ void DicomDir::CreateDicomDir() // neither an 'IMAGE' SQItem. Skip to next item. continue; } + MoveSQItem(si,*i); } + TagHT.clear(); } /** * \ingroup DicomDir * \brief Well ... there is only one occurence */ -void DicomDir::AddDicomDirMeta() +bool DicomDir::AddDicomDirMeta() { if( MetaElems ) { delete MetaElems; } - MetaElems = new DicomDirMeta( &TagHT ); + MetaElems = new DicomDirMeta(); + return true; } /** @@ -851,9 +868,10 @@ void DicomDir::AddDicomDirMeta() * \brief AddDicomDirPatientToEnd * @param s SQ Item to enqueue to the DicomPatient chained List */ -void DicomDir::AddDicomDirPatientToEnd(SQItem *s) +bool DicomDir::AddDicomDirPatientToEnd(DicomDirPatient *dd) { - Patients.push_back(new DicomDirPatient(s, &TagHT)); + Patients.push_back(dd); + return true; } /** @@ -861,14 +879,16 @@ void DicomDir::AddDicomDirPatientToEnd(SQItem *s) * \brief AddDicomDirStudyToEnd * @param s SQ Item to enqueue to the DicomDirStudy chained List */ - void DicomDir::AddDicomDirStudyToEnd(SQItem *s) +bool DicomDir::AddDicomDirStudyToEnd(DicomDirStudy *dd) { if( Patients.size() > 0 ) { ListDicomDirPatient::iterator itp = Patients.end(); itp--; - (*itp)->AddDicomDirStudy(new DicomDirStudy(s, &TagHT)); + (*itp)->AddDicomDirStudy(dd); + return true; } + return false; } /** @@ -876,7 +896,7 @@ void DicomDir::AddDicomDirPatientToEnd(SQItem *s) * \brief AddDicomDirSerieToEnd * @param s SQ Item to enqueue to the DicomDirSerie chained List */ -void DicomDir::AddDicomDirSerieToEnd(SQItem *s) +bool DicomDir::AddDicomDirSerieToEnd(DicomDirSerie *dd) { if( Patients.size() > 0 ) { @@ -888,9 +908,11 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s) ListDicomDirStudy::const_iterator itst = (*itp)->GetDicomDirStudies().end(); itst--; - (*itst)->AddDicomDirSerie(new DicomDirSerie(s, &TagHT)); + (*itst)->AddDicomDirSerie(dd); + return true; } } + return false; } /** @@ -898,7 +920,7 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s) * \brief AddDicomDirImageToEnd * @param s SQ Item to enqueue to the DicomDirImage chained List */ - void DicomDir::AddDicomDirImageToEnd(SQItem *s) +bool DicomDir::AddDicomDirImageToEnd(DicomDirImage *dd) { if( Patients.size() > 0 ) { @@ -915,10 +937,12 @@ void DicomDir::AddDicomDirSerieToEnd(SQItem *s) { ListDicomDirSerie::const_iterator its = (*itst)->GetDicomDirSeries().end(); its--; - (*its)->AddDicomDirImage(new DicomDirImage(s, &TagHT)); + (*its)->AddDicomDirImage(dd); + return true; } } } + return false; } /** @@ -940,32 +964,38 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list) std::string studCurInstanceUID, studCurID; std::string serCurInstanceUID, serCurID; + bool first = true; for( VectDocument::const_iterator it = list.begin(); it != list.end(); ++it ) { // get the current file characteristics - patCurName = (*it)->GetEntryByNumber(0x0010,0x0010); - patCurID = (*it)->GetEntryByNumber(0x0010,0x0011); - studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d); - studCurID = (*it)->GetEntryByNumber(0x0020,0x0010); - serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e); + patCurName = (*it)->GetEntryByNumber(0x0010,0x0010); + patCurID = (*it)->GetEntryByNumber(0x0010,0x0011); + studCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000d); + studCurID = (*it)->GetEntryByNumber(0x0020,0x0010); + serCurInstanceUID = (*it)->GetEntryByNumber(0x0020,0x000e); serCurID = (*it)->GetEntryByNumber(0x0020,0x0011); - if( patCurName != patPrevName || patCurID != patPrevID) + if( patCurName != patPrevName || patCurID != patPrevID || first ) { SetElement(path, GDCM_DICOMDIR_PATIENT, *it); + first = true; } // if new Study Deal with 'STUDY' Elements - if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID ) + if( studCurInstanceUID != studPrevInstanceUID || studCurID != studPrevID + || first ) { SetElement(path, GDCM_DICOMDIR_STUDY, *it); + first = true; } // if new Serie Deal with 'SERIE' Elements - if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID ) + if( serCurInstanceUID != serPrevInstanceUID || serCurID != serPrevID + || first ) { SetElement(path, GDCM_DICOMDIR_SERIE, *it); + first = true; } // Always Deal with 'IMAGE' Elements @@ -977,6 +1007,29 @@ void DicomDir::SetElements(std::string const & path, VectDocument const &list) studPrevID = studCurID; serPrevInstanceUID = serCurInstanceUID; serPrevID = serCurID; + first = false; + } +} + +/** + * \ingroup DicomDir + * \brief Move the content of the src SQItem to the dst SQItem + * Only DocEntry's are moved + * + */ +void DicomDir::MoveSQItem(SQItem* dst,SQItem *src) +{ + DocEntry *entry; + + src->Initialize(); + entry = src->GetNextEntry(); + while(entry) + { + src->RemoveEntryNoDestroy(entry); + dst->AddEntry(entry); + + src->Initialize(); + entry = src->GetNextEntry(); } } diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index c77f91a5..16666170 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.h,v $ Language: C++ - Date: $Date: 2004/11/16 10:25:53 $ - Version: $Revision: 1.39 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.40 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -119,15 +119,17 @@ protected: private: void Initialize(); void CreateDicomDir(); - void AddDicomDirMeta(); - void AddDicomDirPatientToEnd(SQItem* s); - void AddDicomDirStudyToEnd (SQItem* s); - void AddDicomDirSerieToEnd (SQItem* s); - void AddDicomDirImageToEnd (SQItem* s); + + bool AddDicomDirMeta(); + bool AddDicomDirPatientToEnd(DicomDirPatient* dd); + bool AddDicomDirStudyToEnd (DicomDirStudy* dd); + bool AddDicomDirSerieToEnd (DicomDirSerie* dd); + bool AddDicomDirImageToEnd (DicomDirImage* dd); void SetElements(std::string const & path, VectDocument const &list); void SetElement (std::string const & path, DicomDirType type, Document* header); + void MoveSQItem(SQItem* dst,SQItem *src); static bool HeaderLessThan(Document* header1, Document* header2); diff --git a/src/gdcmDicomDirImage.cxx b/src/gdcmDicomDirImage.cxx index ba2134ab..5a12172e 100644 --- a/src/gdcmDicomDirImage.cxx +++ b/src/gdcmDicomDirImage.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirImage.cxx,v $ Language: C++ - Date: $Date: 2004/10/25 03:35:19 $ - Version: $Revision: 1.13 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,28 +23,14 @@ namespace gdcm { //----------------------------------------------------------------------------- // Constructor / Destructor - -/** - * \ingroup DicomDirImage - * \brief Constructor - * @param s SQ Item holding the elements - * @param ptagHT pointer to the HTable (DicomDirObject needs it - * to build the DocEntries) - */ -DicomDirImage::DicomDirImage(SQItem *s, TagDocEntryHT *ptagHT): - DicomDirObject(ptagHT) -{ - DocEntries = s->GetDocEntries(); -} - /** * \ingroup DicomDirImage * \brief Constructor * @param ptagHT pointer to the HTable (DicomDirObject needs it * to build the DocEntries) */ -DicomDirImage::DicomDirImage(TagDocEntryHT *ptagHT): - DicomDirObject(ptagHT) +DicomDirImage::DicomDirImage(): + DicomDirObject() { } /** diff --git a/src/gdcmDicomDirImage.h b/src/gdcmDicomDirImage.h index a1e101f5..5731cd0e 100644 --- a/src/gdcmDicomDirImage.h +++ b/src/gdcmDicomDirImage.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirImage.h,v $ Language: C++ - Date: $Date: 2004/10/25 03:35:19 $ - Version: $Revision: 1.11 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,9 +27,7 @@ namespace gdcm class GDCM_EXPORT DicomDirImage : public DicomDirObject { public: - DicomDirImage(SQItem *s, TagDocEntryHT *ptagHT); - DicomDirImage(TagDocEntryHT *ptagHT); - + DicomDirImage(); ~DicomDirImage(); void Print(std::ostream &os = std::cout); diff --git a/src/gdcmDicomDirMeta.cxx b/src/gdcmDicomDirMeta.cxx index 64ff1459..be4ecbfd 100644 --- a/src/gdcmDicomDirMeta.cxx +++ b/src/gdcmDicomDirMeta.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:10 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/12/03 17:13:18 $ + 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 @@ -29,8 +29,8 @@ namespace gdcm * \ingroup DicomDirMeta * \brief Constructor */ -DicomDirMeta::DicomDirMeta(TagDocEntryHT* ptagHT): - DicomDirObject(ptagHT) +DicomDirMeta::DicomDirMeta(): + DicomDirObject() { } diff --git a/src/gdcmDicomDirMeta.h b/src/gdcmDicomDirMeta.h index 5a3059cb..9c50ee16 100644 --- a/src/gdcmDicomDirMeta.h +++ b/src/gdcmDicomDirMeta.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.h,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.11 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,8 +27,7 @@ namespace gdcm class GDCM_EXPORT DicomDirMeta : public DicomDirObject { public: - DicomDirMeta(TagDocEntryHT *ptagHT); - + DicomDirMeta(); ~DicomDirMeta(); virtual void Print(std::ostream &os = std::cout); diff --git a/src/gdcmDicomDirObject.cxx b/src/gdcmDicomDirObject.cxx index 3997b0f2..882b8a2f 100644 --- a/src/gdcmDicomDirObject.cxx +++ b/src/gdcmDicomDirObject.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirObject.cxx,v $ Language: C++ - Date: $Date: 2004/10/25 04:08:20 $ - Version: $Revision: 1.7 $ + Date: $Date: 2004/12/03 17:13:18 $ + 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 @@ -33,10 +33,9 @@ namespace gdcm * @param depth Sequence depth level */ -DicomDirObject::DicomDirObject(TagDocEntryHT *ptagHT, int depth) +DicomDirObject::DicomDirObject(int depth) : SQItem (depth) { - PtagHT = ptagHT; } diff --git a/src/gdcmDicomDirObject.h b/src/gdcmDicomDirObject.h index 713682ba..8503569b 100644 --- a/src/gdcmDicomDirObject.h +++ b/src/gdcmDicomDirObject.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirObject.h,v $ Language: C++ - Date: $Date: 2004/10/25 03:35:19 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -40,7 +40,7 @@ class GDCM_EXPORT DicomDirObject : public SQItem { public: - DicomDirObject(TagDocEntryHT *ptagHT, int depth = 0); + DicomDirObject(int depth = 1); ~DicomDirObject(); /** diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index f6a149a9..93a459ca 100644 --- a/src/gdcmDicomDirPatient.cxx +++ b/src/gdcmDicomDirPatient.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.19 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.20 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,22 +26,11 @@ namespace gdcm // Constructor / Destructor /** * \brief Constructor - * @param s SQ Item holding the elements related to this "PATIENT" part * @param ptagHT pointer to the HTable (DicomDirObject needs it * to build the HeaderEntries) */ -DicomDirPatient::DicomDirPatient(SQItem *s, TagDocEntryHT *ptagHT) : - DicomDirObject(ptagHT) -{ - DocEntries = s->GetDocEntries(); -} -/** - * \brief Constructor - * @param ptagHT pointer to the HTable (DicomDirObject needs it - * to build the HeaderEntries) - */ -DicomDirPatient::DicomDirPatient(TagDocEntryHT* ptagHT): - DicomDirObject(ptagHT) +DicomDirPatient::DicomDirPatient(): + DicomDirObject() { } /** @@ -104,7 +93,7 @@ DicomDirStudy* DicomDirPatient::NewStudy() ListDicomDirStudyElem const & elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements(); - DicomDirStudy* st = new DicomDirStudy( PtagHT ); + DicomDirStudy* st = new DicomDirStudy(); st->FillObject(elemList); Studies.push_front(st); diff --git a/src/gdcmDicomDirPatient.h b/src/gdcmDicomDirPatient.h index f5e7ebfc..2052d025 100644 --- a/src/gdcmDicomDirPatient.h +++ b/src/gdcmDicomDirPatient.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.h,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.13 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,9 +33,7 @@ typedef std::list ListDicomDirStudy; class GDCM_EXPORT DicomDirPatient : public DicomDirObject { public: - DicomDirPatient(SQItem *s, TagDocEntryHT *ptagHT); - DicomDirPatient(TagDocEntryHT *ptagHT); - + DicomDirPatient(); ~DicomDirPatient(); void Print(std::ostream &os = std::cout); diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 13c31080..dcdd7465 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,23 +27,11 @@ namespace gdcm // Constructor / Destructor /** * \brief Constructor - * @param s SQ Item holding the elements related to this "SERIE" part * @param ptagHT pointer to the HTable (DicomDirObject needs it * to build the DocEntries) */ -DicomDirSerie::DicomDirSerie(SQItem* s, TagDocEntryHT* ptagHT) : - DicomDirObject(ptagHT) -{ - DocEntries = s->GetDocEntries(); -} - -/** - * \brief Constructor - * @param ptagHT pointer to the HTable (DicomDirObject needs it - * to build the DocEntries) - */ -DicomDirSerie::DicomDirSerie(TagDocEntryHT* ptagHT): - DicomDirObject(ptagHT) +DicomDirSerie::DicomDirSerie(): + DicomDirObject() { } /** @@ -106,7 +94,7 @@ DicomDirImage* DicomDirSerie::NewImage() ListDicomDirImageElem const & elemList = Global::GetDicomDirElements()->GetDicomDirImageElements(); - DicomDirImage* st = new DicomDirImage(PtagHT); + DicomDirImage* st = new DicomDirImage(); FillObject(elemList); Images.push_front(st); diff --git a/src/gdcmDicomDirSerie.h b/src/gdcmDicomDirSerie.h index 8021d859..4f4371a3 100644 --- a/src/gdcmDicomDirSerie.h +++ b/src/gdcmDicomDirSerie.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.h,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,9 +31,7 @@ typedef std::list ListDicomDirImage; class GDCM_EXPORT DicomDirSerie : public DicomDirObject { public: - DicomDirSerie( SQItem* s, TagDocEntryHT* ptagHT ); - DicomDirSerie( TagDocEntryHT* ptagHT ); - + DicomDirSerie(); ~DicomDirSerie(); void Print( std::ostream& os = std::cout ); diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index d15c62ef..a602cdd2 100644 --- a/src/gdcmDicomDirStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,27 +24,14 @@ namespace gdcm { //----------------------------------------------------------------------------- // Constructor / Destructor - -/** - * \ingroup DicomDirStudy - * \brief constructor - * @param s SQ Item holding the elements related to this "STUDY" part - * @param ptagHT pointer to the HTable (DicomDirObject needs it - * to build the HeaderEntries) - */ -DicomDirStudy::DicomDirStudy(SQItem* s, TagDocEntryHT* ptagHT): - DicomDirObject(ptagHT) -{ - DocEntries = s->GetDocEntries(); -} /** * \ingroup DicomDirStudy * \brief constructor * @param ptagHT pointer to the HTable (DicomDirObject needs it * to build the HeaderEntries) */ -DicomDirStudy::DicomDirStudy(TagDocEntryHT* ptagHT): - DicomDirObject(ptagHT) +DicomDirStudy::DicomDirStudy(): + DicomDirObject() { } /** @@ -111,7 +98,7 @@ DicomDirSerie* DicomDirStudy::NewSerie() ListDicomDirSerieElem const & elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements(); - DicomDirSerie* st = new DicomDirSerie(PtagHT); + DicomDirSerie* st = new DicomDirSerie(); FillObject(elemList); Series.push_front(st); diff --git a/src/gdcmDicomDirStudy.h b/src/gdcmDicomDirStudy.h index 5a083f28..7ddd3666 100644 --- a/src/gdcmDicomDirStudy.h +++ b/src/gdcmDicomDirStudy.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.h,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.13 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,9 +31,7 @@ typedef std::list ListDicomDirSerie; class GDCM_EXPORT DicomDirStudy : public DicomDirObject { public: - DicomDirStudy(SQItem *s, TagDocEntryHT *ptagHT); - DicomDirStudy(TagDocEntryHT *ptagHT); - + DicomDirStudy(); ~DicomDirStudy(); void Print(std::ostream &os = std::cout); diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 0b60c37d..dd2c6d19 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.32 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.33 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -126,41 +126,41 @@ bool ElementSet::AddEntry(DocEntry* newEntry) } /** - * \brief Clear the hash table from given entry BUT keep the entry. - * @param entryToRemove Entry to remove. + * \brief Clear the hash table from given entry AND delete the entry. + * @param entryToRemove Entry to remove AND delete. + * \warning Some problems when using under Windows... prefer the use of + * Initialize / GetNext methods */ -bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove) +bool ElementSet::RemoveEntry( DocEntry* entryToRemove) { const TagKey& key = entryToRemove->GetKey(); if( TagHT.count(key) == 1 ) { TagHT.erase(key); dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased."); + delete entryToRemove; return true; } - dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: "); + dbg.Verbose(0, "ElementSet::RemoveEntry: key not present"); return false ; } /** - * \brief Clear the hash table from given entry AND delete the entry. - * @param entryToRemove Entry to remove AND delete. - * \warning Some problems when using under Windows... prefer the use of - * Initialize / GetNext methods + * \brief Clear the hash table from given entry BUT keep the entry. + * @param entryToRemove Entry to remove. */ -bool ElementSet::RemoveEntry( DocEntry* entryToRemove) +bool ElementSet::RemoveEntryNoDestroy(DocEntry* entryToRemove) { const TagKey& key = entryToRemove->GetKey(); if( TagHT.count(key) == 1 ) { TagHT.erase(key); dbg.Verbose(0, "ElementSet::RemoveEntry: one element erased."); - delete entryToRemove; return true; } - dbg.Verbose(0, "ElementSet::RemoveEntry: key not present: "); + dbg.Verbose(0, "ElementSet::RemoveEntry: key not present"); return false ; } diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 07309364..62e50677 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 15:46:11 $ - Version: $Revision: 1.38 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.39 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -237,10 +237,83 @@ bool SQItem::SetEntryByNumber(std::string const & val, uint16_t group, } return false; } -//----------------------------------------------------------------------------- -// Protected +/** + * \brief Clear the hash table from given entry AND delete the entry. + * @param entryToRemove Entry to remove AND delete. + * \warning Some problems when using under Windows... prefer the use of + * Initialize / GetNext methods + */ +bool SQItem::RemoveEntry( DocEntry* entryToRemove) +{ + for(ListDocEntry::iterator it = DocEntries.begin(); + it != DocEntries.end(); + ++it) + { + if( *it == entryToRemove) + { + DocEntries.erase(it); + dbg.Verbose(0, "SQItem::RemoveEntry: one element erased."); + delete entryToRemove; + return true; + } + } + + dbg.Verbose(0, "SQItem::RemoveEntry: value not present "); + return false ; +} + +/** + * \brief Clear the hash table from given entry BUT keep the entry. + * @param entryToRemove Entry to remove. + */ +bool SQItem::RemoveEntryNoDestroy(DocEntry* entryToRemove) +{ + for(ListDocEntry::iterator it = DocEntries.begin(); + it != DocEntries.end(); + ++it) + { + if( *it == entryToRemove) + { + DocEntries.erase(it); + dbg.Verbose(0, "SQItem::RemoveEntry: one element erased."); + return true; + } + } + + dbg.Verbose(0, "SQItem::RemoveEntry: value not present "); + return false ; +} + +/** + * \brief Initialise the visit of the chained list + */ +void SQItem::Initialize() +{ + ItDocEntries = DocEntries.begin(); +} + +/** + * \brief Get the next entry whil visiting the chained list + * \return The next DocEntry if found, otherwhise NULL + */ +DocEntry *SQItem::GetNextEntry() +{ + if (ItDocEntries != DocEntries.end()) + { + DocEntry *tmp = *ItDocEntries; + ++ItDocEntries; + + return(tmp); + } + else + { + return(NULL); + } +} +//----------------------------------------------------------------------------- +// Protected /** * \brief Gets a Dicom Element inside a SQ Item Entry, by number * @return diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index be859498..e1ba7a52 100644 --- a/src/gdcmSQItem.h +++ b/src/gdcmSQItem.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.h,v $ Language: C++ - Date: $Date: 2004/11/30 16:24:31 $ - Version: $Revision: 1.24 $ + Date: $Date: 2004/12/03 17:13:18 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,7 +47,9 @@ public: /// this SQ Item. void AddDocEntry(DocEntry *e) { DocEntries.push_back(e); }; - virtual bool AddEntry(DocEntry *Entry); // add to the List + bool AddEntry(DocEntry *Entry); // add to the List + bool RemoveEntry(DocEntry *EntryToRemove); + bool RemoveEntryNoDestroy(DocEntry *EntryToRemove); DocEntry *GetDocEntryByNumber(uint16_t group, uint16_t element); // FIXME method to write @@ -76,12 +78,16 @@ public: /// Accessor on \ref BaseTagKey. BaseTagKey const & GetBaseTagKey() const { return BaseTagKeyNested; } + void Initialize(); + DocEntry *GetNextEntry(); protected: // Variables that need to be access in subclasses - /// \brief chained list of (Elementary) Doc Entries + /// \brief Chained list of (Elementary) Doc Entries ListDocEntry DocEntries; + /// Chained list iterator, used to visit the TagHT variable + ListDocEntry::iterator ItDocEntries; ///\brief pointer to the HTable of the Document, /// (because we don't know it within any DicomDirObject nor any SQItem)