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 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_TRANSLATION_H
26 #define EIGEN_TRANSLATION_H
27 
28 namespace Eigen {
29 
44 template<typename _Scalar, int _Dim>
46 {
47 public:
50  enum { Dim = _Dim };
52  typedef _Scalar Scalar;
61 
62 protected:
63 
65 
66 public:
67 
71  inline Translation(const Scalar& sx, const Scalar& sy)
72  {
73  eigen_assert(Dim==2);
74  m_coeffs.x() = sx;
75  m_coeffs.y() = sy;
76  }
78  inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
79  {
80  eigen_assert(Dim==3);
81  m_coeffs.x() = sx;
82  m_coeffs.y() = sy;
83  m_coeffs.z() = sz;
84  }
86  explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
87 
89  inline Scalar x() const { return m_coeffs.x(); }
91  inline Scalar y() const { return m_coeffs.y(); }
93  inline Scalar z() const { return m_coeffs.z(); }
94 
96  inline Scalar& x() { return m_coeffs.x(); }
98  inline Scalar& y() { return m_coeffs.y(); }
100  inline Scalar& z() { return m_coeffs.z(); }
101 
102  const VectorType& vector() const { return m_coeffs; }
103  VectorType& vector() { return m_coeffs; }
104 
105  const VectorType& translation() const { return m_coeffs; }
107 
109  inline Translation operator* (const Translation& other) const
110  { return Translation(m_coeffs + other.m_coeffs); }
111 
113  inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
114 
116  template<typename OtherDerived>
117  inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
118 
120  template<typename Derived>
122  { return *this * IsometryTransformType(r); }
123 
125  // its a nightmare to define a templated friend function outside its declaration
126  template<typename OtherDerived> friend
128  {
130  res.matrix().setZero();
131  res.linear() = linear.derived();
132  res.translation() = linear.derived() * t.m_coeffs;
133  res.matrix().row(Dim).setZero();
134  res(Dim,Dim) = Scalar(1);
135  return res;
136  }
137 
139  template<int Mode, int Options>
141  {
143  res.pretranslate(m_coeffs);
144  return res;
145  }
146 
148  inline VectorType operator* (const VectorType& other) const
149  { return m_coeffs + other; }
150 
152  Translation inverse() const { return Translation(-m_coeffs); }
153 
155  {
156  m_coeffs = other.m_coeffs;
157  return *this;
158  }
159 
160  static const Translation Identity() { return Translation(VectorType::Zero()); }
161 
167  template<typename NewScalarType>
168  inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
169  { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
170 
172  template<typename OtherScalarType>
173  inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
174  { m_coeffs = other.vector().template cast<Scalar>(); }
175 
181  { return m_coeffs.isApprox(other.m_coeffs, prec); }
182 
183 };
184 
192 
193 template<typename Scalar, int Dim>
196 {
198  res.matrix().setZero();
199  res.linear().diagonal().fill(other.factor());
200  res.translation() = m_coeffs;
201  res(Dim,Dim) = Scalar(1);
202  return res;
203 }
204 
205 template<typename Scalar, int Dim>
206 template<typename OtherDerived>
209 {
211  res.matrix().setZero();
212  res.linear() = linear.derived();
213  res.translation() = m_coeffs;
214  res.matrix().row(Dim).setZero();
215  res(Dim,Dim) = Scalar(1);
216  return res;
217 }
218 
219 } // end namespace Eigen
220 
221 #endif // EIGEN_TRANSLATION_H