From 76f7307f9485e39bba565423a91989f8c9c18c21 Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 22 Jan 2004 10:17:17 +0000 Subject: [PATCH] DICOMDIR utilities --- src/Makefile.am | 1 + src/gdcmHeaderHelper.cxx | 3 ++- src/gdcmHeaderHelper.h | 2 +- src/gdcmImage.cxx | 11 --------- src/gdcmImage.h | 4 ---- src/gdcmObject.h | 24 +++++++------------ src/gdcmParser.cxx | 51 +++++++++++++++++++++++----------------- src/gdcmParser.h | 5 ++-- src/gdcmPatient.cxx | 17 ++++---------- src/gdcmPatient.h | 11 ++++----- src/gdcmSerie.cxx | 17 ++++---------- src/gdcmSerie.h | 12 ++++------ src/gdcmStudy.cxx | 18 ++++---------- src/gdcmStudy.h | 12 ++++------ src/gdcmTS.cxx | 3 +++ 15 files changed, 77 insertions(+), 114 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 4ce15447..9a2cb239 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ libgdcm_la_SOURCES= \ gdcmRLE.cxx \ gdcmParsePixels.cxx \ gdcmDICOMDIR.cxx \ + gdcmObject.cxx \ gdcmPatient.cxx \ gdcmStudy.cxx \ gdcmSerie.cxx \ diff --git a/src/gdcmHeaderHelper.cxx b/src/gdcmHeaderHelper.cxx index aeb83222..22ad729e 100644 --- a/src/gdcmHeaderHelper.cxx +++ b/src/gdcmHeaderHelper.cxx @@ -768,6 +768,7 @@ bool gdcmSerieHeaderHelper::ImagePositionPatientOrdering() } //Based on Image Number + bool gdcmSerieHeaderHelper::ImageNumberOrdering() { int min, max, pos; @@ -800,7 +801,7 @@ bool gdcmSerieHeaderHelper::ImageNumberOrdering() partition[pos - min]++; } - unsigned char mult; + unsigned char mult = 1; for(int i=0; i GetXOrigin in order not to confused reader + * change GetXImagePosition -> GetXOrigin in order not to confuse reader * -# GetXOrigin can return default value (=0) if it was not ImagePosition * -# Image Position is different in dicomV3 <> ACR NEMA -> better use generic * name diff --git a/src/gdcmImage.cxx b/src/gdcmImage.cxx index 245a6a46..382a7470 100644 --- a/src/gdcmImage.cxx +++ b/src/gdcmImage.cxx @@ -11,14 +11,3 @@ gdcmImage::~gdcmImage() { } - - -std::string gdcmImage::GetEntryByNumber(guint16 group, guint16 element) { - return ""; -} - - -std::string gdcmImage::GetEntryByName(TagName name) { - return ""; -} - diff --git a/src/gdcmImage.h b/src/gdcmImage.h index 5b75aaec..0c138ffa 100644 --- a/src/gdcmImage.h +++ b/src/gdcmImage.h @@ -16,10 +16,6 @@ public: gdcmImage(); ~gdcmImage(); - std::string GetEntryByNumber(guint16 group, guint16 element); - std::string GetEntryByName(TagName name); - - }; //----------------------------------------------------------------------------- diff --git a/src/gdcmObject.h b/src/gdcmObject.h index f2f65c06..77c2aab1 100644 --- a/src/gdcmObject.h +++ b/src/gdcmObject.h @@ -6,29 +6,23 @@ #include #include #include "gdcmCommon.h" - +#include "gdcmHeaderEntry.h" +#include "gdcmParser.h" //----------------------------------------------------------------------------- - -typedef std::list lstring; +class gdcmObject; +typedef std::list ListContent; //----------------------------------------------------------------------------- - class gdcmObject { public: + std::string GetEntryByNumber(guint16 group, guint16 element); + std::string GetEntryByName(TagName name); - virtual std::string GetEntryByNumber(guint16 group, guint16 element)=0; - virtual std::string GetEntryByName(TagName name)=0; - + ListTag::iterator beginObj; + ListTag::iterator endObj; + protected: - - //to modify (I don't know the list type) : both iterators (beginning and end) - lstring::iterator beginIter; - lstring::iterator endIter; - - //pointer to the data list - lstring *objectData; - }; //----------------------------------------------------------------------------- diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 362ca03f..d987a847 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -52,12 +52,14 @@ gdcmParser::gdcmParser(const char *InFilename, if ( !OpenFile(exception_on_error)) return; + Parse(); LoadHeaderEntries(); + CloseFile(); wasUpdated = 0; // will be set to 1 if user adds an entry - printLevel = 1; // 'Heavy' header print by default + printLevel = 1; // 'Medium' header print by default } /** @@ -67,7 +69,7 @@ gdcmParser::gdcmParser(const char *InFilename, */ gdcmParser::gdcmParser(bool exception_on_error) { - enableSequences=0; + //enableSequences=0; SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); Initialise(); @@ -98,7 +100,7 @@ void gdcmParser::PrintEntry(std::ostream & os) { std::ostringstream s; - s << "------------ using listEntries ----------------" << std::endl; + s << "------------ gdcmParser::Print, using listEntries ----------------" << std::endl; for (ListTag::iterator i = listEntries.begin(); i != listEntries.end(); ++i) @@ -121,7 +123,7 @@ void gdcmParser::PrintPubDict(std::ostream & os) /** * \ingroup gdcmParser - * \brief Prints The Dict Entries of THE shadow Dicom Dictionnry + * \brief Prints The Dict Entries of the current shadow Dicom Dictionnry * @return */ void gdcmParser::PrintShaDict(std::ostream & os) @@ -133,7 +135,7 @@ void gdcmParser::PrintShaDict(std::ostream & os) // Public /** * \ingroup gdcmParser - * \brief Get the public dictionary used + * \brief Get THE public dictionary used */ gdcmDict *gdcmParser::GetPubDict(void) { @@ -142,7 +144,7 @@ gdcmDict *gdcmParser::GetPubDict(void) /** * \ingroup gdcmParser - * \brief Get the shadow dictionary used + * \brief Get the current shadow dictionary */ gdcmDict *gdcmParser::GetShaDict(void) { @@ -165,8 +167,7 @@ bool gdcmParser::SetShaDict(gdcmDict *dict) * \brief Set the shadow dictionary used * \param dictName name of the dictionary to use in shadow */ -bool gdcmParser::SetShaDict(DictKey dictName) -{ +bool gdcmParser::SetShaDict(DictKey dictName) { RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName); return(!RefShaDict); } @@ -183,19 +184,27 @@ bool gdcmParser::SetShaDict(DictKey dictName) bool gdcmParser::IsReadable(void) { std::string res = GetEntryByNumber(0x0028, 0x0005); - if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) - { + if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) { + //std::cout << "error on : 28 5" << std::endl; return false; // Image Dimensions } - if ( !GetHeaderEntryByNumber(0x0028, 0x0100) ) + if ( !GetHeaderEntryByNumber(0x0028, 0x0100) ) { + //std::cout << "error on : 28 100" << std::endl; return false; // "Bits Allocated" - if ( !GetHeaderEntryByNumber(0x0028, 0x0101) ) + } + if ( !GetHeaderEntryByNumber(0x0028, 0x0101) ){ + // std::cout << "error on : 28 101" << std::endl; return false; // "Bits Stored" - if ( !GetHeaderEntryByNumber(0x0028, 0x0102) ) + } + if ( !GetHeaderEntryByNumber(0x0028, 0x0102) ) { + //std::cout << "error on : 28 102" << std::endl; return false; // "High Bit" - if ( !GetHeaderEntryByNumber(0x0028, 0x0103) ) + } + if ( !GetHeaderEntryByNumber(0x0028, 0x0103) ) { + //std::cout << "error on : 28 103" << std::endl; return false; // "Pixel Representation" + } return true; } @@ -206,8 +215,7 @@ bool gdcmParser::IsReadable(void) * * @return True when ImplicitVRLittleEndian found. False in all other cases. */ -bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void) -{ +bool gdcmParser::IsImplicitVRLittleEndianTransferSyntax(void) { gdcmHeaderEntry *Element = GetHeaderEntryByNumber(0x0002, 0x0010); if ( !Element ) return false; @@ -490,7 +498,6 @@ int gdcmParser::CheckIfEntryExistByNumber(guint16 group, guint16 element ) * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries * for the element value of a given tag. - * \warning Don't use any longer : use GetPubEntryByName * @param tagName name of the searched element. * @return Corresponding element value when it exists, * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise. @@ -2257,11 +2264,11 @@ gdcmHeaderEntry *gdcmParser::NewHeaderEntryByName(std::string Name) /** * \ingroup gdcmParser * \brief Request a new virtual dict entry to the dict set - * @param group group of the underlying DictEntry - * @param elem element of the underlying DictEntry - * @param vr VR of the underlying DictEntry - * @param fourth owner group - * @param name english name + * @param group group of the underlying DictEntry + * @param element element of the underlying DictEntry + * @param vr VR of the underlying DictEntry + * @param fourth owner group + * @param name english name */ gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element, std::string vr, diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 2ca4a793..8e9e5af6 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -136,7 +136,8 @@ protected: static const unsigned int HEADER_LENGTH_TO_READ; static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE; - +protected: + int enableSequences; private: // Read void Parse(bool exception_on_error = false) throw(gdcmFormatError); @@ -195,7 +196,7 @@ private: TagHeaderEntryHT tagHT; // H Table (multimap), to provide fast access ListTag listEntries; // chained list, to keep the 'spacial' ordering - int enableSequences; + // true if a gdcmHeaderEntry was added post parsing int wasUpdated; diff --git a/src/gdcmPatient.cxx b/src/gdcmPatient.cxx index 4e952e40..45781881 100644 --- a/src/gdcmPatient.cxx +++ b/src/gdcmPatient.cxx @@ -8,17 +8,10 @@ gdcmPatient::gdcmPatient() { gdcmPatient::~gdcmPatient() { - -} - - - -std::string gdcmPatient::GetEntryByNumber(guint16 group, guint16 element) { - return ""; -} - - -std::string gdcmPatient::GetEntryByName(TagName name) { - return ""; + lStudy::iterator cc = GetStudies().begin(); + while (cc != GetStudies().end() ) { + delete *cc; + ++cc; + } } diff --git a/src/gdcmPatient.h b/src/gdcmPatient.h index 6640a5f8..662bca15 100644 --- a/src/gdcmPatient.h +++ b/src/gdcmPatient.h @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------- -typedef std::list lStudy; +typedef std::list lStudy; //----------------------------------------------------------------------------- @@ -18,14 +18,11 @@ public: gdcmPatient(); ~gdcmPatient(); - std::string GetEntryByNumber(guint16 group, guint16 element); - std::string GetEntryByName(TagName name); - - inline lStudy GetStudies() {return studies;}; - + inline lStudy &GetStudies() {return studies;}; + + lStudy studies; private: - lStudy studies; }; diff --git a/src/gdcmSerie.cxx b/src/gdcmSerie.cxx index 18508e72..9e4a275b 100644 --- a/src/gdcmSerie.cxx +++ b/src/gdcmSerie.cxx @@ -8,17 +8,10 @@ gdcmSerie::gdcmSerie() { gdcmSerie::~gdcmSerie() { - -} - - - -std::string gdcmSerie::GetEntryByNumber(guint16 group, guint16 element) { - return ""; -} - - -std::string gdcmSerie::GetEntryByName(TagName name) { - return ""; + lImage::iterator cc = GetImages().begin(); + while (cc != GetImages().end() ) { + delete *cc; + ++cc; + } } diff --git a/src/gdcmSerie.h b/src/gdcmSerie.h index ed73cda1..02fe496d 100644 --- a/src/gdcmSerie.h +++ b/src/gdcmSerie.h @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------- -typedef std::list lImage; +typedef std::list lImage; //----------------------------------------------------------------------------- @@ -18,14 +18,12 @@ public: gdcmSerie(); ~gdcmSerie(); - std::string GetEntryByNumber(guint16 group, guint16 element); - std::string GetEntryByName(TagName name); - - inline lImage GetImages() {return images;}; - + inline lImage &GetImages() {return images;}; + + lImage images; + private: - lImage images; }; diff --git a/src/gdcmStudy.cxx b/src/gdcmStudy.cxx index bcfb0e34..9380f519 100644 --- a/src/gdcmStudy.cxx +++ b/src/gdcmStudy.cxx @@ -8,17 +8,9 @@ gdcmStudy::gdcmStudy() { gdcmStudy::~gdcmStudy() { - -} - - - -std::string gdcmStudy::GetEntryByNumber(guint16 group, guint16 element) { - return ""; + lSerie::iterator cc = GetSeries().begin(); + while (cc != GetSeries().end() ) { + delete *cc; + ++cc; + } } - - -std::string gdcmStudy::GetEntryByName(TagName name) { - return ""; -} - diff --git a/src/gdcmStudy.h b/src/gdcmStudy.h index c595f054..f08f709f 100644 --- a/src/gdcmStudy.h +++ b/src/gdcmStudy.h @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------- -typedef std::list lSerie; +typedef std::list lSerie; //----------------------------------------------------------------------------- @@ -18,14 +18,12 @@ public: gdcmStudy(); ~gdcmStudy(); - std::string GetEntryByNumber(guint16 group, guint16 element); - std::string GetEntryByName(TagName name); - - inline lSerie GetSeries() {return series;}; - + inline lSerie &GetSeries() {return series;}; + + lSerie series; + private: - lSerie series; }; diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index 531c4ee7..7445b59c 100644 --- a/src/gdcmTS.cxx +++ b/src/gdcmTS.cxx @@ -34,6 +34,9 @@ gdcmTS::gdcmTS(void) eatwhite(from); from.getline(buff, 1024, ' '); key = buff; + if(key.size()%2==1) + key.push_back(0); + eatwhite(from); from.getline(buff, 1024, '\n'); name = buff; -- 2.46.1