Go to the documentation of this file.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
00026
00027
00042 template<typename _Scalar, int _Dim>
00043 class Scaling
00044 {
00045 public:
00046 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
00048 enum { Dim = _Dim };
00050 typedef _Scalar Scalar;
00052 typedef Matrix<Scalar,Dim,1> VectorType;
00054 typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
00056 typedef Translation<Scalar,Dim> TranslationType;
00058 typedef Transform<Scalar,Dim> TransformType;
00059
00060 protected:
00061
00062 VectorType m_coeffs;
00063
00064 public:
00065
00067 Scaling() {}
00069 explicit inline Scaling(const Scalar& s) { m_coeffs.setConstant(s); }
00071 inline Scaling(const Scalar& sx, const Scalar& sy)
00072 {
00073 ei_assert(Dim==2);
00074 m_coeffs.x() = sx;
00075 m_coeffs.y() = sy;
00076 }
00078 inline Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00079 {
00080 ei_assert(Dim==3);
00081 m_coeffs.x() = sx;
00082 m_coeffs.y() = sy;
00083 m_coeffs.z() = sz;
00084 }
00086 explicit inline Scaling(const VectorType& coeffs) : m_coeffs(coeffs) {}
00087
00088 const VectorType& coeffs() const { return m_coeffs; }
00089 VectorType& coeffs() { return m_coeffs; }
00090
00092 inline Scaling operator* (const Scaling& other) const
00093 { return Scaling(coeffs().cwise() * other.coeffs()); }
00094
00096 inline TransformType operator* (const TranslationType& t) const;
00097
00099 inline TransformType operator* (const TransformType& t) const;
00100
00102
00103 inline LinearMatrixType operator* (const LinearMatrixType& other) const
00104 { return coeffs().asDiagonal() * other; }
00105
00107
00108 friend inline LinearMatrixType operator* (const LinearMatrixType& other, const Scaling& s)
00109 { return other * s.coeffs().asDiagonal(); }
00110
00111 template<typename Derived>
00112 inline LinearMatrixType operator*(const RotationBase<Derived,Dim>& r) const
00113 { return *this * r.toRotationMatrix(); }
00114
00116 inline VectorType operator* (const VectorType& other) const
00117 { return coeffs().asDiagonal() * other; }
00118
00120 inline Scaling inverse() const
00121 { return Scaling(coeffs().cwise().inverse()); }
00122
00123 inline Scaling& operator=(const Scaling& other)
00124 {
00125 m_coeffs = other.m_coeffs;
00126 return *this;
00127 }
00128
00134 template<typename NewScalarType>
00135 inline typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type cast() const
00136 { return typename internal::cast_return_type<Scaling,Scaling<NewScalarType,Dim> >::type(*this); }
00137
00139 template<typename OtherScalarType>
00140 inline explicit Scaling(const Scaling<OtherScalarType,Dim>& other)
00141 { m_coeffs = other.coeffs().template cast<Scalar>(); }
00142
00147 bool isApprox(const Scaling& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00148 { return m_coeffs.isApprox(other.m_coeffs, prec); }
00149
00150 };
00151
00154 typedef Scaling<float, 2> Scaling2f;
00155 typedef Scaling<double,2> Scaling2d;
00156 typedef Scaling<float, 3> Scaling3f;
00157 typedef Scaling<double,3> Scaling3d;
00159
00160 template<typename Scalar, int Dim>
00161 inline typename Scaling<Scalar,Dim>::TransformType
00162 Scaling<Scalar,Dim>::operator* (const TranslationType& t) const
00163 {
00164 TransformType res;
00165 res.matrix().setZero();
00166 res.linear().diagonal() = coeffs();
00167 res.translation() = m_coeffs.cwise() * t.vector();
00168 res(Dim,Dim) = Scalar(1);
00169 return res;
00170 }
00171
00172 template<typename Scalar, int Dim>
00173 inline typename Scaling<Scalar,Dim>::TransformType
00174 Scaling<Scalar,Dim>::operator* (const TransformType& t) const
00175 {
00176 TransformType res = t;
00177 res.prescale(m_coeffs);
00178 return res;
00179 }