Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DualQuaternion.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __DualQuaternion_hh__
27 #define __DualQuaternion_hh__
28 
29 #include <bias_config.h>
30 
31 #include <Base/Geometry/Quaternion.hh>
32 #include <Base/Geometry/DualQuaternionOperators.hh>
33 #include <Base/Geometry/PoseParametrization.hh>
34 #include <Base/Geometry/RMatrixBase.hh>
35 #include <Base/Math/Matrix.hh>
36 #include <Base/Math/Vector.hh>
37 #include <Base/Math/Vector3.hh>
38 
39 namespace BIAS {
40 
41  /** @class DualQuaternion
42 
43  @ingroup g_geometry
44  @brief class representing rigid motion by dual quaternions
45 
46  Dual quaternions can be used to represent a rigid motion in 3d space
47  consisting of a rotation and a translation.
48 
49  A dual quaternion can be described as consisting of a real part q and
50  a dual part p which are both real quaternions. The real part q simply
51  describes the rotational part of the motion (see #Quaternion).
52  The dual part p describes the translational part decomposed into
53  a translation orthogonal to the rotation axis (related to the "moment")
54  and the amount of translation along the rotation axis ("pitch").
55 
56  Dual quaternions describing rigid motion are constrained to have
57  a unit real part and orthogonal real and dual parts.
58 
59  See for example K. Daniilidis: Hand-Eye Calibration Using Dual
60  Quaternions (1999) for further information on dual quaternions
61  and their relation to screw theory.
62 
63  @author esquivel 02/2011
64  */
65 
66  template<class QUAT_TYPE>
67  class BIASGeometryBase_EXPORT DualQuaternion
68  {
69 
70  private:
71 
72  Quaternion<QUAT_TYPE> real, dual;
73 
74  public:
75 
77 
79 
81  const Quaternion<QUAT_TYPE>& p);
82 
84 
85  inline void Invert();
86 
87  inline DualQuaternion<QUAT_TYPE> Inverse() const;
88 
89  /** Make dual quaternion representation unique with respect to the
90  rigid motion it represents. */
91  inline void MakeUnique();
92 
93  /** Scales dual quaternion to unit length, i.e. norm of real part equals 1
94  and real part is orthogonal to dual part. */
95  inline void Normalize();
96 
97  /** Computes dual quaternion norm which is a dual number consisting of
98  real part r and dual part d. */
99  inline void GetDualNorm(QUAT_TYPE &r, QUAT_TYPE &d) const;
100 
101  inline void Add(const DualQuaternion<QUAT_TYPE> &r);
102 
103  inline void Add(const DualQuaternion<QUAT_TYPE> &r,
104  DualQuaternion<QUAT_TYPE> &res) const;
105 
106  inline void Sub(const DualQuaternion<QUAT_TYPE> &r);
108  inline void Sub(const DualQuaternion<QUAT_TYPE> &r,
109  DualQuaternion<QUAT_TYPE> &res) const;
110 
111  inline void Mult(const QUAT_TYPE &scalar);
112 
113  inline void Mult(const QUAT_TYPE &scalar,
115 
116  inline void Div(const QUAT_TYPE &scalar);
117 
118  inline void Div(const QUAT_TYPE &scalar,
119  DualQuaternion<QUAT_TYPE> &res) const;
120 
121  inline void Mult(const DualQuaternion<QUAT_TYPE> &r);
123  inline void Mult(const DualQuaternion<QUAT_TYPE> &r,
124  DualQuaternion<QUAT_TYPE> &res) const;
125 
126  inline void MultLeft(const DualQuaternion<QUAT_TYPE> &l);
127 
128  inline void MultLeft(const DualQuaternion<QUAT_TYPE> &l,
130 
131  inline void MultVec(const Vector3<QUAT_TYPE> &vec,
132  Vector3<QUAT_TYPE> &res) const;
133 
134  inline Vector3<QUAT_TYPE> MultVec(const Vector3<QUAT_TYPE> &vec) const;
135 
136  inline void SetIdentity();
138  inline void Set(const Quaternion<QUAT_TYPE> &q,
139  const Quaternion<QUAT_TYPE> &p);
140 
141  inline void SetRealPart(const Quaternion<QUAT_TYPE> &q);
142 
143  inline void SetDualPart(const Quaternion<QUAT_TYPE> &p);
145  inline Quaternion<QUAT_TYPE> GetRealPart() const;
146 
147  inline Quaternion<QUAT_TYPE> GetDualPart() const;
148 
149  inline Vector<QUAT_TYPE> GetVector() const;
150 
151  /* Get pose parametrization represented by dual quaternion.
152  @note Dual quaternion is assumed to have unit norm! */
153  PoseParametrization GetPoseParametrization() const;
155  /* Get rigid motion (pose transformation) represented by dual quaternion.
156  @note Dual quaternion is assumed to have unit norm! */
157  void GetRigidMotion(Quaternion<QUAT_TYPE> &rotation,
158  Vector3<QUAT_TYPE> &translation) const;
159 
160  /* Get rigid motion (pose transformation) represented by dual quaternion.
161  @note Dual quaternion is assumed to have unit norm! */
162  inline void GetRigidMotion(RMatrixBase &rotation,
163  Vector3<QUAT_TYPE> &translation) const;
164 
165  /* Set dual quaternion from pose parametrization. */
166  void SetFromPoseParametrization(const PoseParametrization &params);
167 
168  /* Set dual quaternion from rigid motion parametrized by unit quaternion
169  and translation vector. */
170  void SetFromRigidMotion(const Quaternion<QUAT_TYPE> &rotation,
171  const Vector3<QUAT_TYPE> &translation);
172 
173  /* Set dual quaternion from rigid motion parametrized by rotation matrix
174  and translation vector. */
175  inline void SetFromRigidMotion(const RMatrixBase &rotation,
176  const Vector3<QUAT_TYPE> &translation);
177 
179  operator = (const DualQuaternion<QUAT_TYPE> &r)
180  { real = r.real; dual = r.dual; return *this; }
181 
184  { Add(r); return *this; }
185 
188  { Sub(r); return *this; }
189 
191  operator *= (const QUAT_TYPE &scalar)
192  { Mult(scalar); return *this; }
193 
195  operator /= (const QUAT_TYPE &scalar)
196  { Div(scalar); return *this; }
197 
200  { Mult(r); return *this; }
204  { Mult(r.Inverse()); return *this; }
205 
206  inline bool operator == (const DualQuaternion<QUAT_TYPE> &r) const
207  { // @todo verify that this is correct!
208  return (real == r.real) && (dual == r.dual);
209  }
210 
211  inline bool operator != (const DualQuaternion<QUAT_TYPE> &r) const
212  { return !(*this == r); }
213 
214  /* Spherical interpolation between this and given dual quaternion.
215  @note Dual quaternions are assumed to have unit norm! */
217  const QUAT_TYPE &t) const;
218 
219  /* Linear interpolation between this and given dual quaternion.
220  Unit norm constraint is enforced afterwards by normalization.
221  @note Dual quaternions are assumed to have unit norm! */
223  const QUAT_TYPE &t) const;
224 
225  /* Returns 8x8 matrix which expresses left dual quaternion multiplication.
226  * A dual quaternion (q,p) consisting of quaternions q = [q0,q1,q2,q3] and
227  * p = [p0,p1,p2,p3] is interpreted as a 8-vector [q0,q1,q2,q3,p0,p1,p2,p3].
228  * Left multiplying a dual quaternion (q',p') with a dual quaternion (q,p)
229  * can be expressed in terms of matrix multiplication as
230  * res = (q,p)*(q',p') = LM((q,p))*[q',p'].
231  * This method returns the matrix LM(*this).
232  */
233  Matrix<QUAT_TYPE> GetLeftMultMatrix() const;
235  /* Returns 8x8 matrix which expresses right dual quaternion multiplication.
236  * A dual quaternion (q,p) consisting of quaternions q = [q0,q1,q2,q3] and
237  * p = [p0,p1,p2,p3] is interpreted as a 8-vector [q0,q1,q2,q3,p0,p1,p2,p3].
238  * Right multiplying a dual quaternion (q',p') with a dual quaternion (q,p)
239  * can be expressed in terms of matrix multiplication as
240  * res = (q',p')*(q,p) = RM((q,p))*[q',p'].
241  * This method returns the matrix RM(*this).
242  */
243  Matrix<QUAT_TYPE> GetRightMultMatrix() const;
244 
245  /** @brief Enforce rigid coupling constraint for this and the other given
246  dual quaternion (equal rotation angle and equal motion pitch/equal
247  real and dual scalar part for both).
248  Computes direct simple interpolation of both dual quaternion where
249  the scalar parts of the real and dual quaternion parts of the resulting
250  dual quaternion are identical. This solution can be used as initial
251  guess for numerical refinement.
252  @param[in/out] other Dual quaternion to enforce rigid coupling constraint with
253  @param[in] useOtherAngle Use rotation angle (= real scalar part) of other
254  dual quaternion instead of interpolating both
255  @param[in] useOtherPitch Use motion pitch (= dual scalar part) of other
256  dual quaternion instead of interpolating both
257  @author esquivel 02/2012 */
258  void EnforceRigidCouplingConstraint(DualQuaternion<QUAT_TYPE> &other,
259  bool useOtherAngle = false,
260  bool useOtherPitch = false);
261 
262  /** @brief Enforce rigid coupling constraint for all dual quaternions in given vector.
263  @param[in/out] quats Dual quaternions to enforce rigid coupling constraint for
264  @param[in] useFirstAngle Use rotation angle (= real scalar part) of first
265  dual quaternion instead of interpolating all
266  @param[in] useFirstPitch Use motion pitch (= dual scalar part) of first
267  dual quaternion instead of interpolating all
268  @author esquivel 02/2012 */
269  static void EnforceRigidCouplingConstraint(std::vector< DualQuaternion<QUAT_TYPE> > &quats,
270  bool useFirstAngle = false,
271  bool useFirstPitch = false);
272 
273  };
274 
275  #include <Base/Geometry/DualQuaternionInl.hh>
276 
277 }
278 
279 #endif // __DualQuaternion_hh__
class for column vectors with arbitrary size
BIASMathBase_EXPORT Vector2< T > & operator/=(Vector2< T > &vec, const Vector2< T > &argvec)
elementwise division
Definition: Vector2.hh:846
class representing rigid motion by dual quaternions
DualQuaternion< QUAT_TYPE > Inverse() const
Slim class bundeling pose parametrization and associated covariance matrix.
Vector2< T > & operator-=(Vector2< T > &vec, const Vector2< T > &argvec)
sub operator for two Vectors
Definition: Vector2.hh:839
BIASMathBase_EXPORT Vector2< T > & operator+=(Vector2< T > &vec, const Vector2< T > &argvec)
add operator for two Vectors
Definition: Vector2.hh:830
void Add(const DualQuaternion< QUAT_TYPE > &r, DualQuaternion< QUAT_TYPE > &res) const
Vector2< T > & operator*=(Vector2< T > &vec, const T &scalar)
Multiplication operator with scalar argument.
Definition: Vector2.hh:873
class Vector3 contains a Vector of fixed dim.
Definition: Matrix.hh:53
matrix class with arbitrary size, indexing is row major.
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44