HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathShear.h
Go to the documentation of this file.
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 HBOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <hboost/python.hpp>
14 #include <ImathShear.h>
15 
16 
17 namespace PyImath {
18 
19 template <class T> hboost::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 hboost::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  hboost::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  hboost::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  hboost::python::extract <hboost::python::tuple> extractorTuple (p);
71  if (extractorTuple.check())
72  {
73  hboost::python::tuple t = extractorTuple();
74  if (t.attr ("__len__") () == 3)
75  {
76  double xy = hboost::python::extract <double> (t[0]);
77  double xz = hboost::python::extract <double> (t[1]);
78  double yz = hboost::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 = hboost::python::extract <double> (t[0]);
86  double xz = hboost::python::extract <double> (t[1]);
87  double yz = hboost::python::extract <double> (t[2]);
88  double yx = hboost::python::extract <double> (t[3]);
89  double zx = hboost::python::extract <double> (t[4]);
90  double zy = hboost::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  hboost::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  hboost::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  hboost::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 
125 
126 }
127 
128 #endif
static int convert(PyObject *p, IMATH_NAMESPACE::Shear6< T > *s)
Definition: PyImathShear.h:48
Vec3< int > V3i
Vec3 of integer.
Definition: ImathVec.h:1058
S6< float > Shear6f
Definition: PyImathShear.h:123
GLdouble s
Definition: glad.h:3009
static PyObject * wrap(const IMATH_NAMESPACE::Shear6< T > &s)
Definition: PyImathShear.h:39
Vec3< double > V3d
Vec3 of double.
Definition: ImathVec.h:1067
Shear6< float > Shear6f
Shear6 of type float.
Definition: ImathShear.h:334
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GLdouble t
Definition: glad.h:2397
Vec3< float > V3f
Vec3 of float.
Definition: ImathVec.h:1064
Shear6< double > Shear6d
Shear6 of type double.
Definition: ImathShear.h:337
S6< double > Shear6d
Definition: PyImathShear.h:124
hboost::python::class_< IMATH_NAMESPACE::Shear6< T > > register_Shear()