Kindr
Kinematics and Dynamics for Robotics
VectorBase.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Christian Gehring, Hannes Sommer, Paul Furgale, Remo Diethelm
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the Autonomous Systems Lab, ETH Zurich nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL Christian Gehring, Hannes Sommer, Paul Furgale,
20  * Remo Diethelm BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27 */
28 
29 #pragma once
30 
31 #include "kindr/common/common.hpp"
32 
33 namespace kindr {
35 namespace internal {
36 
37 
41 template<typename Vector_>
42 class get_dimension {
43  public:
44 // typedef PrimType Scalar;
45 };
46 
47 template<typename factor1, typename factor2>
48 class MultiplicationReturnTypeTrait
49 {
50  public:
51 };
52 
53 template<typename dividend, typename divisor>
54 class DivisionReturnTypeTrait
55 {
56  public:
57 };
58 
59 } // namespace internal
60 
70 template<typename Derived_>
71 class VectorBase {
72  public:
75  typedef typename internal::get_scalar<Derived_>::Scalar Scalar;
76 
79  static constexpr int Dimension = internal::get_dimension<Derived_>::Dimension;
80 
85  VectorBase() = default;
86 
91  VectorBase(const Derived_&) = delete; // on purpose!!
92 
97  operator Derived_& () {
98  return static_cast<Derived_&>(*this);
99  }
100 
105  operator const Derived_& () const {
106  return static_cast<const Derived_&>(*this);
107  }
108 
113  const Derived_& derived() const {
114  return static_cast<const Derived_&>(*this);
115  }
116 
120  static Derived_ Zero();
121 
125  Derived_& setZero();
126 
130  static Derived_ Random();
131 
135  Derived_& setRandom();
136 
140  Scalar operator()(int index) const;
141 
145  Scalar& operator()(int index);
146 
150  template<typename Output_, int DimensionOutput_>
151  Output_ getHead() const;
152 
156  template<typename Output_, int DimensionOutput_>
157  Output_ getTail() const;
158 
162  template<typename Output_, int Start_, int DimensionOutput_>
163  Output_ getSegment() const;
164 
169  Derived_ operator+(const VectorBase<Derived_>& other) const;
170 
175  Derived_ operator-(const VectorBase<Derived_>& other) const;
176 
181  template<typename PrimTypeFactor_>
182  Derived_ operator*(PrimTypeFactor_ factor) const;
183 
188  template<typename PrimTypeDivisor_>
189  Derived_ operator/(PrimTypeDivisor_ divisor) const;
190 
195  Derived_& operator+=(const VectorBase<Derived_>& other);
196 
201  Derived_& operator-=(const VectorBase<Derived_>& other);
202 
207  template<typename PrimTypeFactor_>
208  Derived_& operator*=(PrimTypeFactor_ factor);
209 
214  template<typename PrimTypeDivisor_>
215  Derived_& operator/=(PrimTypeDivisor_ divisor);
216 
220  Derived_ operator-() const;
221 
226  bool operator==(const VectorBase<Derived_>& other) const;
227 
232  bool operator!=(const VectorBase<Derived_>& other) const;
233 
239  bool isSimilarTo(const VectorBase<Derived_>& other, Scalar tol) const;
240 
244  Scalar norm() const;
245 
249  Derived_& normalize();
250 
254  Derived_ normalized() const;
255 
259  Scalar dot(const VectorBase<Derived_>& other) const;
260 
264  template<typename ReturnDerived_, typename OtherDerived_>
265  ReturnDerived_ cross(const VectorBase<OtherDerived_>& other) const;
266 
271  template<typename ReturnDerived_, typename OtherDerived_>
272  ReturnDerived_ elementwiseMultiplication(const VectorBase<OtherDerived_>& other) const;
273 
278  template<typename ReturnDerived_, typename OtherDerived_>
279  ReturnDerived_ elementwiseDivision(const VectorBase<OtherDerived_>& other) const;
280 
284  Derived_ abs() const;
285 
289  Scalar max() const;
290 
294  Scalar min() const;
295 
299  Scalar sum() const;
300 
304  Scalar mean() const;
305 };
306 
307 
308 } // namespace kindr
309 
Vector< PhysicalType_, PrimType_, Dimension_ > operator*(PrimTypeFactor_ factor, const Vector< PhysicalType_, PrimType_, Dimension_ > &vector)
Multiplies a vector with a scalar.
Definition: Vector.hpp:578
const Derived_ & derived() const
Gets the derived vector. (only for advanced users)
Definition: VectorBase.hpp:113
internal::get_scalar< Derived_ >::Scalar Scalar
The primitive type of a vector coordinate.
Definition: VectorBase.hpp:75
Interface for a vector.
Definition: VectorBase.hpp:71