Skip to content

Commit

Permalink
Implemented all tests transferable to the 2x2 matrix case from 3x3. A…
Browse files Browse the repository at this point in the history
…dded needed functionality to ensure boost::python worked for testing.

Signed-off-by: Owen Thompson <oxt3479@rit.edu>
  • Loading branch information
oxt3479 authored and cary-ilm committed Apr 17, 2020
1 parent b70eabd commit cfc9d85
Show file tree
Hide file tree
Showing 6 changed files with 1,227 additions and 8 deletions.
1 change: 1 addition & 0 deletions PyIlmBase/PyImath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pyilmbase_define_module(imath
PyImathFixedArray.cpp
PyImathFrustum.cpp
PyImathLine.cpp
PyImathMatrix22.cpp
PyImathMatrix33.cpp
PyImathMatrix44.cpp
PyImathPlane.cpp
Expand Down
45 changes: 45 additions & 0 deletions PyIlmBase/PyImath/PyImathMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@

namespace PyImath {

template <class T> boost::python::class_<IMATH_NAMESPACE::Matrix22<T> > register_Matrix22();
template <class T> boost::python::class_<IMATH_NAMESPACE::Matrix33<T> > register_Matrix33();
template <class T> boost::python::class_<IMATH_NAMESPACE::Matrix44<T> > register_Matrix44();
template <class T> boost::python::class_<FixedArray<IMATH_NAMESPACE::Matrix44<T> > > register_M44Array();
template <class T> boost::python::class_<FixedArray<IMATH_NAMESPACE::Matrix33<T> > > register_M33Array();
template <class T> boost::python::class_<FixedArray<IMATH_NAMESPACE::Matrix22<T> > > register_M22Array();
typedef FixedArray<IMATH_NAMESPACE::Matrix22<float> > M22fArray;
typedef FixedArray<IMATH_NAMESPACE::Matrix22<double> > M22dArray;
typedef FixedArray<IMATH_NAMESPACE::Matrix33<float> > M33fArray;
typedef FixedArray<IMATH_NAMESPACE::Matrix33<double> > M33dArray;
typedef FixedArray<IMATH_NAMESPACE::Matrix44<float> > M44fArray;
Expand All @@ -61,6 +65,13 @@ typedef FixedArray<IMATH_NAMESPACE::Matrix44<double> > M44dArray;
// have these properties, so we define a companion class here.
// The template argument, T, is the element type (e.g.,float, double).

template <class T>
class M22 {
public:
static PyObject * wrap (const IMATH_NAMESPACE::Matrix22<T> &m);
static int convert (PyObject *p, IMATH_NAMESPACE::Matrix22<T> *m);
};

template <class T>
class M33 {
public:
Expand All @@ -75,6 +86,15 @@ class M44 {
static int convert (PyObject *p, IMATH_NAMESPACE::Matrix44<T> *m);
};

template <class T>
PyObject *
M22<T>::wrap (const IMATH_NAMESPACE::Matrix22<T> &m)
{
typename boost::python::return_by_value::apply < IMATH_NAMESPACE::Matrix22<T> >::type converter;
PyObject *p = converter (m);
return p;
}

template <class T>
PyObject *
M33<T>::wrap (const IMATH_NAMESPACE::Matrix33<T> &m)
Expand All @@ -93,6 +113,29 @@ M44<T>::wrap (const IMATH_NAMESPACE::Matrix44<T> &m)
return p;
}

template <class T>
int
M22<T>::convert (PyObject *p, IMATH_NAMESPACE::Matrix22<T> *m)
{
boost::python::extract <IMATH_NAMESPACE::M22f> extractorMf (p);
if (extractorMf.check())
{
IMATH_NAMESPACE::M22f e = extractorMf();
m->setValue (e);
return 1;
}

boost::python::extract <IMATH_NAMESPACE::M22d> extractorMd (p);
if (extractorMd.check())
{
IMATH_NAMESPACE::M22d e = extractorMd();
m->setValue (e);
return 1;
}

return 0;
}

template <class T>
int
M33<T>::convert (PyObject *p, IMATH_NAMESPACE::Matrix33<T> *m)
Expand Down Expand Up @@ -174,6 +217,8 @@ jacobiEigensolve(const Matrix& m)
return boost::python::make_tuple (Q, S);
}

typedef M22<float> M22f;
typedef M22<double> M22d;

typedef M33<float> M33f;
typedef M33<double> M33d;
Expand Down

0 comments on commit cfc9d85

Please sign in to comment.