From d7a4d5d474ae599b723e52ebda8bd3fc6cee752a Mon Sep 17 00:00:00 2001 From: regrain Date: Tue, 20 Jan 2004 15:21:06 +0000 Subject: [PATCH] * add shadow dictionary * bug fix * coding style --- src/gdcm.h | 2 + src/gdcmDict.cxx | 34 +++--- src/gdcmDict.h | 1 - src/gdcmDictSet.cxx | 5 +- src/gdcmDictSet.h | 2 +- src/gdcmHeader.cxx | 13 --- src/gdcmHeaderEntry.cxx | 116 +++++++++++---------- src/gdcmHeaderEntry.h | 22 ++-- src/gdcmParser.cxx | 226 +++++++++++++++++++++++++++++++++------- src/gdcmParser.h | 12 ++- src/gdcmTS.cxx | 38 ++++++- src/gdcmTS.h | 4 + src/gdcmUtil.cxx | 14 +-- src/gdcmUtil.h | 10 +- src/gdcmVR.cxx | 37 ++++++- src/gdcmVR.h | 7 +- 16 files changed, 376 insertions(+), 167 deletions(-) diff --git a/src/gdcm.h b/src/gdcm.h index a3d7ad5c..997001a0 100644 --- a/src/gdcm.h +++ b/src/gdcm.h @@ -28,5 +28,7 @@ #include "gdcmHeaderHelper.h" #include "gdcmFile.h" +#include "gdcmUtil.h" + //----------------------------------------------------------------------------- #endif // #ifndef GDCM_H diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 9f2d3882..e15c5ded 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -2,7 +2,11 @@ //----------------------------------------------------------------------------- #include "gdcmDict.h" #include "gdcmUtil.h" + #include +#include +#include + #ifdef GDCM_NO_ANSI_STRING_STREAM # include # define ostringstream ostrstream @@ -18,17 +22,16 @@ * @param FileName from which to build the dictionary. */ gdcmDict::gdcmDict(std::string & FileName) { - std::ifstream from(FileName.c_str()); - dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary", - FileName.c_str()); guint16 group, element; - // CLEANME : use defines for all those constants char buff[1024]; - TagKey key; TagName vr; TagName fourth; TagName name; + std::ifstream from(FileName.c_str()); + dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary", + FileName.c_str()); + while (!from.eof()) { from >> std::hex >> group >> element; eatwhite(from); @@ -39,13 +42,14 @@ gdcmDict::gdcmDict(std::string & FileName) { fourth = buff; from.getline(buff, 256, '\n'); name = buff; + gdcmDictEntry * newEntry = new gdcmDictEntry(group, element, vr, fourth, name); - // FIXME: use AddNewEntry - NameHt[name] = newEntry; - KeyHt[gdcmDictEntry::TranslateToKey(group, element)] = newEntry; + AddNewEntry(newEntry); } from.close(); + + filename=FileName; } /** @@ -74,6 +78,7 @@ gdcmDict::~gdcmDict() { * @param os The output stream to be written to. */ void gdcmDict::Print(std::ostream &os) { + os<<"Dict file name : "<second->GetGroup() << ','; - s << std::hex << tag->second->GetElement() << ") = " << std::dec; + s << "Entry : "; + s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ','; + s << std::hex << std::setw(4) << tag->second->GetElement() << ") = " << std::dec; s << tag->second->GetVR() << ", "; s << tag->second->GetFourth() << ", "; s << tag->second->GetName() << "." << std::endl; @@ -109,12 +114,13 @@ void gdcmDict::PrintByName(std::ostream& os) { std::ostringstream s; for (TagNameHT::iterator tag = NameHt.begin(); tag != NameHt.end(); ++tag){ - s << "Tag : "; + s << "Entry : "; s << tag->second->GetName() << ","; s << tag->second->GetVR() << ", "; s << tag->second->GetFourth() << ", "; - s << "(" << std::hex << tag->second->GetGroup() << ','; - s << std::hex << tag->second->GetElement() << ") = " << std::dec << std::endl; + s << "(" << std::hex << std::setw(4) << tag->second->GetGroup() << ','; + s << std::hex << std::setw(4) << tag->second->GetElement() << ") = "; + s << std::dec << std::endl; } os << s.str(); } diff --git a/src/gdcmDict.h b/src/gdcmDict.h index 1e1f0754..b901f57a 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -57,7 +57,6 @@ public: inline TagKeyHT & gdcmDict::GetEntries(void) { return KeyHt; } private: - std::string name; std::string filename; /// Access through TagKey (see alternate access with NameHt) diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index 5982f00c..518eb728 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -121,10 +121,11 @@ std::map > *gdcmDictSet::GetPubDictEntryName * @param Name Symbolic name that be used as identifier of the newly * created dictionary. */ -void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) +gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) { gdcmDict *NewDict = new gdcmDict(FileName); AppendDict(NewDict,Name); + return(NewDict); } /** @@ -163,7 +164,7 @@ gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element, std::string name) { gdcmDictEntry *entry; - std::string tag=gdcmDictEntry::TranslateToKey(group,element)+vr; + std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name; std::map::iterator it; it=virtualEntry.find(tag); diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index a992fc66..e970b80b 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -37,7 +37,7 @@ public: std::map > * GetPubDictEntryNamesByCategory(void); - void LoadDictFromFile(std::string FileName, DictKey Name); + gdcmDict *LoadDictFromFile(std::string FileName, DictKey Name); gdcmDict *GetDict(DictKey DictName); gdcmDict *GetDefaultPubDict(void); diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 024862dd..e9d52811 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -4,21 +4,8 @@ #include #include -/*// For nthos: -#ifdef _MSC_VER - #include -#else - #include -#endif*/ #include // for isalpha -/*#ifdef GDCM_NO_ANSI_STRING_STREAM -# include -# define ostringstream ostrstream -# else -# include -#endif*/ - #include "gdcmUtil.h" #include "gdcmTS.h" diff --git a/src/gdcmHeaderEntry.cxx b/src/gdcmHeaderEntry.cxx index f2e78cb8..6ce3a9f8 100644 --- a/src/gdcmHeaderEntry.cxx +++ b/src/gdcmHeaderEntry.cxx @@ -21,7 +21,7 @@ * @param in Pointer to existing dictionary entry */ gdcmHeaderEntry::gdcmHeaderEntry(gdcmDictEntry* in) { - ImplicitVr = false; + ImplicitVR = false; entry = in; } @@ -39,65 +39,67 @@ void gdcmHeaderEntry::Print(std::ostream & os) { 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)) << " "; + 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 << 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) << "]"; + s << std::setw(8) << "-1"; } 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(); + 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; + } + + s << "[" << GetVR() << "] "; + + if (printLevel>=1) { + 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(); } //----------------------------------------------------------------------------- diff --git a/src/gdcmHeaderEntry.h b/src/gdcmHeaderEntry.h index 01f2bc74..20e23ceb 100644 --- a/src/gdcmHeaderEntry.h +++ b/src/gdcmHeaderEntry.h @@ -52,27 +52,21 @@ public: * \ingroup gdcmHeaderEntry * \brief Sets to TRUE the ImplicitVr flag of the current Dicom Element */ - inline void gdcmHeaderEntry::SetImplicitVr(void) { - ImplicitVr = true; - }; + inline void gdcmHeaderEntry::SetImplicitVR(void) { ImplicitVR = true; }; /** * \ingroup gdcmHeaderEntry * \brief tells us if the current Dicom Element was checked as ImplicitVr * @return true if the current Dicom Element was checked as ImplicitVr */ - inline bool gdcmHeaderEntry::IsImplicitVr(void) { - return ImplicitVr; - }; + inline bool gdcmHeaderEntry::IsImplicitVR(void) { return ImplicitVR; }; /** * \ingroup gdcmHeaderEntry * \brief tells us if the VR of the current Dicom Element is Unkonwn * @return true if the VR is unkonwn */ - inline bool gdcmHeaderEntry::IsVRUnknown(void) { - return entry->IsVRUnknown(); - }; + inline bool gdcmHeaderEntry::IsVRUnknown(void) { return entry->IsVRUnknown(); }; /** * \ingroup gdcmHeaderEntry @@ -88,17 +82,15 @@ public: * \brief Gets the DicEntry of the current Dicom Element * @return the DicEntry of the current Dicom Element */ - gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { - return entry; - }; + gdcmDictEntry * gdcmHeaderEntry::GetDictEntry(void) { return entry; }; /** * \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; }; - void Print (std::ostream & os = std::cout); + void SetPrintLevel(int level) { printLevel = level; }; + void Print (std::ostream & os = std::cout); private: // FIXME: In fact we should be more specific and use : @@ -119,7 +111,7 @@ private: // going on. // *for internal* use only - bool ImplicitVr; // Even when reading explicit vr files, some + bool ImplicitVR; // Even when reading explicit vr files, some // elements happen to be implicit. Flag them here // since we can't use the entry->vr without breaking // the underlying dictionary. diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index ec1dcb9f..05460431 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -17,6 +17,7 @@ # else # include #endif +# include //----------------------------------------------------------------------------- // Refer to gdcmParser::CheckSwap() @@ -93,7 +94,7 @@ gdcmParser::~gdcmParser (void) * both from the H Table and the chained list * @return */ -void gdcmParser::PrintPubEntry(std::ostream & os) +void gdcmParser::PrintEntry(std::ostream & os) { std::ostringstream s; @@ -324,7 +325,6 @@ FILE *gdcmParser::OpenFile(bool exception_on_error) dbg.Verbose(0, "gdcmParser::gdcmParser not DICOM/ACR", filename.c_str()); } else { - std::cerr< from public dictionary - if((*it)->GetGroup()%1==0) + if((*it)->GetGroup()%2==0) continue; // Peer group => search the corresponding dict entry - entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement()); + if(RefShaDict) + entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement()); + else + entry=NULL; + + if((*it)->IsImplicitVR()) + vr="Implicit"; + else + vr=(*it)->GetVR(); + if(entry) { + // Set the new entry and the new value (*it)->SetDictEntry(entry); - vr=(*it)->GetVR(); CheckHeaderEntryVR(*it,vr); + + (*it)->SetValue(GetHeaderEntryValue(*it)); + } + else + { + // Remove precedent value transformation + (*it)->SetValue(GetHeaderEntryUnvalue(*it)); + (*it)->SetDictEntry(NewVirtualDictEntry((*it)->GetGroup(),(*it)->GetElement(),vr)); } } } @@ -1086,6 +1100,17 @@ guint32 gdcmParser::SwapLong(guint32 a) return(a); } +/** + * \ingroup gdcmParser + * \brief Unswaps back the bytes of 4-byte long integer accordingly to + * processor order. + * @return The properly unswaped 32 bits integer. + */ +guint32 gdcmParser::UnswapLong(guint32 a) +{ + return (SwapLong(a)); +} + /** * \ingroup gdcmParser * \brief Swaps the bytes so they agree with the processor order @@ -1098,6 +1123,16 @@ guint16 gdcmParser::SwapShort(guint16 a) return (a); } +/** + * \ingroup gdcmParser + * \brief Unswaps the bytes so they agree with the processor order + * @return The properly unswaped 16 bits integer. + */ +guint16 gdcmParser::UnswapShort(guint16 a) +{ + return (SwapShort(a)); +} + //----------------------------------------------------------------------------- // Private /** @@ -1129,8 +1164,8 @@ void gdcmParser::LoadHeaderEntries(void) i != GetListEntry().end(); ++i) { - LoadHeaderEntry(*i); - } + LoadHeaderEntry(*i); + } rewind(fp); @@ -1238,7 +1273,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) guint32 NewInt; std::ostringstream s; int nbInt; - if (vr == "US" || vr == "SS") + if (vr == "US" || vr == "SS") { nbInt = length / 2; NewInt = ReadInt16(); @@ -1253,7 +1288,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) } } - } + } else if (vr == "UL" || vr == "SL") { nbInt = length / 4; @@ -1268,7 +1303,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) s << NewInt; } } - } + } #ifdef GDCM_NO_ANSI_STRING_STREAM s << std::ends; // to avoid oddities on Solaris #endif //GDCM_NO_ANSI_STRING_STREAM @@ -1306,7 +1341,7 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) * \ when position to be taken care of * @param newHeaderEntry */ -void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) +void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { tagHT.insert( PairHT( newHeaderEntry->GetKey(),newHeaderEntry) ); listEntries.push_back(newHeaderEntry); @@ -1320,7 +1355,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) * @return */ - void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry * Entry) + void gdcmParser::FindHeaderEntryLength (gdcmHeaderEntry *Entry) { guint16 element = Entry->GetElement(); guint16 group = Entry->GetGroup(); @@ -1333,7 +1368,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) "we reached 7fe0 0010"); } - if ( (filetype == ExplicitVR) && ! Entry->IsImplicitVr() ) + if ( (filetype == ExplicitVR) && (! Entry->IsImplicitVR()) ) { if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) { @@ -1421,15 +1456,17 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) FixHeaderEntryFoundLength(Entry, (guint32)length16); return; } - - // Either implicit VR or a non DICOM conformal (see not below) explicit - // VR that ommited the VR of (at least) this element. Farts happen. - // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25 - // on Data elements "Implicit and Explicit VR Data Elements shall - // not coexist in a Data Set and Data Sets nested within it".] - // Length is on 4 bytes. - FixHeaderEntryFoundLength(Entry, ReadInt32()); - return; + else + { + // Either implicit VR or a non DICOM conformal (see not below) explicit + // VR that ommited the VR of (at least) this element. Farts happen. + // [Note: according to the part 5, PS 3.5-2001, section 7.1 p25 + // on Data elements "Implicit and Explicit VR Data Elements shall + // not coexist in a Data Set and Data Sets nested within it".] + // Length is on 4 bytes. + FixHeaderEntryFoundLength(Entry, ReadInt32()); + return; + } } /** @@ -1466,7 +1503,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *Entry) // avoid . if ( Entry->IsVRUnknown() ) Entry->SetVR("Implicit"); - Entry->SetImplicitVr(); + Entry->SetImplicitVR(); } } @@ -1480,7 +1517,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *Entry) * @return false if the VR is incorrect of if the VR isn't referenced * otherwise, it returns true */ -bool gdcmParser::CheckHeaderEntryVR (gdcmHeaderEntry *Entry, VRKey vr) +bool gdcmParser::CheckHeaderEntryVR(gdcmHeaderEntry *Entry, VRKey vr) { char msg[100]; // for sprintf bool RealExplicit = true; @@ -1525,22 +1562,131 @@ bool gdcmParser::CheckHeaderEntryVR (gdcmHeaderEntry *Entry, VRKey vr) // be unwise to overwrite the VR of a dictionary (since it would // compromise it's next user), we need to clone the actual DictEntry // and change the VR for the read one. - gdcmDictEntry* NewTag = NewVirtualDictEntry(Entry->GetGroup(), - Entry->GetElement(), - vr, - "FIXME", - Entry->GetName()); - Entry->SetDictEntry(NewTag); + gdcmDictEntry* NewEntry = NewVirtualDictEntry( + Entry->GetGroup(),Entry->GetElement(), + vr,"FIXME",Entry->GetName()); + Entry->SetDictEntry(NewEntry); } return(true); } /** * \ingroup gdcmParser - * \brief Skip a given Header Entry + * \brief Get the transformed value of the header entry. The VR value + * is used to define the transformation to operate on the value * \warning NOT end user intended method ! - * @param entry - * @return + * @param Entry + * @return Transformed entry value + */ +std::string gdcmParser::GetHeaderEntryValue(gdcmHeaderEntry *Entry) +{ + if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) + { + std::string val=Entry->GetValue(); + std::string vr=Entry->GetVR(); + guint32 length = Entry->GetLength(); + std::ostringstream s; + int nbInt; + + if (vr == "US" || vr == "SS") + { + guint16 NewInt16; + + nbInt = length / 2; + for (int i=0; i < nbInt; i++) + { + if(i!=0) + s << '\\'; + NewInt16 = (val[2*i+0]&0xFF)+((val[2*i+1]&0xFF)<<8); + NewInt16 = SwapShort(NewInt16); + s << NewInt16; + } + } + + else if (vr == "UL" || vr == "SL") + { + guint32 NewInt32; + + nbInt = length / 4; + for (int i=0; i < nbInt; i++) + { + if(i!=0) + s << '\\'; + NewInt32=(val[4*i+0]&0xFF)+((val[4*i+1]&0xFF)<<8)+((val[4*i+2]&0xFF)<<16)+((val[4*i+3]&0xFF)<<24); + NewInt32=SwapLong(NewInt32); + s << NewInt32; + } + } + +#ifdef GDCM_NO_ANSI_STRING_STREAM + s << std::ends; // to avoid oddities on Solaris +#endif //GDCM_NO_ANSI_STRING_STREAM + return(s.str()); + } + + return(Entry->GetValue()); +} + +/** + * \ingroup gdcmParser + * \brief Get the reverse transformed value of the header entry. The VR + * value is used to define the reverse transformation to operate on + * the value + * \warning NOT end user intended method ! + * @param Entry + * @return Reverse transformed entry value + */ +std::string gdcmParser::GetHeaderEntryUnvalue(gdcmHeaderEntry *Entry) +{ + if ( (IsHeaderEntryAnInteger(Entry)) && (Entry->IsImplicitVR()) ) + { + std::string vr=Entry->GetVR(); + std::ostringstream s; + std::vector tokens; + unsigned char *ptr; + + if (vr == "US" || vr == "SS") + { + guint16 NewInt16; + + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (Entry->GetValue(), tokens, "\\"); + for (unsigned int i=0; i>8)&0xFF); + } + tokens.clear(); + } + if (vr == "UL" || vr == "SL") + { + guint32 NewInt32; + + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (Entry->GetValue(), tokens, "\\"); + for (unsigned int i=0; i>8)&0xFF) + <<(char)((NewInt32>>16)&0xFF)<<(char)((NewInt32>>24)&0xFF); + } + tokens.clear(); + } + +#ifdef GDCM_NO_ANSI_STRING_STREAM + s << std::ends; // to avoid oddities on Solaris +#endif //GDCM_NO_ANSI_STRING_STREAM + return(s.str()); + } + + return(Entry->GetValue()); +} + +/** + * \ingroup gdcmParser + * \brief Skip a given Header Entry + * \warning NOT end user intended method ! + * @param entry */ void gdcmParser::SkipHeaderEntry(gdcmHeaderEntry *entry) { @@ -2145,11 +2291,11 @@ gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element, gdcmHeaderEntry *gdcmParser::NewHeaderEntryByNumber(guint16 Group, guint16 Elem) { // Find out if the tag we encountered is in the dictionaries: - gdcmDictEntry *NewTag = GetDictEntryByNumber(Group, Elem); - if (!NewTag) - NewTag = NewVirtualDictEntry(Group, Elem); + gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem); + if (!DictEntry) + DictEntry = NewVirtualDictEntry(Group, Elem); - gdcmHeaderEntry* NewEntry = new gdcmHeaderEntry(NewTag); + gdcmHeaderEntry *NewEntry = new gdcmHeaderEntry(DictEntry); if (!NewEntry) { dbg.Verbose(1, "gdcmParser::NewHeaderEntryByNumber", diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 54c6636c..2ca4a793 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -48,7 +48,7 @@ public: * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy */ void SetPrintLevel(int level) { printLevel = level; }; - virtual void PrintPubEntry(std::ostream &os = std::cout); + virtual void PrintEntry(std::ostream &os = std::cout); virtual void PrintPubDict (std::ostream &os = std::cout); virtual void PrintShaDict (std::ostream &os = std::cout); @@ -98,7 +98,9 @@ public: // System access inline int GetSwapCode(void) { return sw; } guint16 SwapShort(guint16); // needed by gdcmFile - guint32 SwapLong(guint32); // for JPEG Files + guint32 SwapLong(guint32); // needed by gdcmFile + guint16 UnswapShort(guint16); // needed by gdcmFile + guint32 UnswapLong(guint32); // needed by gdcmFile protected: // Entry @@ -123,7 +125,7 @@ protected: gdcmHeaderEntry *GetHeaderEntryByName (std::string Name); gdcmHeaderEntry *GetHeaderEntryByNumber(guint16 group, guint16 element); - void LoadHeaderEntrySafe (gdcmHeaderEntry *); + void LoadHeaderEntrySafe(gdcmHeaderEntry *); void UpdateGroupLength(bool SkipSequence = false, FileType type = ImplicitVR); void WriteEntries(FileType type, FILE *); @@ -146,6 +148,9 @@ private: void FindHeaderEntryVR (gdcmHeaderEntry *); bool CheckHeaderEntryVR (gdcmHeaderEntry *, VRKey); + std::string GetHeaderEntryValue (gdcmHeaderEntry *); + std::string GetHeaderEntryUnvalue(gdcmHeaderEntry *); + void SkipHeaderEntry (gdcmHeaderEntry *); void FixHeaderEntryFoundLength(gdcmHeaderEntry *, guint32); bool IsHeaderEntryAnInteger (gdcmHeaderEntry *); @@ -173,6 +178,7 @@ private: std::string vr = "Unknown", std::string fourth = "Unknown", std::string name = "Unknown"); + gdcmDictEntry *NewVirtualDictEntry(gdcmHeaderEntry *); // Deprecated (Not used) gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName, diff --git a/src/gdcmTS.cxx b/src/gdcmTS.cxx index f3e89ab9..531c4ee7 100644 --- a/src/gdcmTS.cxx +++ b/src/gdcmTS.cxx @@ -10,9 +10,18 @@ #endif #define DICT_TS "dicomTS.dic" +#include +#ifdef GDCM_NO_ANSI_STRING_STREAM +# include +# define ostringstream ostrstream +# else +# include +#endif + //----------------------------------------------------------------------------- // Constructor / Destructor -gdcmTS::gdcmTS(void) { +gdcmTS::gdcmTS(void) +{ std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_TS); std::ifstream from(filename.c_str()); dbg.Error(!from, "gdcmTS::gdcmTS: can't open dictionary",filename.c_str()); @@ -29,27 +38,46 @@ gdcmTS::gdcmTS(void) { from.getline(buff, 1024, '\n'); name = buff; - if(key!="") { + if(key!="") + { ts[key]=name; } } from.close(); } -gdcmTS::~gdcmTS() { +gdcmTS::~gdcmTS() +{ ts.clear(); } //----------------------------------------------------------------------------- // Print +/** + * \ingroup gdcmVR + * \brief Print all + * @param os The output stream to be written to. + */ +void gdcmTS::Print(std::ostream &os) +{ + std::ostringstream s; + + for (TSHT::iterator it = ts.begin(); it != ts.end(); ++it) + { + s << "TS : "<first<<" = "<second< #include +#include //----------------------------------------------------------------------------- typedef std::string TSKey; @@ -21,6 +22,9 @@ class GDCM_EXPORT gdcmTS { public: gdcmTS(void); ~gdcmTS(); + + void Print(std::ostream &os = std::cout); + int Count(TSKey key); std::string GetValue(TSKey key); diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 40143310..b642db19 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -52,9 +52,9 @@ void gdcmDebug::Exit(int a) { } //----------------------------------------------------------------------------- -gdcmVR * gdcmGlobal::VR = (gdcmVR*)0; -gdcmTS * gdcmGlobal::TS = (gdcmTS*)0; -gdcmDictSet * gdcmGlobal::Dicts = (gdcmDictSet*)0; +gdcmVR *gdcmGlobal::VR = (gdcmVR *)0; +gdcmTS *gdcmGlobal::TS = (gdcmTS *)0; +gdcmDictSet *gdcmGlobal::Dicts = (gdcmDictSet *)0; gdcmGlobal gdcmGlob; gdcmGlobal::gdcmGlobal(void) { @@ -71,15 +71,15 @@ gdcmGlobal::~gdcmGlobal() { delete Dicts; } -gdcmVR * gdcmGlobal::GetVR(void) { +gdcmVR *gdcmGlobal::GetVR(void) { return VR; } -gdcmTS * gdcmGlobal::GetTS(void) { +gdcmTS *gdcmGlobal::GetTS(void) { return TS; } -gdcmDictSet * gdcmGlobal::GetDicts(void) { +gdcmDictSet *gdcmGlobal::GetDicts(void) { return Dicts; } @@ -113,7 +113,7 @@ void Tokenize (const std::string& str, /////////////////////////////////////////////////////////////////////////// // to prevent a flashing screen when non-printable character -char * _cleanString(char *v) { +char *_cleanString(char *v) { char *d; int i, l; l = strlen(v); diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 7b35b952..4c552409 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -42,14 +42,14 @@ private: * This class contains all globals elements that might be * instanciated only one time */ -class gdcmGlobal { +class GDCM_EXPORT gdcmGlobal { public: gdcmGlobal(void); ~gdcmGlobal(); - static gdcmVR * GetVR(void); - static gdcmTS * GetTS(void); - static gdcmDictSet * GetDicts(void); + static gdcmVR *GetVR(void); + static gdcmTS *GetTS(void); + static gdcmDictSet *GetDicts(void); private: static gdcmVR *VR; @@ -66,7 +66,7 @@ void Tokenize (const std::string& str, extern gdcmDebug dbg; -char * _cleanString(char *v); +char *_cleanString(char *v); std::string _CreateCleanString(std::string s); //----------------------------------------------------------------------------- diff --git a/src/gdcmVR.cxx b/src/gdcmVR.cxx index de4f1e1c..f002d0a0 100644 --- a/src/gdcmVR.cxx +++ b/src/gdcmVR.cxx @@ -9,9 +9,18 @@ #endif #define DICT_VR "dicomVR.dic" +#include +#ifdef GDCM_NO_ANSI_STRING_STREAM +# include +# define ostringstream ostrstream +# else +# include +#endif + //----------------------------------------------------------------------------- // Constructor / Destructor -gdcmVR::gdcmVR(void) { +gdcmVR::gdcmVR(void) +{ std::string filename=gdcmDictSet::BuildDictPath() + std::string(DICT_VR); std::ifstream from(filename.c_str()); dbg.Error(!from, "gdcmVR::gdcmVR: can't open dictionary",filename.c_str()); @@ -20,7 +29,8 @@ gdcmVR::gdcmVR(void) { std::string key; std::string name; - while (!from.eof()) { + while (!from.eof()) + { eatwhite(from); from.getline(buff, 1024, ' '); key = buff; @@ -45,10 +55,31 @@ gdcmVR::~gdcmVR() { //----------------------------------------------------------------------------- // Print +/** + * \ingroup gdcmVR + * \brief Print all + * @param os The output stream to be written to. + */ +void gdcmVR::Print(std::ostream &os) +{ + std::ostringstream s; + + for (VRHT::iterator it = vr.begin(); it != vr.end(); ++it) + { + s << "VR : "<first<<" = "<second< #include +#include //----------------------------------------------------------------------------- typedef std::string VRKey; @@ -17,10 +18,14 @@ typedef std::map VRHT; // Value Representation Hash Table * Container for dicom Value Representation Hash Table * \note This is a singleton */ -class GDCM_EXPORT gdcmVR { +class GDCM_EXPORT gdcmVR +{ public: gdcmVR(void); ~gdcmVR(); + + void Print(std::ostream &os = std::cout); + int Count(VRKey key); private: -- 2.48.1