Warning, file /include/eigen3/Eigen/src/Geometry/Translation.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_TRANSLATION_H
0011 #define EIGEN_TRANSLATION_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template<typename _Scalar, int _Dim>
0030 class Translation
0031 {
0032 public:
0033 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_Dim)
0034
0035 enum { Dim = _Dim };
0036
0037 typedef _Scalar Scalar;
0038
0039 typedef Matrix<Scalar,Dim,1> VectorType;
0040
0041 typedef Matrix<Scalar,Dim,Dim> LinearMatrixType;
0042
0043 typedef Transform<Scalar,Dim,Affine> AffineTransformType;
0044
0045 typedef Transform<Scalar,Dim,Isometry> IsometryTransformType;
0046
0047 protected:
0048
0049 VectorType m_coeffs;
0050
0051 public:
0052
0053
0054 EIGEN_DEVICE_FUNC Translation() {}
0055
0056 EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy)
0057 {
0058 eigen_assert(Dim==2);
0059 m_coeffs.x() = sx;
0060 m_coeffs.y() = sy;
0061 }
0062
0063 EIGEN_DEVICE_FUNC inline Translation(const Scalar& sx, const Scalar& sy, const Scalar& sz)
0064 {
0065 eigen_assert(Dim==3);
0066 m_coeffs.x() = sx;
0067 m_coeffs.y() = sy;
0068 m_coeffs.z() = sz;
0069 }
0070
0071 EIGEN_DEVICE_FUNC explicit inline Translation(const VectorType& vector) : m_coeffs(vector) {}
0072
0073
0074 EIGEN_DEVICE_FUNC inline Scalar x() const { return m_coeffs.x(); }
0075
0076 EIGEN_DEVICE_FUNC inline Scalar y() const { return m_coeffs.y(); }
0077
0078 EIGEN_DEVICE_FUNC inline Scalar z() const { return m_coeffs.z(); }
0079
0080
0081 EIGEN_DEVICE_FUNC inline Scalar& x() { return m_coeffs.x(); }
0082
0083 EIGEN_DEVICE_FUNC inline Scalar& y() { return m_coeffs.y(); }
0084
0085 EIGEN_DEVICE_FUNC inline Scalar& z() { return m_coeffs.z(); }
0086
0087 EIGEN_DEVICE_FUNC const VectorType& vector() const { return m_coeffs; }
0088 EIGEN_DEVICE_FUNC VectorType& vector() { return m_coeffs; }
0089
0090 EIGEN_DEVICE_FUNC const VectorType& translation() const { return m_coeffs; }
0091 EIGEN_DEVICE_FUNC VectorType& translation() { return m_coeffs; }
0092
0093
0094 EIGEN_DEVICE_FUNC inline Translation operator* (const Translation& other) const
0095 { return Translation(m_coeffs + other.m_coeffs); }
0096
0097
0098 EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const UniformScaling<Scalar>& other) const;
0099
0100
0101 template<typename OtherDerived>
0102 EIGEN_DEVICE_FUNC inline AffineTransformType operator* (const EigenBase<OtherDerived>& linear) const;
0103
0104
0105 template<typename Derived>
0106 EIGEN_DEVICE_FUNC inline IsometryTransformType operator*(const RotationBase<Derived,Dim>& r) const
0107 { return *this * IsometryTransformType(r); }
0108
0109
0110
0111 template<typename OtherDerived> friend
0112 EIGEN_DEVICE_FUNC inline AffineTransformType operator*(const EigenBase<OtherDerived>& linear, const Translation& t)
0113 {
0114 AffineTransformType res;
0115 res.matrix().setZero();
0116 res.linear() = linear.derived();
0117 res.translation() = linear.derived() * t.m_coeffs;
0118 res.matrix().row(Dim).setZero();
0119 res(Dim,Dim) = Scalar(1);
0120 return res;
0121 }
0122
0123
0124 template<int Mode, int Options>
0125 EIGEN_DEVICE_FUNC inline Transform<Scalar,Dim,Mode> operator* (const Transform<Scalar,Dim,Mode,Options>& t) const
0126 {
0127 Transform<Scalar,Dim,Mode> res = t;
0128 res.pretranslate(m_coeffs);
0129 return res;
0130 }
0131
0132
0133 template<typename Derived>
0134 inline typename internal::enable_if<Derived::IsVectorAtCompileTime,VectorType>::type
0135 operator* (const MatrixBase<Derived>& vec) const
0136 { return m_coeffs + vec.derived(); }
0137
0138
0139 Translation inverse() const { return Translation(-m_coeffs); }
0140
0141 static const Translation Identity() { return Translation(VectorType::Zero()); }
0142
0143
0144
0145
0146
0147
0148 template<typename NewScalarType>
0149 EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type cast() const
0150 { return typename internal::cast_return_type<Translation,Translation<NewScalarType,Dim> >::type(*this); }
0151
0152
0153 template<typename OtherScalarType>
0154 EIGEN_DEVICE_FUNC inline explicit Translation(const Translation<OtherScalarType,Dim>& other)
0155 { m_coeffs = other.vector().template cast<Scalar>(); }
0156
0157
0158
0159
0160
0161 EIGEN_DEVICE_FUNC bool isApprox(const Translation& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
0162 { return m_coeffs.isApprox(other.m_coeffs, prec); }
0163
0164 };
0165
0166
0167
0168 typedef Translation<float, 2> Translation2f;
0169 typedef Translation<double,2> Translation2d;
0170 typedef Translation<float, 3> Translation3f;
0171 typedef Translation<double,3> Translation3d;
0172
0173
0174 template<typename Scalar, int Dim>
0175 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
0176 Translation<Scalar,Dim>::operator* (const UniformScaling<Scalar>& other) const
0177 {
0178 AffineTransformType res;
0179 res.matrix().setZero();
0180 res.linear().diagonal().fill(other.factor());
0181 res.translation() = m_coeffs;
0182 res(Dim,Dim) = Scalar(1);
0183 return res;
0184 }
0185
0186 template<typename Scalar, int Dim>
0187 template<typename OtherDerived>
0188 EIGEN_DEVICE_FUNC inline typename Translation<Scalar,Dim>::AffineTransformType
0189 Translation<Scalar,Dim>::operator* (const EigenBase<OtherDerived>& linear) const
0190 {
0191 AffineTransformType res;
0192 res.matrix().setZero();
0193 res.linear() = linear.derived();
0194 res.translation() = m_coeffs;
0195 res.matrix().row(Dim).setZero();
0196 res(Dim,Dim) = Scalar(1);
0197 return res;
0198 }
0199
0200 }
0201
0202 #endif