| 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 "PyImathMatrix.h" |
| 21 |
#include "PyImathExport.h" |
| 22 |
#include "PyImathDecorators.h" |
| 23 |
#include "PyImath.h" |
| 24 |
#include "PyImathVec.h" |
| 25 |
#include "PyImathMathExc.h" |
| 26 |
|
| 27 |
namespace PyImath { |
| 28 |
|
| 29 |
template<> const char *PyImath::M33fArray::name() { return "M33fArray"; } |
| 30 |
template<> const char *PyImath::M33dArray::name() { return "M33dArray"; } |
| 31 |
|
| 32 |
using namespace boost::python; |
| 33 |
using namespace IMATH_NAMESPACE; |
| 34 |
|
| 35 |
template <class T, int len> |
| 36 |
struct MatrixRow { |
| 37 |
explicit MatrixRow(T *data) : _data(data) {} |
| 38 |
T & operator [] (int i) { return _data[i]; } |
| 39 |
T *_data; |
| 40 |
|
| 41 |
static const char *name; |
| 42 |
static void register_class() |
| 43 |
{ |
| 44 |
typedef PyImath::StaticFixedArray<MatrixRow,T,len> MatrixRow_helper; |
| 45 |
class_<MatrixRow> matrixRow_class(name,no_init); |
| 46 |
matrixRow_class |
| 47 |
.def("__len__", MatrixRow_helper::len) |
| 48 |
.def("__getitem__", MatrixRow_helper::getitem,return_value_policy<copy_non_const_reference>()) |
| 49 |
.def("__setitem__", MatrixRow_helper::setitem) |
| 50 |
; |
| 51 |
} |
| 52 |
}; |
| 53 |
|
| 54 |
template <> const char *MatrixRow<float,3>::name = "M33fRow"; |
| 55 |
template <> const char *MatrixRow<double,3>::name = "M33dRow"; |
| 56 |
|
| 57 |
|
| 58 |
template <class Container, class Data, int len> |
| 59 |
struct IndexAccessMatrixRow { |
| 60 |
typedef MatrixRow<Data,len> result_type; |
| 61 |
static MatrixRow<Data,len> apply(Container &c, int i) { return MatrixRow<Data,len>(c[i]); } |
| 62 |
}; |
| 63 |
|
| 64 |
template <class T> struct Matrix33Name { static const char *value; }; |
| 65 |
template<> const char *Matrix33Name<float>::value = "M33f"; |
| 66 |
template<> const char *Matrix33Name<double>::value = "M33d"; |
| 67 |
|
| 68 |
template <class T> |
| 69 |
static std::string Matrix33_str(const Matrix33<T> &v) |
| 70 |
{ |
| 71 |
std::stringstream stream; |
| 72 |
stream << Matrix33Name<T>::value << "("; |
| 73 |
for (int row = 0; row < 3; row++) |
| 74 |
{ |
| 75 |
stream << "("; |
| 76 |
for (int col = 0; col < 3; col++) |
| 77 |
{ |
| 78 |
stream << v[row][col]; |
| 79 |
stream << (col != 2 ? ", " : ""); |
| 80 |
} |
| 81 |
stream << ")" << (row != 2 ? ", " : ""); |
| 82 |
} |
| 83 |
stream << ")"; |
| 84 |
return stream.str(); |
| 85 |
} |
| 86 |
|
| 87 |
// Non-specialized repr is same as str |
| 88 |
template <class T> |
| 89 |
static std::string Matrix33_repr(const Matrix33<T> &v) |
| 90 |
{ |
| 91 |
return Matrix33_str(v); |
| 92 |
} |
| 93 |
|
| 94 |
// Specialization for float to full precision |
| 95 |
template <> |
| 96 |
std::string Matrix33_repr(const Matrix33<float> &v) |
| 97 |
{ |
| 98 |
return (boost::format("%s((%.9g, %.9g, %.9g), (%.9g, %.9g, %.9g), (%.9g, %.9g, %.9g))") |
| 99 |
% Matrix33Name<float>::value |
| 100 |
% v[0][0] % v[0][1] % v[0][2] |
| 101 |
% v[1][0] % v[1][1] % v[1][2] |
| 102 |
% v[2][0] % v[2][1] % v[2][2]).str(); |
| 103 |
} |
| 104 |
|
| 105 |
// Specialization for double to full precision |
| 106 |
template <> |
| 107 |
std::string Matrix33_repr(const Matrix33<double> &v) |
| 108 |
{ |
| 109 |
return (boost::format("%s((%.17g, %.17g, %.17g), (%.17g, %.17g, %.17g), (%.17g, %.17g, %.17g))") |
| 110 |
% Matrix33Name<double>::value |
| 111 |
% v[0][0] % v[0][1] % v[0][2] |
| 112 |
% v[1][0] % v[1][1] % v[1][2] |
| 113 |
% v[2][0] % v[2][1] % v[2][2]).str(); |
| 114 |
} |
| 115 |
|
| 116 |
template <class T> |
| 117 |
static const Matrix33<T> & |
| 118 |
invert33 (Matrix33<T> &m, bool singExc = true) |
| 119 |
{ |
| 120 |
MATH_EXC_ON; |
| 121 |
return m.invert(singExc); |
| 122 |
} |
| 123 |
|
| 124 |
template <class T> |
| 125 |
static Matrix33<T> |
| 126 |
inverse33 (Matrix33<T> &m, bool singExc = true) |
| 127 |
{ |
| 128 |
MATH_EXC_ON; |
| 129 |
return m.inverse(singExc); |
| 130 |
} |
| 131 |
|
| 132 |
template <class T> |
| 133 |
static const Matrix33<T> & |
| 134 |
gjInvert33 (Matrix33<T> &m, bool singExc = true) |
| 135 |
{ |
| 136 |
MATH_EXC_ON; |
| 137 |
return m.gjInvert(singExc); |
| 138 |
} |
| 139 |
|
| 140 |
template <class T> |
| 141 |
static Matrix33<T> |
| 142 |
gjInverse33 (Matrix33<T> &m, bool singExc = true) |
| 143 |
{ |
| 144 |
MATH_EXC_ON; |
| 145 |
return m.gjInverse(singExc); |
| 146 |
} |
| 147 |
|
| 148 |
template <class T, class U> |
| 149 |
static const Matrix33<T> & |
| 150 |
iadd33(Matrix33<T> &m, const Matrix33<U> &m2) |
| 151 |
{ |
| 152 |
MATH_EXC_ON; |
| 153 |
Matrix33<T> m3; |
| 154 |
m3.setValue (m2); |
| 155 |
return m += m3; |
| 156 |
} |
| 157 |
|
| 158 |
template <class T> |
| 159 |
static const Matrix33<T> & |
| 160 |
iadd33T(Matrix33<T> &mat, T a) |
| 161 |
{ |
| 162 |
MATH_EXC_ON; |
| 163 |
return mat += a; |
| 164 |
} |
| 165 |
|
| 166 |
template <class T> |
| 167 |
static Matrix33<T> |
| 168 |
add33(Matrix33<T> &m, const Matrix33<T> &m2) |
| 169 |
{ |
| 170 |
MATH_EXC_ON; |
| 171 |
return m + m2; |
| 172 |
} |
| 173 |
|
| 174 |
template <class T, class U> |
| 175 |
static const Matrix33<T> & |
| 176 |
isub33(Matrix33<T> &m, const Matrix33<U> &m2) |
| 177 |
{ |
| 178 |
MATH_EXC_ON; |
| 179 |
Matrix33<T> m3; |
| 180 |
m3.setValue (m2); |
| 181 |
return m -= m3; |
| 182 |
} |
| 183 |
|
| 184 |
template <class T> |
| 185 |
static const Matrix33<T> & |
| 186 |
isub33T(Matrix33<T> &mat, T a) |
| 187 |
{ |
| 188 |
MATH_EXC_ON; |
| 189 |
return mat -= a; |
| 190 |
} |
| 191 |
|
| 192 |
template <class T> |
| 193 |
static Matrix33<T> |
| 194 |
sub33(Matrix33<T> &m, const Matrix33<T> &m2) |
| 195 |
{ |
| 196 |
MATH_EXC_ON; |
| 197 |
return m - m2; |
| 198 |
} |
| 199 |
|
| 200 |
template <class T> |
| 201 |
static const Matrix33<T> & |
| 202 |
negate33 (Matrix33<T> &m) |
| 203 |
{ |
| 204 |
MATH_EXC_ON; |
| 205 |
return m.negate(); |
| 206 |
} |
| 207 |
|
| 208 |
template <class T> |
| 209 |
static Matrix33<T> |
| 210 |
neg33 (Matrix33<T> &m) |
| 211 |
{ |
| 212 |
MATH_EXC_ON; |
| 213 |
return -m; |
| 214 |
} |
| 215 |
|
| 216 |
template <class T> |
| 217 |
static const Matrix33<T> & |
| 218 |
imul33T(Matrix33<T> &m, const T &t) |
| 219 |
{ |
| 220 |
MATH_EXC_ON; |
| 221 |
return m *= t; |
| 222 |
} |
| 223 |
|
| 224 |
template <class T> |
| 225 |
static Matrix33<T> |
| 226 |
mul33T(Matrix33<T> &m, const T &t) |
| 227 |
{ |
| 228 |
MATH_EXC_ON; |
| 229 |
return m * t; |
| 230 |
} |
| 231 |
|
| 232 |
template <class T> |
| 233 |
static Matrix33<T> |
| 234 |
rmul33T(Matrix33<T> &m, const T &t) |
| 235 |
{ |
| 236 |
MATH_EXC_ON; |
| 237 |
return t * m; |
| 238 |
} |
| 239 |
|
| 240 |
template <class T> |
| 241 |
static const Matrix33<T> & |
| 242 |
idiv33T(Matrix33<T> &m, const T &t) |
| 243 |
{ |
| 244 |
MATH_EXC_ON; |
| 245 |
return m /= t; |
| 246 |
} |
| 247 |
|
| 248 |
template <class T> |
| 249 |
static Matrix33<T> |
| 250 |
div33T(Matrix33<T> &m, const T &t) |
| 251 |
{ |
| 252 |
MATH_EXC_ON; |
| 253 |
return m / t; |
| 254 |
} |
| 255 |
|
| 256 |
template <class T> |
| 257 |
static void |
| 258 |
extractAndRemoveScalingAndShear33(Matrix33<T> &mat, IMATH_NAMESPACE::Vec2<T> &dstScl, IMATH_NAMESPACE::Vec2<T> &dstShr, int exc = 1) |
| 259 |
{ |
| 260 |
MATH_EXC_ON; |
| 261 |
T dstShrTmp; |
| 262 |
IMATH_NAMESPACE::extractAndRemoveScalingAndShear(mat, dstScl, dstShrTmp, exc); |
| 263 |
|
| 264 |
dstShr.setValue(dstShrTmp, T (0)); |
| 265 |
} |
| 266 |
|
| 267 |
template <class T> |
| 268 |
static void |
| 269 |
extractEuler(Matrix33<T> &mat, Vec2<T> &dstObj) |
| 270 |
{ |
| 271 |
MATH_EXC_ON; |
| 272 |
T dst; |
| 273 |
IMATH_NAMESPACE::extractEuler(mat, dst); |
| 274 |
dstObj.setValue(dst, T (0)); |
| 275 |
} |
| 276 |
|
| 277 |
template <class T> |
| 278 |
static int |
| 279 |
extractSHRT33(Matrix33<T> &mat, Vec2<T> &s, Vec2<T> &h, Vec2<T> &r, Vec2<T> &t, int exc = 1) |
| 280 |
{ |
| 281 |
MATH_EXC_ON; |
| 282 |
T hTmp, rTmp; |
| 283 |
|
| 284 |
int b = IMATH_NAMESPACE::extractSHRT(mat, s, hTmp, rTmp, t, exc); |
| 285 |
|
| 286 |
h.setValue(hTmp, T (0)); |
| 287 |
r.setValue(rTmp, T (0)); |
| 288 |
|
| 289 |
return b; |
| 290 |
} |
| 291 |
|
| 292 |
template <class T> |
| 293 |
static void |
| 294 |
extractScaling33(Matrix33<T> &mat, Vec2<T> &dst, int exc = 1) |
| 295 |
{ |
| 296 |
MATH_EXC_ON; |
| 297 |
IMATH_NAMESPACE::extractScaling(mat, dst, exc); |
| 298 |
} |
| 299 |
|
| 300 |
template <class T> |
| 301 |
void |
| 302 |
outerProduct33(Matrix33<T> &mat, const Vec3<T> &a, const Vec3<T> &b) |
| 303 |
{ |
| 304 |
MATH_EXC_ON; |
| 305 |
mat = IMATH_NAMESPACE::outerProduct(a,b); |
| 306 |
} |
| 307 |
|
| 308 |
template <class T> |
| 309 |
static void |
| 310 |
extractScalingAndShear33(Matrix33<T> &mat, Vec2<T> &dstScl, Vec2<T> &dstShr, int exc = 1) |
| 311 |
{ |
| 312 |
MATH_EXC_ON; |
| 313 |
T dstShrTmp; |
| 314 |
IMATH_NAMESPACE::extractScalingAndShear(mat, dstScl, dstShrTmp, exc); |
| 315 |
|
| 316 |
dstShr.setValue(dstShrTmp, T (0)); |
| 317 |
} |
| 318 |
|
| 319 |
template <class TV,class TM> |
| 320 |
static void |
| 321 |
multDirMatrix33(Matrix33<TM> &mat, const Vec2<TV> &src, Vec2<TV> &dst) |
| 322 |
{ |
| 323 |
MATH_EXC_ON; |
| 324 |
mat.multDirMatrix(src, dst); |
| 325 |
} |
| 326 |
|
| 327 |
template <class TV,class TM> |
| 328 |
static Vec2<TV> |
| 329 |
multDirMatrix33_return_value(Matrix33<TM> &mat, const Vec2<TV> &src) |
| 330 |
{ |
| 331 |
MATH_EXC_ON; |
| 332 |
Vec2<TV> dst; |
| 333 |
mat.multDirMatrix(src, dst); |
| 334 |
return dst; |
| 335 |
} |
| 336 |
|
| 337 |
template <class TV,class TM> |
| 338 |
static FixedArray<Vec2<TV> > |
| 339 |
multDirMatrix33_array(Matrix33<TM> &mat, const FixedArray<Vec2<TV> >&src) |
| 340 |
{ |
| 341 |
MATH_EXC_ON; |
| 342 |
size_t len = src.len(); |
| 343 |
FixedArray<Vec2<TV> > dst(len); |
| 344 |
for (size_t i=0; i<len; ++i) mat.multDirMatrix(src[i], dst[i]); |
| 345 |
return dst; |
| 346 |
} |
| 347 |
|
| 348 |
template <class TV,class TM> |
| 349 |
static void |
| 350 |
multVecMatrix33(Matrix33<TM> &mat, const Vec2<TV> &src, Vec2<TV> &dst) |
| 351 |
{ |
| 352 |
MATH_EXC_ON; |
| 353 |
mat.multVecMatrix(src, dst); |
| 354 |
} |
| 355 |
|
| 356 |
template <class TV,class TM> |
| 357 |
static Vec2<TV> |
| 358 |
multVecMatrix33_return_value(Matrix33<TM> &mat, const Vec2<TV> &src) |
| 359 |
{ |
| 360 |
MATH_EXC_ON; |
| 361 |
Vec2<TV> dst; |
| 362 |
mat.multVecMatrix(src, dst); |
| 363 |
return dst; |
| 364 |
} |
| 365 |
|
| 366 |
template <class TV,class TM> |
| 367 |
static FixedArray<Vec2<TV> > |
| 368 |
multVecMatrix33_array(Matrix33<TM> &mat, const FixedArray<Vec2<TV> >&src) |
| 369 |
{ |
| 370 |
MATH_EXC_ON; |
| 371 |
size_t len = src.len(); |
| 372 |
FixedArray<Vec2<TV> > dst(len); |
| 373 |
for (size_t i=0; i<len; ++i) mat.multVecMatrix(src[i], dst[i]); |
| 374 |
return dst; |
| 375 |
} |
| 376 |
|
| 377 |
template <class T> |
| 378 |
static int |
| 379 |
removeScaling33(Matrix33<T> &mat, int exc = 1) |
| 380 |
{ |
| 381 |
MATH_EXC_ON; |
| 382 |
return IMATH_NAMESPACE::removeScaling(mat, exc); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
template <class T> |
| 387 |
static int |
| 388 |
removeScalingAndShear33(Matrix33<T> &mat, int exc = 1) |
| 389 |
{ |
| 390 |
MATH_EXC_ON; |
| 391 |
return IMATH_NAMESPACE::removeScalingAndShear(mat, exc); |
| 392 |
} |
| 393 |
|
| 394 |
template <class T> |
| 395 |
static const Matrix33<T> & |
| 396 |
rotate33(Matrix33<T> &mat, const T &r) |
| 397 |
{ |
| 398 |
MATH_EXC_ON; |
| 399 |
return mat.rotate(r); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
template <class T> |
| 404 |
static Matrix33<T> |
| 405 |
sansScaling33(const Matrix33<T> &mat, bool exc = true) |
| 406 |
{ |
| 407 |
MATH_EXC_ON; |
| 408 |
return IMATH_NAMESPACE::sansScaling(mat, exc); |
| 409 |
} |
| 410 |
|
| 411 |
template <class T> |
| 412 |
static Matrix33<T> |
| 413 |
sansScalingAndShear33(const Matrix33<T> &mat, bool exc = true) |
| 414 |
{ |
| 415 |
MATH_EXC_ON; |
| 416 |
return IMATH_NAMESPACE::sansScalingAndShear(mat, exc); |
| 417 |
} |
| 418 |
|
| 419 |
template <class T> |
| 420 |
static const Matrix33<T> & |
| 421 |
scaleSc33(Matrix33<T> &mat, const T &s) |
| 422 |
{ |
| 423 |
MATH_EXC_ON; |
| 424 |
Vec2<T> sVec(s, s); |
| 425 |
return mat.scale(sVec); |
| 426 |
} |
| 427 |
|
| 428 |
template <class T> |
| 429 |
static const Matrix33<T> & |
| 430 |
scaleV33(Matrix33<T> &mat, const Vec2<T> &s) |
| 431 |
{ |
| 432 |
MATH_EXC_ON; |
| 433 |
return mat.scale(s); |
| 434 |
} |
| 435 |
|
| 436 |
template <class T> |
| 437 |
static const Matrix33<T> & |
| 438 |
scale33Tuple(Matrix33<T> &mat, const tuple &t) |
| 439 |
{ |
| 440 |
MATH_EXC_ON; |
| 441 |
if(t.attr("__len__")() == 2) |
| 442 |
{ |
| 443 |
Vec2<T> s; |
| 444 |
s.x = extract<T>(t[0]); |
| 445 |
s.y = extract<T>(t[1]); |
| 446 |
|
| 447 |
return mat.scale(s); |
| 448 |
} |
| 449 |
else |
| 450 |
throw std::domain_error ("m.scale needs tuple of length 2"); |
| 451 |
} |
| 452 |
|
| 453 |
template <class T> |
| 454 |
static const Matrix33<T> & |
| 455 |
setRotation33(Matrix33<T> &mat, const T &r) |
| 456 |
{ |
| 457 |
MATH_EXC_ON; |
| 458 |
return mat.setRotation(r); |
| 459 |
} |
| 460 |
|
| 461 |
template <class T> |
| 462 |
static const Matrix33<T> & |
| 463 |
setScaleSc33(Matrix33<T> &mat, const T &s) |
| 464 |
{ |
| 465 |
MATH_EXC_ON; |
| 466 |
return mat.setScale(s); |
| 467 |
} |
| 468 |
|
| 469 |
template <class T> |
| 470 |
static const Matrix33<T> & |
| 471 |
setScaleV33(Matrix33<T> &mat, const Vec2<T> &s) |
| 472 |
{ |
| 473 |
MATH_EXC_ON; |
| 474 |
return mat.setScale(s); |
| 475 |
} |
| 476 |
|
| 477 |
template <class T> |
| 478 |
static const Matrix33<T> & |
| 479 |
setScale33Tuple(Matrix33<T> &mat, const tuple &t) |
| 480 |
{ |
| 481 |
MATH_EXC_ON; |
| 482 |
if(t.attr("__len__")() == 2) |
| 483 |
{ |
| 484 |
Vec2<T> s; |
| 485 |
s.x = extract<T>(t[0]); |
| 486 |
s.y = extract<T>(t[1]); |
| 487 |
|
| 488 |
return mat.setScale(s); |
| 489 |
} |
| 490 |
else |
| 491 |
throw std::invalid_argument ("m.setScale needs tuple of length 2"); |
| 492 |
} |
| 493 |
|
| 494 |
template <class T> |
| 495 |
static const Matrix33<T> & |
| 496 |
setShearSc33(Matrix33<T> &mat, const T &h) |
| 497 |
{ |
| 498 |
MATH_EXC_ON; |
| 499 |
Vec2<T> hVec(h, T(0)); |
| 500 |
return mat.setShear(hVec); |
| 501 |
} |
| 502 |
|
| 503 |
template <class T> |
| 504 |
static const Matrix33<T> & |
| 505 |
setShearV33(Matrix33<T> &mat, const Vec2<T> &h) |
| 506 |
{ |
| 507 |
MATH_EXC_ON; |
| 508 |
return mat.setShear(h); |
| 509 |
} |
| 510 |
|
| 511 |
template <class T> |
| 512 |
static const Matrix33<T> & |
| 513 |
setShear33Tuple(Matrix33<T> &mat, const tuple &t) |
| 514 |
{ |
| 515 |
MATH_EXC_ON; |
| 516 |
if(t.attr("__len__")() == 2) |
| 517 |
{ |
| 518 |
Vec2<T> h; |
| 519 |
h.x = extract<T>(t[0]); |
| 520 |
h.y = extract<T>(t[1]); |
| 521 |
|
| 522 |
return mat.setShear(h); |
| 523 |
} |
| 524 |
else |
| 525 |
throw std::domain_error ("m.shear needs tuple of length 2"); |
| 526 |
} |
| 527 |
|
| 528 |
template <class T> |
| 529 |
static const Matrix33<T> & |
| 530 |
setTranslation33(Matrix33<T> &mat, const Vec2<T> &t) |
| 531 |
{ |
| 532 |
MATH_EXC_ON; |
| 533 |
return mat.setTranslation(t); |
| 534 |
} |
| 535 |
|
| 536 |
template <class T> |
| 537 |
static const Matrix33<T> & |
| 538 |
setTranslation33Tuple(Matrix33<T> &mat, const tuple &t) |
| 539 |
{ |
| 540 |
MATH_EXC_ON; |
| 541 |
if(t.attr("__len__")() == 2) |
| 542 |
{ |
| 543 |
Vec2<T> trans; |
| 544 |
trans.x = extract<T>(t[0]); |
| 545 |
trans.y = extract<T>(t[1]); |
| 546 |
|
| 547 |
return mat.setTranslation(trans); |
| 548 |
} |
| 549 |
else |
| 550 |
throw std::domain_error ("m.translate needs tuple of length 2"); |
| 551 |
} |
| 552 |
|
| 553 |
template <class T> |
| 554 |
static const Matrix33<T> & |
| 555 |
setTranslation33Obj(Matrix33<T> &mat, const object &o) |
| 556 |
{ |
| 557 |
MATH_EXC_ON; |
| 558 |
Vec2<T> v; |
| 559 |
if (PyImath::V2<T>::convert (o.ptr(), &v)) |
| 560 |
{ |
| 561 |
return mat.setTranslation(v); |
| 562 |
} |
| 563 |
else |
| 564 |
{ |
| 565 |
throw std::invalid_argument ("m.setTranslation expected V2 argument"); |
| 566 |
return mat; |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
template <class T> |
| 571 |
static void |
| 572 |
setValue33(Matrix33<T> &mat, const Matrix33<T> &value) |
| 573 |
{ |
| 574 |
MATH_EXC_ON; |
| 575 |
mat.setValue(value); |
| 576 |
} |
| 577 |
|
| 578 |
template <class T> |
| 579 |
static const Matrix33<T> & |
| 580 |
shearSc33(Matrix33<T> &mat, const T &h) |
| 581 |
{ |
| 582 |
MATH_EXC_ON; |
| 583 |
Vec2<T> hVec(h, T (0)); |
| 584 |
|
| 585 |
return mat.shear(hVec); |
| 586 |
} |
| 587 |
|
| 588 |
template <class T> |
| 589 |
static const Matrix33<T> & |
| 590 |
shearV33(Matrix33<T> &mat, const Vec2<T> &h) |
| 591 |
{ |
| 592 |
MATH_EXC_ON; |
| 593 |
return mat.shear(h); |
| 594 |
} |
| 595 |
|
| 596 |
template <class T> |
| 597 |
static const Matrix33<T> & |
| 598 |
shear33Tuple(Matrix33<T> &mat, const tuple &t) |
| 599 |
{ |
| 600 |
MATH_EXC_ON; |
| 601 |
if(t.attr("__len__")() == 2) |
| 602 |
{ |
| 603 |
Vec2<T> h; |
| 604 |
h.x = extract<T>(t[0]); |
| 605 |
h.y = extract<T>(t[1]); |
| 606 |
|
| 607 |
return mat.shear(h); |
| 608 |
} |
| 609 |
else |
| 610 |
throw std::domain_error ("m.shear needs tuple of length 2"); |
| 611 |
} |
| 612 |
|
| 613 |
template <class T> |
| 614 |
static const Matrix33<T> & |
| 615 |
translate33(Matrix33<T> &mat, const object &t) |
| 616 |
{ |
| 617 |
MATH_EXC_ON; |
| 618 |
Vec2<T> v; |
| 619 |
if (PyImath::V2<T>::convert (t.ptr(), &v)) |
| 620 |
{ |
| 621 |
return mat.translate(v); |
| 622 |
} |
| 623 |
else |
| 624 |
{ |
| 625 |
throw std::invalid_argument ("m.translate expected V2 argument"); |
| 626 |
return mat; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
template <class T> |
| 631 |
static const Matrix33<T> & |
| 632 |
translate33Tuple(Matrix33<T> &mat, const tuple &t) |
| 633 |
{ |
| 634 |
MATH_EXC_ON; |
| 635 |
if(t.attr("__len__")() == 2) |
| 636 |
{ |
| 637 |
Vec2<T> trans; |
| 638 |
trans.x = extract<T>(t[0]); |
| 639 |
trans.y = extract<T>(t[1]); |
| 640 |
|
| 641 |
return mat.translate(trans); |
| 642 |
} |
| 643 |
else |
| 644 |
throw std::domain_error ("m.translate needs tuple of length 2"); |
| 645 |
} |
| 646 |
|
| 647 |
template <class T> |
| 648 |
static Matrix33<T> |
| 649 |
subtractTL33(Matrix33<T> &mat, T a) |
| 650 |
{ |
| 651 |
MATH_EXC_ON; |
| 652 |
Matrix33<T> m(mat.x); |
| 653 |
for(int i = 0; i < 3; ++i) |
| 654 |
for(int j = 0; j < 3; ++j) |
| 655 |
m.x[i][j] -= a; |
| 656 |
|
| 657 |
return m; |
| 658 |
} |
| 659 |
|
| 660 |
template <class T> |
| 661 |
static Matrix33<T> |
| 662 |
subtractTR33(Matrix33<T> &mat, T a) |
| 663 |
{ |
| 664 |
MATH_EXC_ON; |
| 665 |
Matrix33<T> m(mat.x); |
| 666 |
for(int i = 0; i < 3; ++i) |
| 667 |
for(int j = 0; j < 3; ++j) |
| 668 |
m.x[i][j] = a - m.x[i][j]; |
| 669 |
|
| 670 |
return m; |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
template <class T> |
| 675 |
static Matrix33<T> |
| 676 |
add33T(Matrix33<T> &mat, T a) |
| 677 |
{ |
| 678 |
MATH_EXC_ON; |
| 679 |
Matrix33<T> m(mat.x); |
| 680 |
for(int i = 0; i < 3; ++i) |
| 681 |
for(int j = 0; j < 3; ++j) |
| 682 |
m.x[i][j] += a; |
| 683 |
|
| 684 |
return m; |
| 685 |
} |
| 686 |
|
| 687 |
template <class S, class T> |
| 688 |
static Matrix33<T> |
| 689 |
mul33(Matrix33<T> &mat1, Matrix33<S> &mat2) |
| 690 |
{ |
| 691 |
MATH_EXC_ON; |
| 692 |
Matrix33<T> mat2T; |
| 693 |
mat2T.setValue (mat2); |
| 694 |
return mat1 * mat2T; |
| 695 |
} |
| 696 |
|
| 697 |
template <class S, class T> |
| 698 |
static Matrix33<T> |
| 699 |
rmul33(Matrix33<T> &mat2, Matrix33<S> &mat1) |
| 700 |
{ |
| 701 |
MATH_EXC_ON; |
| 702 |
Matrix33<T> mat1T; |
| 703 |
mat1T.setValue (mat1); |
| 704 |
return mat1T * mat2; |
| 705 |
} |
| 706 |
|
| 707 |
template <class S, class T> |
| 708 |
static const Matrix33<T> & |
| 709 |
imul33(Matrix33<T> &mat1, Matrix33<S> &mat2) |
| 710 |
{ |
| 711 |
MATH_EXC_ON; |
| 712 |
Matrix33<T> mat2T; |
| 713 |
mat2T.setValue (mat2); |
| 714 |
return mat1 *= mat2T; |
| 715 |
} |
| 716 |
|
| 717 |
template <class T> |
| 718 |
static bool |
| 719 |
lessThan33(Matrix33<T> &mat1, const Matrix33<T> &mat2) |
| 720 |
{ |
| 721 |
for(int i = 0; i < 3; ++i){ |
| 722 |
for(int j = 0; j < 3; ++j){ |
| 723 |
if(mat1[i][j] > mat2[i][j]){ |
| 724 |
return false; |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
return (mat1 != mat2); |
| 730 |
} |
| 731 |
|
| 732 |
template <class T> |
| 733 |
static bool |
| 734 |
lessThanEqual33(Matrix33<T> &mat1, const Matrix33<T> &mat2) |
| 735 |
{ |
| 736 |
for(int i = 0; i < 3; ++i){ |
| 737 |
for(int j = 0; j < 3; ++j){ |
| 738 |
if(mat1[i][j] > mat2[i][j]){ |
| 739 |
return false; |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
|
| 744 |
return true; |
| 745 |
} |
| 746 |
|
| 747 |
template <class T> |
| 748 |
static bool |
| 749 |
greaterThan33(Matrix33<T> &mat1, const Matrix33<T> &mat2) |
| 750 |
{ |
| 751 |
for(int i = 0; i < 3; ++i){ |
| 752 |
for(int j = 0; j < 3; ++j){ |
| 753 |
if(mat1[i][j] < mat2[i][j]){ |
| 754 |
std::cout << mat1[i][j] << " " << mat2[i][j] << std::endl; |
| 755 |
return false; |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
return (mat1 != mat2); |
| 761 |
} |
| 762 |
|
| 763 |
template <class T> |
| 764 |
static bool |
| 765 |
greaterThanEqual33(Matrix33<T> &mat1, const Matrix33<T> &mat2) |
| 766 |
{ |
| 767 |
for(int i = 0; i < 3; ++i){ |
| 768 |
for(int j = 0; j < 3; ++j){ |
| 769 |
if(mat1[i][j] < mat2[i][j]){ |
| 770 |
return false; |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
return true; |
| 776 |
} |
| 777 |
|
| 778 |
template <class T> |
| 779 |
static tuple |
| 780 |
singularValueDecomposition33(const Matrix33<T>& m, bool forcePositiveDeterminant = false) |
| 781 |
{ |
| 782 |
IMATH_NAMESPACE::Matrix33<T> U, V; |
| 783 |
IMATH_NAMESPACE::Vec3<T> S; |
| 784 |
IMATH_NAMESPACE::jacobiSVD (m, U, S, V, std::numeric_limits<T>::epsilon(), forcePositiveDeterminant); |
| 785 |
return make_tuple (U, S, V); |
| 786 |
} |
| 787 |
|
| 788 |
BOOST_PYTHON_FUNCTION_OVERLOADS(invert33_overloads, invert33, 1, 2); |
| 789 |
BOOST_PYTHON_FUNCTION_OVERLOADS(inverse33_overloads, inverse33, 1, 2); |
| 790 |
BOOST_PYTHON_FUNCTION_OVERLOADS(gjInvert33_overloads, gjInvert33, 1, 2); |
| 791 |
BOOST_PYTHON_FUNCTION_OVERLOADS(gjInverse33_overloads, gjInverse33, 1, 2); |
| 792 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractAndRemoveScalingAndShear33_overloads, extractAndRemoveScalingAndShear33, 3, 4) |
| 793 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractSHRT33_overloads, extractSHRT33, 5, 6) |
| 794 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractScaling33_overloads, extractScaling33, 2, 3) |
| 795 |
BOOST_PYTHON_FUNCTION_OVERLOADS(extractScalingAndShear33_overloads, extractScalingAndShear33, 3, 4) |
| 796 |
BOOST_PYTHON_FUNCTION_OVERLOADS(removeScaling33_overloads, removeScaling33, 1, 2) |
| 797 |
BOOST_PYTHON_FUNCTION_OVERLOADS(removeScalingAndShear33_overloads, removeScalingAndShear33, 1, 2) |
| 798 |
BOOST_PYTHON_FUNCTION_OVERLOADS(sansScaling33_overloads, sansScaling33, 1, 2) |
| 799 |
BOOST_PYTHON_FUNCTION_OVERLOADS(sansScalingAndShear33_overloads, sansScalingAndShear33, 1, 2) |
| 800 |
BOOST_PYTHON_FUNCTION_OVERLOADS(outerProduct33_overloads, outerProduct33, 3, 3); |
| 801 |
|
| 802 |
template <class T> |
| 803 |
static Matrix33<T> * Matrix3_tuple_constructor(const tuple &t0, const tuple &t1, const tuple &t2) |
| 804 |
{ |
| 805 |
if(t0.attr("__len__")() == 3 && t1.attr("__len__")() == 3 && t2.attr("__len__")() == 3) |
| 806 |
{ |
| 807 |
return new Matrix33<T>(extract<T>(t0[0]), extract<T>(t0[1]), extract<T>(t0[2]), |
| 808 |
extract<T>(t1[0]), extract<T>(t1[1]), extract<T>(t1[2]), |
| 809 |
extract<T>(t2[0]), extract<T>(t2[1]), extract<T>(t2[2])); |
| 810 |
} |
| 811 |
else |
| 812 |
throw std::domain_error ("Matrix33 takes 3 tuples of length 3"); |
| 813 |
} |
| 814 |
|
| 815 |
template <class T, class S> |
| 816 |
static Matrix33<T> *Matrix3_matrix_constructor(const Matrix33<S> &mat) |
| 817 |
{ |
| 818 |
Matrix33<T> *m = new Matrix33<T>; |
| 819 |
|
| 820 |
for(int i = 0; i < 3; ++i) |
| 821 |
for(int j = 0; j < 3; ++j) |
| 822 |
m->x[i][j] = T (mat.x[i][j]); |
| 823 |
|
| 824 |
return m; |
| 825 |
} |
| 826 |
|
| 827 |
template <class T> |
| 828 |
class_<Matrix33<T> > |
| 829 |
register_Matrix33() |
| 830 |
{ |
| 831 |
typedef PyImath::StaticFixedArray<Matrix33<T>,T,3,IndexAccessMatrixRow<Matrix33<T>,T,3> > Matrix33_helper; |
| 832 |
|
| 833 |
MatrixRow<T,3>::register_class(); |
| 834 |
class_<Matrix33<T> > matrix33_class(Matrix33Name<T>::value, Matrix33Name<T>::value,init<Matrix33<T> >("copy construction")); |
| 835 |
matrix33_class |
| 836 |
.def(init<>("initialize to identity")) |
| 837 |
.def(init<T>("initialize all entries to a single value")) |
| 838 |
.def(init<T,T,T,T,T,T,T,T,T>("make from components")) |
| 839 |
.def("__init__", make_constructor(Matrix3_tuple_constructor<T>)) |
| 840 |
.def("__init__", make_constructor(Matrix3_matrix_constructor<T,float>)) |
| 841 |
.def("__init__", make_constructor(Matrix3_matrix_constructor<T,double>)) |
| 842 |
|
| 843 |
//.def_readwrite("x00", &Matrix33<T>::x[0][0]) |
| 844 |
//.def_readwrite("x01", &Matrix33<T>::x[0][1]) |
| 845 |
//.def_readwrite("x02", &Matrix33<T>::x[0][2]) |
| 846 |
//.def_readwrite("x10", &Matrix33<T>::x[1][0]) |
| 847 |
//.def_readwrite("x11", &Matrix33<T>::x[1][1]) |
| 848 |
//.def_readwrite("x12", &Matrix33<T>::x[1][2]) |
| 849 |
//.def_readwrite("x20", &Matrix33<T>::x[2][0]) |
| 850 |
//.def_readwrite("x21", &Matrix33<T>::x[2][1]) |
| 851 |
//.def_readwrite("x22", &Matrix33<T>::x[2][2]) |
| 852 |
.def("baseTypeEpsilon", &Matrix33<T>::baseTypeEpsilon,"baseTypeEpsilon() epsilon value of the base type of the vector") |
| 853 |
.staticmethod("baseTypeEpsilon") |
| 854 |
.def("baseTypeMax", &Matrix33<T>::baseTypeMax,"baseTypeMax() max value of the base type of the vector") |
| 855 |
.staticmethod("baseTypeMax") |
| 856 |
.def("baseTypeLowest", &Matrix33<T>::baseTypeLowest,"baseTypeLowest() largest negative value of the base type of the vector") |
| 857 |
.staticmethod("baseTypeLowest") |
| 858 |
.def("baseTypeSmallest", &Matrix33<T>::baseTypeSmallest,"baseTypeSmallest() smallest value of the base type of the vector") |
| 859 |
.staticmethod("baseTypeSmallest") |
| 860 |
.def("equalWithAbsError", &Matrix33<T>::equalWithAbsError,"m1.equalWithAbsError(m2,e) true if the elements " |
| 861 |
"of v1 and v2 are the same with an absolute error of no more than e, " |
| 862 |
"i.e., abs(m1[i] - m2[i]) <= e") |
| 863 |
.def("equalWithRelError", &Matrix33<T>::equalWithRelError,"m1.equalWithAbsError(m2,e) true if the elements " |
| 864 |
"of m1 and m2 are the same with an absolute error of no more than e, " |
| 865 |
"i.e., abs(m1[i] - m2[i]) <= e * abs(m1[i])") |
| 866 |
// need a different version for matrix data access |
| 867 |
.def("__len__", Matrix33_helper::len) |
| 868 |
.def("__getitem__", Matrix33_helper::getitem) |
| 869 |
//.def("__setitem__", Matrix33_helper::setitem) |
| 870 |
.def("makeIdentity",&Matrix33<T>::makeIdentity,"makeIdentity() make this matrix the identity matrix") |
| 871 |
.def("transpose",&Matrix33<T>::transpose,return_internal_reference<>(),"transpose() transpose this matrix") |
| 872 |
.def("transposed",&Matrix33<T>::transposed,"transposed() return a transposed copy of this matrix") |
| 873 |
.def("invert",&invert33<T>,invert33_overloads("invert() invert this matrix")[return_internal_reference<>()]) |
| 874 |
.def("inverse",&inverse33<T>,inverse33_overloads("inverse() return an inverted copy of this matrix")) |
| 875 |
.def("gjInvert",&gjInvert33<T>,gjInvert33_overloads("gjInvert() invert this matrix")[return_internal_reference<>()]) |
| 876 |
.def("gjInverse",&gjInverse33<T>,gjInverse33_overloads("gjInverse() return an inverted copy of this matrix")) |
| 877 |
.def("minorOf",&Matrix33<T>::minorOf,"minorOf() return the matrix minor of the (row,col) element of this matrix") |
| 878 |
.def("fastMinor",&Matrix33<T>::fastMinor,"fastMinor() return the matrix minor using the specified rows and columns of this matrix") |
| 879 |
.def("determinant",&Matrix33<T>::determinant,"determinant() return the determinant of this matrix") |
| 880 |
.def(self == self) // NOSONAR - suppress SonarCloud bug report. |
| 881 |
.def(self != self) // NOSONAR - suppress SonarCloud bug report. |
| 882 |
.def("__iadd__", &iadd33<T, float>,return_internal_reference<>()) |
| 883 |
.def("__iadd__", &iadd33<T, double>,return_internal_reference<>()) |
| 884 |
.def("__iadd__", &iadd33T<T>,return_internal_reference<>()) |
| 885 |
.def("__add__", &add33<T>) |
| 886 |
.def("__isub__", &isub33<T, float>,return_internal_reference<>()) |
| 887 |
.def("__isub__", &isub33<T, double>,return_internal_reference<>()) |
| 888 |
.def("__isub__", &isub33T<T>,return_internal_reference<>()) |
| 889 |
.def("__sub__", &sub33<T>) |
| 890 |
.def("negate",&negate33<T>,return_internal_reference<>(),"negate() negate all entries in this matrix") |
| 891 |
.def("__neg__", &neg33<T>) |
| 892 |
.def("__imul__", &imul33T<T>,return_internal_reference<>()) |
| 893 |
.def("__mul__", &mul33T<T>) |
| 894 |
.def("__rmul__", &rmul33T<T>) |
| 895 |
.def("__idiv__", &idiv33T<T>,return_internal_reference<>()) |
| 896 |
.def("__itruediv__", &idiv33T<T>,return_internal_reference<>()) |
| 897 |
.def("__div__", &div33T<T>) |
| 898 |
.def("__truediv__", &div33T<T>) |
| 899 |
.def("__add__", &add33T<T>) |
| 900 |
.def("__radd__", &add33T<T>) |
| 901 |
.def("__sub__", &subtractTL33<T>) |
| 902 |
.def("__rsub__", &subtractTR33<T>) |
| 903 |
.def("__mul__", &mul33<float, T>) |
| 904 |
.def("__mul__", &mul33<double, T>) |
| 905 |
.def("__rmul__", &rmul33<float, T>) |
| 906 |
.def("__rmul__", &rmul33<double, T>) |
| 907 |
.def("__imul__", &imul33<float, T>,return_internal_reference<>()) |
| 908 |
.def("__imul__", &imul33<double, T>,return_internal_reference<>()) |
| 909 |
.def("__lt__", &lessThan33<T>) |
| 910 |
.def("__le__", &lessThanEqual33<T>) |
| 911 |
.def("__gt__", &greaterThan33<T>) |
| 912 |
.def("__ge__", &greaterThanEqual33<T>) |
| 913 |
//.def(self_ns::str(self)) |
| 914 |
.def("__str__",&Matrix33_str<T>) |
| 915 |
.def("__repr__",&Matrix33_repr<T>) |
| 916 |
.def("extractAndRemoveScalingAndShear", &extractAndRemoveScalingAndShear33<T>, |
| 917 |
extractAndRemoveScalingAndShear33_overloads( |
| 918 |
"M.extractAndRemoveScalingAndShear(scl, shr, " |
| 919 |
"[exc]) -- extracts the scaling component of " |
| 920 |
"M into scl and the shearing component of M " |
| 921 |
"into shr. Also removes the scaling and " |
| 922 |
"shearing components from M. " |
| 923 |
"Returns 1 unless the scaling component is " |
| 924 |
"nearly 0, in which case 0 is returned. " |
| 925 |
"If optional arg. exc == 1, then if the " |
| 926 |
"scaling component is nearly 0, then MathExc " |
| 927 |
"is thrown. ")) |
| 928 |
|
| 929 |
.def("extractEuler", &extractEuler<T>, |
| 930 |
"M.extractEulerZYX(r) -- extracts the " |
| 931 |
"rotation component of M into r. " |
| 932 |
"Assumes that M contains no shear or " |
| 933 |
"non-uniform scaling; results are " |
| 934 |
"meaningless if it does.") |
| 935 |
|
| 936 |
.def("extractSHRT", &extractSHRT33<T>, extractSHRT33_overloads( |
| 937 |
"M.extractSHRT(Vs, Vh, Vr, Vt, [exc]) -- " |
| 938 |
"extracts the scaling component of M into Vs, " |
| 939 |
"the shearing component of M in Vh (as XY, " |
| 940 |
"XZ, YZ shear factors), the rotation of M " |
| 941 |
"into Vr (as Euler angles in the order XYZ), " |
| 942 |
"and the translaation of M into Vt. " |
| 943 |
"If optional arg. exc == 1, then if the " |
| 944 |
"scaling component is nearly 0, then MathExc " |
| 945 |
"is thrown. ")) |
| 946 |
|
| 947 |
.def("extractScaling", &extractScaling33<T>, extractScaling33_overloads("extract scaling")) |
| 948 |
.def("outerProduct", &outerProduct33<T>, outerProduct33_overloads( |
| 949 |
"M.outerProduct(Va,Vb) -- " |
| 950 |
"Performs the outer product, or tensor product, of two 3D vectors, Va and Vb")) |
| 951 |
|
| 952 |
.def("extractScalingAndShear", &extractScalingAndShear33<T>, extractScalingAndShear33_overloads("extract scaling")) |
| 953 |
.def("singularValueDecomposition", &singularValueDecomposition33<T>, |
| 954 |
"Decomposes the matrix using the singular value decomposition (SVD) into three\n" |
| 955 |
"matrices U, S, and V which have the following properties: \n" |
| 956 |
" 1. U and V are both orthonormal matrices, \n" |
| 957 |
" 2. S is the diagonal matrix of singular values, \n" |
| 958 |
" 3. U * S * V.transposed() gives back the original matrix.\n" |
| 959 |
"The result is returned as a tuple [U, S, V]. Note that since S is diagonal we\n" |
| 960 |
"don't need to return the entire matrix, so we return it as a three-vector. \n" |
| 961 |
"\n" |
| 962 |
"The 'forcePositiveDeterminant' argument can be used to force the U and V^T to\n" |
| 963 |
"have positive determinant (that is, to be proper rotation matrices); if\n" |
| 964 |
"forcePositiveDeterminant is False, then the singular values are guaranteed to\n" |
| 965 |
"be nonnegative but the U and V matrices might contain negative scale along one\n" |
| 966 |
"of the axes; if forcePositiveDeterminant is True, then U and V cannot contain\n" |
| 967 |
"negative scale but S[2] might be negative. \n" |
| 968 |
"\n" |
| 969 |
"Our SVD implementation uses two-sided Jacobi rotations to iteratively\n" |
| 970 |
"diagonalize the matrix, which should be quite robust and significantly faster\n" |
| 971 |
"than the more general SVD solver in LAPACK. \n", |
| 972 |
args("matrix", "forcePositiveDeterminant")) |
| 973 |
.def("symmetricEigensolve", &PyImath::jacobiEigensolve<IMATH_NAMESPACE::Matrix33<T> >, |
| 974 |
"Decomposes the matrix A using a symmetric eigensolver into matrices Q and S \n" |
| 975 |
"which have the following properties: \n" |
| 976 |
" 1. Q is the orthonormal matrix of eigenvectors, \n" |
| 977 |
" 2. S is the diagonal matrix of eigenvalues, \n" |
| 978 |
" 3. Q * S * Q.transposed() gives back the original matrix.\n" |
| 979 |
"\n" |
| 980 |
"IMPORTANT: It is vital that the passed-in matrix be symmetric, or the result \n" |
| 981 |
"won't make any sense. This function will return an error if passed an \n" |
| 982 |
"unsymmetric matrix.\n" |
| 983 |
"\n" |
| 984 |
"The result is returned as a tuple [Q, S]. Note that since S is diagonal \n" |
| 985 |
"we don't need to return the entire matrix, so we return it as a three-vector. \n" |
| 986 |
"\n" |
| 987 |
"Our eigensolver implementation uses one-sided Jacobi rotations to iteratively \n" |
| 988 |
"diagonalize the matrix, which should be quite robust and significantly faster \n" |
| 989 |
"than the more general symmetric eigenvalue solver in LAPACK. \n") |
| 990 |
.def("multDirMatrix", &multDirMatrix33<double,T>, "mult matrix") |
| 991 |
.def("multDirMatrix", &multDirMatrix33_return_value<double,T>, "mult matrix") |
| 992 |
.def("multDirMatrix", &multDirMatrix33_array<double,T>, "mult matrix") |
| 993 |
.def("multDirMatrix", &multDirMatrix33<float,T>, "mult matrix") |
| 994 |
.def("multDirMatrix", &multDirMatrix33_return_value<float,T>, "mult matrix") |
| 995 |
.def("multDirMatrix", &multDirMatrix33_array<float,T>, "mult matrix") |
| 996 |
.def("multVecMatrix", &multVecMatrix33<double,T>, "mult matrix") |
| 997 |
.def("multVecMatrix", &multVecMatrix33_return_value<double,T>, "mult matrix") |
| 998 |
.def("multVecMatrix", &multVecMatrix33_array<double,T>, "mult matrix") |
| 999 |
.def("multVecMatrix", &multVecMatrix33<float,T>, "mult matrix") |
| 1000 |
.def("multVecMatrix", &multVecMatrix33_return_value<float,T>, "mult matrix") |
| 1001 |
.def("multVecMatrix", &multVecMatrix33_array<float,T>, "mult matrix") |
| 1002 |
.def("removeScaling", &removeScaling33<T>, removeScaling33_overloads("remove scaling")) |
| 1003 |
|
| 1004 |
.def("removeScalingAndShear", &removeScalingAndShear33<T>, removeScalingAndShear33_overloads("remove scaling")) |
| 1005 |
.def("sansScaling", &sansScaling33<T>, sansScaling33_overloads("sans scaling")) |
| 1006 |
.def("rotate", &rotate33<T>, return_internal_reference<>(),"rotate matrix") |
| 1007 |
|
| 1008 |
.def("sansScalingAndShear", &sansScalingAndShear33<T>, sansScalingAndShear33_overloads("sans scaling and shear")) |
| 1009 |
.def("scale", &scaleSc33<T>, return_internal_reference<>(),"scale matrix") |
| 1010 |
.def("scale", &scaleV33<T>, return_internal_reference<>(),"scale matrix") |
| 1011 |
.def("scale", &scale33Tuple<T>, return_internal_reference<>(),"scale matrix") |
| 1012 |
|
| 1013 |
.def("setRotation", &setRotation33<T>, return_internal_reference<>(),"setRotation()") |
| 1014 |
.def("setScale", &setScaleSc33<T>, return_internal_reference<>(),"setScale()") |
| 1015 |
.def("setScale", &setScaleV33<T>, return_internal_reference<>(),"setScale()") |
| 1016 |
.def("setScale", &setScale33Tuple<T>, return_internal_reference<>(),"setScale()") |
| 1017 |
|
| 1018 |
.def("setShear", &setShearSc33<T>, return_internal_reference<>(),"setShear()") |
| 1019 |
.def("setShear", &setShearV33<T>, return_internal_reference<>(),"setShear()") |
| 1020 |
.def("setShear", &setShear33Tuple<T>, return_internal_reference<>(),"setShear()") |
| 1021 |
|
| 1022 |
.def("setTranslation", &setTranslation33<T>, return_internal_reference<>(),"setTranslation()") |
| 1023 |
.def("setTranslation", &setTranslation33Tuple<T>, return_internal_reference<>(),"setTranslation()") |
| 1024 |
.def("setTranslation", &setTranslation33Obj<T>, return_internal_reference<>(),"setTranslation()") |
| 1025 |
.def("setValue", &setValue33<T>, "setValue()") |
| 1026 |
.def("shear", &shearSc33<T>, return_internal_reference<>(),"shear()") |
| 1027 |
.def("shear", &shearV33<T>, return_internal_reference<>(),"shear()") |
| 1028 |
.def("shear", &shear33Tuple<T>, return_internal_reference<>(),"shear()") |
| 1029 |
.def("translate", &translate33<T>, return_internal_reference<>(),"translate()") |
| 1030 |
.def("translate", &translate33Tuple<T>, return_internal_reference<>(),"translate()") |
| 1031 |
.def("translation", &Matrix33<T>::translation, "translation()") |
| 1032 |
; |
| 1033 |
|
| 1034 |
decoratecopy(matrix33_class); |
| 1035 |
|
| 1036 |
return matrix33_class; |
| 1037 |
/* |
| 1038 |
const Matrix33 & operator = (const Matrix33 &v); |
| 1039 |
const Matrix33 & operator = (T a); |
| 1040 |
T * getValue (); |
| 1041 |
const T * getValue () const; |
| 1042 |
template <class S> void getValue (Matrix33<S> &v) const; |
| 1043 |
template <class S> Matrix33 & setValue (const Matrix33<S> &v); |
| 1044 |
template <class S> Matrix33 & setTheMatrix (const Matrix33<S> &v); |
| 1045 |
template <class S> void multVecMatrix(const Vec2<S> &src, Vec2<S> &dst) const; |
| 1046 |
template <class S> void multDirMatrix(const Vec2<S> &src, Vec2<S> &dst) const; |
| 1047 |
template <class S> const Matrix33 & setRotation (S r); |
| 1048 |
template <class S> const Matrix33 & rotate (S r); |
| 1049 |
const Matrix33 & setScale (T s); |
| 1050 |
template <class S> const Matrix33 & setScale (const Vec2<S> &s); |
| 1051 |
template <class S> const Matrix33 & scale (const Vec2<S> &s); |
| 1052 |
template <class S> const Matrix33 & setTranslation (const Vec2<S> &t); |
| 1053 |
Vec2<T> translation () const; |
| 1054 |
template <class S> const Matrix33 & translate (const Vec2<S> &t); |
| 1055 |
template <class S> const Matrix33 & setShear (const S &h); |
| 1056 |
template <class S> const Matrix33 & setShear (const Vec2<S> &h); |
| 1057 |
template <class S> const Matrix33 & shear (const S &xy); |
| 1058 |
template <class S> const Matrix33 & shear (const Vec2<S> &h); |
| 1059 |
*/ |
| 1060 |
} |
| 1061 |
|
| 1062 |
template <class T> |
| 1063 |
struct Matrix33Array_Constructor : public Task |
| 1064 |
{ |
| 1065 |
const FixedArray<T> &a; const FixedArray<T> &b; const FixedArray<T> &c; |
| 1066 |
const FixedArray<T> &d; const FixedArray<T> &e; const FixedArray<T> &f; |
| 1067 |
const FixedArray<T> &g; const FixedArray<T> &h; const FixedArray<T> &i; |
| 1068 |
FixedArray<IMATH_NAMESPACE::Matrix33<T> > &result; |
| 1069 |
|
| 1070 |
Matrix33Array_Constructor (const FixedArray<T> &a, const FixedArray<T> &b, const FixedArray<T> &c, |
| 1071 |
const FixedArray<T> &d, const FixedArray<T> &e, const FixedArray<T> &f, |
| 1072 |
const FixedArray<T> &g, const FixedArray<T> &h, const FixedArray<T> &i, |
| 1073 |
FixedArray<IMATH_NAMESPACE::Matrix33<T> > &result) |
| 1074 |
: a (a), b (b), c (c), |
| 1075 |
d (d), e (e), f (f), |
| 1076 |
g (g), h (h), i (i), result (result) {} |
| 1077 |
|
| 1078 |
void execute (size_t start, size_t end) |
| 1079 |
{ |
| 1080 |
for (size_t index = start; index < end; ++index) |
| 1081 |
{ |
| 1082 |
result[index] = IMATH_NAMESPACE::Matrix33<T>(a[index], b[index], c[index], |
| 1083 |
d[index], e[index], f[index], |
| 1084 |
g[index], h[index], i[index]); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
}; |
| 1088 |
|
| 1089 |
template <class T> |
| 1090 |
static FixedArray<IMATH_NAMESPACE::Matrix33<T> > * |
| 1091 |
M33Array_constructor(const FixedArray<T> &a, const FixedArray<T> &b, const FixedArray<T> &c, |
| 1092 |
const FixedArray<T> &d, const FixedArray<T> &e, const FixedArray<T> &f, |
| 1093 |
const FixedArray<T> &g, const FixedArray<T> &h, const FixedArray<T> &i) |
| 1094 |
{ |
| 1095 |
MATH_EXC_ON; |
| 1096 |
Py_ssize_t len = a.len(); |
| 1097 |
if (!( a.len() == len && b.len() == len && c.len() == len && |
| 1098 |
d.len() == len && e.len() == len && f.len() == len && |
| 1099 |
g.len() == len && h.len() == len && i.len() == len)) |
| 1100 |
throw std::invalid_argument("Dimensions do not match" ); |
| 1101 |
FixedArray<IMATH_NAMESPACE::Matrix33<T> >* result = |
| 1102 |
new FixedArray<IMATH_NAMESPACE::Matrix33<T> > (Py_ssize_t(len), UNINITIALIZED); |
| 1103 |
|
| 1104 |
Matrix33Array_Constructor<T> task (a, b, c, d, e, f, g, h, i, *result); |
| 1105 |
dispatchTask (task, len); |
| 1106 |
return result; |
| 1107 |
} |
| 1108 |
|
| 1109 |
template <class T> |
| 1110 |
static void |
| 1111 |
setM33ArrayItem(FixedArray<IMATH_NAMESPACE::Matrix33<T> > &ma, |
| 1112 |
Py_ssize_t index, |
| 1113 |
const IMATH_NAMESPACE::Matrix33<T> &m) |
| 1114 |
{ |
| 1115 |
ma[ma.canonical_index(index)] = m; |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
template <class T> |
| 1120 |
struct M33Array_Inverse : public Task |
| 1121 |
{ |
| 1122 |
const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &mats; |
| 1123 |
FixedArray<IMATH_NAMESPACE::Matrix33<T> > &result; |
| 1124 |
|
| 1125 |
M33Array_Inverse (FixedArray<IMATH_NAMESPACE::Matrix33<T> > &result, |
| 1126 |
const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &mats) |
| 1127 |
: mats (mats), result (result) {} |
| 1128 |
|
| 1129 |
void execute (size_t start, size_t end) |
| 1130 |
{ |
| 1131 |
for (size_t i = start; i < end; ++i) |
| 1132 |
result[i] = mats[i].inverse(); |
| 1133 |
} |
| 1134 |
}; |
| 1135 |
|
| 1136 |
template <class T> |
| 1137 |
static FixedArray<IMATH_NAMESPACE::Matrix33<T> > |
| 1138 |
M33Array_inverse(const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &ma) |
| 1139 |
{ |
| 1140 |
MATH_EXC_ON; |
| 1141 |
size_t len = ma.len(); |
| 1142 |
FixedArray<IMATH_NAMESPACE::Matrix33<T> > result (len); |
| 1143 |
|
| 1144 |
M33Array_Inverse<T> task (result, ma); |
| 1145 |
dispatchTask (task, len); |
| 1146 |
|
| 1147 |
return result; |
| 1148 |
} |
| 1149 |
|
| 1150 |
template <class T> |
| 1151 |
struct M33Array_RmulVec3 : public Task |
| 1152 |
{ |
| 1153 |
const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &a; |
| 1154 |
const Vec3<T> &v; |
| 1155 |
FixedArray<Vec3<T> > &r; |
| 1156 |
|
| 1157 |
M33Array_RmulVec3 (const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &a, |
| 1158 |
const Vec3<T> &v, |
| 1159 |
FixedArray<Vec3<T> > &r) |
| 1160 |
: a (a), v (v), r (r) {} |
| 1161 |
|
| 1162 |
void execute(size_t start, size_t end) |
| 1163 |
{ |
| 1164 |
for (size_t i = start; i < end; ++i) |
| 1165 |
{ |
| 1166 |
r[i] = v * a[i]; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
}; |
| 1170 |
|
| 1171 |
template <class T> |
| 1172 |
static FixedArray< Vec3<T> > |
| 1173 |
M33Array_rmulVec3 (const FixedArray< IMATH_NAMESPACE::Matrix33<T> > &a, const Vec3<T> &v) |
| 1174 |
{ |
| 1175 |
MATH_EXC_ON; |
| 1176 |
size_t len = a.len(); |
| 1177 |
FixedArray< Vec3<T> > r (Py_ssize_t(len), UNINITIALIZED); |
| 1178 |
|
| 1179 |
M33Array_RmulVec3<T> task (a, v, r); |
| 1180 |
dispatchTask (task, len); |
| 1181 |
return r; |
| 1182 |
} |
| 1183 |
|
| 1184 |
template <class T> |
| 1185 |
struct M33Array_RmulVec3Array : public Task |
| 1186 |
{ |
| 1187 |
const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &a; |
| 1188 |
const FixedArray<Vec3<T> > &b; |
| 1189 |
FixedArray<Vec3<T> > &r; |
| 1190 |
|
| 1191 |
M33Array_RmulVec3Array (const FixedArray<IMATH_NAMESPACE::Matrix33<T> > &a, |
| 1192 |
const FixedArray<Vec3<T> > &b, |
| 1193 |
FixedArray<Vec3<T> > &r) |
| 1194 |
: a (a), b (b), r (r) {} |
| 1195 |
|
| 1196 |
void execute(size_t start, size_t end) |
| 1197 |
{ |
| 1198 |
for (size_t i = start; i < end; ++i) |
| 1199 |
{ |
| 1200 |
r[i] = b[i] * a[i]; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
}; |
| 1204 |
|
| 1205 |
template <class T> |
| 1206 |
static FixedArray< Vec3<T> > |
| 1207 |
M33Array_rmulVec3Array (const FixedArray< IMATH_NAMESPACE::Matrix33<T> > &a, |
| 1208 |
const FixedArray< Vec3<T> > &b) |
| 1209 |
{ |
| 1210 |
MATH_EXC_ON; |
| 1211 |
size_t len = a.match_dimension(b); |
| 1212 |
FixedArray< Vec3<T> > r (Py_ssize_t(len), UNINITIALIZED); |
| 1213 |
|
| 1214 |
M33Array_RmulVec3Array<T> task (a, b, r); |
| 1215 |
dispatchTask (task, len); |
| 1216 |
return r; |
| 1217 |
} |
| 1218 |
|
| 1219 |
template <class T> |
| 1220 |
class_<FixedArray<IMATH_NAMESPACE::Matrix33<T> > > |
| 1221 |
register_M33Array() |
| 1222 |
{ |
| 1223 |
class_<FixedArray<IMATH_NAMESPACE::Matrix33<T> > > matrixArray_class = FixedArray<IMATH_NAMESPACE::Matrix33<T> >::register_("Fixed length array of IMATH_NAMESPACE::Matrix33"); |
| 1224 |
matrixArray_class |
| 1225 |
.def("__init__", make_constructor(M33Array_constructor<T>)) |
| 1226 |
.def("__setitem__", &setM33ArrayItem<T>) |
| 1227 |
.def("inverse", &M33Array_inverse<T>, |
| 1228 |
"Return M^-1 for each element M.", |
| 1229 |
(args("vector"))) |
| 1230 |
.def("__rmul__", &M33Array_rmulVec3<T>) |
| 1231 |
.def("__rmul__", &M33Array_rmulVec3Array<T>) |
| 1232 |
; |
| 1233 |
|
| 1234 |
add_comparison_functions(matrixArray_class); |
| 1235 |
|
| 1236 |
return matrixArray_class; |
| 1237 |
} |
| 1238 |
|
| 1239 |
template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix33<float> > register_Matrix33<float>(); |
| 1240 |
template PYIMATH_EXPORT class_<IMATH_NAMESPACE::Matrix33<double> > register_Matrix33<double>(); |
| 1241 |
|
| 1242 |
template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix33<float> > > register_M33Array<float>(); |
| 1243 |
template PYIMATH_EXPORT class_<FixedArray<IMATH_NAMESPACE::Matrix33<double> > > register_M33Array<double>(); |
| 1244 |
|
| 1245 |
|
| 1246 |
template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix33<float> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix33<float> >::value() { return IMATH_NAMESPACE::Matrix33<float>(); } |
| 1247 |
template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix33<double> FixedArrayDefaultValue<IMATH_NAMESPACE::Matrix33<double> >::value() { return IMATH_NAMESPACE::Matrix33<double>(); } |
| 1248 |
} |