2 #pragma SWIG nowarn=504
6 #include "gdcmCommon.h"
9 #include "gdcmDictEntry.h"
10 #include "gdcmDictSet.h"
11 #include "gdcmDicomDir.h"
12 #include "gdcmDicomDirElement.h"
13 #include "gdcmDicomDirImage.h"
14 #include "gdcmDicomDirMeta.h"
15 #include "gdcmDicomDirObject.h"
16 #include "gdcmDicomDirPatient.h"
17 #include "gdcmDicomDirStudy.h"
18 #include "gdcmDicomDirSerie.h"
19 #include "gdcmDocEntrySet.h"
20 #include "gdcmDocument.h"
21 #include "gdcmElementSet.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmGlobal.h"
25 #include "gdcmSerieHelper.h"
26 #include "gdcmRLEFramesInfo.h"
27 #include "gdcmJPEGFragmentsInfo.h"
28 #include "gdcmSQItem.h"
30 #include "gdcmDocEntry.h"
31 #include "gdcmDataEntry.h"
32 #include "gdcmSeqEntry.h"
35 #include "gdcmDictGroupName.h"
37 ////////////////////////////////////////////////////////////////////////////
38 /// Refer (below) to the definition of multi-argument typemap
39 /// %typemap(python, in)
40 /// ( gdcm::DicomDir::Method*, void*, gdcm::DicomDir::Method*)
41 /// for detail on gdcmPythonVoidFunc() and gdcmPythonVoidFuncArgDelete().
42 void gdcmPythonVoidFunc(void *arg)
44 PyObject *arglist, *result;
45 PyObject *func = (PyObject *)arg;
47 arglist = Py_BuildValue("()");
49 result = PyEval_CallObject(func, arglist);
58 if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
60 std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
67 void gdcmPythonVoidFuncArgDelete(void *arg)
69 PyObject *func = (PyObject *)arg;
76 /// This is required in order to avoid %including all the gdcm include files.
81 /////////////////////// typemap section ////////////////////////////////////
83 ////////////////////////////////////////////////
84 // Redefine all types used
86 typedef unsigned char uint8_t;
87 typedef short int16_t;
88 typedef unsigned short uint16_t;
90 typedef unsigned int uint32_t;
91 typedef long long int64_t;
92 typedef unsigned long long uint64_t;
94 ////////////////////////////////////////////////
95 // Convert a DocEntry * to the real derived class
96 %typemap(out) gdcm::DocEntry *
102 if(dynamic_cast<SeqEntry *>($1)) // SeqEntry *
103 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__SeqEntry,0);
104 else if(dynamic_cast<BinEntry *>($1)) // BinEntry *
105 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__BinEntry,0);
107 newEntry = SWIG_NewPointerObj($1,SWIGTYPE_p_gdcm__ValEntry,0);
111 newEntry = Py_BuildValue("");
116 ////////////////////////////////////////////////////////////////////////////
117 // Multi-argument typemap designed for wrapping the progress related methods
118 // in order to control from an external application the computation of
119 // a DicomDir object (see DicomDir::SetStartMethod*,
120 // DicomDir::SetProgressMethod* and DicomDir::SetEndMethod*).
121 // Motivation: since DicomDir parsing can be quite long, a GUI application
122 // needs to display the avancement and potentially offer a
123 // cancel method to the user (when this one feels things are
124 // longer than expected).
125 // Example of usage: refer to demo/DicomDirProgressMethod.py
126 // Note: Uses gdcmPythonVoidFunc and gdcmPythonVoidFuncArgDelete defined
127 // in the Swig verbatim section of this gdcm.i i.e. in the above section
128 // enclosed within the %{ ... %} scope operator ).
129 %typemap(python, in) (void(*method)(void *),void *arg,void(*argDelete)(void *))
134 $1=gdcmPythonVoidFunc;
136 $3=gdcmPythonVoidFuncArgDelete;
146 //////////////////// STL string versus Python str ////////////////////////
147 // Convertion returning a C++ string.
148 %typemap(out) std::string
150 $result = PyString_FromString(($1).c_str());
155 $result = PyString_FromString(($1).c_str());
158 %typemap(out) std::string const &
160 $result = PyString_FromString(($1)->c_str());
163 // Convertion of incoming Python str to STL string
164 %typemap(python, in) const std::string, std::string
166 $1 = PyString_AsString($input);
169 // Same convertion as above but references (since swig converts C++
170 // refererences to pointers)
171 %typemap(python, in) std::string const &
173 $1 = new std::string( PyString_AsString( $input ) );
176 //////////////////// gdcm.TagName versus Python str //////////////////////
177 %typemap(out) gdcm::TagName, const gdcm::TagName &
179 $result = PyString_FromString(($1)->c_str());
182 // Convertion of incoming Python str to STL string
183 %typemap(python, in) const gdcm::TagName, gdcm::TagName
185 $1 = PyString_AsString($input);
188 // Same convertion as above but references (since swig converts C++
189 // refererences to pointers)
190 %typemap(python, in) gdcm::TagName const &
192 $1 = new std::string( PyString_AsString( $input ) );
195 ////////////////////////////////////////////////////////////////////////////
196 // Because overloading and %rename don't work together (see below Note 1)
197 // we need to ignore some methods (e.g. the overloaded default constructor).
198 // The gdcm::File class doesn't have any SetFilename method anyhow, and
199 // this constructor is only used internaly (not from the API) so this is
201 %ignore gdcm::binary_write(std::ostream &,uint32_t const &);
202 %ignore gdcm::binary_write(std::ostream &,uint16_t const &);
204 %ignore gdcm::DicomDir::SetStartMethod(DicomDir::Method *method,void *arg = NULL);
205 %ignore gdcm::DicomDir::SetProgressMethod(DicomDir::Method *method,void *arg = NULL);
206 %ignore gdcm::DicomDir::SetEndMethod(DicomDir::Method *method,void *arg = NULL);
208 // Ignore all placed in gdcmCommon.h
209 %ignore GDCM_UNKNOWN;
210 %ignore GDCM_UNFOUND;
211 %ignore GDCM_BINLOADED;
212 %ignore GDCM_NOTLOADED;
214 %ignore GDCM_NOTASCII;
215 %ignore GDCM_PIXELDATA;
217 %ignore GDCM_VRUNKNOWN;
219 %constant const char *UNKNOWN = "gdcm::Unknown";
220 %constant const char *UNFOUND = "gdcm::Unfound";
221 %constant const char *BINLOADED = "gdcm::Binary data loaded";
222 %constant const char *NOTLOADED = "gdcm::NotLoaded";
223 %constant const char *UNREAD = "gdcm::UnRead";
224 %constant const char *GDCM_NOTASCII = "gdcm::NotAscii";
225 %constant const char *GDCM_PIXELDATA = "gdcm::Pixel Data to be loaded";
226 %constant const char *VRUNKNOWN = " ";
228 ////////////////////////////////////////////////////////////////////////////
229 // Warning: Order matters !
230 %include "gdcmCommon.h"
231 %include "gdcmBase.h"
232 %include "gdcmDictEntry.h"
233 %include "gdcmDict.h"
234 %include "gdcmDictSet.h"
235 %include "gdcmDocEntrySet.h"
236 %include "gdcmElementSet.h"
237 %include "gdcmSQItem.h"
238 %include "gdcmDicomDirElement.h"
239 %include "gdcmDicomDirObject.h"
240 %include "gdcmDicomDirImage.h"
241 %include "gdcmDicomDirSerie.h"
242 %include "gdcmDicomDirStudy.h"
243 %include "gdcmDicomDirPatient.h"
244 %include "gdcmDicomDirMeta.h"
245 %include "gdcmDocument.h"
246 %include "gdcmFile.h"
247 %include "gdcmSerieHelper.h"
248 %include "gdcmFileHelper.h"
249 %include "gdcmUtil.h"
250 %include "gdcmGlobal.h"
251 %include "gdcmDicomDir.h"
252 %include "gdcmDocEntry.h"
253 %include "gdcmDataEntry.h"
254 %include "gdcmSeqEntry.h"
257 %include "gdcmDictGroupName.h"
259 ////////////////////////////////////////////////////////////////////////////
260 // Notes on swig and this file gdcm.i:
262 /////////////////////////////////////
263 // Note 1: swig collision of method overloading and %typemap
264 // Consider the following junk.i file:
268 // #include <iostream>
269 // void Junk(std::string const & bozo) { std::cout << bozo << std::endl; }
270 // void Junk() { std::cout << "Renamed Junk()" << std::endl; }
273 // %typemap(python, in) std::string const &
275 // $1 = new std::string( PyString_AsString( $input ) );
278 // void Junk(std::string const & bozo);
280 // that we compile on linux with:
281 // swig -c++ -python junk.i
282 // g++ -g -I/usr/include/python2.3/ -o junk_wrap.o -c junk_wrap.cxx
283 // g++ junk_wrap.o -shared -g -o _junk.so -L/usr/lib/python2.3/config \
286 // python -c 'from junk import *; Junk("aaa") '
287 // then we get the following unexpected (for novice) python TypeError:
288 // TypeError: No matching function for overloaded 'Junk'
290 // This happens because the swig generated code (at least for python) does
291 // the following two stage process:
292 // 1/ first do a dynamic dispatch ON THE NUMBER OF ARGUMENTS of the overloaded
293 // Junk function (the same happens with method of course). [Note that the
294 // dispatch is NOT done on the type of the arguments].
295 // 2/ second apply the typemap.
296 // When the first dynamic dispatch is executed, the swig generated code
297 // has no knowledge of the typemap, and thus expects a pointer to a std::string
298 // type i.e. an argument to Junk of the form _p_std__int<address>. But this
299 // is not what python handles to Junk ! An invocation of the form 'Junk("aaa")'
300 // will make Python pass a PyString to swig (and this is precisely why we
301 // wrote the typemap). And this will fail....
302 /////////////////////////////////////