]> Creatis software - gdcm.git/commitdiff
* Python wrapping process moved away from src/Makefile to
authorfrog <frog>
Wed, 6 Nov 2002 22:48:40 +0000 (22:48 +0000)
committerfrog <frog>
Wed, 6 Nov 2002 22:48:40 +0000 (22:48 +0000)
        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

ChangeLog
src/Makefile
src/gdcm.h
src/gdcm.i [deleted file]
src/gdcmDict.cxx
src/gdcmDictSet.cxx
src/gdcmHeader.cxx

index 4aea47dda993e9b0f2acbf855d4301ac4c4db77b..a2c75eb65522811b612635a35e1c8df644b87a58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2002-11-6 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+      * 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 <Eric.Boix@creatis.insa-lyon.fr>
       * Straightforward temporary fixes for swig to build the python wrappers.
         src/Makefile now has a python working entry [by working we mean
index e28a8765518c7a858eedbaaf119a6a6c9bfd12cf..d2f92c565f66f29e2c600bcab7cf511d2cd3c138 100644 (file)
@@ -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
index 80e98048f99f9e3bf15df81cc47e82bf99f14eae..421ca6c67797760d672f59a3b2747e59e7ddea53 100644 (file)
@@ -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<DictKey, gdcmDict*> 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 (file)
index 4ec4600..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-%module gdcm
-%{
-#include "gdcm.h"
-%}
-%rename(new_dcmHeader_c) dcmHeader::dcmHeader(char*);
-
-%include gdcm.h
index 271a2346640b96f1ed8233d6a9d30fd3423f334f..3514749ecbbc4dee8eb260bfbb0e3e49377379ed 100644 (file)
@@ -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;
 }
index ed4bdf9be3a8aecc3d371380fe7c0bf3887b35a9..c8f594b33cc60904162cf393baee1cbe9ff194a3 100644 (file)
@@ -1,21 +1,35 @@
 #include <fstream>
+#include <stdlib.h>  // 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);
 }
index cd5785b1985683f6f2ba118bca6ccb133f12c9ba..6eb47c6fa1bdee96fc7c0a97b4e6eb8b726d98c3 100644 (file)
@@ -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);
 }