HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathPlane.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 _PyImathPlane_h_
9 #define _PyImathPlane_h_
10 
11 #include <Python.h>
12 #define HBOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <hboost/python.hpp>
14 #include <ImathPlane.h>
15 #include "PyImath.h"
16 
17 
18 namespace PyImath {
19 
20 template <class T> hboost::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 hboost::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  hboost::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  hboost::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 
74 
75 }
76 
77 #endif
hboost::python::class_< IMATH_NAMESPACE::Plane3< T > > register_Plane()
static PyObject * wrap(const IMATH_NAMESPACE::Plane3< T > &pl)
Definition: PyImathPlane.h:40
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
P3< double > Plane3d
Definition: PyImathPlane.h:73
Plane3< double > Plane3d
Plane of type double.
Definition: ImathPlane.h:123
Plane3< float > Plane3f
Plane of type float.
Definition: ImathPlane.h:120
static int convert(PyObject *p, IMATH_NAMESPACE::Plane3< T > *pl)
Definition: PyImathPlane.h:49
P3< float > Plane3f
Definition: PyImathPlane.h:72