Directory: | ./ |
---|---|
File: | src/log-visitor.hh |
Date: | 2025-05-04 12:09:19 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 10 | 25 | 40.0% |
Branches: | 11 | 48 | 22.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2017, CNRS | ||
2 | // Authors: Florent Lamiraux | ||
3 | // | ||
4 | |||
5 | // Redistribution and use in source and binary forms, with or without | ||
6 | // modification, are permitted provided that the following conditions are | ||
7 | // met: | ||
8 | // | ||
9 | // 1. Redistributions of source code must retain the above copyright | ||
10 | // notice, this list of conditions and the following disclaimer. | ||
11 | // | ||
12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
13 | // notice, this list of conditions and the following disclaimer in the | ||
14 | // documentation and/or other materials provided with the distribution. | ||
15 | // | ||
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
27 | // DAMAGE. | ||
28 | |||
29 | #ifndef HPP_PINOCCHIO_SRC_LOG_VISITOR_HH | ||
30 | #define HPP_PINOCCHIO_SRC_LOG_VISITOR_HH | ||
31 | |||
32 | #include <Eigen/Geometry> | ||
33 | |||
34 | namespace hpp { | ||
35 | namespace pinocchio { | ||
36 | namespace liegroupType { | ||
37 | |||
38 | typedef Eigen::Quaternion<value_type> quaternion_t; | ||
39 | |||
40 | /// Visitor to compute log of a LiegroupType instance | ||
41 | struct LogVisitor : public boost::static_visitor<> { | ||
42 |
1/2✓ Branch 2 taken 102 times.
✗ Branch 3 not taken.
|
102 | LogVisitor(vectorIn_t v, vectorOut_t log) : v_(v), log(log) {} |
43 | template <typename LiegroupType> | ||
44 | void operator()(const LiegroupType& lg); | ||
45 | vectorIn_t v_; | ||
46 | vectorOut_t log; | ||
47 | }; // struct LogVisitor | ||
48 | |||
49 | template <> | ||
50 | 1 | inline void LogVisitor::operator()<liegroup::CartesianProductOperation< | |
51 | liegroup::VectorSpaceOperation<3, false>, | ||
52 | liegroup::SpecialOrthogonalOperation<3> > >( | ||
53 | const liegroup::CartesianProductOperation< | ||
54 | liegroup::VectorSpaceOperation<3, false>, | ||
55 | liegroup::SpecialOrthogonalOperation<3> >&) { | ||
56 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | log.head<3>() = v_.head<3>(); |
57 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | quaternion_t q(v_.tail<4>()); |
58 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Eigen::AngleAxis<value_type> u(q); |
59 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (u.angle() > M_PI) { |
60 | ✗ | log.tail<3>() = -(2 * M_PI - u.angle()) * u.axis(); | |
61 | } else { | ||
62 |
3/6✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
1 | log.tail<3>() = u.axis() * u.angle(); |
63 | } | ||
64 | 1 | } | |
65 | |||
66 | template <> | ||
67 | ✗ | inline void LogVisitor::operator()<liegroup::CartesianProductOperation< | |
68 | liegroup::VectorSpaceOperation<2, false>, | ||
69 | liegroup::SpecialOrthogonalOperation<2> > >( | ||
70 | const liegroup::CartesianProductOperation< | ||
71 | liegroup::VectorSpaceOperation<2, false>, | ||
72 | liegroup::SpecialOrthogonalOperation<2> >&) { | ||
73 | ✗ | log.head<2>() = v_.head<2>(); | |
74 | ✗ | value_type c = v_[2], s = v_[3]; | |
75 | ✗ | log[2] = atan2(s, c); | |
76 | } | ||
77 | |||
78 | template <> | ||
79 | ✗ | inline void LogVisitor::operator()<liegroup::SpecialOrthogonalOperation<2> >( | |
80 | const liegroup::SpecialOrthogonalOperation<2>&) { | ||
81 | ✗ | value_type c = v_[0], s = v_[1]; | |
82 | ✗ | log[0] = atan2(s, c); | |
83 | } | ||
84 | |||
85 | template <> | ||
86 | ✗ | inline void LogVisitor::operator()<liegroup::SpecialOrthogonalOperation<3> >( | |
87 | const liegroup::SpecialOrthogonalOperation<3>&) { | ||
88 | ✗ | vector4_t tmp(v_); | |
89 | ✗ | quaternion_t q(tmp); | |
90 | ✗ | Eigen::AngleAxis<value_type> u(q); | |
91 | ✗ | if (u.angle() > M_PI) { | |
92 | ✗ | log = -(2 * M_PI - u.angle()) * u.axis(); | |
93 | } else { | ||
94 | ✗ | log = u.axis() * u.angle(); | |
95 | } | ||
96 | } | ||
97 | |||
98 | template <typename LiegroupType> | ||
99 | 202 | void LogVisitor::operator()(const LiegroupType&) { | |
100 | 202 | log = v_; | |
101 | } | ||
102 | } // namespace liegroupType | ||
103 | } // namespace pinocchio | ||
104 | } // namespace hpp | ||
105 | |||
106 | #endif // HPP_PINOCCHIO_SRC_LOG_VISITOR_HH | ||
107 |