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"
15 * \ingroup gdcmDictSet
16 * \brief Consider all the entries of the public dicom dictionnary.
17 * Build all list of all the tag names of all those entries.
18 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
19 * @return A list of all entries of the public dicom dictionnary.
21 std::list<std::string> * gdcmDictSet::GetPubDictTagNames(void) {
22 std::list<std::string> * Result = new std::list<std::string>;
23 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
25 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
26 Result->push_back( tag->second->GetName() );
32 * \ingroup gdcmDictSet
33 * \brief Consider all the entries of the public dicom dictionnary.
34 * Build an hashtable whose keys are the names of the groups
35 * (fourth field in each line of dictionary) and whose corresponding
36 * values are lists of all the dictionnary entries among that
37 * group. Note that apparently the Dicom standard doesn't explicitely
38 * define a name (as a string) for each group.
39 * A typical usage of this method would be to enable a dynamic
40 * configuration of a Dicom file browser: the admin/user can
41 * select in the interface which Dicom tags should be displayed.
42 * \warning Dicom *doesn't* define any name for any 'categorie'
43 * (the dictionnary fourth field was formerly NIH defined
44 * - and no longer he is-
45 * and will be removed when Dicom provides us a text file
46 * with the 'official' Dictionnary, that would be more friendly
47 * than asking us to perform a line by line check od thhe dictionnary
48 * at the beginning of each year to -try to- guess the changes)
49 * Therefore : please NEVER use that fourth field :-(
51 * @return An hashtable: whose keys are the names of the groups and whose
52 * corresponding values are lists of all the dictionnary entries
55 std::map<std::string, std::list<std::string> > * gdcmDictSet::GetPubDictTagNamesByCategory(void) {
56 std::map<std::string, std::list<std::string> > * Result = new std::map<std::string, std::list<std::string> >;
57 TagKeyHT entries = GetDefaultPubDict()->GetEntries();
59 for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){
60 (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName());
66 * \ingroup gdcmDictSet
67 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
68 * path to directory containing the dictionnaries. When
69 * the environnement variable is absent the path is defaulted
72 std::string gdcmDictSet::BuildDictPath(void) {
73 std::string ResultPath;
74 const char* EnvPath = (char*)0;
75 EnvPath = getenv("GDCM_DICT_PATH");
76 if (EnvPath && (strlen(EnvPath) != 0)) {
78 if (ResultPath[ResultPath.length() -1] != '/' )
80 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
81 "Dictionary path set from environnement");
83 ResultPath = PUB_DICT_PATH;
88 * \ingroup gdcmDictSet
89 * \brief The Dictionnary Set obtained with this constructor simply
90 * contains the Default Public dictionnary.
92 gdcmDictSet::gdcmDictSet(void) {
93 DictPath = BuildDictPath();
94 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
95 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
98 gdcmDictSet::~gdcmDictSet() {
99 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag) {
100 gdcmDict* EntryToDelete = tag->second;
102 delete EntryToDelete;
108 * \ingroup gdcmDictSet
109 * \brief Loads a dictionary from a specified file, and add it
110 * to already the existing ones contained in this gdcmDictSet.
111 * @param FileName Absolute or relative filename containing the
112 * dictionary to load.
113 * @param Name Symbolic name that be used as identifier of the newly
114 * created dictionary.
116 void gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name) {
117 gdcmDict *NewDict = new gdcmDict(FileName);
118 Dicts[Name] = NewDict;
122 * \ingroup gdcmDictSet
123 * \brief Print, in an informal fashion, the list of all the dictionaries
124 * contained is this gdcmDictSet, along with their respective content.
125 * @param os Output stream used for printing.
127 void gdcmDictSet::Print(std::ostream& os) {
128 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict){
129 os << "Printing dictionary " << dict->first << std::endl;
130 dict->second->Print(os);
135 * \ingroup gdcmDictSet
136 * \brief Retrieve the specified dictionary (when existing) from this
138 * @param DictName The synbolic name of the searched dictionary.
139 * \result The retrieved dictionary.
141 gdcmDict * gdcmDictSet::GetDict(DictKey DictName) {
142 DictSetHT::iterator dict = Dicts.find(DictName);
147 * \ingroup gdcmDictSet
148 * \brief Retrieve the default reference DICOM V3 public dictionary.
149 * \result The retrieved default dictionary.
151 gdcmDict * gdcmDictSet::GetDefaultPubDict() {
152 return GetDict(PUB_DICT_NAME);