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 
54  EIGEN_DEVICE_FUNC Translation() {}
56  EIGEN_DEVICE_FUNC 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  EIGEN_DEVICE_FUNC 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  EIGEN_DEVICE_FUNC explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
72 
74  EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); }
76  EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); }
78  EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); }
79 
81  EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); }
83  EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); }
85  EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); }
86 
87  EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; }
88  EIGEN_DEVICE_FUNC VectorType& vector() { return m_coeffs; }
89 
90  EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; }
91  EIGEN_DEVICE_FUNC VectorType& translation() { return m_coeffs; }
92 
94  EIGEN_DEVICE_FUNC inline Translation operator* (const Translation& other) const
95  { return Translation(m_coeffs + other.m_coeffs); }
96 
98  EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
99 
101  template<typename OtherDerived>
102  EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
103 
105  template<typename Derived>
106  EIGEN_DEVICE_FUNC 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  EIGEN_DEVICE_FUNC 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  template<typename Derived>
135  operator* (const MatrixBase<Derived>& vec) const
136  { return m_coeffs + vec.derived(); }
137 
139  Translation inverse() const { return Translation(-m_coeffs); }
140 
142  {
143  m_coeffs = other.m_coeffs;
144  return *this;
145  }
146 
147  static const Translation Identity() { return Translation(VectorType::Zero()); }
148 
154  template<typename NewScalarType>
157 
159  template<typename OtherScalarType>
160  EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
161  { m_coeffs = other.vector().template cast<Scalar>(); }
162 
167  EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
168  { return m_coeffs.isApprox(other.m_coeffs, prec); }
169 
170 };
171 
179 
180 template<typename Scalar, int Dim>
181 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
183 {
184  AffineTransformType res;
185  res.matrix().setZero();
186  res.linear().diagonal().fill(other.factor());
187  res.translation() = m_coeffs;
188  res(Dim,Dim) = Scalar(1);
189  return res;
190 }
191 
192 template<typename Scalar, int Dim>
193 template<typename OtherDerived>
194 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
196 {
197  AffineTransformType res;
198  res.matrix().setZero();
199  res.linear() = linear.derived();
200  res.translation() = m_coeffs;
201  res.matrix().row(Dim).setZero();
202  res(Dim,Dim) = Scalar(1);
203  return res;
204 }
205 
206 } // end namespace Eigen
207 
208 #endif // EIGEN_TRANSLATION_H
EIGEN_DEVICE_FUNC VectorType & translation()
Definition: Translation.h:91
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
EIGEN_DEVICE_FUNC Scalar y() const
Retruns the y-translation by value.
Definition: Translation.h:76
Translation & operator=(const Translation &other)
Definition: Translation.h:141
Translation< double, 3 > Translation3d
Definition: Translation.h:177
Matrix< Scalar, Dim, Dim > LinearMatrixType
Definition: Translation.h:41
const Scalar & factor() const
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
EIGEN_DEVICE_FUNC const VectorType & vector() const
Definition: Translation.h:87
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
Translation inverse() const
Definition: Translation.h:139
EIGEN_DEVICE_FUNC ConstTranslationPart translation() const
Definition: Transform.h:410
VectorType m_coeffs
Definition: Translation.h:49
static const Translation Identity()
Definition: Translation.h:147
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:691
Translation< float, 3 > Translation3f
Definition: Translation.h:176
EIGEN_DEVICE_FUNC internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
Definition: Translation.h:155
Represents a translation transformation.
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
EIGEN_DEVICE_FUNC VectorType & vector()
Definition: Translation.h:88
EIGEN_DEVICE_FUNC Translation(const VectorType &vector)
Definition: Translation.h:71
EIGEN_DEVICE_FUNC Translation(const Scalar &sx, const Scalar &sy)
Definition: Translation.h:56
EIGEN_DEVICE_FUNC Transform & pretranslate(const MatrixBase< OtherDerived > &other)
Translation< float, 2 > Translation2f
Definition: Translation.h:174
EIGEN_DEVICE_FUNC const MatrixType & matrix() const
Definition: Transform.h:395
Transform< Scalar, Dim, Affine > AffineTransformType
Definition: Translation.h:43
#define eigen_assert(x)
Definition: Macros.h:579
EIGEN_DEVICE_FUNC const VectorType & translation() const
Definition: Translation.h:90
Common base class for compact rotation representations.
EIGEN_DEVICE_FUNC ConstLinearPart linear() const
Definition: Transform.h:400
EIGEN_DEVICE_FUNC Scalar z() const
Retruns the z-translation by value.
Definition: Translation.h:78
Transform< Scalar, Dim, Isometry > IsometryTransformType
Definition: Translation.h:45
EIGEN_DEVICE_FUNC Translation()
Definition: Translation.h:54
EIGEN_DEVICE_FUNC Scalar & y()
Retruns the y-translation as a reference.
Definition: Translation.h:83
EIGEN_DEVICE_FUNC Scalar & z()
Retruns the z-translation as a reference.
Definition: Translation.h:85
EIGEN_DEVICE_FUNC IsometryTransformType operator*(const RotationBase< Derived, Dim > &r) const
Definition: Translation.h:106
EIGEN_DEVICE_FUNC Translation(const Scalar &sx, const Scalar &sy, const Scalar &sz)
Definition: Translation.h:63
Translation< double, 2 > Translation2d
Definition: Translation.h:175
Matrix< Scalar, Dim, 1 > VectorType
Definition: Translation.h:39
EIGEN_DEVICE_FUNC Scalar & x()
Retruns the x-translation as a reference.
Definition: Translation.h:81
friend EIGEN_DEVICE_FUNC AffineTransformType operator*(const EigenBase< OtherDerived > &linear, const Translation &t)
Definition: Translation.h:112
EIGEN_DEVICE_FUNC Scalar x() const
Retruns the x-translation by value.
Definition: Translation.h:74
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:45
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
EIGEN_DEVICE_FUNC Translation operator*(const Translation &other) const
Definition: Translation.h:94
EIGEN_DEVICE_FUNC Translation(const Translation< OtherScalarType, Dim > &other)
Definition: Translation.h:160
Represents an homogeneous transformation in a N dimensional space.
EIGEN_DEVICE_FUNC bool isApprox(const Translation &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Translation.h:167
Point2 t(10, 10)
Definition: pytypes.h:897


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:51:06