Directory: | ./ |
---|---|
File: | python/math.cc |
Date: | 2025-04-01 09:23:31 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 66 | 78 | 84.6% |
Branches: | 63 | 134 | 47.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Software License Agreement (BSD License) | ||
3 | // | ||
4 | // Copyright (c) 2019 CNRS-LAAS INRIA | ||
5 | // Author: Joseph Mirabel | ||
6 | // All rights reserved. | ||
7 | // | ||
8 | // Redistribution and use in source and binary forms, with or without | ||
9 | // modification, are permitted provided that the following conditions | ||
10 | // are met: | ||
11 | // | ||
12 | // * Redistributions of source code must retain the above copyright | ||
13 | // notice, this list of conditions and the following disclaimer. | ||
14 | // * Redistributions in binary form must reproduce the above | ||
15 | // copyright notice, this list of conditions and the following | ||
16 | // disclaimer in the documentation and/or other materials provided | ||
17 | // with the distribution. | ||
18 | // * Neither the name of CNRS-LAAS. nor the names of its | ||
19 | // contributors may be used to endorse or promote products derived | ||
20 | // from this software without specific prior written permission. | ||
21 | // | ||
22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
26 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
28 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
29 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
30 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
32 | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
33 | // POSSIBILITY OF SUCH DAMAGE. | ||
34 | |||
35 | #include <eigenpy/eigenpy.hpp> | ||
36 | #include <eigenpy/geometry.hpp> | ||
37 | |||
38 | #include "coal/fwd.hh" | ||
39 | #include "coal/math/transform.h" | ||
40 | #include "coal/serialization/transform.h" | ||
41 | |||
42 | #include "coal.hh" | ||
43 | #include "pickle.hh" | ||
44 | #include "serializable.hh" | ||
45 | |||
46 | #ifdef COAL_HAS_DOXYGEN_AUTODOC | ||
47 | #include "doxygen_autodoc/coal/math/transform.h" | ||
48 | #endif | ||
49 | |||
50 | using namespace boost::python; | ||
51 | using namespace coal; | ||
52 | using namespace coal::python; | ||
53 | |||
54 | namespace dv = doxygen::visitor; | ||
55 | |||
56 | struct TriangleWrapper { | ||
57 | ✗ | static Triangle::index_type getitem(const Triangle& t, int i) { | |
58 | ✗ | if (i >= 3 || i <= -3) | |
59 | ✗ | PyErr_SetString(PyExc_IndexError, "Index out of range"); | |
60 | ✗ | return t[static_cast<coal::Triangle::index_type>(i % 3)]; | |
61 | } | ||
62 | ✗ | static void setitem(Triangle& t, int i, Triangle::index_type v) { | |
63 | ✗ | if (i >= 3 || i <= -3) | |
64 | ✗ | PyErr_SetString(PyExc_IndexError, "Index out of range"); | |
65 | ✗ | t[static_cast<coal::Triangle::index_type>(i % 3)] = v; | |
66 | } | ||
67 | }; | ||
68 | |||
69 | 5 | void exposeMaths() { | |
70 | 5 | eigenpy::enableEigenPy(); | |
71 | |||
72 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | if (!eigenpy::register_symbolic_link_to_registered_type<Eigen::Quaterniond>()) |
73 | 5 | eigenpy::exposeQuaternion(); | |
74 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | if (!eigenpy::register_symbolic_link_to_registered_type<Eigen::AngleAxisd>()) |
75 | 5 | eigenpy::exposeAngleAxis(); | |
76 | |||
77 | 5 | eigenpy::enableEigenPySpecific<Matrix3s>(); | |
78 | 5 | eigenpy::enableEigenPySpecific<Vec3s>(); | |
79 | |||
80 | 5 | class_<Transform3s>("Transform3s", doxygen::class_doc<Transform3s>(), no_init) | |
81 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s>()) |
82 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(dv::init<Transform3s, const Matrix3s::MatrixBase&, |
83 | 5 | const Vec3s::MatrixBase&>()) | |
84 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s, const Quats&, const Vec3s::MatrixBase&>()) |
85 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s, const Matrix3s&>()) |
86 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s, const Quats&>()) |
87 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s, const Vec3s&>()) |
88 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Transform3s, const Transform3s&>()) |
89 | |||
90 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("getQuatRotation", &Transform3s::getQuatRotation)) |
91 | 10 | .def("getTranslation", &Transform3s::getTranslation, | |
92 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | doxygen::member_func_doc(&Transform3s::getTranslation), |
93 | ✗ | return_value_policy<copy_const_reference>()) | |
94 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def("getRotation", &Transform3s::getRotation, |
95 | ✗ | return_value_policy<copy_const_reference>()) | |
96 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def("isIdentity", &Transform3s::isIdentity, |
97 | ✗ | (bp::arg("self"), | |
98 |
3/6✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
|
10 | bp::arg("prec") = Eigen::NumTraits<Scalar>::dummy_precision()), |
99 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | doxygen::member_func_doc(&Transform3s::getTranslation)) |
100 | |||
101 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("setQuatRotation", &Transform3s::setQuatRotation)) |
102 | 10 | .def("setTranslation", &Transform3s::setTranslation<Vec3s>) | |
103 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def("setRotation", &Transform3s::setRotation<Matrix3s>) |
104 |
3/6✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5 times.
✗ Branch 8 not taken.
|
5 | .def(dv::member_func("setTransform", |
105 | &Transform3s::setTransform<Matrix3s, Vec3s>)) | ||
106 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(dv::member_func( |
107 | "setTransform", | ||
108 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | static_cast<void (Transform3s::*)(const Quats&, const Vec3s&)>( |
109 | &Transform3s::setTransform))) | ||
110 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("setIdentity", &Transform3s::setIdentity)) |
111 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("Identity", &Transform3s::Identity)) |
112 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .staticmethod("Identity") |
113 | |||
114 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("setRandom", &Transform3s::setRandom)) |
115 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("Random", &Transform3s::Random)) |
116 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .staticmethod("Random") |
117 | |||
118 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("transform", &Transform3s::transform<Vec3s>)) |
119 | 10 | .def("inverseInPlace", &Transform3s::inverseInPlace, | |
120 | ✗ | return_internal_reference<>(), | |
121 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | doxygen::member_func_doc(&Transform3s::inverseInPlace)) |
122 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("inverse", &Transform3s::inverse)) |
123 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("inverseTimes", &Transform3s::inverseTimes)) |
124 | |||
125 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(self * self) |
126 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(self *= self) |
127 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(self == self) |
128 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(self != self) |
129 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def_pickle(PickleObject<Transform3s>()) |
130 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(SerializableVisitor<Transform3s>()); |
131 | |||
132 | 5 | class_<Triangle>("Triangle", no_init) | |
133 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(dv::init<Triangle>()) |
134 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(dv::init<Triangle, Triangle::index_type, Triangle::index_type, |
135 | 5 | Triangle::index_type>()) | |
136 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def("__getitem__", &TriangleWrapper::getitem) |
137 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def("__setitem__", &TriangleWrapper::setitem) |
138 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("set", &Triangle::set)) |
139 |
2/4✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
5 | .def(dv::member_func("size", &Triangle::size)) |
140 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .staticmethod("size") |
141 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | .def(self == self); |
142 | |||
143 | 5 | if (!eigenpy::register_symbolic_link_to_registered_type< | |
144 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | std::vector<Vec3s> >()) { |
145 | 10 | class_<std::vector<Vec3s> >("StdVec_Vec3s") | |
146 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(vector_indexing_suite<std::vector<Vec3s> >()); |
147 | } | ||
148 | 5 | if (!eigenpy::register_symbolic_link_to_registered_type< | |
149 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | std::vector<Triangle> >()) { |
150 | 10 | class_<std::vector<Triangle> >("StdVec_Triangle") | |
151 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | .def(vector_indexing_suite<std::vector<Triangle> >()); |
152 | } | ||
153 | 5 | } | |
154 |