Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/eigen3/Eigen/src/Geometry/Translation.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_TRANSLATION_H
0011 #define EIGEN_TRANSLATION_H
0012 
0013 namespace Eigen { 
0014 
0015 /** \geometry_module \ingroup Geometry_Module
0016   *
0017   * \class Translation
0018   *
0019   * \brief Represents a translation transformation
0020   *
0021   * \tparam _Scalar the scalar type, i.e., the type of the coefficients.
0022   * \tparam _Dim the  dimension of the space, can be a compile time value or Dynamic
0023   *
0024   * \note This class is not aimed to be used to store a translation transformation,
0025   * but rather to make easier the constructions and updates of Transform objects.
0026   *
0027   * \sa class Scaling, class Transform
0028   */
0029 template<typename _Scalar, int _Dim>
0030 class Translation
0031 {
0032 public:
0033   EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
0034   /** dimension of the space */
0035   enum { Dim = _Dim };
0036   /** the scalar type of the coefficients */
0037   typedef _Scalar Scalar;
0038   /** corresponding vector type */
0039   typedef Matrix<Scalar,Dim,1> VectorType;
0040   /** corresponding linear transformation matrix type */
0041   typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
0042   /** corresponding affine transformation type */
0043   typedef Transform<Scalar,Dim,Affine> AffineTransformType;
0044   /** corresponding isometric transformation type */
0045   typedef Transform<Scalar,Dim,Isometry> IsometryTransformType;
0046 
0047 protected:
0048 
0049   VectorType m_coeffs;
0050 
0051 public:
0052 
0053   /** Default constructor without initialization. */
0054   EIGEN_DEVICE_FUNC Translation() {}
0055   /**  */
0056   EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy)
0057   {
0058     eigen_assert(Dim==2);
0059     m_coeffs.x() = sx;
0060     m_coeffs.y() = sy;
0061   }
0062   /**  */
0063   EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
0064   {
0065     eigen_assert(Dim==3);
0066     m_coeffs.x() = sx;
0067     m_coeffs.y() = sy;
0068     m_coeffs.z() = sz;
0069   }
0070   /** Constructs and initialize the translation transformation from a vector of translation coefficients */
0071   EIGEN_DEVICE_FUNC explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
0072 
0073   /** \brief Returns the x-translation by value. **/
0074   EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); }
0075   /** \brief Returns the y-translation by value. **/
0076   EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); }
0077   /** \brief Returns the z-translation by value. **/
0078   EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); }
0079 
0080   /** \brief Returns the x-translation as a reference. **/
0081   EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); }
0082   /** \brief Returns the y-translation as a reference. **/
0083   EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); }
0084   /** \brief Returns the z-translation as a reference. **/
0085   EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); }
0086 
0087   EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; }
0088   EIGEN_DEVICE_FUNC VectorType& vector() { return m_coeffs; }
0089 
0090   EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; }
0091   EIGEN_DEVICE_FUNC VectorType& translation() { return m_coeffs; }
0092 
0093   /** Concatenates two translation */
0094   EIGEN_DEVICE_FUNC inline Translation operator* (const Translation& other) const
0095   { return Translation(m_coeffs + other.m_coeffs); }
0096 
0097   /** Concatenates a translation and a uniform scaling */
0098   EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
0099 
0100   /** Concatenates a translation and a linear transformation */
0101   template<typename OtherDerived>
0102   EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
0103 
0104   /** Concatenates a translation and a rotation */
0105   template<typename Derived>
0106   EIGEN_DEVICE_FUNC inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const
0107   { return *this * IsometryTransformType(r); }
0108 
0109   /** \returns the concatenation of a linear transformation \a l with the translation \a t */
0110   // its a nightmare to define a templated friend function outside its declaration
0111   template<typename OtherDerived> friend
0112   EIGEN_DEVICE_FUNC inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
0113   {
0114     AffineTransformType res;
0115     res.matrix().setZero();
0116     res.linear() = linear.derived();
0117     res.translation() = linear.derived() * t.m_coeffs;
0118     res.matrix().row(Dim).setZero();
0119     res(Dim,Dim) = Scalar(1);
0120     return res;
0121   }
0122 
0123   /** Concatenates a translation and a transformation */
0124   template<int Mode, int Options>
0125   EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
0126   {
0127     Transform<Scalar,Dim,Mode> res = t;
0128     res.pretranslate(m_coeffs);
0129     return res;
0130   }
0131 
0132   /** Applies translation to vector */
0133   template<typename Derived>
0134   inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type
0135   operator* (const MatrixBase<Derived>& vec) const
0136   { return m_coeffs + vec.derived(); }
0137 
0138   /** \returns the inverse translation (opposite) */
0139   Translation inverse() const { return Translation(-m_coeffs); }
0140 
0141   static const Translation Identity() { return Translation(VectorType::Zero()); }
0142 
0143   /** \returns \c *this with scalar type casted to \a NewScalarType
0144     *
0145     * Note that if \a NewScalarType is equal to the current scalar type of \c *this
0146     * then this function smartly returns a const reference to \c *this.
0147     */
0148   template<typename NewScalarType>
0149   EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
0150   { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
0151 
0152   /** Copy constructor with scalar type conversion */
0153   template<typename OtherScalarType>
0154   EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
0155   { m_coeffs = other.vector().template cast<Scalar>(); }
0156 
0157   /** \returns \c true if \c *this is approximately equal to \a other, within the precision
0158     * determined by \a prec.
0159     *
0160     * \sa MatrixBase::isApprox() */
0161   EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
0162   { return m_coeffs.isApprox(other.m_coeffs, prec); }
0163 
0164 };
0165 
0166 /** \addtogroup Geometry_Module */
0167 //@{
0168 typedef Translation<float, 2> Translation2f;
0169 typedef Translation<double,2> Translation2d;
0170 typedef Translation<float, 3> Translation3f;
0171 typedef Translation<double,3> Translation3d;
0172 //@}
0173 
0174 template<typename Scalar, int Dim>
0175 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
0176 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
0177 {
0178   AffineTransformType res;
0179   res.matrix().setZero();
0180   res.linear().diagonal().fill(other.factor());
0181   res.translation() = m_coeffs;
0182   res(Dim,Dim) = Scalar(1);
0183   return res;
0184 }
0185 
0186 template<typename Scalar, int Dim>
0187 template<typename OtherDerived>
0188 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
0189 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
0190 {
0191   AffineTransformType res;
0192   res.matrix().setZero();
0193   res.linear() = linear.derived();
0194   res.translation() = m_coeffs;
0195   res.matrix().row(Dim).setZero();
0196   res(Dim,Dim) = Scalar(1);
0197   return res;
0198 }
0199 
0200 } // end namespace Eigen
0201 
0202 #endif // EIGEN_TRANSLATION_H