From 49c0af19f5bf0f2402d37d8abf7fb139e7453245 Mon Sep 17 00:00:00 2001 From: malaterre Date: Sun, 1 Aug 2004 00:59:21 +0000 Subject: [PATCH] ENH: Minor patch, cosmetic -again-. Remove all this->. I might have discover the reason of misterious leaks --- src/gdcmBinEntry.cxx | 43 +++++++----- src/gdcmDicomDirPatient.cxx | 22 +++--- src/gdcmDicomDirSerie.cxx | 28 +++++--- src/gdcmDicomDirStudy.cxx | 21 +++--- src/gdcmDictSet.cxx | 6 +- src/gdcmDictSet.h | 19 ++--- src/gdcmDirList.cxx | 8 +-- src/gdcmDocEntry.cxx | 134 +++++++++++++++++++++--------------- src/gdcmDocEntry.h | 8 +-- src/gdcmDocument.cxx | 12 ++-- src/gdcmHeaderHelper.cxx | 10 +-- src/gdcmObject.cxx | 41 ++++++----- src/gdcmObject.h | 16 ++--- src/gdcmSQItem.cxx | 102 ++++++++++++++++----------- src/gdcmSQItem.h | 10 +-- src/gdcmValEntry.cxx | 94 +++++++++++++++++-------- src/gdcmValEntry.h | 15 ++-- 17 files changed, 343 insertions(+), 246 deletions(-) diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index 81230ef9..03a93ba2 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2004/06/25 12:58:24 $ - Version: $Revision: 1.19 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -28,7 +28,7 @@ */ gdcmBinEntry::gdcmBinEntry(gdcmDictEntry* e) : gdcmValEntry(e) { - this->voidArea = NULL; + voidArea = NULL; } /** @@ -37,22 +37,26 @@ gdcmBinEntry::gdcmBinEntry(gdcmDictEntry* e) : gdcmValEntry(e) */ gdcmBinEntry::gdcmBinEntry(gdcmDocEntry* e) : gdcmValEntry(e->GetDictEntry()) { - this->UsableLength = e->GetLength(); - this->ReadLength = e->GetReadLength(); - this->ImplicitVR = e->IsImplicitVR(); - this->Offset = e->GetOffset(); - this->printLevel = e->GetPrintLevel(); - this->SQDepthLevel = e->GetDepthLevel(); + UsableLength = e->GetLength(); + ReadLength = e->GetReadLength(); + ImplicitVR = e->IsImplicitVR(); + Offset = e->GetOffset(); + printLevel = e->GetPrintLevel(); + SQDepthLevel = e->GetDepthLevel(); - this->voidArea = NULL; // let's be carefull ! + voidArea = NULL; // let's be carefull ! } /** * \brief Canonical destructor. */ -gdcmBinEntry::~gdcmBinEntry(){ +gdcmBinEntry::~gdcmBinEntry() +{ if (voidArea) + { free (voidArea); + voidArea = NULL; // let's be carefull ! + } } @@ -67,7 +71,7 @@ void gdcmBinEntry::Print(std::ostream &os) gdcmDocEntry::Print(os); std::ostringstream s; void *voidArea = GetVoidArea(); - if (voidArea != NULL) + if (voidArea) { s << " [gdcm::Binary data loaded with length is " << GetLength() << "]"; @@ -75,7 +79,9 @@ void gdcmBinEntry::Print(std::ostream &os) else { if ( GetLength() == 0 ) + { s << " []"; + } else { s << " [gdcm::Binary data NOT loaded]"; @@ -88,15 +94,16 @@ void gdcmBinEntry::Print(std::ostream &os) /* * \brief canonical Writer */ -void gdcmBinEntry::Write(FILE *fp, FileType filetype) { +void gdcmBinEntry::Write(FILE *fp, FileType filetype) +{ gdcmDocEntry::Write(fp, filetype); void *voidArea = GetVoidArea(); - int lgr=GetLength(); - if (voidArea != NULL) - { // there is a 'non string' LUT, overlay, etc + int lgr = GetLength(); + if (voidArea) + { + // there is a 'non string' LUT, overlay, etc fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,fp); // Elem value - return; - } + } } //----------------------------------------------------------------------------- // Public diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index e4c646d0..85fa49b5 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/06/20 18:08:47 $ - Version: $Revision: 1.8 $ + Date: $Date: 2004/08/01 00:59:21 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -65,12 +65,13 @@ gdcmDicomDirPatient::~gdcmDicomDirPatient() */ void gdcmDicomDirPatient::Print(std::ostream &os) { - os<<"PATIENT"<SetPrintLevel(printLevel); + (*cc)->SetPrintLevel(PrintLevel); (*cc)->Print(os); } } @@ -83,17 +84,16 @@ void gdcmDicomDirPatient::Print(std::ostream &os) * \brief adds a new Patient at the begining of the PatientList * of a partially created DICOMDIR */ -gdcmDicomDirStudy * gdcmDicomDirPatient::NewStudy(void) { - std::list elemList; - elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements(); +gdcmDicomDirStudy * gdcmDicomDirPatient::NewStudy() +{ + std::list elemList = + gdcmGlobal::GetDicomDirElements()->GetDicomDirStudyElements(); - gdcmDicomDirStudy *st = new gdcmDicomDirStudy( ptagHT); + gdcmDicomDirStudy *st = new gdcmDicomDirStudy( PtagHT ); st->FillObject(elemList); studies.push_front(st); return st; - - } //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 0b62c553..146d1c06 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/07/21 14:02:10 $ - Version: $Revision: 1.11 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -48,7 +48,9 @@ gdcmDicomDirSerie::gdcmDicomDirSerie(TagDocEntryHT *ptagHT): */ gdcmDicomDirSerie::~gdcmDicomDirSerie() { - for(ListDicomDirImage::iterator cc = images.begin();cc != images.end();++cc) + for(ListDicomDirImage::iterator cc = images.begin(); + cc != images.end(); + ++cc) { delete *cc; } @@ -62,12 +64,14 @@ gdcmDicomDirSerie::~gdcmDicomDirSerie() */ void gdcmDicomDirSerie::Print(std::ostream &os) { - os<<"SERIE"<SetPrintLevel(printLevel); + (*cc)->SetPrintLevel(PrintLevel); (*cc)->Print(os); } } @@ -77,13 +81,15 @@ void gdcmDicomDirSerie::Print(std::ostream &os) /** * \brief adds a new Image (with the basic elements) to a partially created DICOMDIR */ -gdcmDicomDirImage * gdcmDicomDirSerie::NewImage(void) { - std::list elemList; - elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements(); - - gdcmDicomDirImage *st = new gdcmDicomDirImage(ptagHT); +gdcmDicomDirImage * gdcmDicomDirSerie::NewImage() +{ + std::list elemList = + gdcmGlobal::GetDicomDirElements()->GetDicomDirImageElements(); + + gdcmDicomDirImage *st = new gdcmDicomDirImage(PtagHT); FillObject(elemList); images.push_front(st); + return st; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index 3dffdb3a..ca551f16 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/06/20 18:08:47 $ - Version: $Revision: 1.7 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -68,9 +68,11 @@ void gdcmDicomDirStudy::Print(std::ostream &os) os<<"STUDY"<SetPrintLevel(printLevel); + (*cc)->SetPrintLevel(PrintLevel); (*cc)->Print(os); } } @@ -83,14 +85,15 @@ void gdcmDicomDirStudy::Print(std::ostream &os) * \brief adds a new Serie at the begining of the SerieList * of a partially created DICOMDIR */ -gdcmDicomDirSerie * gdcmDicomDirStudy::NewSerie(void) { - - std::list elemList; - elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements(); +gdcmDicomDirSerie * gdcmDicomDirStudy::NewSerie() +{ + std::list elemList = + gdcmGlobal::GetDicomDirElements()->GetDicomDirSerieElements(); - gdcmDicomDirSerie *st = new gdcmDicomDirSerie(ptagHT); + gdcmDicomDirSerie *st = new gdcmDicomDirSerie(PtagHT); FillObject(elemList); series.push_front(st); + return st; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index c26768c0..6d8e10b0 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.cxx,v $ Language: C++ - Date: $Date: 2004/07/02 13:55:27 $ - Version: $Revision: 1.32 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -28,7 +28,7 @@ * \brief The Dictionnary Set obtained with this constructor simply * contains the Default Public dictionnary. */ -gdcmDictSet::gdcmDictSet(void) +gdcmDictSet::gdcmDictSet() { DictPath = BuildDictPath(); std::string PubDictFile(DictPath); diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index b9d57a9d..960296d6 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.h,v $ Language: C++ - Date: $Date: 2004/07/02 13:55:27 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -35,7 +35,8 @@ typedef std::map DictSetHT; * \par having many in memory representations of the same dictionary * (saving memory). */ -class GDCM_EXPORT gdcmDictSet { +class GDCM_EXPORT gdcmDictSet +{ public: // TODO Swig int LoadDictFromFile(std::string filename); // QUESTION: the following function might not be thread safe !? Maybe @@ -44,26 +45,26 @@ public: // TODO Swig int LoadDictFromName(std::string filename); // TODO Swig int LoadAllDictFromDirectory(std::string DirectoryName); // TODO Swig std::string* GetAllDictNames(); - gdcmDictSet(void); - ~gdcmDictSet(void); + gdcmDictSet(); + ~gdcmDictSet(); void Print(std::ostream& os); - std::list *GetPubDictEntryNames(void); + std::list *GetPubDictEntryNames(); std::map > * - GetPubDictEntryNamesByCategory(void); + GetPubDictEntryNamesByCategory(); gdcmDict *LoadDictFromFile(std::string FileName, DictKey Name); gdcmDict *GetDict(DictKey DictName); - gdcmDict *GetDefaultPubDict(void); + gdcmDict *GetDefaultPubDict(); gdcmDictEntry *NewVirtualDictEntry(uint16_t group, uint16_t element, std::string vr = "Unknown", std::string fourth = "Unknown", std::string name = "Unknown"); - static std::string BuildDictPath(void); + static std::string BuildDictPath(); protected: bool AppendDict(gdcmDict *NewDict,DictKey Name); diff --git a/src/gdcmDirList.cxx b/src/gdcmDirList.cxx index 71c09f24..d76015df 100644 --- a/src/gdcmDirList.cxx +++ b/src/gdcmDirList.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDirList.cxx,v $ Language: C++ - Date: $Date: 2004/07/26 19:36:56 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -107,7 +107,7 @@ int gdcmDirList::Explore(std::string dirName, bool recursive) } else { - this->push_back(dirName+fileName); + push_back(dirName+fileName); numberOfFiles++; } @@ -137,7 +137,7 @@ int gdcmDirList::Explore(std::string dirName, bool recursive) stat(fileName.c_str(), &buf); //really discard output ? if( S_ISREG(buf.st_mode) ) //is it a regular file? { - this->push_back( fileName ); + push_back( fileName ); numberOfFiles++; } else if( S_ISDIR(buf.st_mode) ) //directory? diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 5b1a9f3b..cd53a4b0 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2004/07/02 13:55:27 $ - Version: $Revision: 1.13 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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,7 +33,8 @@ * \brief Constructor from a given gdcmDictEntry * @param in Pointer to existing dictionary entry */ -gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) { +gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) +{ ImplicitVR = false; entry = in; } @@ -45,8 +46,8 @@ gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) { * \brief Prints the common part of gdcmValEntry, gdcmBinEntry, gdcmSeqEntry * @param os ostream we want to print in */ -void gdcmDocEntry::Print(std::ostream & os) { - +void gdcmDocEntry::Print(std::ostream & os) +{ printLevel=2; // FIXME size_t o; @@ -65,17 +66,21 @@ void gdcmDocEntry::Print(std::ostream & os) { sprintf(greltag,"%04x|%04x ",g,e); s << greltag ; - if (printLevel>=2) { + if (printLevel>=2) + { s << "lg : "; lgth = GetReadLength(); // ReadLength, as opposed to UsableLength - if (lgth == 0xffffffff) { + if (lgth == 0xffffffff) + { sprintf(st,"x(ffff)"); // I said : "x(ffff)" ! s.setf(std::ios::left); s << std::setw(10-strlen(st)) << " "; s << st << " "; s.setf(std::ios::left); s << std::setw(8) << "-1"; - } else { + } + else + { sprintf(st,"x(%x)",lgth); s.setf(std::ios::left); s << std::setw(10-strlen(st)) << " "; @@ -92,7 +97,8 @@ void gdcmDocEntry::Print(std::ostream & os) { s << "[" << vr << "] "; - if (printLevel>=1) { + if (printLevel >= 1) + { s.setf(std::ios::left); s << std::setw(66-GetName().length()) << " "; } @@ -105,19 +111,21 @@ void gdcmDocEntry::Print(std::ostream & os) { * \ingroup gdcmDocEntry * \brief Writes the common part of any gdcmValEntry, gdcmBinEntry, gdcmSeqEntry */ -void gdcmDocEntry::Write(FILE *fp, FileType filetype) { - +void gdcmDocEntry::Write(FILE *fp, FileType filetype) +{ uint32_t FFFF = 0xffffffff; uint16_t group = GetGroup(); gdcmVRKey vr = GetVR(); uint16_t el = GetElement(); uint32_t lgr = GetReadLength(); - if ( (group == 0xfffe) && (el == 0x0000) ) + if ( (group == 0xfffe) && (el == 0x0000) ) + { // Fix in order to make some MR PHILIPS images e-film readable // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm: // we just *always* ignore spurious fffe|0000 tag ! - return; + return; + } // // ----------- Writes the common part @@ -125,10 +133,11 @@ void gdcmDocEntry::Write(FILE *fp, FileType filetype) { fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element - if ( filetype == gdcmExplicitVR ) { - + if ( filetype == gdcmExplicitVR ) + { // Special case of delimiters: - if (group == 0xfffe) { + if (group == 0xfffe) + { // Delimiters have NO Value Representation // Hence we skip writing the VR. // In order to avoid further troubles, we choose to write them @@ -139,44 +148,56 @@ void gdcmDocEntry::Write(FILE *fp, FileType filetype) { // TODO : verify if the Sequence Delimitor Item was forced during Parsing - int ff=0xffffffff; + int ff = 0xffffffff; fwrite (&ff,(size_t)4 ,(size_t)1 ,fp); return; } - uint16_t z=0; + uint16_t z = 0; uint16_t shortLgr = lgr; - if (vr == "unkn") { // Unknown was 'written' + if (vr == "unkn") + { + // Unknown was 'written' // deal with Little Endian fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp); fwrite ( &z, (size_t)2 ,(size_t)1 ,fp); - } else { + } + else + { fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp); if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") ) { fwrite ( &z, (size_t)2 ,(size_t)1 ,fp); - if (vr == "SQ") { - // we set SQ length to ffffffff - // and we shall write a Sequence Delimitor Item - // at the end of the Sequence! + if (vr == "SQ") + { + // we set SQ length to ffffffff + // and we shall write a Sequence Delimitor Item + // at the end of the Sequence! fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp); - } else { + } + else + { fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp); } - } else { + } + else + { fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp); } } } else // IMPLICIT VR { - if (vr == "SQ") { - fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp); - } else { - fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp); - } + if (vr == "SQ") + { + fwrite ( &FFFF,(size_t)4 ,(size_t)1 ,fp); + } + else + { + fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp); + } } } @@ -187,30 +208,39 @@ void gdcmDocEntry::Write(FILE *fp, FileType filetype) { * \ingroup gdcmDocEntry * \brief Gets the full length of the elementary DocEntry (not only value length) */ -uint32_t gdcmDocEntry::GetFullLength(void) { - uint32_t l; - l = GetReadLength(); - if ( IsImplicitVR() ) +uint32_t gdcmDocEntry::GetFullLength() +{ + uint32_t l = GetReadLength(); + if ( IsImplicitVR() ) + { l = l + 8; // 2 (gr) + 2 (el) + 4 (lgth) - else + } + else + { if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" ) + { l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth) + } else + { l = l + 8; // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth) - return(l); + } + } + return l; } /** * \ingroup gdcmDocEntry * \brief Copies all the attributes from an other DocEntry */ -void gdcmDocEntry::Copy (gdcmDocEntry* e) { - this->entry = e->entry; - this->UsableLength = e->UsableLength; - this->ReadLength = e->ReadLength; - this->ImplicitVR = e->ImplicitVR; - this->Offset = e->Offset; - this->printLevel = e->printLevel; +void gdcmDocEntry::Copy (gdcmDocEntry* e) +{ + entry = e->entry; + UsableLength = e->UsableLength; + ReadLength = e->ReadLength; + ImplicitVR = e->ImplicitVR; + Offset = e->Offset; + printLevel = e->printLevel; // TODO : remove gdcmDocEntry SQDepth } @@ -219,22 +249,18 @@ void gdcmDocEntry::Copy (gdcmDocEntry* e) { * \brief tells us if entry is the last one of a 'no length' SequenceItem * (fffe,e00d) */ -bool gdcmDocEntry::isItemDelimitor() { - if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) ) - return true; - else - return false; +bool gdcmDocEntry::isItemDelimitor() +{ + return (GetGroup() == 0xfffe && GetElement() == 0xe00d); } /** * \ingroup gdcmDocEntry * \brief tells us if entry is the last one of a 'no length' Sequence * (fffe,e0dd) */ -bool gdcmDocEntry::isSequenceDelimitor() { - if (GetGroup() == 0xfffe && GetElement() == 0xe0dd) - return true; - else - return false; +bool gdcmDocEntry::isSequenceDelimitor() +{ + return (GetGroup() == 0xfffe && GetElement() == 0xe0dd); } //----------------------------------------------------------------------------- diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index 5792c641..9f7a59a6 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.h,v $ Language: C++ - Date: $Date: 2004/07/31 18:43:43 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -39,7 +39,7 @@ class GDCM_EXPORT gdcmDocEntry { public: gdcmDocEntry(gdcmDictEntry*); - + /// Returns the Dicom Group number of the current Dicom Header Entry uint16_t GetGroup() { return entry->GetGroup(); }; @@ -120,7 +120,7 @@ public: void SetPrintLevel(int level) { printLevel = level; }; /// \brief Gets the print level for the Dicom Header Elements - int GetPrintLevel() { return(printLevel); }; + int GetPrintLevel() { return printLevel; }; virtual void Print (std::ostream & os = std::cout); virtual void Write(FILE *fp, FileType filetype); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index af9d840d..499accac 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/07/31 23:30:04 $ - Version: $Revision: 1.61 $ + Date: $Date: 2004/08/01 00:59:21 $ + Version: $Revision: 1.62 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -2763,7 +2763,7 @@ void gdcmDocument::Parse7FE0 () bool gdcmDocument::operator<(gdcmDocument &document) { // Patient Name - std::string s1 = this->GetEntryByNumber(0x0010,0x0010); + std::string s1 = GetEntryByNumber(0x0010,0x0010); std::string s2 = document.GetEntryByNumber(0x0010,0x0010); if(s1 < s2) { @@ -2776,7 +2776,7 @@ bool gdcmDocument::operator<(gdcmDocument &document) else { // Patient ID - s1 = this->GetEntryByNumber(0x0010,0x0020); + s1 = GetEntryByNumber(0x0010,0x0020); s2 = document.GetEntryByNumber(0x0010,0x0020); if ( s1 < s2 ) { @@ -2789,7 +2789,7 @@ bool gdcmDocument::operator<(gdcmDocument &document) else { // Study Instance UID - s1 = this->GetEntryByNumber(0x0020,0x000d); + s1 = GetEntryByNumber(0x0020,0x000d); s2 = document.GetEntryByNumber(0x0020,0x000d); if ( s1 < s2 ) { @@ -2802,7 +2802,7 @@ bool gdcmDocument::operator<(gdcmDocument &document) else { // Serie Instance UID - s1 = this->GetEntryByNumber(0x0020,0x000e); + s1 = GetEntryByNumber(0x0020,0x000e); s2 = document.GetEntryByNumber(0x0020,0x000e); if ( s1 < s2 ) { diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index 164254ef..c8d6c43e 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeaderHelper.cxx,v $ Language: C++ - Date: $Date: 2004/06/25 20:48:25 $ - Version: $Revision: 1.40 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -55,7 +55,7 @@ gdcmSerieHeader::~gdcmSerieHeader() void gdcmSerieHeader::AddFileName(std::string const & filename) { gdcmHeader *header = new gdcmHeader( filename ); - this->CoherentGdcmFileList.push_back( header ); + CoherentGdcmFileList.push_back( header ); } /** @@ -64,7 +64,7 @@ void gdcmSerieHeader::AddFileName(std::string const & filename) */ void gdcmSerieHeader::AddGdcmFile(gdcmHeader *file) { - this->CoherentGdcmFileList.push_back( file ); + CoherentGdcmFileList.push_back( file ); } /** @@ -80,7 +80,7 @@ void gdcmSerieHeader::SetDirectory(std::string const & dir) { //use string and not const char*: gdcmHeader *header = new gdcmHeader( *it ); - this->CoherentGdcmFileList.push_back( header ); + CoherentGdcmFileList.push_back( header ); } } diff --git a/src/gdcmObject.cxx b/src/gdcmObject.cxx index 953131b2..d5f2848f 100644 --- a/src/gdcmObject.cxx +++ b/src/gdcmObject.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmObject.cxx,v $ Language: C++ - Date: $Date: 2004/07/21 14:02:10 $ - Version: $Revision: 1.23 $ + Date: $Date: 2004/08/01 00:59:21 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,8 +32,9 @@ */ gdcmObject::gdcmObject(TagDocEntryHT *ptagHT, int depth) - : gdcmSQItem (depth) { - this->ptagHT = ptagHT; + : gdcmSQItem (depth) +{ + PtagHT = ptagHT; } @@ -41,7 +42,8 @@ gdcmObject::gdcmObject(TagDocEntryHT *ptagHT, int depth) * \ingroup gdcmObject * \brief Canonical destructor. */ -gdcmObject::~gdcmObject(void) { +gdcmObject::~gdcmObject() +{ } @@ -57,13 +59,16 @@ gdcmObject::~gdcmObject(void) { * related to this 'object' * @return */ -TagDocEntryHT gdcmObject::GetEntry(void) { +TagDocEntryHT gdcmObject::GetEntry() +{ TagDocEntryHT HT; docEntries=GetDocEntries(); - for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) { + for(ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); ++i) + { HT[(*i)->GetKey()]=*i; } - return(HT); + return HT; } //----------------------------------------------------------------------------- @@ -72,8 +77,8 @@ TagDocEntryHT gdcmObject::GetEntry(void) { * \brief add the 'Object' related Dicom Elements to the listEntries * of a partially created DICOMDIR */ -void gdcmObject::FillObject(std::list elemList) { - +void gdcmObject::FillObject(std::list elemList) +{ // FillObject rempli le SQItem qui sera accroche au bon endroit std::list::iterator it; @@ -82,12 +87,12 @@ void gdcmObject::FillObject(std::list elemList) { gdcmValEntry *entry; // for all the Elements found in they own part of the DicomDir dict. - for(it=elemList.begin();it!=elemList.end();++it) + for(it = elemList.begin(); it != elemList.end(); ++it) { - tmpGr=it->group; - tmpEl=it->elem; - dictEntry=gdcmGlobal::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl); - entry=new gdcmValEntry(dictEntry); + tmpGr = it->group; + tmpEl = it->elem; + dictEntry = gdcmGlobal::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl); + entry = new gdcmValEntry(dictEntry); entry->SetOffset(0); // just to avoid further missprinting entry->SetValue(it->value); @@ -97,15 +102,15 @@ void gdcmObject::FillObject(std::list elemList) { { entry->SetLength(entry->GetValue().length()); } - else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) + else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" ) { entry->SetLength(4); } - else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") ) + else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" ) { entry->SetLength(2); } - else if(dictEntry->GetVR()=="SQ") + else if( dictEntry->GetVR() == "SQ" ) { entry->SetLength(0xffffffff); } diff --git a/src/gdcmObject.h b/src/gdcmObject.h index 92a10313..2f4317fa 100644 --- a/src/gdcmObject.h +++ b/src/gdcmObject.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmObject.h,v $ Language: C++ - Date: $Date: 2004/06/20 18:08:48 $ - Version: $Revision: 1.17 $ + Date: $Date: 2004/08/01 00:59:21 $ + Version: $Revision: 1.18 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -39,15 +39,13 @@ typedef std::list ListContent; class GDCM_EXPORT gdcmObject : public gdcmSQItem { public: - /** * \brief Sets the print level for the Dicom Header * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy */ - void SetPrintLevel(int level) - { printLevel = level; }; + void SetPrintLevel(int level) { PrintLevel = level; }; - TagDocEntryHT GetEntry(void); + TagDocEntryHT GetEntry(); void FillObject(std::list elemList); protected: @@ -55,13 +53,11 @@ protected: // Constructor and destructor are protected to avoid end user to // instanciate from this class. gdcmObject(TagDocEntryHT *ptagHT, int depth = 0); - virtual ~gdcmObject(void); + virtual ~gdcmObject(); // Members : ///\brief detail level to be printed - int printLevel; - -private: + int PrintLevel; }; //----------------------------------------------------------------------------- diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index d34f7a9d..cdd330d0 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/07/17 22:47:01 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/08/01 00:59:21 $ + 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 @@ -33,7 +33,8 @@ * \brief Constructor from a given gdcmSQItem */ gdcmSQItem::gdcmSQItem(int depthLevel ) - : gdcmDocEntrySet(depthLevel) { + : gdcmDocEntrySet(depthLevel) +{ SQDepthLevel = depthLevel +1; } @@ -56,16 +57,19 @@ gdcmSQItem::~gdcmSQItem() /* * \brief canonical Printer */ - void gdcmSQItem::Print(std::ostream & os) { + void gdcmSQItem::Print(std::ostream & os) + { std::ostringstream s; - if (SQDepthLevel>0) + if (SQDepthLevel > 0) { - for (int i=0;iisItemDelimitor() ) + { break; + } // Fix in order to make some MR PHILIPS images e-film readable // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm: // we just *always* ignore spurious fffe|0000 tag ! - if ( ((*i)->GetGroup() == 0xfffe) && ((*i)->GetElement() == 0x0000) ) - break; + if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0x0000 ) + { + break; + } // It's up to the gdcmDocEntry Writter to write the SQItem begin element // (fffe|e000) as a 'no length' one @@ -142,57 +152,67 @@ bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) bool gdcmSQItem::SetEntryByNumber(std::string val,uint16_t group, uint16_t element) { - for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) + for(ListDocEntry::iterator i = docEntries.begin(); i != docEntries.end(); ++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 gdcmDocument :-( - gdcmValEntry* Entry = (gdcmValEntry*)0; + gdcmValEntry* entry = 0; gdcmTagKey key = gdcmDictEntry::TranslateToKey(group, element); - if ( ! ptagHT->count(key)) + if ( ! PtagHT->count(key)) { // we assume a Public Dictionnary *is* loaded - gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); + gdcmDict *pubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); // if the invoked (group,elem) doesn't exist inside the Dictionary // we create a VirtualDictEntry - gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, + gdcmDictEntry *dictEntry = pubDict->GetDictEntryByNumber(group, element); - if (DictEntry == NULL) + if (dictEntry == NULL) { - DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group, - element, - "UN", - "??","??"); + dictEntry = + gdcmGlobal::GetDicts()->NewVirtualDictEntry(group, element, + "UN", "??", "??"); } // we assume the constructor didn't fail - Entry = new gdcmValEntry(DictEntry); + entry = new gdcmValEntry(dictEntry); /// \todo /// ---- /// better we don't assume too much ! /// gdcmSQItem is now used to describe any DICOMDIR related object - } else { - gdcmDocEntry* FoundEntry = ptagHT->find(key)->second; - Entry = dynamic_cast(FoundEntry); - if (!Entry) + } + else + { + gdcmDocEntry* foundEntry = PtagHT->find(key)->second; + entry = dynamic_cast(foundEntry); + if (!entry) + { dbg.Verbose(0, "gdcmSQItem::SetEntryByNumber: docEntries" " contains non gdcmValEntry occurences"); + } } - if (Entry) - Entry->SetValue(val); - Entry->SetLength(val.length()); - docEntries.insert(i,Entry); + if (entry) + { + entry->SetValue(val); + } + entry->SetLength(val.length()); + docEntries.insert(i,entry); + return true; } if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) { - if ( gdcmValEntry* Entry = dynamic_cast(*i) ) - Entry->SetValue(val); + if ( gdcmValEntry* entry = dynamic_cast(*i) ) + { + entry->SetValue(val); + } (*i)->SetLength(val.length()); return true; } @@ -209,14 +229,15 @@ bool gdcmSQItem::SetEntryByNumber(std::string val,uint16_t group, */ gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(uint16_t group, uint16_t element) { - for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) + for(ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); ++i) { - if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) + if ( (*i)->GetGroup() == group && (*i)->GetElement() == element ) { - return (*i); + return *i; } - } - return NULL; + } + return 0; } /** @@ -225,14 +246,15 @@ gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(uint16_t group, uint16_t element) */ std::string gdcmSQItem::GetEntryByNumber(uint16_t group, uint16_t element) -{ - for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) +{ + for(ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); ++i) { - if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) + if ( (*i)->GetGroup() == group && (*i)->GetElement() == element) { - return ((gdcmValEntry *)(*i))->GetValue(); + return ((gdcmValEntry *)(*i))->GetValue(); //FIXME } - } + } return GDCM_UNFOUND; } //----------------------------------------------------------------------------- diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index fe7f7938..540e2538 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/07/19 11:51:26 $ - Version: $Revision: 1.12 $ + Date: $Date: 2004/08/01 00:59:22 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,7 +33,7 @@ class GDCM_EXPORT gdcmSQItem : public gdcmDocEntrySet { public: gdcmSQItem(int); - ~gdcmSQItem(void); + ~gdcmSQItem(); virtual void Print(std::ostream &os = std::cout); virtual void Write(FILE *fp, FileType filetype); @@ -57,7 +57,7 @@ public: int GetSQItemNumber() { return SQItemNumber; }; - void SetSQItemNumber(int itemNumber) { SQItemNumber=itemNumber; }; + void SetSQItemNumber(int itemNumber) { SQItemNumber = itemNumber; }; protected: @@ -71,7 +71,7 @@ protected: ///\brief pointer to the HTable of the gdcmDocument, /// (because we don't know it within any gdcmObject nor any gdcmSQItem) - TagDocEntryHT *ptagHT; + TagDocEntryHT *PtagHT; private: diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index 36bdca4f..2ab55cbf 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2004/07/20 08:29:13 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/08/01 00:59:22 $ + 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 @@ -41,27 +41,29 @@ gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) */ gdcmValEntry::gdcmValEntry(gdcmDocEntry* e) : gdcmDocEntry(e->GetDictEntry()) { - this->UsableLength = e->GetLength(); - this->ReadLength = e->GetReadLength(); - this->ImplicitVR = e->IsImplicitVR(); - this->Offset = e->GetOffset(); - this->printLevel = e->GetPrintLevel(); - this->SQDepthLevel = e->GetDepthLevel(); + UsableLength = e->GetLength(); + ReadLength = e->GetReadLength(); + ImplicitVR = e->IsImplicitVR(); + Offset = e->GetOffset(); + printLevel = e->GetPrintLevel(); + SQDepthLevel = e->GetDepthLevel(); - this->voidArea = NULL; // will be in BinEntry ? + voidArea = NULL; // will be in BinEntry ? } /** * \brief Canonical destructor. */ -gdcmValEntry::~gdcmValEntry (void) +gdcmValEntry::~gdcmValEntry () { if (!voidArea) // will be in BinEntry + { free(voidArea); + voidArea = NULL; // let's be carefull ! + } } - //----------------------------------------------------------------------------- // Print /** @@ -101,27 +103,50 @@ void gdcmValEntry::Print(std::ostream & os) // Display the UID value (instead of displaying only the rough code) // First 'clean' trailing character (space or zero) - if (g == 0x0002) { // Any more to be displayed ? - if ( (e == 0x0010) || (e == 0x0002) ) { + if (g == 0x0002) + { + // Any more to be displayed ? + if ( (e == 0x0010) || (e == 0x0002) ) + { if ( v.length() != 0 ) // for brain damaged headers + { if ( ! isdigit(v[v.length()-1]) ) + { v.erase(v.length()-1, 1); + } + } s << " ==>\t[" << ts->GetValue(v) << "]"; } - } else { - if (g == 0x0008) { - if ( (e == 0x0016) || (e == 0x1150) ) { + } + else + { + if (g == 0x0008) + { + if ( e == 0x0016 || e == 0x1150 ) + { if ( v.length() != 0 ) // for brain damaged headers + { if ( ! isdigit(v[v.length()-1]) ) + { v.erase(v.length()-1, 1); + } + } s << " ==>\t[" << ts->GetValue(v) << "]"; } - } else { - if (g == 0x0004) { - if ( (e == 0x1510) || (e == 0x1512) ) { - if ( v.length() != 0 ) // for brain damaged headers - if ( ! isdigit(v[v.length()-1]) ) - v.erase(v.length()-1, 1); + } + else + { + if (g == 0x0004) + { + if ( (e == 0x1510) || (e == 0x1512) ) + { + if ( v.length() != 0 ) // for brain damaged headers + { + if ( ! isdigit(v[v.length()-1]) ) + { + v.erase(v.length()-1, 1); + } + } s << " ==>\t[" << ts->GetValue(v) << "]"; } } @@ -131,12 +156,19 @@ void gdcmValEntry::Print(std::ostream & os) if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) { if (v == "4294967295") // to avoid troubles in convertion + { sprintf (st," x(ffffffff)"); - else { - if ( GetLength() !=0 ) + } + else + { + if ( GetLength() !=0 ) + { sprintf(st," x(%x)", atoi(v.c_str()));//FIXME - else - sprintf(st," "); + } + else + { + sprintf(st," "); + } } s << st; } @@ -149,8 +181,8 @@ void gdcmValEntry::Print(std::ostream & os) void gdcmValEntry::Write(FILE *fp, FileType filetype) { gdcmDocEntry::Write(fp, filetype); - std::string vr=GetVR(); - int lgr=GetReadLength(); + std::string vr = GetVR(); + int lgr = GetReadLength(); if (vr == "US" || vr == "SS") { // some 'Short integer' fields may be mulivaluated @@ -159,7 +191,8 @@ void gdcmValEntry::Write(FILE *fp, FileType filetype) std::vector tokens; tokens.erase(tokens.begin(),tokens.end()); // clean any previous value Tokenize (GetValue(), tokens, "\\"); - for (unsigned int i=0; i tokens; tokens.erase(tokens.begin(),tokens.end()); // clean any previous value Tokenize (GetValue(), tokens, "\\"); - for (unsigned int i=0; i