/////////////////////////////////////////////////////////////////////////// // // Copyright (c) 1998-2011, Industrial Light & Magic, a division of Lucas // Digital Ltd. LLC // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Industrial Light & Magic nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////// #define BOOST_PYTHON_MAX_ARITY 17 #include #include "PyImathExport.h" #include "PyImathDecorators.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace PyImath { template<> const char PYIMATH_EXPORT *PyImath::M44fArray::name() { return "M44fArray"; } template<> const char PYIMATH_EXPORT *PyImath::M44dArray::name() { return "M44dArray"; } using namespace boost::python; using namespace IMATH_NAMESPACE; using namespace PyImath; template struct MatrixRow { explicit MatrixRow(T *data) : _data(data) {} T & operator [] (int i) { return _data[i]; } T *_data; static const char *name; static void register_class() { typedef PyImath::StaticFixedArray MatrixRow_helper; class_ matrixRow_class(name,no_init); matrixRow_class .def("__len__", MatrixRow_helper::len) .def("__getitem__", MatrixRow_helper::getitem,return_value_policy()) .def("__setitem__", MatrixRow_helper::setitem) ; } }; template <> const char *MatrixRow::name = "M44fRow"; template <> const char *MatrixRow::name = "M44dRow"; template struct IndexAccessMatrixRow { typedef MatrixRow result_type; static MatrixRow apply(Container &c, int i) { return MatrixRow(c[i]); } }; template struct Matrix44Name { static const char *value; }; template<> const char *Matrix44Name::value = "M44f"; template<> const char *Matrix44Name::value = "M44d"; template static std::string Matrix44_str(const Matrix44 &v) { std::stringstream stream; stream << Matrix44Name::value << "("; for (int row = 0; row < 4; row++) { stream << "("; for (int col = 0; col < 4; col++) { stream << v[row][col]; stream << (col != 3 ? ", " : ""); } stream << ")" << (row != 3 ? ", " : ""); } stream << ")"; return stream.str(); } // Non-specialized repr is same as str template static std::string Matrix44_repr(const Matrix44 &v) { return Matrix44_str(v); } // Specialization for float to full precision template <> std::string Matrix44_repr(const Matrix44 &v) { return (boost::format("%s((%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g), (%.9g, %.9g, %.9g, %.9g))") % Matrix44Name::value % v[0][0] % v[0][1] % v[0][2] % v[0][3] % v[1][0] % v[1][1] % v[1][2] % v[1][3] % v[2][0] % v[2][1] % v[2][2] % v[2][3] % v[3][0] % v[3][1] % v[3][2] % v[3][3]).str(); } // Specialization for double to full precision template <> std::string Matrix44_repr(const Matrix44 &v) { return (boost::format("%s((%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g), (%.17g, %.17g, %.17g, %.17g))") % Matrix44Name::value % v[0][0] % v[0][1] % v[0][2] % v[0][3] % v[1][0] % v[1][1] % v[1][2] % v[1][3] % v[2][0] % v[2][1] % v[2][2] % v[2][3] % v[3][0] % v[3][1] % v[3][2] % v[3][3]).str(); } template static const Matrix44 & invert44 (Matrix44 &m, bool singExc = true) { MATH_EXC_ON; return m.invert(singExc); } template static Matrix44 inverse44 (Matrix44 &m, bool singExc = true) { MATH_EXC_ON; return m.inverse(singExc); } template static const Matrix44 & gjInvert44 (Matrix44 &m, bool singExc = true) { MATH_EXC_ON; return m.gjInvert(singExc); } template static Matrix44 gjInverse44 (Matrix44 &m, bool singExc = true) { MATH_EXC_ON; return m.gjInverse(singExc); } template static const Matrix44 & iadd44(Matrix44 &m, const Matrix44 &m2) { MATH_EXC_ON; Matrix44 m3; m3.setValue (m2); return m += m3; } template static const Matrix44 & iadd44T(Matrix44 &mat, T a) { MATH_EXC_ON; return mat += a; } template static Matrix44 add44(Matrix44 &m, const Matrix44 &m2) { MATH_EXC_ON; return m + m2; } template static const Matrix44 & isub44(Matrix44 &m, const Matrix44 &m2) { MATH_EXC_ON; Matrix44 m3; m3.setValue (m2); return m -= m3; } template static const Matrix44 & isub44T(Matrix44 &mat, T a) { MATH_EXC_ON; return mat -= a; } template static Matrix44 sub44(Matrix44 &m, const Matrix44 &m2) { MATH_EXC_ON; return m - m2; } template static const Matrix44 & negate44 (Matrix44 &m) { MATH_EXC_ON; return m.negate(); } template static Matrix44 neg44 (Matrix44 &m) { MATH_EXC_ON; return -m; } template static const Matrix44 & imul44T(Matrix44 &m, const T &t) { MATH_EXC_ON; return m *= t; } template static Matrix44 mul44T(Matrix44 &m, const T &t) { MATH_EXC_ON; return m * t; } template static Matrix44 rmul44T(Matrix44 &m, const T &t) { MATH_EXC_ON; return t * m; } template static const Matrix44 & idiv44T(Matrix44 &m, const T &t) { MATH_EXC_ON; return m /= t; } template static Matrix44 div44T(Matrix44 &m, const T &t) { MATH_EXC_ON; return m / t; } template static void extractAndRemoveScalingAndShear44(Matrix44 &mat, Vec3 &dstScl, Vec3 &dstShr, int exc = 1) { MATH_EXC_ON; IMATH_NAMESPACE::extractAndRemoveScalingAndShear(mat, dstScl, dstShr, exc); } template static void extractEulerXYZ(Matrix44 &mat, IMATH_NAMESPACE::Vec3 &dst) { MATH_EXC_ON; IMATH_NAMESPACE::extractEulerXYZ(mat, dst); } template static void extractEulerZYX(Matrix44 &mat, IMATH_NAMESPACE::Vec3 &dst) { MATH_EXC_ON; IMATH_NAMESPACE::extractEulerZYX(mat, dst); } template static int extractSHRT44(Matrix44 &mat, Vec3 &s, Vec3 &h, Vec3 &r, Vec3 &t, int exc = 1) { MATH_EXC_ON; return IMATH_NAMESPACE::extractSHRT(mat, s, h, r, t, exc); } template static void extractScaling44(Matrix44 &mat, Vec3 &dst, int exc = 1) { MATH_EXC_ON; IMATH_NAMESPACE::extractScaling(mat, dst, exc); } template static void extractScalingAndShear44(Matrix44 &mat, Vec3 &dstScl, Vec3 &dstShr, int exc = 1) { MATH_EXC_ON; IMATH_NAMESPACE::extractScalingAndShear(mat, dstScl, dstShr, exc); } template static void multDirMatrix44(Matrix44 &mat, const Vec3 &src, Vec3 &dst) { MATH_EXC_ON; mat.multDirMatrix(src, dst); } template static Vec3 multDirMatrix44_return_value(Matrix44 &mat, const Vec3 &src) { MATH_EXC_ON; Vec3 dst; mat.multDirMatrix(src, dst); return dst; } template struct op_multDirMatrix { static inline void apply(const Matrix44& m, const Vec3& src, Vec3& dst) { m.multDirMatrix(src,dst); } }; template struct op_multVecMatrix { static inline void apply(const Matrix44& m, const Vec3& src, Vec3& dst) { m.multVecMatrix(src,dst); } }; template struct MatrixVecTask : public Task { const Matrix44 &mat; const FixedArray >& src; FixedArray >& dst; MatrixVecTask(const Matrix44 &m, const FixedArray >& s, FixedArray >& d) : mat(m), src(s), dst(d) {} void execute(size_t start, size_t end) { for(size_t p = start; p < end; ++p) Op::apply(mat,src[p],dst[p]); } }; template static FixedArray > multDirMatrix44_array(Matrix44 &mat, const FixedArray >&src) { MATH_EXC_ON; size_t len = src.len(); FixedArray > dst(len); MatrixVecTask > task(mat,src,dst); dispatchTask(task,len); return dst; } template static void multVecMatrix44(Matrix44 &mat, const Vec3 &src, Vec3 &dst) { MATH_EXC_ON; mat.multVecMatrix(src, dst); } template static Vec3 multVecMatrix44_return_value(Matrix44 &mat, const Vec3 &src) { MATH_EXC_ON; Vec3 dst; mat.multVecMatrix(src, dst); return dst; } template static FixedArray > multVecMatrix44_array(Matrix44 &mat, const FixedArray >&src) { MATH_EXC_ON; size_t len = src.len(); FixedArray > dst(len); MatrixVecTask > task(mat,src,dst); dispatchTask(task,len); return dst; } template static int removeScaling44(Matrix44 &mat, int exc = 1) { MATH_EXC_ON; return IMATH_NAMESPACE::removeScaling(mat, exc); } template static int removeScalingAndShear44(Matrix44 &mat, int exc = 1) { MATH_EXC_ON; return IMATH_NAMESPACE::removeScalingAndShear(mat, exc); } template static Matrix44 sansScaling44(const Matrix44 &mat, bool exc = true) { MATH_EXC_ON; return IMATH_NAMESPACE::sansScaling(mat, exc); } template static Matrix44 sansScalingAndShear44(const Matrix44 &mat, bool exc = true) { MATH_EXC_ON; return IMATH_NAMESPACE::sansScalingAndShear(mat, exc); } template static const Matrix44 & scaleSc44(Matrix44 &mat, const T &s) { MATH_EXC_ON; Vec3 sVec(s, s, s); return mat.scale(sVec); } template static const Matrix44 & scaleV44(Matrix44 &mat, const Vec3 &s) { MATH_EXC_ON; return mat.scale(s); } template static const Matrix44 & scale44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 s; s.x = extract(t[0]); s.y = extract(t[1]); s.z = extract(t[2]); return mat.scale(s); } else THROW(IEX_NAMESPACE::LogicExc, "m.scale needs tuple of length 3"); } template static const Matrix44 & rotateV44(Matrix44 &mat, const Vec3 &r) { MATH_EXC_ON; return mat.rotate(r); } template static const Matrix44 & rotationMatrix44(Matrix44 &mat, const object &fromObj, const object &toObj) { MATH_EXC_ON; Vec3 from, to; if (PyImath::V3::convert (fromObj.ptr(), &from) && PyImath::V3::convert (toObj.ptr(), &to)) { Matrix44 rot = IMATH_NAMESPACE::rotationMatrix(from, to); return mat.setValue(rot); } else { THROW(IEX_NAMESPACE::ArgExc, "m.rotationMatrix expected V3 arguments"); } } template static const Matrix44 & rotationMatrixWithUp44(Matrix44 &mat, const object &fromObj, const object &toObj, const object &upObj) { MATH_EXC_ON; Vec3 from, to, up; if (PyImath::V3::convert (fromObj.ptr(), &from) && PyImath::V3::convert (toObj.ptr(), &to) & PyImath::V3::convert (upObj.ptr(), &up)) { Matrix44 rot = IMATH_NAMESPACE::rotationMatrixWithUpDir(from, to, up); return mat.setValue(rot); } else { THROW(IEX_NAMESPACE::ArgExc, "m.rotationMatrix expected V3 arguments"); } } template static const Matrix44 & setScaleSc44(Matrix44 &mat, const T &s) { MATH_EXC_ON; Vec3 sVec(s, s, s); return mat.setScale(sVec); } template static const Matrix44 & setScaleV44(Matrix44 &mat, const Vec3 &s) { MATH_EXC_ON; return mat.setScale(s); } template static const Matrix44 & setScale44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 s; s.x = extract(t[0]); s.y = extract(t[1]); s.z = extract(t[2]); return mat.setScale(s); } else THROW(IEX_NAMESPACE::LogicExc, "m.translate needs tuple of length 3"); } template static const Matrix44 & setShearV44(Matrix44 &mat, const Vec3 &sVec) { MATH_EXC_ON; IMATH_NAMESPACE::Shear6 shear(sVec[0], sVec[1], sVec[2], T (0), T (0), T (0)); return mat.setShear(shear); } template static const Matrix44 & setShearS44(Matrix44 &mat, const Shear6 &s) { MATH_EXC_ON; return mat.setShear(s); } template static const Matrix44 & setShear44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 s; s.x = extract(t[0]); s.y = extract(t[1]); s.z = extract(t[2]); Shear6 shear(s); return mat.setShear(shear); } else if(t.attr("__len__")() == 6) { Shear6 shear; for(int i = 0; i < 6; ++i) { shear[i] = extract(t[i]); } return mat.setShear(shear); } else THROW(IEX_NAMESPACE::LogicExc, "m.setShear needs tuple of length 3 or 6"); } template static const Matrix44 & setTranslation44(Matrix44 &mat, const Vec3 t) { MATH_EXC_ON; return mat.setTranslation(t); } template static const Matrix44 & setTranslation44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 trans; trans.x = extract(t[0]); trans.y = extract(t[1]); trans.z = extract(t[2]); return mat.setTranslation(trans); } else THROW(IEX_NAMESPACE::LogicExc, "m.translate needs tuple of length 3"); } template static const Matrix44 & setTranslation44Obj(Matrix44 &mat, const object &o) { MATH_EXC_ON; Vec3 v; if (PyImath::V3::convert (o.ptr(), &v)) { return mat.setTranslation(v); } else { THROW(IEX_NAMESPACE::ArgExc, "m.setTranslation expected V3 argument"); return mat; } } template static void setValue44(Matrix44 &mat, const Matrix44 &value) { MATH_EXC_ON; mat.setValue(value); } template static const Matrix44 & shearV44(Matrix44 &mat, const Vec3 &s) { MATH_EXC_ON; IMATH_NAMESPACE::Shear6 shear(s[0], s[1], s[2], T (0), T (0), T (0)); return mat.shear(shear); } template static const Matrix44 & shearS44(Matrix44 &mat, const Shear6 &s) { MATH_EXC_ON; return mat.shear(s); } template static const Matrix44 & shear44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 s; s.x = extract(t[0]); s.y = extract(t[1]); s.z = extract(t[2]); Shear6 shear(s); return mat.shear(shear); } else if(t.attr("__len__")() == 6) { Shear6 shear; for(int i = 0; i < 6; ++i) { shear[i] = extract(t[i]); } return mat.shear(shear); } else THROW(IEX_NAMESPACE::LogicExc, "m.shear needs tuple of length 3 or 6"); } template static const Matrix44 & translate44(Matrix44 &mat, const object &t) { MATH_EXC_ON; Vec3 v; if (PyImath::V3::convert (t.ptr(), &v)) { return mat.translate(v); } else { THROW(IEX_NAMESPACE::ArgExc, "m.translate expected V3 argument"); return mat; } } template static const Matrix44 & translate44Tuple(Matrix44 &mat, const tuple &t) { MATH_EXC_ON; if(t.attr("__len__")() == 3) { Vec3 trans; trans.x = extract(t[0]); trans.y = extract(t[1]); trans.z = extract(t[2]); return mat.translate(trans); } else THROW(IEX_NAMESPACE::LogicExc, "m.translate needs tuple of length 3"); } template static Matrix44 subtractTL44(Matrix44 &mat, T a) { MATH_EXC_ON; Matrix44 m(mat.x); for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) m.x[i][j] -= a; return m; } template static Matrix44 subtractTR44(Matrix44 &mat, T a) { MATH_EXC_ON; Matrix44 m(mat.x); for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) m.x[i][j] = a - m.x[i][j]; return m; } template static Matrix44 add44T(Matrix44 &mat, T a) { MATH_EXC_ON; Matrix44 m(mat.x); for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) m.x[i][j] += a; return m; } template static Matrix44 mul44(Matrix44 &mat1, Matrix44 &mat2) { MATH_EXC_ON; Matrix44 mat2T; mat2T.setValue (mat2); return mat1 * mat2T; } template static Matrix44 rmul44(Matrix44 &mat2, Matrix44 &mat1) { MATH_EXC_ON; Matrix44 mat1T; mat1T.setValue (mat1); return mat1T * mat2; } template static const Matrix44 & imul44(Matrix44 &mat1, Matrix44 &mat2) { MATH_EXC_ON; Matrix44 mat2T; mat2T.setValue (mat2); return mat1 *= mat2T; } template static bool lessThan44(Matrix44 &mat1, const Matrix44 &mat2) { for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ if(mat1[i][j] > mat2[i][j]){ return false; } } } return (mat1 != mat2); } template static bool lessThanEqual44(Matrix44 &mat1, const Matrix44 &mat2) { for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ if(mat1[i][j] > mat2[i][j]){ return false; } } } return true; } template static bool greaterThan44(Matrix44 &mat1, const Matrix44 &mat2) { for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ if(mat1[i][j] < mat2[i][j]){ return false; } } } return (mat1 != mat2); } template static bool greaterThanEqual44(Matrix44 &mat1, const Matrix44 &mat2) { for(int i = 0; i < 4; ++i){ for(int j = 0; j < 4; ++j){ if(mat1[i][j] < mat2[i][j]){ return false; } } } return true; } template static tuple singularValueDecomposition44(const Matrix44& m, bool forcePositiveDeterminant = false) { IMATH_NAMESPACE::Matrix44 U, V; IMATH_NAMESPACE::Vec4 S; IMATH_NAMESPACE::jacobiSVD (m, U, S, V, IMATH_NAMESPACE::limits::epsilon(), forcePositiveDeterminant); return make_tuple (U, S, V); } BOOST_PYTHON_FUNCTION_OVERLOADS(invert44_overloads, invert44, 1, 2); BOOST_PYTHON_FUNCTION_OVERLOADS(inverse44_overloads, inverse44, 1, 2); BOOST_PYTHON_FUNCTION_OVERLOADS(gjInvert44_overloads, gjInvert44, 1, 2); BOOST_PYTHON_FUNCTION_OVERLOADS(gjInverse44_overloads, gjInverse44, 1, 2); BOOST_PYTHON_FUNCTION_OVERLOADS(extractAndRemoveScalingAndShear44_overloads, extractAndRemoveScalingAndShear44, 3, 4) BOOST_PYTHON_FUNCTION_OVERLOADS(extractSHRT44_overloads, extractSHRT44, 5, 6) BOOST_PYTHON_FUNCTION_OVERLOADS(extractScaling44_overloads, extractScaling44, 2, 3) BOOST_PYTHON_FUNCTION_OVERLOADS(extractScalingAndShear44_overloads, extractScalingAndShear44, 3, 4) BOOST_PYTHON_FUNCTION_OVERLOADS(removeScaling44_overloads, removeScaling44, 1, 2) BOOST_PYTHON_FUNCTION_OVERLOADS(removeScalingAndShear44_overloads, removeScalingAndShear44, 1, 2) BOOST_PYTHON_FUNCTION_OVERLOADS(sansScaling44_overloads, sansScaling44, 1, 2) BOOST_PYTHON_FUNCTION_OVERLOADS(sansScalingAndShear44_overloads, sansScalingAndShear44, 1, 2) template static Matrix44 * Matrix4_tuple_constructor(const tuple &t0, const tuple &t1, const tuple &t2, const tuple &t3) { if(t0.attr("__len__")() == 4 && t1.attr("__len__")() == 4 && t2.attr("__len__")() == 4 && t3.attr("__len__")() == 4) { return new Matrix44(extract(t0[0]), extract(t0[1]), extract(t0[2]), extract(t0[3]), extract(t1[0]), extract(t1[1]), extract(t1[2]), extract(t1[3]), extract(t2[0]), extract(t2[1]), extract(t2[2]), extract(t2[3]), extract(t3[0]), extract(t3[1]), extract(t3[2]), extract(t3[3])); } else THROW(IEX_NAMESPACE::LogicExc, "Matrix44 takes 4 tuples of length 4"); } template static Matrix44 *Matrix4_matrix_constructor(const Matrix44 &mat) { Matrix44 *m = new Matrix44; for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) m->x[i][j] = T (mat.x[i][j]); return m; } template class_ > register_Matrix44() { typedef PyImath::StaticFixedArray,T,4,IndexAccessMatrixRow,T,4> > Matrix44_helper; MatrixRow::register_class(); class_ > matrix44_class(Matrix44Name::value, Matrix44Name::value,init >("copy construction")); matrix44_class .def(init<>("initialize to identity")) .def(init("initialize all entries to a single value")) .def("__init__", make_constructor(Matrix4_tuple_constructor),"tuple constructor1") .def("__init__", make_constructor(Matrix4_matrix_constructor)) .def("__init__", make_constructor(Matrix4_matrix_constructor)) .def(init("make from components")) //.def_readwrite("x00", &Matrix44::x[0][0]) //.def_readwrite("x01", &Matrix44::x[0][1]) //.def_readwrite("x02", &Matrix44::x[0][2]) //.def_readwrite("x03", &Matrix44::x[0][3]) //.def_readwrite("x10", &Matrix44::x[1][0]) //.def_readwrite("x11", &Matrix44::x[1][1]) //.def_readwrite("x12", &Matrix44::x[1][2]) //.def_readwrite("x13", &Matrix44::x[1][3]) //.def_readwrite("x20", &Matrix44::x[2][0]) //.def_readwrite("x21", &Matrix44::x[2][1]) //.def_readwrite("x22", &Matrix44::x[2][2]) //.def_readwrite("x23", &Matrix44::x[2][3]) //.def_readwrite("x30", &Matrix44::x[3][0]) //.def_readwrite("x31", &Matrix44::x[3][1]) //.def_readwrite("x32", &Matrix44::x[3][2]) //.def_readwrite("x33", &Matrix44::x[3][3]) .def("baseTypeEpsilon", &Matrix44::baseTypeEpsilon,"baseTypeEpsilon() epsilon value of the base type of the vector") .staticmethod("baseTypeEpsilon") .def("baseTypeMax", &Matrix44::baseTypeMax,"baseTypeMax() max value of the base type of the vector") .staticmethod("baseTypeMax") .def("baseTypeMin", &Matrix44::baseTypeMin,"baseTypeMin() min value of the base type of the vector") .staticmethod("baseTypeMin") .def("baseTypeSmallest", &Matrix44::baseTypeSmallest,"baseTypeSmallest() smallest value of the base type of the vector") .staticmethod("baseTypeSmallest") .def("equalWithAbsError", &Matrix44::equalWithAbsError, "m1.equalWithAbsError(m2,e) true if the elements " "of v1 and v2 are the same with an absolute error of no more than e, " "i.e., abs(m1[i] - m2[i]) <= e") .def("equalWithRelError", &Matrix44::equalWithRelError, "m1.equalWithAbsError(m2,e) true if the elements " "of m1 and m2 are the same with an absolute error of no more than e, " "i.e., abs(m1[i] - m2[i]) <= e * abs(m1[i])") // need a different version for matrix data access .def("__len__", Matrix44_helper::len) .def("__getitem__", Matrix44_helper::getitem) //.def("__setitem__", Matrix44_helper::setitem) .def("makeIdentity",&Matrix44::makeIdentity,"makeIdentity() make this matrix the identity matrix") .def("transpose",&Matrix44::transpose,return_internal_reference<>(),"transpose() transpose this matrix") .def("transposed",&Matrix44::transposed,"transposed() return a transposed copy of this matrix") .def("minorOf",&Matrix44::minorOf,"minorOf() return matrix minor of the (row,col) element of this matrix") .def("fastMinor",&Matrix44::fastMinor,"fastMinor() return matrix minor using the specified rows and columns of this matrix") .def("determinant",&Matrix44::determinant,"determinant() return the determinant of this matrix") .def("invert",&invert44,invert44_overloads("invert() invert this matrix")[return_internal_reference<>()]) .def("inverse",&inverse44,inverse44_overloads("inverse() return a inverted copy of this matrix")) .def("gjInvert",&gjInvert44,gjInvert44_overloads("gjInvert() invert this matrix")[return_internal_reference<>()]) .def("gjInverse",&gjInverse44,gjInverse44_overloads("gjInverse() return a inverted copy of this matrix")) .def(self == self) .def(self != self) .def("__iadd__", &iadd44,return_internal_reference<>()) .def("__iadd__", &iadd44,return_internal_reference<>()) .def("__iadd__", &iadd44T,return_internal_reference<>()) .def("__add__", &add44) .def("__isub__", &isub44,return_internal_reference<>()) .def("__isub__", &isub44,return_internal_reference<>()) .def("__isub__", &isub44T,return_internal_reference<>()) .def("__sub__", &sub44) .def("negate",&negate44,return_internal_reference<>(),"negate() negate all entries in this matrix") .def("__neg__", &neg44) .def("__imul__", &imul44T,return_internal_reference<>()) .def("__mul__", &mul44T) .def("__rmul__", &rmul44T) .def("__idiv__", &idiv44T,return_internal_reference<>()) .def("__itruediv__", &idiv44T,return_internal_reference<>()) .def("__div__", &div44T) .def("__truediv__", &div44T) .def("__add__", &add44T) .def("__radd__", &add44T) .def("__sub__", &subtractTL44) .def("__rsub__", &subtractTR44) .def("__mul__", &mul44) .def("__mul__", &mul44) .def("__rmul__", &rmul44) .def("__rmul__", &rmul44) .def("__imul__", &imul44,return_internal_reference<>()) .def("__imul__", &imul44,return_internal_reference<>()) .def("__lt__", &lessThan44) .def("__gt__", &greaterThan44) .def("__le__", &lessThanEqual44) .def("__ge__", &greaterThanEqual44) //.def(self_ns::str(self)) .def("__repr__",&Matrix44_repr) .def("extractAndRemoveScalingAndShear", &extractAndRemoveScalingAndShear44, extractAndRemoveScalingAndShear44_overloads( "M.extractAndRemoveScalingAndShear(scl, shr, " "[exc]) -- extracts the scaling component of " "M into scl and the shearing component of M " "into shr. Also removes the scaling and " "shearing components from M. " "Returns 1 unless the scaling component is " "nearly 0, in which case 0 is returned. " "If optional arg. exc == 1, then if the " "scaling component is nearly 0, then MathExc " "is thrown.")) .def("extractEulerXYZ", &extractEulerXYZ, "extract Euler") .def("extractEulerZYX", &extractEulerZYX, "extract Euler") .def("extractSHRT", &extractSHRT44, extractSHRT44_overloads( "M.extractSHRT(Vs, Vh, Vr, Vt, [exc]) -- " "extracts the scaling component of M into Vs, " "the shearing component of M in Vh (as XY, " "XZ, YZ shear factors), the rotation of M " "into Vr (as Euler angles in the order XYZ), " "and the translaation of M into Vt. " "If optional arg. exc == 1, then if the " "scaling component is nearly 0, then MathExc " "is thrown. ")) .def("extractScaling", &extractScaling44, extractScaling44_overloads("extract scaling")) .def("extractScalingAndShear", &extractScalingAndShear44, extractScalingAndShear44_overloads("extract scaling")) .def("singularValueDecomposition", &singularValueDecomposition44, "Decomposes the matrix using the singular value decomposition (SVD) into three\n" "matrices U, S, and V which have the following properties: \n" " 1. U and V are both orthonormal matrices, \n" " 2. S is the diagonal matrix of singular values, \n" " 3. U * S * V.transposed() gives back the original matrix.\n" "The result is returned as a tuple [U, S, V]. Note that since S is diagonal we\n" "don't need to return the entire matrix, so we return it as a three-vector. \n" "\n" "The 'forcePositiveDeterminant' argument can be used to force the U and V^T to\n" "have positive determinant (that is, to be proper rotation matrices); if\n" "forcePositiveDeterminant is False, then the singular values are guaranteed to\n" "be nonnegative but the U and V matrices might contain negative scale along one\n" "of the axes; if forcePositiveDeterminant is True, then U and V cannot contain\n" "negative scale but S[3] might be negative. \n" "\n" "Our SVD implementation uses two-sided Jacobi rotations to iteratively\n" "diagonalize the matrix, which should be quite robust and significantly faster\n" "than the more general SVD solver in LAPACK. \n", args("matrix", "forcePositiveDeterminant")) .def("symmetricEigensolve", &PyImath::jacobiEigensolve >, "Decomposes the matrix A using a symmetric eigensolver into matrices Q and S \n" "which have the following properties: \n" " 1. Q is the orthonormal matrix of eigenvectors, \n" " 2. S is the diagonal matrix of eigenvalues, \n" " 3. Q.transposed() * S * Q gives back the original matrix.\n" "\n" "IMPORTANT: It is vital that the passed-in matrix be symmetric, or the result \n" "won't make any sense. This function will return an error if passed an \n" "unsymmetric matrix.\n" "\n" "The result is returned as a tuple [Q, S]. Note that since S is diagonal \n" "we don't need to return the entire matrix, so we return it as a three-vector. \n" "\n" "Our eigensolver implementation uses one-sided Jacobi rotations to iteratively \n" "diagonalize the matrix, which should be quite robust and significantly faster \n" "than the more general symmetric eigenvalue solver in LAPACK. \n") .def("multDirMatrix", &multDirMatrix44, "mult matrix") .def("multDirMatrix", &multDirMatrix44_return_value, "mult matrix") .def("multDirMatrix", &multDirMatrix44_array, "mult matrix") .def("multDirMatrix", &multDirMatrix44, "mult matrix") .def("multDirMatrix", &multDirMatrix44_return_value, "mult matrix") .def("multDirMatrix", &multDirMatrix44_array, "mult matrix") .def("multVecMatrix", &multVecMatrix44, "mult matrix") .def("multVecMatrix", &multVecMatrix44_return_value, "mult matrix") .def("multVecMatrix", &multVecMatrix44_array, "mult matrix") .def("multVecMatrix", &multVecMatrix44, "mult matrix") .def("multVecMatrix", &multVecMatrix44_return_value, "mult matrix") .def("multVecMatrix", &multVecMatrix44_array, "mult matrix") .def("removeScaling", &removeScaling44, removeScaling44_overloads("remove scaling")) .def("removeScalingAndShear", &removeScalingAndShear44, removeScalingAndShear44_overloads("remove scaling")) .def("sansScaling", &sansScaling44, sansScaling44_overloads("sans scaling")) .def("sansScalingAndShear", &sansScalingAndShear44, sansScalingAndShear44_overloads("sans scaling and shear")) .def("scale", &scaleSc44, return_internal_reference<>(), "scale matrix") .def("scale", &scaleV44, return_internal_reference<>(), "scale matrix") .def("scale", &scale44Tuple, return_internal_reference<>(), "scale matrix") .def("rotate", &rotateV44, return_internal_reference<>(), "rotate matrix") .def("rotationMatrix", &rotationMatrix44, return_internal_reference<>(), "rotationMatrix()") .def("rotationMatrixWithUpDir", &rotationMatrixWithUp44, return_internal_reference<>(), "roationMatrixWithUp()") .def("setScale", &setScaleSc44, return_internal_reference<>(),"setScale()") .def("setScale", &setScaleV44, return_internal_reference<>(),"setScale()") .def("setScale", &setScale44Tuple, return_internal_reference<>(),"setScale()") .def("setShear", &setShearV44, return_internal_reference<>(),"setShear()") .def("setShear", &setShearS44, return_internal_reference<>(),"setShear()") .def("setShear", &setShear44Tuple, return_internal_reference<>(),"setShear()") .def("setTranslation", &setTranslation44, return_internal_reference<>(),"setTranslation()") .def("setTranslation", &setTranslation44Tuple, return_internal_reference<>(),"setTranslation()") .def("setTranslation", &setTranslation44Obj, return_internal_reference<>(),"setTranslation()") .def("setValue", &setValue44, "setValue()") .def("shear", &shearV44, return_internal_reference<>(),"shear()") .def("shear", &shearS44, return_internal_reference<>(),"shear()") .def("shear", &shear44Tuple, return_internal_reference<>(),"shear()") .def("translate", &translate44, return_internal_reference<>(),"translate()") .def("translate", &translate44Tuple, return_internal_reference<>(),"translate()") .def("translation", &Matrix44::translation, "translation()") ; decoratecopy(matrix44_class); return matrix44_class; /* const Matrix44 & operator = (const Matrix44 &v); const Matrix44 & operator = (T a); T * getValue (); const T * getValue () const; template void getValue (Matrix44 &v) const; template Matrix44 & setValue (const Matrix44 &v); template Matrix44 & setTheMatrix (const Matrix44 &v); template void multVecMatrix(const Vec2 &src, Vec2 &dst) const; template void multDirMatrix(const Vec2 &src, Vec2 &dst) const; template const Matrix44 & setRotation (S r); template const Matrix44 & rotate (S r); const Matrix44 & setScale (T s); template const Matrix44 & setScale (const Vec2 &s); template const Matrix44 & scale (const Vec2 &s); template const Matrix44 & setTranslation (const Vec2 &t); Vec2 translation () const; template const Matrix44 & translate (const Vec2 &t); template const Matrix44 & setShear (const S &h); template const Matrix44 & setShear (const Vec2 &h); template const Matrix44 & shear (const S &xy); template const Matrix44 & shear (const Vec2 &h); */ } template static void setM44ArrayItem(FixedArray > &ma, Py_ssize_t index, const IMATH_NAMESPACE::Matrix44 &m) { ma[ma.canonical_index(index)] = m; } template class_ > > register_M44Array() { class_ > > matrixArray_class = FixedArray >::register_("Fixed length array of IMATH_NAMESPACE::Matrix44"); matrixArray_class .def("__setitem__", &setM44ArrayItem) ; return matrixArray_class; } template PYIMATH_EXPORT class_ > register_Matrix44(); template PYIMATH_EXPORT class_ > register_Matrix44(); template PYIMATH_EXPORT class_ > > register_M44Array(); template PYIMATH_EXPORT class_ > > register_M44Array(); template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix44 FixedArrayDefaultValue >::value() { return IMATH_NAMESPACE::Matrix44(); } template<> PYIMATH_EXPORT IMATH_NAMESPACE::Matrix44 FixedArrayDefaultValue >::value() { return IMATH_NAMESPACE::Matrix44(); } }