From 1e74cf45bc96f14c342cc404f0f91dfffe0810b9 Mon Sep 17 00:00:00 2001 From: regrain Date: Mon, 19 Jan 2004 14:28:24 +0000 Subject: [PATCH] * bug fix under python -- BeNours --- ChangeLog | 1 + gdcmPython/__init__.py | 1 + gdcmPython/gdcm.i | 9 ++- gdcmPython/win32/_vtkGdcm.dsp | 10 +-- gdcmPython/win32/gdcmpyembedded.dsp | 12 +-- src/gdcmDict.cxx | 116 +++++++++++++++++++++------ src/gdcmDict.h | 28 ++++--- src/gdcmDictEntry.cxx | 6 +- src/gdcmDictEntry.h | 54 +++++-------- src/gdcmDictSet.cxx | 18 +---- src/gdcmDictSet.h | 6 +- src/gdcmParser.cxx | 119 +++++++++++++++------------- src/gdcmParser.h | 42 +++++----- src/win32/gdcmdll.dsp | 18 ++--- vtk/win32/vtkgdcm.dsp | 10 +-- 15 files changed, 256 insertions(+), 194 deletions(-) diff --git a/ChangeLog b/ChangeLog index bac4695f..9e14294f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * split class gdcmHeader into gdcmParser and gdcmHeader, with gdcmHeader inheriting from gdcmParser. This split is to prepare the integration of dicom dir parsing + * bug fix under python 2004-01-16 Jean-Pierre Roux * removal of class gdcmHeaderEntrySet diff --git a/gdcmPython/__init__.py b/gdcmPython/__init__.py index 7d6390e7..cb32100c 100644 --- a/gdcmPython/__init__.py +++ b/gdcmPython/__init__.py @@ -70,6 +70,7 @@ except ImportError,e: raise ImportError, "gdcm extension not imported." ### Expose only the necessary stuff +gdcmGlobal = gdcm.gdcmGlobal gdcmDictSet = gdcm.gdcmDictSet gdcmHeader = gdcm.gdcmHeader gdcmHeaderHelper = gdcm.gdcmHeaderHelper diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 3f68d08e..0f3fea6b 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -98,13 +98,14 @@ extern gdcmGlobal gdcmGlob; //////////////////////////////////////////////////////////////////////////// // Deals with function returning a C++ string. -%typemap(out) string { - $result = PyString_FromString(($1).c_str()); -} -%typemap(out) std::string { +%typemap(out) string, std::string { $result = PyString_FromString(($1).c_str()); } +%typemap(python, in) const std::string, std::string +{ + $1 = PyString_AsString($input); +} //////////////////////////////////////////////////////////////////////////// %include "gdcmCommon.h" %include "gdcmDictEntry.h" diff --git a/gdcmPython/win32/_vtkGdcm.dsp b/gdcmPython/win32/_vtkGdcm.dsp index f6236770..be158e83 100644 --- a/gdcmPython/win32/_vtkGdcm.dsp +++ b/gdcmPython/win32/_vtkGdcm.dsp @@ -86,10 +86,6 @@ SOURCE=..\..\src\gdcmHeaderEntry.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmHeaderEntrySet.cxx -# End Source File -# Begin Source File - SOURCE=..\..\src\gdcmHeaderHelper.cxx # End Source File # Begin Source File @@ -106,7 +102,11 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmParse.cxx +SOURCE=..\..\src\gdcmParsePixels.cxx +# End Source File +# Begin Source File + +SOURCE=..\..\src\gdcmParser.cxx # End Source File # Begin Source File diff --git a/gdcmPython/win32/gdcmpyembedded.dsp b/gdcmPython/win32/gdcmpyembedded.dsp index 29e42f31..ea230953 100644 --- a/gdcmPython/win32/gdcmpyembedded.dsp +++ b/gdcmPython/win32/gdcmpyembedded.dsp @@ -53,7 +53,7 @@ LINK32=link.exe # Begin Special Build Tool ProjDir=. SOURCE="$(InputPath)" -PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ +PostBuild_Cmds=move $(ProjDir)\gdcm.py $(ProjDir)\..\ # End Special Build Tool # Begin Target @@ -108,10 +108,6 @@ SOURCE=..\..\src\gdcmHeaderEntry.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmHeaderEntrySet.cxx -# End Source File -# Begin Source File - SOURCE=..\..\src\gdcmHeaderHelper.cxx # End Source File # Begin Source File @@ -128,7 +124,11 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmParse.cxx +SOURCE=..\..\src\gdcmParsePixels.cxx +# End Source File +# Begin Source File + +SOURCE=..\..\src\gdcmParser.cxx # End Source File # Begin Source File diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 725d2d6c..085de514 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -58,10 +58,11 @@ gdcmDict::~gdcmDict() { if ( EntryToDelete ) delete EntryToDelete; } - KeyHt.clear(); + // Since AddNewEntry adds symetrical in both KeyHt and NameHT we can // assume all the pointed gdcmDictEntries are already cleaned-up when // we cleaned KeyHt. + KeyHt.clear(); NameHt.clear(); } @@ -72,7 +73,7 @@ gdcmDict::~gdcmDict() { * Entries will be sorted by tag i.e. the couple (group, element). * @param os The output stream to be written to. */ -void gdcmDict::Print(std::ostream& os) { +void gdcmDict::Print(std::ostream &os) { PrintByKey(os); } @@ -82,7 +83,7 @@ void gdcmDict::Print(std::ostream& os) { * Entries will be sorted by tag i.e. the couple (group, element). * @param os The output stream to be written to. */ -void gdcmDict::PrintByKey(std::ostream& os) { +void gdcmDict::PrintByKey(std::ostream &os) { std::ostringstream s; for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag){ @@ -126,15 +127,20 @@ void gdcmDict::PrintByName(std::ostream& os) { * @param NewEntry * @return false if Dicom Element already existed */ - bool gdcmDict::AddNewEntry(gdcmDictEntry* NewEntry) { +bool gdcmDict::AddNewEntry(gdcmDictEntry *NewEntry) +{ TagKey key; key = NewEntry->GetKey(); - if(KeyHt.count(key) == 1) { + if(KeyHt.count(key) == 1) + { dbg.Verbose(1, "gdcmDict::AddNewEntry already present", key.c_str()); return(false); - } else { + } + else + { KeyHt[NewEntry->GetKey()] = NewEntry; + NameHt[NewEntry->GetName()] = NewEntry; return(true); } } @@ -145,9 +151,10 @@ void gdcmDict::PrintByName(std::ostream& os) { * @param NewEntry * @return false if Dicom Element doesn't exist */ -bool gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) { +bool gdcmDict::ReplaceEntry(gdcmDictEntry *NewEntry) { if ( RemoveEntry(NewEntry->gdcmDictEntry::GetKey()) ) { - KeyHt[ NewEntry->GetKey()] = NewEntry; + KeyHt[NewEntry->GetKey()] = NewEntry; + NameHt[NewEntry->GetName()] = NewEntry; return (true); } return (false); @@ -160,14 +167,23 @@ bool gdcmDict::ReplaceEntry(gdcmDictEntry* NewEntry) { * @param key (group|element) * @return false if Dicom Dictionary Entry doesn't exist */ -bool gdcmDict::RemoveEntry(TagKey key) { - if(KeyHt.count(key) == 1) { +bool gdcmDict::RemoveEntry(TagKey key) +{ + if(KeyHt.count(key) == 1) + { gdcmDictEntry* EntryToDelete = KeyHt.find(key)->second; + if ( EntryToDelete ) + { + NameHt.erase(EntryToDelete->GetName()); delete EntryToDelete; + } + KeyHt.erase(key); return (true); - } else { + } + else + { dbg.Verbose(1, "gdcmDict::RemoveEntry unfound entry", key.c_str()); return (false); } @@ -186,6 +202,21 @@ bool gdcmDict::RemoveEntry (guint16 group, guint16 element) { return( RemoveEntry(gdcmDictEntry::TranslateToKey(group, element)) ); } +/** + * \ingroup gdcmDict + * \brief Get the dictionnary entry identified by it's name. + * @param name element of the ElVal to modify + * \warning : NEVER use it ! + * the 'name' IS NOT an identifier within the Dicom Dicom Dictionary + * the name MAY CHANGE between two versions ! + * @return the corresponding dictionnary entry when existing, NULL otherwise + */ +gdcmDictEntry *gdcmDict::GetTagByName(TagName name) { + if ( ! NameHt.count(name)) + return NULL; + return NameHt.find(name)->second; +} + /** * \ingroup gdcmDict * \brief Get the dictionnary entry identified by a given tag (group,element) @@ -193,26 +224,63 @@ bool gdcmDict::RemoveEntry (guint16 group, guint16 element) { * @param element element of the entry to be found * @return the corresponding dictionnary entry when existing, NULL otherwise */ -gdcmDictEntry * gdcmDict::GetTagByNumber(guint16 group, guint16 element) { +gdcmDictEntry *gdcmDict::GetTagByNumber(guint16 group, guint16 element) { TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! KeyHt.count(key)) - return (gdcmDictEntry*)0; + return NULL; return KeyHt.find(key)->second; } -/** +/** * \ingroup gdcmDict - * \brief Get the dictionnary entry identified by it's name. - * @param name element of the ElVal to modify - * \warning : NEVER use it ! - * the 'name' IS NOT an identifier within the Dicom Dicom Dictionary - * the name MAY CHANGE between two versions ! - * @return the corresponding dictionnary entry when existing, NULL otherwise + * \brief Consider all the entries of the public dicom dictionnary. + * Build all list of all the tag names of all those entries. + * \sa gdcmDictSet::GetPubDictTagNamesByCategory + * @return A list of all entries of the public dicom dictionnary. */ -gdcmDictEntry * gdcmDict::GetTagByName(TagName name) { - if ( ! NameHt.count(name)) - return (gdcmDictEntry*)0; - return NameHt.find(name)->second; +std::list *gdcmDict::GetTagNames(void) +{ + std::list *Result = new std::list; + for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) + { + Result->push_back( tag->second->GetName() ); + } + return Result; +} + +/** + * \ingroup gdcmDict + * \brief Consider all the entries of the public dicom dictionnary. + * Build an hashtable whose keys are the names of the groups + * (fourth field in each line of dictionary) and whose corresponding + * values are lists of all the dictionnary entries among that + * group. Note that apparently the Dicom standard doesn't explicitely + * define a name (as a string) for each group. + * A typical usage of this method would be to enable a dynamic + * configuration of a Dicom file browser: the admin/user can + * select in the interface which Dicom tags should be displayed. + * \warning Dicom *doesn't* define any name for any 'categorie' + * (the dictionnary fourth field was formerly NIH defined + * - and no longer he is- + * and will be removed when Dicom provides us a text file + * with the 'official' Dictionnary, that would be more friendly + * than asking us to perform a line by line check of the dictionnary + * at the beginning of each year to -try to- guess the changes) + * Therefore : please NEVER use that fourth field :-( + * * + * @return An hashtable: whose keys are the names of the groups and whose + * corresponding values are lists of all the dictionnary entries + * among that group. + */ +std::map > *gdcmDict::GetTagNamesByCategory(void) +{ + std::map > *Result = new std::map >; + + for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) + { + (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName()); + } + return Result; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDict.h b/src/gdcmDict.h index cf340244..8add2a6b 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -5,6 +5,9 @@ #include "gdcmCommon.h" #include "gdcmDictEntry.h" + +#include +#include #include //----------------------------------------------------------------------------- @@ -27,35 +30,40 @@ public: gdcmDict(std::string & FileName); ~gdcmDict(); - void Print(std::ostream&); - void PrintByKey(std::ostream&); - void PrintByName(std::ostream&); +// Print + void Print(std::ostream &os = std::cout); + void PrintByKey(std::ostream &os = std::cout); + void PrintByName(std::ostream &os = std::cout); - bool AddNewEntry (gdcmDictEntry* NewEntry); - bool ReplaceEntry(gdcmDictEntry* NewEntry); +// Entries + bool AddNewEntry (gdcmDictEntry *NewEntry); + bool ReplaceEntry(gdcmDictEntry *NewEntry); bool RemoveEntry (TagKey key); bool RemoveEntry (guint16 group, guint16 element); - gdcmDictEntry * GetTagByNumber(guint16 group, guint16 element); +// Tag gdcmDictEntry * GetTagByName(TagName name); + gdcmDictEntry * GetTagByNumber(guint16 group, guint16 element); + + std::list *GetTagNames(void); + std::map > * + GetTagNamesByCategory(void); /** * \ingroup gdcmDict * \brief returns a ref to the Dicom Dictionary H table (map) * return the Dicom Dictionary H table */ - inline TagKeyHT & gdcmDict::GetEntries(void) { - return KeyHt; - } + inline TagKeyHT & gdcmDict::GetEntries(void) { return KeyHt; } private: std::string name; std::string filename; + /// Access through TagKey (see alternate access with NameHt) TagKeyHT KeyHt; /// Access through TagName (see alternate access with KeyHt) TagNameHT NameHt; - }; //----------------------------------------------------------------------------- diff --git a/src/gdcmDictEntry.cxx b/src/gdcmDictEntry.cxx index ee04a0c6..0bc2afa9 100644 --- a/src/gdcmDictEntry.cxx +++ b/src/gdcmDictEntry.cxx @@ -60,10 +60,12 @@ TagKey gdcmDictEntry::TranslateToKey(guint16 group, guint16 element) { * is unset then overwrite it. * @param NewVr New V(alue) R(epresentation) to be set. */ -void gdcmDictEntry::SetVR(std::string NewVr) { +void gdcmDictEntry::SetVR(std::string NewVr) +{ if ( IsVRUnknown() ) vr = NewVr; - else { + else + { dbg.Error(true, "gdcmDictEntry::SetVR", "Overwriting vr might compromise a dictionary"); } diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 115ed7ac..f729d9b7 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -16,7 +16,8 @@ * - the owner group * - etc. */ -class GDCM_EXPORT gdcmDictEntry { +class GDCM_EXPORT gdcmDictEntry +{ public: gdcmDictEntry(guint16 group, guint16 element, @@ -25,6 +26,7 @@ public: std::string name = "Unknown"); static TagKey TranslateToKey(guint16 group, guint16 element); + void SetVR(std::string); /** @@ -33,47 +35,35 @@ public: * * @return */ - inline bool gdcmDictEntry::IsVRUnknown() { - if ( vr == "Unknown" ) - return true; - return false; - } + inline bool IsVRUnknown() {return vr == "Unknown"; } /** * \ingroup gdcmDictEntry * \brief returns the Dicom Group Number of the current gdcmDictEntry * return the Dicom Group Number */ - inline guint16 gdcmDictEntry::GetGroup(void) { - return group; - } + inline guint16 GetGroup(void) { return group; } /** * \ingroup gdcmDictEntry * \brief returns the Dicom Element Number of the current gdcmDictEntry * return the Dicom Element Number */ - inline guint16 gdcmDictEntry::GetElement(void) { - return element; - } + inline guint16 GetElement(void) { return element; } /** * \ingroup gdcmDictEntry * \brief returns the Dicom Value Representation of the current gdcmDictEntry * return the Dicom Value Representation */ - inline std::string gdcmDictEntry::GetVR(void) { - return vr; - } + inline std::string GetVR(void) { return vr; } /** * \ingroup gdcmDictEntry * \brief sets the key of the current gdcmDictEntry * @param k New key to be set. */ - inline void gdcmDictEntry::SetKey(std::string k) { - key = k; - } + inline void SetKey(std::string k) { key = k; } /** * \ingroup gdcmDictEntry @@ -83,9 +73,7 @@ public: * \ NEVER use it * return the Fourth field */ - inline std::string gdcmDictEntry::GetFourth(void) { - return fourth; - } + inline std::string GetFourth(void) { return fourth; } /** * \ingroup gdcmDictEntry @@ -93,34 +81,30 @@ public: * \ e.g. "Patient Name" for Dicom Tag (0x0010, 0x0010) * return the Dicom Name */ - inline std::string gdcmDictEntry::GetName(void) { - return name; - } + inline std::string GetName(void) { return name; } /** * \ingroup gdcmDictEntry * \brief Gets the key of the current gdcmDictEntry * @return the key . */ - inline std::string gdcmDictEntry::GetKey(void) { - return key; - } + inline std::string GetKey(void) { return key; } private: // FIXME : were are the group and element used except from building up // a TagKey. If the answer is nowhere then there is no need // to store the group and element independently. - guint16 group; // e.g. 0x0010 - guint16 element; // e.g. 0x0103 - std::string vr; // Value Representation i.e. some clue about the nature + guint16 group; // e.g. 0x0010 + guint16 element; // e.g. 0x0103 + std::string vr; // Value Representation i.e. some clue about the nature // of the data represented e.g. "FD" short for // "Floating Point Double" // CLEANME: find the official dicom name for this field ! - std::string fourth; // Fourth field containing some semantics. - //(Group Name abbr.) - std::string name; // e.g. "Patient_Name" - TagKey key; // Redundant with (group, element) but we add it - // on efficiency purposes. + std::string fourth; // Fourth field containing some semantics. + //(Group Name abbr.) + std::string name; // e.g. "Patient_Name" + TagKey key; // Redundant with (group, element) but we add it + // on efficiency purposes. // DCMTK has many fields for handling a DictEntry (see below). What are the // relevant ones for gdcmlib ? diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index fe95d73a..82962d6e 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -80,14 +80,7 @@ void gdcmDictSet::Print(std::ostream& os) */ std::list *gdcmDictSet::GetPubDictTagNames(void) { - std::list *Result = new std::list; - TagKeyHT entries = GetDefaultPubDict()->GetEntries(); - - for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag) - { - Result->push_back( tag->second->GetName() ); - } - return Result; + return(GetDefaultPubDict()->GetTagNames()); } /** @@ -116,14 +109,7 @@ std::list *gdcmDictSet::GetPubDictTagNames(void) */ std::map > *gdcmDictSet::GetPubDictTagNamesByCategory(void) { - std::map > *Result = new std::map >; - TagKeyHT entries = GetDefaultPubDict()->GetEntries(); - - for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag) - { - (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName()); - } - return Result; + return(GetDefaultPubDict()->GetTagNamesByCategory()); } /** diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 86abe1cd..8ef38e95 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -33,8 +33,8 @@ public: void Print(std::ostream& os); - std::list * GetPubDictTagNames(void); - std::map >* + std::list *GetPubDictTagNames(void); + std::map > * GetPubDictTagNamesByCategory(void); void LoadDictFromFile(std::string FileName, DictKey Name); @@ -43,7 +43,7 @@ public: gdcmDict *GetDefaultPubDict(void); gdcmDictEntry *NewVirtualDictEntry(guint16 group, guint16 element, - std::string vr = "Unknown", + std::string vr = "Unknown", std::string fourth = "Unknown", std::string name = "Unknown"); diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 797d50c8..8e2c0a07 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -81,10 +81,8 @@ gdcmParser::gdcmParser(bool exception_on_error) */ gdcmParser::~gdcmParser (void) { - dicom_vr = (gdcmVR*)0; - Dicts = (gdcmDictSet*)0; - RefPubDict = (gdcmDict*)0; - RefShaDict = (gdcmDict*)0; + RefPubDict = NULL; + RefShaDict = NULL; } //----------------------------------------------------------------------------- @@ -99,12 +97,7 @@ void gdcmParser::PrintPubEntry(std::ostream & os) { std::ostringstream s; -// guint32 lgth; -// char greltag[10]; //group element tag - s << "------------ using listEntries ----------------" << std::endl; - -// char st[20]; for (ListTag::iterator i = listEntries.begin(); i != listEntries.end(); ++i) @@ -137,6 +130,46 @@ void gdcmParser::PrintShaDict(std::ostream & os) //----------------------------------------------------------------------------- // Public +/** + * \ingroup gdcmParser + * \brief Get the public dictionary used + */ +gdcmDict *gdcmParser::GetPubDict(void) +{ + return(RefPubDict); +} + +/** + * \ingroup gdcmParser + * \brief Get the shadow dictionary used + */ +gdcmDict *gdcmParser::GetShaDict(void) +{ + return(RefShaDict); +} + +/** + * \ingroup gdcmParser + * \brief Set the shadow dictionary used + * \param dict dictionary to use in shadow + */ +bool gdcmParser::SetShaDict(gdcmDict *dict) +{ + RefShaDict=dict; + return(!RefShaDict); +} + +/** + * \ingroup gdcmParser + * \brief Set the shadow dictionary used + * \param dictName name of the dictionary to use in shadow + */ +bool gdcmParser::SetShaDict(DictKey dictName) +{ + RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName); + return(!RefShaDict); +} + /** * \ingroup gdcmParser * \brief This predicate, based on hopefully reasonable heuristics, @@ -569,40 +602,6 @@ bool gdcmParser::SetEntryByName(std::string content,std::string tagName) return(SetEntryByNumber(content,dictEntry->GetGroup(), dictEntry->GetElement())); -/* TagKey key = gdcmDictEntry::TranslateToKey(dictEntry->GetGroup(), - dictEntry->GetElement()); - if ( GetPubEntry().count(key) == 0 ) - return false; - - int l = content.length(); - if(l%2) // Odd length are padded with a space (020H). - { - l++; - content = content + '\0'; - } - - //tagHt[key]->SetValue(content); - gdcmHeaderEntry * a; - IterHT p; - TagHeaderEntryHT::iterator p2; - // DO NOT remove the following lines : they explain how the stuff works - //p= tagHt.equal_range(key); // get a pair of iterators first-last synonym - //p2=p.first; // iterator on the first synonym - //a=p2->second; // H Table target column (2-nd col) - // or, easier : - a = ((GetPubEntry().equal_range(key)).first)->second; - a-> SetValue(content); - std::string vr = a->GetVR(); - - guint32 lgr; - if( (vr == "US") || (vr == "SS") ) - lgr = 2; - else if( (vr == "UL") || (vr == "SL") ) - lgr = 4; - else - lgr = l; - a->SetLength(lgr); - return true;*/ } /** @@ -1370,7 +1369,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry * newHeaderEntry) if (!NewTag) { // This correct tag is not in the dictionary. Create a new one. - NewTag = Dicts->NewVirtualDictEntry(CorrectGroup, CorrectElem); + NewTag = NewVirtualDictEntry(CorrectGroup, CorrectElem); } // FIXME this can create a memory leaks on the old entry that be // left unreferenced. @@ -1444,7 +1443,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *ElVal) // CLEANME searching the dicom_vr at each occurence is expensive. // PostPone this test in an optional integrity check at the end // of parsing or only in debug mode. - if ( RealExplicit && !dicom_vr->Count(vr) ) + if ( RealExplicit && !gdcmGlobal::GetVR()->Count(vr) ) RealExplicit= false; if ( RealExplicit ) @@ -1465,7 +1464,7 @@ void gdcmParser::FindHeaderEntryVR( gdcmHeaderEntry *ElVal) // 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 = Dicts->NewVirtualDictEntry(ElVal->GetGroup(), + gdcmDictEntry* NewTag = NewVirtualDictEntry(ElVal->GetGroup(), ElVal->GetElement(), vr, "FIXME", @@ -1725,10 +1724,7 @@ void gdcmParser::SkipBytes(guint32 NBytes) */ void gdcmParser::Initialise(void) { - dicom_vr = gdcmGlobal::GetVR(); - dicom_ts = gdcmGlobal::GetTS(); - Dicts = gdcmGlobal::GetDicts(); - RefPubDict = Dicts->GetDefaultPubDict(); + RefPubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); RefShaDict = (gdcmDict*)0; } @@ -2065,7 +2061,7 @@ gdcmHeaderEntry *gdcmParser::NewHeaderEntryByName(std::string Name) { gdcmDictEntry *NewTag = GetDictEntryByName(Name); if (!NewTag) - NewTag = Dicts->NewVirtualDictEntry(0xffff, 0xffff, "LO", "Unknown", Name); + NewTag = NewVirtualDictEntry(0xffff, 0xffff, "LO", "Unknown", Name); gdcmHeaderEntry* NewElVal = new gdcmHeaderEntry(NewTag); if (!NewElVal) @@ -2077,6 +2073,23 @@ gdcmHeaderEntry *gdcmParser::NewHeaderEntryByName(std::string Name) return NewElVal; } +/** + * \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 + */ +gdcmDictEntry *gdcmParser::NewVirtualDictEntry(guint16 group, guint16 element, + std::string vr, + std::string fourth, + std::string name) +{ + return gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,vr,fourth,name); +} + /** * \ingroup gdcmParser * \brief Build a new Element Value from all the low level arguments. @@ -2090,7 +2103,7 @@ 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 = Dicts->NewVirtualDictEntry(Group, Elem); + NewTag = NewVirtualDictEntry(Group, Elem); gdcmHeaderEntry* NewElVal = new gdcmHeaderEntry(NewTag); if (!NewElVal) @@ -2128,7 +2141,7 @@ gdcmHeaderEntry *gdcmParser::NewManualHeaderEntryToPubDict(std::string NewTagNam return NULL; } - NewEntry = Dicts->NewVirtualDictEntry(StuffGroup, FreeElem, + NewEntry = NewVirtualDictEntry(StuffGroup, FreeElem, VR, "GDCM", NewTagName); NewElVal = new gdcmHeaderEntry(NewEntry); AddHeaderEntry(NewElVal); diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 054c158a..61f125fa 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -48,13 +48,20 @@ 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 PrintPubDict (std::ostream & os = std::cout); - virtual void PrintShaDict (std::ostream & os = std::cout); + virtual void PrintPubEntry(std::ostream &os = std::cout); + virtual void PrintPubDict (std::ostream &os = std::cout); + virtual void PrintShaDict (std::ostream &os = std::cout); -// Standard values and informations contained in the header +// Standard values inline std::string GetFileName(void) {return filename;} +// Dictionnaries + gdcmDict *GetPubDict(void); + gdcmDict *GetShaDict(void); + bool SetShaDict(gdcmDict *dict); + bool SetShaDict(DictKey dictName); + +// Informations contained in the parser bool IsReadable(void); bool IsImplicitVRLittleEndianTransferSyntax(void); bool IsExplicitVRLittleEndianTransferSyntax(void); @@ -158,6 +165,10 @@ private: 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"); // Deprecated (Not used) gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName, @@ -167,33 +178,17 @@ private: // Refering underlying filename. std::string filename; - // Pointer to the Value Representation Hash Table which contains all - // the VR of the DICOM version3 public dictionary. - gdcmVR *dicom_vr; // Not a class member for thread-safety reasons - - // Pointer to the Transfert Syntax Hash Table which contains all - // the TS of the DICOM version3 public dictionary. - gdcmTS *dicom_ts; // Not a class member for thread-safety reasons - - // Pointer to global dictionary container - gdcmDictSet *Dicts; // Not a class member for thread-safety reasons - // Public dictionary used to parse this header gdcmDict *RefPubDict; - - // Optional "shadow dictionary" (private elements) used to parse this - // header + // Optional "shadow dictionary" (private elements) used to parse this header gdcmDict *RefShaDict; 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; - // for PrintHeader - int printLevel; - - int enableSequences; // Swap code e.g. little, big, bad-big, bad-little endian). Warning: // this code is not fixed during header parsing. @@ -204,6 +199,9 @@ private: // this upper bound is fixed to 1024 bytes (which might look reasonable // when one considers the definition of the various VR contents). guint32 MaxSizeLoadEntry; + + // for PrintHeader + int printLevel; }; //----------------------------------------------------------------------------- diff --git a/src/win32/gdcmdll.dsp b/src/win32/gdcmdll.dsp index be1f6b45..9581a86a 100644 --- a/src/win32/gdcmdll.dsp +++ b/src/win32/gdcmdll.dsp @@ -58,7 +58,7 @@ LINK32=link.exe # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy for test -PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ +PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Release\gdcmdll.lib ..\..\lib\ # End Special Build Tool !ELSEIF "$(CFG)" == "gdcmdll - Win32 Debug" @@ -90,7 +90,7 @@ LINK32=link.exe # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Desc=Copy for test -PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ +PostBuild_Cmds=copy ..\..\lib\gdcmdll.dll ..\..\gdcmPython\ copy ..\..\lib\gdcmdll.dll ..\..\test\ copy Debug\gdcmdll.lib ..\..\lib\ # End Special Build Tool !ENDIF @@ -132,10 +132,6 @@ SOURCE=..\gdcmHeaderEntry.cxx # End Source File # Begin Source File -SOURCE=..\gdcmHeaderEntrySet.cxx -# End Source File -# Begin Source File - SOURCE=..\gdcmHeaderHelper.cxx # End Source File # Begin Source File @@ -152,7 +148,11 @@ SOURCE=..\gdcmJpeg2000.cxx # End Source File # Begin Source File -SOURCE=..\gdcmParse.cxx +SOURCE=..\gdcmParsePixels.cxx +# End Source File +# Begin Source File + +SOURCE=..\gdcmParser.cxx # End Source File # Begin Source File @@ -212,11 +212,11 @@ SOURCE=..\gdcmHeaderEntry.h # End Source File # Begin Source File -SOURCE=..\gdcmHeaderEntrySet.h +SOURCE=..\gdcmHeaderHelper.h # End Source File # Begin Source File -SOURCE=..\gdcmHeaderHelper.h +SOURCE=..\gdcmParser.h # End Source File # Begin Source File diff --git a/vtk/win32/vtkgdcm.dsp b/vtk/win32/vtkgdcm.dsp index 17907c60..9a90affe 100644 --- a/vtk/win32/vtkgdcm.dsp +++ b/vtk/win32/vtkgdcm.dsp @@ -128,10 +128,6 @@ SOURCE=..\..\src\gdcmHeaderEntry.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmHeaderEntrySet.cxx -# End Source File -# Begin Source File - SOURCE=..\..\src\gdcmHeaderHelper.cxx # End Source File # Begin Source File @@ -148,7 +144,11 @@ SOURCE=..\..\src\gdcmJpeg2000.cxx # End Source File # Begin Source File -SOURCE=..\..\src\gdcmParse.cxx +SOURCE=..\..\src\gdcmParsePixels.cxx +# End Source File +# Begin Source File + +SOURCE=..\..\src\gdcmParser.cxx # End Source File # Begin Source File -- 2.48.1