2 //-----------------------------------------------------------------------------
3 #include "gdcmDictSet.h"
6 #include <stdlib.h> // For getenv
8 #define PUB_DICT_NAME "DicomV3Dict"
10 # define PUB_DICT_PATH "../Dicts/"
12 #define PUB_DICT_FILENAME "dicomV3.dic"
14 //-----------------------------------------------------------------------------
15 // Constructor / Destructor
17 * \ingroup gdcmDictSet
18 * \brief The Dictionnary Set obtained with this constructor simply
19 * contains the Default Public dictionnary.
21 gdcmDictSet::gdcmDictSet(void)
23 DictPath = BuildDictPath();
24 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
25 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
29 * \ingroup gdcmDictSet
32 gdcmDictSet::~gdcmDictSet()
34 // Remove dictionnaries
35 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
37 gdcmDict *EntryToDelete = tag->second;
44 // Remove virtual dictionnary entries
45 std::map<std::string,gdcmDictEntry *>::iterator it;
46 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
48 gdcmDictEntry *Entry = it->second;
55 //-----------------------------------------------------------------------------
58 * \ingroup gdcmDictSet
59 * \brief Print, in an informal fashion, the list of all the dictionaries
60 * contained is this gdcmDictSet, along with their respective content.
61 * @param os Output stream used for printing.
63 void gdcmDictSet::Print(std::ostream& os)
65 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
67 os << "Printing dictionary " << dict->first << std::endl;
68 dict->second->Print(os);
72 //-----------------------------------------------------------------------------
75 * \ingroup gdcmDictSet
76 * \brief Consider all the entries of the public dicom dictionnary.
77 * Build all list of all the tag names of all those entries.
78 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
79 * @return A list of all entries of the public dicom dictionnary.
81 std::list<std::string> *gdcmDictSet::GetPubDictTagNames(void)
83 std::list<std::string> *Result = new std::list<std::string>;
84 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
86 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag)
88 Result->push_back( tag->second->GetName() );
94 * \ingroup gdcmDictSet
95 * \brief Consider all the entries of the public dicom dictionnary.
96 * Build an hashtable whose keys are the names of the groups
97 * (fourth field in each line of dictionary) and whose corresponding
98 * values are lists of all the dictionnary entries among that
99 * group. Note that apparently the Dicom standard doesn't explicitely
100 * define a name (as a string) for each group.
101 * A typical usage of this method would be to enable a dynamic
102 * configuration of a Dicom file browser: the admin/user can
103 * select in the interface which Dicom tags should be displayed.
104 * \warning Dicom *doesn't* define any name for any 'categorie'
105 * (the dictionnary fourth field was formerly NIH defined
106 * - and no longer he is-
107 * and will be removed when Dicom provides us a text file
108 * with the 'official' Dictionnary, that would be more friendly
109 * than asking us to perform a line by line check of the dictionnary
110 * at the beginning of each year to -try to- guess the changes)
111 * Therefore : please NEVER use that fourth field :-(
113 * @return An hashtable: whose keys are the names of the groups and whose
114 * corresponding values are lists of all the dictionnary entries
117 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictTagNamesByCategory(void)
119 std::map<std::string, std::list<std::string> > *Result = new std::map<std::string, std::list<std::string> >;
120 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
122 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag)
124 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
130 * \ingroup gdcmDictSet
131 * \brief Loads a dictionary from a specified file, and add it
132 * to already the existing ones contained in this gdcmDictSet.
133 * @param FileName Absolute or relative filename containing the
134 * dictionary to load.
135 * @param Name Symbolic name that be used as identifier of the newly
136 * created dictionary.
138 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
140 gdcmDict *NewDict = new gdcmDict(FileName);
141 AppendDict(NewDict,Name);
145 * \ingroup gdcmDictSet
146 * \brief Retrieve the specified dictionary (when existing) from this
148 * @param DictName The symbolic name of the searched dictionary.
149 * \result The retrieved dictionary.
151 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
153 DictSetHT::iterator dict = Dicts.find(DictName);
154 if(dict!=Dicts.end())
160 * \ingroup gdcmDictSet
161 * \brief Retrieve the default reference DICOM V3 public dictionary.
162 * \result The retrieved default dictionary.
164 gdcmDict *gdcmDictSet::GetDefaultPubDict()
166 return GetDict(PUB_DICT_NAME);
170 * \ingroup gdcmDictSet
171 * \brief Create a gdcmDictEntry which will be reference
173 * @return virtual entry
175 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
176 std::string vr,std::string fourth,
179 gdcmDictEntry *entry;
180 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+vr;
181 std::map<std::string,gdcmDictEntry *>::iterator it;
183 it=virtualEntry.find(tag);
184 if(it!=virtualEntry.end())
190 entry=new gdcmDictEntry(group,element,vr,fourth,name);
191 virtualEntry[tag]=entry;
197 * \ingroup gdcmDictSet
198 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
199 * path to directory containing the dictionnaries. When
200 * the environnement variable is absent the path is defaulted
202 * @return path to directory containing the dictionnaries
204 std::string gdcmDictSet::BuildDictPath(void)
206 std::string ResultPath;
207 const char *EnvPath = (char*)0;
208 EnvPath = getenv("GDCM_DICT_PATH");
209 if (EnvPath && (strlen(EnvPath) != 0))
211 ResultPath = EnvPath;
212 if (ResultPath[ResultPath.length() -1] != '/' )
214 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
215 "Dictionary path set from environnement");
218 ResultPath = PUB_DICT_PATH;
222 //-----------------------------------------------------------------------------
224 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
226 Dicts[Name] = NewDict;
230 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------