pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
transform.hpp
1//
2// Copyright (c) 2019 INRIA
3//
4
5#pragma once
6
7#include "pinocchio/spatial.hpp"
8#include <coal/math/transform.h>
9
10namespace boost
11{
12 namespace python
13 {
14 namespace converter
15 {
16
17 template<typename Scalar, int Options>
18 struct implicit<::coal::Transform3s, ::pinocchio::SE3Tpl<Scalar, Options>>
19 {
20 typedef ::coal::Transform3s Source;
21 typedef ::pinocchio::SE3Tpl<Scalar, Options> Target;
22
23 static void * convertible(PyObject * obj)
24 {
25 // Find a converter which can produce a Source instance from
26 // obj. The user has told us that Source can be converted to
27 // Target, and instantiating construct() below, ensures that
28 // at compile-time.
29 return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) ? obj
30 : 0;
31 }
32
33 static void construct(PyObject * obj, rvalue_from_python_stage1_data * data)
34 {
35 void * storage =
36 reinterpret_cast<rvalue_from_python_storage<Target> *>(reinterpret_cast<void *>(data))
37 ->storage.bytes;
38
39 arg_from_python<Source> get_source(obj);
40 bool convertible = get_source.convertible();
41 BOOST_VERIFY(convertible);
42
43 const Source & t = get_source();
44 new (storage) Target(t.getRotation(), t.getTranslation());
45
46 // record successful construction
47 data->convertible = storage;
48 }
49 };
50
51 template<typename Scalar, int Options>
52 struct implicit<::pinocchio::SE3Tpl<Scalar, Options>, ::coal::Transform3s>
53 {
54 typedef ::pinocchio::SE3Tpl<Scalar, Options> Source;
55 typedef ::coal::Transform3s Target;
56
57 static void * convertible(PyObject * obj)
58 {
59 // Find a converter which can produce a Source instance from
60 // obj. The user has told us that Source can be converted to
61 // Target, and instantiating construct() below, ensures that
62 // at compile-time.
63 return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters) ? obj
64 : 0;
65 }
66
67 static void construct(PyObject * obj, rvalue_from_python_stage1_data * data)
68 {
69 void * storage =
70 reinterpret_cast<rvalue_from_python_storage<Target> *>(reinterpret_cast<void *>(data))
71 ->storage.bytes;
72
73 arg_from_python<Source> get_source(obj);
74 bool convertible = get_source.convertible();
75 BOOST_VERIFY(convertible);
76
77 const Source & M = get_source();
78 new (storage) Target(M.rotation(), M.translation());
79
80 // record successful construction
81 data->convertible = storage;
82 }
83 };
84
85 } // namespace converter
86 } // namespace python
87} // namespace boost