From: frog Date: Wed, 6 Nov 2002 22:48:40 +0000 (+0000) Subject: * Python wrapping process moved away from src/Makefile to X-Git-Tag: April2003~88 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=6351b90935bc5444536352964345f03e6fe21432;p=gdcm.git * Python wrapping process moved away from src/Makefile to newly created python/Makefile (as well as gdcm.i) * python/demo/test.py (that mirrors Test/test.cxx) is effective. * src/gdcmHeader::FindLength only looks for current vr when necessary. * src/gdcmDictSet.cxx: the dictionnaries directory path is now imported from the environement variable GDCM_DICT_PATH (when existing). * src/gdcmDict::GetTag bug fix. --- Frog --- diff --git a/ChangeLog b/ChangeLog index 4aea47dd..a2c75eb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-11-6 Eric Boix + * Python wrapping process moved away from src/Makefile to + newly created python/Makefile (as well as gdcm.i) + * python/demo/test.py (that mirrors Test/test.cxx) is effective. + * src/gdcmHeader::FindLength only looks for current vr when necessary. + * src/gdcmDictSet.cxx: the dictionnaries directory path is now imported + from the environement variable GDCM_DICT_PATH (when existing). + * src/gdcmDict::GetTag bug fix. + 2002-10-31 Eric Boix * Straightforward temporary fixes for swig to build the python wrappers. src/Makefile now has a python working entry [by working we mean diff --git a/src/Makefile b/src/Makefile index e28a8765..d2f92c56 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,28 +1,8 @@ - -###CC = gcc -###LINK = gcc -shared -o ptinpoly.so -SWIG = swig -SWIGFLAGS= -python -c++ - -PYTHON=python -PYTHON_PREFIX =`$(PYTHON) -c "import sys; print sys.exec_prefix"` -PYTHON_VERSION =`$(PYTHON) -c "import sys; print sys.version[:3]"` -PYTHON_INCLUDES="-I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)" - CXXFLAGS=`glib-config --cflags` CPPFLAGS=-g -Wall -Wunused-variable LDFLAGS=`glib-config --libs` -g -%_wrap.o : %_wrap.cxx - $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(PYTHON_INCLUDES) $< -o $@ -%_wrap.cxx : %.i - $(SWIG) $(SWIGFLAGS) $(PYTHON_INCLUDES) -o $@ $< -%.o : %.cxx - $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ - -all: gdcmlib.so - -gdcmlib.so: gdcmUtil.o \ +OBJECTS=gdcmUtil.o \ gdcmHeader.o \ gdcmElValue.o \ gdcmDictEntry.o \ @@ -31,12 +11,17 @@ gdcmlib.so: gdcmUtil.o \ gdcmElValSet.o \ gdcmHeaderIdo.o \ gdcmFile.o - g++ -shared -o gdcmlib.so $^ $(LDFLAGS) -python: gdcmlib.so gdcm_wrap.o - g++ -shared $^ -o _gdcm.so +%.o : %.cxx + $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ -clean: - rm -f *_wrap* *.so *.o *.pyc gdcm.py +all: libgdcm.so libgdcm.a -.SECONDARY: dcm_wrap.cxx +libgdcm.so: $(OBJECTS) + g++ -shared -o $@ $^ $(LDFLAGS) + +libgdcm.a: $(OBJECTS) + ar cr $@ $^ + +clean: + rm -f *.so *.a *.o diff --git a/src/gdcm.h b/src/gdcm.h index 80e98048..421ca6c6 100644 --- a/src/gdcm.h +++ b/src/gdcm.h @@ -92,7 +92,7 @@ class gdcmDict { string filename; TagHT entries; public: - gdcmDict(char *FileName); // Read Dict from disk + gdcmDict(const char* FileName); // Read Dict from disk // TODO Swig int AppendEntry(gdcmDictEntry* NewEntry); gdcmDictEntry * GetTag(guint32 group, guint32 element); void Print(ostream&); @@ -102,15 +102,15 @@ public: // should avoid : // * reloading an allready loaded dictionary. // * having many in memory representations of the same dictionary. -#define PUBDICTNAME "DicomV3Dict" -#define PUBDICTFILENAME "../Dicts/dicomV3.dic" typedef string DictKey; typedef map DictSetHT; class gdcmDictSet { private: + string DictPath; // Directory path to dictionaries DictSetHT dicts; int AppendDict(gdcmDict* NewDict); - int LoadDictFromFile(char* filename, DictKey); + int LoadDictFromFile(string filename, DictKey); + void SetDictPath(void); public: gdcmDictSet(void); // loads THE DICOM v3 dictionary // TODO Swig int LoadDictFromFile(string filename); @@ -262,7 +262,7 @@ public: // of C/C++ vs Python). // TODO Swig string GetPubElValRepByName(string TagName); // TODO Swig string GetPubElValRepByNumber(guint16 group, guint16 element); - void PrintPubElVal(ostream &); + void PrintPubElVal(ostream & os = std::cout); void PrintPubDict(ostream &); // Same thing with the shadow : diff --git a/src/gdcm.i b/src/gdcm.i deleted file mode 100644 index 4ec46001..00000000 --- a/src/gdcm.i +++ /dev/null @@ -1,7 +0,0 @@ -%module gdcm -%{ -#include "gdcm.h" -%} -%rename(new_dcmHeader_c) dcmHeader::dcmHeader(char*); - -%include gdcm.h diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 271a2346..3514749e 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -2,10 +2,9 @@ #include "gdcm.h" #include "gdcmUtil.h" -gdcmDict::gdcmDict(char * FileName) { +gdcmDict::gdcmDict(const char* FileName) { std::ifstream from(FileName); - dbg.Error(!from, "gdcmDictSet::gdcmDictSet:", - "can't open dictionary"); + dbg.Error(!from, "gdcmDict::gdcmDict: can't open dictionary", FileName); guint16 group, element; // CLEANME : use defines for all those constants char buff[1024]; @@ -40,6 +39,10 @@ void gdcmDict::Print(ostream& os) { gdcmDictEntry * gdcmDict::GetTag(guint32 group, guint32 element) { TagKey key = gdcmDictEntry::TranslateToKey(group, element); - TagHT::iterator found = entries.find(key); - return found->second; + if ( ! entries.count(key)) + return (gdcmDictEntry*)0; + if (entries.count(key) > 1) + dbg.Verbose(0, "gdcmDict::GetTag", + "multiple entries for this key (FIXME) !"); + return entries.find(key)->second; } diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index ed4bdf9b..c8f594b3 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -1,21 +1,35 @@ #include +#include // For getenv #include "gdcm.h" #include "gdcmUtil.h" +#define PUB_DICT_NAME "DicomV3Dict" +#define PUB_DICT_PATH "../Dicts/" +#define PUB_DICT_FILENAME "dicomV3.dic" gdcmDictSet::gdcmDictSet(void) { + SetDictPath(); if (! LoadDicomV3Dict()) return; } +void gdcmDictSet::SetDictPath(void) { + const char* EnvPath = (char*)0; + EnvPath = getenv("GDCM_DICT_PATH"); + if (EnvPath && (strlen(EnvPath) != 0)) + DictPath = EnvPath; + else + DictPath = PUB_DICT_PATH; +} + int gdcmDictSet::LoadDicomV3Dict(void) { - if (dicts.count(PUBDICTNAME)) + if (dicts.count(PUB_DICT_NAME)) return 1; - return LoadDictFromFile(PUBDICTFILENAME, PUBDICTNAME); + return LoadDictFromFile(DictPath + PUB_DICT_FILENAME, PUB_DICT_NAME); } -int gdcmDictSet::LoadDictFromFile(char * FileName, DictKey Name) { - gdcmDict *NewDict = new gdcmDict(FileName); +int gdcmDictSet::LoadDictFromFile(string FileName, DictKey Name) { + gdcmDict *NewDict = new gdcmDict(FileName.c_str()); dicts[Name] = NewDict; } @@ -32,5 +46,5 @@ gdcmDict * gdcmDictSet::GetDict(DictKey DictName) { } gdcmDict * gdcmDictSet::GetDefaultPublicDict() { - return GetDict(PUBDICTNAME); + return GetDict(PUB_DICT_NAME); } diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index cd5785b1..6eb47c6f 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -302,11 +302,10 @@ void gdcmHeader::FindLength( ElValue * ElVal) { guint32 length32; guint16 length16; - string vr = ElVal->GetVR(); - - if ( (filetype == ExplicitVR) && (vr != "Implicit") ) { - if ( ( vr == "OB" ) || ( vr == "OW" ) - || ( vr == "SQ" ) || ( vr == "UN" ) ) { + if (filetype == ExplicitVR) { + string vr = ElVal->GetVR(); + if ( (vr != "Implicit") + && ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) ) { // The following two bytes are reserved, so we skip them, // and we proceed on reading the length on 4 bytes. @@ -624,7 +623,7 @@ void gdcmHeader::LoadElements(void) { LoadElementValue(tag->second); } -void gdcmHeader::PrintPubElVal(ostream & os) { +void gdcmHeader::PrintPubElVal(ostream & os = std::cout) { PubElVals.Print(os); }