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 // 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 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
00026 
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 Scaling<Scalar,Dim> ScalingType;
00058   typedef Transform<Scalar,Dim> TransformType;
00059 
00060 protected:
00061 
00062   VectorType m_coeffs;
00063 
00064 public:
00065 
00067   Translation() {}
00069   inline Translation(const Scalar& sx, const Scalar& sy)
00070   {
00071     ei_assert(Dim==2);
00072     m_coeffs.x() = sx;
00073     m_coeffs.y() = sy;
00074   }
00076   inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00077   {
00078     ei_assert(Dim==3);
00079     m_coeffs.x() = sx;
00080     m_coeffs.y() = sy;
00081     m_coeffs.z() = sz;
00082   }
00084   explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00085 
00086   const VectorType& vector() const { return m_coeffs; }
00087   VectorType& vector() { return m_coeffs; }
00088 
00090   inline Translation operator* (const Translation& other) const
00091   { return Translation(m_coeffs + other.m_coeffs); }
00092 
00094   inline TransformType operator* (const ScalingType& other) const;
00095 
00097   inline TransformType operator* (const LinearMatrixType& linear) const;
00098 
00099   template<typename Derived>
00100   inline TransformType operator*(const RotationBase<Derived,Dim>& r) const
00101   { return *this * r.toRotationMatrix(); }
00102 
00104   // its a nightmare to define a templated friend function outside its declaration
00105   friend inline TransformType operator* (const LinearMatrixType& linear, const Translation& t)
00106   {
00107     TransformType res;
00108     res.matrix().setZero();
00109     res.linear() = linear;
00110     res.translation() = linear * t.m_coeffs;
00111     res.matrix().row(Dim).setZero();
00112     res(Dim,Dim) = Scalar(1);
00113     return res;
00114   }
00115 
00117   inline TransformType operator* (const TransformType& t) const;
00118 
00120   inline VectorType operator* (const VectorType& other) const
00121   { return m_coeffs + other; }
00122 
00124   Translation inverse() const { return Translation(-m_coeffs); }
00125 
00126   Translation& operator=(const Translation& other)
00127   {
00128     m_coeffs = other.m_coeffs;
00129     return *this;
00130   }
00131 
00137   template<typename NewScalarType>
00138   inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00139   { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00140 
00142   template<typename OtherScalarType>
00143   inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00144   { m_coeffs = other.vector().template cast<Scalar>(); }
00145 
00150   bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00151   { return m_coeffs.isApprox(other.m_coeffs, prec); }
00152 
00153 };
00154 
00157 typedef Translation<float, 2> Translation2f;
00158 typedef Translation<double,2> Translation2d;
00159 typedef Translation<float, 3> Translation3f;
00160 typedef Translation<double,3> Translation3d;
00162 
00163 
00164 template<typename Scalar, int Dim>
00165 inline typename Translation<Scalar,Dim>::TransformType
00166 Translation<Scalar,Dim>::operator* (const ScalingType& other) const
00167 {
00168   TransformType res;
00169   res.matrix().setZero();
00170   res.linear().diagonal() = other.coeffs();
00171   res.translation() = m_coeffs;
00172   res(Dim,Dim) = Scalar(1);
00173   return res;
00174 }
00175 
00176 template<typename Scalar, int Dim>
00177 inline typename Translation<Scalar,Dim>::TransformType
00178 Translation<Scalar,Dim>::operator* (const LinearMatrixType& linear) const
00179 {
00180   TransformType res;
00181   res.matrix().setZero();
00182   res.linear() = linear;
00183   res.translation() = m_coeffs;
00184   res.matrix().row(Dim).setZero();
00185   res(Dim,Dim) = Scalar(1);
00186   return res;
00187 }
00188 
00189 template<typename Scalar, int Dim>
00190 inline typename Translation<Scalar,Dim>::TransformType
00191 Translation<Scalar,Dim>::operator* (const TransformType& t) const
00192 {
00193   TransformType res = t;
00194   res.pretranslate(m_coeffs);
00195   return res;
00196 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:11