Skip to content

Commit 44cd2dc

Browse files
committed
Ability to split configuration for a module into multiple files, a lot of json configuration
1 parent 434b208 commit 44cd2dc

File tree

6 files changed

+572
-191
lines changed

6 files changed

+572
-191
lines changed

modules/python/bindings/include/core/arrays.hpp

+58
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ py::buffer_info get_buffer_info(vpHomogeneousMatrix &array)
9393
return make_array_buffer<double, 2>(array.data, { array.getRows(), array.getCols() }, true);
9494
}
9595

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+
96140
/*
97141
* Array 2D indexing
98142
*/
@@ -219,6 +263,11 @@ Construct a matrix by **copying** a 2D numpy array.
219263
220264
)doc", py::arg("np_array"));
221265

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+
222271
define_get_item_2d_array<py::class_<vpMatrix, vpArray2D<double>>, vpMatrix, double>(pyMatrix);
223272
}
224273

@@ -326,6 +375,11 @@ Construct a column vector by **copying** a 1D numpy array.
326375
)doc", py::arg("np_array"));
327376
define_get_item_1d_array<py::class_<vpColVector, vpArray2D<double>>, vpColVector, double>(pyColVector);
328377

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+
329383
}
330384

331385
void bindings_vpRowVector(py::class_<vpRowVector, vpArray2D<double>> &pyRowVector)
@@ -347,6 +401,10 @@ Construct a row vector by **copying** a 1D numpy array.
347401
348402
)doc", py::arg("np_array"));
349403
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);
350408
}
351409

352410

0 commit comments

Comments
 (0)