KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gr_rigid_object.h
Go to the documentation of this file.
1 
34 /* =========================================================================== *
35 |
36 | Copyright (c) 1994-2008 by Kobus Barnard (author).
37 |
38 | Personal and educational use of this code is granted, provided that this
39 | header is kept intact, and that the authorship is not misrepresented, that
40 | its use is acknowledged in publications, and relevant papers are cited.
41 |
42 | For other use contact the author (kobus AT cs DOT arizona DOT edu).
43 |
44 | Please note that the code in this file has not necessarily been adequately
45 | tested. Naturally, there is no guarantee of performance, support, or fitness
46 | for any particular task. Nonetheless, I am interested in hearing about
47 | problems that you encounter.
48 |
49 | Authors:
50 | Joseph Schlecht, Luca Del Pero
51 |
52 * =========================================================================== */
53 
61 #ifndef KJB_RIGID_OBJECT_H
62 #define KJB_RIGID_OBJECT_H
63 
64 #include <m_cpp/m_vector.h>
65 
66 #include "l_cpp/l_transformable.h"
67 #include "l_cpp/l_cloneable.h"
68 #include "g_cpp/g_quaternion.h"
69 #include <m_cpp/m_matrix.h>
70 
71 #define RO_PITCH 0
72 #define RO_YAW 1
73 #define RO_ROLL 2
74 
75 #define RO_ANGLE_EPSILON 1e-120
76 
77 namespace kjb
78 {
79  /* @class Rigid object: Implements basic transformation for rigid objects,
80  * such translations and rotations. The object can be translated and rotated
81  * around its three main axes using pitch, yaw and roll angles, following
82  * classic Tait-Bryan formulation (ie, changing the pitch at a given moment
83  * will rotate the object around its x-axis). Rotations are always performed in
84  * the following order: pitch, yaw and roll. Quaternions are used to
85  * perform rotations.
86  */
87  class Rigid_object : public Transformable, public Cloneable
88  {
89  typedef Rigid_object Self;
90  public:
92  q(0.0, 0.0, 0.0, kjb::Quaternion::XYZR),temp_matrix(4,4)
93  {
94 
95  }
96 
97  Rigid_object(const Rigid_object & ro);
98  virtual Rigid_object& operator=(const Rigid_object& src);
99  virtual ~Rigid_object() {}
100 
107  virtual void swap(Self& other)
108  {
109  q.swap(other.q);
110  temp_matrix.swap(other.temp_matrix);
111  }
112 
114  virtual void translate(double dx, double dy, double dz);
115 
120  virtual void rotate(double dpitch, double dyaw, double droll);
121 
129  virtual void compute_new_euler_angles_on_rotations(double dpitch, double dyaw, double droll, kjb::Vector & angles) const;
130 
134  virtual void set_rotations(double pitch, double yaw, double roll);
135 
139  virtual void set_rotations_and_translate(double pitch, double yaw, double roll, double dx, double dy, double dz);
140 
141 
142  virtual Rigid_object * clone() const = 0;
143 
147  virtual void transform(const kjb::Matrix & M) = 0;
148 
151  inline const Matrix & get_rotations() const
152  {
153  //return transformation_matrix;
154  return q.get_rotation_matrix();
155  }
156 
158  inline const Vector& get_euler_angles() const
159  {
160  return q.get_euler_angles();
161  }
162 
169  {
170  q.set_euler_mode(imode);
171  }
172 
174  inline const kjb::Quaternion & get_orientation() const
175  {
176  return q;
177  }
178 
180  void set_orientation(const Quaternion& orientation);
181 
182  private:
183 
184  Quaternion q;
185  Matrix temp_matrix;
186 
187  };
188 }
189 
190 #endif
virtual void translate(double dx, double dy, double dz)
Translates this rigid object.
Definition: gr_rigid_object.cpp:86
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Abstract class to apply a linear transformation to this object.
const Matrix & get_rotation_matrix() const
Definition: g_quaternion.cpp:282
const Matrix & get_rotations() const
Returns the current transformation matrix, that is used to store the rotation to be applied to the ob...
Definition: gr_rigid_object.h:151
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Euler_mode
Definition: g_quaternion.h:55
virtual void compute_new_euler_angles_on_rotations(double dpitch, double dyaw, double droll, kjb::Vector &angles) const
computes the new values for the object's euler angles, after a rotation of dpitch around the object's...
Definition: gr_rigid_object.cpp:123
virtual void set_rotations(double pitch, double yaw, double roll)
rotate this object so that its pitch, yaw and roll match the input values
Definition: gr_rigid_object.cpp:142
Abstract class to clone this object.
Definition: l_cloneable.h:45
Definition: g_quaternion.h:40
const kjb::Quaternion & get_orientation() const
returns the quaternion defining this object's orientation
Definition: gr_rigid_object.h:174
void swap(Self &other)
Definition: g_quaternion.cpp:250
void set_orientation(const Quaternion &orientation)
sets the orientation of this object from an input quaternion
Definition: gr_rigid_object.cpp:179
Abstract class to clone this object.
Abstract class to apply a linear transformation to this object.
Definition: g_transformable.h:79
virtual void transform(const kjb::Matrix &M)=0
virtual Rigid_object & operator=(const Rigid_object &src)
Definition: gr_rigid_object.cpp:73
Quaternion & set_euler_mode(Euler_mode m)
Definition: g_quaternion.cpp:516
const Vector & get_euler_angles() const
returns vector [phi, theta, psi]
Definition: g_quaternion.cpp:308
virtual void rotate(double dpitch, double dyaw, double droll)
rotate this object around its x-axis by dpitch, the y-axis by dyaw, and its z-axis by droll (in this ...
Definition: gr_rigid_object.cpp:105
const Vector & get_euler_angles() const
returns vector [pitch, yaw, roll]
Definition: gr_rigid_object.h:158
Rigid_object()
Definition: gr_rigid_object.h:91
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
virtual void swap(Self &other)
Definition: gr_rigid_object.h:107
void swap(Matrix &other)
Swap the representations of two matrices.
Definition: m_matrix.h:532
virtual void set_rotations_and_translate(double pitch, double yaw, double roll, double dx, double dy, double dz)
rotate this object so that its pitch, yaw and roll match the input values, and translates it ...
Definition: gr_rigid_object.cpp:169
Definition: gr_rigid_object.h:87
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void set_rotation_mode(kjb::Quaternion::Euler_mode imode)
Definition: gr_rigid_object.h:168
virtual ~Rigid_object()
Definition: gr_rigid_object.h:99
virtual Rigid_object * clone() const =0
Processes an Option from program command-line arguments.