Skip to content

Commit

Permalink
Ignore Windows subclasses for display, fix some MSVC issues in bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Feb 2, 2024
1 parent 2197587 commit ac8e4b0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions modules/python/bindings/include/core/arrays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void bindings_vpArray2D(py::class_<vpArray2D<T>> &pyArray2D)

pyArray2D.def(py::init([](np_array_cf<T> &np_array) {
verify_array_shape_and_dims(np_array, 2, "ViSP 2D array");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpArray2D<T> result(shape[0], shape[1]);
copy_data_from_np(np_array, result.data);
return result;
Expand All @@ -207,7 +207,7 @@ void bindings_vpMatrix(py::class_<vpMatrix, vpArray2D<double>> &pyMatrix)

pyMatrix.def(py::init([](np_array_cf<double> np_array) {
verify_array_shape_and_dims(np_array, 2, "ViSP Matrix");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpMatrix result(shape[0], shape[1]);
copy_data_from_np(np_array, result.data);
return result;
Expand All @@ -231,7 +231,7 @@ void bindings_vpRotationMatrix(py::class_<vpRotationMatrix, vpArray2D<double>> &
}, numpy_fn_doc_nonwritable, py::keep_alive<0, 1>());
pyRotationMatrix.def(py::init([](np_array_cf<double> np_array) {
verify_array_shape_and_dims(np_array, { 3, 3 }, "ViSP rotation matrix");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpRotationMatrix result;
copy_data_from_np(np_array, result.data);
if (!result.isARotationMatrix()) {
Expand All @@ -258,7 +258,7 @@ void bindings_vpHomogeneousMatrix(py::class_<vpHomogeneousMatrix, vpArray2D<doub

pyHomogeneousMatrix.def(py::init([](np_array_cf<double> np_array) {
verify_array_shape_and_dims(np_array, { 4, 4 }, "ViSP homogeneous matrix");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpHomogeneousMatrix result;
copy_data_from_np(np_array, result.data);
if (!result.isAnHomogeneousMatrix()) {
Expand Down Expand Up @@ -287,9 +287,9 @@ void bindings_vpTranslationVector(py::class_<vpTranslationVector, vpArray2D<doub
}, numpy_fn_doc_writable, py::keep_alive<0, 1>());

pyTranslationVector.def(py::init([](np_array_cf<double> np_array) {
const std::vector<ssize_t> required_shape = { 3 };
const std::vector<py::ssize_t> required_shape = { 3 };
verify_array_shape_and_dims(np_array, required_shape, "ViSP translation vector");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpTranslationVector result;
copy_data_from_np(np_array, result.data);
return result;
Expand All @@ -313,7 +313,7 @@ void bindings_vpColVector(py::class_<vpColVector, vpArray2D<double>> &pyColVecto

pyColVector.def(py::init([](np_array_cf<double> np_array) {
verify_array_shape_and_dims(np_array, 1, "ViSP column vector");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpColVector result(shape[0]);
copy_data_from_np(np_array, result.data);
return result;
Expand All @@ -335,7 +335,7 @@ void bindings_vpRowVector(py::class_<vpRowVector, vpArray2D<double>> &pyRowVecto
}, numpy_fn_doc_writable, py::keep_alive<0, 1>());
pyRowVector.def(py::init([](np_array_cf<double> np_array) {
verify_array_shape_and_dims(np_array, 1, "ViSP row vector");
const std::vector<ssize_t> shape = np_array.request().shape;
const std::vector<py::ssize_t> shape = np_array.request().shape;
vpRowVector result(shape[0]);
copy_data_from_np(np_array, result.data);
return result;
Expand Down
14 changes: 7 additions & 7 deletions modules/python/bindings/include/core/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using np_array_cf = py::array_t<Item, py::array::c_style | py::array::forcecast>
template<typename T, unsigned N>
py::buffer_info make_array_buffer(T *data, std::array<unsigned, N> dims, bool readonly)
{
std::array<ssize_t, N> strides;
std::array<py::ssize_t, N> strides;
for (unsigned i = 0; i < N; i++) {
unsigned s = sizeof(T);
for (unsigned j = i + 1; j < N; ++j) {
Expand All @@ -71,7 +71,7 @@ py::buffer_info make_array_buffer(T *data, std::array<unsigned, N> dims, bool re
);
}

std::string shape_to_string(const std::vector<ssize_t> &shape)
std::string shape_to_string(const std::vector<py::ssize_t> &shape)
{
std::stringstream ss;
ss << "(";
Expand All @@ -89,7 +89,7 @@ template<typename Item>
void verify_array_shape_and_dims(np_array_cf<Item> np_array, unsigned dims, const char *class_name)
{
py::buffer_info buffer = np_array.request();
std::vector<ssize_t> shape = buffer.shape;
std::vector<py::ssize_t> shape = buffer.shape;
if (shape.size() != dims) {
std::stringstream ss;
ss << "Tried to instanciate " << class_name
Expand All @@ -100,11 +100,11 @@ void verify_array_shape_and_dims(np_array_cf<Item> np_array, unsigned dims, cons
}
}
template<typename Item>
void verify_array_shape_and_dims(np_array_cf<Item> np_array, std::vector<ssize_t> expected_dims, const char *class_name)
void verify_array_shape_and_dims(np_array_cf<Item> np_array, std::vector<py::ssize_t> expected_dims, const char *class_name)
{
verify_array_shape_and_dims(np_array, expected_dims.size(), class_name);
py::buffer_info buffer = np_array.request();
std::vector<ssize_t> shape = buffer.shape;
std::vector<py::ssize_t> shape = buffer.shape;
bool invalid_shape = false;
for (unsigned int i = 0; i < expected_dims.size(); ++i) {
if (shape[i] != expected_dims[i]) {
Expand All @@ -125,9 +125,9 @@ template<typename Item>
void copy_data_from_np(np_array_cf<Item> src, Item *dest)
{
py::buffer_info buffer = src.request();
std::vector<ssize_t> shape = buffer.shape;
std::vector<py::ssize_t> shape = buffer.shape;
unsigned int elements = 1;
for (ssize_t dim : shape) {
for (py::ssize_t dim : shape) {
elements *= dim;
}
const Item *data = (Item *)buffer.ptr;
Expand Down
2 changes: 1 addition & 1 deletion modules/python/bindings/include/mbt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void bindings_vpMbGenericTracker(py::class_<vpMbGenericTracker, vpMbTracker> &py
for (const auto &point_cloud_pair: mapOfPointClouds) {

py::buffer_info buffer = point_cloud_pair.second.request();
if (buffer.ndim != 3 and buffer.shape[2] != 3) {
if (buffer.ndim != 3 && buffer.shape[2] != 3) {
std::stringstream ss;
ss << "Pointcloud error: pointcloud at key: " << point_cloud_pair.first <<
" should be a 3D numpy array of dimensions H X W x 3";
Expand Down
2 changes: 1 addition & 1 deletion modules/python/config/gui.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignored_headers": [],
"ignored_headers": ["vpWin32Renderer.h", "vpWin32Window.h", "vpWin32API.h", "vpGDIRenderer.h"],
"ignored_classes": [],
"user_defined_headers": [],
"classes": {},
Expand Down

0 comments on commit ac8e4b0

Please sign in to comment.