1 /*=========================================================================
4 Module: $RCSfile: gdcmDictSet.cxx,v $
6 Date: $Date: 2004/08/31 14:24:47 $
7 Version: $Revision: 1.35 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDictSet.h"
20 #include "gdcmDebug.h"
22 #include <stdlib.h> // For getenv
24 //-----------------------------------------------------------------------------
25 // Constructor / Destructor
27 * \ingroup gdcmDictSet
28 * \brief The Dictionnary Set obtained with this constructor simply
29 * contains the Default Public dictionnary.
31 gdcmDictSet::gdcmDictSet()
33 DictPath = BuildDictPath();
34 std::string pubDictFile(DictPath);
35 pubDictFile += PUB_DICT_FILENAME;
36 Dicts[PUB_DICT_NAME] = new gdcmDict(pubDictFile);
40 * \ingroup gdcmDictSet
43 gdcmDictSet::~gdcmDictSet()
45 // Remove dictionnaries
46 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
48 gdcmDict *entryToDelete = tag->second;
57 // Remove virtual dictionnary entries
58 std::map<std::string,gdcmDictEntry *>::iterator it;
59 for(it = VirtualEntry.begin(); it != VirtualEntry.end(); ++it)
61 gdcmDictEntry *entry = it->second;
70 //-----------------------------------------------------------------------------
73 * \ingroup gdcmDictSet
74 * \brief Print, in an informal fashion, the list of all the dictionaries
75 * contained is this gdcmDictSet, along with their respective content.
76 * @param os Output stream used for printing.
78 void gdcmDictSet::Print(std::ostream& os)
80 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
82 os << "Printing dictionary " << dict->first << std::endl;
83 dict->second->Print(os);
87 //-----------------------------------------------------------------------------
90 * \ingroup gdcmDictSet
91 * \brief Consider all the entries of the public dicom dictionnary.
92 * Build all list of all the tag names of all those entries.
93 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
94 * @return A list of all entries of the public dicom dictionnary.
96 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames()
98 return GetDefaultPubDict()->GetDictEntryNames();
102 * \ingroup gdcmDictSet
104 * - Consider all the entries of the public dicom dictionnary.
105 * - Build an hashtable whose keys are the names of the groups
106 * (fourth field in each line of dictionary) and whose corresponding
107 * values are lists of all the dictionnary entries among that
108 * group. Note that apparently the Dicom standard doesn't explicitely
109 * define a name (as a string) for each group.
110 * - A typical usage of this method would be to enable a dynamic
111 * configuration of a Dicom file browser: the admin/user can
112 * select in the interface which Dicom tags should be displayed.
114 * - Dicom *doesn't* define any name for any 'categorie'
115 * (the dictionnary fourth field was formerly NIH defined
116 * -and no longer he is-
117 * and will be removed when Dicom provides us a text file
118 * with the 'official' Dictionnary, that would be more friendly
119 * than asking us to perform a line by line check of the dictionnary
120 * at the beginning of each year to -try to- guess the changes)
121 * - Therefore : please NEVER use that fourth field :-(
123 * @return An hashtable: whose keys are the names of the groups and whose
124 * corresponding values are lists of all the dictionnary entries
127 std::map<std::string, std::list<std::string> > *
128 gdcmDictSet::GetPubDictEntryNamesByCategory()
130 return GetDefaultPubDict()->GetDictEntryNamesByCategory();
134 * \ingroup gdcmDictSet
135 * \brief Loads a dictionary from a specified file, and add it
136 * to already the existing ones contained in this gdcmDictSet.
137 * @param fileName Absolute or relative filename containing the
138 * dictionary to load.
139 * @param name Symbolic name that be used as identifier of the newly
140 * created dictionary.
142 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string const & fileName,
143 DictKey const & name)
145 gdcmDict *newDict = new gdcmDict(fileName);
146 AppendDict(newDict, name);
152 * \ingroup gdcmDictSet
153 * \brief Retrieve the specified dictionary (when existing) from this
155 * @param dictName The symbolic name of the searched dictionary.
156 * \result The retrieved dictionary.
158 gdcmDict *gdcmDictSet::GetDict(DictKey const & dictName)
160 DictSetHT::iterator dict = Dicts.find(dictName);
161 if(dict != Dicts.end())
169 * \brief Retrieve the default reference DICOM V3 public dictionary.
170 * \result The retrieved default dictionary.
172 gdcmDict *gdcmDictSet::GetDefaultPubDict()
174 return GetDict(PUB_DICT_NAME);
178 * \brief Create a gdcmDictEntry which will be reference
180 * @return virtual entry
182 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(uint16_t group,
188 gdcmDictEntry* entry;
189 const std::string tag = gdcmDictEntry::TranslateToKey(group,element)
190 + "#" + vr + "#" + fourth + "#" + name;
191 std::map<std::string,gdcmDictEntry *>::iterator it;
193 it = VirtualEntry.find(tag);
194 if(it != VirtualEntry.end())
200 entry = new gdcmDictEntry(group, element, vr, fourth, name);
201 VirtualEntry[tag] = entry;
208 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
209 * path to directory containing the dictionnaries. When
210 * the environnement variable is absent the path is defaulted
212 * @return path to directory containing the dictionnaries
214 std::string gdcmDictSet::BuildDictPath()
216 std::string resultPath;
217 const char *envPath = 0;
218 envPath = getenv("GDCM_DICT_PATH");
220 if (envPath && (strlen(envPath) != 0))
222 resultPath = envPath;
223 if ( resultPath[resultPath.length()-1] != '/' )
227 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
228 "Dictionary path set from environnement");
232 resultPath = PUB_DICT_PATH;
238 //-----------------------------------------------------------------------------
240 bool gdcmDictSet::AppendDict(gdcmDict *newDict, DictKey const & name)
242 Dicts[name] = newDict;
247 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------