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 #ifndef EIGEN_TRANSLATION_H
00026 #define EIGEN_TRANSLATION_H
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 Transform<Scalar,Dim,Affine> AffineTransformType;
00057
00058 protected:
00059
00060 VectorType m_coeffs;
00061
00062 public:
00063
00065 Translation() {}
00067 inline Translation(const Scalar& sx, const Scalar& sy)
00068 {
00069 eigen_assert(Dim==2);
00070 m_coeffs.x() = sx;
00071 m_coeffs.y() = sy;
00072 }
00074 inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00075 {
00076 eigen_assert(Dim==3);
00077 m_coeffs.x() = sx;
00078 m_coeffs.y() = sy;
00079 m_coeffs.z() = sz;
00080 }
00082 explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00083
00085 inline Scalar x() const { return m_coeffs.x(); }
00087 inline Scalar y() const { return m_coeffs.y(); }
00089 inline Scalar z() const { return m_coeffs.z(); }
00090
00092 inline Scalar& x() { return m_coeffs.x(); }
00094 inline Scalar& y() { return m_coeffs.y(); }
00096 inline Scalar& z() { return m_coeffs.z(); }
00097
00098 const VectorType& vector() const { return m_coeffs; }
00099 VectorType& vector() { return m_coeffs; }
00100
00101 const VectorType& translation() const { return m_coeffs; }
00102 VectorType& translation() { return m_coeffs; }
00103
00105 inline Translation operator* (const Translation& other) const
00106 { return Translation(m_coeffs + other.m_coeffs); }
00107
00109 inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
00110
00112 template<typename OtherDerived>
00113 inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
00114
00116 template<typename Derived>
00117 inline AffineTransformType operator*(const RotationBase<Derived,Dim>& r) const
00118 { return *this * r.toRotationMatrix(); }
00119
00121
00122 template<typename OtherDerived> friend
00123 inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
00124 {
00125 AffineTransformType res;
00126 res.matrix().setZero();
00127 res.linear() = linear.derived();
00128 res.translation() = linear.derived() * t.m_coeffs;
00129 res.matrix().row(Dim).setZero();
00130 res(Dim,Dim) = Scalar(1);
00131 return res;
00132 }
00133
00135 template<int Mode, int Options>
00136 inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
00137 {
00138 Transform<Scalar,Dim,Mode> res = t;
00139 res.pretranslate(m_coeffs);
00140 return res;
00141 }
00142
00144 inline VectorType operator* (const VectorType& other) const
00145 { return m_coeffs + other; }
00146
00148 Translation inverse() const { return Translation(-m_coeffs); }
00149
00150 Translation& operator=(const Translation& other)
00151 {
00152 m_coeffs = other.m_coeffs;
00153 return *this;
00154 }
00155
00156 static const Translation Identity() { return Translation(VectorType::Zero()); }
00157
00163 template<typename NewScalarType>
00164 inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00165 { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00166
00168 template<typename OtherScalarType>
00169 inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00170 { m_coeffs = other.vector().template cast<Scalar>(); }
00171
00176 bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00177 { return m_coeffs.isApprox(other.m_coeffs, prec); }
00178
00179 };
00180
00183 typedef Translation<float, 2> Translation2f;
00184 typedef Translation<double,2> Translation2d;
00185 typedef Translation<float, 3> Translation3f;
00186 typedef Translation<double,3> Translation3d;
00188
00189 template<typename Scalar, int Dim>
00190 inline typename Translation<Scalar,Dim>::AffineTransformType
00191 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
00192 {
00193 AffineTransformType res;
00194 res.matrix().setZero();
00195 res.linear().diagonal().fill(other.factor());
00196 res.translation() = m_coeffs;
00197 res(Dim,Dim) = Scalar(1);
00198 return res;
00199 }
00200
00201 template<typename Scalar, int Dim>
00202 template<typename OtherDerived>
00203 inline typename Translation<Scalar,Dim>::AffineTransformType
00204 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
00205 {
00206 AffineTransformType res;
00207 res.matrix().setZero();
00208 res.linear() = linear.derived();
00209 res.translation() = m_coeffs;
00210 res.matrix().row(Dim).setZero();
00211 res(Dim,Dim) = Scalar(1);
00212 return res;
00213 }
00214
00215 #endif // EIGEN_TRANSLATION_H