OSVR-Core
Translation.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
11 
12 namespace Eigen {
13 
28 template<typename _Scalar, int _Dim>
29 class Translation
30 {
31 public:
32  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
34  enum { Dim = _Dim };
36  typedef _Scalar Scalar;
45 
46 protected:
47 
48  VectorType m_coeffs;
49 
50 public:
51 
55  inline Translation(const Scalar& sx, const Scalar& sy)
56  {
57  ei_assert(Dim==2);
58  m_coeffs.x() = sx;
59  m_coeffs.y() = sy;
60  }
62  inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
63  {
64  ei_assert(Dim==3);
65  m_coeffs.x() = sx;
66  m_coeffs.y() = sy;
67  m_coeffs.z() = sz;
68  }
70  explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
71 
72  const VectorType& vector() const { return m_coeffs; }
73  VectorType& vector() { return m_coeffs; }
74 
76  inline Translation operator* (const Translation& other) const
77  { return Translation(m_coeffs + other.m_coeffs); }
78 
80  inline TransformType operator* (const ScalingType& other) const;
81 
83  inline TransformType operator* (const LinearMatrixType& linear) const;
84 
85  template<typename Derived>
86  inline TransformType operator*(const RotationBase<Derived,Dim>& r) const
87  { return *this * r.toRotationMatrix(); }
88 
90  // its a nightmare to define a templated friend function outside its declaration
91  friend inline TransformType operator* (const LinearMatrixType& linear, const Translation& t)
92  {
93  TransformType res;
94  res.matrix().setZero();
95  res.linear() = linear;
96  res.translation() = linear * t.m_coeffs;
97  res.matrix().row(Dim).setZero();
98  res(Dim,Dim) = Scalar(1);
99  return res;
100  }
101 
103  inline TransformType operator* (const TransformType& t) const;
104 
106  inline VectorType operator* (const VectorType& other) const
107  { return m_coeffs + other; }
108 
110  Translation inverse() const { return Translation(-m_coeffs); }
111 
112  Translation& operator=(const Translation& other)
113  {
114  m_coeffs = other.m_coeffs;
115  return *this;
116  }
117 
123  template<typename NewScalarType>
126 
128  template<typename OtherScalarType>
129  inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
130  { m_coeffs = other.vector().template cast<Scalar>(); }
131 
136  bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
137  { return m_coeffs.isApprox(other.m_coeffs, prec); }
138 
139 };
140 
148 
149 
150 template<typename Scalar, int Dim>
152 Translation<Scalar,Dim>::operator* (const ScalingType& other) const
153 {
154  TransformType res;
155  res.matrix().setZero();
156  res.linear().diagonal() = other.coeffs();
157  res.translation() = m_coeffs;
158  res(Dim,Dim) = Scalar(1);
159  return res;
160 }
161 
162 template<typename Scalar, int Dim>
164 Translation<Scalar,Dim>::operator* (const LinearMatrixType& linear) const
165 {
166  TransformType res;
167  res.matrix().setZero();
168  res.linear() = linear;
169  res.translation() = m_coeffs;
170  res.matrix().row(Dim).setZero();
171  res(Dim,Dim) = Scalar(1);
172  return res;
173 }
174 
175 template<typename Scalar, int Dim>
177 Translation<Scalar,Dim>::operator* (const TransformType& t) const
178 {
179  TransformType res = t;
180  res.pretranslate(m_coeffs);
181  return res;
182 }
183 
184 } // end namespace Eigen
Definition: XprHelper.h:393
Definition: Scaling.h:29
ConstTranslationPart translation() const
Definition: Transform.h:153
Translation()
Default constructor without initialization.
Definition: Translation.h:53
Matrix< Scalar, Dim, Dim > LinearMatrixType
corresponding linear transformation matrix type
Definition: Translation.h:40
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
const MatrixType & matrix() const
Definition: Transform.h:143
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
Transform< Scalar, Dim > TransformType
corresponding affine transformation type
Definition: Translation.h:44
RotationMatrixType toRotationMatrix() const
Definition: RotationBase.h:39
Definition: ForwardDeclarations.h:236
Translation operator*(const Translation &other) const
Concatenates two translation.
Definition: Translation.h:76
internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
Definition: Translation.h:124
Translation inverse() const
Definition: Translation.h:110
Translation(const Translation< OtherScalarType, Dim > &other)
Copy constructor with scalar type conversion.
Definition: Translation.h:129
Common base class for compact rotation representations.
Definition: ForwardDeclarations.h:231
Derived & setZero(Index size)
Resizes to the given size, and sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:515
ConstLinearPart linear() const
Definition: Transform.h:148
_Scalar Scalar
the scalar type of the coefficients
Definition: Translation.h:36
bool isApprox(const Translation &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const
Definition: Translation.h:136
Matrix< Scalar, Dim, 1 > VectorType
corresponding vector type
Definition: Translation.h:38
Translation(const VectorType &vector)
Constructs and initialize the scaling transformation from a vector of scaling coefficients.
Definition: Translation.h:70
Definition: Transform.h:43
Scaling< Scalar, Dim > ScalingType
corresponding scaling transformation type
Definition: Translation.h:42