OpenWalker Project
Documentation of the ROS Packages
quaternion_ref.h
Go to the documentation of this file.
1 
34 #ifndef OPEN_WALKER_CORE_EIGEN_QUATERNION_REF_H
35 #define OPEN_WALKER_CORE_EIGEN_QUATERNION_REF_H
36 
37 #include <Eigen/Geometry>
38 
39 // has to be in eigen namespace for QuaternionBase<...> to work with custom type QuaternionRef
40 namespace Eigen
41 {
42 // forward declaration
43 template <typename _Derived>
45 
46 namespace internal
47 {
66 template <typename _Derived>
67 struct traits<QuaternionRef<_Derived> >
68 {
70  typedef typename _Derived::Scalar Scalar;
71  typedef Eigen::Block<_Derived, 4, 1> Coefficients;
72 
73  enum
74  {
75  Alignment = internal::traits<Coefficients>::Alignment,
76  Flags = LvalueBit
77  };
78 };
79 
80 } // namespace internal
81 
93 template <typename _Derived>
94 class QuaternionRef : public Eigen::QuaternionBase<QuaternionRef<_Derived> >
95 {
96 public:
97  typedef _Derived Derived;
98  typedef Eigen::QuaternionBase<QuaternionRef<_Derived> > Base;
99  typedef typename Eigen::internal::traits<QuaternionRef>::Coefficients Coefficients;
100 
101 protected:
102  Coefficients coeffs_;
103 
104 public:
118  QuaternionRef(Derived& ref, int startRow = 0, int startCol = 0) :
119  coeffs_(ref, startRow, startCol)
120  {
121  }
122 
123  // /*!
124  // * \brief Copy constructor.
125  // */
126  // QuaternionRef(const QuaternionRef& other) :
127  // m_coeffs(other.coeffs())
128  // {}
129 
133  using Base::operator=;
134 
141  using Base::operator*=;
142 
150  Coefficients& coeffs()
151  {
152  return coeffs_;
153  }
154 
162  const Coefficients& coeffs() const
163  {
164  return coeffs_;
165  }
166 
170  std::string toString() const
171  {
172  std::ostringstream out;
173  out << coeffs_.transpose();
174  return out.str();
175  }
176 
177 private:
181  QuaternionRef();
182 };
183 
184 } // namespace Eigen
185 
186 #endif // OPEN_WALKER_CORE_EIGEN_QUATERNION_REF_H
Definition: quaternion_ref.h:40
Coefficients & coeffs()
Get quaternion coefficients.
Definition: quaternion_ref.h:150
The QuaternionRef class.
Definition: quaternion_ref.h:44
Coefficients coeffs_
The quaternion coefficients in a Eigen::Block.
Definition: quaternion_ref.h:102
const Coefficients & coeffs() const
Get quaternion coefficients.
Definition: quaternion_ref.h:162
std::string toString() const
Conversion to std::string.
Definition: quaternion_ref.h:170
QuaternionRef(Derived &ref, int startRow=0, int startCol=0)
Default Constructor.
Definition: quaternion_ref.h:118