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 Translation
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 Scaling<Scalar,Dim> ScalingType;
00058 typedef Transform<Scalar,Dim> TransformType;
00059
00060 protected:
00061
00062 VectorType m_coeffs;
00063
00064 public:
00065
00067 Translation() {}
00069 inline Translation(const Scalar& sx, const Scalar& sy)
00070 {
00071 ei_assert(Dim==2);
00072 m_coeffs.x() = sx;
00073 m_coeffs.y() = sy;
00074 }
00076 inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00077 {
00078 ei_assert(Dim==3);
00079 m_coeffs.x() = sx;
00080 m_coeffs.y() = sy;
00081 m_coeffs.z() = sz;
00082 }
00084 explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00085
00086 const VectorType& vector() const { return m_coeffs; }
00087 VectorType& vector() { return m_coeffs; }
00088
00090 inline Translation operator* (const Translation& other) const
00091 { return Translation(m_coeffs + other.m_coeffs); }
00092
00094 inline TransformType operator* (const ScalingType& other) const;
00095
00097 inline TransformType operator* (const LinearMatrixType& linear) const;
00098
00099 template<typename Derived>
00100 inline TransformType operator*(const RotationBase<Derived,Dim>& r) const
00101 { return *this * r.toRotationMatrix(); }
00102
00104
00105 friend inline TransformType operator* (const LinearMatrixType& linear, const Translation& t)
00106 {
00107 TransformType res;
00108 res.matrix().setZero();
00109 res.linear() = linear;
00110 res.translation() = linear * t.m_coeffs;
00111 res.matrix().row(Dim).setZero();
00112 res(Dim,Dim) = Scalar(1);
00113 return res;
00114 }
00115
00117 inline TransformType operator* (const TransformType& t) const;
00118
00120 inline VectorType operator* (const VectorType& other) const
00121 { return m_coeffs + other; }
00122
00124 Translation inverse() const { return Translation(-m_coeffs); }
00125
00126 Translation& operator=(const Translation& other)
00127 {
00128 m_coeffs = other.m_coeffs;
00129 return *this;
00130 }
00131
00137 template<typename NewScalarType>
00138 inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00139 { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00140
00142 template<typename OtherScalarType>
00143 inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00144 { m_coeffs = other.vector().template cast<Scalar>(); }
00145
00150 bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00151 { return m_coeffs.isApprox(other.m_coeffs, prec); }
00152
00153 };
00154
00157 typedef Translation<float, 2> Translation2f;
00158 typedef Translation<double,2> Translation2d;
00159 typedef Translation<float, 3> Translation3f;
00160 typedef Translation<double,3> Translation3d;
00162
00163
00164 template<typename Scalar, int Dim>
00165 inline typename Translation<Scalar,Dim>::TransformType
00166 Translation<Scalar,Dim>::operator* (const ScalingType& other) const
00167 {
00168 TransformType res;
00169 res.matrix().setZero();
00170 res.linear().diagonal() = other.coeffs();
00171 res.translation() = m_coeffs;
00172 res(Dim,Dim) = Scalar(1);
00173 return res;
00174 }
00175
00176 template<typename Scalar, int Dim>
00177 inline typename Translation<Scalar,Dim>::TransformType
00178 Translation<Scalar,Dim>::operator* (const LinearMatrixType& linear) const
00179 {
00180 TransformType res;
00181 res.matrix().setZero();
00182 res.linear() = linear;
00183 res.translation() = m_coeffs;
00184 res.matrix().row(Dim).setZero();
00185 res(Dim,Dim) = Scalar(1);
00186 return res;
00187 }
00188
00189 template<typename Scalar, int Dim>
00190 inline typename Translation<Scalar,Dim>::TransformType
00191 Translation<Scalar,Dim>::operator* (const TransformType& t) const
00192 {
00193 TransformType res = t;
00194 res.pretranslate(m_coeffs);
00195 return res;
00196 }