3 #include "gdcmCommon.h"
5 #include "gdcmDictEntry.h"
6 #include "gdcmDictSet.h"
7 #include "gdcmDicomDir.h"
8 #include "gdcmDicomDirElement.h"
9 #include "gdcmDicomDirImage.h"
10 #include "gdcmDicomDirMeta.h"
11 #include "gdcmDicomDirObject.h"
12 #include "gdcmDicomDirPatient.h"
13 #include "gdcmDicomDirStudy.h"
14 #include "gdcmDicomDirSerie.h"
15 #include "gdcmDocEntrySet.h"
16 #include "gdcmDocument.h"
17 #include "gdcmElementSet.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmHeader.h"
21 #include "gdcmHeaderHelper.h"
22 #include "gdcmRLEFramesInfo.h"
23 #include "gdcmJPEGFragmentsInfo.h"
24 #include "gdcmSQItem.h"
26 #include "gdcmValEntry.h"
28 ////////////////////////////////////////////////////////////////////////////
29 // Utility functions on strings for removing leading and trailing spaces
30 void EatLeadingAndTrailingSpaces(std::string & s) {
31 while ( s.length() && (s[0] == ' ') )
33 while ( s.length() && (s[s.length()-1] == ' ') )
34 s.erase(s.length()-1, 1);
37 void gdcmPythonVoidFunc(void *arg)
39 PyObject *arglist, *result;
40 PyObject *func = (PyObject *)arg;
42 arglist = Py_BuildValue("()");
44 result = PyEval_CallObject(func, arglist);
53 if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt))
55 std::cerr << "Caught a Ctrl-C within python, exiting program.\n";
62 void gdcmPythonVoidFuncArgDelete(void *arg)
64 PyObject *func = (PyObject *)arg;
73 typedef unsigned short guint16;
74 typedef unsigned int guint32;
76 ////////////////////////////////////////////////////////////////////////////
77 %typemap(out) std::list<std::string> * {
78 PyObject* NewItem = (PyObject*)0;
79 PyObject* NewList = PyList_New(0); // The result of this typemap
81 for (std::list<std::string>::iterator NewString = ($1)->begin();
82 NewString != ($1)->end();
85 NewItem = PyString_FromString(NewString->c_str());
86 PyList_Append( NewList, NewItem);
91 ////////////////////////////////////////////////////////////////////////////
92 // Convert a c++ hash table in a python native dictionary
93 %typemap(out) std::map<std::string, std::list<std::string> > * {
94 PyObject* NewDict = PyDict_New(); // The result of this typemap
95 PyObject* NewKey = (PyObject*)0;
96 PyObject* NewVal = (PyObject*)0;
98 for (std::map<std::string,
99 std::list<std::string> >::iterator tag = ($1)->begin();
100 tag != ($1)->end(); ++tag)
102 std::string first = tag->first;
103 // Do not publish entries whose keys is made of spaces
104 if (first.length() == 0)
106 NewKey = PyString_FromString(first.c_str());
107 PyObject* NewList = PyList_New(0);
108 for (std::list<std::string>::iterator Item = tag->second.begin();
109 Item != tag->second.end();
112 NewVal = PyString_FromString(Item->c_str());
113 PyList_Append( NewList, NewVal);
115 PyDict_SetItem( NewDict, NewKey, NewList);
120 ////////////////////////////////////////////////////////////////////////////
121 // Convert a c++ hash table in a python native dictionary
122 %typemap(out) gdcm::TagDocEntryHT & {
123 PyObject* NewDict = PyDict_New(); // The result of this typemap
124 std::string RawName; // Element name as gotten from gdcm
125 PyObject* NewKey = (PyObject*)0; // Associated name as python object
126 std::string RawValue; // Element value as gotten from gdcm
127 PyObject* NewVal = (PyObject*)0; // Associated value as python object
129 for (gdcm::TagDocEntryHT::iterator tag = $1->begin(); tag != $1->end(); ++tag)
131 // The element name shall be the key:
132 RawName = tag->second->GetName();
133 // gdcm unrecognized (including not loaded because their size exceeds
134 // the user specified treshold) elements are exported with their
136 if (RawName == "Unknown")
137 RawName = tag->second->GetKey();
138 NewKey = PyString_FromString(RawName.c_str());
140 // Element values are striped from leading/trailing spaces
141 if (gdcm::ValEntry* ValEntryPtr =
142 dynamic_cast< gdcm::ValEntry* >(tag->second) )
144 RawValue = ValEntryPtr->GetValue();
148 EatLeadingAndTrailingSpaces(RawValue);
149 NewVal = PyString_FromString(RawValue.c_str());
150 PyDict_SetItem( NewDict, NewKey, NewVal);
155 ////////////////////////////////////////////////////////////////////////////
156 %typemap(out) ListDicomDirPatient & {
157 PyObject* NewItem = (PyObject*)0;
158 $result = PyList_New(0); // The result of this typemap
160 for (std::list<gdcm::DicomDirPatient *>::iterator New = ($1)->begin();
161 New != ($1)->end(); ++New) {
162 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_DicomDirPatient,1);
163 PyList_Append($result, NewItem);
167 %typemap(out) ListDicomDirStudy & {
168 PyObject* NewItem = (PyObject*)0;
169 $result = PyList_New(0); // The result of this typemap
171 for (std::list<gdcm::DicomDirStudy *>::iterator New = ($1)->begin();
172 New != ($1)->end(); ++New) {
173 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_DicomDirStudy,1);
174 PyList_Append($result, NewItem);
178 %typemap(out) ListDicomDirSerie & {
179 PyObject* NewItem = (PyObject*)0;
180 $result = PyList_New(0); // The result of this typemap
182 for (std::list<gdcm::DicomDirSerie *>::iterator New = ($1)->begin();
183 New != ($1)->end(); ++New) {
184 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_DicomDirSerie,1);
185 PyList_Append($result, NewItem);
189 %typemap(out) ListDicomDirImage & {
190 PyObject* NewItem = (PyObject*)0;
191 $result = PyList_New(0); // The result of this typemap
193 for (std::list<gdcm::DicomDirImage *>::iterator New = ($1)->begin();
194 New != ($1)->end(); ++New) {
195 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_DicomDirImage,1);
196 PyList_Append($result, NewItem);
200 ////////////////////////////////////////////////////////////////////////////
201 // Deals with function returning a C++ string.
202 %typemap(python, in) (gdcm::Method *,void * =NULL,gdcm::Method * =NULL) {
206 $1=gdcmPythonVoidFunc;
208 $3=gdcmPythonVoidFuncArgDelete;
219 ////////////////////////////////////////////////////////////////////////////
220 // Deals with function returning a C++ string.
221 %typemap(out) string, std::string {
222 $result = PyString_FromString(($1).c_str());
225 %typemap(python, in) const std::string, std::string
227 $1 = PyString_AsString($input);
230 ////////////////////////////////////////////////////////////////////////////
231 // Warning: Order matters !
232 %include "gdcmCommon.h"
233 %include "gdcmRLEFramesInfo.h"
234 %include "gdcmJPEGFragmentsInfo.h"
235 %include "gdcmDictEntry.h"
236 %include "gdcmDict.h"
237 %include "gdcmDocEntry.h"
238 %include "gdcmDocEntrySet.h"
239 %include "gdcmElementSet.h"
240 %include "gdcmDictSet.h"
243 %include "gdcmSQItem.h"
244 %include "gdcmDicomDirElement.h"
245 %include "gdcmDicomDirObject.h"
246 %include "gdcmDicomDirImage.h"
247 %include "gdcmDicomDirSerie.h"
248 %include "gdcmDicomDirStudy.h"
249 %include "gdcmDicomDirPatient.h"
250 %include "gdcmDicomDirMeta.h"
251 %include "gdcmDocument.h"
252 %include "gdcmHeader.h"
253 %include "gdcmHeaderHelper.h"
254 %include "gdcmFile.h"
255 %include "gdcmUtil.h"
256 %include "gdcmGlobal.h"
257 %include "gdcmDicomDir.h"