Eigen2Support/Geometry/Translation.h
Go to the documentation of this file.
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:
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 
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
Translation(const Scalar &sx, const Scalar &sy, const Scalar &sz)
Represents a possibly non uniform scaling transformation.
const VectorType & vector() const
#define ei_assert
Translation< float, 3 > Translation3f
Translation & operator=(const Translation &other)
Matrix< Scalar, Dim, Dim > LinearMatrixType
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Transform< Scalar, Dim > TransformType
Translation(const Scalar &sx, const Scalar &sy)
Represents a translation transformation.
const VectorType & coeffs() const
Transform & pretranslate(const MatrixBase< OtherDerived > &other)
Translation< float, 2 > Translation2f
Translation(const Translation< OtherScalarType, Dim > &other)
Common base class for compact rotation representations.
TransformType operator*(const RotationBase< Derived, Dim > &r) const
Derived & setZero(Index size)
ConstTranslationPart translation() const
const MatrixType & matrix() const
Translation operator*(const Translation &other) const
Translation< double, 2 > Translation2d
ConstLinearPart linear() const
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Translation< double, 3 > Translation3d
Matrix< Scalar, Dim, 1 > VectorType
#define Translation
Definition: All.h:43
Translation(const VectorType &vector)
Represents an homogeneous transformation in a N dimensional space.
RotationMatrixType toRotationMatrix() const
internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
bool isApprox(const Translation &other, typename NumTraits< Scalar >::Real prec=precision< Scalar >()) const


tuw_aruco
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:41:01