Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_TRANSLATION_H
00011 #define EIGEN_TRANSLATION_H
00012
00013 namespace Eigen {
00014
00029 template<typename _Scalar, int _Dim>
00030 class Translation
00031 {
00032 public:
00033 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
00035 enum { Dim = _Dim };
00037 typedef _Scalar Scalar;
00039 typedef Matrix<Scalar,Dim,1> VectorType;
00041 typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
00043 typedef Transform<Scalar,Dim,Affine> AffineTransformType;
00045 typedef Transform<Scalar,Dim,Isometry> IsometryTransformType;
00046
00047 protected:
00048
00049 VectorType m_coeffs;
00050
00051 public:
00052
00054 Translation() {}
00056 inline Translation(const Scalar& sx, const Scalar& sy)
00057 {
00058 eigen_assert(Dim==2);
00059 m_coeffs.x() = sx;
00060 m_coeffs.y() = sy;
00061 }
00063 inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
00064 {
00065 eigen_assert(Dim==3);
00066 m_coeffs.x() = sx;
00067 m_coeffs.y() = sy;
00068 m_coeffs.z() = sz;
00069 }
00071 explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
00072
00074 inline Scalar x() const { return m_coeffs.x(); }
00076 inline Scalar y() const { return m_coeffs.y(); }
00078 inline Scalar z() const { return m_coeffs.z(); }
00079
00081 inline Scalar& x() { return m_coeffs.x(); }
00083 inline Scalar& y() { return m_coeffs.y(); }
00085 inline Scalar& z() { return m_coeffs.z(); }
00086
00087 const VectorType& vector() const { return m_coeffs; }
00088 VectorType& vector() { return m_coeffs; }
00089
00090 const VectorType& translation() const { return m_coeffs; }
00091 VectorType& translation() { return m_coeffs; }
00092
00094 inline Translation operator* (const Translation& other) const
00095 { return Translation(m_coeffs + other.m_coeffs); }
00096
00098 inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
00099
00101 template<typename OtherDerived>
00102 inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
00103
00105 template<typename Derived>
00106 inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const
00107 { return *this * IsometryTransformType(r); }
00108
00110
00111 template<typename OtherDerived> friend
00112 inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
00113 {
00114 AffineTransformType res;
00115 res.matrix().setZero();
00116 res.linear() = linear.derived();
00117 res.translation() = linear.derived() * t.m_coeffs;
00118 res.matrix().row(Dim).setZero();
00119 res(Dim,Dim) = Scalar(1);
00120 return res;
00121 }
00122
00124 template<int Mode, int Options>
00125 inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
00126 {
00127 Transform<Scalar,Dim,Mode> res = t;
00128 res.pretranslate(m_coeffs);
00129 return res;
00130 }
00131
00133 inline VectorType operator* (const VectorType& other) const
00134 { return m_coeffs + other; }
00135
00137 Translation inverse() const { return Translation(-m_coeffs); }
00138
00139 Translation& operator=(const Translation& other)
00140 {
00141 m_coeffs = other.m_coeffs;
00142 return *this;
00143 }
00144
00145 static const Translation Identity() { return Translation(VectorType::Zero()); }
00146
00152 template<typename NewScalarType>
00153 inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
00154 { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
00155
00157 template<typename OtherScalarType>
00158 inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
00159 { m_coeffs = other.vector().template cast<Scalar>(); }
00160
00165 bool isApprox(const Translation& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00166 { return m_coeffs.isApprox(other.m_coeffs, prec); }
00167
00168 };
00169
00172 typedef Translation<float, 2> Translation2f;
00173 typedef Translation<double,2> Translation2d;
00174 typedef Translation<float, 3> Translation3f;
00175 typedef Translation<double,3> Translation3d;
00177
00178 template<typename Scalar, int Dim>
00179 inline typename Translation<Scalar,Dim>::AffineTransformType
00180 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
00181 {
00182 AffineTransformType res;
00183 res.matrix().setZero();
00184 res.linear().diagonal().fill(other.factor());
00185 res.translation() = m_coeffs;
00186 res(Dim,Dim) = Scalar(1);
00187 return res;
00188 }
00189
00190 template<typename Scalar, int Dim>
00191 template<typename OtherDerived>
00192 inline typename Translation<Scalar,Dim>::AffineTransformType
00193 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
00194 {
00195 AffineTransformType res;
00196 res.matrix().setZero();
00197 res.linear() = linear.derived();
00198 res.translation() = m_coeffs;
00199 res.matrix().row(Dim).setZero();
00200 res(Dim,Dim) = Scalar(1);
00201 return res;
00202 }
00203
00204 }
00205
00206 #endif // EIGEN_TRANSLATION_H