Translation.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_TRANSLATION_H
00026 #define EIGEN_TRANSLATION_H
00027 
00042 template<typename _Scalar, int _Dim>
00043 class Translation
00044 {
00045 public:
00046   EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
00048   enum { Dim = _Dim };
00050   typedef _Scalar Scalar;
00052   typedef Matrix<Scalar,Dim,1> VectorType;
00054   typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
00056   typedef Transform<Scalar,Dim,Affine> AffineTransformType;
00057 
00058 protected:
00059 
00060   VectorType m_coeffs;
00061 
00062 public:
00063 
00065   Translation() {}
00067   inline Translation(const Scalar& sx, const Scalar& sy)
00068   {
00069     eigen_assert(Dim==2);
00070     m_coeffs.x() = sx;
00071     m_coeffs.y() = sy;
00072   }
00074   inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00075   {
00076     eigen_assert(Dim==3);
00077     m_coeffs.x() = sx;
00078     m_coeffs.y() = sy;
00079     m_coeffs.z() = sz;
00080   }
00082   explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00083 
00085   inline Scalar x() const { return m_coeffs.x(); }
00087   inline Scalar y() const { return m_coeffs.y(); }
00089   inline Scalar z() const { return m_coeffs.z(); }
00090 
00092   inline Scalar& x() { return m_coeffs.x(); }
00094   inline Scalar& y() { return m_coeffs.y(); }
00096   inline Scalar& z() { return m_coeffs.z(); }
00097 
00098   const VectorType& vector() const { return m_coeffs; }
00099   VectorType& vector() { return m_coeffs; }
00100 
00101   const VectorType& translation() const { return m_coeffs; }
00102   VectorType& translation() { return m_coeffs; }
00103 
00105   inline Translation operator* (const Translation& other) const
00106   { return Translation(m_coeffs + other.m_coeffs); }
00107 
00109   inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
00110 
00112   template<typename OtherDerived>
00113   inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
00114 
00116   template<typename Derived>
00117   inline AffineTransformType operator*(const RotationBase<Derived,Dim>& r) const
00118   { return *this * r.toRotationMatrix(); }
00119 
00121   // its a nightmare to define a templated friend function outside its declaration
00122   template<typename OtherDerived> friend
00123   inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
00124   {
00125     AffineTransformType res;
00126     res.matrix().setZero();
00127     res.linear() = linear.derived();
00128     res.translation() = linear.derived() * t.m_coeffs;
00129     res.matrix().row(Dim).setZero();
00130     res(Dim,Dim) = Scalar(1);
00131     return res;
00132   }
00133 
00135   template<int Mode, int Options>
00136   inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
00137   {
00138     Transform<Scalar,Dim,Mode> res = t;
00139     res.pretranslate(m_coeffs);
00140     return res;
00141   }
00142 
00144   inline VectorType operator* (const VectorType& other) const
00145   { return m_coeffs + other; }
00146 
00148   Translation inverse() const { return Translation(-m_coeffs); }
00149 
00150   Translation& operator=(const Translation& other)
00151   {
00152     m_coeffs = other.m_coeffs;
00153     return *this;
00154   }
00155 
00156   static const Translation Identity() { return Translation(VectorType::Zero()); }
00157 
00163   template<typename NewScalarType>
00164   inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00165   { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00166 
00168   template<typename OtherScalarType>
00169   inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00170   { m_coeffs = other.vector().template cast<Scalar>(); }
00171 
00176   bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00177   { return m_coeffs.isApprox(other.m_coeffs, prec); }
00178 
00179 };
00180 
00183 typedef Translation<float, 2> Translation2f;
00184 typedef Translation<double,2> Translation2d;
00185 typedef Translation<float, 3> Translation3f;
00186 typedef Translation<double,3> Translation3d;
00188 
00189 template<typename Scalar, int Dim>
00190 inline typename Translation<Scalar,Dim>::AffineTransformType
00191 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
00192 {
00193   AffineTransformType res;
00194   res.matrix().setZero();
00195   res.linear().diagonal().fill(other.factor());
00196   res.translation() = m_coeffs;
00197   res(Dim,Dim) = Scalar(1);
00198   return res;
00199 }
00200 
00201 template<typename Scalar, int Dim>
00202 template<typename OtherDerived>
00203 inline typename Translation<Scalar,Dim>::AffineTransformType
00204 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
00205 {
00206   AffineTransformType res;
00207   res.matrix().setZero();
00208   res.linear() = linear.derived();
00209   res.translation() = m_coeffs;
00210   res.matrix().row(Dim).setZero();
00211   res(Dim,Dim) = Scalar(1);
00212   return res;
00213 }
00214 
00215 #endif // EIGEN_TRANSLATION_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:46