00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
00117
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