Debian Codegraph @

src/python/PyImath/PyImathEuler.h

raw
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
4 //
5
6 // clang-format off
7
8 #ifndef _PyImathEuler_h_
9 #define _PyImathEuler_h_
10
11 #include <Python.h>
12 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <boost/python.hpp>
14 #include <ImathEuler.h>
15 #include <ImathVec.h>
16 #include "PyImath.h"
17
18 namespace PyImath {
19
20 template <class T> boost::python::class_<IMATH_NAMESPACE::Euler<T>,boost::python::bases<IMATH_NAMESPACE::Vec3<T> > > register_Euler();
21 template <class T> boost::python::class_<PyImath::FixedArray<IMATH_NAMESPACE::Euler<T> > > register_EulerArray();
22 typedef FixedArray<IMATH_NAMESPACE::Eulerf> EulerfArray;
23 typedef FixedArray<IMATH_NAMESPACE::Eulerd> EulerdArray;
24
25 //
26
27 // Other code in the Zeno code base assumes the existance of a class with the
28 // same name as the Imath class, and with static functions wrap() and
29 // convert() to produce a PyImath object from an Imath object and vice-versa,
30 // respectively. The class Boost generates from the Imath class does not
31 // have these properties, so we define a companion class here.
32 // The template argument, T, is the element type for the axis vector
33 // (e.g.,float, double).
34
35 template <class T>
36 class E {
37 public:
38 static PyObject * wrap (const IMATH_NAMESPACE::Euler<T> &e);
39 static int convert (PyObject *p, IMATH_NAMESPACE::Euler<T> *v);
40 };
41
42 template <class T>
43 PyObject *
44 E<T>::wrap (const IMATH_NAMESPACE::Euler<T> &e)
45 {
46 typename boost::python::return_by_value::apply < IMATH_NAMESPACE::Euler<T> >::type converter;
47 PyObject *p = converter (e);
48 return p;
49 }
50
51 template <class T>
52 int
53 E<T>::convert (PyObject *p, IMATH_NAMESPACE::Euler<T> *v)
54 {
55 boost::python::extract <IMATH_NAMESPACE::Eulerf> extractorEf (p);
56 if (extractorEf.check())
57 {
58 IMATH_NAMESPACE::Eulerf e = extractorEf();
59 v->x = T(e.x);
60 v->y = T(e.y);
61 v->z = T(e.z);
62 v->setOrder (typename IMATH_NAMESPACE::Euler<T>::Order (e.order()));
63 return 1;
64 }
65
66 boost::python::extract <IMATH_NAMESPACE::Eulerd> extractorEd (p);
67 if (extractorEd.check())
68 {
69 IMATH_NAMESPACE::Eulerd e = extractorEd();
70 v->x = T(e.x);
71 v->y = T(e.y);
72 v->z = T(e.z);
73 v->setOrder (typename IMATH_NAMESPACE::Euler<T>::Order (e.order()));
74 return 1;
75 }
76
77 return 0;
78 }
79
80 typedef E<float> Eulerf;
81 typedef E<double> Eulerd;
82
83 }
84
85 #endif