From: frog Date: Mon, 10 Mar 2003 10:16:40 +0000 (+0000) Subject: * gdcmPython/__init__.py doesn't crash anymore when running in X-Git-Tag: April2003~29 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d74d6412b83d9f596597b54c3413d1a6ee9fb617;p=gdcm.git * gdcmPython/__init__.py doesn't crash anymore when running in in InstallMode or PreInstallMode but with an environement given value of GDCM_DICT_PATH. * src/gdcmDictSet.[cxx/h] coding style. --- Frog --- diff --git a/ChangeLog b/ChangeLog index 38d0686c..8fc0034d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-03-10 Eric Boix + * gdcmPython/__init__.py doesn't crash anymore when running in + in InstallMode or PreInstallMode but with an environement given + value of GDCM_DICT_PATH. + * src/gdcmDictSet.[cxx/h] coding style. + 2003-03-06 Eric Boix * src/gdcmHeader.h and gdcmHeader.cxx Coding style + doxigenation. * src/gdcm.h general comments moved to TODO, and README diff --git a/TODO b/TODO index 5ca3f531..420485ae 100644 --- a/TODO +++ b/TODO @@ -30,3 +30,7 @@ sous forme d'une liste. * gdcmHeader::CheckSwap() dans le cas ACR pas propre, degager tout de suite si on a deduit que c'en est pas... +* python /usr/lib/python2.2/site-packages/DaVaW/demo/dvwDcmReader.py + and load image /home/frog/cvs/DCMlib/Data/CT-MONO2-16-ankle.dcm + will yield wrong coloring scheme as opposed to + affim filein=/home/frog/cvs/DCMlib/Data/CT-MONO2-16-ankle.dcm diff --git a/gdcmPython/__init__.py b/gdcmPython/__init__.py index f454cdb1..34ce06f7 100644 --- a/gdcmPython/__init__.py +++ b/gdcmPython/__init__.py @@ -8,54 +8,56 @@ import os, sys # the standard dictionary i.e. the file dicomV3.dic. try: - ### First consider the environnement variable. - os.environ["GDCM_DICT_PATH"] - if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"], - "dicomV3.dic")): - raise KeyError + ### First consider the environnement variable. + os.environ["GDCM_DICT_PATH"] + if not os.path.isfile(os.path.join(os.environ["GDCM_DICT_PATH"], + "dicomV3.dic")): + raise KeyError except KeyError: - # When environnement variable is unavailable assume the package was - # properly installed i.e. the layout is such that the directory containing - # the dictionaries is BELOW (the root is at the top) the current file. - # Note: when importing this __init__ file the pathes are relative to the - # invocation directory. In order to get them relative to the package - # (or more simply to this file) we rely on the __path__ variable. - InstallModePath = os.path.join(__path__[0], "Dicts/") - if os.path.isfile(os.path.join(InstallModePath, "dicomV3.dic")): - os.environ["GDCM_DICT_PATH"] = InstallModePath - PreInstallModePath = None - else: - # When both environnement variable and proper package installation - # strategy fail we eventually consider the pre-installation mode - # i.e. when developpers are toying in a CVS tree. In this case - # the layout is such that the directory containing the dictionaries is - # ABOVE (the root is at the top) the current directory. - PreInstallModePath = os.path.join(__path__[0], "..", "Dicts/") - if os.path.isfile(os.path.join(PreInstallModePath, "dicomV3.dic")): - os.environ["GDCM_DICT_PATH"] = PreInstallModePath - InstallModePath = None - else: - print "Unfound gdcm dictionaries path" - sys.exit(1) + # When environnement variable is unavailable assume the package was + # properly installed i.e. the layout is such that the directory containing + # the dictionaries is BELOW (the root is at the top) the current file. + # Note: when importing this __init__ file the pathes are relative to the + # invocation directory. In order to get them relative to the package + # (or more simply to this file) we rely on the __path__ variable. + InstallModePath = os.path.join(__path__[0], "Dicts/") + if os.path.isfile(os.path.join(InstallModePath, "dicomV3.dic")): + os.environ["GDCM_DICT_PATH"] = InstallModePath + PreInstallModePath = None + else: + # When both environnement variable and proper package installation + # strategy fail we eventually consider the pre-installation mode + # i.e. when developpers are toying in a CVS tree. In this case + # the layout is such that the directory containing the dictionaries is + # ABOVE (the root is at the top) the current directory. + PreInstallModePath = os.path.join(__path__[0], "..", "Dicts/") + if os.path.isfile(os.path.join(PreInstallModePath, "dicomV3.dic")): + os.environ["GDCM_DICT_PATH"] = PreInstallModePath + InstallModePath = None + else: + print "Unfound gdcm dictionaries path" + sys.exit(1) ### Set up the path to the data images (for the test suite and the demo # examples). As for GDCM_DICT_PATH we offer both proper python package # installation scheme and the pre-install mode (see above). -if InstallModePath: - GDCM_DATA_PATH = os.path.join(__path__[0], "Data") +InstallModePath = os.path.join(__path__[0], "Data") +if os.path.isfile(os.path.join(InstallModePath, "test.acr")): + os.environ["GDCM_DATA_PATH"] = InstallModePath else: - if PreInstallModePath: - GDCM_DATA_PATH = os.path.join(__path__[0], "..","Data") - else: - print "Unfound data path" - sys.exit(1) + PreInstallModePath = os.path.join(__path__[0], "..", "Data") + if os.path.isfile(os.path.join(PreInstallModePath, "test.acr")): + os.environ["GDCM_DATA_PATH"] = PreInstallModePath + else: + print "Unfound data path" + sys.exit(1) ### Import the swig generated shadow classes. try: - import gdcm + import gdcm except ImportError,e: - print e - raise ImportError, "gdcm extension not imported." + print e + raise ImportError, "gdcm extension not imported." ### Expose only the necessary stuff gdcmHeader = gdcm.gdcmHeader diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index 41a39c3f..2d6d95fa 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -78,6 +78,11 @@ string gdcmDictSet::BuildDictPath(void) { return ResultPath; } +/** + * \ingroup gdcmDictSet + * \brief Loads the default public DICOM V3 dictionary as a gdcmDict. + * \return The newly build reference public dictionary. + */ gdcmDict* gdcmDictSet::LoadDefaultPubDict(void) { string PubDictFile = gdcmDictSet::DictPath + PUB_DICT_FILENAME; return new gdcmDict(PubDictFile.c_str()); @@ -92,11 +97,26 @@ gdcmDictSet::gdcmDictSet(void) { dicts[PUB_DICT_NAME] = DefaultPubDict; } +/** + * \ingroup gdcmDictSet + * \brief Loads a dictionary from a specified file, and add it + * to allready the existing ones contained in this gdcmDictSet. + * @param FileName Absolute or relative filename containing the + * dictionary to load. + * @param Name Symbolic name that be used as identifier of the newly + * created dictionary. + */ void gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) { gdcmDict *NewDict = new gdcmDict(FileName.c_str()); dicts[Name] = NewDict; } +/** + * \ingroup gdcmDictSet + * \brief Print, in an informal fashion, the list of all the dictionaries + * contained is this gdcmDictSet, along with their respective content. + * @param os Output stream used for printing. + */ void gdcmDictSet::Print(ostream& os) { for (DictSetHT::iterator dict = dicts.begin(); dict != dicts.end(); ++dict){ os << "Printing dictionary " << dict->first << " \n"; @@ -104,11 +124,23 @@ void gdcmDictSet::Print(ostream& os) { } } +/** + * \ingroup gdcmDictSet + * \brief Retrieve the specified dictionary (when existing) from this + * gdcmDictSet. + * @param DictName The synbolic name of the searched dictionary. + * \result The retrieved dictionary. + */ gdcmDict * gdcmDictSet::GetDict(DictKey DictName) { DictSetHT::iterator dict = dicts.find(DictName); return dict->second; } +/** + * \ingroup gdcmDictSet + * \brief Retrieve the default reference DICOM V3 public dictionary. + * \result The retrieved default dictionary. + */ gdcmDict * gdcmDictSet::GetDefaultPubDict() { return GetDict(PUB_DICT_NAME); } diff --git a/src/gdcmDictSet.h b/src/gdcmDictSet.h index 0e2aed0b..3ccc09d9 100644 --- a/src/gdcmDictSet.h +++ b/src/gdcmDictSet.h @@ -5,25 +5,27 @@ #include #include -#include "gdcmCommon.h" #include "gdcmDict.h" -//////////////////////////////////////////////////////////////////////////// -// Container for managing a set of loaded dictionaries. Sharing dictionaries -// should avoid : -// * reloading an allready loaded dictionary, -// * having many in memory representations of the same dictionary. - typedef string DictKey; typedef map DictSetHT; +/* + * \defgroup gdcmDictSet + * \brief Container for managing a set of loaded dictionaries. + * \note Hopefully, sharing dictionaries should avoid + * \par reloading an allready loaded dictionary (saving time) + * \par having many in memory representations of the same dictionary + * (saving memory). + */ class GDCM_EXPORT gdcmDictSet { private: DictSetHT dicts; int AppendDict(gdcmDict* NewDict); void LoadDictFromFile(string filename, DictKey); private: - static string DictPath; // Directory path to dictionaries + /// Directory path to dictionaries + static string DictPath; static string BuildDictPath(void); static gdcmDict* DefaultPubDict; public: @@ -31,7 +33,6 @@ public: static map >* GetPubDictTagNamesByCategory(void); static gdcmDict* LoadDefaultPubDict(void); - gdcmDictSet(void); // TODO Swig int LoadDictFromFile(string filename); // QUESTION: the following function might not be thread safe !? Maybe // we need some mutex here, to avoid concurent creation of @@ -39,7 +40,7 @@ public: // TODO Swig int LoadDictFromName(string filename); // TODO Swig int LoadAllDictFromDirectory(string DirectoryName); // TODO Swig string* GetAllDictNames(); - // + gdcmDictSet(void); void Print(ostream&); gdcmDict* GetDict(DictKey DictName); gdcmDict* GetDefaultPubDict(void); diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index f46a12c6..6b665031 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -14,10 +14,10 @@ typedef string VRKey; typedef string VRAtr; typedef map VRHT; // Value Representation Hash Table -/// \brief The purpous of an instance of gdcmHeader is to act as a container of -/// all the DICOM elements and their corresponding values (and -/// additionaly the corresponding DICOM dictionary entry) of the header -/// of a DICOM file. +/// The purpose of an instance of gdcmHeader is to act as a container of +/// all the DICOM elements and their corresponding values (and +/// additionaly the corresponding DICOM dictionary entry) of the header +/// of a DICOM file. /// /// The typical usage of instances of class gdcmHeader is to classify a set of /// dicom files according to header information e.g. to create a file hierarchy @@ -42,7 +42,8 @@ private: gdcmDictSet* Dicts; /// Public dictionary used to parse this header gdcmDict* RefPubDict; - /// Optional "shadow dictionary" (private elements) used to parse this header + /// Optional "shadow dictionary" (private elements) used to parse this + /// header gdcmDict* RefShaDict; /// ELement VALueS parsed with the PUBlic dictionary.