| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
// clang-format off |
| 7 |
|
| 8 |
#ifndef _PyImathShear_h_ |
| 9 |
#define _PyImathShear_h_ |
| 10 |
|
| 11 |
#include <Python.h> |
| 12 |
#define BOOST_BIND_GLOBAL_PLACEHOLDERS |
| 13 |
#include <boost/python.hpp> |
| 14 |
#include <ImathShear.h> |
| 15 |
|
| 16 |
|
| 17 |
namespace PyImath { |
| 18 |
|
| 19 |
template <class T> boost::python::class_<IMATH_NAMESPACE::Shear6<T> > register_Shear(); |
| 20 |
|
| 21 |
// |
| 22 |
|
| 23 |
// Other code in the Zeno code base assumes the existance of a class with the |
| 24 |
// same name as the Imath class, and with static functions wrap() and |
| 25 |
// convert() to produce a PyImath object from an Imath object and vice-versa, |
| 26 |
// respectively. The class Boost generates from the Imath class does not |
| 27 |
// have these properties, so we define a companion class here. |
| 28 |
// The template argument, T, is the element type (e.g.,float, double). |
| 29 |
|
| 30 |
template <class T> |
| 31 |
class S6 { |
| 32 |
public: |
| 33 |
static PyObject * wrap (const IMATH_NAMESPACE::Shear6<T> &s); |
| 34 |
static int convert (PyObject *p, IMATH_NAMESPACE::Shear6<T> *s); |
| 35 |
}; |
| 36 |
|
| 37 |
template <class T> |
| 38 |
PyObject * |
| 39 |
S6<T>::wrap (const IMATH_NAMESPACE::Shear6<T> &s) |
| 40 |
{ |
| 41 |
typename boost::python::return_by_value::apply < IMATH_NAMESPACE::Shear6<T> >::type converter; |
| 42 |
PyObject *p = converter (s); |
| 43 |
return p; |
| 44 |
} |
| 45 |
|
| 46 |
template <class T> |
| 47 |
int |
| 48 |
S6<T>::convert (PyObject *p, IMATH_NAMESPACE::Shear6<T> *s) |
| 49 |
{ |
| 50 |
boost::python::extract <IMATH_NAMESPACE::Shear6f> extractorShear6f (p); |
| 51 |
if (extractorShear6f.check()) |
| 52 |
{ |
| 53 |
IMATH_NAMESPACE::Shear6f s6f = extractorShear6f(); |
| 54 |
float xy, xz, yz, yx, zx, zy; |
| 55 |
s6f.getValue (xy, xz, yz, yx, zx, zy); |
| 56 |
s->setValue(T(xy), T(xz), T(yz), T(yx), T(zx), T(zy)); |
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
boost::python::extract <IMATH_NAMESPACE::Shear6d> extractorShear6d (p); |
| 61 |
if (extractorShear6d.check()) |
| 62 |
{ |
| 63 |
IMATH_NAMESPACE::Shear6d s6d = extractorShear6d(); |
| 64 |
double xy, xz, yz, yx, zx, zy; |
| 65 |
s6d.getValue (xy, xz, yz, yx, zx, zy); |
| 66 |
s->setValue(T(xy), T(xz), T(yz), T(yx), T(zx), T(zy)); |
| 67 |
return 1; |
| 68 |
} |
| 69 |
|
| 70 |
boost::python::extract <boost::python::tuple> extractorTuple (p); |
| 71 |
if (extractorTuple.check()) |
| 72 |
{ |
| 73 |
boost::python::tuple t = extractorTuple(); |
| 74 |
if (t.attr ("__len__") () == 3) |
| 75 |
{ |
| 76 |
double xy = boost::python::extract <double> (t[0]); |
| 77 |
double xz = boost::python::extract <double> (t[1]); |
| 78 |
double yz = boost::python::extract <double> (t[2]); |
| 79 |
s->setValue (T(xy), T(xz), T(yz), T(0), T(0), T(0)); |
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
else if (t.attr ("__len__") () == 6) |
| 84 |
{ |
| 85 |
double xy = boost::python::extract <double> (t[0]); |
| 86 |
double xz = boost::python::extract <double> (t[1]); |
| 87 |
double yz = boost::python::extract <double> (t[2]); |
| 88 |
double yx = boost::python::extract <double> (t[3]); |
| 89 |
double zx = boost::python::extract <double> (t[4]); |
| 90 |
double zy = boost::python::extract <double> (t[5]); |
| 91 |
s->setValue (T(xy), T(xz), T(yz), T(yx), T(zx), T(zy)); |
| 92 |
return 1; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
boost::python::extract <IMATH_NAMESPACE::V3i> extractorV3i (p); |
| 97 |
if (extractorV3i.check()) |
| 98 |
{ |
| 99 |
IMATH_NAMESPACE::V3i v3i = extractorV3i(); |
| 100 |
s->setValue (T(v3i[0]), T(v3i[1]), T(v3i[2]), T(0), T(0), T(0)); |
| 101 |
return 1; |
| 102 |
} |
| 103 |
|
| 104 |
boost::python::extract <IMATH_NAMESPACE::V3f> extractorV3f (p); |
| 105 |
if (extractorV3f.check()) |
| 106 |
{ |
| 107 |
IMATH_NAMESPACE::V3f v3f = extractorV3f(); |
| 108 |
s->setValue (T(v3f[0]), T(v3f[1]), T(v3f[2]), T(0), T(0), T(0)); |
| 109 |
return 1; |
| 110 |
} |
| 111 |
|
| 112 |
boost::python::extract <IMATH_NAMESPACE::V3d> extractorV3d (p); |
| 113 |
if (extractorV3d.check()) |
| 114 |
{ |
| 115 |
IMATH_NAMESPACE::V3d v3d = extractorV3d(); |
| 116 |
s->setValue (T(v3d[0]), T(v3d[1]), T(v3d[2]), T(0), T(0), T(0)); |
| 117 |
return 1; |
| 118 |
} |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
typedef S6<float> Shear6f; |
| 124 |
typedef S6<double> Shear6d; |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
#endif |