Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_SCALING_H
00011 #define EIGEN_SCALING_H
00012
00013 namespace Eigen {
00014
00032 template<typename _Scalar>
00033 class UniformScaling
00034 {
00035 public:
00037 typedef _Scalar Scalar;
00038
00039 protected:
00040
00041 Scalar m_factor;
00042
00043 public:
00044
00046 UniformScaling() {}
00048 explicit inline UniformScaling(const Scalar& s) : m_factor(s) {}
00049
00050 inline const Scalar& factor() const { return m_factor; }
00051 inline Scalar& factor() { return m_factor; }
00052
00054 inline UniformScaling operator* (const UniformScaling& other) const
00055 { return UniformScaling(m_factor * other.factor()); }
00056
00058 template<int Dim>
00059 inline Transform<Scalar,Dim,Affine> operator* (const Translation<Scalar,Dim>& t) const;
00060
00062 template<int Dim, int Mode, int Options>
00063 inline Transform<Scalar,Dim,(int(Mode)==int(Isometry)?Affine:Mode)> operator* (const Transform<Scalar,Dim, Mode, Options>& t) const
00064 {
00065 Transform<Scalar,Dim,(int(Mode)==int(Isometry)?Affine:Mode)> res = t;
00066 res.prescale(factor());
00067 return res;
00068 }
00069
00071
00072 template<typename Derived>
00073 inline typename internal::plain_matrix_type<Derived>::type operator* (const MatrixBase<Derived>& other) const
00074 { return other * m_factor; }
00075
00076 template<typename Derived,int Dim>
00077 inline Matrix<Scalar,Dim,Dim> operator*(const RotationBase<Derived,Dim>& r) const
00078 { return r.toRotationMatrix() * m_factor; }
00079
00081 inline UniformScaling inverse() const
00082 { return UniformScaling(Scalar(1)/m_factor); }
00083
00089 template<typename NewScalarType>
00090 inline UniformScaling<NewScalarType> cast() const
00091 { return UniformScaling<NewScalarType>(NewScalarType(m_factor)); }
00092
00094 template<typename OtherScalarType>
00095 inline explicit UniformScaling(const UniformScaling<OtherScalarType>& other)
00096 { m_factor = Scalar(other.factor()); }
00097
00102 bool isApprox(const UniformScaling& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
00103 { return internal::isApprox(m_factor, other.factor(), prec); }
00104
00105 };
00106
00108
00109
00110 template<typename Derived> typename MatrixBase<Derived>::ScalarMultipleReturnType
00111 MatrixBase<Derived>::operator*(const UniformScaling<Scalar>& s) const
00112 { return derived() * s.factor(); }
00113
00115 static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
00117 static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
00119 template<typename RealScalar>
00120 static inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
00121 { return UniformScaling<std::complex<RealScalar> >(s); }
00122
00124 template<typename Scalar>
00125 static inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
00126 { return DiagonalMatrix<Scalar,2>(sx, sy); }
00128 template<typename Scalar>
00129 static inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00130 { return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
00131
00135 template<typename Derived>
00136 static inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
00137 { return coeffs.asDiagonal(); }
00138
00142 typedef DiagonalMatrix<float, 2> AlignedScaling2f;
00144 typedef DiagonalMatrix<double,2> AlignedScaling2d;
00146 typedef DiagonalMatrix<float, 3> AlignedScaling3f;
00148 typedef DiagonalMatrix<double,3> AlignedScaling3d;
00150
00151 template<typename Scalar>
00152 template<int Dim>
00153 inline Transform<Scalar,Dim,Affine>
00154 UniformScaling<Scalar>::operator* (const Translation<Scalar,Dim>& t) const
00155 {
00156 Transform<Scalar,Dim,Affine> res;
00157 res.matrix().setZero();
00158 res.linear().diagonal().fill(factor());
00159 res.translation() = factor() * t.vector();
00160 res(Dim,Dim) = Scalar(1);
00161 return res;
00162 }
00163
00164 }
00165
00166 #endif // EIGEN_SCALING_H