3 #include "gdcmCommon.h"
4 #include "gdcmDictEntry.h"
6 #include "gdcmDictSet.h"
7 #include "gdcmParser.h"
8 #include "gdcmHeaderEntry.h"
9 #include "gdcmHeader.h"
10 #include "gdcmHeaderHelper.h"
13 #include "gdcmObject.h"
14 #include "gdcmDicomDir.h"
15 #include "gdcmDicomDirElement.h"
17 #include "gdcmPatient.h"
18 #include "gdcmStudy.h"
19 #include "gdcmSerie.h"
20 #include "gdcmImage.h"
24 // Utility functions on strings for removing leading and trailing spaces
25 void EatLeadingAndTrailingSpaces(string & s) {
26 while ( s.length() && (s[0] == ' ') )
28 while ( s.length() && (s[s.length()-1] == ' ') )
29 s.erase(s.length()-1, 1);
32 typedef unsigned short guint16;
33 typedef unsigned int guint32;
35 ////////////////////////////////////////////////////////////////////////////
36 // Global variables get exported to cvar in Python
38 extern gdcmGlobal gdcmGlob;
41 ////////////////////////////////////////////////////////////////////////////
42 %typemap(out) std::list<std::string> * {
43 PyObject* NewItem = (PyObject*)0;
44 PyObject* NewList = PyList_New(0); // The result of this typemap
45 for (list<string>::iterator NewString = ($1)->begin();
46 NewString != ($1)->end(); ++NewString) {
47 NewItem = PyString_FromString(NewString->c_str());
48 PyList_Append( NewList, NewItem);
53 ////////////////////////////////////////////////////////////////////////////
54 // Convert a c++ hash table in a python native dictionary
55 %typemap(out) std::map<std::string, std::list<std::string> > * {
56 PyObject* NewDict = PyDict_New(); // The result of this typemap
57 PyObject* NewKey = (PyObject*)0;
58 PyObject* NewVal = (PyObject*)0;
60 for (map<string, list<string> >::iterator tag = ($1)->begin();
61 tag != ($1)->end(); ++tag) {
62 string first = tag->first;
63 // Do not publish entries whose keys is made of spaces
64 if (first.length() == 0)
66 NewKey = PyString_FromString(first.c_str());
67 PyObject* NewList = PyList_New(0);
68 for (list<string>::iterator Item = tag->second.begin();
69 Item != tag->second.end(); ++Item) {
70 NewVal = PyString_FromString(Item->c_str());
71 PyList_Append( NewList, NewVal);
73 PyDict_SetItem( NewDict, NewKey, NewList);
78 ////////////////////////////////////////////////////////////////////////////
79 // Convert a c++ hash table in a python native dictionary
80 %typemap(out) TagHeaderEntryHT & {
81 PyObject* NewDict = PyDict_New(); // The result of this typemap
82 string RawName; // Element name as gotten from gdcm
83 PyObject* NewKey = (PyObject*)0; // Associated name as python object
84 string RawValue; // Element value as gotten from gdcm
85 PyObject* NewVal = (PyObject*)0; // Associated value as python object
87 for (TagHeaderEntryHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
89 // The element name shall be the key:
90 RawName = tag->second->GetName();
91 // gdcm unrecognized (including not loaded because their size exceeds
92 // the user specified treshold) elements are exported with their
94 if (RawName == "Unknown")
95 RawName = tag->second->GetKey();
96 NewKey = PyString_FromString(RawName.c_str());
98 // Element values are striped from leading/trailing spaces
99 RawValue = tag->second->GetValue();
100 EatLeadingAndTrailingSpaces(RawValue);
101 NewVal = PyString_FromString(RawValue.c_str());
103 PyDict_SetItem( NewDict, NewKey, NewVal);
108 %typemap(out) TagHeaderEntryHT {
109 PyObject* NewDict = PyDict_New(); // The result of this typemap
110 string RawName; // Element name as gotten from gdcm
111 PyObject* NewKey = (PyObject*)0; // Associated name as python object
112 string RawValue; // Element value as gotten from gdcm
113 PyObject* NewVal = (PyObject*)0; // Associated value as python object
115 for (TagHeaderEntryHT::iterator tag = $1.begin(); tag != $1.end(); ++tag) {
117 // The element name shall be the key:
118 RawName = tag->second->GetName();
119 // gdcm unrecognized (including not loaded because their size exceeds
120 // the user specified treshold) elements are exported with their
122 if (RawName == "Unknown")
123 RawName = tag->second->GetKey();
124 NewKey = PyString_FromString(RawName.c_str());
126 // Element values are striped from leading/trailing spaces
127 RawValue = tag->second->GetValue();
128 EatLeadingAndTrailingSpaces(RawValue);
129 NewVal = PyString_FromString(RawValue.c_str());
131 PyDict_SetItem( NewDict, NewKey, NewVal);
136 ////////////////////////////////////////////////////////////////////////////
137 %typemap(out) ListPatient & {
138 PyObject* NewItem = (PyObject*)0;
139 $result = PyList_New(0); // The result of this typemap
141 for (list<gdcmPatient *>::iterator New = ($1)->begin();
142 New != ($1)->end(); ++New) {
143 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_gdcmPatient,1);
144 PyList_Append($result, NewItem);
148 %typemap(out) ListStudy & {
149 PyObject* NewItem = (PyObject*)0;
150 $result = PyList_New(0); // The result of this typemap
152 for (list<gdcmStudy *>::iterator New = ($1)->begin();
153 New != ($1)->end(); ++New) {
154 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_gdcmStudy,1);
155 PyList_Append($result, NewItem);
159 %typemap(out) ListSerie & {
160 PyObject* NewItem = (PyObject*)0;
161 $result = PyList_New(0); // The result of this typemap
163 for (list<gdcmSerie *>::iterator New = ($1)->begin();
164 New != ($1)->end(); ++New) {
165 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_gdcmSerie,1);
166 PyList_Append($result, NewItem);
170 %typemap(out) ListImage & {
171 PyObject* NewItem = (PyObject*)0;
172 $result = PyList_New(0); // The result of this typemap
174 for (list<gdcmImage *>::iterator New = ($1)->begin();
175 New != ($1)->end(); ++New) {
176 NewItem = SWIG_NewPointerObj(*New,SWIGTYPE_p_gdcmImage,1);
177 PyList_Append($result, NewItem);
181 ////////////////////////////////////////////////////////////////////////////
183 ////////////////////////////////////////////////////////////////////////////
184 // Deals with function returning a C++ string.
185 %typemap(out) string, std::string {
186 $result = PyString_FromString(($1).c_str());
189 %typemap(python, in) const std::string, std::string
191 $1 = PyString_AsString($input);
194 ////////////////////////////////////////////////////////////////////////////
195 %include "gdcmCommon.h"
196 %include "gdcmDictEntry.h"
197 %include "gdcmDict.h"
198 %include "gdcmDictSet.h"
199 %include "gdcmParser.h"
200 %include "gdcmHeaderEntry.h"
201 %include "gdcmHeader.h"
202 %include "gdcmHeaderHelper.h"
203 %include "gdcmFile.h"
204 %include "gdcmUtil.h"
205 %include "gdcmObject.h"
206 %include "gdcmDicomDir.h"
207 %include "gdcmDicomDirElement.h"
208 %include "gdcmMeta.h"
209 %include "gdcmPatient.h"
210 %include "gdcmStudy.h"
211 %include "gdcmSerie.h"
212 %include "gdcmImage.h"