+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
-
-###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 \
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
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&);
// 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);
// 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 :
+++ /dev/null
-%module gdcm
-%{
-#include "gdcm.h"
-%}
-%rename(new_dcmHeader_c) dcmHeader::dcmHeader(char*);
-
-%include gdcm.h
#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];
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;
}
#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;
}
}
gdcmDict * gdcmDictSet::GetDefaultPublicDict() {
- return GetDict(PUBDICTNAME);
+ return GetDict(PUB_DICT_NAME);
}
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.
LoadElementValue(tag->second);
}
-void gdcmHeader::PrintPubElVal(ostream & os) {
+void gdcmHeader::PrintPubElVal(ostream & os = std::cout) {
PubElVals.Print(os);
}