Skip to content

Commit 2249a44

Browse files
authored
Merge pull request #81 from pariterre/RotoPython
Rotation and RotoTrans from python
2 parents c302751 + b1a7430 commit 2249a44

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

binding/python3/biorbd_python.i.in

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,86 @@
9090
return output;
9191
};
9292
}
93+
%typemap(typecheck, precedence=2155) Eigen::Matrix3d & {
94+
if( PyArray_Check($input) ) {
95+
// test if it is a numpy array
96+
$1 = true;
97+
} else {
98+
$1 = false;
99+
}
100+
}
101+
%typemap(in) Eigen::Matrix3d & {
102+
if( PyArray_Check($input) ) {
103+
// Get dimensions of the data::
104+
int ndim = PyArray_NDIM ((PyArrayObject*)$input);
105+
npy_intp* dims = PyArray_DIMS ((PyArrayObject*)$input);
106+
107+
// Dimension controls
108+
if (ndim != 2 ){
109+
PyErr_SetString(PyExc_ValueError, "Eigen::Matrix3d must be a 3x3 matrix");
110+
SWIG_fail;
111+
}
112+
if (dims[0] != 3 || dims[1] != 3){
113+
PyErr_SetString(PyExc_ValueError, "Eigen::Matrix3d must be a 3x3 matrix");
114+
SWIG_fail;
115+
}
116+
117+
// Cast the vector
118+
PyObject *data = PyArray_FROM_OTF((PyObject*)$input, NPY_DOUBLE, NPY_IN_ARRAY);
119+
// Copy the actual data
120+
$1 = new Eigen::Matrix3d();
121+
for (unsigned int i=0; i<3; ++i){
122+
for (unsigned int j=0; j<3; ++j){
123+
(*$1)(i, j) = *(double*)PyArray_GETPTR2(data, i, j);
124+
}
125+
}
126+
} else {
127+
PyErr_SetString(PyExc_ValueError,
128+
"Eigen::Matrix3d must be a 3x3 matrix "
129+
"when using a numpy array");
130+
SWIG_fail;
131+
}
132+
};
133+
%typemap(typecheck, precedence=2155) Eigen::Matrix4d & {
134+
if( PyArray_Check($input) ) {
135+
// test if it is a numpy array
136+
$1 = true;
137+
} else {
138+
$1 = false;
139+
}
140+
}
141+
%typemap(in) Eigen::Matrix4d & {
142+
if( PyArray_Check($input) ) {
143+
// Get dimensions of the data::
144+
int ndim = PyArray_NDIM ((PyArrayObject*)$input);
145+
npy_intp* dims = PyArray_DIMS ((PyArrayObject*)$input);
146+
147+
// Dimension controls
148+
if (ndim != 2 ){
149+
PyErr_SetString(PyExc_ValueError, "Eigen::Matrix4d must be a 4x4 matrix");
150+
SWIG_fail;
151+
}
152+
if (dims[0] != 4 || dims[1] != 4){
153+
PyErr_SetString(PyExc_ValueError, "Eigen::Matrix4d must be a 4x4 matrix");
154+
SWIG_fail;
155+
}
156+
157+
// Cast the vector
158+
PyObject *data = PyArray_FROM_OTF((PyObject*)$input, NPY_DOUBLE, NPY_IN_ARRAY);
159+
// Copy the actual data
160+
$1 = new Eigen::Matrix4d();
161+
for (unsigned int i=0; i<4; ++i){
162+
for (unsigned int j=0; j<4; ++j){
163+
(*$1)(i, j) = *(double*)PyArray_GETPTR2(data, i, j);
164+
}
165+
}
166+
} else {
167+
PyErr_SetString(PyExc_ValueError,
168+
"Eigen::Matrix4d must be a 4x4 matrix "
169+
"when using a numpy array");
170+
SWIG_fail;
171+
}
172+
};
93173

94174
// --- Vector --- //
95175
%extend biorbd::utils::Vector{

include/Utils/Rotation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class BIORBD_API Rotation : public Eigen::Matrix3d
8383
/// sequence
8484
///
8585
biorbd::utils::Rotation& fromEulerAngles(
86-
const Eigen::VectorXd& rot,
86+
const biorbd::utils::Vector& rot,
8787
const biorbd::utils::String& seq);
8888

8989
///

src/Utils/Rotation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ biorbd::utils::Rotation biorbd::utils::Rotation::fromSpatialTransform(
4343
}
4444

4545
biorbd::utils::Rotation& biorbd::utils::Rotation::fromEulerAngles(
46-
const Eigen::VectorXd& rot,
46+
const biorbd::utils::Vector &rot,
4747
const biorbd::utils::String& seq)
4848
{
4949
// Check for size consistency

0 commit comments

Comments
 (0)