Main MRPT website > C++ reference
MRPT logo

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 
00028 /** \geometry_module \ingroup Geometry_Module
00029   *
00030   * \class Scaling
00031   *
00032   * \brief Represents a generic uniform scaling transformation
00033   *
00034   * \param _Scalar the scalar type, i.e., the type of the coefficients.
00035   *
00036   * This class represent a uniform scaling transformation. It is the return
00037   * type of Scaling(Scalar), and most of the time this is the only way it
00038   * is used. In particular, this class is not aimed to be used to store a scaling transformation,
00039   * but rather to make easier the constructions and updates of Transform objects.
00040   *
00041   * To represent an axis aligned scaling, use the DiagonalMatrix class.
00042   *
00043   * \sa Scaling(), class DiagonalMatrix, MatrixBase::asDiagonal(), class Translation, class Transform
00044   */
00045 template<typename _Scalar>
00046 class UniformScaling
00047 {
00048 public:
00049   /** the scalar type of the coefficients */
00050   typedef _Scalar Scalar;
00051 
00052 protected:
00053 
00054   Scalar m_factor;
00055 
00056 public:
00057 
00058   /** Default constructor without initialization. */
00059   UniformScaling() {}
00060   /** Constructs and initialize a uniform scaling transformation */
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 
00066   /** Concatenates two uniform scaling */
00067   inline UniformScaling operator* (const UniformScaling& other) const
00068   { return UniformScaling(m_factor * other.factor()); }
00069 
00070   /** Concatenates a uniform scaling and a translation */
00071   template<int Dim>
00072   inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const;
00073 
00074   /** Concatenates a uniform scaling and an affine transformation */
00075   template<int Dim, int Mode>
00076   inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim, Mode>& t) const;
00077 
00078   /** Concatenates a uniform scaling and a linear transformation matrix */
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 
00088   /** \returns the inverse scaling */
00089   inline UniformScaling inverse() const
00090   { return UniformScaling(Scalar(1)/m_factor); }
00091 
00092   /** \returns \c *this with scalar type casted to \a NewScalarType
00093     *
00094     * Note that if \a NewScalarType is equal to the current scalar type of \c *this
00095     * then this function smartly returns a const reference to \c *this.
00096     */
00097   template<typename NewScalarType>
00098   inline UniformScaling<NewScalarType> cast() const
00099   { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
00100 
00101   /** Copy constructor with scalar type conversion */
00102   template<typename OtherScalarType>
00103   inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
00104   { m_factor = Scalar(other.factor()); }
00105 
00106   /** \returns \c true if \c *this is approximately equal to \a other, within the precision
00107     * determined by \a prec.
00108     *
00109     * \sa MatrixBase::isApprox() */
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 
00115 /** Concatenates a linear transformation matrix and a uniform scaling */
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 
00122 /** Constructs a uniform scaling from scale factor \a s */
00123 static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
00124 /** Constructs a uniform scaling from scale factor \a s */
00125 static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
00126 /** Constructs a uniform scaling from scale factor \a 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 
00131 /** Constructs a 2D axis aligned scaling */
00132 template<typename Scalar>
00133 static inline DiagonalMatrix<Scalar,2> Scaling(Scalar sx, Scalar sy)
00134 { return DiagonalMatrix<Scalar,2>(sx, sy); }
00135 /** Constructs a 3D axis aligned scaling */
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 
00140 /** Constructs an axis aligned scaling expression from vector expression \a coeffs
00141   * This is an alias for coeffs.asDiagonal()
00142   */
00143 template<typename Derived>
00144 static inline const DiagonalWrapper<Derived> Scaling(const MatrixBase<Derived>& coeffs)
00145 { return coeffs.asDiagonal(); }
00146 
00147 /** \addtogroup Geometry_Module */
00148 //@{
00149 /** \deprecated */
00150 typedef DiagonalMatrix<float, 2> AlignedScaling2f;
00151 /** \deprecated */
00152 typedef DiagonalMatrix<double,2> AlignedScaling2d;
00153 /** \deprecated */
00154 typedef DiagonalMatrix<float, 3> AlignedScaling3f;
00155 /** \deprecated */
00156 typedef DiagonalMatrix<double,3> AlignedScaling3d;
00157 //@}
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>
00174 inline Transform<Scalar,Dim,Mode>
00175 UniformScaling<Scalar>::operator* (const Transform<Scalar,Dim, Mode>& t) const
00176 {
00177   Transform<Scalar,Dim,Mode> res = t;
00178   res.prescale(factor());
00179   return res;
00180 }
00181 
00182 #endif // EIGEN_SCALING_H



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011