Debian Codegraph @

src/python/PyImath/PyImathPlane.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 _PyImathPlane_h_
9 #define _PyImathPlane_h_
10
11 #include <Python.h>
12 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <boost/python.hpp>
14 #include <ImathPlane.h>
15 #include "PyImath.h"
16
17
18 namespace PyImath {
19
20 template <class T> boost::python::class_<IMATH_NAMESPACE::Plane3<T> > register_Plane();
21
22 //
23
24 // Other code in the Zeno code base assumes the existance of a class with the
25 // same name as the Imath class, and with static functions wrap() and
26 // convert() to produce a PyImath object from an Imath object and vice-versa,
27 // respectively. The class Boost generates from the Imath class does not
28 // have these properties, so we define a companion class here.
29 // The template argument, T, is the element type (e.g.,float, double).
30
31 template <class T>
32 class P3 {
33 public:
34 static PyObject * wrap (const IMATH_NAMESPACE::Plane3<T> &pl);
35 static int convert (PyObject *p, IMATH_NAMESPACE::Plane3<T> *pl);
36 };
37
38 template <class T>
39 PyObject *
40 P3<T>::wrap (const IMATH_NAMESPACE::Plane3<T> &pl)
41 {
42 typename boost::python::return_by_value::apply < IMATH_NAMESPACE::Plane3<T> >::type converter;
43 PyObject *p = converter (pl);
44 return p;
45 }
46
47 template <class T>
48 int
49 P3<T>::convert (PyObject *p, IMATH_NAMESPACE::Plane3<T> *pl)
50 {
51 boost::python::extract <IMATH_NAMESPACE::Plane3f> extractorPf (p);
52 if (extractorPf.check())
53 {
54 IMATH_NAMESPACE::Plane3f e = extractorPf();
55 pl->normal.setValue (e.normal);
56 pl->distance = T(e.distance);
57 return 1;
58 }
59
60 boost::python::extract <IMATH_NAMESPACE::Plane3d> extractorPd (p);
61 if (extractorPd.check())
62 {
63 IMATH_NAMESPACE::Plane3d e = extractorPd();
64 pl->normal.setValue (e.normal);
65 pl->distance = T(e.distance);
66 return 1;
67 }
68
69 return 0;
70 }
71
72 typedef P3<float> Plane3f;
73 typedef P3<double> Plane3d;
74
75 }
76
77 #endif