HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathFrustum.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 _PyImathFrustum_h_
9 #define _PyImathFrustum_h_
10 
11 #include <Python.h>
12 #define HBOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <hboost/python.hpp>
14 #include <ImathFrustum.h>
15 #include <ImathFrustumTest.h>
16 #include "PyImath.h"
17 
18 
19 namespace PyImath {
20 
21 template <class T> hboost::python::class_<IMATH_NAMESPACE::Frustum<T> > register_Frustum();
22 template <class T> hboost::python::class_<IMATH_NAMESPACE::FrustumTest<T> > register_FrustumTest();
23 
24 //
25 
26 // Other code in the Zeno code base assumes the existance of a class with the
27 // same name as the Imath class, and with static functions wrap() and
28 // convert() to produce a PyImath object from an Imath object and vice-versa,
29 // respectively. The class Boost generates from the Imath class does not
30 // have these properties, so we define a companion class here.
31 // The template argument, T, is the element type (e.g.,float, double).
32 
33 template <class T>
34 class F {
35  public:
36  static PyObject * wrap (const IMATH_NAMESPACE::Frustum<T> &f);
37  static int convert (PyObject *p, IMATH_NAMESPACE::Frustum<T> *f);
38 };
39 
40 template <class T>
41 PyObject *
42 F<T>::wrap (const IMATH_NAMESPACE::Frustum<T> &f)
43 {
44  typename hboost::python::return_by_value::apply < IMATH_NAMESPACE::Frustum<T> >::type converter;
45  PyObject *p = converter (f);
46  return p;
47 }
48 
49 template <class T>
50 int
51 F<T>::convert (PyObject *p, IMATH_NAMESPACE::Frustum<T> *f)
52 {
53  hboost::python::extract <IMATH_NAMESPACE::Frustumf> extractorEf (p);
54  if (extractorEf.check())
55  {
56  IMATH_NAMESPACE::Frustumf e = extractorEf();
57  f->set (T(e.nearPlane()), T(e.farPlane()), T(e.left()), T(e.right()),
58  T(e.top()), T(e.bottom()), e.orthographic());
59  return 1;
60  }
61 
62  hboost::python::extract <IMATH_NAMESPACE::Frustumd> extractorEd (p);
63  if (extractorEd.check())
64  {
65  IMATH_NAMESPACE::Frustumd e = extractorEd();
66  f->set (T(e.nearPlane()), T(e.farPlane()), T(e.left()), T(e.right()),
67  T(e.top()), T(e.bottom()), e.orthographic());
68  return 1;
69  }
70 
71  return 0;
72 }
73 
76 
77 }
78 
79 #endif
hboost::python::class_< IMATH_NAMESPACE::FrustumTest< T > > register_FrustumTest()
F< float > Frustumf
static int convert(PyObject *p, IMATH_NAMESPACE::Frustum< T > *f)
static PyObject * wrap(const IMATH_NAMESPACE::Frustum< T > &f)
hboost::python::class_< IMATH_NAMESPACE::Frustum< T > > register_Frustum()
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Frustum< double > Frustumd
Frustum of type double.
Frustum< float > Frustumf
Frustum of type float.
F< double > Frustumd