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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
31 template<typename Scalar_, int Dim_>
33 {
34 public:
37  enum { Dim = Dim_ };
39  typedef Scalar_ Scalar;
48 
49 protected:
50 
52 
53 public:
54 
58  EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy)
59  {
60  eigen_assert(Dim==2);
61  m_coeffs.x() = sx;
62  m_coeffs.y() = sy;
63  }
65  EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
66  {
67  eigen_assert(Dim==3);
68  m_coeffs.x() = sx;
69  m_coeffs.y() = sy;
70  m_coeffs.z() = sz;
71  }
74 
76  EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); }
78  EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); }
80  EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); }
81 
83  EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); }
85  EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); }
87  EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); }
88 
89  EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; }
91 
92  EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; }
94 
97  { return Translation(m_coeffs + other.m_coeffs); }
98 
101 
103  template<typename OtherDerived>
105 
107  template<typename Derived>
109  { return *this * IsometryTransformType(r); }
110 
112  // its a nightmare to define a templated friend function outside its declaration
113  template<typename OtherDerived> friend
115  {
117  res.matrix().setZero();
118  res.linear() = linear.derived();
119  res.translation() = linear.derived() * t.m_coeffs;
120  res.matrix().row(Dim).setZero();
121  res(Dim,Dim) = Scalar(1);
122  return res;
123  }
124 
126  template<int Mode, int Options>
128  {
130  res.pretranslate(m_coeffs);
131  return res;
132  }
133 
135  template<typename Derived>
136  inline std::enable_if_t<Derived::IsVectorAtCompileTime,VectorType>
137  operator* (const MatrixBase<Derived>& vec) const
138  { return m_coeffs + vec.derived(); }
139 
141  Translation inverse() const { return Translation(-m_coeffs); }
142 
143  static const Translation Identity() { return Translation(VectorType::Zero()); }
144 
150  template<typename NewScalarType>
151  EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
152  { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
153 
155  template<typename OtherScalarType>
157  { m_coeffs = other.vector().template cast<Scalar>(); }
158 
164  { return m_coeffs.isApprox(other.m_coeffs, prec); }
165 
166 };
167 
175 
176 template<typename Scalar, int Dim>
179 {
181  res.matrix().setZero();
182  res.linear().diagonal().fill(other.factor());
183  res.translation() = m_coeffs;
184  res(Dim,Dim) = Scalar(1);
185  return res;
186 }
187 
188 template<typename Scalar, int Dim>
189 template<typename OtherDerived>
192 {
194  res.matrix().setZero();
195  res.linear() = linear.derived();
196  res.translation() = m_coeffs;
197  res.matrix().row(Dim).setZero();
198  res(Dim,Dim) = Scalar(1);
199  return res;
200 }
201 
202 } // end namespace Eigen
203 
204 #endif // EIGEN_TRANSLATION_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define eigen_assert(x)
Definition: Macros.h:902
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:921
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Common base class for compact rotation representations.
Definition: RotationBase.h:32
Represents an homogeneous transformation in a N dimensional space.
Definition: Transform.h:207
Represents a translation transformation.
Definition: Translation.h:33
Matrix< Scalar, Dim, 1 > VectorType
Definition: Translation.h:41
Translation(const VectorType &vector)
Definition: Translation.h:73
Scalar z() const
Returns the z-translation by value.
Definition: Translation.h:80
VectorType & vector()
Definition: Translation.h:90
VectorType m_coeffs
Definition: Translation.h:51
Translation operator*(const Translation &other) const
Definition: Translation.h:96
Scalar & x()
Returns the x-translation as a reference.
Definition: Translation.h:83
Matrix< Scalar, Dim, Dim > LinearMatrixType
Definition: Translation.h:43
Transform< Scalar, Dim, Isometry > IsometryTransformType
Definition: Translation.h:47
Transform< Scalar, Dim, Affine > AffineTransformType
Definition: Translation.h:45
internal::cast_return_type< Translation, Translation< NewScalarType, Dim > >::type cast() const
Definition: Translation.h:151
IsometryTransformType operator*(const RotationBase< Derived, Dim > &r) const
Definition: Translation.h:108
static const Translation Identity()
Definition: Translation.h:143
bool isApprox(const Translation &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition: Translation.h:163
const VectorType & vector() const
Definition: Translation.h:89
Scalar & z()
Returns the z-translation as a reference.
Definition: Translation.h:87
Translation(const Scalar &sx, const Scalar &sy, const Scalar &sz)
Definition: Translation.h:65
const VectorType & translation() const
Definition: Translation.h:92
friend AffineTransformType operator*(const EigenBase< OtherDerived > &linear, const Translation &t)
Definition: Translation.h:114
VectorType & translation()
Definition: Translation.h:93
Scalar x() const
Returns the x-translation by value.
Definition: Translation.h:76
Translation(const Scalar &sx, const Scalar &sy)
Definition: Translation.h:58
Scalar y() const
Returns the y-translation by value.
Definition: Translation.h:78
Translation(const Translation< OtherScalarType, Dim > &other)
Definition: Translation.h:156
Translation inverse() const
Definition: Translation.h:141
Scalar & y()
Returns the y-translation as a reference.
Definition: Translation.h:85
Represents a generic uniform scaling transformation.
Definition: Scaling.h:52
const Scalar & factor() const
Definition: Scaling.h:68
: InteropHeaders
Definition: Core:139
Translation< float, 2 > Translation2f
Definition: Translation.h:170
Translation< double, 2 > Translation2d
Definition: Translation.h:171
Translation< float, 3 > Translation3f
Definition: Translation.h:172
Translation< double, 3 > Translation3d
Definition: Translation.h:173
Derived & derived()
Definition: EigenBase.h:48
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:231