| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
// clang-format off |
| 7 |
|
| 8 |
#define BOOST_PYTHON_MAX_ARITY 17 |
| 9 |
|
| 10 |
#include <Python.h> |
| 11 |
#define BOOST_BIND_GLOBAL_PLACEHOLDERS |
| 12 |
#include <boost/python.hpp> |
| 13 |
#include <boost/python/make_constructor.hpp> |
| 14 |
#include <boost/format.hpp> |
| 15 |
#include <boost/python/tuple.hpp> |
| 16 |
#include <boost/python/dict.hpp> |
| 17 |
#include <boost/python/raw_function.hpp> |
| 18 |
#include <ImathVec.h> |
| 19 |
#include <ImathMatrixAlgo.h> |
| 20 |
#include "PyImath.h" |
| 21 |
#include "PyImathVec.h" |
| 22 |
#include "PyImathMathExc.h" |
| 23 |
#include "PyImathMatrix.h" |
| 24 |
#include "PyImathExport.h" |
| 25 |
#include "PyImathDecorators.h" |
| 26 |
#include "PyImathTask.h" |
| 27 |
|
| 28 |
namespace PyImath { |
| 29 |
template<> const char PYIMATH_EXPORT *PyImath::M44fArray::name() { return "M44fArray"; } |
| 30 |
template<> const char PYIMATH_EXPORT *PyImath::M44dArray::name() { return "M44dArray"; } |
| 31 |
|
| 32 |
using namespace boost::python; |
| 33 |
using namespace IMATH_NAMESPACE; |
| 34 |
using namespace PyImath; |
| 35 |
|
| 36 |
template <class T, int len> |
| 37 |
struct MatrixRow { |
| 38 |
explicit MatrixRow(T *data) : _data(data) {} |
| 39 |
T & operator [] (int i) { return _data[i]; } |
| 40 |
T *_data; |
| 41 |
|
| 42 |
static const char *name; |
| 43 |
static void register_class() |
| 44 |
{ |
| 45 |
typedef PyImath::StaticFixedArray<MatrixRow,T,len> MatrixRow_helper; |
| 46 |
class_<MatrixRow> matrixRow_class(name,no_init); |
| 47 |
matrixRow_class |
| 48 |
.def("__len__", MatrixRow_helper::len) |
| 49 |
.def("__getitem__", MatrixRow_helper::getitem,return_value_policy<copy_non_const_reference>()) |
| 50 |
.def("__setitem__", MatrixRow_helper::setitem) |
| 51 |
; |
| 52 |
} |
| 53 |
}; |
| 54 |
|
| 55 |
template <> const char *MatrixRow<float,4>::name = "M44fRow"; |
| 56 |
template <> const char *MatrixRow<double,4>::name = "M44dRow"; |
| 57 |
|
| 58 |
|
| 59 |
template <class Container, class Data, int len> |
| 60 |
struct IndexAccessMatrixRow { |
| 61 |
typedef MatrixRow<Data,len> result_type; |
| 62 |
static MatrixRow<Data,len> apply(Container &c, int i) { return MatrixRow<Data,len>(c[i]); } |
| 63 |
}; |
| 64 |
|
| 65 |
template <class T> struct Matrix44Name { static const char *value; }; |
| 66 |
template<> const char *Matrix44Name<float>::value = "M44f"; |
| 67 |
template<> const char *Matrix44Name<double>::value = "M44d"; |
| 68 |
|
| 69 |
template <class T> |
| 70 |
static std::string Matrix44_str(const Matrix44<T> &v) |
| 71 |
{ |
| 72 |
std::stringstream stream; |
| 73 |
stream << Matrix44Name<T>::value << "("; |
| 74 |
for (int row = 0; row < 4; row++) |
| 75 |
{ |
| 76 |
stream << "("; |
| 77 |
for (int col = 0; col < 4; col++) |
| 78 |
{ |
| 79 |
stream << v[row][col]; |
| 80 |
stream << (col != 3 ? ", " : ""); |
| 81 |
} |
| 82 |
stream << ")" << (row != 3 ? ", " : ""); |
| 83 |
} |
| 84 |
stream << ")"; |
| 85 |
return stream.str(); |
| 86 |
} |
| 87 |
|
| 88 |
// Non-specialized repr is same as str |
| 89 |
template <class T> |
| 90 |
static std::string Matrix44_repr(const Matrix44<T> &v) |
| 91 |
{ |
| 92 |
return Matrix44_str(v); |
| 93 |
} |
| 94 |
|
| 95 |
// Specialization for float to full precision |
| 96 |
template <> |
| 97 |
std::string Matrix44_repr(const Matrix44<float> &v) |
| 98 |
{ |
| 99 |
return (boost::format("%s((%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g))") |
| 100 |
% Matrix44Name<float>::value |
| 101 |
% v[0][0] % v[0][1] % v[0][2] % v[0][3] |
| 102 |
% v[1][0] % v[1][1] % v[1][2] % v[1][3] |
| 103 |
% v[2][0] % v[2][1] % v[2][2] % v[2][3] |
| 104 |
% v[3][0] % v[3][1] % v[3][2] % v[3][3]).str(); |
| 105 |
} |
| 106 |
|
| 107 |
// Specialization for double to full precision |
| 108 |
template <> |
| 109 |
std::string Matrix44_repr(const Matrix44<double> &v) |
| 110 |
{ |
| 111 |
return (boost::format("%s((%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g))") |
| 112 |
% Matrix44Name<double>::value |
| 113 |
% v[0][0] % v[0][1] % v[0][2] % v[0][3] |
| 114 |
% v[1][0] % v[1][1] % v[1][2] % v[1][3] |
| 115 |
% v[2][0] % v[2][1] % v[2][2] % v[2][3] |
| 116 |
% v[3][0] % v[3][1] % v[3][2] % v[3][3]).str(); |
| 117 |
} |
| 118 |
|
| 119 |
template <class T> |
| 120 |
static const Matrix44<T> & |
| 121 |
invert44 (Matrix44<T> &m, bool singExc = true) |
| 122 |
{ |
| 123 |
MATH_EXC_ON; |
| 124 |
return m.invert(singExc); |
| 125 |
} |
| 126 |
|
| 127 |
template <class T> |
| 128 |
static Matrix44<T> |
| 129 |
inverse44 (Matrix44<T> &m, bool singExc = true) |
| 130 |
{ |
| 131 |
MATH_EXC_ON; |
| 132 |
return m.inverse(singExc); |
| 133 |
} |
| 134 |
|
| 135 |
template <class T> |
| 136 |
static const Matrix44<T> & |
| 137 |
gjInvert44 (Matrix44<T> &m, bool singExc = true) |
| 138 |
{ |
| 139 |
MATH_EXC_ON; |
| 140 |
return m.gjInvert(singExc); |
| 141 |
} |
| 142 |
|
| 143 |
template <class T> |
| 144 |
static Matrix44<T> |
| 145 |
gjInverse44 (Matrix44<T> &m, bool singExc = true) |
| 146 |
{ |
| 147 |
MATH_EXC_ON; |
| 148 |
return m.gjInverse(singExc); |
| 149 |
} |
| 150 |
|
| 151 |
template <class T, class U> |
| 152 |
static const Matrix44<T> & |
| 153 |
iadd44(Matrix44<T> &m, const Matrix44<U> &m2) |
| 154 |
{ |
| 155 |
MATH_EXC_ON; |
| 156 |
Matrix44<T> m3; |
| 157 |
m3.setValue (m2); |
| 158 |
return m += m3; |
| 159 |
} |
| 160 |
|
| 161 |
template <class T> |
| 162 |
static const Matrix44<T> & |
| 163 |
iadd44T(Matrix44<T> &mat, T a) |
| 164 |
{ |
| 165 |
MATH_EXC_ON; |
| 166 |
return mat += a; |
| 167 |
} |
| 168 |
|
| 169 |
template <class T> |
| 170 |
static Matrix44<T> |
| 171 |
add44(Matrix44<T> &m, const Matrix44<T> &m2) |
| 172 |
{ |
| 173 |
MATH_EXC_ON; |
| 174 |
return m + m2; |
| 175 |
} |
| 176 |
|
| 177 |
template <class T, class U> |
| 178 |
static const Matrix44<T> & |
| 179 |
isub44(Matrix44<T> &m, const Matrix44<U> &m2) |
| 180 |
{ |
| 181 |
MATH_EXC_ON; |
| 182 |
Matrix44<T> m3; |
| 183 |
m3.setValue (m2); |
| 184 |
return m -= m3; |
| 185 |
} |
| 186 |
|
| 187 |
template <class T> |
| 188 |
static const Matrix44<T> & |
| 189 |
isub44T(Matrix44<T> &mat, T a) |
| 190 |
{ |
| 191 |
MATH_EXC_ON; |
| 192 |
return mat -= a; |
| 193 |
} |
| 194 |
|
| 195 |
template <class T> |
| 196 |
static Matrix44<T> |
| 197 |
sub44(Matrix44<T> &m, const Matrix44<T> &m2) |
| 198 |
{ |
| 199 |
MATH_EXC_ON; |
| 200 |
return m - m2; |
| 201 |
} |
| 202 |
|
| 203 |
template <class T> |
| 204 |
static const Matrix44<T> & |
| 205 |
negate44 (Matrix44<T> &m) |
| 206 |
{ |
| 207 |
MATH_EXC_ON; |
| 208 |
return m.negate(); |
| 209 |
} |
| 210 |
|
| 211 |
template <class T> |
| 212 |
static Matrix44<T> |
| 213 |
neg44 (Matrix44<T> &m) |
| 214 |
{ |
| 215 |
MATH_EXC_ON; |
| 216 |
return -m; |
| 217 |
} |
| 218 |
|
| 219 |
template <class T> |
| 220 |
static const Matrix44<T> & |
| 221 |
imul44T(Matrix44<T> &m, const T &t) |
| 222 |
{ |
| 223 |
MATH_EXC_ON; |
| 224 |
return m *= t; |
| 225 |
} |
| 226 |
|
| 227 |
template <class T> |
| 228 |
static Matrix44<T> |
| 229 |
mul44T(Matrix44<T> &m, const T &t) |
| 230 |
{ |
| 231 |
MATH_EXC_ON; |
| 232 |
return m * t; |
| 233 |
} |
| 234 |
|
| 235 |
template <class T> |
| 236 |
static Matrix44<T> |
| 237 |
rmul44T(Matrix44<T> &m, const T &t) |
| 238 |
{ |
| 239 |
MATH_EXC_ON; |
| 240 |
return t * m; |
| 241 |
} |
| 242 |
|
| 243 |
template <class T> |
| 244 |
static const Matrix44<T> & |
| 245 |
idiv44T(Matrix44<T> &m, const T &t) |
| 246 |
{ |
| 247 |
MATH_EXC_ON; |
| 248 |
return m /= t; |
| 249 |
} |
| 250 |
|
| 251 |
template <class T> |
| 252 |
static Matrix44<T> |
| 253 |
div44T(Matrix44<T> &m, const T &t) |
| 254 |
{ |
| 255 |
MATH_EXC_ON; |
| 256 |
return m / t; |
| 257 |
} |
| 258 |
|
| 259 |
template <class T> |
| 260 |
static void |
| 261 |
extractAndRemoveScalingAndShear44(Matrix44<T> &mat, Vec3<T> &dstScl, Vec3<T> &dstShr, int exc = 1) |
| 262 |
{ |
| 263 |
MATH_EXC_ON; |
| 264 |
IMATH_NAMESPACE::extractAndRemoveScalingAndShear(mat, dstScl, dstShr, exc); |
| 265 |
} |
| 266 |
|
| 267 |
template <class T> |
| 268 |
static void |
| 269 |
extractEulerXYZ(Matrix44<T> &mat, IMATH_NAMESPACE::Vec3<T> &dst) |
| 270 |
{ |
| 271 |
MATH_EXC_ON; |
| 272 |
IMATH_NAMESPACE::extractEulerXYZ(mat, dst); |
| 273 |
} |
| 274 |
|
| 275 |
template <class T> |
| 276 |
static void |
| 277 |
extractEulerZYX(Matrix44<T> &mat, IMATH_NAMESPACE::Vec3<T> &dst) |
| 278 |
{ |
| 279 |
MATH_EXC_ON; |
| 280 |
IMATH_NAMESPACE::extractEulerZYX(mat, dst); |
| 281 |
} |
| 282 |
|
| 283 |
template <class T> |
| 284 |
static int |
| 285 |
extractSHRT44(Matrix44<T> &mat, Vec3<T> &s, Vec3<T> &h, Vec3<T> &r, Vec3<T> &t, int exc = 1) |
| 286 |
{ |
| 287 |
MATH_EXC_ON; |
| 288 |
return IMATH_NAMESPACE::extractSHRT(mat, s, h, r, t, exc); |
| 289 |
} |
| 290 |
|
| 291 |
template <class T> |
| 292 |
static void |
| 293 |
extractScaling44(Matrix44<T> &mat, Vec3<T> &dst, int exc = 1) |
| 294 |
{ |
| 295 |
MATH_EXC_ON; |
| 296 |
IMATH_NAMESPACE::extractScaling(mat, dst, exc); |
| 297 |
} |
| 298 |
|
| 299 |
template <class T> |
| 300 |
static void |
| 301 |
extractScalingAndShear44(Matrix44<T> &mat, Vec3<T> &dstScl, Vec3<T> &dstShr, int exc = 1) |
| 302 |
{ |
| 303 |
MATH_EXC_ON; |
| 304 |
IMATH_NAMESPACE::extractScalingAndShear(mat, dstScl, dstShr, exc); |
| 305 |
} |
| 306 |
|
| 307 |
template <class TV,class TM> |
| 308 |
static void |
| 309 |
multDirMatrix44(Matrix44<TM> &mat, const Vec3<TV> &src, Vec3<TV> &dst) |
| 310 |
{ |
| 311 |
MATH_EXC_ON; |
| 312 |
mat.multDirMatrix(src, dst); |
| 313 |
} |
| 314 |
|
| 315 |
template <class TV,class TM> |
| 316 |
static Vec3<TV> |
| 317 |
multDirMatrix44_return_value(Matrix44<TM> &mat, const Vec3<TV> &src) |
| 318 |
{ |
| 319 |
MATH_EXC_ON; |
| 320 |
Vec3<TV> dst; |
| 321 |
mat.multDirMatrix(src, dst); |
| 322 |
return dst; |
| 323 |
} |
| 324 |
|
| 325 |
template <class T1, class T2> |
| 326 |
struct op_multDirMatrix { |
| 327 |
|
| 328 |
static inline void apply(const Matrix44<T2>& m, const Vec3<T1>& src, Vec3<T1>& dst) |
| 329 |
{ |
| 330 |
m.multDirMatrix(src,dst); |
| 331 |
} |
| 332 |
}; |
| 333 |
|
| 334 |
template <class T1, class T2> |
| 335 |
struct op_multVecMatrix { |
| 336 |
|
| 337 |
static inline void apply(const Matrix44<T2>& m, const Vec3<T1>& src, Vec3<T1>& dst) |
| 338 |
{ |
| 339 |
m.multVecMatrix(src,dst); |
| 340 |
} |
| 341 |
}; |
| 342 |
|
| 343 |
template <class T1,class T2, class Op> |
| 344 |
struct MatrixVecTask : public Task |
| 345 |
{ |
| 346 |
const Matrix44<T2> &mat; |
| 347 |
const FixedArray<Vec3<T1> >& src; |
| 348 |
FixedArray<Vec3<T1> >& dst; |
| 349 |
|
| 350 |
MatrixVecTask(const Matrix44<T2> &m, const FixedArray<Vec3<T1> >& s, FixedArray<Vec3<T1> >& d) |
| 351 |
: mat(m), src(s), dst(d) {} |
| 352 |
|
| 353 |
void execute(size_t start, size_t end) |
| 354 |
{ |
| 355 |
for(size_t p = start; p < end; ++p) |
| 356 |
Op::apply(mat,src[p],dst[p]); |
| 357 |
} |
| 358 |
}; |
| 359 |
|
| 360 |
template <class TV,class TM> |
| 361 |
static FixedArray<Vec3<TV> > |
| 362 |
multDirMatrix44_array(Matrix44<TM> &mat, const FixedArray<Vec3<TV> >&src) |
| 363 |
{ |
| 364 |
MATH_EXC_ON; |
| 365 |
size_t len = src.len(); |
| 366 |
FixedArray<Vec3<TV> > dst(len); |
| 367 |
|
| 368 |
MatrixVecTask<TV,TM,op_multDirMatrix<TV,TM> > task(mat,src,dst); |
| 369 |
dispatchTask(task,len); |
| 370 |
|
| 371 |
return dst; |
| 372 |
} |
| 373 |
|
| 374 |
template <class TV,class TM> |
| 375 |
static void |
| 376 |
multVecMatrix44(Matrix44<TM> &mat, const Vec3<TV> &src, Vec3<TV> &dst) |
| 377 |
{ |
| 378 |
MATH_EXC_ON; |
| 379 |
mat.multVecMatrix(src, dst); |
| 380 |
} |
| 381 |
|
| 382 |
template <class TV,class TM> |
| 383 |
static Vec3<TV> |
| 384 |
multVecMatrix44_return_value(Matrix44<TM> &mat, const Vec3<TV> &src) |
| 385 |
{ |
| 386 |
MATH_EXC_ON; |
| 387 |
Vec3<TV> dst; |
| 388 |
mat.multVecMatrix(src, dst); |
| 389 |
return dst; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
template <class TV,class TM> |
| 394 |
static FixedArray<Vec3<TV> > |
| 395 |
multVecMatrix44_array(Matrix44<TM> &mat, const FixedArray<Vec3<TV> >&src) |
| 396 |
{ |
| 397 |
MATH_EXC_ON; |
| 398 |
size_t len = src.len(); |
| 399 |
FixedArray<Vec3<TV> > dst(len); |
| 400 |
|
| 401 |
MatrixVecTask<TV,TM,op_multVecMatrix<TV,TM> > task(mat,src,dst); |
| 402 |
dispatchTask(task,len); |
| 403 |
|
| 404 |
return dst; |
| 405 |
} |
| 406 |
|
| 407 |
template <class T> |
| 408 |
static int |
| 409 |
removeScaling44(Matrix44<T> &mat, int exc = 1) |
| 410 |
{ |
| 411 |
MATH_EXC_ON; |
| 412 |
return IMATH_NAMESPACE::removeScaling(mat, exc); |
| 413 |
} |
| 414 |
|
| 415 |
template <class T> |
| 416 |
static int |
| 417 |
removeScalingAndShear44(Matrix44<T> &mat, int exc = 1) |
| 418 |
{ |
| 419 |
MATH_EXC_ON; |
| 420 |
return IMATH_NAMESPACE::removeScalingAndShear(mat, exc); |
| 421 |
} |
| 422 |
|
| 423 |
template <class T> |
| 424 |
static Matrix44<T> |
| 425 |
sansScaling44(const Matrix44<T> &mat, bool exc = true) |
| 426 |
{ |
| 427 |
MATH_EXC_ON; |
| 428 |
return IMATH_NAMESPACE::sansScaling(mat, exc); |
| 429 |
} |
| 430 |
|
| 431 |
template <class T> |
| 432 |
static Matrix44<T> |
| 433 |
sansScalingAndShear44(const Matrix44<T> &mat, bool exc = true) |
| 434 |
{ |
| 435 |
MATH_EXC_ON; |
| 436 |
return IMATH_NAMESPACE::sansScalingAndShear(mat, exc); |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
template <class T> |
| 441 |
static const Matrix44<T> & |
| 442 |
scaleSc44(Matrix44<T> &mat, const T &s) |
| 443 |
{ |
| 444 |
MATH_EXC_ON; |
| 445 |
Vec3<T> sVec(s, s, s); |
| 446 |
return mat.scale(sVec); |
| 447 |
} |
| 448 |
|
| 449 |
template <class T> |
| 450 |
static const Matrix44<T> & |
| 451 |
scaleV44(Matrix44<T> &mat, const Vec3<T> &s) |
| 452 |
{ |
| 453 |
MATH_EXC_ON; |
| 454 |
return mat.scale(s); |
| 455 |
} |
| 456 |
|
| 457 |
template <class T> |
| 458 |
static const Matrix44<T> & |
| 459 |
scale44Tuple(Matrix44<T> &mat, const tuple &t) |
| 460 |
{ |
| 461 |
MATH_EXC_ON; |
| 462 |
if(t.attr("__len__")() == 3) |
| 463 |
{ |
| 464 |
Vec3<T> s; |
| 465 |
s.x = extract<T>(t[0]); |
| 466 |
s.y = extract<T>(t[1]); |
| 467 |
s.z = extract<T>(t[2]); |
| 468 |
|
| 469 |
return mat.scale(s); |
| 470 |
} |
| 471 |
else |
| 472 |
throw std::domain_error ("m.scale needs tuple of length 3"); |
| 473 |
} |
| 474 |
|
| 475 |
template <class T> |
| 476 |
static const Matrix44<T> & |
| 477 |
rotateV44(Matrix44<T> &mat, const Vec3<T> &r) |
| 478 |
{ |
| 479 |
MATH_EXC_ON; |
| 480 |
return mat.rotate(r); |
| 481 |
} |
| 482 |
|
| 483 |
template <class T> |
| 484 |
static const Matrix44<T> & |
| 485 |
rotationMatrix44(Matrix44<T> &mat, const object &fromObj, const object &toObj) |
| 486 |
{ |
| 487 |
MATH_EXC_ON; |
| 488 |
Vec3<T> from, to; |
| 489 |
if (PyImath::V3<T>::convert (fromObj.ptr(), &from) && |
| 490 |
PyImath::V3<T>::convert (toObj.ptr(), &to)) |
| 491 |
{ |
| 492 |
Matrix44<T> rot = IMATH_NAMESPACE::rotationMatrix(from, to); |
| 493 |
return mat.setValue(rot); |
| 494 |
} |
| 495 |
else |
| 496 |
{ |
| 497 |
throw std::invalid_argument ("m.rotationMatrix expected V3 arguments"); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
template <class T> |
| 502 |
static const Matrix44<T> & |
| 503 |
rotationMatrixWithUp44(Matrix44<T> &mat, const object &fromObj, const object &toObj, |
| 504 |
const object &upObj) |
| 505 |
{ |
| 506 |
MATH_EXC_ON; |
| 507 |
Vec3<T> from, to, up; |
| 508 |
if (PyImath::V3<T>::convert (fromObj.ptr(), &from) && |
| 509 |
PyImath::V3<T>::convert (toObj.ptr(), &to) & |
| 510 |
PyImath::V3<T>::convert (upObj.ptr(), &up)) |
| 511 |
{ |
| 512 |
Matrix44<T> rot = IMATH_NAMESPACE::rotationMatrixWithUpDir(from, to, up); |
| 513 |
return mat.setValue(rot); |
| 514 |
} |
| 515 |
else |
| 516 |
{ |
| 517 |
throw std::invalid_argument ("m.rotationMatrix expected V3 arguments"); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
template <class T> |
| 522 |
static const Matrix44<T> & |
| 523 |
setScaleSc44(Matrix44<T> &mat, const T &s) |
| 524 |
{ |
| 525 |
MATH_EXC_ON; |
| 526 |
return mat.setScale(s); |
| 527 |
} |
| 528 |
|
| 529 |
template <class T> |
| 530 |
static const Matrix44<T> & |
| 531 |
setScaleV44(Matrix44<T> &mat, const Vec3<T> &s) |
| 532 |
{ |
| 533 |
MATH_EXC_ON; |
| 534 |
return mat.setScale(s); |
| 535 |
} |
| 536 |
|
| 537 |
template <class T> |
| 538 |
static const Matrix44<T> & |
| 539 |
setScale44Tuple(Matrix44<T> &mat, const tuple &t) |
| 540 |
{ |
| 541 |
MATH_EXC_ON; |
| 542 |
if(t.attr("__len__")() == 3) |
| 543 |
{ |
| 544 |
Vec3<T> s; |
| 545 |
s.x = extract<T>(t[0]); |
| 546 |
s.y = extract<T>(t[1]); |
| 547 |
s.z = extract<T>(t[2]); |
| 548 |
|
| 549 |
return mat.setScale(s); |
| 550 |
} |
| 551 |
else |
| 552 |
throw std::domain_error ("m.translate needs tuple of length 3"); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
template <class T> |
| 557 |
static const Matrix44<T> & |
| 558 |
setShearV44(Matrix44<T> &mat, const Vec3<T> &sVec) |
| 559 |
{ |
| 560 |
MATH_EXC_ON; |
| 561 |
return mat.setShear(sVec); |
| 562 |
} |
| 563 |
|
| 564 |
template <class T> |
| 565 |
static const Matrix44<T> & |
| 566 |
setShearS44(Matrix44<T> &mat, const Shear6<T> &s) |
| 567 |
{ |
| 568 |
MATH_EXC_ON; |
| 569 |
return mat.setShear(s); |
| 570 |
} |
| 571 |
|
| 572 |
template <class T> |
| 573 |
static const Matrix44<T> & |
| 574 |
setShear44Tuple(Matrix44<T> &mat, const tuple &t) |
| 575 |
{ |
| 576 |
MATH_EXC_ON; |
| 577 |
if(t.attr("__len__")() == 3) |
| 578 |
{ |
| 579 |
Vec3<T> s; |
| 580 |
s.x = extract<T>(t[0]); |
| 581 |
s.y = extract<T>(t[1]); |
| 582 |
s.z = extract<T>(t[2]); |
| 583 |
|
| 584 |
return mat.setShear(s); |
| 585 |
} |
| 586 |
else if(t.attr("__len__")() == 6) |
| 587 |
{ |
| 588 |
Shear6<T> shear; |
| 589 |
for(int i = 0; i < 6; ++i) |
| 590 |
{ |
| 591 |
shear[i] = extract<T>(t[i]); |
| 592 |
} |
| 593 |
|
| 594 |
return mat.setShear(shear); |
| 595 |
} |
| 596 |
else |
| 597 |
throw std::domain_error ("m.setShear needs tuple of length 3 or 6"); |
| 598 |
} |
| 599 |
|
| 600 |
template <class T> |
| 601 |
static const Matrix44<T> & |
| 602 |
setTranslation44(Matrix44<T> &mat, const Vec3<T> t) |
| 603 |
{ |
| 604 |
MATH_EXC_ON; |
| 605 |
return mat.setTranslation(t); |
| 606 |
} |
| 607 |
|
| 608 |
template <class T> |
| 609 |
static const Matrix44<T> & |
| 610 |
setTranslation44Tuple(Matrix44<T> &mat, const tuple &t) |
| 611 |
{ |
| 612 |
MATH_EXC_ON; |
| 613 |
if(t.attr("__len__")() == 3) |
| 614 |
{ |
| 615 |
Vec3<T> trans; |
| 616 |
trans.x = extract<T>(t[0]); |
| 617 |
trans.y = extract<T>(t[1]); |
| 618 |
trans.z = extract<T>(t[2]); |
| 619 |
|
| 620 |
return mat.setTranslation(trans); |
| 621 |
} |
| 622 |
else |
| 623 |
throw std::domain_error ("m.translate needs tuple of length 3"); |
| 624 |
} |
| 625 |
|
| 626 |
template <class T> |
| 627 |
static const Matrix44<T> & |
| 628 |
setTranslation44Obj(Matrix44<T> &mat, const object &o) |
| 629 |
{ |
| 630 |
MATH_EXC_ON; |
| 631 |
Vec3<T> v; |
| 632 |
if (PyImath::V3<T>::convert (o.ptr(), &v)) |
| 633 |
{ |
| 634 |
return mat.setTranslation(v); |
| 635 |
} |
| 636 |
else |
| 637 |
{ |
| 638 |
throw std::invalid_argument ("m.setTranslation expected V3 argument"); |
| 639 |
return mat; |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
template <class T> |
| 644 |
static void |
| 645 |
setValue44(Matrix44<T> &mat, const Matrix44<T> &value) |
| 646 |
{ |
| 647 |
MATH_EXC_ON; |
| 648 |
mat.setValue(value); |
| 649 |
} |
| 650 |
|
| 651 |
template <class T> |
| 652 |
static const Matrix44<T> & |
| 653 |
shearV44(Matrix44<T> &mat, const Vec3<T> &s) |
| 654 |
{ |
| 655 |
MATH_EXC_ON; |
| 656 |
IMATH_NAMESPACE::Shear6<T> shear(s[0], s[1], s[2], T (0), T (0), T (0)); |
| 657 |
return mat.shear(shear); |
| 658 |
} |
| 659 |
|
| 660 |
template <class T> |
| 661 |
static const Matrix44<T> & |
| 662 |
shearS44(Matrix44<T> &mat, const Shear6<T> &s) |
| 663 |
{ |
| 664 |
MATH_EXC_ON; |
| 665 |
return mat.shear(s); |
| 666 |
} |
| 667 |
|
| 668 |
template <class T> |
| 669 |
static const Matrix44<T> & |
| 670 |
shear44Tuple(Matrix44<T> &mat, const tuple &t) |
| 671 |
{ |
| 672 |
MATH_EXC_ON; |
| 673 |
if(t.attr("__len__")() == 3) |
| 674 |
{ |
| 675 |
Vec3<T> s; |
| 676 |
s.x = extract<T>(t[0]); |
| 677 |
s.y = extract<T>(t[1]); |
| 678 |
s.z = extract<T>(t[2]); |
| 679 |
Shear6<T> shear(s); |
| 680 |
|
| 681 |
return mat.shear(shear); |
| 682 |
} |
| 683 |
else if(t.attr("__len__")() == 6) |
| 684 |
{ |
| 685 |
Shear6<T> shear; |
| 686 |
for(int i = 0; i < 6; ++i) |
| 687 |
{ |
| 688 |
shear[i] = extract<T>(t[i]); |
| 689 |
} |
| 690 |
|
| 691 |
return mat.shear(shear); |
| 692 |
} |
| 693 |
else |
| 694 |
throw std::domain_error ("m.shear needs tuple of length 3 or 6"); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
template <class T> |
| 699 |
static const Matrix44<T> & |
| 700 |
translate44(Matrix44<T> &mat, const object &t) |
| 701 |
{ |
| 702 |
MATH_EXC_ON; |
| 703 |
Vec3<T> v; |
| 704 |
if (PyImath::V3<T>::convert (t.ptr(), &v)) |
| 705 |
{ |
| 706 |
return mat.translate(v); |
| 707 |
} |
| 708 |
else |
| 709 |
{ |
| 710 |
throw std::invalid_argument ("m.translate expected V3 argument"); |
| 711 |
return mat; |
| 712 |
} |
| 713 |
} |
| 714 |
template <class T> |
| 715 |
static const Matrix44<T> & |
| 716 |
translate44Tuple(Matrix44<T> &mat, const tuple &t) |
| 717 |
{ |
| 718 |
MATH_EXC_ON; |
| 719 |
if(t.attr("__len__")() == 3) |
| 720 |
{ |
| 721 |
Vec3<T> trans; |
| 722 |
trans.x = extract<T>(t[0]); |
| 723 |
trans.y = extract<T>(t[1]); |
| 724 |
trans.z = extract<T>(t[2]); |
| 725 |
|
| 726 |
return mat.translate(trans); |
| 727 |
} |
| 728 |
else |
| 729 |
throw std::domain_error ("m.translate needs tuple of length 3"); |
| 730 |
} |
| 731 |
|
| 732 |
template <class T> |
| 733 |
static Matrix44<T> |
| 734 |
subtractTL44(Matrix44<T> &mat, T a) |
| 735 |
{ |
| 736 |
MATH_EXC_ON; |
| 737 |
Matrix44<T> m(mat.x); |
| 738 |
for(int i = 0; i < 4; ++i) |
| 739 |
for(int j = 0; j < 4; ++j) |
| 740 |
m.x[i][j] -= a; |
| 741 |
|
| 742 |
return m; |
| 743 |
} |
| 744 |
|
| 745 |
template <class T> |
| 746 |
static Matrix44<T> |
| 747 |
subtractTR44(Matrix44<T> &mat, T a) |
| 748 |
{ |
| 749 |
MATH_EXC_ON; |
| 750 |
Matrix44<T> m(mat.x); |
| 751 |
for(int i = 0; i < 4; ++i) |
| 752 |
for(int j = 0; j < 4; ++j) |
| 753 |
m.x[i][j] = a - m.x[i][j]; |
| 754 |
|
| 755 |
return m; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
template <class T> |
| 760 |
static Matrix44<T> |
| 761 |
add44T(Matrix44<T> &mat, T a) |
| 762 |
{ |
| 763 |
MATH_EXC_ON; |
| 764 |
Matrix44<T> m(mat.x); |
| 765 |
for(int i = 0; i < 4; ++i) |
| 766 |
for(int j = 0; j < 4; ++j) |
| 767 |
m.x[i][j] += a; |
| 768 |
|
| 769 |
return m; |
| 770 |
} |
| 771 |
|
| 772 |
template <class S, class T> |
| 773 |
static Matrix44<T> |
| 774 |
mul44(Matrix44<T> &mat1, Matrix44<S> &mat2) |
| 775 |
{ |
| 776 |
MATH_EXC_ON; |
| 777 |
Matrix44<T> mat2T; |
| 778 |
mat2T.setValue (mat2); |
| 779 |
return mat1 * mat2T; |
| 780 |
} |
| 781 |
|
| 782 |
template <class S, class T> |
| 783 |
static Matrix44<T> |
| 784 |
rmul44(Matrix44<T> &mat2, Matrix44<S> &mat1) |
| 785 |
{ |
| 786 |
MATH_EXC_ON; |
| 787 |
Matrix44<T> mat1T; |
| 788 |
mat1T.setValue (mat1); |
| 789 |
return mat1T * mat2; |
| 790 |
} |
| 791 |
|
| 792 |
template <class S, class T> |
| 793 |
static const Matrix44<T> & |
| 794 |
imul44(Matrix44<T> &mat1, Matrix44<S> &mat2) |
| 795 |
{ |
| 796 |
MATH_EXC_ON; |
| 797 |
Matrix44<T> mat2T; |
| 798 |
mat2T.setValue (mat2); |
| 799 |
return mat1 *= mat2T; |
| 800 |
} |
| 801 |
|
| 802 |
template <class T> |
| 803 |
static bool |
| 804 |
lessThan44(Matrix44<T> &mat1, const Matrix44<T> &mat2) |
| 805 |
{ |
| 806 |
for(int i = 0; i < 4; ++i){ |
| 807 |
for(int j = 0; j < 4; ++j){ |
| 808 |
if(mat1[i][j] > mat2[i][j]){ |
| 809 |
return false; |
| 810 |
} |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
return (mat1 != mat2); |
| 815 |
} |
| 816 |
|
| 817 |
template <class T> |
| 818 |
static bool |
| 819 |
lessThanEqual44(Matrix44<T> &mat1, const Matrix44<T> &mat2) |
| 820 |
{ |
| 821 |
for(int i = 0; i < 4; ++i){ |
| 822 |
for(int j = 0; j < 4; ++j){ |
| 823 |
if(mat1[i][j] > mat2[i][j]){ |
| 824 |
return false; |
| 825 |
} |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
return true; |
| 830 |
} |
| 831 |
|
| 832 |
template <class T> |
| 833 |
static bool |
| 834 |
greaterThan44(Matrix44<T> &mat1, const Matrix44<T> &mat2) |
| 835 |
{ |
| 836 |
for(int i = 0; i < 4; ++i){ |
| 837 |
for(int j = 0; j < 4; ++j){ |
| 838 |
if(mat1[i][j] < mat2[i][j]){ |
| 839 |
return false; |
| 840 |
} |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
return (mat1 != mat2); |
| 845 |
} |
| 846 |
|
| 847 |
template <class T> |
| 848 |
static bool |
| 849 |
greaterThanEqual44(Matrix44<T> &mat1, const Matrix44<T> &mat2) |
| 850 |
{ |
| 851 |
for(int i = 0; i < 4; ++i){ |
| 852 |
for(int j = 0; j < 4; ++j){ |
| 853 |
if(mat1[i][j] < mat2[i][j]){ |
| 854 |
return false; |
| 855 |
} |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
return true; |
| 860 |
} |
| 861 |
|
| 862 |
template <class T> |
| 863 |
static tuple |
| 864 |
singularValueDecomposition44(const Matrix44<T>& m, bool forcePositiveDeterminant = false) |
| 865 |
{ |
| 866 |
IMATH_NAMESPACE::Matrix44<T> U, V; |
| 867 |
IMATH_NAMESPACE::Vec4<T> S; |
| 868 |
IMATH_NAMESPACE::jacobiSVD (m, U, S, V, std::numeric_limits<T>::epsilon(), forcePositiveDeterminant); |
| 869 |
return make_tuple (U, S, V); |
| 870 |
} |
| 871 |
|
| 872 |
BOOST_PYTHON_FUNCTION_OVERLOADS(invert44_overloads, invert44, 1, 2); |
| 873 |
BOOST_PYTHON_FUNCTION_OVERLOADS(inverse44_overloads, inverse44, 1, 2); |
| 874 |
BOOST_PYTHON_FUNCTION_OVERLOADS(gjInvert44_overloads, gjInvert44, 1, 2); |
| 875 |
BOOST_PYTHON_FUNCTION_OVERLOADS(gjInverse44_overloads, gjInverse44, 1, 2); |
| 876 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractAndRemoveScalingAndShear44_overloads, extractAndRemoveScalingAndShear44, 3, 4) |
| 877 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractSHRT44_overloads, extractSHRT44, 5, 6) |
| 878 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractScaling44_overloads, extractScaling44, 2, 3) |
| 879 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractScalingAndShear44_overloads, extractScalingAndShear44, 3, 4) |
| 880 |
BOOST_PYTHON_FUNCTION_OVERLOADS(removeScaling44_overloads, removeScaling44, 1, 2) |
| 881 |
BOOST_PYTHON_FUNCTION_OVERLOADS(removeScalingAndShear44_overloads, removeScalingAndShear44, 1, 2) |
| 882 |
BOOST_PYTHON_FUNCTION_OVERLOADS(sansScaling44_overloads, sansScaling44, 1, 2) |
| 883 |
BOOST_PYTHON_FUNCTION_OVERLOADS(sansScalingAndShear44_overloads, sansScalingAndShear44, 1, 2) |
| 884 |
|
| 885 |
template <class T> |
| 886 |
static Matrix44<T> * Matrix4_tuple_constructor(const tuple &t0, const tuple &t1, const tuple &t2, const tuple &t3) |
| 887 |
{ |
| 888 |
if(t0.attr("__len__")() == 4 && t1.attr("__len__")() == 4 && t2.attr("__len__")() == 4 && t3.attr("__len__")() == 4) |
| 889 |
{ |
| 890 |
return new Matrix44<T>(extract<T>(t0[0]), extract<T>(t0[1]), extract<T>(t0[2]), extract<T>(t0[3]), |
| 891 |
extract<T>(t1[0]), extract<T>(t1[1]), extract<T>(t1[2]), extract<T>(t1[3]), |
| 892 |
extract<T>(t2[0]), extract<T>(t2[1]), extract<T>(t2[2]), extract<T>(t2[3]), |
| 893 |
extract<T>(t3[0]), extract<T>(t3[1]), extract<T>(t3[2]), extract<T>(t3[3])); |
| 894 |
} |
| 895 |
else |
| 896 |
throw std::domain_error ("Matrix44 takes 4 tuples of length 4"); |
| 897 |
} |
| 898 |
|
| 899 |
template <class T, class S> |
| 900 |
static Matrix44<T> *Matrix4_matrix_constructor(const Matrix44<S> &mat) |
| 901 |
{ |
| 902 |
Matrix44<T> *m = new Matrix44<T>; |
| 903 |
|
| 904 |
for(int i = 0; i < 4; ++i) |
| 905 |
for(int j = 0; j < 4; ++j) |
| 906 |
m->x[i][j] = T (mat.x[i][j]); |
| 907 |
|
| 908 |
return m; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
template <class T> |
| 913 |
class_<Matrix44<T> > |
| 914 |
register_Matrix44() |
| 915 |
{ |
| 916 |
typedef PyImath::StaticFixedArray<Matrix44<T>,T,4,IndexAccessMatrixRow<Matrix44<T>,T,4> > Matrix44_helper; |
| 917 |
|
| 918 |
MatrixRow<T,4>::register_class(); |
| 919 |
|
| 920 |
class_<Matrix44<T> > matrix44_class(Matrix44Name<T>::value, Matrix44Name<T>::value,init<Matrix44<T> >("copy construction")); |
| 921 |
matrix44_class |
| 922 |
.def(init<>("initialize to identity")) |
| 923 |
.def(init<T>("initialize all entries to a single value")) |
| 924 |
.def("__init__", make_constructor(Matrix4_tuple_constructor<T>),"tuple constructor1") |
| 925 |
.def("__init__", make_constructor(Matrix4_matrix_constructor<T,float>)) |
| 926 |
.def("__init__", make_constructor(Matrix4_matrix_constructor<T,double>)) |
| 927 |
|
| 928 |
.def(init<T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T>("make from components")) |
| 929 |
//.def_readwrite("x00", &Matrix44<T>::x[0][0]) |
| 930 |
//.def_readwrite("x01", &Matrix44<T>::x[0][1]) |
| 931 |
//.def_readwrite("x02", &Matrix44<T>::x[0][2]) |
| 932 |
//.def_readwrite("x03", &Matrix44<T>::x[0][3]) |
| 933 |
//.def_readwrite("x10", &Matrix44<T>::x[1][0]) |
| 934 |
//.def_readwrite("x11", &Matrix44<T>::x[1][1]) |
| 935 |
//.def_readwrite("x12", &Matrix44<T>::x[1][2]) |
| 936 |
//.def_readwrite("x13", &Matrix44<T>::x[1][3]) |
| 937 |
//.def_readwrite("x20", &Matrix44<T>::x[2][0]) |
| 938 |
//.def_readwrite("x21", &Matrix44<T>::x[2][1]) |
| 939 |
//.def_readwrite("x22", &Matrix44<T>::x[2][2]) |
| 940 |
//.def_readwrite("x23", &Matrix44<T>::x[2][3]) |
| 941 |
//.def_readwrite("x30", &Matrix44<T>::x[3][0]) |
| 942 |
//.def_readwrite("x31", &Matrix44<T>::x[3][1]) |
| 943 |
//.def_readwrite("x32", &Matrix44<T>::x[3][2]) |
| 944 |
//.def_readwrite("x33", &Matrix44<T>::x[3][3]) |
| 945 |
.def("baseTypeEpsilon", &Matrix44<T>::baseTypeEpsilon,"baseTypeEpsilon() epsilon value of the base type of the vector") |
| 946 |
.staticmethod("baseTypeEpsilon") |
| 947 |
.def("baseTypeMax", &Matrix44<T>::baseTypeMax,"baseTypeMax() max value of the base type of the vector") |
| 948 |
.staticmethod("baseTypeMax") |
| 949 |
.def("baseTypeLowest", &Matrix44<T>::baseTypeLowest,"baseTypeLowest() largest negative value of the base type of the vector") |
| 950 |
.staticmethod("baseTypeLowest") |
| 951 |
.def("baseTypeSmallest", &Matrix44<T>::baseTypeSmallest,"baseTypeSmallest() smallest value of the base type of the vector") |
| 952 |
.staticmethod("baseTypeSmallest") |
| 953 |
.def("equalWithAbsError", &Matrix44<T>::equalWithAbsError, |
| 954 |
"m1.equalWithAbsError(m2,e) true if the elements " |
| 955 |
"of v1 and v2 are the same with an absolute error of no more than e, " |
| 956 |
"i.e., abs(m1[i] - m2[i]) <= e") |
| 957 |
|
| 958 |
.def("equalWithRelError", &Matrix44<T>::equalWithRelError, |
| 959 |
"m1.equalWithAbsError(m2,e) true if the elements " |
| 960 |
"of m1 and m2 are the same with an absolute error of no more than e, " |
| 961 |
"i.e., abs(m1[i] - m2[i]) <= e * abs(m1[i])") |
| 962 |
|
| 963 |
// need a different version for matrix data access |
| 964 |
.def("__len__", Matrix44_helper::len) |
| 965 |
.def("__getitem__", Matrix44_helper::getitem) |
| 966 |
//.def("__setitem__", Matrix44_helper::setitem) |
| 967 |
.def("makeIdentity",&Matrix44<T>::makeIdentity,"makeIdentity() make this matrix the identity matrix") |
| 968 |
.def("transpose",&Matrix44<T>::transpose,return_internal_reference<>(),"transpose() transpose this matrix") |
| 969 |
.def("transposed",&Matrix44<T>::transposed,"transposed() return a transposed copy of this matrix") |
| 970 |
.def("minorOf",&Matrix44<T>::minorOf,"minorOf() return matrix minor of the (row,col) element of this matrix") |
| 971 |
.def("fastMinor",&Matrix44<T>::fastMinor,"fastMinor() return matrix minor using the specified rows and columns of this matrix") |
| 972 |
.def("determinant",&Matrix44<T>::determinant,"determinant() return the determinant of this matrix") |
| 973 |
.def("invert",&invert44<T>,invert44_overloads("invert() invert this matrix")[return_internal_reference<>()]) |
| 974 |
.def("inverse",&inverse44<T>,inverse44_overloads("inverse() return an inverted copy of this matrix")) |
| 975 |
.def("gjInvert",&gjInvert44<T>,gjInvert44_overloads("gjInvert() invert this matrix")[return_internal_reference<>()]) |
| 976 |
.def("gjInverse",&gjInverse44<T>,gjInverse44_overloads("gjInverse() return an inverted copy of this matrix")) |
| 977 |
.def(self == self) // NOSONAR - suppress SonarCloud bug report. |
| 978 |
.def(self != self) // NOSONAR - suppress SonarCloud bug report. |
| 979 |
.def("__iadd__", &iadd44<T, float>,return_internal_reference<>()) |
| 980 |
.def("__iadd__", &iadd44<T, double>,return_internal_reference<>()) |
| 981 |
.def("__iadd__", &iadd44T<T>,return_internal_reference<>()) |
| 982 |
.def("__add__", &add44<T>) |
| 983 |
.def("__isub__", &isub44<T, float>,return_internal_reference<>()) |
| 984 |
.def("__isub__", &isub44<T, double>,return_internal_reference<>()) |
| 985 |
.def("__isub__", &isub44T<T>,return_internal_reference<>()) |
| 986 |
.def("__sub__", &sub44<T>) |
| 987 |
.def("negate",&negate44<T>,return_internal_reference<>(),"negate() negate all entries in this matrix") |
| 988 |
.def("__neg__", &neg44<T>) |
| 989 |
.def("__imul__", &imul44T<T>,return_internal_reference<>()) |
| 990 |
.def("__mul__", &mul44T<T>) |
| 991 |
.def("__rmul__", &rmul44T<T>) |
| 992 |
.def("__idiv__", &idiv44T<T>,return_internal_reference<>()) |
| 993 |
.def("__itruediv__", &idiv44T<T>,return_internal_reference<>()) |
| 994 |
.def("__div__", &div44T<T>) |
| 995 |
.def("__truediv__", &div44T<T>) |
| 996 |
.def("__add__", &add44T<T>) |
| 997 |
.def("__radd__", &add44T<T>) |
| 998 |
.def("__sub__", &subtractTL44<T>) |
| 999 |
.def("__rsub__", &subtractTR44<T>) |
| 1000 |
.def("__mul__", &mul44<float, T>) |
| 1001 |
.def("__mul__", &mul44<double, T>) |
| 1002 |
.def("__rmul__", &rmul44<float, T>) |
| 1003 |
.def("__rmul__", &rmul44<double, T>) |
| 1004 |
.def("__imul__", &imul44<float, T>,return_internal_reference<>()) |
| 1005 |
.def("__imul__", &imul44<double, T>,return_internal_reference<>()) |
| 1006 |
.def("__lt__", &lessThan44<T>) |
| 1007 |
.def("__gt__", &greaterThan44<T>) |
| 1008 |
.def("__le__", &lessThanEqual44<T>) |
| 1009 |
.def("__ge__", &greaterThanEqual44<T>) |
| 1010 |
//.def(self_ns::str(self)) |
| 1011 |
.def("__repr__",&Matrix44_repr<T>) |
| 1012 |
|
| 1013 |
.def("extractAndRemoveScalingAndShear", &extractAndRemoveScalingAndShear44<T>, |
| 1014 |
extractAndRemoveScalingAndShear44_overloads( |
| 1015 |
"M.extractAndRemoveScalingAndShear(scl, shr, " |
| 1016 |
"[exc]) -- extracts the scaling component of " |
| 1017 |
"M into scl and the shearing component of M " |
| 1018 |
"into shr. Also removes the scaling and " |
| 1019 |
"shearing components from M. " |
| 1020 |
"Returns 1 unless the scaling component is " |
| 1021 |
"nearly 0, in which case 0 is returned. " |
| 1022 |
"If optional arg. exc == 1, then if the " |
| 1023 |
"scaling component is nearly 0, then MathExc " |
| 1024 |
"is thrown.")) |
| 1025 |
|
| 1026 |
.def("extractEulerXYZ", &extractEulerXYZ<T>, "extract Euler") |
| 1027 |
.def("extractEulerZYX", &extractEulerZYX<T>, "extract Euler") |
| 1028 |
|
| 1029 |
.def("extractSHRT", &extractSHRT44<T>, extractSHRT44_overloads( |
| 1030 |
"M.extractSHRT(Vs, Vh, Vr, Vt, [exc]) -- " |
| 1031 |
"extracts the scaling component of M into Vs, " |
| 1032 |
"the shearing component of M in Vh (as XY, " |
| 1033 |
"XZ, YZ shear factors), the rotation of M " |
| 1034 |
"into Vr (as Euler angles in the order XYZ), " |
| 1035 |
"and the translaation of M into Vt. " |
| 1036 |
"If optional arg. exc == 1, then if the " |
| 1037 |
"scaling component is nearly 0, then MathExc " |
| 1038 |
"is thrown. ")) |
| 1039 |
|
| 1040 |
.def("extractScaling", &extractScaling44<T>, extractScaling44_overloads("extract scaling")) |
| 1041 |
.def("extractScalingAndShear", &extractScalingAndShear44<T>, extractScalingAndShear44_overloads("extract scaling")) |
| 1042 |
.def("singularValueDecomposition", &singularValueDecomposition44<T>, |
| 1043 |
"Decomposes the matrix using the singular value decomposition (SVD) into three\n" |
| 1044 |
"matrices U, S, and V which have the following properties: \n" |
| 1045 |
" 1. U and V are both orthonormal matrices, \n" |
| 1046 |
" 2. S is the diagonal matrix of singular values, \n" |
| 1047 |
" 3. U * S * V.transposed() gives back the original matrix.\n" |
| 1048 |
"The result is returned as a tuple [U, S, V]. Note that since S is diagonal we\n" |
| 1049 |
"don't need to return the entire matrix, so we return it as a three-vector. \n" |
| 1050 |
"\n" |
| 1051 |
"The 'forcePositiveDeterminant' argument can be used to force the U and V^T to\n" |
| 1052 |
"have positive determinant (that is, to be proper rotation matrices); if\n" |
| 1053 |
"forcePositiveDeterminant is False, then the singular values are guaranteed to\n" |
| 1054 |
"be nonnegative but the U and V matrices might contain negative scale along one\n" |
| 1055 |
"of the axes; if forcePositiveDeterminant is True, then U and V cannot contain\n" |
| 1056 |
"negative scale but S[3] might be negative. \n" |
| 1057 |
"\n" |
| 1058 |
"Our SVD implementation uses two-sided Jacobi rotations to iteratively\n" |
| 1059 |
"diagonalize the matrix, which should be quite robust and significantly faster\n" |
| 1060 |
"than the more general SVD solver in LAPACK. \n", |
| 1061 |
args("matrix", "forcePositiveDeterminant")) |
| 1062 |
.def("symmetricEigensolve", &PyImath::jacobiEigensolve<IMATH_NAMESPACE::Matrix44<T> >, |
| 1063 |
"Decomposes the matrix A using a symmetric eigensolver into matrices Q and S \n" |
| 1064 |
"which have the following properties: \n" |
| 1065 |
" 1. Q is the orthonormal matrix of eigenvectors, \n" |
| 1066 |
" 2. S is the diagonal matrix of eigenvalues, \n" |
| 1067 |
" 3. Q.transposed() * S * Q gives back the original matrix.\n" |
| 1068 |
"\n" |
| 1069 |
"IMPORTANT: It is vital that the passed-in matrix be symmetric, or the result \n" |
| 1070 |
"won't make any sense. This function will return an error if passed an \n" |
| 1071 |
"unsymmetric matrix.\n" |
| 1072 |
"\n" |
| 1073 |
"The result is returned as a tuple [Q, S]. Note that since S is diagonal \n" |
| 1074 |
"we don't need to return the entire matrix, so we return it as a three-vector. \n" |
| 1075 |
"\n" |
| 1076 |
"Our eigensolver implementation uses one-sided Jacobi rotations to iteratively \n" |
| 1077 |
"diagonalize the matrix, which should be quite robust and significantly faster \n" |
| 1078 |
"than the more general symmetric eigenvalue solver in LAPACK. \n") |
| 1079 |
.def("multDirMatrix", &multDirMatrix44<double,T>, "mult matrix") |
| 1080 |
.def("multDirMatrix", &multDirMatrix44_return_value<double,T>, "mult matrix") |
| 1081 |
.def("multDirMatrix", &multDirMatrix44_array<double,T>, "mult matrix") |
| 1082 |
.def("multDirMatrix", &multDirMatrix44<float,T>, "mult matrix") |
| 1083 |
.def("multDirMatrix", &multDirMatrix44_return_value<float,T>, "mult matrix") |
| 1084 |
.def("multDirMatrix", &multDirMatrix44_array<float,T>, "mult matrix") |
| 1085 |
.def("multVecMatrix", &multVecMatrix44<double,T>, "mult matrix") |
| 1086 |
.def("multVecMatrix", &multVecMatrix44_return_value<double,T>, "mult matrix") |
| 1087 |
.def("multVecMatrix", &multVecMatrix44_array<double,T>, "mult matrix") |
| 1088 |
.def("multVecMatrix", &multVecMatrix44<float,T>, "mult matrix") |
| 1089 |
.def("multVecMatrix", &multVecMatrix44_return_value<float,T>, "mult matrix") |
| 1090 |
.def("multVecMatrix", &multVecMatrix44_array<float,T>, "mult matrix") |
| 1091 |
.def("removeScaling", &removeScaling44<T>, removeScaling44_overloads("remove scaling")) |
| 1092 |
.def("removeScalingAndShear", &removeScalingAndShear44<T>, removeScalingAndShear44_overloads("remove scaling")) |
| 1093 |
.def("sansScaling", &sansScaling44<T>, sansScaling44_overloads("sans scaling")) |
| 1094 |
.def("sansScalingAndShear", &sansScalingAndShear44<T>, sansScalingAndShear44_overloads("sans scaling and shear")) |
| 1095 |
.def("scale", &scaleSc44<T>, return_internal_reference<>(), "scale matrix") |
| 1096 |
.def("scale", &scaleV44<T>, return_internal_reference<>(), "scale matrix") |
| 1097 |
.def("scale", &scale44Tuple<T>, return_internal_reference<>(), "scale matrix") |
| 1098 |
.def("rotate", &rotateV44<T>, return_internal_reference<>(), "rotate matrix") |
| 1099 |
.def("rotationMatrix", &rotationMatrix44<T>, return_internal_reference<>(), "rotationMatrix()") |
| 1100 |
.def("rotationMatrixWithUpDir", &rotationMatrixWithUp44<T>, return_internal_reference<>(), "roationMatrixWithUp()") |
| 1101 |
.def("setScale", &setScaleSc44<T>, return_internal_reference<>(),"setScale()") |
| 1102 |
.def("setScale", &setScaleV44<T>, return_internal_reference<>(),"setScale()") |
| 1103 |
.def("setScale", &setScale44Tuple<T>, return_internal_reference<>(),"setScale()") |
| 1104 |
|
| 1105 |
.def("setShear", &setShearV44<T>, return_internal_reference<>(),"setShear()") |
| 1106 |
.def("setShear", &setShearS44<T>, return_internal_reference<>(),"setShear()") |
| 1107 |
.def("setShear", &setShear44Tuple<T>, return_internal_reference<>(),"setShear()") |
| 1108 |
.def("setTranslation", &setTranslation44<T>, return_internal_reference<>(),"setTranslation()") |
| 1109 |
.def("setTranslation", &setTranslation44Tuple<T>, return_internal_reference<>(),"setTranslation()") |
| 1110 |
.def("setTranslation", &setTranslation44Obj<T>, return_internal_reference<>(),"setTranslation()") |
| 1111 |
.def("setValue", &setValue44<T>, "setValue()") |
| 1112 |
.def("shear", &shearV44<T>, return_internal_reference<>(),"shear()") |
| 1113 |
.def("shear", &shearS44<T>, return_internal_reference<>(),"shear()") |
| 1114 |
.def("shear", &shear44Tuple<T>, return_internal_reference<>(),"shear()") |
| 1115 |
.def("translate", &translate44<T>, return_internal_reference<>(),"translate()") |
| 1116 |
.def("translate", &translate44Tuple<T>, return_internal_reference<>(),"translate()") |
| 1117 |
.def("translation", &Matrix44<T>::translation, "translation()") |
| 1118 |
|
| 1119 |
; |
| 1120 |
|
| 1121 |
decoratecopy(matrix44_class); |
| 1122 |
|
| 1123 |
return matrix44_class; |
| 1124 |
/* |
| 1125 |
const Matrix44 & operator = (const Matrix44 &v); |
| 1126 |
const Matrix44 & operator = (T a); |
| 1127 |
T * getValue (); |
| 1128 |
const T * getValue () const; |
| 1129 |
template <class S> void getValue (Matrix44<S> &v) const; |
| 1130 |
template <class S> Matrix44 & setValue (const Matrix44<S> &v); |
| 1131 |
template <class S> Matrix44 & setTheMatrix (const Matrix44<S> &v); |
| 1132 |
template <class S> void multVecMatrix(const Vec2<S> &src, Vec2<S> &dst) const; |
| 1133 |
template <class S> void multDirMatrix(const Vec2<S> &src, Vec2<S> &dst) const; |
| 1134 |
template <class S> const Matrix44 & setRotation (S r); |
| 1135 |
template <class S> const Matrix44 & rotate (S r); |
| 1136 |
const Matrix44 & setScale (T s); |
| 1137 |
template <class S> const Matrix44 & setScale (const Vec2<S> &s); |
| 1138 |
template <class S> const Matrix44 & scale (const Vec2<S> &s); |
| 1139 |
template <class S> const Matrix44 & setTranslation (const Vec2<S> &t); |
| 1140 |
Vec2<T> translation () const; |
| 1141 |
template <class S> const Matrix44 & translate (const Vec2<S> &t); |
| 1142 |
template <class S> const Matrix44 & setShear (const S &h); |
| 1143 |
template <class S> const Matrix44 & setShear (const Vec2<S> &h); |
| 1144 |
template <class S> const Matrix44 & shear (const S &xy); |
| 1145 |
template <class S> const Matrix44 & shear (const Vec2<S> &h); |
| 1146 |
*/ |
| 1147 |
} |
| 1148 |
|
| 1149 |
template <class T> |
| 1150 |
struct Matrix44Array_Constructor : public Task |
| 1151 |
{ |
| 1152 |
const FixedArray<T> &a; const FixedArray<T> &b; const FixedArray<T> &c; const FixedArray<T> &d; |
| 1153 |
const FixedArray<T> &e; const FixedArray<T> &f; const FixedArray<T> &g; const FixedArray<T> &h; |
| 1154 |
const FixedArray<T> &i; const FixedArray<T> &j; const FixedArray<T> &k; const FixedArray<T> &l; |
| 1155 |
const FixedArray<T> &m; const FixedArray<T> &n; const FixedArray<T> &o; const FixedArray<T> &p; |
| 1156 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > &result; |
| 1157 |
|
| 1158 |
Matrix44Array_Constructor (const FixedArray<T> &a, const FixedArray<T> &b, const FixedArray<T> &c, const FixedArray<T> &d, |
| 1159 |
const FixedArray<T> &e, const FixedArray<T> &f, const FixedArray<T> &g, const FixedArray<T> &h, |
| 1160 |
const FixedArray<T> &i, const FixedArray<T> &j, const FixedArray<T> &k, const FixedArray<T> &l, |
| 1161 |
const FixedArray<T> &m, const FixedArray<T> &n, const FixedArray<T> &o, const FixedArray<T> &p, |
| 1162 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > &result) |
| 1163 |
: a (a), b (b), c (c), d (d), |
| 1164 |
e (e), f (f), g (g), h (h), |
| 1165 |
i (i), j (j), k (k), l (l), |
| 1166 |
m (m), n (n), o (o), p (p), result (result) {} |
| 1167 |
|
| 1168 |
void execute (size_t start, size_t end) |
| 1169 |
{ |
| 1170 |
for (size_t index = start; index < end; ++index) |
| 1171 |
{ |
| 1172 |
result[index] = IMATH_NAMESPACE::Matrix44<T>(a[index], b[index], c[index], d[index], |
| 1173 |
e[index], f[index], g[index], h[index], |
| 1174 |
i[index], j[index], k[index], l[index], |
| 1175 |
m[index], n[index], o[index], p[index]); |
| 1176 |
} |
| 1177 |
} |
| 1178 |
}; |
| 1179 |
|
| 1180 |
template <class T> |
| 1181 |
static FixedArray<IMATH_NAMESPACE::Matrix44<T> > * |
| 1182 |
M44Array_constructor(const FixedArray<T> &a, const FixedArray<T> &b, const FixedArray<T> &c, const FixedArray<T> &d, |
| 1183 |
const FixedArray<T> &e, const FixedArray<T> &f, const FixedArray<T> &g, const FixedArray<T> &h, |
| 1184 |
const FixedArray<T> &i, const FixedArray<T> &j, const FixedArray<T> &k, const FixedArray<T> &l, |
| 1185 |
const FixedArray<T> &m, const FixedArray<T> &n, const FixedArray<T> &o, const FixedArray<T> &p) |
| 1186 |
{ |
| 1187 |
MATH_EXC_ON; |
| 1188 |
Py_ssize_t len = a.len(); |
| 1189 |
if (!( a.len() == len && b.len() == len && c.len() == len && d.len() == len && |
| 1190 |
e.len() == len && f.len() == len && g.len() == len && h.len() == len && |
| 1191 |
i.len() == len && j.len() == len && k.len() == len && l.len() == len && |
| 1192 |
m.len() == len && n.len() == len && o.len() == len && p.len() == len)) |
| 1193 |
throw std::invalid_argument ("Dimensions do not match" ); |
| 1194 |
|
| 1195 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> >* result = |
| 1196 |
new FixedArray<IMATH_NAMESPACE::Matrix44<T> > (Py_ssize_t(len), UNINITIALIZED); |
| 1197 |
|
| 1198 |
Matrix44Array_Constructor<T> task (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, *result); |
| 1199 |
dispatchTask (task, len); |
| 1200 |
return result; |
| 1201 |
} |
| 1202 |
|
| 1203 |
template <class T> |
| 1204 |
static void |
| 1205 |
setM44ArrayItem(FixedArray<IMATH_NAMESPACE::Matrix44<T> > &ma, |
| 1206 |
Py_ssize_t index, |
| 1207 |
const IMATH_NAMESPACE::Matrix44<T> &m) |
| 1208 |
{ |
| 1209 |
ma[ma.canonical_index(index)] = m; |
| 1210 |
} |
| 1211 |
|
| 1212 |
template <class T> |
| 1213 |
struct M44Array_Inverse : public Task |
| 1214 |
{ |
| 1215 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &mats; |
| 1216 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > &result; |
| 1217 |
|
| 1218 |
M44Array_Inverse (FixedArray<IMATH_NAMESPACE::Matrix44<T> > &result, |
| 1219 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &mats) |
| 1220 |
: mats (mats), result (result) {} |
| 1221 |
|
| 1222 |
void execute (size_t start, size_t end) |
| 1223 |
{ |
| 1224 |
for (size_t i = start; i < end; ++i) |
| 1225 |
result[i] = mats[i].inverse(); |
| 1226 |
} |
| 1227 |
}; |
| 1228 |
|
| 1229 |
template <class T> |
| 1230 |
static FixedArray<IMATH_NAMESPACE::Matrix44<T> > |
| 1231 |
M44Array_inverse(const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &ma) |
| 1232 |
{ |
| 1233 |
MATH_EXC_ON; |
| 1234 |
size_t len = ma.len(); |
| 1235 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > result (len); |
| 1236 |
|
| 1237 |
M44Array_Inverse<T> task (result, ma); |
| 1238 |
dispatchTask (task, len); |
| 1239 |
|
| 1240 |
return result; |
| 1241 |
} |
| 1242 |
|
| 1243 |
template <class T> |
| 1244 |
struct M44Array_RmulVec4 : public Task |
| 1245 |
{ |
| 1246 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a; |
| 1247 |
const Vec4<T> &v; |
| 1248 |
FixedArray<Vec4<T> > &r; |
| 1249 |
|
| 1250 |
M44Array_RmulVec4 (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a, |
| 1251 |
const Vec4<T> &v, |
| 1252 |
FixedArray<Vec4<T> > &r) |
| 1253 |
: a (a), v (v), r (r) {} |
| 1254 |
|
| 1255 |
void execute(size_t start, size_t end) |
| 1256 |
{ |
| 1257 |
for (size_t i = start; i < end; ++i) |
| 1258 |
{ |
| 1259 |
r[i] = v * a[i]; |
| 1260 |
} |
| 1261 |
} |
| 1262 |
}; |
| 1263 |
|
| 1264 |
template <class T> |
| 1265 |
static FixedArray< Vec4<T> > |
| 1266 |
M44Array_rmulVec4 (const FixedArray< IMATH_NAMESPACE::Matrix44<T> > &a, const Vec4<T> &v) |
| 1267 |
{ |
| 1268 |
MATH_EXC_ON; |
| 1269 |
size_t len = a.len(); |
| 1270 |
FixedArray< Vec4<T> > r (Py_ssize_t(len), UNINITIALIZED); |
| 1271 |
|
| 1272 |
M44Array_RmulVec4<T> task (a, v, r); |
| 1273 |
dispatchTask (task, len); |
| 1274 |
return r; |
| 1275 |
} |
| 1276 |
|
| 1277 |
template <class T> |
| 1278 |
struct M44Array_RmulVec4Array : public Task |
| 1279 |
{ |
| 1280 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a; |
| 1281 |
const FixedArray<Vec4<T> > &b; |
| 1282 |
FixedArray<Vec4<T> > &r; |
| 1283 |
|
| 1284 |
M44Array_RmulVec4Array (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a, |
| 1285 |
const FixedArray<Vec4<T> > &b, |
| 1286 |
FixedArray<Vec4<T> > &r) |
| 1287 |
: a (a), b (b), r (r) {} |
| 1288 |
|
| 1289 |
void execute(size_t start, size_t end) |
| 1290 |
{ |
| 1291 |
for (size_t i = start; i < end; ++i) |
| 1292 |
{ |
| 1293 |
r[i] = b[i] * a[i]; |
| 1294 |
} |
| 1295 |
} |
| 1296 |
}; |
| 1297 |
|
| 1298 |
template <class T> |
| 1299 |
static FixedArray< Vec4<T> > |
| 1300 |
M44Array_rmulVec4Array (const FixedArray< IMATH_NAMESPACE::Matrix44<T> > &a, |
| 1301 |
const FixedArray< Vec4<T> > &b) |
| 1302 |
{ |
| 1303 |
MATH_EXC_ON; |
| 1304 |
size_t len = a.match_dimension(b); |
| 1305 |
FixedArray< Vec4<T> > r (Py_ssize_t(len), UNINITIALIZED); |
| 1306 |
|
| 1307 |
M44Array_RmulVec4Array<T> task (a, b, r); |
| 1308 |
dispatchTask (task, len); |
| 1309 |
return r; |
| 1310 |
} |
| 1311 |
|
| 1312 |
template <class T> |
| 1313 |
struct M44Array_RmulVec3ArrayT : public Task |
| 1314 |
{ |
| 1315 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a; |
| 1316 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &b; |
| 1317 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r; |
| 1318 |
|
| 1319 |
M44Array_RmulVec3ArrayT (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a, |
| 1320 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &b, |
| 1321 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r) |
| 1322 |
: a(a), b(b), r(r) {} |
| 1323 |
|
| 1324 |
void execute(size_t start, size_t end) |
| 1325 |
{ |
| 1326 |
for (size_t i = start; i < end; ++i) |
| 1327 |
r[i] = b[i] * a[i]; |
| 1328 |
} |
| 1329 |
}; |
| 1330 |
|
| 1331 |
template <class T> |
| 1332 |
FixedArray<Vec3<T> > |
| 1333 |
M44Array_rmulVec3ArrayT (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &a, |
| 1334 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &b) |
| 1335 |
{ |
| 1336 |
MATH_EXC_ON; |
| 1337 |
size_t len = a.match_dimension(b); |
| 1338 |
FixedArray< IMATH_NAMESPACE::Vec3<T> > result (Py_ssize_t(len), UNINITIALIZED); |
| 1339 |
|
| 1340 |
M44Array_RmulVec3ArrayT<T> task (a, b, result); |
| 1341 |
dispatchTask (task, len); |
| 1342 |
|
| 1343 |
return result; |
| 1344 |
} |
| 1345 |
|
| 1346 |
template <class T> |
| 1347 |
struct M44Array_Invert : public Task |
| 1348 |
{ |
| 1349 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m; |
| 1350 |
|
| 1351 |
M44Array_Invert (FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m) |
| 1352 |
: m(m) {} |
| 1353 |
|
| 1354 |
void execute(size_t start, size_t end) |
| 1355 |
{ |
| 1356 |
for (size_t i = start; i < end; ++i) |
| 1357 |
m[i].invert(); |
| 1358 |
} |
| 1359 |
}; |
| 1360 |
|
| 1361 |
template <class T> |
| 1362 |
void |
| 1363 |
M44Array_invert (FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m) |
| 1364 |
{ |
| 1365 |
MATH_EXC_ON; |
| 1366 |
size_t len = m.len(); |
| 1367 |
|
| 1368 |
M44Array_Invert<T> task (m); |
| 1369 |
dispatchTask (task, len); |
| 1370 |
} |
| 1371 |
|
| 1372 |
template <class T> |
| 1373 |
struct M44Array_Transpose : public Task |
| 1374 |
{ |
| 1375 |
FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m; |
| 1376 |
|
| 1377 |
M44Array_Transpose (FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m) |
| 1378 |
: m(m) {} |
| 1379 |
|
| 1380 |
void execute(size_t start, size_t end) |
| 1381 |
{ |
| 1382 |
for (size_t i = start; i < end; ++i) |
| 1383 |
m[i].transpose(); |
| 1384 |
} |
| 1385 |
}; |
| 1386 |
|
| 1387 |
template <class T> |
| 1388 |
void |
| 1389 |
M44Array_transpose (FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m) |
| 1390 |
{ |
| 1391 |
MATH_EXC_ON; |
| 1392 |
size_t len = m.len(); |
| 1393 |
|
| 1394 |
M44Array_Transpose<T> task (m); |
| 1395 |
dispatchTask (task, len); |
| 1396 |
} |
| 1397 |
|
| 1398 |
template <class T> |
| 1399 |
struct M44Array_MultDirMatrix : public Task |
| 1400 |
{ |
| 1401 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m; |
| 1402 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v; |
| 1403 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r; |
| 1404 |
|
| 1405 |
M44Array_MultDirMatrix (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m, |
| 1406 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v, |
| 1407 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r) |
| 1408 |
: m(m), v(v), r(r) {} |
| 1409 |
|
| 1410 |
void execute(size_t start, size_t end) |
| 1411 |
{ |
| 1412 |
for (size_t i = start; i < end; ++i) |
| 1413 |
m[i].multDirMatrix (v[i], r[i]); |
| 1414 |
} |
| 1415 |
}; |
| 1416 |
|
| 1417 |
template <class T> |
| 1418 |
FixedArray<Vec3<T> > |
| 1419 |
M44Array_multDirMatrix (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m, |
| 1420 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v) |
| 1421 |
{ |
| 1422 |
MATH_EXC_ON; |
| 1423 |
size_t len = m.match_dimension(v); |
| 1424 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > result (Py_ssize_t(len), UNINITIALIZED); |
| 1425 |
|
| 1426 |
M44Array_MultDirMatrix<T> task (m, v, result); |
| 1427 |
dispatchTask (task, len); |
| 1428 |
|
| 1429 |
return result; |
| 1430 |
} |
| 1431 |
|
| 1432 |
template <class T> |
| 1433 |
struct M44Array_MultVecMatrix : public Task |
| 1434 |
{ |
| 1435 |
const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m; |
| 1436 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v; |
| 1437 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r; |
| 1438 |
|
| 1439 |
M44Array_MultVecMatrix (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m, |
| 1440 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v, |
| 1441 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > &r) |
| 1442 |
: m(m), v(v), r(r) {} |
| 1443 |
|
| 1444 |
void execute(size_t start, size_t end) |
| 1445 |
{ |
| 1446 |
for (size_t i = start; i < end; ++i) |
| 1447 |
m[i].multVecMatrix (v[i], r[i]); |
| 1448 |
} |
| 1449 |
}; |
| 1450 |
|
| 1451 |
template <class T> |
| 1452 |
FixedArray<Vec3<T> > |
| 1453 |
M44Array_multVecMatrix (const FixedArray<IMATH_NAMESPACE::Matrix44<T> > &m, |
| 1454 |
const FixedArray<IMATH_NAMESPACE::Vec3<T> > &v) |
| 1455 |
{ |
| 1456 |
MATH_EXC_ON; |
| 1457 |
size_t len = m.match_dimension(v); |
| 1458 |
FixedArray<IMATH_NAMESPACE::Vec3<T> > result (Py_ssize_t(len), UNINITIALIZED); |
| 1459 |
|
| 1460 |
M44Array_MultVecMatrix<T> task (m, v, result); |
| 1461 |
dispatchTask (task, len); |
| 1462 |
|
| 1463 |
return result; |
| 1464 |
} |
| 1465 |
|
| 1466 |
template <class T> |
| 1467 |
class_<FixedArray<IMATH_NAMESPACE::Matrix44<T> > > |
| 1468 |
register_M44Array() |
| 1469 |
{ |
| 1470 |
|
| 1471 |
class_<FixedArray<IMATH_NAMESPACE::Matrix44<T> > > matrixArray_class = FixedArray<IMATH_NAMESPACE::Matrix44<T> >::register_("Fixed length array of IMATH_NAMESPACE::Matrix44"); |
| 1472 |
matrixArray_class |
| 1473 |
.def("__init__", make_constructor(M44Array_constructor<T>)) |
| 1474 |
.def("__setitem__", &setM44ArrayItem<T>) |
| 1475 |
.def("inverse", &M44Array_inverse<T>, |
| 1476 |
"Return M^-1 for each element M.", |
| 1477 |
(args("vector"))) |
| 1478 |
.def("invert", &M44Array_invert<T>, |
| 1479 |
"Perform M^-1 in place for each element M.") |
| 1480 |
.def("transpose", &M44Array_transpose<T>, |
| 1481 |
"Perform M^T in place for each element M.") |
| 1482 |
.def("multDirMatrix", &M44Array_multDirMatrix<T>, |
| 1483 |
"Multiply an array of vectors element by element with the matrix array.", |
| 1484 |
(args("vector"))) |
| 1485 |
.def("multVecMatrix", &M44Array_multVecMatrix<T>, |
| 1486 |
"Multiply an array of normals element by element with the matrix array.", |
| 1487 |
(args("vector"))) |
| 1488 |
.def("__rmul__", &M44Array_rmulVec4<T>) |
| 1489 |
.def("__rmul__", &M44Array_rmulVec4Array<T>) |
| 1490 |
.def("__rmul__", &M44Array_rmulVec3ArrayT<T>) |
| 1491 |
; |
| 1492 |
|
| 1493 |
add_comparison_functions(matrixArray_class); |
| 1494 |
|
| 1495 |
return matrixArray_class; |
| 1496 |
} |
| 1497 |
|
| 1498 |
|
| 1499 |
template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix44<float> > register_Matrix44<float>(); |
| 1500 |
template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix44<double> > register_Matrix44<double>(); |
| 1501 |
|
| 1502 |
template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix44<float> > > register_M44Array<float>(); |
| 1503 |
template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix44<double> > > register_M44Array<double>(); |
| 1504 |
|
| 1505 |
template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix44<float> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix44<float> >::value() { return IMATH_NAMESPACE::Matrix44<float>(); } |
| 1506 |
template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix44<double> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix44<double> >::value() { return IMATH_NAMESPACE::Matrix44<double>(); } |
| 1507 |
} |