Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.3.9
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 <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>
31 {
32 public:
33  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
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  {
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>
134  inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type
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>
149  EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
150  { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
151 
153  template<typename OtherScalarType>
154  EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
155  { m_coeffs = other.vector().template cast<Scalar>(); }
156 
161  EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
162  { return m_coeffs.isApprox(other.m_coeffs, prec); }
163 
164 };
165 
168 typedef Translation<float, 2> Translation2f;
169 typedef Translation<double,2> Translation2d;
170 typedef Translation<float, 3> Translation3f;
171 typedef Translation<double,3> Translation3d;
173 
174 template<typename Scalar, int Dim>
175 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
177 {
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>
188 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
190 {
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::Translation::x
Scalar & x()
Retruns the x-translation as a reference.
Definition: Translation.h:81
Eigen::Translation::isApprox
bool isApprox(const Translation &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Translation.h:161
Eigen
Namespace containing all symbols from the Eigen library.
Definition: Core:309
Eigen::Translation::z
Scalar z() const
Retruns the z-translation by value.
Definition: Translation.h:78
Eigen::Transform
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:202
Eigen::Transform::matrix
const MatrixType & matrix() const
Definition: Transform.h:395
Eigen::EigenBase
Definition: EigenBase.h:30
Eigen::DenseCoeffsBase< Derived, DirectWriteAccessors >::derived
Derived & derived()
Definition: EigenBase.h:45
Eigen::Translation::inverse
Translation inverse() const
Definition: Translation.h:139
Eigen::Translation::AffineTransformType
Transform< Scalar, Dim, Affine > AffineTransformType
Definition: Translation.h:43
Eigen::Translation::operator*
friend AffineTransformType operator*(const EigenBase< OtherDerived > &linear, const Translation &t)
Definition: Translation.h:112
Eigen::Translation::Translation
Translation(const Translation< OtherScalarType, Dim > &other)
Definition: Translation.h:154
Eigen::Translation::operator*
Translation operator*(const Translation &other) const
Definition: Translation.h:94
Eigen::Translation::y
Scalar & y()
Retruns the y-translation as a reference.
Definition: Translation.h:83
Eigen::Translation::Translation
Translation()
Definition: Translation.h:54
Eigen::Translation::cast
internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
Definition: Translation.h:149
Eigen::RotationBase
Common base class for compact rotation representations.
Definition: RotationBase.h:30
Eigen::Translation::y
Scalar y() const
Retruns the y-translation by value.
Definition: Translation.h:76
Eigen::PlainObjectBase::setZero
Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:515
Eigen::Translation::operator*
IsometryTransformType operator*(const RotationBase< Derived, Dim > &r) const
Definition: Translation.h:106
Eigen::Translation::VectorType
Matrix< Scalar, Dim, 1 > VectorType
Definition: Translation.h:39
Eigen::Translation::IsometryTransformType
Transform< Scalar, Dim, Isometry > IsometryTransformType
Definition: Translation.h:45
Eigen::EigenBase::derived
Derived & derived()
Definition: EigenBase.h:45
Eigen::Translation::Translation
Translation(const VectorType &vector)
Definition: Translation.h:71
Eigen::Transform::linear
ConstLinearPart linear() const
Definition: Transform.h:400
Eigen::UniformScaling
Represents a generic uniform scaling transformation.
Definition: Scaling.h:34
Eigen::Transform::translation
ConstTranslationPart translation() const
Definition: Transform.h:410
Eigen::Translation
Represents a translation transformation.
Definition: Translation.h:31
Eigen::Matrix< Scalar, Dim, 1 >
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Eigen::Translation::Scalar
_Scalar Scalar
Definition: Translation.h:37
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:151
Eigen::Translation::z
Scalar & z()
Retruns the z-translation as a reference.
Definition: Translation.h:85
Eigen::Translation::x
Scalar x() const
Retruns the x-translation by value.
Definition: Translation.h:74
Eigen::Translation::LinearMatrixType
Matrix< Scalar, Dim, Dim > LinearMatrixType
Definition: Translation.h:41