GCC Code Coverage Report


Directory: ./
File: include/hpp/pinocchio/liegroup/cartesian-product.hh
Date: 2025-05-04 12:09:19
Exec Total Coverage
Lines: 13 14 92.9%
Branches: 9 32 28.1%

Line Branch Exec Source
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
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_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
30 #define HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
31
32 #include <hpp/util/exception-factory.hh>
33 #include <pinocchio/multibody/liegroup/cartesian-product.hpp>
34
35 namespace hpp {
36 namespace pinocchio {
37 namespace liegroup {
38 template <typename LieGroup1, typename LieGroup2>
39 struct CartesianProductOperation
40 : public ::pinocchio::CartesianProductOperation<LieGroup1, LieGroup2> {
41 enum {
42 BoundSize = LieGroup1::BoundSize + LieGroup2::BoundSize,
43 NR = LieGroup1::NR + LieGroup2::NR,
44 NT = LieGroup1::NT + LieGroup2::NT
45 };
46
47 typedef ::pinocchio::CartesianProductOperation<LieGroup1, LieGroup2> Base;
48
49 template <class ConfigL_t, class ConfigR_t>
50 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
51 const Eigen::MatrixBase<ConfigR_t>& q1) {
52 return Base::squaredDistance(q0, q1);
53 }
54
55 template <class ConfigL_t, class ConfigR_t>
56 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
57 const Eigen::MatrixBase<ConfigR_t>& q1,
58 const typename ConfigL_t::Scalar& w) {
59 return LieGroup1().squaredDistance(q0.template head<LieGroup1::NQ>(),
60 q1.template head<LieGroup1::NQ>(), w) +
61 LieGroup2().squaredDistance(q0.template tail<LieGroup2::NQ>(),
62 q1.template tail<LieGroup2::NQ>(), w);
63 }
64
65 template <class ConfigIn_t, class ConfigOut_t>
66 16 static void setBound(const Eigen::MatrixBase<ConfigIn_t>& bound,
67 const Eigen::MatrixBase<ConfigOut_t>& out) {
68 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigOut_t, Base::ConfigVector_t)
69 ConfigOut_t& oout =
70 16 const_cast<Eigen::MatrixBase<ConfigOut_t>&>(out).derived();
71
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
16 if (bound.size() == BoundSize) {
72 if (LieGroup1::BoundSize > 0)
73
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 LieGroup1::setBound(bound.template head<LieGroup1::BoundSize>(),
74 24 oout.template head<LieGroup1::NQ>());
75 if (LieGroup2::BoundSize > 0)
76 LieGroup2::setBound(bound.template tail<LieGroup2::BoundSize>(),
77 oout.template tail<LieGroup2::NQ>());
78
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 } else if (bound.size() == Base::NQ) {
79
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 LieGroup1::setBound(bound.template head<LieGroup1::NQ>(),
80 4 oout.template head<LieGroup1::NQ>());
81
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 LieGroup2::setBound(bound.template tail<LieGroup2::NQ>(),
82 8 oout.template tail<LieGroup2::NQ>());
83 } else {
84 HPP_THROW(std::invalid_argument, "Expected vector of size "
85 << (int)BoundSize << " or "
86 << (int)Base::NQ << ", got size "
87 << bound.size());
88 }
89 }
90
91 template <class JacobianIn_t, class JacobianOut_t>
92 static void getRotationSubJacobian(
93 const Eigen::MatrixBase<JacobianIn_t>& Jin,
94 const Eigen::MatrixBase<JacobianOut_t>& Jout) {
95 JacobianOut_t& J =
96 const_cast<Eigen::MatrixBase<JacobianOut_t>&>(Jout).derived();
97 if (LieGroup1::NR > 0)
98 LieGroup1::getRotationSubJacobian(Jin.template leftCols<LieGroup1::NV>(),
99 J.template leftCols<LieGroup1::NR>());
100 if (LieGroup2::NR > 0)
101 LieGroup2::getRotationSubJacobian(Jin.template rightCols<LieGroup2::NV>(),
102 J.template rightCols<LieGroup2::NR>());
103 }
104
105 template <class ConfigIn_t>
106 32137 static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t>& q,
107 const value_type& eps) {
108 EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(ConfigIn_t, Base::ConfigVector_t);
109 64274 return LieGroup1::isNormalized(q.template head<LieGroup1::NQ>(), eps) &&
110 64274 LieGroup2::isNormalized(q.template tail<LieGroup2::NQ>(), eps);
111 }
112 }; // struct CartesianProductOperation
113 } // namespace liegroup
114 } // namespace pinocchio
115 } // namespace hpp
116
117 #endif // HPP_PINOCCHIO_LIEGROUP_CARTESIAN_PRODUCT_OPERATION_HH
118