From: jpr Date: Fri, 16 Jan 2004 18:06:51 +0000 (+0000) Subject: new Print method for gdcmHeaderEntry X-Git-Tag: Version0.4~93 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a394111e93ec16aade3e5a074e6574f50559b7d0;p=gdcm.git new Print method for gdcmHeaderEntry --- diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index ba4b347b..a5828675 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -136,7 +136,7 @@ public: /** * \ingroup gdcmHeader * \brief Sets the print level for the Dicom Header - * \note 0 for Light Print; 1 for 'heavy' Print + * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy */ void SetPrintLevel(int level) { printLevel = level; }; @@ -174,7 +174,7 @@ public: // ================= Was in EntrySet ================= - void Print(std::ostream &); + void Print(std::ostream & os = std::cout); void Add(gdcmHeaderEntry*); bool SetEntryByNumber(std::string content, guint16 group, guint16 element); bool SetEntryLengthByNumber(guint32 l, guint16 group, guint16 element); diff --git a/src/gdcmHeader2.cxx b/src/gdcmHeader2.cxx index ded3d1be..263e2608 100644 --- a/src/gdcmHeader2.cxx +++ b/src/gdcmHeader2.cxx @@ -27,111 +27,19 @@ void gdcmHeader::Print(std::ostream & os) { TSKey v; std::string d2; gdcmTS * ts = gdcmGlobal::GetTS(); - std::ostringstream s; -/* -// DO NOT remove this code right now. - - // Tag HT - s << "------------- using tagHT ---------------------" << std::endl; - for (TagHeaderEntryHT::iterator tag = tagHT.begin(); - tag != tagHT.end(); - ++tag){ - g = tag->second->GetGroup(); - e = tag->second->GetElement(); - v = tag->second->GetValue(); - o = tag->second->GetOffset(); - d2 = _CreateCleanString(v); // replace non printable characters by '.' - - s << tag->first << ": "; - s << " lgr : " <second->GetLength(); - s << ",\t Offset : " << o; - s << " x(" << std::hex << o << std::dec << ") "; - s << "\t[" << tag->second->GetVR() << "]"; - s << "\t[" << tag->second->GetName() << "]"; - s << "\t[" << d2 << "]"; - - // Display the UID value (instead of displaying the rough code) - if (g == 0x0002) { // Some more to be displayed ? - if ( (e == 0x0010) || (e == 0x0002) ) - s << " ==>\t[" << ts->GetValue(v) << "]"; - } else { - if (g == 0x0008) { - if ( (e == 0x0016) || (e == 0x1150) ) - s << " ==>\t[" << ts->GetValue(v) << "]"; - } - } - s << std::endl; - } -*/ + std::ostringstream s; - // List element guint32 lgth; char greltag[10]; //group element tag s << "------------ using listEntries ----------------" << std::endl; - char st[11]; + char st[20]; for (ListTag::iterator i = listEntries.begin(); i != listEntries.end(); ++i){ - g = (*i)->GetGroup(); - e = (*i)->GetElement(); - v = (*i)->GetValue(); - o = (*i)->GetOffset(); - sprintf(greltag,"%04x|%04x ",g,e); - d2 = _CreateCleanString(v); // replace non printable characters by '.' - s << greltag ; - - if (printLevel>=2) { - s << "lg : "; - lgth = (*i)->GetReadLength(); - if (lgth == 0xffffffff) { - sprintf(st,"x(%ff)"); - s.setf(std::ios::left); - s << std::setw(10-strlen(st)) << " "; - s << st << " "; - s.setf(std::ios::left); - s << std::setw(8) << "-1"; - } else { - sprintf(st,"x(%x)",lgth); - s.setf(std::ios::left); - s << std::setw(10-strlen(st)) << " "; - s << st << " "; - s.setf(std::ios::left); - s << std::setw(8) << lgth; - } - s << " Off.: "; - sprintf(st,"x(%x)",o); - s << std::setw(10-strlen(st)) << " "; - s << st << " "; - s << std::setw(8) << o; - } - if (printLevel>=1) { - s << "[" << (*i)->GetVR() << "] "; - s.setf(std::ios::left); - s << std::setw(66-(*i)->GetName().length()) << " "; - } - - s << "[" << (*i)->GetName()<< "]"; - s << " [" << d2 << "]"; - // Display the UID value (instead of displaying the rough code) - if (g == 0x0002) { // Any more to be displayed ? - if ( (e == 0x0010) || (e == 0x0002) ) - s << " ==>\t[" << ts->GetValue(v) << "]"; - } else { - if (g == 0x0008) { - if ( (e == 0x0016) || (e == 0x1150) ) - s << " ==>\t[" << ts->GetValue(v) << "]"; - } - } - if (e == 0x0000) { // elem 0x0000 --> group length - if (v == "4294967295") // to avoid troubles in convertion - sprintf (st," x(ffffffff)"); - else - sprintf(st," x(%08x)",atoi(v.c_str())); - s << st; - } - s << std::endl; + (*i)->SetPrintLevel(printLevel); + (*i)->Print(os); } os< +# define ostringstream ostrstream +# else +# include +#endif +#include // for std::ios::left, ... //----------------------------------------------------------------------------- // Constructor / Destructor @@ -18,6 +28,78 @@ gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) { //----------------------------------------------------------------------------- // Print +void gdcmHeaderEntry::Print(std::ostream & os) { + size_t o; + unsigned short int g, e; + char st[20]; + TSKey v; + std::string d2; + gdcmTS * ts = gdcmGlobal::GetTS(); + std::ostringstream s; + guint32 lgth; + char greltag[10]; //group element tag + + g = GetGroup(); + e = GetElement(); + v = GetValue(); + o = GetOffset(); + sprintf(greltag,"%04x|%04x ",g,e); + d2 = _CreateCleanString(v); // replace non printable characters by '.' + s << greltag ; + + if (printLevel>=2) { + s << "lg : "; + lgth = GetReadLength(); + if (lgth == 0xffffffff) { + sprintf(st,"x(%ff)"); + s.setf(std::ios::left); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s.setf(std::ios::left); + s << std::setw(8) << "-1"; + } else { + sprintf(st,"x(%x)",lgth); + s.setf(std::ios::left); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s.setf(std::ios::left); + s << std::setw(8) << lgth; + } + s << " Off.: "; + sprintf(st,"x(%x)",o); + s << std::setw(10-strlen(st)) << " "; + s << st << " "; + s << std::setw(8) << o; + } + if (printLevel>=1) { + s << "[" << GetVR() << "] "; + s.setf(std::ios::left); + s << std::setw(66-GetName().length()) << " "; + } + + s << "[" << GetName()<< "]"; + s << " [" << d2 << "]"; + // Display the UID value (instead of displaying the rough code) + if (g == 0x0002) { // Any more to be displayed ? + if ( (e == 0x0010) || (e == 0x0002) ) + s << " ==>\t[" << ts->GetValue(v) << "]"; + } else { + if (g == 0x0008) { + if ( (e == 0x0016) || (e == 0x1150) ) + s << " ==>\t[" << ts->GetValue(v) << "]"; + } + } + if (e == 0x0000) { // elem 0x0000 --> group length + if (v == "4294967295") // to avoid troubles in convertion + sprintf (st," x(ffffffff)"); + else + sprintf(st," x(%08x)",atoi(v.c_str())); + s << st; + } + s << std::endl; + os << s.str(); +} + //----------------------------------------------------------------------------- // Public diff --git a/src/gdcmHeaderEntry.h b/src/gdcmHeaderEntry.h index 1c8520ae..be3f4f85 100644 --- a/src/gdcmHeaderEntry.h +++ b/src/gdcmHeaderEntry.h @@ -37,6 +37,14 @@ public: inline void SetValue(std::string val) { value = val; }; inline void SetVoidArea(void * area) { voidArea = area; }; + void Print (std::ostream & os = std::cout); + /** + * \ingroup gdcmHeaderEntry + * \brief Sets the print level for the Dicom Header Elements + * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy + */ + void SetPrintLevel(int level) { printLevel = level; }; + /** * \ingroup gdcmHeaderEntry * \brief Sets the offset of the Dicom Element @@ -118,6 +126,7 @@ private: void *voidArea; // unsecure memory area to hold 'non string' values // (ie : Lookup Tables, overlays) size_t Offset; // Offset from the begining of file for direct user access + int printLevel; }; //-----------------------------------------------------------------------------