Directory: | ./ |
---|---|
File: | include/pinocchio/spatial/force-tpl.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 53 | 53 | 100.0% |
Branches: | 19 | 36 | 52.8% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2015-2019 CNRS INRIA | ||
3 | // Copyright (c) 2015-2016 Wandercraft, 86 rue de Paris 91400 Orsay, France. | ||
4 | // | ||
5 | |||
6 | #ifndef __pinocchio_spatial_force_tpl_hpp__ | ||
7 | #define __pinocchio_spatial_force_tpl_hpp__ | ||
8 | |||
9 | namespace pinocchio | ||
10 | { | ||
11 | template<typename _Scalar, int _Options> | ||
12 | struct traits<ForceTpl<_Scalar, _Options>> | ||
13 | { | ||
14 | typedef _Scalar Scalar; | ||
15 | typedef Eigen::Matrix<Scalar, 3, 1, _Options> Vector3; | ||
16 | typedef Eigen::Matrix<Scalar, 6, 1, _Options> Vector6; | ||
17 | typedef Eigen::Matrix<Scalar, 6, 6, _Options> Matrix6; | ||
18 | typedef typename PINOCCHIO_EIGEN_REF_CONST_TYPE(Vector6) ToVectorConstReturnType; | ||
19 | typedef typename PINOCCHIO_EIGEN_REF_TYPE(Vector6) ToVectorReturnType; | ||
20 | typedef typename Vector6::template FixedSegmentReturnType<3>::Type LinearType; | ||
21 | typedef typename Vector6::template FixedSegmentReturnType<3>::Type AngularType; | ||
22 | typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstLinearType; | ||
23 | typedef typename Vector6::template ConstFixedSegmentReturnType<3>::Type ConstAngularType; | ||
24 | typedef ForceTpl<Scalar, _Options> ForcePlain; | ||
25 | enum | ||
26 | { | ||
27 | LINEAR = 0, | ||
28 | ANGULAR = 3, | ||
29 | Options = _Options | ||
30 | }; | ||
31 | |||
32 | typedef ForceRef<Vector6> ForceRefType; | ||
33 | }; // traits ForceTpl | ||
34 | |||
35 | template<typename _Scalar, int _Options> | ||
36 | class ForceTpl : public ForceDense<ForceTpl<_Scalar, _Options>> | ||
37 | { | ||
38 | public: | ||
39 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
40 | typedef ForceDense<ForceTpl> Base; | ||
41 | FORCE_TYPEDEF_TPL(ForceTpl); | ||
42 | enum | ||
43 | { | ||
44 | Options = _Options | ||
45 | }; | ||
46 | |||
47 | using Base::operator=; | ||
48 | using Base::operator!=; | ||
49 | using Base::angular; | ||
50 | using Base::linear; | ||
51 | |||
52 | // Constructors | ||
53 | 288896 | ForceTpl() | |
54 | 288896 | { | |
55 | 288896 | } | |
56 | |||
57 | template<typename V1, typename V2> | ||
58 | 267142 | ForceTpl(const Eigen::MatrixBase<V1> & v, const Eigen::MatrixBase<V2> & w) | |
59 | 267142 | { | |
60 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(V1); | ||
61 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(V2); | ||
62 |
3/5✓ Branch 1 taken 217 times.
✓ Branch 2 taken 165165 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 217 times.
✗ Branch 5 not taken.
|
267142 | linear() = v; |
63 |
3/5✓ Branch 1 taken 217 times.
✓ Branch 2 taken 165165 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 217 times.
✗ Branch 5 not taken.
|
267142 | angular() = w; |
64 | 267142 | } | |
65 | |||
66 | template<typename V6> | ||
67 | 408015 | explicit ForceTpl(const Eigen::MatrixBase<V6> & v) | |
68 | 408015 | : m_data(v) | |
69 | { | ||
70 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(V6); | ||
71 | 408015 | } | |
72 | |||
73 | 434922 | ForceTpl(const ForceTpl & clone) // Copy constructor | |
74 | 434922 | : m_data(clone.toVector()) | |
75 | { | ||
76 | 434922 | } | |
77 | |||
78 | template<typename S2, int O2> | ||
79 | 1 | explicit ForceTpl(const ForceTpl<S2, O2> & other) | |
80 | 1 | { | |
81 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | *this = other.template cast<Scalar>(); |
82 | 1 | } | |
83 | |||
84 | template<typename F2> | ||
85 | explicit ForceTpl(const ForceBase<F2> & clone) | ||
86 | { | ||
87 | *this = clone; | ||
88 | } | ||
89 | |||
90 | 137991 | ForceTpl & operator=(const ForceTpl & clone) // Copy assignment operator | |
91 | { | ||
92 | 137991 | m_data = clone.toVector(); | |
93 | 137991 | return *this; | |
94 | } | ||
95 | |||
96 | template<int O2> | ||
97 | explicit ForceTpl(const ForceTpl<Scalar, O2> & clone) | ||
98 | : m_data(clone.toVector()) | ||
99 | { | ||
100 | } | ||
101 | |||
102 | template<typename M2> | ||
103 | 1 | explicit ForceTpl(const ForceDense<M2> & clone) | |
104 | 1 | { | |
105 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | linear() = clone.linear(); |
106 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | angular() = clone.angular(); |
107 | 1 | } | |
108 | |||
109 | // initializers | ||
110 | 206386 | static ForceTpl Zero() | |
111 | { | ||
112 |
1/2✓ Branch 2 taken 206386 times.
✗ Branch 3 not taken.
|
206386 | return ForceTpl(Vector6::Zero()); |
113 | } | ||
114 | 478 | static ForceTpl Random() | |
115 | { | ||
116 |
1/2✓ Branch 2 taken 478 times.
✗ Branch 3 not taken.
|
478 | return ForceTpl(Vector6::Random()); |
117 | } | ||
118 | |||
119 | 575482 | ToVectorConstReturnType toVector_impl() const | |
120 | { | ||
121 | 575482 | return m_data; | |
122 | } | ||
123 | 154293 | ToVectorReturnType toVector_impl() | |
124 | { | ||
125 | 154451 | return m_data; | |
126 | } | ||
127 | |||
128 | // Getters | ||
129 | 652934 | ConstAngularType angular_impl() const | |
130 | { | ||
131 | 652934 | return m_data.template segment<3>(ANGULAR); | |
132 | } | ||
133 | 724391 | ConstLinearType linear_impl() const | |
134 | { | ||
135 | 727976 | return m_data.template segment<3>(LINEAR); | |
136 | } | ||
137 | 814975 | AngularType angular_impl() | |
138 | { | ||
139 | 819599 | return m_data.template segment<3>(ANGULAR); | |
140 | } | ||
141 | 818307 | LinearType linear_impl() | |
142 | { | ||
143 | 822933 | return m_data.template segment<3>(LINEAR); | |
144 | } | ||
145 | |||
146 | template<typename V3> | ||
147 | 1 | void angular_impl(const Eigen::MatrixBase<V3> & w) | |
148 | { | ||
149 | EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3, 3); | ||
150 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | angular_impl() = w; |
151 | 1 | } | |
152 | template<typename V3> | ||
153 | 1 | void linear_impl(const Eigen::MatrixBase<V3> & v) | |
154 | { | ||
155 | EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(V3, 3); | ||
156 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | linear_impl() = v; |
157 | 1 | } | |
158 | |||
159 | 2 | ForceRef<Vector6> ref() | |
160 | { | ||
161 | 2 | return ForceRef<Vector6>(m_data); | |
162 | } | ||
163 | |||
164 | /// \returns An expression of *this with the Scalar type casted to NewScalar. | ||
165 | template<typename NewScalar> | ||
166 | 3 | ForceTpl<NewScalar, Options> cast() const | |
167 | { | ||
168 | typedef ForceTpl<NewScalar, Options> ReturnType; | ||
169 |
4/8✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
3 | ReturnType res(linear().template cast<NewScalar>(), angular().template cast<NewScalar>()); |
170 | 3 | return res; | |
171 | } | ||
172 | |||
173 | protected: | ||
174 | Vector6 m_data; | ||
175 | |||
176 | }; // class ForceTpl | ||
177 | |||
178 | } // namespace pinocchio | ||
179 | |||
180 | #endif // ifndef __pinocchio_spatial_force_tpl_hpp__ | ||
181 |