4 #include <stdlib.h> // For getenv
6 #include "gdcmDictSet.h"
8 #define PUB_DICT_NAME "DicomV3Dict"
10 # define PUB_DICT_PATH "../Dicts/"
12 #define PUB_DICT_FILENAME "dicomV3.dic"
14 string gdcmDictSet::DictPath = gdcmDictSet::BuildDictPath();
15 gdcmDict* gdcmDictSet::DefaultPubDict = gdcmDictSet::LoadDefaultPubDict();
18 * \ingroup gdcmDictSet
19 * \brief Consider all the entries of the public dicom dictionnary.
20 * Build all list of all the tag names of all those entries.
21 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
22 * @return A list of all entries of the public dicom dictionnary.
24 list<string> * gdcmDictSet::GetPubDictTagNames(void) {
25 list<string> * Result = new list<string>;
26 TagKeyHT entries = gdcmDictSet::DefaultPubDict->GetEntries();
28 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
29 Result->push_back( tag->second->GetName() );
35 * \ingroup gdcmDictSet
36 * \brief Consider all the entries of the public dicom dictionnary.
37 * Build an hashtable whose keys are the names of the groups
38 * (fourth field in each line of dictionary) and whose corresponding
39 * values are lists of all the dictionnary entries among that
40 * group. Note that apparently the Dicom standard doesn't explicitely
41 * define a name (as a string) for each group.
42 * A typical usage of this method would be to enable a dynamic
43 * configuration of a Dicom file browser: the admin/user can
44 * select in the interface which Dicom tags should be displayed.
45 * @return An hashtable: whose keys are the names of the groups and whose
46 * corresponding values are lists of all the dictionnary entries
49 map<string, list<string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
50 map<string, list<string> > * Result = new map<string, list<string> >;
51 TagKeyHT entries = gdcmDictSet::DefaultPubDict->GetEntries();
53 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
54 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
60 * \ingroup gdcmDictSet
61 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
62 * path to directory containing the dictionnaries. When
63 * the environnement variable is absent the path is defaulted
66 string gdcmDictSet::BuildDictPath(void) {
68 const char* EnvPath = (char*)0;
69 EnvPath = getenv("GDCM_DICT_PATH");
70 if (EnvPath && (strlen(EnvPath) != 0)) {
72 if (ResultPath[ResultPath.length() -1] != '/' )
74 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
75 "Dictionary path set from environnement");
77 ResultPath = PUB_DICT_PATH;
82 * \ingroup gdcmDictSet
83 * \brief Loads the default public DICOM V3 dictionary as a gdcmDict.
84 * \return The newly build reference public dictionary.
86 gdcmDict* gdcmDictSet::LoadDefaultPubDict(void) {
87 string PubDictFile = gdcmDictSet::DictPath + PUB_DICT_FILENAME;
88 return new gdcmDict(PubDictFile.c_str());
92 * \ingroup gdcmDictSet
93 * \brief The Dictionnary Set obtained with this constructor simply
94 * contains the Default Public dictionnary.
96 gdcmDictSet::gdcmDictSet(void) {
97 dicts[PUB_DICT_NAME] = DefaultPubDict;
101 * \ingroup gdcmDictSet
102 * \brief Loads a dictionary from a specified file, and add it
103 * to allready the existing ones contained in this gdcmDictSet.
104 * @param FileName Absolute or relative filename containing the
105 * dictionary to load.
106 * @param Name Symbolic name that be used as identifier of the newly
107 * created dictionary.
109 void gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) {
110 gdcmDict *NewDict = new gdcmDict(FileName.c_str());
111 dicts[Name] = NewDict;
115 * \ingroup gdcmDictSet
116 * \brief Print, in an informal fashion, the list of all the dictionaries
117 * contained is this gdcmDictSet, along with their respective content.
118 * @param os Output stream used for printing.
120 void gdcmDictSet::Print(ostream& os) {
121 for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){
122 os << "Printing dictionary " << dict->first << " \n";
123 dict->second->Print(os);
128 * \ingroup gdcmDictSet
129 * \brief Retrieve the specified dictionary (when existing) from this
131 * @param DictName The synbolic name of the searched dictionary.
132 * \result The retrieved dictionary.
134 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
135 DictSetHT::iterator dict = dicts.find(DictName);
140 * \ingroup gdcmDictSet
141 * \brief Retrieve the default reference DICOM V3 public dictionary.
142 * \result The retrieved default dictionary.
144 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
145 return GetDict(PUB_DICT_NAME);