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"
16 #include "gdcmPatient.h"
17 #include "gdcmStudy.h"
18 #include "gdcmSerie.h"
19 #include "gdcmImage.h"
20 #include "gdcmDirList.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 ////////////////////////////////////////////////////////////////////////////
109 // Deals with function returning a C++ string.
110 %typemap(out) string, std::string {
111 $result = PyString_FromString(($1).c_str());
114 %typemap(python, in) const std::string, std::string
116 $1 = PyString_AsString($input);
118 ////////////////////////////////////////////////////////////////////////////
119 %include "gdcmCommon.h"
120 %include "gdcmDictEntry.h"
121 %include "gdcmDict.h"
122 %include "gdcmDictSet.h"
123 %include "gdcmParser.h"
124 %include "gdcmHeaderEntry.h"
125 %include "gdcmHeader.h"
126 %include "gdcmHeaderHelper.h"
127 %include "gdcmFile.h"
128 %include "gdcmUtil.h"
129 %include "gdcmObject.h"
130 %include "gdcmDicomDir.h"
131 %include "gdcmDicomDirElement.h"
132 %include "gdcmPatient.h"
133 %include "gdcmStudy.h"
134 %include "gdcmSerie.h"
135 %include "gdcmImage.h"
136 %include "gdcmDirList.h"