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 <gael.guennebaud@inria.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 #ifndef EIGEN_TRANSLATION_H
11 #define EIGEN_TRANSLATION_H
12 
13 namespace Eigen {
14 
29 template<typename _Scalar, int _Dim>
30 class Translation
31 {
32 public:
35  enum { Dim = _Dim };
37  typedef _Scalar Scalar;
46 
47 protected:
48 
49  VectorType m_coeffs;
50 
51 public:
52 
56  inline Translation(const Scalar& sx, const Scalar& sy)
57  {
58  eigen_assert(Dim==2);
59  m_coeffs.x() = sx;
60  m_coeffs.y() = sy;
61  }
63  inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
64  {
65  eigen_assert(Dim==3);
66  m_coeffs.x() = sx;
67  m_coeffs.y() = sy;
68  m_coeffs.z() = sz;
69  }
71  explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
72 
74  inline Scalar x() const { return m_coeffs.x(); }
76  inline Scalar y() const { return m_coeffs.y(); }
78  inline Scalar z() const { return m_coeffs.z(); }
79 
81  inline Scalar& x() { return m_coeffs.x(); }
83  inline Scalar& y() { return m_coeffs.y(); }
85  inline Scalar& z() { return m_coeffs.z(); }
86 
87  const VectorType& vector() const { return m_coeffs; }
88  VectorType& vector() { return m_coeffs; }
89 
90  const VectorType& translation() const { return m_coeffs; }
91  VectorType& translation() { return m_coeffs; }
92 
94  inline Translation operator* (const Translation& other) const
95  { return Translation(m_coeffs + other.m_coeffs); }
96 
98  inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
99 
101  template<typename OtherDerived>
102  inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
103 
105  template<typename Derived>
106  inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const
107  { return *this * IsometryTransformType(r); }
108 
110  // its a nightmare to define a templated friend function outside its declaration
111  template<typename OtherDerived> friend
112  inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
113  {
114  AffineTransformType res;
115  res.matrix().setZero();
116  res.linear() = linear.derived();
117  res.translation() = linear.derived() * t.m_coeffs;
118  res.matrix().row(Dim).setZero();
119  res(Dim,Dim) = Scalar(1);
120  return res;
121  }
122 
124  template<int Mode, int Options>
126  {
128  res.pretranslate(m_coeffs);
129  return res;
130  }
131 
133  inline VectorType operator* (const VectorType& other) const
134  { return m_coeffs + other; }
135 
137  Translation inverse() const { return Translation(-m_coeffs); }
138 
140  {
141  m_coeffs = other.m_coeffs;
142  return *this;
143  }
144 
145  static const Translation Identity() { return Translation(VectorType::Zero()); }
146 
152  template<typename NewScalarType>
155 
157  template<typename OtherScalarType>
158  inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
159  { m_coeffs = other.vector().template cast<Scalar>(); }
160 
166  { return m_coeffs.isApprox(other.m_coeffs, prec); }
167 
168 };
169 
177 
178 template<typename Scalar, int Dim>
181 {
182  AffineTransformType res;
183  res.matrix().setZero();
184  res.linear().diagonal().fill(other.factor());
185  res.translation() = m_coeffs;
186  res(Dim,Dim) = Scalar(1);
187  return res;
188 }
189 
190 template<typename Scalar, int Dim>
191 template<typename OtherDerived>
194 {
195  AffineTransformType res;
196  res.matrix().setZero();
197  res.linear() = linear.derived();
198  res.translation() = m_coeffs;
199  res.matrix().row(Dim).setZero();
200  res(Dim,Dim) = Scalar(1);
201  return res;
202 }
203 
204 } // end namespace Eigen
205 
206 #endif // EIGEN_TRANSLATION_H
Translation(const Scalar &sx, const Scalar &sy, const Scalar &sz)
bool isApprox(const Translation &other, typename NumTraits< Scalar >::Real prec=NumTraits< Scalar >::dummy_precision()) const
Scalar & z()
Retruns the z-translation as a reference.
const VectorType & vector() const
Translation< float, 3 > Translation3f
Translation & operator=(const Translation &other)
Matrix< Scalar, Dim, Dim > LinearMatrixType
const Scalar & factor() const
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Translation inverse() const
const VectorType & translation() const
Translation(const Scalar &sx, const Scalar &sy)
Scalar & y()
Retruns the y-translation as a reference.
Derived & derived()
Definition: EigenBase.h:34
static const Translation Identity()
VectorType & translation()
Represents a translation transformation.
Transform & pretranslate(const MatrixBase< OtherDerived > &other)
Scalar x() const
Retruns the x-translation by value.
Translation< float, 2 > Translation2f
Scalar y() const
Retruns the y-translation by value.
Translation(const Translation< OtherScalarType, Dim > &other)
Transform< Scalar, Dim, Affine > AffineTransformType
Common base class for compact rotation representations.
Derived & setZero(Index size)
ConstTranslationPart translation() const
Transform< Scalar, Dim, Isometry > IsometryTransformType
Scalar & x()
Retruns the x-translation as a reference.
const MatrixType & matrix() const
Translation operator*(const Translation &other) const
IsometryTransformType operator*(const RotationBase< Derived, Dim > &r) const
Translation< double, 2 > Translation2d
Scalar z() const
Retruns the z-translation by value.
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 eigen_assert(x)
#define Translation
Definition: All.h:43
friend AffineTransformType operator*(const EigenBase< OtherDerived > &linear, const Translation &t)
Translation(const VectorType &vector)
Represents an homogeneous transformation in a N dimensional space.
internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const


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