Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Translation.h
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 // 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 #ifndef EIGEN_TRANSLATION_H 00011 #define EIGEN_TRANSLATION_H 00012 00013 namespace Eigen { 00014 00015 /** \geometry_module \ingroup Geometry_Module 00016 * 00017 * \class Translation 00018 * 00019 * \brief Represents a translation transformation 00020 * 00021 * \param _Scalar the scalar type, i.e., the type of the coefficients. 00022 * \param _Dim the dimension of the space, can be a compile time value or Dynamic 00023 * 00024 * \note This class is not aimed to be used to store a translation transformation, 00025 * but rather to make easier the constructions and updates of Transform objects. 00026 * 00027 * \sa class Scaling, class Transform 00028 */ 00029 template<typename _Scalar, int _Dim> 00030 class Translation 00031 { 00032 public: 00033 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim) 00034 /** dimension of the space */ 00035 enum { Dim = _Dim }; 00036 /** the scalar type of the coefficients */ 00037 typedef _Scalar Scalar; 00038 /** corresponding vector type */ 00039 typedef Matrix<Scalar,Dim,1> VectorType; 00040 /** corresponding linear transformation matrix type */ 00041 typedef Matrix<Scalar,Dim,Dim> LinearMatrixType; 00042 /** corresponding affine transformation type */ 00043 typedef Transform<Scalar,Dim,Affine> AffineTransformType; 00044 /** corresponding isometric transformation type */ 00045 typedef Transform<Scalar,Dim,Isometry> IsometryTransformType; 00046 00047 protected: 00048 00049 VectorType m_coeffs; 00050 00051 public: 00052 00053 /** Default constructor without initialization. */ 00054 Translation() {} 00055 /** */ 00056 inline Translation(const Scalar& sx, const Scalar& sy) 00057 { 00058 eigen_assert(Dim==2); 00059 m_coeffs.x() = sx; 00060 m_coeffs.y() = sy; 00061 } 00062 /** */ 00063 inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz) 00064 { 00065 eigen_assert(Dim==3); 00066 m_coeffs.x() = sx; 00067 m_coeffs.y() = sy; 00068 m_coeffs.z() = sz; 00069 } 00070 /** Constructs and initialize the translation transformation from a vector of translation coefficients */ 00071 explicit inline Translation(const VectorType & vector) : m_coeffs(vector) {} 00072 00073 /** \brief Retruns the x-translation by value. **/ 00074 inline Scalar x() const { return m_coeffs.x(); } 00075 /** \brief Retruns the y-translation by value. **/ 00076 inline Scalar y() const { return m_coeffs.y(); } 00077 /** \brief Retruns the z-translation by value. **/ 00078 inline Scalar z() const { return m_coeffs.z(); } 00079 00080 /** \brief Retruns the x-translation as a reference. **/ 00081 inline Scalar& x() { return m_coeffs.x(); } 00082 /** \brief Retruns the y-translation as a reference. **/ 00083 inline Scalar& y() { return m_coeffs.y(); } 00084 /** \brief Retruns the z-translation as a reference. **/ 00085 inline Scalar& z() { return m_coeffs.z(); } 00086 00087 const VectorType& vector() const { return m_coeffs; } 00088 VectorType& vector() { return m_coeffs; } 00089 00090 const VectorType& translation() const { return m_coeffs; } 00091 VectorType& translation() { return m_coeffs; } 00092 00093 /** Concatenates two translation */ 00094 inline Translation operator* (const Translation & other) const 00095 { return Translation(m_coeffs + other.m_coeffs); } 00096 00097 /** Concatenates a translation and a uniform scaling */ 00098 inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const; 00099 00100 /** Concatenates a translation and a linear transformation */ 00101 template<typename OtherDerived> 00102 inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const; 00103 00104 /** Concatenates a translation and a rotation */ 00105 template<typename Derived> 00106 inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const 00107 { return *this * IsometryTransformType(r); } 00108 00109 /** \returns the concatenation of a linear transformation \a l with the translation \a t */ 00110 // its a nightmare to define a templated friend function outside its declaration 00111 template<typename OtherDerived> friend 00112 inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation & t) 00113 { 00114 AffineTransformType res; 00115 res.matrix ().setZero(); 00116 res.linear () = linear.derived (); 00117 res.translation () = linear.derived () * t.m_coeffs; 00118 res.matrix ().row(Dim).setZero(); 00119 res(Dim,Dim) = Scalar(1); 00120 return res; 00121 } 00122 00123 /** Concatenates a translation and a transformation */ 00124 template<int Mode, int Options> 00125 inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options> & t) const 00126 { 00127 Transform<Scalar,Dim,Mode> res = t; 00128 res.pretranslate(m_coeffs); 00129 return res; 00130 } 00131 00132 /** Applies translation to vector */ 00133 inline VectorType operator* (const VectorType & other) const 00134 { return m_coeffs + other; } 00135 00136 /** \returns the inverse translation (opposite) */ 00137 Translation inverse () const { return Translation(-m_coeffs); } 00138 00139 Translation & operator=(const Translation & other) 00140 { 00141 m_coeffs = other.m_coeffs; 00142 return *this; 00143 } 00144 00145 static const Translation Identity() { return Translation(VectorType::Zero()); } 00146 00147 /** \returns \c *this with scalar type casted to \a NewScalarType 00148 * 00149 * Note that if \a NewScalarType is equal to the current scalar type of \c *this 00150 * then this function smartly returns a const reference to \c *this. 00151 */ 00152 template<typename NewScalarType> 00153 inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast () const 00154 { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); } 00155 00156 /** Copy constructor with scalar type conversion */ 00157 template<typename OtherScalarType> 00158 inline explicit Translation(const Translation<OtherScalarType,Dim> & other) 00159 { m_coeffs = other.vector().template cast<Scalar>(); } 00160 00161 /** \returns \c true if \c *this is approximately equal to \a other, within the precision 00162 * determined by \a prec. 00163 * 00164 * \sa MatrixBase::isApprox() */ 00165 bool isApprox (const Translation & other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const 00166 { return m_coeffs.isApprox(other.m_coeffs, prec); } 00167 00168 }; 00169 00170 /** \addtogroup Geometry_Module */ 00171 //@{ 00172 typedef Translation<float, 2> Translation2f; 00173 typedef Translation<double,2> Translation2d; 00174 typedef Translation<float, 3> Translation3f; 00175 typedef Translation<double,3> Translation3d; 00176 //@} 00177 00178 template<typename Scalar, int Dim> 00179 inline typename Translation<Scalar,Dim>::AffineTransformType 00180 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const 00181 { 00182 AffineTransformType res; 00183 res.matrix ().setZero(); 00184 res.linear ().diagonal().fill(other.factor()); 00185 res.translation () = m_coeffs; 00186 res(Dim,Dim) = Scalar(1); 00187 return res; 00188 } 00189 00190 template<typename Scalar, int Dim> 00191 template<typename OtherDerived> 00192 inline typename Translation<Scalar,Dim>::AffineTransformType 00193 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const 00194 { 00195 AffineTransformType res; 00196 res.matrix ().setZero(); 00197 res.linear () = linear.derived (); 00198 res.translation () = m_coeffs; 00199 res.matrix ().row(Dim).setZero(); 00200 res(Dim,Dim) = Scalar(1); 00201 return res; 00202 } 00203 00204 } // end namespace Eigen 00205 00206 #endif // EIGEN_TRANSLATION_H
Generated on Thu Nov 17 2022 22:01:30 by
1.7.2