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  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 
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 
141  static const Translation Identity() { return Translation(VectorType::Zero()); }
142 
148  template<typename NewScalarType>
151 
153  template<typename OtherScalarType>
155  { m_coeffs = other.vector().template cast<Scalar>(); }
156 
162  { return m_coeffs.isApprox(other.m_coeffs, prec); }
163 
164 };
165 
173 
174 template<typename Scalar, int Dim>
177 {
178  AffineTransformType res;
179  res.matrix().setZero();
180  res.linear().diagonal().fill(other.factor());
181  res.translation() = m_coeffs;
182  res(Dim,Dim) = Scalar(1);
183  return res;
184 }
185 
186 template<typename Scalar, int Dim>
187 template<typename OtherDerived>
190 {
191  AffineTransformType res;
192  res.matrix().setZero();
193  res.linear() = linear.derived();
194  res.translation() = m_coeffs;
195  res.matrix().row(Dim).setZero();
196  res(Dim,Dim) = Scalar(1);
197  return res;
198 }
199 
200 } // end namespace Eigen
201 
202 #endif // EIGEN_TRANSLATION_H
EIGEN_DEVICE_FUNC VectorType & translation()
Definition: Translation.h:91
EIGEN_DEVICE_FUNC const VectorType & translation() const
Definition: Translation.h:90
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
EIGEN_DEVICE_FUNC Scalar z() const
Returns the z-translation by value.
Definition: Translation.h:78
Translation< double, 3 > Translation3d
Definition: Translation.h:171
Matrix< Scalar, Dim, Dim > LinearMatrixType
Definition: Translation.h:41
EIGEN_DEVICE_FUNC Translation operator*(const Translation &other) const
Definition: Translation.h:94
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
const Scalar & factor() const
VectorType m_coeffs
Definition: Translation.h:49
static const Translation Identity()
Definition: Translation.h:141
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:842
Translation< float, 3 > Translation3f
Definition: Translation.h:170
Represents a translation transformation.
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
EIGEN_DEVICE_FUNC const MatrixType & matrix() const
Definition: Transform.h:389
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 bool isApprox(const Translation &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Translation.h:161
EIGEN_DEVICE_FUNC ConstTranslationPart translation() const
Definition: Transform.h:404
EIGEN_DEVICE_FUNC const VectorType & vector() const
Definition: Translation.h:87
EIGEN_DEVICE_FUNC Transform & pretranslate(const MatrixBase< OtherDerived > &other)
Translation< float, 2 > Translation2f
Definition: Translation.h:168
EIGEN_DEVICE_FUNC ConstLinearPart linear() const
Definition: Transform.h:394
EIGEN_DEVICE_FUNC internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
Definition: Translation.h:149
Translation inverse() const
Definition: Translation.h:139
Transform< Scalar, Dim, Affine > AffineTransformType
Definition: Translation.h:43
#define eigen_assert(x)
Definition: Macros.h:1037
EIGEN_DEVICE_FUNC Scalar y() const
Returns the y-translation by value.
Definition: Translation.h:76
Represents a generic uniform scaling transformation.
Common base class for compact rotation representations.
EIGEN_DEVICE_FUNC Scalar x() const
Returns the x-translation by value.
Definition: Translation.h:74
Transform< Scalar, Dim, Isometry > IsometryTransformType
Definition: Translation.h:45
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
EIGEN_DEVICE_FUNC Translation()
Definition: Translation.h:54
EIGEN_DEVICE_FUNC Scalar & y()
Returns the y-translation as a reference.
Definition: Translation.h:83
EIGEN_DEVICE_FUNC Scalar & z()
Returns 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:169
Matrix< Scalar, Dim, 1 > VectorType
Definition: Translation.h:39
EIGEN_DEVICE_FUNC Scalar & x()
Returns 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 Derived & derived()
Definition: EigenBase.h:46
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
EIGEN_DEVICE_FUNC Translation(const Translation< OtherScalarType, Dim > &other)
Definition: Translation.h:154
Represents an homogeneous transformation in a N dimensional space.
Point2 t(10, 10)
Definition: pytypes.h:1370


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:22