1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <META http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
5 <TITLE>GdcmPython</TITLE>
10 <!#######################################################################>
11 <H1>Python wrappers for gdcm</H1>
12 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>
14 <!#######################################################################>
15 <H2>Working with Python</H2>
17 <LI><code>cd GDCM_HOME</code>
19 <LI><code>export PYTHONPATH=`pwd`</code>
21 <LI><code>cd gdcmPython</code>
23 <LI><code>ln -s .libs/pygdcm.so _gdcm.so</code>
24 <BR> (this is because automake doesn't allow the building of libraries
25 whose name starts with an underscore. Since we need the
26 wrapper library to be named _gdcm [because swig automaticatily uses
27 this name when building the shadow classes], automake generates
28 pygdcm.so and at install stage stage renames it to _gdcm.so).
30 <LI>You can then use gdcmPython for manual test/demos
32 <LI><code>cd GDCM_HOME/gdcmPython/demo</code>
34 <LI><code>python PrintHeader.py</code>
40 <!#######################################################################>
41 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>
43 Depending on the cmake flags you used in order to compile gdcm could
44 be wrapped in two ways:
45 - the first python wrappers of gdcm uses Swig (http://www.swig.org). These
46 are the one generated when using autogen.sh --enable-python.
47 The entry point here is the file gdcmPython/gdcm.i which uses the
48 Swig syntax. As the last lines of this file (the ones starting
49 with the %include directive) only some classes are wrapped for python.
50 In theory only the library interface (basically the classes gdcmHeader
51 and gdcmFile) should be wrapped, but the time being some additional
52 classes are added (just to make sure those classes are Swig compatible:
53 swig is here used as some link checker!?).
54 Since gdcm is written in C++, Swig will produce two different outputs:
55 -- some C based low level wrapper (see gdcmPython/gdcm_wrap.c)
56 -- some Python based object oriented so called "shadow classes" (see
57 file gdcmPython/gdcm.py)
58 We also added the file gdcmPython/__init__.py which is the one that
59 actually gets loaded when one uses the gdcmPython Python package.
60 The file __init__.py loads the Swig generated shadow classes (gdcm.py)
61 but will only re-export the interface of gdcm which corresponds to
63 gdcmHeader = gdcm.gdcmHeader
64 gdcmDictSet = gdcm.gdcmDictSet
65 gdcmFile = gdcm.gdcmFile
67 Hence this whole Swig wrapping process is quite odd since we shall
68 wrap more classes (%include in swig.i) that eventually get exported to
69 the final user by gdcmPython/__init__.py.
70 - the second python wrappers uses the vtk (http://public.kitware.com/VTK/)
71 native wrappers i.e. the binary vtkWrapPython. But it should be noticed
72 that the purpose is here a bit different than the one of the Swig
73 generated Python wrappers. When using vtkWrapPython the goal is to
74 wrap a single vtk class namely vtkGdcmReader as defined in files
75 vtk/vtkGdcmReader.h and vtk/vtkGdcmReader.cxx (and of course those
76 files are hand made vtk oriented wrappers of gdcm).
77 Those wrappers are the one generated when using
78 autogen.sh --enable-python --enable-vtk
79 - In order to understand the difference between both wrappers you should
80 compare both demo scripts gdcmPython/demo/vtkGdcmDemo.py and
81 gdcmPython/demo/vtkGdcmReader.py. The first one only uses the
82 Swig wrapped classes ("from gdcmPython import gdcmHeader') as opposed
83 to vtkGdcmReader.py which also uses vtkWrapPython wrapped classes
84 ("from gdcmPython.vtkgdcmPython import *").
87 <!#######################################################################>
88 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>