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 <gael.guennebaud@inria.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 #ifndef EIGEN_SCALING_H
00026 #define EIGEN_SCALING_H
00027 
00045 template<typename _Scalar>
00046 class UniformScaling
00047 {
00048 public:
00050   typedef _Scalar Scalar;
00051 
00052 protected:
00053 
00054   Scalar m_factor;
00055 
00056 public:
00057 
00059   UniformScaling() {}
00061   explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
00062 
00063   inline const Scalar& factor() const { return m_factor; }
00064   inline Scalar& factor() { return m_factor; }
00065 
00067   inline UniformScaling operator* (const UniformScaling& other) const
00068   { return UniformScaling(m_factor * other.factor()); }
00069 
00071   template<int Dim>
00072   inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const;
00073 
00075   template<int Dim, int Mode, int Options>
00076   inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim, Mode, Options>& t) const;
00077 
00079   // TODO returns an expression
00080   template<typename Derived>
00081   inline typename internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
00082   { return other * m_factor; }
00083 
00084   template<typename Derived,int Dim>
00085   inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const
00086   { return r.toRotationMatrix() * m_factor; }
00087 
00089   inline UniformScaling inverse() const
00090   { return UniformScaling(Scalar(1)/m_factor); }
00091 
00097   template<typename NewScalarType>
00098   inline UniformScaling<NewScalarType> cast() const
00099   { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
00100 
00102   template<typename OtherScalarType>
00103   inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
00104   { m_factor = Scalar(other.factor()); }
00105 
00110   bool isApprox(const UniformScaling& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00111   { return internal::isApprox(m_factor, other.factor(), prec); }
00112 
00113 };
00114 
00116 // NOTE this operator is defiend in MatrixBase and not as a friend function
00117 // of UniformScaling to fix an internal crash of Intel's ICC
00118 template<typename Derived> typename MatrixBase<Derived>::ScalarMultipleReturnType
00119 MatrixBase<Derived>::operator*(const UniformScaling<Scalar>& s) const
00120 { return derived() * s.factor(); }
00121 
00123 static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
00125 static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
00127 template<typename RealScalar>
00128 static inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
00129 { return UniformScaling<std::complex<RealScalar> >(s); }
00130 
00132 template<typename Scalar>
00133 static inline DiagonalMatrix<Scalar,2> Scaling(Scalar sx, Scalar sy)
00134 { return DiagonalMatrix<Scalar,2>(sx, sy); }
00136 template<typename Scalar>
00137 static inline DiagonalMatrix<Scalar,3> Scaling(Scalar sx, Scalar sy, Scalar sz)
00138 { return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
00139 
00143 template<typename Derived>
00144 static inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
00145 { return coeffs.asDiagonal(); }
00146 
00150 typedef DiagonalMatrix<float, 2> AlignedScaling2f;
00152 typedef DiagonalMatrix<double,2> AlignedScaling2d;
00154 typedef DiagonalMatrix<float, 3> AlignedScaling3f;
00156 typedef DiagonalMatrix<double,3> AlignedScaling3d;
00158 
00159 template<typename Scalar>
00160 template<int Dim>
00161 inline Transform<Scalar,Dim,Affine>
00162 UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const
00163 {
00164   Transform<Scalar,Dim,Affine> res;
00165   res.matrix().setZero();
00166   res.linear().diagonal().fill(factor());
00167   res.translation() = factor() * t.vector();
00168   res(Dim,Dim) = Scalar(1);
00169   return res;
00170 }
00171 
00172 template<typename Scalar>
00173 template<int Dim,int Mode,int Options>
00174 inline Transform<Scalar,Dim,Mode>
00175 UniformScaling<Scalar>::operator* (const Transform<Scalar,Dim, Mode, Options>& t) const
00176 {
00177   Transform<Scalar,Dim,Mode> res = t;
00178   res.prescale(factor());
00179   return res;
00180 }
00181 
00182 #endif // EIGEN_SCALING_H


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