@@ -93,6 +93,50 @@ py::buffer_info get_buffer_info(vpHomogeneousMatrix &array)
93
93
return make_array_buffer<double , 2 >(array.data , { array.getRows (), array.getCols () }, true );
94
94
}
95
95
96
+ /*
97
+ * Print helpers
98
+ */
99
+
100
+ const char *matlab_str_help = R"doc(
101
+ Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)
102
+ )doc" ;
103
+ const char *csv_str_help = R"doc(
104
+ Returns the CSV representation of this data array (see csvPrint in the C++ documentation)
105
+ )doc" ;
106
+ const char *maple_str_help = R"doc(
107
+ Returns the CSV representation of this data array (see maplePrint in the C++ documentation)
108
+ )doc" ;
109
+
110
+ const char *cpp_str_help = R"doc(
111
+ Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)
112
+
113
+ :param name: variable name of the matrix.
114
+ :param byte_per_byte: Whether to print byte per byte defaults to false.
115
+ )doc" ;
116
+
117
+ template <typename PybindClass, typename T, typename S>
118
+ void add_print_helper (PybindClass &pyCls, std::ostream &(T:: *fn)(std::ostream &) const , const S pythonName, const char *help)
119
+ {
120
+ pyCls.def (pythonName, [fn](const T &self) -> std::string {
121
+ std::stringstream ss;
122
+ (self.*fn)(ss);
123
+ return ss.str ();
124
+ }, help);
125
+ }
126
+
127
+ template <typename PybindClass, typename T>
128
+ void add_cpp_print_helper (PybindClass &pyCls, std::ostream &(T:: *fn)(std::ostream &, const std::string &, bool ) const )
129
+ {
130
+ pyCls.def (" strCppCode" , [fn](const T &self, const std::string &name = " A" , bool byte_per_byte = false ) -> std::string {
131
+ std::stringstream ss;
132
+ (self.*fn)(ss, name, byte_per_byte);
133
+ return ss.str ();
134
+ }, cpp_str_help, py::arg (" name" ), py::arg (" byte_per_byte" ) = false );
135
+ }
136
+
137
+
138
+
139
+
96
140
/*
97
141
* Array 2D indexing
98
142
*/
@@ -219,6 +263,11 @@ Construct a matrix by **copying** a 2D numpy array.
219
263
220
264
)doc" , py::arg (" np_array" ));
221
265
266
+ add_print_helper (pyMatrix, &vpMatrix::csvPrint, " strCsv" , csv_str_help);
267
+ add_print_helper (pyMatrix, &vpMatrix::maplePrint, " strMaple" , maple_str_help);
268
+ add_print_helper (pyMatrix, &vpMatrix::matlabPrint, " strMatlab" , matlab_str_help);
269
+ add_cpp_print_helper (pyMatrix, &vpMatrix::cppPrint);
270
+
222
271
define_get_item_2d_array<py::class_<vpMatrix, vpArray2D<double >>, vpMatrix, double >(pyMatrix);
223
272
}
224
273
@@ -326,6 +375,11 @@ Construct a column vector by **copying** a 1D numpy array.
326
375
)doc" , py::arg (" np_array" ));
327
376
define_get_item_1d_array<py::class_<vpColVector, vpArray2D<double >>, vpColVector, double >(pyColVector);
328
377
378
+ add_print_helper (pyColVector, &vpColVector::csvPrint, " strCsv" , csv_str_help);
379
+ add_print_helper (pyColVector, &vpColVector::maplePrint, " strMaple" , maple_str_help);
380
+ add_print_helper (pyColVector, &vpColVector::matlabPrint, " strMatlab" , matlab_str_help);
381
+ add_cpp_print_helper (pyColVector, &vpColVector::cppPrint);
382
+
329
383
}
330
384
331
385
void bindings_vpRowVector (py::class_<vpRowVector, vpArray2D<double >> &pyRowVector)
@@ -347,6 +401,10 @@ Construct a row vector by **copying** a 1D numpy array.
347
401
348
402
)doc" , py::arg (" np_array" ));
349
403
define_get_item_1d_array<py::class_<vpRowVector, vpArray2D<double >>, vpRowVector, double >(pyRowVector);
404
+ add_print_helper (pyRowVector, &vpRowVector::csvPrint, " strCsv" , csv_str_help);
405
+ add_print_helper (pyRowVector, &vpRowVector::maplePrint, " strMaple" , maple_str_help);
406
+ add_print_helper (pyRowVector, &vpRowVector::matlabPrint, " strMatlab" , matlab_str_help);
407
+ add_cpp_print_helper (pyRowVector, &vpRowVector::cppPrint);
350
408
}
351
409
352
410
0 commit comments