|
90 | 90 | return output; |
91 | 91 | }; |
92 | 92 | } |
| 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 | +}; |
93 | 173 |
|
94 | 174 | // --- Vector --- // |
95 | 175 | %extend biorbd::utils::Vector{ |
|
0 commit comments