| 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 BOOST_BIND_GLOBAL_PLACEHOLDERS |
| 13 |
#include <boost/python.hpp> |
| 14 |
#include <ImathFrustum.h> |
| 15 |
#include <ImathFrustumTest.h> |
| 16 |
#include "PyImath.h" |
| 17 |
|
| 18 |
|
| 19 |
namespace PyImath { |
| 20 |
|
| 21 |
template <class T> boost::python::class_<IMATH_NAMESPACE::Frustum<T> > register_Frustum(); |
| 22 |
template <class T> boost::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 boost::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 |
boost::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 |
boost::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 |
|
| 74 |
typedef F<float> Frustumf; |
| 75 |
typedef F<double> Frustumd; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
#endif |