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 "gdcmPatient.h"
16 #include "gdcmStudy.h"
17 #include "gdcmSerie.h"
18 #include "gdcmImage.h"
23 // Utility functions on strings for removing leading and trailing spaces
24 void EatLeadingAndTrailingSpaces(string & s) {
25 while ( s.length() && (s[0] == ' ') )
27 while ( s.length() && (s[s.length()-1] == ' ') )
28 s.erase(s.length()-1, 1);
31 typedef unsigned short guint16;
32 typedef unsigned int guint32;
34 ////////////////////////////////////////////////////////////////////////////
35 // Global variables get exported to cvar in Python
37 extern gdcmGlobal gdcmGlob;
40 ////////////////////////////////////////////////////////////////////////////
41 %typemap(out) std::list<std::string> * {
42 PyObject* NewItem = (PyObject*)0;
43 PyObject* NewList = PyList_New(0); // The result of this typemap
44 for (list<string>::iterator NewString = ($1)->begin();
45 NewString != ($1)->end(); ++NewString) {
46 NewItem = PyString_FromString(NewString->c_str());
47 PyList_Append( NewList, NewItem);
52 ////////////////////////////////////////////////////////////////////////////
53 // Convert a c++ hash table in a python native dictionary
54 %typemap(out) std::map<std::string, std::list<std::string> > * {
55 PyObject* NewDict = PyDict_New(); // The result of this typemap
56 PyObject* NewKey = (PyObject*)0;
57 PyObject* NewVal = (PyObject*)0;
59 for (map<string, list<string> >::iterator tag = ($1)->begin();
60 tag != ($1)->end(); ++tag) {
61 string first = tag->first;
62 // Do not publish entries whose keys is made of spaces
63 if (first.length() == 0)
65 NewKey = PyString_FromString(first.c_str());
66 PyObject* NewList = PyList_New(0);
67 for (list<string>::iterator Item = tag->second.begin();
68 Item != tag->second.end(); ++Item) {
69 NewVal = PyString_FromString(Item->c_str());
70 PyList_Append( NewList, NewVal);
72 PyDict_SetItem( NewDict, NewKey, NewList);
77 ////////////////////////////////////////////////////////////////////////////
78 // Convert a c++ hash table in a python native dictionary
79 %typemap(out) TagHeaderEntryHT & {
80 PyObject* NewDict = PyDict_New(); // The result of this typemap
81 string RawName; // Element name as gotten from gdcm
82 PyObject* NewKey = (PyObject*)0; // Associated name as python object
83 string RawValue; // Element value as gotten from gdcm
84 PyObject* NewVal = (PyObject*)0; // Associated value as python object
86 for (TagHeaderEntryHT::iterator tag = $1->begin(); tag != $1->end(); ++tag) {
88 // The element name shall be the key:
89 RawName = tag->second->GetName();
90 // gdcm unrecognized (including not loaded because their size exceeds
91 // the user specified treshold) elements are exported with their
93 if (RawName == "Unknown")
94 RawName = tag->second->GetKey();
95 NewKey = PyString_FromString(RawName.c_str());
97 // Element values are striped from leading/trailing spaces
98 RawValue = tag->second->GetValue();
99 EatLeadingAndTrailingSpaces(RawValue);
100 NewVal = PyString_FromString(RawValue.c_str());
102 PyDict_SetItem( NewDict, NewKey, NewVal);
107 ////////////////////////////////////////////////////////////////////////////
108 // Deals with function returning a C++ string.
109 %typemap(out) string, std::string {
110 $result = PyString_FromString(($1).c_str());
113 %typemap(python, in) const std::string, std::string
115 $1 = PyString_AsString($input);
117 ////////////////////////////////////////////////////////////////////////////
118 %include "gdcmCommon.h"
119 %include "gdcmDictEntry.h"
120 %include "gdcmDict.h"
121 %include "gdcmDictSet.h"
122 %include "gdcmParser.h"
123 %include "gdcmHeaderEntry.h"
124 %include "gdcmHeader.h"
125 %include "gdcmHeaderHelper.h"
126 %include "gdcmFile.h"
127 %include "gdcmUtil.h"
128 %include "gdcmObject.h"
129 %include "gdcmDICOMDIR.h"
130 %#include "gdcmPatient.h"
131 %include "gdcmStudy.h"
132 %include "gdcmSerie.h"
133 %include "gdcmImage.h"