00001
00016 #ifndef _DLR_PYTHONIO_H_
00017 #define _DLR_PYTHONIO_H_
00018
00019 #include <iostream>
00020 #include <string>
00021
00022 namespace dlr {
00023
00024 namespace utilities {
00025
00046 template<class ArrayType>
00047 std::string
00048 toPythonList(const ArrayType& array0);
00049
00050
00062 template<class ArrayType>
00063 std::string
00064 toPythonNumericArray(const ArrayType& array0) {
00065 return toPythonNumeric2DArray(array0);
00066 }
00067
00068
00084 template<class ArrayType>
00085 std::string
00086 toPythonNumeric1DArray(const ArrayType& array0);
00087
00088
00112 template<class ArrayType>
00113 std::string
00114 toPythonNumeric2DArray(const ArrayType& array0);
00115
00116 }
00117
00118 }
00119
00120
00121
00122
00123 namespace dlr {
00124
00125 using utilities::toPythonList;
00126 using utilities::toPythonNumericArray;
00127 using utilities::toPythonNumeric1DArray;
00128 using utilities::toPythonNumeric2DArray;
00129
00130 }
00131
00132
00133
00134
00135 namespace dlr {
00136
00137 namespace utilities {
00138
00139 template<class ArrayType>
00140 std::string
00141 toPythonList(const ArrayType& array0)
00142 {
00143
00144 std::ostringstream outputStream;
00145
00146
00147 outputStream << "[";
00148
00149
00150 size_t count = 0;
00151 while(count < array0.size()) {
00152
00153
00154
00155 size_t lineCount = 0;
00156
00157 while((count < array0.size()) & (lineCount < 20)) {
00158
00159 if(count != 0) {
00160
00161 outputStream << ", ";
00162
00163
00164
00165 if(lineCount == 0) {
00166 outputStream << "\n\t\t";
00167 }
00168 }
00169
00170
00171 outputStream << array0[count];
00172
00173
00174 ++count;
00175 ++lineCount;
00176 }
00177 }
00178
00179
00180 outputStream << "]";
00181
00182
00183 return outputStream.str();
00184 }
00185
00186
00187 template<class ArrayType>
00188 std::string
00189 toPythonNumeric1DArray(const ArrayType& array0)
00190 {
00191
00192 std::ostringstream outputStream;
00193
00194
00195
00196 outputStream << "array(";
00197 outputStream << toPythonList(array0);
00198
00199
00200 outputStream << ")\n";
00201
00202
00203 return outputStream.str();
00204 }
00205
00206
00207 template<class ArrayType>
00208 std::string
00209 toPythonNumeric2DArray(const ArrayType& array0)
00210 {
00211
00212 std::ostringstream outputStream;
00213
00214
00215
00216 outputStream << "array([";
00217
00218
00219 for(size_t index0 = 0; index0 < array0.rows(); ++index0) {
00220 if(index0 != 0) {
00221 outputStream << ",\n\t";
00222 }
00223 outputStream << toPythonList(array0.row(index0));
00224 }
00225
00226
00227 outputStream << "])\n";
00228
00229
00230 return outputStream.str();
00231 }
00232
00233 }
00234
00235 }
00236
00237 #endif // #ifndef _DLR_IMAGEIO_H_