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. 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 Scaling
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 Translation<Scalar,Dim> TranslationType;
00058   typedef Transform<Scalar,Dim> TransformType;
00059 
00060 protected:
00061 
00062   VectorType m_coeffs;
00063 
00064 public:
00065 
00067   Scaling() {}
00069   explicit inline Scaling(const Scalar& s) { m_coeffs.setConstant(s); }
00071   inline Scaling(const Scalar& sx, const Scalar& sy)
00072   {
00073     ei_assert(Dim==2);
00074     m_coeffs.x() = sx;
00075     m_coeffs.y() = sy;
00076   }
00078   inline Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00079   {
00080     ei_assert(Dim==3);
00081     m_coeffs.x() = sx;
00082     m_coeffs.y() = sy;
00083     m_coeffs.z() = sz;
00084   }
00086   explicit inline Scaling(const VectorType& coeffs) : m_coeffs(coeffs) {}
00087 
00088   const VectorType& coeffs() const { return m_coeffs; }
00089   VectorType& coeffs() { return m_coeffs; }
00090 
00092   inline Scaling operator* (const Scaling& other) const
00093   { return Scaling(coeffs().cwise() * other.coeffs()); }
00094 
00096   inline TransformType operator* (const TranslationType& t) const;
00097 
00099   inline TransformType operator* (const TransformType& t) const;
00100 
00102   // TODO returns an expression
00103   inline LinearMatrixType operator* (const LinearMatrixType& other) const
00104   { return coeffs().asDiagonal() * other; }
00105 
00107   // TODO returns an expression
00108   friend inline LinearMatrixType operator* (const LinearMatrixType& other, const Scaling& s)
00109   { return other * s.coeffs().asDiagonal(); }
00110 
00111   template<typename Derived>
00112   inline LinearMatrixType operator*(const RotationBase<Derived,Dim>& r) const
00113   { return *this * r.toRotationMatrix(); }
00114 
00116   inline VectorType operator* (const VectorType& other) const
00117   { return coeffs().asDiagonal() * other; }
00118 
00120   inline Scaling inverse() const
00121   { return Scaling(coeffs().cwise().inverse()); }
00122 
00123   inline Scaling& operator=(const Scaling& other)
00124   {
00125     m_coeffs = other.m_coeffs;
00126     return *this;
00127   }
00128 
00134   template<typename NewScalarType>
00135   inline typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type cast() const
00136   { return typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type(*this); }
00137 
00139   template<typename OtherScalarType>
00140   inline explicit Scaling(const Scaling<OtherScalarType,Dim>& other)
00141   { m_coeffs = other.coeffs().template cast<Scalar>(); }
00142 
00147   bool isApprox(const Scaling& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00148   { return m_coeffs.isApprox(other.m_coeffs, prec); }
00149 
00150 };
00151 
00154 typedef Scaling<float, 2> Scaling2f;
00155 typedef Scaling<double,2> Scaling2d;
00156 typedef Scaling<float, 3> Scaling3f;
00157 typedef Scaling<double,3> Scaling3d;
00159 
00160 template<typename Scalar, int Dim>
00161 inline typename Scaling<Scalar,Dim>::TransformType
00162 Scaling<Scalar,Dim>::operator* (const TranslationType& t) const
00163 {
00164   TransformType res;
00165   res.matrix().setZero();
00166   res.linear().diagonal() = coeffs();
00167   res.translation() = m_coeffs.cwise() * t.vector();
00168   res(Dim,Dim) = Scalar(1);
00169   return res;
00170 }
00171 
00172 template<typename Scalar, int Dim>
00173 inline typename Scaling<Scalar,Dim>::TransformType
00174 Scaling<Scalar,Dim>::operator* (const TransformType& t) const
00175 {
00176   TransformType res = t;
00177   res.prescale(m_coeffs);
00178   return res;
00179 }


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:19