]> Creatis software - gdcm.git/blob - Doc/Website/DeveloppersPython.html
Fix mistypings
[gdcm.git] / Doc / Website / DeveloppersPython.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML>
3 <HEAD>
4    <META http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
5    <TITLE>GdcmPython</TITLE>
6 </HEAD>
7
8 <BODY>
9
10 <!#######################################################################>
11 <H1>Python wrappers for gdcm</H1>
12 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>
13
14 <!#######################################################################>
15 <H2>Working with Python</H2>
16 <UL>
17 <LI><code>cd GDCM_HOME</code>
18 </LI>
19 <LI><code>export PYTHONPATH=`pwd`</code>
20 </LI>
21 <LI><code>cd gdcmPython</code>
22 </LI>
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).
29 </LI>
30 <LI>You can then use gdcmPython for manual test/demos
31    <OL>
32    <LI><code>cd GDCM_HOME/gdcmPython/demo</code>
33    </LI>
34    <LI><code>python PrintHeader.py</code>
35    </LI>
36    </OL>
37 </LI>
38 </UL>
39
40 <!#######################################################################>
41 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>
42 <PRE>
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
62     the lines :
63        gdcmHeader = gdcm.gdcmHeader
64        gdcmDictSet = gdcm.gdcmDictSet
65        gdcmFile = gdcm.gdcmFile
66        [etc.]
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 *").
85 </PRE>
86
87 <!#######################################################################>
88 <HR size="1"><ADDRESS style="align: right;"></ADDRESS>
89
90 </BODY>
91 </HTML>