Eigne Matrix Class Library
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/Geometry/Scaling.h@1:3b8049da21b8, 2019-09-24 (annotated)
- Committer:
- jsoh91
- Date:
- Tue Sep 24 00:18:23 2019 +0000
- Revision:
- 1:3b8049da21b8
- Parent:
- 0:13a5d365ba16
ignore and revise some of error parts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ykuroda | 0:13a5d365ba16 | 1 | // This file is part of Eigen, a lightweight C++ template library |
ykuroda | 0:13a5d365ba16 | 2 | // for linear algebra. |
ykuroda | 0:13a5d365ba16 | 3 | // |
ykuroda | 0:13a5d365ba16 | 4 | // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> |
ykuroda | 0:13a5d365ba16 | 5 | // |
ykuroda | 0:13a5d365ba16 | 6 | // This Source Code Form is subject to the terms of the Mozilla |
ykuroda | 0:13a5d365ba16 | 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
ykuroda | 0:13a5d365ba16 | 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
ykuroda | 0:13a5d365ba16 | 9 | |
ykuroda | 0:13a5d365ba16 | 10 | #ifndef EIGEN_SCALING_H |
ykuroda | 0:13a5d365ba16 | 11 | #define EIGEN_SCALING_H |
ykuroda | 0:13a5d365ba16 | 12 | |
ykuroda | 0:13a5d365ba16 | 13 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 14 | |
ykuroda | 0:13a5d365ba16 | 15 | /** \geometry_module \ingroup Geometry_Module |
ykuroda | 0:13a5d365ba16 | 16 | * |
ykuroda | 0:13a5d365ba16 | 17 | * \class Scaling |
ykuroda | 0:13a5d365ba16 | 18 | * |
ykuroda | 0:13a5d365ba16 | 19 | * \brief Represents a generic uniform scaling transformation |
ykuroda | 0:13a5d365ba16 | 20 | * |
ykuroda | 0:13a5d365ba16 | 21 | * \param _Scalar the scalar type, i.e., the type of the coefficients. |
ykuroda | 0:13a5d365ba16 | 22 | * |
ykuroda | 0:13a5d365ba16 | 23 | * This class represent a uniform scaling transformation. It is the return |
ykuroda | 0:13a5d365ba16 | 24 | * type of Scaling(Scalar), and most of the time this is the only way it |
ykuroda | 0:13a5d365ba16 | 25 | * is used. In particular, this class is not aimed to be used to store a scaling transformation, |
ykuroda | 0:13a5d365ba16 | 26 | * but rather to make easier the constructions and updates of Transform objects. |
ykuroda | 0:13a5d365ba16 | 27 | * |
ykuroda | 0:13a5d365ba16 | 28 | * To represent an axis aligned scaling, use the DiagonalMatrix class. |
ykuroda | 0:13a5d365ba16 | 29 | * |
ykuroda | 0:13a5d365ba16 | 30 | * \sa Scaling(), class DiagonalMatrix, MatrixBase::asDiagonal(), class Translation, class Transform |
ykuroda | 0:13a5d365ba16 | 31 | */ |
ykuroda | 0:13a5d365ba16 | 32 | template<typename _Scalar> |
ykuroda | 0:13a5d365ba16 | 33 | class UniformScaling |
ykuroda | 0:13a5d365ba16 | 34 | { |
ykuroda | 0:13a5d365ba16 | 35 | public: |
ykuroda | 0:13a5d365ba16 | 36 | /** the scalar type of the coefficients */ |
ykuroda | 0:13a5d365ba16 | 37 | typedef _Scalar Scalar; |
ykuroda | 0:13a5d365ba16 | 38 | |
ykuroda | 0:13a5d365ba16 | 39 | protected: |
ykuroda | 0:13a5d365ba16 | 40 | |
ykuroda | 0:13a5d365ba16 | 41 | Scalar m_factor; |
ykuroda | 0:13a5d365ba16 | 42 | |
ykuroda | 0:13a5d365ba16 | 43 | public: |
ykuroda | 0:13a5d365ba16 | 44 | |
ykuroda | 0:13a5d365ba16 | 45 | /** Default constructor without initialization. */ |
ykuroda | 0:13a5d365ba16 | 46 | UniformScaling() {} |
ykuroda | 0:13a5d365ba16 | 47 | /** Constructs and initialize a uniform scaling transformation */ |
ykuroda | 0:13a5d365ba16 | 48 | explicit inline UniformScaling(const Scalar& s) : m_factor(s) {} |
ykuroda | 0:13a5d365ba16 | 49 | |
ykuroda | 0:13a5d365ba16 | 50 | inline const Scalar& factor() const { return m_factor; } |
ykuroda | 0:13a5d365ba16 | 51 | inline Scalar& factor() { return m_factor; } |
ykuroda | 0:13a5d365ba16 | 52 | |
ykuroda | 0:13a5d365ba16 | 53 | /** Concatenates two uniform scaling */ |
ykuroda | 0:13a5d365ba16 | 54 | inline UniformScaling operator* (const UniformScaling& other) const |
ykuroda | 0:13a5d365ba16 | 55 | { return UniformScaling(m_factor * other.factor()); } |
ykuroda | 0:13a5d365ba16 | 56 | |
ykuroda | 0:13a5d365ba16 | 57 | /** Concatenates a uniform scaling and a translation */ |
ykuroda | 0:13a5d365ba16 | 58 | template<int Dim> |
ykuroda | 0:13a5d365ba16 | 59 | inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const; |
ykuroda | 0:13a5d365ba16 | 60 | |
ykuroda | 0:13a5d365ba16 | 61 | /** Concatenates a uniform scaling and an affine transformation */ |
ykuroda | 0:13a5d365ba16 | 62 | template<int Dim, int Mode, int Options> |
ykuroda | 0:13a5d365ba16 | 63 | inline Transform<Scalar,Dim,(int(Mode)==int(Isometry)?Affine:Mode)> operator* (const Transform<Scalar,Dim, Mode, Options>& t) const |
ykuroda | 0:13a5d365ba16 | 64 | { |
ykuroda | 0:13a5d365ba16 | 65 | Transform<Scalar,Dim,(int(Mode)==int(Isometry)?Affine:Mode)> res = t; |
ykuroda | 0:13a5d365ba16 | 66 | res.prescale(factor()); |
ykuroda | 0:13a5d365ba16 | 67 | return res; |
ykuroda | 0:13a5d365ba16 | 68 | } |
ykuroda | 0:13a5d365ba16 | 69 | |
ykuroda | 0:13a5d365ba16 | 70 | /** Concatenates a uniform scaling and a linear transformation matrix */ |
ykuroda | 0:13a5d365ba16 | 71 | // TODO returns an expression |
ykuroda | 0:13a5d365ba16 | 72 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 73 | inline typename internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const |
ykuroda | 0:13a5d365ba16 | 74 | { return other * m_factor; } |
ykuroda | 0:13a5d365ba16 | 75 | |
ykuroda | 0:13a5d365ba16 | 76 | template<typename Derived,int Dim> |
ykuroda | 0:13a5d365ba16 | 77 | inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const |
ykuroda | 0:13a5d365ba16 | 78 | { return r.toRotationMatrix() * m_factor; } |
ykuroda | 0:13a5d365ba16 | 79 | |
ykuroda | 0:13a5d365ba16 | 80 | /** \returns the inverse scaling */ |
ykuroda | 0:13a5d365ba16 | 81 | inline UniformScaling inverse() const |
ykuroda | 0:13a5d365ba16 | 82 | { return UniformScaling(Scalar(1)/m_factor); } |
ykuroda | 0:13a5d365ba16 | 83 | |
ykuroda | 0:13a5d365ba16 | 84 | /** \returns \c *this with scalar type casted to \a NewScalarType |
ykuroda | 0:13a5d365ba16 | 85 | * |
ykuroda | 0:13a5d365ba16 | 86 | * Note that if \a NewScalarType is equal to the current scalar type of \c *this |
ykuroda | 0:13a5d365ba16 | 87 | * then this function smartly returns a const reference to \c *this. |
ykuroda | 0:13a5d365ba16 | 88 | */ |
ykuroda | 0:13a5d365ba16 | 89 | template<typename NewScalarType> |
ykuroda | 0:13a5d365ba16 | 90 | inline UniformScaling<NewScalarType> cast() const |
ykuroda | 0:13a5d365ba16 | 91 | { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); } |
ykuroda | 0:13a5d365ba16 | 92 | |
ykuroda | 0:13a5d365ba16 | 93 | /** Copy constructor with scalar type conversion */ |
ykuroda | 0:13a5d365ba16 | 94 | template<typename OtherScalarType> |
ykuroda | 0:13a5d365ba16 | 95 | inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other) |
ykuroda | 0:13a5d365ba16 | 96 | { m_factor = Scalar(other.factor()); } |
ykuroda | 0:13a5d365ba16 | 97 | |
ykuroda | 0:13a5d365ba16 | 98 | /** \returns \c true if \c *this is approximately equal to \a other, within the precision |
ykuroda | 0:13a5d365ba16 | 99 | * determined by \a prec. |
ykuroda | 0:13a5d365ba16 | 100 | * |
ykuroda | 0:13a5d365ba16 | 101 | * \sa MatrixBase::isApprox() */ |
ykuroda | 0:13a5d365ba16 | 102 | bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const |
ykuroda | 0:13a5d365ba16 | 103 | { return internal::isApprox(m_factor, other.factor(), prec); } |
ykuroda | 0:13a5d365ba16 | 104 | |
ykuroda | 0:13a5d365ba16 | 105 | }; |
ykuroda | 0:13a5d365ba16 | 106 | |
ykuroda | 0:13a5d365ba16 | 107 | /** Concatenates a linear transformation matrix and a uniform scaling */ |
ykuroda | 0:13a5d365ba16 | 108 | // NOTE this operator is defiend in MatrixBase and not as a friend function |
ykuroda | 0:13a5d365ba16 | 109 | // of UniformScaling to fix an internal crash of Intel's ICC |
ykuroda | 0:13a5d365ba16 | 110 | template<typename Derived> typename MatrixBase<Derived>::ScalarMultipleReturnType |
ykuroda | 0:13a5d365ba16 | 111 | MatrixBase<Derived>::operator*(const UniformScaling<Scalar>& s) const |
ykuroda | 0:13a5d365ba16 | 112 | { return derived() * s.factor(); } |
ykuroda | 0:13a5d365ba16 | 113 | |
ykuroda | 0:13a5d365ba16 | 114 | /** Constructs a uniform scaling from scale factor \a s */ |
ykuroda | 0:13a5d365ba16 | 115 | static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); } |
ykuroda | 0:13a5d365ba16 | 116 | /** Constructs a uniform scaling from scale factor \a s */ |
ykuroda | 0:13a5d365ba16 | 117 | static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); } |
ykuroda | 0:13a5d365ba16 | 118 | /** Constructs a uniform scaling from scale factor \a s */ |
ykuroda | 0:13a5d365ba16 | 119 | template<typename RealScalar> |
ykuroda | 0:13a5d365ba16 | 120 | static inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s) |
ykuroda | 0:13a5d365ba16 | 121 | { return UniformScaling<std::complex<RealScalar> >(s); } |
ykuroda | 0:13a5d365ba16 | 122 | |
ykuroda | 0:13a5d365ba16 | 123 | /** Constructs a 2D axis aligned scaling */ |
ykuroda | 0:13a5d365ba16 | 124 | template<typename Scalar> |
ykuroda | 0:13a5d365ba16 | 125 | static inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy) |
ykuroda | 0:13a5d365ba16 | 126 | { return DiagonalMatrix<Scalar,2>(sx, sy); } |
ykuroda | 0:13a5d365ba16 | 127 | /** Constructs a 3D axis aligned scaling */ |
ykuroda | 0:13a5d365ba16 | 128 | template<typename Scalar> |
ykuroda | 0:13a5d365ba16 | 129 | static inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz) |
ykuroda | 0:13a5d365ba16 | 130 | { return DiagonalMatrix<Scalar,3>(sx, sy, sz); } |
ykuroda | 0:13a5d365ba16 | 131 | |
ykuroda | 0:13a5d365ba16 | 132 | /** Constructs an axis aligned scaling expression from vector expression \a coeffs |
ykuroda | 0:13a5d365ba16 | 133 | * This is an alias for coeffs.asDiagonal() |
ykuroda | 0:13a5d365ba16 | 134 | */ |
ykuroda | 0:13a5d365ba16 | 135 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 136 | static inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs) |
ykuroda | 0:13a5d365ba16 | 137 | { return coeffs.asDiagonal(); } |
ykuroda | 0:13a5d365ba16 | 138 | |
ykuroda | 0:13a5d365ba16 | 139 | /** \addtogroup Geometry_Module */ |
ykuroda | 0:13a5d365ba16 | 140 | //@{ |
ykuroda | 0:13a5d365ba16 | 141 | /** \deprecated */ |
ykuroda | 0:13a5d365ba16 | 142 | typedef DiagonalMatrix<float, 2> AlignedScaling2f; |
ykuroda | 0:13a5d365ba16 | 143 | /** \deprecated */ |
ykuroda | 0:13a5d365ba16 | 144 | typedef DiagonalMatrix<double,2> AlignedScaling2d; |
ykuroda | 0:13a5d365ba16 | 145 | /** \deprecated */ |
ykuroda | 0:13a5d365ba16 | 146 | typedef DiagonalMatrix<float, 3> AlignedScaling3f; |
ykuroda | 0:13a5d365ba16 | 147 | /** \deprecated */ |
ykuroda | 0:13a5d365ba16 | 148 | typedef DiagonalMatrix<double,3> AlignedScaling3d; |
ykuroda | 0:13a5d365ba16 | 149 | //@} |
ykuroda | 0:13a5d365ba16 | 150 | |
ykuroda | 0:13a5d365ba16 | 151 | template<typename Scalar> |
ykuroda | 0:13a5d365ba16 | 152 | template<int Dim> |
ykuroda | 0:13a5d365ba16 | 153 | inline Transform<Scalar,Dim,Affine> |
ykuroda | 0:13a5d365ba16 | 154 | UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const |
ykuroda | 0:13a5d365ba16 | 155 | { |
ykuroda | 0:13a5d365ba16 | 156 | Transform<Scalar,Dim,Affine> res; |
ykuroda | 0:13a5d365ba16 | 157 | res.matrix().setZero(); |
ykuroda | 0:13a5d365ba16 | 158 | res.linear().diagonal().fill(factor()); |
ykuroda | 0:13a5d365ba16 | 159 | res.translation() = factor() * t.vector(); |
ykuroda | 0:13a5d365ba16 | 160 | res(Dim,Dim) = Scalar(1); |
ykuroda | 0:13a5d365ba16 | 161 | return res; |
ykuroda | 0:13a5d365ba16 | 162 | } |
ykuroda | 0:13a5d365ba16 | 163 | |
ykuroda | 0:13a5d365ba16 | 164 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 165 | |
ykuroda | 0:13a5d365ba16 | 166 | #endif // EIGEN_SCALING_H |