HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PyImathLine.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 _PyImathLine_h_
9 #define _PyImathLine_h_
10 
11 #include <Python.h>
12 #define HBOOST_BIND_GLOBAL_PLACEHOLDERS
13 #include <hboost/python.hpp>
14 #include <ImathLine.h>
15 #include "PyImath.h"
16 
17 
18 namespace PyImath {
19 
20 template <class T> hboost::python::class_<IMATH_NAMESPACE::Line3<T> > register_Line();
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 L3 {
33  public:
34  static PyObject * wrap (const IMATH_NAMESPACE::Line3<T> &l);
35  static int convert (PyObject *p, IMATH_NAMESPACE::Line3<T> *l);
36 };
37 
38 template <class T>
39 PyObject *
40 L3<T>::wrap (const IMATH_NAMESPACE::Line3<T> &l)
41 {
42  typename hboost::python::return_by_value::apply < IMATH_NAMESPACE::Line3<T> >::type converter;
43  PyObject *p = converter (l);
44  return p;
45 }
46 
47 template <class T>
48 int
49 L3<T>::convert (PyObject *p, IMATH_NAMESPACE::Line3<T> *l)
50 {
51  hboost::python::extract <IMATH_NAMESPACE::Line3f> extractorLf (p);
52  if (extractorLf.check())
53  {
54  IMATH_NAMESPACE::Line3f e = extractorLf();
55  l->pos.setValue (e.pos);
56  l->dir.setValue (e.dir);
57  return 1;
58  }
59 
60  hboost::python::extract <IMATH_NAMESPACE::Line3d> extractorLd (p);
61  if (extractorLd.check())
62  {
63  IMATH_NAMESPACE::Line3d e = extractorLd();
64  l->pos.setValue (e.pos);
65  l->dir.setValue (e.dir);
66  return 1;
67  }
68 
69  return 0;
70 }
71 
72 typedef L3<float> Line3f;
74 
75 }
76 
77 #endif
hboost::python::class_< IMATH_NAMESPACE::Line3< T > > register_Line()
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
static int convert(PyObject *p, IMATH_NAMESPACE::Line3< T > *l)
Definition: PyImathLine.h:49
L3< double > Line3d
Definition: PyImathLine.h:73
Line3< double > Line3d
Line of type double.
Definition: ImathLine.h:94
L3< float > Line3f
Definition: PyImathLine.h:72
static PyObject * wrap(const IMATH_NAMESPACE::Line3< T > &l)
Definition: PyImathLine.h:40
Line3< float > Line3f
Line of type float.
Definition: ImathLine.h:91