X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDictSet.cxx;h=56482cb300f1d2e505c96d93873bbc5dc6c9f05a;hb=d84a0a9e04fe65dc2ff732d75731fa403d0e02b8;hp=ed4bdf9be3a8aecc3d371380fe7c0bf3887b35a9;hpb=51b61705e90b352de08519835fa1c63b81bca616;p=gdcm.git diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index ed4bdf9b..56482cb3 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -1,36 +1,114 @@ +// gdcmDictEntry + #include +#include // For getenv #include "gdcm.h" #include "gdcmUtil.h" +#define PUB_DICT_NAME "DicomV3Dict" +#ifndef PUB_DICT_PATH +# define PUB_DICT_PATH "../Dicts/" +#endif +#define PUB_DICT_FILENAME "dicomV3.dic" -gdcmDictSet::gdcmDictSet(void) { - if (! LoadDicomV3Dict()) - return; +string gdcmDictSet::DictPath = gdcmDictSet::BuildDictPath(); +gdcmDict* gdcmDictSet::DefaultPubDict = gdcmDictSet::LoadDefaultPubDict(); + +/** + * \ingroup gdcmDictSet + * \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. + */ +list * gdcmDictSet::GetPubDictTagNames(void) { + list * Result = new list; + TagKeyHT entries = gdcmDictSet::DefaultPubDict->GetEntries(); + + for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){ + Result->push_back( tag->second->GetName() ); + } + return Result; +} + +/** + * \ingroup gdcmDictSet + * \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. + * @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. + */ +map > * gdcmDictSet::GetPubDictTagNamesByCategory(void) { + map > * Result = new map >; + TagKeyHT entries = gdcmDictSet::DefaultPubDict->GetEntries(); + + for (TagKeyHT::iterator tag = entries.begin(); tag != entries.end(); ++tag){ + (*Result)[tag->second->GetFourth()].push_back(tag->second->GetName()); + } + return Result; } -int gdcmDictSet::LoadDicomV3Dict(void) { - if (dicts.count(PUBDICTNAME)) - return 1; - return LoadDictFromFile(PUBDICTFILENAME, PUBDICTNAME); +/** + * \ingroup gdcmDictSet + * \brief Obtain from the GDCM_DICT_PATH environnement variable the + * path to directory containing the dictionnaries. When + * the environnement variable is absent the path is defaulted + * to "../Dicts/". + */ +string gdcmDictSet::BuildDictPath(void) { + string ResultPath; + const char* EnvPath = (char*)0; + EnvPath = getenv("GDCM_DICT_PATH"); + if (EnvPath && (strlen(EnvPath) != 0)) { + ResultPath = EnvPath; + if (ResultPath[ResultPath.length() -1] != '/' ) + ResultPath += '/'; + dbg.Verbose(1, "gdcmDictSet::BuildDictPath:", + "Dictionary path set from environnement"); + } else + ResultPath = PUB_DICT_PATH; + return ResultPath; +} + +gdcmDict* gdcmDictSet::LoadDefaultPubDict(void) { + string PubDictFile = gdcmDictSet::DictPath + PUB_DICT_FILENAME; + return new gdcmDict(PubDictFile.c_str()); +} + +/** + * \ingroup gdcmDictSet + * \brief The Dictionnary Set obtained with this constructor simply + * contains the Default Public dictionnary. + */ +gdcmDictSet::gdcmDictSet(void) { + dicts[PUB_DICT_NAME] = DefaultPubDict; } -int gdcmDictSet::LoadDictFromFile(char * FileName, DictKey Name) { - gdcmDict *NewDict = new gdcmDict(FileName); - dicts[Name] = NewDict; +void gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) { + gdcmDict *NewDict = new gdcmDict(FileName.c_str()); + dicts[Name] = NewDict; } void gdcmDictSet::Print(ostream& os) { - for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){ - os << "Printing dictionary " << dict->first << " \n"; - dict->second->Print(os); - } + for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){ + os << "Printing dictionary " << dict->first << " \n"; + dict->second->Print(os); + } } gdcmDict * gdcmDictSet::GetDict(DictKey DictName) { - DictSetHT::iterator dict = dicts.find(DictName); - return dict->second; + DictSetHT::iterator dict = dicts.find(DictName); + return dict->second; } -gdcmDict * gdcmDictSet::GetDefaultPublicDict() { - return GetDict(PUBDICTNAME); +gdcmDict * gdcmDictSet::GetDefaultPubDict() { + return GetDict(PUB_DICT_NAME); }