From 8d4184fc7129f85d9ec384a3c7b9c5928a1f5b5e Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 28 Jan 2004 17:45:35 +0000 Subject: [PATCH] upgrade GdcmHeaderEntry Print Method for DICOMDIR --- src/gdcmDicomDir.cxx | 20 ++++++++++++++++++++ src/gdcmDicomDir.h | 2 ++ src/gdcmHeader.cxx | 24 +++++++++++------------- src/gdcmHeader.h | 19 +++++++++++-------- src/gdcmHeaderEntry.cxx | 5 +++++ src/gdcmParser.h | 20 ++++++++++---------- 6 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index f14f63e2..a3441303 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -10,6 +10,13 @@ //----------------------------------------------------------------------------- // Constructor / Destructor + +/* + * \ingroup gdcmDicomDir + * \brief + * @param Filename + * @param exception_on_error + */ gdcmDicomDir::gdcmDicomDir(std::string & FileName, bool exception_on_error): gdcmParser(FileName.c_str(),exception_on_error, true ) @@ -23,6 +30,19 @@ gdcmDicomDir::gdcmDicomDir(std::string & FileName, } +/* + * \ingroup gdcmDicomDir + * \brief + * @param exception_on_error + */ +gdcmDicomDir::gdcmDicomDir(bool exception_on_error): + gdcmParser(exception_on_error ) +{ + +} + + + gdcmDicomDir::~gdcmDicomDir() { for(ListPatient::iterator cc = patients.begin();cc!=patients.end();++cc) diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index d3fbc023..ed91ea96 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -19,7 +19,9 @@ typedef std::list ListPatient; class GDCM_EXPORT gdcmDicomDir: public gdcmParser { public: + gdcmDicomDir(bool exception_on_error = false); gdcmDicomDir(std::string &FileName,bool exception_on_error = false ); + ~gdcmDicomDir(void); void SetPrintLevel(int level) { printLevel = level; }; diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 1cbb7aac..bfe4b672 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -78,7 +78,6 @@ bool gdcmHeader::IsReadable(void) { std::string res = GetEntryByNumber(0x0028, 0x0005); if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) return false; // Image Dimensions - if ( !GetHeaderEntryByNumber(0x0028, 0x0100) ) return false; // "Bits Allocated" if ( !GetHeaderEntryByNumber(0x0028, 0x0101) ) @@ -121,11 +120,7 @@ bool gdcmHeader::IsJPEGExtendedProcess2_4TransferSyntax(void) { if ( !Element ) return false; LoadHeaderEntrySafe(Element); - - std::string Transfer = Element->GetValue(); - if ( Transfer == "1.2.840.10008.1.2.4.51" ) - return true; - return false; + return ( Element->GetValue() == "1.2.840.10008.1.2.4.51" ); } /** @@ -421,16 +416,17 @@ std::string gdcmHeader::GetPixelType(void) { /** * \ingroup gdcmHeader * \brief Recover the offset (from the beginning of the file) - * \ of *image* pixels (not *icone* pixels, if any !) + * \ of *image* pixels (not *icone image* pixels, if any !) */ size_t gdcmHeader::GetPixelOffset(void) { - // If this file complies with the norm we should encounter the - // "Image Location" tag (0x0028, 0x0200). This tag contains the + // We may encounter the 'RETired' (0x0028, 0x0200) tag + // (Image Location") . This Element contains the number of // the group that contains the pixel data (hence the "Pixel Data" // is found by indirection through the "Image Location"). // Inside the group pointed by "Image Location" the searched element // is conventionally the element 0x0010 (when the norm is respected). // When the "Image Location" is absent we default to group 0x7fe0. + // // If the element (0x0088,0x0200) 'icone image sequence' is found // (grPixel,numPixel) is stored twice : the first one for the icon // the second one for the image ... @@ -545,7 +541,7 @@ bool gdcmHeader::HasLUT(void) { if ( !GetHeaderEntryByNumber(0x0028,0x1103) ) return false; - // It is not enough + // It is not enough : // we check also // Red Palette Color Lookup Table Data @@ -687,7 +683,8 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) { // if it works, we shall have to check the 3 Palettes // to see which byte is ==0 (first one, or second one) // and fix the code - // We give up the checking to avoid some overhead + // We give up the checking to avoid some (useless ?)overhead + // (optimistic asumption) unsigned char *a; int i; @@ -713,7 +710,6 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) { } //How to free the now useless LUTs? - //free(LutR); free(LutB); free(LutG); // Seg Fault when used return(LUTRGBA); } @@ -752,7 +748,9 @@ std::string gdcmHeader::GetTransfertSyntaxName(void) { void gdcmHeader::SetImageDataSize(size_t ImageDataSize) { std::string content1; char car[20]; - // Assumes HeaderEntry (0x7fe0, 0x0010) exists ... + // Assumes HeaderEntry (0x7fe0, 0x0010) exists ... + // TODO define private members PixelGroupNumber, PicxelElementNumber + // update them, use them (only necessary for ACR-NEMA, not DICOM) sprintf(car,"%d",ImageDataSize); gdcmHeaderEntry *a = GetHeaderEntryByNumber(0x7fe0, 0x0010); diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index feefcee8..1e67bc4f 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -51,7 +51,7 @@ public: // Some heuristic based accessors, end user intended // (to be move to gdcmHeaderHelper?) - int GetXSize(void); + int GetXSize(void); int GetYSize(void); int GetZSize(void); int GetBitsStored(void); @@ -81,19 +81,22 @@ public: // TODO Swig int SetPubDict(std::string filename); // Entry - inline virtual std::string GetEntryByName (std::string tagName) - { return(gdcmParser::GetEntryByName(tagName)); } - inline virtual std::string GetEntryVRByName (std::string tagName) - { return(gdcmParser::GetEntryVRByName(tagName)); } + inline virtual std::string GetEntryByNumber (guint16 group, guint16 element) { return(gdcmParser::GetEntryByNumber(group,element)); } inline virtual std::string GetEntryVRByNumber(guint16 group, guint16 element) { return(gdcmParser::GetEntryVRByNumber(group,element)); } - - inline virtual bool SetEntryByName(std::string content,std::string tagName) - { return(gdcmParser::SetEntryByName(content,tagName)); } + + inline virtual std::string GetEntryByName (std::string tagName) + { return(gdcmParser::GetEntryByName(tagName)); } + inline virtual std::string GetEntryVRByName (std::string tagName) + { return(gdcmParser::GetEntryVRByName(tagName)); } + inline virtual bool SetEntryByNumber(std::string content,guint16 group, guint16 element) { return(gdcmParser::SetEntryByNumber(content,group,element)); } + inline virtual bool SetEntryByName(std::string content,std::string tagName) + { return(gdcmParser::SetEntryByName(content,tagName)); } + inline virtual void UpdateShaEntries(void) { gdcmParser::UpdateShaEntries(); } diff --git a/src/gdcmHeaderEntry.cxx b/src/gdcmHeaderEntry.cxx index 5832ad31..e5312074 100644 --- a/src/gdcmHeaderEntry.cxx +++ b/src/gdcmHeaderEntry.cxx @@ -92,6 +92,11 @@ void gdcmHeaderEntry::Print(std::ostream & os) { if (g == 0x0008) { if ( (e == 0x0016) || (e == 0x1150) ) s << " ==>\t[" << ts->GetValue(v) << "]"; + } else { + if (g == 0x0004) { + if ( (e == 0x1510) || (e == 0x1512) ) + s << " ==>\t[" << ts->GetValue(v) << "]"; + } } } //if (e == 0x0000) { // elem 0x0000 --> group length diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 7165817e..cf2cc947 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -29,8 +29,8 @@ typedef std::map GroupHT; //----------------------------------------------------------------------------- /* - * \defgroup gdcmHeader - * \brief + * \defgroup gdcmParser + * \brief used by both gdcmHeader and gdcmDicomDir */ class GDCM_EXPORT gdcmParser { @@ -128,7 +128,6 @@ protected: IterHT GetHeaderEntrySameNumber(guint16 group, guint16 element); // IterHT GetHeaderEntrySameName (std::string Name); - void LoadHeaderEntrySafe(gdcmHeaderEntry *); void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR); @@ -177,21 +176,22 @@ private: void SwitchSwapToBigEndian(void); void SetMaxSizeLoadEntry(long); - // Dict + // DictEntry related utilities gdcmDictEntry *GetDictEntryByName (std::string Name); gdcmDictEntry *GetDictEntryByNumber(guint16, guint16); - - // HeaderEntry related utilities - gdcmHeaderEntry *ReadNextHeaderEntry (void); - gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, - guint16 element); - gdcmHeaderEntry *NewHeaderEntryByName (std::string Name); gdcmDictEntry *NewVirtualDictEntry(guint16 group, guint16 element, std::string vr = "Unknown", std::string fourth = "Unknown", std::string name = "Unknown"); gdcmDictEntry *NewVirtualDictEntry(gdcmHeaderEntry *); + + // HeaderEntry related utilities + gdcmHeaderEntry *ReadNextHeaderEntry (void); + gdcmHeaderEntry *NewHeaderEntryByNumber(guint16 group, + guint16 element); + gdcmHeaderEntry *NewHeaderEntryByName (std::string Name); + // Deprecated (Not used) gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName, -- 2.45.1