00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef EIGEN_LGSM_LIE_GROUP_SO3_H
00011 #define EIGEN_LGSM_LIE_GROUP_SO3_H
00012
00013
00014
00015
00016
00027 template<class Derived>
00028 class LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>
00029 {
00030 public:
00031
00033 typedef typename internal::traits<Derived>::Scalar Scalar;
00035 typedef Quaternion<Scalar> BaseType;
00037 typedef typename internal::traits<Derived>::Coefficients Coefficients;
00039 typedef LieGroup<Quaternion<Scalar> > PlainObject;
00040
00042 typedef Matrix<Scalar, 3, 3> AdjointMatrix;
00044 typedef LieAlgebra<Matrix<Scalar, 3, 1> > Algebra;
00046 typedef LieAlgebraDual<Matrix<Scalar, 3, 1> > AlgebraDual;
00047
00049 EIGEN_STRONG_INLINE PlainObject inverse() const;
00051 static PlainObject Identity();
00053 template<class OtherDerived> EIGEN_STRONG_INLINE PlainObject operator*(const LieGroupBase<BaseType, OtherDerived>& other) const;
00055 template<class OtherDerived> EIGEN_STRONG_INLINE Derived& operator*=(const LieGroupBase<BaseType, OtherDerived>& other);
00057 template<class MatrixDerived> EIGEN_STRONG_INLINE Matrix<Scalar, 3, 1> operator*(const MatrixBase<MatrixDerived>& v) const {
00058 return this->get() * v;
00059 }
00060
00062 inline AdjointMatrix adjoint(void) const;
00064 template<class AlgebraDerived> inline Algebra adjoint(const LieAlgebraBase<Matrix<Scalar, 3, 1>, AlgebraDerived>& ) const;
00066 template<class AlgebraDualDerived> inline AlgebraDual adjointTr(const LieAlgebraDualBase<Matrix<Scalar, 3, 1>, AlgebraDualDerived>& ) const;
00067
00071 Algebra log(const Scalar precision = 1e-6) const;
00072
00074 EIGEN_STRONG_INLINE LieGroupBase& operator=(const LieGroupBase& other);
00076 template<class OtherDerived> EIGEN_STRONG_INLINE Derived& operator=(const LieGroupBase<BaseType, OtherDerived>& other);
00078 template<class OtherDerived> Derived& operator=(const MatrixBase<OtherDerived>& m){ this->get() = m; return this->derived();}
00079
00081 inline const Derived& derived() const { return *static_cast<const Derived*>(this); }
00083 inline Derived& derived() { return *static_cast<Derived*>(this); }
00084
00085
00087 inline Scalar x() const { return this->get().x(); }
00089 inline Scalar y() const { return this->get().y(); }
00091 inline Scalar z() const { return this->get().z(); }
00093 inline Scalar w() const { return this->get().w(); }
00094
00096 inline Scalar& x() { return this->get().x(); }
00098 inline Scalar& y() { return this->get().y(); }
00100 inline Scalar& z() { return this->get().z(); }
00102 inline Scalar& w() { return this->get().w(); }
00103
00109 template<typename NewScalarType>
00110 inline typename internal::cast_return_type<Derived, LieGroup<Quaternion<NewScalarType> > >::type cast() const
00111 {
00112 return typename internal::cast_return_type<Derived, LieGroup<Quaternion<NewScalarType> > >::type(
00113 get().template cast<NewScalarType>());
00114 }
00115
00117 inline const VectorBlock<Coefficients,3> vec() const { return this->get().vec(); }
00118
00120 inline VectorBlock<Coefficients,3> vec() { return this->get().vec(); }
00121
00123 Coefficients& get() { return derived().get(); }
00125 const Coefficients& get() const { return derived().get(); }
00126 };
00127
00128
00129
00130
00131
00132
00133 template<class Derived>
00134 EIGEN_STRONG_INLINE LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>&
00135 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::operator=(const LieGroupBase& other)
00136 {
00137 this->get() = other.get();
00138 return *this;
00139 }
00140
00141
00142 template<class Derived>
00143 template<class OtherDerived>
00144 EIGEN_STRONG_INLINE Derived&
00145 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::operator=(const LieGroupBase<BaseType, OtherDerived>& other)
00146 {
00147 this->get() = other.get();
00148 return derived();
00149 }
00150
00151
00152 template<class Derived>
00153 EIGEN_STRONG_INLINE typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::PlainObject
00154 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::inverse() const
00155 {
00156 return PlainObject(this->get().conjugate());
00157 }
00158
00159
00160 template<class Derived>
00161 typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::PlainObject
00162 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::Identity()
00163 {
00164 return PlainObject(Quaternion<Scalar>::Identity());
00165 }
00166
00167
00168 template<class Derived>
00169 template<class OtherDerived> EIGEN_STRONG_INLINE typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::PlainObject
00170 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::operator*(const LieGroupBase<Quaternion<Scalar>, OtherDerived>& other) const
00171 {
00172 return PlainObject(this->get() * other.get());
00173 }
00174
00175
00176 template<class Derived>
00177 template<class OtherDerived>
00178 EIGEN_STRONG_INLINE Derived&
00179 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::operator*=(const LieGroupBase<BaseType, OtherDerived>& other)
00180 {
00181 this->get() *= other.get();
00182 return derived();
00183 }
00184
00185
00186 template<class Derived>
00187 typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::Algebra
00188 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::log(const Scalar precision) const
00189 {
00190 const Scalar n2 = this->get().vec().squaredNorm();
00191 const Scalar n = std::sqrt(n2);
00192
00193 if (n < precision)
00194 return Algebra((2 / this->get().w()) * this->get().vec());
00195 else
00196 return Algebra(std::atan2(2 * n * this->get().w(), this->get().w() * this->get().w() - n2) / n * this->get().vec());
00197 }
00198
00199
00200 template<class Derived>
00201 typename LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::AdjointMatrix
00202 LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>::adjoint() const
00203 {
00204 return this->get().toRotationMatrix();
00205 }
00206
00207 template<class Derived>
00208 inline std::ostream& operator <<(std::ostream& os, const LieGroupBase<Quaternion<typename internal::traits<Derived>::Scalar>, Derived>& g)
00209 {
00210 os << g.w() << "\t" << g.x() << "\t" << g.y() << "\t" << g.z();
00211 return os;
00212 }
00213
00214
00215
00216
00217
00230 template<typename _Scalar> class LieGroup<Quaternion<_Scalar> > :
00231 public LieGroupBase<Quaternion<_Scalar>, LieGroup<Quaternion<_Scalar> > >
00232 {
00233 protected:
00235 typedef LieGroupBase<Quaternion<_Scalar>, LieGroup<Quaternion<_Scalar> > > Base;
00236 public:
00238 typedef _Scalar Scalar;
00240 typedef typename internal::traits<LieGroup<Quaternion<Scalar> > >::Coefficients Coefficients;
00241
00242 EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(LieGroup)
00243
00244
00245 inline LieGroup() : m_coeffs() {}
00247 template<class OtherDerived> inline LieGroup(const LieGroupBase<typename Base::BaseType, OtherDerived>& g) : m_coeffs(g.get()) {}
00249
00251 EIGEN_STRONG_INLINE LieGroup(const Coefficients& g) : m_coeffs(g) {}
00252 EIGEN_STRONG_INLINE LieGroup(const AngleAxis<Scalar>& aa) : m_coeffs(aa) {}
00255 template<class OtherDerived> inline LieGroup(Scalar w, const MatrixBase<OtherDerived>& vec)
00256 : m_coeffs(w, vec.coeff(0), vec.coeff(1), vec.coeff(2))
00257 {
00258
00259 }
00260
00262 template<typename Derived>
00263 explicit inline LieGroup(const MatrixBase<Derived> & other) { this->get() = other;}
00264
00265 template<typename Derived>
00266 explicit inline LieGroup(const Matrix<Scalar, 4, 1> & other) { this = other;}
00267
00275 inline LieGroup(Scalar w, Scalar x, Scalar y, Scalar z) : m_coeffs(w, x, y, z) {}
00276 inline LieGroup(Scalar w, const Matrix<Scalar, 3, 1> & v) : m_coeffs(w, v.x(), v.y(), v.z()) {}
00277
00279 Coefficients& get() { return m_coeffs; }
00281 const Coefficients& get() const { return m_coeffs; }
00282
00283 protected:
00285 Coefficients m_coeffs;
00286 };
00287
00288
00289
00290
00291
00292
00293
00294 #endif