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. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
00011 
00012 namespace Eigen { 
00013 
00028 template<typename _Scalar, int _Dim>
00029 class Translation
00030 {
00031 public:
00032   EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
00034   enum { Dim = _Dim };
00036   typedef _Scalar Scalar;
00038   typedef Matrix<Scalar,Dim,1> VectorType;
00040   typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
00042   typedef Scaling<Scalar,Dim> ScalingType;
00044   typedef Transform<Scalar,Dim> TransformType;
00045 
00046 protected:
00047 
00048   VectorType m_coeffs;
00049 
00050 public:
00051 
00053   Translation() {}
00055   inline Translation(const Scalar& sx, const Scalar& sy)
00056   {
00057     ei_assert(Dim==2);
00058     m_coeffs.x() = sx;
00059     m_coeffs.y() = sy;
00060   }
00062   inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00063   {
00064     ei_assert(Dim==3);
00065     m_coeffs.x() = sx;
00066     m_coeffs.y() = sy;
00067     m_coeffs.z() = sz;
00068   }
00070   explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00071 
00072   const VectorType& vector() const { return m_coeffs; }
00073   VectorType& vector() { return m_coeffs; }
00074 
00076   inline Translation operator* (const Translation& other) const
00077   { return Translation(m_coeffs + other.m_coeffs); }
00078 
00080   inline TransformType operator* (const ScalingType& other) const;
00081 
00083   inline TransformType operator* (const LinearMatrixType& linear) const;
00084 
00085   template<typename Derived>
00086   inline TransformType operator*(const RotationBase<Derived,Dim>& r) const
00087   { return *this * r.toRotationMatrix(); }
00088 
00090   // its a nightmare to define a templated friend function outside its declaration
00091   friend inline TransformType operator* (const LinearMatrixType& linear, const Translation& t)
00092   {
00093     TransformType res;
00094     res.matrix().setZero();
00095     res.linear() = linear;
00096     res.translation() = linear * t.m_coeffs;
00097     res.matrix().row(Dim).setZero();
00098     res(Dim,Dim) = Scalar(1);
00099     return res;
00100   }
00101 
00103   inline TransformType operator* (const TransformType& t) const;
00104 
00106   inline VectorType operator* (const VectorType& other) const
00107   { return m_coeffs + other; }
00108 
00110   Translation inverse() const { return Translation(-m_coeffs); }
00111 
00112   Translation& operator=(const Translation& other)
00113   {
00114     m_coeffs = other.m_coeffs;
00115     return *this;
00116   }
00117 
00123   template<typename NewScalarType>
00124   inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00125   { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00126 
00128   template<typename OtherScalarType>
00129   inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00130   { m_coeffs = other.vector().template cast<Scalar>(); }
00131 
00136   bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00137   { return m_coeffs.isApprox(other.m_coeffs, prec); }
00138 
00139 };
00140 
00143 typedef Translation<float, 2> Translation2f;
00144 typedef Translation<double,2> Translation2d;
00145 typedef Translation<float, 3> Translation3f;
00146 typedef Translation<double,3> Translation3d;
00148 
00149 
00150 template<typename Scalar, int Dim>
00151 inline typename Translation<Scalar,Dim>::TransformType
00152 Translation<Scalar,Dim>::operator* (const ScalingType& other) const
00153 {
00154   TransformType res;
00155   res.matrix().setZero();
00156   res.linear().diagonal() = other.coeffs();
00157   res.translation() = m_coeffs;
00158   res(Dim,Dim) = Scalar(1);
00159   return res;
00160 }
00161 
00162 template<typename Scalar, int Dim>
00163 inline typename Translation<Scalar,Dim>::TransformType
00164 Translation<Scalar,Dim>::operator* (const LinearMatrixType& linear) const
00165 {
00166   TransformType res;
00167   res.matrix().setZero();
00168   res.linear() = linear;
00169   res.translation() = m_coeffs;
00170   res.matrix().row(Dim).setZero();
00171   res(Dim,Dim) = Scalar(1);
00172   return res;
00173 }
00174 
00175 template<typename Scalar, int Dim>
00176 inline typename Translation<Scalar,Dim>::TransformType
00177 Translation<Scalar,Dim>::operator* (const TransformType& t) const
00178 {
00179   TransformType res = t;
00180   res.pretranslate(m_coeffs);
00181   return res;
00182 }
00183 
00184 } // end namespace Eigen


win_eigen
Author(s): Daniel Stonier
autogenerated on Wed Sep 16 2015 07:12:25