Scaling.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 <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 Scaling
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 Translation<Scalar,Dim> TranslationType;
00044   typedef Transform<Scalar,Dim> TransformType;
00045 
00046 protected:
00047 
00048   VectorType m_coeffs;
00049 
00050 public:
00051 
00053   Scaling() {}
00055   explicit inline Scaling(const Scalar& s) { m_coeffs.setConstant(s); }
00057   inline Scaling(const Scalar& sx, const Scalar& sy)
00058   {
00059     ei_assert(Dim==2);
00060     m_coeffs.x() = sx;
00061     m_coeffs.y() = sy;
00062   }
00064   inline Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00065   {
00066     ei_assert(Dim==3);
00067     m_coeffs.x() = sx;
00068     m_coeffs.y() = sy;
00069     m_coeffs.z() = sz;
00070   }
00072   explicit inline Scaling(const VectorType& coeffs) : m_coeffs(coeffs) {}
00073 
00074   const VectorType& coeffs() const { return m_coeffs; }
00075   VectorType& coeffs() { return m_coeffs; }
00076 
00078   inline Scaling operator* (const Scaling& other) const
00079   { return Scaling(coeffs().cwise() * other.coeffs()); }
00080 
00082   inline TransformType operator* (const TranslationType& t) const;
00083 
00085   inline TransformType operator* (const TransformType& t) const;
00086 
00088   // TODO returns an expression
00089   inline LinearMatrixType operator* (const LinearMatrixType& other) const
00090   { return coeffs().asDiagonal() * other; }
00091 
00093   // TODO returns an expression
00094   friend inline LinearMatrixType operator* (const LinearMatrixType& other, const Scaling& s)
00095   { return other * s.coeffs().asDiagonal(); }
00096 
00097   template<typename Derived>
00098   inline LinearMatrixType operator*(const RotationBase<Derived,Dim>& r) const
00099   { return *this * r.toRotationMatrix(); }
00100 
00102   inline VectorType operator* (const VectorType& other) const
00103   { return coeffs().asDiagonal() * other; }
00104 
00106   inline Scaling inverse() const
00107   { return Scaling(coeffs().cwise().inverse()); }
00108 
00109   inline Scaling& operator=(const Scaling& other)
00110   {
00111     m_coeffs = other.m_coeffs;
00112     return *this;
00113   }
00114 
00120   template<typename NewScalarType>
00121   inline typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type cast() const
00122   { return typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type(*this); }
00123 
00125   template<typename OtherScalarType>
00126   inline explicit Scaling(const Scaling<OtherScalarType,Dim>& other)
00127   { m_coeffs = other.coeffs().template cast<Scalar>(); }
00128 
00133   bool isApprox(const Scaling& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00134   { return m_coeffs.isApprox(other.m_coeffs, prec); }
00135 
00136 };
00137 
00140 typedef Scaling<float, 2> Scaling2f;
00141 typedef Scaling<double,2> Scaling2d;
00142 typedef Scaling<float, 3> Scaling3f;
00143 typedef Scaling<double,3> Scaling3d;
00145 
00146 template<typename Scalar, int Dim>
00147 inline typename Scaling<Scalar,Dim>::TransformType
00148 Scaling<Scalar,Dim>::operator* (const TranslationType& t) const
00149 {
00150   TransformType res;
00151   res.matrix().setZero();
00152   res.linear().diagonal() = coeffs();
00153   res.translation() = m_coeffs.cwise() * t.vector();
00154   res(Dim,Dim) = Scalar(1);
00155   return res;
00156 }
00157 
00158 template<typename Scalar, int Dim>
00159 inline typename Scaling<Scalar,Dim>::TransformType
00160 Scaling<Scalar,Dim>::operator* (const TransformType& t) const
00161 {
00162   TransformType res = t;
00163   res.prescale(m_coeffs);
00164   return res;
00165 }
00166 
00167 } // end namespace Eigen


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:55