Library of Assembled Shared Sources
 
Loading...
Searching...
No Matches
export_traits_prim.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2026 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44#ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H
45#define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H
46
47#include "python_common.h"
48#include "pyobject_plus.h"
49#include "py_tuple.h"
50
51namespace lass
52{
53namespace python
54{
55namespace impl
56{
57
58template <typename ObjectType, typename ExportTraits, size_t dimension = ObjectType::dimension>
59struct PyExportTraitsVectorPoint
60{
61 static PyObject* build(const ObjectType& v)
62 {
63 TPyObjPtr tuple(PyTuple_New(dimension));
64 if (!tuple)
65 {
66 return nullptr;
67 }
68 for (size_t i = 0; i < dimension; ++i)
69 {
70 PyObject* x = pyBuildSimpleObject(v[i]);
71 if (!x || PyTuple_SetItem(tuple.get(), static_cast<Py_ssize_t>(i), x) != 0)
72 {
73 return nullptr;
74 }
75 }
76 return fromSharedPtrToNakedCast(tuple);
77 }
78
79 static int get(PyObject* obj, ObjectType& v)
80 {
81 const TPyObjPtr tuple = impl::checkedFastSequence(obj, dimension);
82 if (!tuple)
83 {
84 impl::addMessageHeader(ExportTraits::className());
85 return 1;
86 }
87 PyObject** objects = PySequence_Fast_ITEMS(tuple.get());
88 ObjectType result;
89 for (size_t k = 0; k < dimension; ++k)
90 {
91 if (!impl::decodeObject(objects[k], static_cast<Py_ssize_t>(k), result[k]))
92 {
93 impl::addMessageHeader(ExportTraits::className());
94 return 1;
95 }
96 }
97 v = result;
98 return 0;
99 }
100};
101
102template < typename AabbType, typename ExportTraits >
103struct PyExportTraitsPrimAabb
104{
105 typedef AabbType TAabb;
106 static PyObject* build(const TAabb& aabb)
107 {
108 return fromSharedPtrToNakedCast(makeTuple(aabb.min(), aabb.max()));
109 }
110 static int get(PyObject* obj, TAabb& aabb)
111 {
112 typename TAabb::TPoint min, max;
113 if (decodeTuple(obj, min, max) != 0)
114 {
115 impl::addMessageHeader(ExportTraits::className());
116 return 1;
117 }
118 try
119 {
120 aabb = TAabb(min, max);
121 }
122 catch (util::Exception& error)
123 {
124 std::ostringstream buffer;
125 buffer << ExportTraits::className() << ": " << error.message();
126 PyErr_SetString(PyExc_ValueError, buffer.str().c_str());
127 return 1;
128 }
129 return 0;
130 }
131};
132
133template < typename LineSegmentType, typename ExportTraits >
134struct PyExportTraitsPrimLineSegment
135{
136 typedef LineSegmentType TLineSegment;
137 static PyObject* build(const TLineSegment& seg)
138 {
139 return fromSharedPtrToNakedCast(makeTuple(seg.tail(), seg.head()));
140 }
141 static int get(PyObject* obj, TLineSegment& seg)
142 {
143 typename TLineSegment::TPoint tail, head;
144 if (decodeTuple(obj, tail, head) != 0)
145 {
146 impl::addMessageHeader(ExportTraits::className());
147 return 1;
148 }
149 seg = TLineSegment(tail, head);
150 return 0;
151 }
152};
153
154template <typename TransformationType, typename ExporTraits>
155struct PyExportTraitsPrimTransformation
156{
157 typedef TransformationType TTransformation;
158 typedef typename TransformationType::TValue TValue;
159 enum { size = TransformationType::dimension + 1 };
160
161 static PyObject* build(const TTransformation& transfo)
162 {
163 const TValue* const values = transfo.matrix();
164 TPyObjPtr matrix(PyTuple_New(size));
165 if (!matrix)
166 {
167 return nullptr;
168 }
169 for (int i = 0; i < size; ++i)
170 {
171 TPyObjPtr row(PyTuple_New(size));
172 if (!row)
173 {
174 return nullptr;
175 }
176 for (int j = 0; j < size; ++j)
177 {
178 PyObject* x = pyBuildSimpleObject(values[i * size + j]);
179 if (!x || PyTuple_SetItem(row.get(), j, x) != 0)
180 {
181 return nullptr;
182 }
183 }
184 if (PyTuple_SetItem(matrix.get(), i, fromSharedPtrToNakedCast(row)) != 0)
185 {
186 return nullptr;
187 }
188 }
189 return fromSharedPtrToNakedCast(matrix);
190 }
191
192 static int get(PyObject* obj, TTransformation& transfo)
193 {
194 TPyObjPtr tuple = impl::checkedFastSequence(obj, size);
195 if (!tuple)
196 {
197 impl::addMessageHeader(ExporTraits::className());
198 return 1;
199 }
200 PyObject** rows = PySequence_Fast_ITEMS(tuple.get());
201 TValue values[size * size];
202 for (int i = 0; i < size; ++i)
203 {
204 TPyObjPtr row = impl::checkedFastSequence(rows[i], size);
205 if (!row)
206 {
207 std::ostringstream buffer;
208 buffer << ExporTraits::className() << ": row " << i;
209 impl::addMessageHeader(buffer.str().c_str());
210 return 1;
211 }
212 PyObject** objects = PySequence_Fast_ITEMS(row.get());
213 for (int j = 0; j < size; ++j)
214 {
215 if (pyGetSimpleObject(objects[j], values[size * i + j]) != 0)
216 {
217 std::ostringstream buffer;
218 buffer << ExporTraits::className() << ": row " << i << ", column " << j;
219 impl::addMessageHeader(buffer.str().c_str());
220 return 1;
221 }
222 }
223 }
224 transfo = TTransformation(values, values + size * size);
225 return 0;
226 }
227};
228
229template <typename PolygonType, typename ExportTraits>
230struct PyExportTraitsPrimSimplePolygon
231{
232 typedef PolygonType TPolygon;
233 typedef typename PolygonType::TPoint TPoint;
234 static PyObject* build(const TPolygon& poly)
235 {
236 std::vector<TPoint> points;
237 for (unsigned i = 0; i < poly.size(); ++i)
238 points.push_back(poly[i]);
239 return pyBuildSimpleObject( points );
240 }
241 static int get(PyObject* obj, TPolygon& poly)
242 {
243 std::vector<TPoint> points;
244 if (pyGetSimpleObject(obj, points) != 0)
245 {
246 impl::addMessageHeader(ExportTraits::className());
247 return 1;
248 }
249 poly = TPolygon(points.begin(), points.end());
250 return 0;
251 }
252};
253
254template <typename AxisType, typename ExportTraits>
255struct PyExportTraitsPrimAxis
256{
257 typedef AxisType TAxis;
258 static PyObject* build(const TAxis& axis)
259 {
260 return pyBuildSimpleObject(std::string(1, axis.axis()));
261 }
262 static int get(PyObject* obj, TAxis& axis)
263 {
264 std::string s;
265 if (pyGetSimpleObject(obj, s) != 0)
266 {
267 impl::addMessageHeader(ExportTraits::className());
268 return 1;
269 }
270 try
271 {
272 axis = TAxis(s);
273 }
274 catch (util::Exception& error)
275 {
276 std::ostringstream buffer;
277 buffer << ExportTraits::className() << ": " << error.message();
278 PyErr_SetString(PyExc_ValueError, buffer.str().c_str());
279 return 1;
280 }
281 return 0;
282 }
283};
284
285LASS_PYTHON_DLL PyObject* LASS_CALL buildIndexVertex(size_t vertex, size_t normal, size_t uv);
286LASS_PYTHON_DLL int LASS_CALL getIndexVertex(PyObject* iIndices, size_t& vertex, size_t& normal, size_t& uv);
287
288}
289}
290}
291
292#endif
293
294namespace lass
295{
296namespace python
297{
298
299// --- vectors -------------------------------------------------------------------------------------
300
301#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_VECTOR_2D)
302# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_2D
303# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_2D
304
305/** Maps prim::Vector2D<T> to a Python tuple of two elements of type T.
306 * @ingroup PyExportTraits
307 */
308template <typename T>
309struct PyExportTraits< prim::Vector2D<T> >:
310 public impl::PyExportTraitsVectorPoint< prim::Vector2D<T>, PyExportTraits< prim::Vector2D<T> > >
311{
312 constexpr static const char* py_typing = "_Vector2D[T]";
313 constexpr static const char* py_typing_preamble = "type _Vector2D[T] = tuple[T, T]";
314
315 static const char* className() { return "Vector2D"; }
316};
317
318# endif
319#endif
320
321
322
323#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_VECTOR_3D)
324# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_3D
325# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_3D
326
327/** Maps prim::Vector3D<T> to a Python tuple of three elements of type T.
328 * @ingroup PyExportTraits
329 */
330template <typename T>
331struct PyExportTraits< prim::Vector3D<T> >:
332 public impl::PyExportTraitsVectorPoint< prim::Vector3D<T>, PyExportTraits< prim::Vector3D<T> > >
333{
334 constexpr static const char* py_typing = "_Vector3D[T]";
335 constexpr static const char* py_typing_preamble = "type _Vector3D[T] = tuple[T, T, T]";
336
337 static const char* className() { return "Vector3D"; }
338};
339
340# endif
341#endif
342
343
344#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_VECTOR_4D)
345# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_4D
346# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_VECTOR_4D
347
348/** Maps prim::Vector4D<T> to a Python tuple of four elements of type T.
349 * @ingroup PyExportTraits
350 */
351template <typename T>
352struct PyExportTraits< prim::Vector4D<T> >:
353 public impl::PyExportTraitsVectorPoint< prim::Vector4D<T>, PyExportTraits< prim::Vector4D<T> > >
354{
355 constexpr static const char* py_typing = "_Vector4D[T]";
356 constexpr static const char* py_typing_preamble = "type _Vector4D[T] = tuple[T, T, T, T]";
357
358 static const char* className() { return "Vector4D"; }
359};
360
361# endif
362#endif
363
364
365
366// --- points --------------------------------------------------------------------------------------
367
368#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_POINT_2D)
369# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_POINT_2D
370# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_POINT_2D
371
372/** Maps prim::Point2D<T> to a Python tuple of two elements of type T.
373 * @ingroup PyExportTraits
374 */
375template <typename T>
376struct PyExportTraits< prim::Point2D<T> >:
377 public impl::PyExportTraitsVectorPoint< prim::Point2D<T>, PyExportTraits< prim::Point2D<T> > >
378{
379 constexpr static const char* py_typing = "_Point2D[T]";
380 constexpr static const char* py_typing_preamble = "type _Point2D[T] = tuple[T, T]";
381
382 static const char* className() { return "Point2D"; }
383};
384
385# endif
386#endif
387
388
389
390#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_POINT_3D)
391# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_POINT_3D
392# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_POINT_3D
393
394/** Maps prim::Point3D<T> to a Python tuple of three elements of type T.
395 * @ingroup PyExportTraits
396 */
397template <typename T>
398struct PyExportTraits< prim::Point3D<T> >:
399 public impl::PyExportTraitsVectorPoint< prim::Point3D<T>, PyExportTraits< prim::Point3D<T> > >
400{
401 constexpr static const char* py_typing = "_Point3D[T]";
402 constexpr static const char* py_typing_preamble = "type _Point3D[T] = tuple[T, T, T]";
403
404 static const char* className() { return "Point3D"; }
405};
406
407# endif
408#endif
409
410
411
412// --- boxes ---------------------------------------------------------------------------------------
413
414#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_AABB_2D)
415# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AABB_2D
416# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AABB_2D
417
418/** Maps prim::Aabb2D<T> to a Python tuple of two tuples of two elements of type T.
419 * @ingroup PyExportTraits
420 */
421template <typename T, typename MMP>
422struct PyExportTraits< prim::Aabb2D<T, MMP> >:
423 public impl::PyExportTraitsPrimAabb< prim::Aabb2D<T, MMP>, PyExportTraits< prim::Aabb2D<T, MMP> > >
424{
425 constexpr static const char* py_typing = "_Aabb2D[T]";
426 constexpr static const char* py_typing_preamble =
427 "type _Point2D[T] = tuple[T, T]\n"
428 "type _Aabb2D[T] = tuple[_Point2D[T], _Point2D[T]]";
429
430 static const char* className() { return "Aabb2D"; }
431};
432
433# endif
434#endif
435
436#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_AABB_3D)
437# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AABB_3D
438# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AABB_3D
439
440/** Maps prim::Aabb3D<T> to a Python tuple of two tuples of three elements of type T.
441 * @ingroup PyExportTraits
442 */
443template <typename T, typename MMP>
444struct PyExportTraits< prim::Aabb3D<T, MMP> >:
445 public impl::PyExportTraitsPrimAabb< prim::Aabb3D<T, MMP>, PyExportTraits< prim::Aabb3D<T, MMP> > >
446{
447 constexpr static const char* py_typing = "_Aabb3D[T]";
448 constexpr static const char* py_typing_preamble =
449 "type _Point3D[T] = tuple[T, T, T]\n"
450 "type _Aabb3D[T] = tuple[_Point3D[T], _Point3D[T]]";
451
452 static const char* className() { return "Aabb3D"; }
453};
454
455# endif
456#endif
457
458
459
460// --- line segments -------------------------------------------------------------------------------
461
462#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_LINE_SEGMENT_2D)
463# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_LINE_SEGMENT_2D
464# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_LINE_SEGMENT_2D
465
466/** Maps prim::LineSegment2D<T> to a Python tuple of two tuples of two elements of type T.
467 * @ingroup PyExportTraits
468 */
469template <typename T, typename PP>
470struct PyExportTraits< prim::LineSegment2D<T, PP> >:
471 public impl::PyExportTraitsPrimLineSegment< prim::LineSegment2D<T, PP>, PyExportTraits< prim::LineSegment2D<T, PP> > >
472{
473 constexpr static const char* py_typing = "_LineSegment2D[T]";
474 constexpr static const char* py_typing_preamble =
475 "type _Point2D[T] = tuple[T, T]\n"
476 "type _LineSegment2D[T] = tuple[_Point2D[T], _Point2D[T]]";
477
478 static const char* className() { return "LineSegment2D"; }
479};
480
481# endif
482#endif
483
484#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_LINE_SEGMENT_3D)
485# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_LINE_SEGMENT_3D
486# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_LINE_SEGMENT_3D
487
488/** Maps prim::LineSegment3D<T> to a Python tuple of two tuples of three elements of type T.
489 * @ingroup PyExportTraits
490 */
491template <typename T, typename PP>
492struct PyExportTraits< prim::LineSegment3D<T, PP> >:
493 public impl::PyExportTraitsPrimLineSegment< prim::LineSegment3D<T, PP>, PyExportTraits< prim::LineSegment3D<T, PP> > >
494{
495 constexpr static const char* py_typing = "_LineSegment3D[T]";
496 constexpr static const char* py_typing_preamble =
497 "type _Point3D[T] = tuple[T, T, T]\n"
498 "type _LineSegment3D[T] = tuple[_Point3D[T], _Point3D[T]]";
499
500 static const char* className() { return "LineSegment3D"; }
501};
502
503# endif
504#endif
505
506
507
508// --- transformations -----------------------------------------------------------------------------
509
510#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRANSFORMATION_2D)
511# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_TRANSFORMATION_2D
512# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_TRANSFORMATION_2D
513
514/** Maps prim::Transformation2D<T> to a Python tuple of three tuples of three elements of type T.
515 * @ingroup PyExportTraits
516 */
517template <typename T>
518struct PyExportTraits< prim::Transformation2D<T> >:
519 public impl::PyExportTraitsPrimTransformation< prim::Transformation2D<T>, PyExportTraits< prim::Transformation2D<T> > >
520{
521 constexpr static const char* py_typing = "_Transformation2D[T]";
522 constexpr static const char* py_typing_preamble = "type _Transformation2D[T] = tuple[tuple[T, T, T], tuple[T, T, T], tuple[T, T, T]]";
523
524 static const char* className() { return "Transformation2D"; }
525};
526
527# endif
528#endif
529
530#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRANSFORMATION_3D)
531# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_TRANSFORMATION_3D
532# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_TRANSFORMATION_3D
533
534/** Maps prim::Transformation3D<T> to a Python tuple of four tuples of four elements of type T.
535 * @ingroup PyExportTraits
536 */
537template <typename T>
538struct PyExportTraits< prim::Transformation3D<T> >:
539 public impl::PyExportTraitsPrimTransformation< prim::Transformation3D<T>, PyExportTraits< prim::Transformation3D<T> > >
540{
541 constexpr static const char* py_typing = "_Transformation3D[T]";
542 constexpr static const char* py_typing_preamble = "type _Transformation3D[T] = tuple[tuple[T, T, T, T], tuple[T, T, T, T], tuple[T, T, T, T], tuple[T, T, T, T]]";
543
544 static const char* className() { return "Transformation3D"; }
545};
546
547# endif
548#endif
549
550
551
552// --- simplepolygons -----------------------------------------------------------------------------
553
554#ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON
555#define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON
556
557
558#endif
559
560#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_SIMPLE_POLYGON_2D)
561# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON_2D
562# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON_2D
563
564/** Maps prim::SimplePolygon2D<T> to a Python sequence of tuples of two elements of type T.
565 * @ingroup PyExportTraits
566 */
567template <typename T, typename DP>
568struct PyExportTraits< prim::SimplePolygon2D<T, DP> >:
569 public impl::PyExportTraitsPrimSimplePolygon< prim::SimplePolygon2D<T, DP>, PyExportTraits< prim::SimplePolygon2D<T, DP> > >
570{
571 constexpr static const char* py_typing = "_SimplePolygon2D[T]";
572 constexpr static const char* py_typing_preamble =
573 "type _Point2D[T] = tuple[T, T]\n"
574 "type _SimplePolygon2D[T] = Sequence[_Point2D[T]]";
575
576 static const char* className() { return "SimplePolygon2D"; }
577};
578
579# endif
580#endif
581
582
583#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_SIMPLE_POLYGON_3D)
584# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON_3D
585# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_SIMPLE_POLYGON_3D
586
587/** Maps prim::SimplePolygon3D<T> to a Python sequence of tuples of three elements of type T.
588 * @ingroup PyExportTraits
589 */
590template <typename T, typename DP>
591struct PyExportTraits< prim::SimplePolygon3D<T, DP> >:
592 public impl::PyExportTraitsPrimSimplePolygon< prim::SimplePolygon3D<T, DP>, PyExportTraits< prim::SimplePolygon3D<T, DP> > >
593{
594 constexpr static const char* py_typing = "_SimplePolygon3D[T]";
595 constexpr static const char* py_typing_preamble =
596 "type _Point3D[T] = tuple[T, T, T]\n"
597 "type _SimplePolygon3D[T] = Sequence[_Point3D[T]]";
598
599 static const char* className() { return "SimplePolygon3D"; }
600};
601
602# endif
603#endif
604
605// --- axes ----------------------------------------------------------------------------------------
606
607#ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AXIS
608#define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_AXIS
609
610
611#endif
612
613#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_XY)
614# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XY
615# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XY
616
617/** Maps prim::XY to a Python string literal "x" or "y".
618 * @ingroup PyExportTraits
619 */
620template <>
622 public impl::PyExportTraitsPrimAxis<prim::XY, PyExportTraits<prim::XY> >
623{
624 constexpr static const char* py_typing = "Literal['x', 'X', 'y', 'Y']";
625 static const char* className() { return "XY"; }
626};
627
628# endif
629#endif
630
631#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_XYZ)
632# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XYZ
633# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XYZ
634
635/** Maps prim::XYZ to a Python string literal "x", "y" or "z".
636 * @ingroup PyExportTraits
637 */
638template <>
639struct PyExportTraits<prim::XYZ>:
640 public impl::PyExportTraitsPrimAxis<prim::XYZ, PyExportTraits<prim::XYZ> >
641{
642 constexpr static const char* py_typing = "Literal['x', 'X', 'y', 'Y', 'z', 'Z']";
643 static const char* className() { return "XYZ"; }
644};
645
646# endif
647#endif
648
649#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_XYZW)
650# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XYZW
651# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_XYZW
652
653/** Maps prim::XYZW to a Python string literal "x", "y", "z" or "w".
654 * @ingroup PyExportTraits
655 */
656template <>
657struct PyExportTraits<prim::XYZW>:
658 public impl::PyExportTraitsPrimAxis<prim::XYZW, PyExportTraits<prim::XYZW> >
659{
660 constexpr static const char* py_typing = "Literal['x', 'X', 'y', 'Y', 'z', 'Z', 'w', 'W']";
661 static const char* className() { return "XYZW"; }
662};
663
664# endif
665#endif
666
667// --- ColorRGBA -----------------------------------------------------------------------------------
668
669#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_COLOR_RGBA)
670# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_COLOR_RGBA
671# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_COLOR_RGBA
672
673/** Maps prim::ColorRGBA to a Python tuple of four elements of type float.
674 * @ingroup PyExportTraits
675 */
676template <>
677struct PyExportTraits<prim::ColorRGBA>
678{
679 constexpr static const char* py_typing = "_RGBA";
680 constexpr static const char* py_typing_param = "_RGBA | _RGB";
681 constexpr static const char* py_typing_preamble =
682 "type _RGBA = tuple[float, float, float, float]\n"
683 "type _RGB = tuple[float, float, float]";
684
685 static PyObject* build(const prim::ColorRGBA& v)
686 {
687 return pyBuildSimpleObject(v.vector());
688 }
689 static int get(PyObject* obj, prim::ColorRGBA& v)
690 {
691 prim::ColorRGBA x(0, 0, 0, 1);
692 if (decodeTupleMinimum(obj, 3, x.r, x.g, x.b, x.a))
693 {
694 impl::addMessageHeader("ColorRGBA");
695 return 1;
696 }
697 v = x;
698 return 0;
699 }
700};
701
702# endif
703#endif
704
705// --- IndexTriangle -------------------------------------------------------------------------------
706
707#if defined(LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRIANGLE_MESH_3D)
708# ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_INDEX_TRIANGLE
709# define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXPORT_TRAITS_PRIM_H_INDEX_TRIANGLE
710
711namespace impl
712{
713}
714
715/** Maps prim::IndexTriangle to a Python tuple of three index vertices.
716 *
717 * An index vertex is a tuple of one, two or three size_t values:
718 * - (vertex,)
719 * - (vertex, normal)
720 * - (vertex, normal, uv)
721 * where 'vertex', 'normal' and 'uv' are indices in the corresponding arrays.
722 * The indices are zero-based.
723 *
724 * The 'normal' and 'uv' indices can be None to indicate that no normal or uv is specified.
725 * The vertex index is mandatory.
726 *
727 * @ingroup PyExportTraits
728 */
729template <>
730struct PyExportTraits<prim::IndexTriangle>
731{
732 constexpr static const char* py_typing = "_IndexTriangle";
733 constexpr static const char* py_typing_preamble =
734 "type _IndexVertex = tuple[int] | tuple[int, int | None] | tuple[int, int | None, int | None]\n"
735 "type _IndexTriangle = tuple[_IndexVertex, _IndexVertex, _IndexVertex]";
736
737 static PyObject* build(const prim::IndexTriangle& iTriangle)
738 {
739 TPyObjPtr triangle(PyTuple_New(3));
740 if (!triangle) return 0;
741 for (int k = 0; k < 3; ++k)
742 {
743 PyObject* vertex = impl::buildIndexVertex(
744 iTriangle.vertices[k], iTriangle.normals[k], iTriangle.uvs[k]);
745 if (!vertex) return 0;
746 if (PyTuple_SetItem(triangle.get(), k, vertex) != 0) return 0;
747 }
748 return fromSharedPtrToNakedCast(triangle);
749 }
750 static int get(PyObject* obj, prim::IndexTriangle& oTriangle)
751 {
752 const TPyObjPtr tuple(impl::checkedFastSequence(obj, 3));
753 if (!tuple)
754 {
755 impl::addMessageHeader("IndexTriangle");
756 return 1;
757 }
758 PyObject** objects = PySequence_Fast_ITEMS(tuple.get());
759 prim::IndexTriangle result = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
760 for (int k = 0; k < 3; ++k)
761 {
762 if (impl::getIndexVertex(objects[k], result.vertices[k], result.normals[k], result.uvs[k]) != 0)
763 {
764 std::ostringstream buffer;
765 buffer << "IndexTriangle: " << (k + 1) << "th vertex";
766 impl::addMessageHeader(buffer.str().c_str());
767 return 1;
768 }
769 }
770 oTriangle = result;
771 return 0;
772 }
773};
774
775# endif
776#endif
777
778}
779}
780
781// EOF
an [0, 1] floating point RGB colour with Alpha channel.
Definition color_rgba.h:62
void addMessageHeader(const char *header)
Prepend a message to the current Python exception value.
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
PyObject * fromSharedPtrToNakedCast(const util::SharedPtr< T, PyObjectStorage, PyObjectCounter > &object)
fromSharedPtrToNakedCast.
set of geometrical primitives
Definition aabb_2d.h:81
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.
Definition config.h:53
by copy, general case assumes shadow type or PyObjectPlus based type.