Main MRPT website > C++ reference
MRPT logo
CPose3D.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2015, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CPOSE3D_H
10 #define CPOSE3D_H
11 
12 #include <mrpt/poses/CPose.h>
14 #include <mrpt/math/CQuaternion.h>
15 
16 namespace mrpt
17 {
18 namespace poses
19 {
22 
24 
25  /** A class used to store a 3D pose (a 3D translation + a rotation in 3D).
26  * The 6D transformation in SE(3) stored in this class is kept in two
27  * separate containers: a 3-array for the translation, and a 3x3 rotation matrix.
28  *
29  * This class allows parameterizing 6D poses as a 6-vector: [x y z yaw pitch roll] (read below
30  * for the angles convention). Note however,
31  * that the yaw/pitch/roll angles are only computed (on-demand and transparently)
32  * when the user requests them. Normally, rotations and transformations are always handled
33  * via the 3x3 rotation matrix.
34  *
35  * Yaw/Pitch/Roll angles are defined as successive rotations around *local* (dynamic) axes in the Z/Y/X order:
36  *
37  * <div align=center>
38  * <img src="CPose3D.gif">
39  * </div>
40  *
41  * It may be extremely confusing and annoying to find a different criterion also involving
42  * the names "yaw, pitch, roll" but regarding rotations around *global* (static) axes.
43  * Fortunately, it's very easy to see (by writing down the product of the three
44  * rotation matrices) that both conventions lead to exactly the same numbers.
45  * Only, that it's conventional to write the numbers in reverse order.
46  * That is, the same rotation can be described equivalently with any of these two
47  * parameterizations:
48  *
49  * - In local axes Z/Y/X convention: [yaw pitch roll] (This is the convention used in mrpt::poses::CPose3D)
50  * - In global axes X/Y/Z convention: [roll pitch yaw] (One of the Euler angles conventions)
51  *
52  * For further descriptions of point & pose classes, see mrpt::poses::CPoseOrPoint or refer
53  * to the [2D/3D Geometry tutorial](http://www.mrpt.org/2D_3D_Geometry) online.
54  *
55  * To change the individual components of the pose, use CPose3D::setFromValues. This class assures that the internal
56  * 3x3 rotation matrix is always up-to-date with the "yaw pitch roll" members.
57  *
58  * Rotations in 3D can be also represented by quaternions. See mrpt::math::CQuaternion, and method CPose3D::getAsQuaternion.
59  *
60  * This class and CPose3DQuat are very similar, and they can be converted to the each other automatically via transformation constructors.
61  *
62  * There are Lie algebra methods: \a exp and \a ln (see the methods for documentation).
63  *
64  * \note Read also: "A tutorial on SE(3) transformation parameterizations and on-manifold optimization", (Technical report), 2010-2014. [PDF](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf)
65  *
66  * \ingroup poses_grp
67  * \sa CPoseOrPoint,CPoint3D, mrpt::math::CQuaternion
68  */
69  class BASE_IMPEXP CPose3D : public CPose<CPose3D>, public mrpt::utils::CSerializable
70  {
71  // This must be added to any CSerializable derived class:
73 
74  public:
75  mrpt::math::CArrayDouble<3> m_coords; //!< The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods.
76  protected:
77  mrpt::math::CMatrixDouble33 m_ROT; //!< The 3x3 rotation matrix, access with getRotationMatrix(), setRotationMatrix() (It's not safe to set this field as public)
78 
79  mutable bool m_ypr_uptodate; //!< Whether yaw/pitch/roll members are up-to-date since the last rotation matrix update.
80  mutable double m_yaw, m_pitch, m_roll; //!< These variables are updated every time that the object rotation matrix is modified (construction, loading from values, pose composition, etc )
81 
82  /** Rebuild the homog matrix from the angles. */
83  void rebuildRotationMatrix();
84 
85  /** Updates Yaw/pitch/roll members from the m_ROT */
86  inline void updateYawPitchRoll() const { if (!m_ypr_uptodate) { m_ypr_uptodate=true; getYawPitchRoll( m_yaw, m_pitch, m_roll ); } }
87 
88  public:
89  /** @name Constructors
90  @{ */
91 
92  /** Default constructor, with all the coordinates set to zero. */
93  CPose3D();
94 
95  /** Constructor with initilization of the pose; (remember that angles are always given in radians!) */
96  CPose3D(const double x,const double y,const double z,const double yaw=0, const double pitch=0, const double roll=0);
97 
98  /** Constructor from a 4x4 homogeneous matrix - the passed matrix can be actually of any size larger than or equal 3x4, since only those first values are used (the last row of a homogeneous 4x4 matrix are always fixed). */
99  explicit CPose3D(const math::CMatrixDouble &m);
100 
101  /** Constructor from a 4x4 homogeneous matrix: */
102  explicit CPose3D(const math::CMatrixDouble44 &m);
103 
104  /** Constructor from a 3x3 rotation matrix and a the translation given as a 3-vector, a 3-array, a CPoint3D or a mrpt::math::TPoint3D */
105  template <class MATRIX33,class VECTOR3>
106  inline CPose3D(const MATRIX33 &rot, const VECTOR3& xyz) : m_ROT(mrpt::math::UNINITIALIZED_MATRIX), m_ypr_uptodate(false)
107  {
109  for (int r=0;r<3;r++)
110  for (int c=0;c<3;c++)
111  m_ROT(r,c)=rot.get_unsafe(r,c);
112  for (int r=0;r<3;r++) m_coords[r]=xyz[r];
113  }
114  //! \overload
115  inline CPose3D(const mrpt::math::CMatrixDouble33 &rot, const mrpt::math::CArrayDouble<3>& xyz) : m_coords(xyz),m_ROT(rot), m_ypr_uptodate(false)
116  { }
117 
118  /** Constructor from a CPose2D object.
119  */
120  CPose3D(const CPose2D &);
121 
122  /** Constructor from a CPoint3D object.
123  */
124  CPose3D(const CPoint3D &);
125 
126  /** Constructor from lightweight object.
127  */
128  CPose3D(const mrpt::math::TPose3D &);
129 
130  /** Constructor from a quaternion (which only represents the 3D rotation part) and a 3D displacement. */
131  CPose3D(const mrpt::math::CQuaternionDouble &q, const double x, const double y, const double z );
132 
133  /** Constructor from a CPose3DQuat. */
134  CPose3D(const CPose3DQuat &);
135 
136  /** Constructor from a CPose3DRotVec. */
137  CPose3D(const CPose3DRotVec &p );
138 
139  /** Fast constructor that leaves all the data uninitialized - call with UNINITIALIZED_POSE as argument */
140  inline CPose3D(TConstructorFlags_Poses ) : m_ROT(mrpt::math::UNINITIALIZED_MATRIX), m_ypr_uptodate(false) { }
141 
142  /** Constructor from an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 tx ty tz]
143  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are the 3D translation of the pose
144  * \sa setFrom12Vector, getAs12Vector
145  */
146  inline explicit CPose3D(const mrpt::math::CArrayDouble<12> &vec12) : m_ROT( mrpt::math::UNINITIALIZED_MATRIX ), m_ypr_uptodate(false) {
147  setFrom12Vector(vec12);
148  }
149 
150  /** @} */ // end Constructors
151 
152 
153 
154  /** @name Access 3x3 rotation and 4x4 homogeneous matrices
155  @{ */
156 
157  /** Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (translation+orientation).
158  * \sa getInverseHomogeneousMatrix, getRotationMatrix
159  */
161  {
162  out_HM.insertMatrix(0,0,m_ROT);
163  for (int i=0;i<3;i++) out_HM(i,3)=m_coords[i];
164  out_HM(3,0)=out_HM(3,1)=out_HM(3,2)=0.; out_HM(3,3)=1.;
165  }
166 
167  inline mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const { mrpt::math::CMatrixDouble44 M; getHomogeneousMatrix(M); return M;}
168 
169  /** Get the 3x3 rotation matrix \sa getHomogeneousMatrix */
170  inline void getRotationMatrix( mrpt::math::CMatrixDouble33 & ROT ) const { ROT = m_ROT; }
171  //! \overload
172  inline const mrpt::math::CMatrixDouble33 & getRotationMatrix() const { return m_ROT; }
173 
174  /** Sets the 3x3 rotation matrix \sa getRotationMatrix, getHomogeneousMatrix */
175  inline void setRotationMatrix( const mrpt::math::CMatrixDouble33 & ROT ) { m_ROT = ROT; m_ypr_uptodate = false; }
176 
177  /** @} */ // end rot and HM
178 
179 
180  /** @name Pose-pose and pose-point compositions and operators
181  @{ */
182 
183  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
184  inline CPose3D operator + (const CPose3D& b) const
185  {
186  CPose3D ret(UNINITIALIZED_POSE);
187  ret.composeFrom(*this,b);
188  return ret;
189  }
190 
191  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
192  CPoint3D operator + (const CPoint3D& b) const;
193 
194  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
195  CPoint3D operator + (const CPoint2D& b) const;
196 
197  /** Computes the spherical coordinates of a 3D point as seen from the 6D pose specified by this object. For the coordinate system see the top of this page. */
198  void sphericalCoordinates(
199  const mrpt::math::TPoint3D &point,
200  double &out_range,
201  double &out_yaw,
202  double &out_pitch ) const;
203 
204  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L \f$ with G and L being 3D points and P this 6D pose.
205  * If pointers are provided, the corresponding Jacobians are returned.
206  * "out_jacobian_df_dse3" stands for the Jacobian with respect to the 6D locally Euclidean vector in the tangent space of SE(3).
207  * See [this report](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf) for mathematical details.
208  * \param If set to true, the Jacobian "out_jacobian_df_dpose" uses a fastest linearized appoximation (valid only for small rotations!).
209  */
210  void composePoint(double lx,double ly,double lz, double &gx, double &gy, double &gz,
211  mrpt::math::CMatrixFixedNumeric<double,3,3> *out_jacobian_df_dpoint=NULL,
212  mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dpose=NULL,
213  mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dse3=NULL,
214  bool use_small_rot_approx = false) const;
215 
216  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L \f$ with G and L being 3D points and P this 6D pose.
217  * \note local_point is passed by value to allow global and local point to be the same variable
218  */
219  inline void composePoint(const mrpt::math::TPoint3D &local_point, mrpt::math::TPoint3D &global_point) const {
220  composePoint(local_point.x,local_point.y,local_point.z, global_point.x,global_point.y,global_point.z );
221  }
222  /** This version of the method assumes that the resulting point has no Z component (use with caution!) */
223  inline void composePoint(const mrpt::math::TPoint3D &local_point, mrpt::math::TPoint2D &global_point) const {
224  double dummy_z;
225  composePoint(local_point.x,local_point.y,local_point.z, global_point.x,global_point.y,dummy_z );
226  }
227 
228  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L \f$ with G and L being 3D points and P this 6D pose. */
229  inline void composePoint(double lx,double ly,double lz, float &gx, float &gy, float &gz ) const {
230  double ggx, ggy,ggz;
231  composePoint(lx,ly,lz,ggx,ggy,ggz);
232  gx = ggx; gy = ggy; gz = ggz;
233  }
234 
235  /** Computes the 3D point L such as \f$ L = G \ominus this \f$.
236  * If pointers are provided, the corresponding Jacobians are returned.
237  * "out_jacobian_df_dse3" stands for the Jacobian with respect to the 6D locally Euclidean vector in the tangent space of SE(3).
238  * See [this report](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf) for mathematical details.
239  * \sa composePoint, composeFrom
240  */
241  void inverseComposePoint(const double gx,const double gy,const double gz,double &lx,double &ly,double &lz,
242  mrpt::math::CMatrixFixedNumeric<double,3,3> *out_jacobian_df_dpoint=NULL,
243  mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dpose=NULL,
244  mrpt::math::CMatrixFixedNumeric<double,3,6> *out_jacobian_df_dse3=NULL ) const;
245 
246  /** \overload */
248  inverseComposePoint(g.x,g.y,g.z, l.x,l.y,l.z);
249  }
250 
251  /** \overload for 2D points \exception If the z component of the result is greater than some epsilon */
252  inline void inverseComposePoint(const mrpt::math::TPoint2D &g, mrpt::math::TPoint2D &l, const double eps=1e-6) const {
253  double lz;
254  inverseComposePoint(g.x,g.y,0, l.x,l.y,lz);
255  ASSERT_BELOW_(std::abs(lz),eps)
256  }
257 
258  /** Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids the temporary object.
259  * \note A or B can be "this" without problems.
260  */
261  void composeFrom(const CPose3D& A, const CPose3D& B );
262 
263  /** Make \f$ this = this \oplus b \f$ (\a b can be "this" without problems) */
264  inline CPose3D& operator += (const CPose3D& b)
265  {
266  composeFrom(*this,b);
267  return *this;
268  }
269 
270  /** Makes \f$ this = A \ominus B \f$ this method is slightly more efficient than "this= A - B;" since it avoids the temporary object.
271  * \note A or B can be "this" without problems.
272  * \sa composeFrom, composePoint
273  */
274  void inverseComposeFrom(const CPose3D& A, const CPose3D& B );
275 
276  /** Compute \f$ RET = this \oplus b \f$ */
277  inline CPose3D operator - (const CPose3D& b) const
278  {
279  CPose3D ret(UNINITIALIZED_POSE);
280  ret.inverseComposeFrom(*this,b);
281  return ret;
282  }
283 
284  /** Convert this pose into its inverse, saving the result in itself. \sa operator- */
285  void inverse();
286 
287  /** makes: this = p (+) this */
288  inline void changeCoordinatesReference( const CPose3D & p ) { composeFrom(p,CPose3D(*this)); }
289 
290  /** @} */ // compositions
291 
292 
293  /** @name Access and modify contents
294  @{ */
295 
296  /** Scalar sum of all 6 components: This is diferent from poses composition, which is implemented as "+" operators.
297  * \sa normalizeAngles
298  */
299  void addComponents(const CPose3D &p);
300 
301  /** Rebuild the internal matrix & update the yaw/pitch/roll angles within the ]-PI,PI] range (Must be called after using addComponents)
302  * \sa addComponents
303  */
304  void normalizeAngles();
305 
306  /** Scalar multiplication of x,y,z,yaw,pitch & roll (angles will be wrapped to the ]-pi,pi] interval). */
307  void operator *=(const double s);
308 
309  /** Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes the internal rotation matrix.
310  * \sa getYawPitchRoll, setYawPitchRoll
311  */
312  void setFromValues(
313  const double x0,
314  const double y0,
315  const double z0,
316  const double yaw=0,
317  const double pitch=0,
318  const double roll=0);
319 
320  /** Set the pose from a 3D position (meters) and a quaternion, stored as [x y z qr qx qy qz] in a 7-element vector.
321  * \sa setFromValues, getYawPitchRoll, setYawPitchRoll, CQuaternion, getAsQuaternion
322  */
323  template <typename VECTORLIKE>
324  inline void setFromXYZQ(
325  const VECTORLIKE &v,
326  const size_t index_offset = 0)
327  {
328  ASSERT_ABOVEEQ_(v.size(), 7+index_offset)
329  // The 3x3 rotation part:
330  mrpt::math::CQuaternion<typename VECTORLIKE::value_type> q( v[index_offset+3],v[index_offset+4],v[index_offset+5],v[index_offset+6] );
331  q.rotationMatrixNoResize(m_ROT);
332  m_ypr_uptodate=false;
333  m_coords[0] = v[index_offset+0];
334  m_coords[1] = v[index_offset+1];
335  m_coords[2] = v[index_offset+2];
336  }
337 
338  /** Set the 3 angles of the 3D pose (in radians) - This method recomputes the internal rotation coordinates matrix.
339  * \sa getYawPitchRoll, setFromValues
340  */
341  inline void setYawPitchRoll(
342  const double yaw_,
343  const double pitch_,
344  const double roll_)
345  {
346  setFromValues(x(),y(),z(),yaw_,pitch_,roll_);
347  }
348 
349  /** Set pose from an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 tx ty tz]
350  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are the 3D translation of the pose
351  * \sa getAs12Vector
352  */
353  template <class ARRAYORVECTOR>
354  inline void setFrom12Vector(const ARRAYORVECTOR &vec12)
355  {
356  m_ROT.set_unsafe(0,0, vec12[0]); m_ROT.set_unsafe(0,1, vec12[3]); m_ROT.set_unsafe(0,2, vec12[6]);
357  m_ROT.set_unsafe(1,0, vec12[1]); m_ROT.set_unsafe(1,1, vec12[4]); m_ROT.set_unsafe(1,2, vec12[7]);
358  m_ROT.set_unsafe(2,0, vec12[2]); m_ROT.set_unsafe(2,1, vec12[5]); m_ROT.set_unsafe(2,2, vec12[8]);
359  m_ypr_uptodate = false;
360  m_coords[0] = vec12[ 9];
361  m_coords[1] = vec12[10];
362  m_coords[2] = vec12[11];
363  }
364 
365  /** Get the pose representation as an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 tx ty tz]
366  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are the 3D translation of the pose
367  * \sa setFrom12Vector
368  */
369  template <class ARRAYORVECTOR>
370  inline void getAs12Vector(ARRAYORVECTOR &vec12) const
371  {
372  vec12[0] = m_ROT.get_unsafe(0,0); vec12[3] = m_ROT.get_unsafe(0,1); vec12[6] = m_ROT.get_unsafe(0,2);
373  vec12[1] = m_ROT.get_unsafe(1,0); vec12[4] = m_ROT.get_unsafe(1,1); vec12[7] = m_ROT.get_unsafe(1,2);
374  vec12[2] = m_ROT.get_unsafe(2,0); vec12[5] = m_ROT.get_unsafe(2,1); vec12[8] = m_ROT.get_unsafe(2,2);
375  vec12[ 9] = m_coords[0];
376  vec12[10] = m_coords[1];
377  vec12[11] = m_coords[2];
378  }
379 
380  /** Returns the three angles (yaw, pitch, roll), in radians, from the rotation matrix.
381  * \sa setFromValues, yaw, pitch, roll
382  */
383  void getYawPitchRoll( double &yaw, double &pitch, double &roll ) const;
384 
385  inline double yaw() const { updateYawPitchRoll(); return m_yaw; } //!< Get the YAW angle (in radians) \sa setFromValues
386  inline double pitch() const { updateYawPitchRoll(); return m_pitch; } //!< Get the PITCH angle (in radians) \sa setFromValues
387  inline double roll() const { updateYawPitchRoll(); return m_roll; } //!< Get the ROLL angle (in radians) \sa setFromValues
388 
389  /** Returns a 1x6 vector with [x y z yaw pitch roll] */
390  void getAsVector(mrpt::math::CVectorDouble &v) const;
391  /// \overload
392  void getAsVector(mrpt::math::CArrayDouble<6> &v) const;
393 
394  /** Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored)
395  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2) \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) + \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2) \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\ \end{array}\right) \f]
396  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
397  * \param out_dq_dr If provided, the 4x3 Jacobian of the transformation will be computed and stored here. It's the Jacobian of the transformation from (yaw pitch roll) to (qr qx qy qz).
398  */
399  void getAsQuaternion(
402  ) const;
403 
404  inline const double &operator[](unsigned int i) const
405  {
406  updateYawPitchRoll();
407  switch(i)
408  {
409  case 0:return m_coords[0];
410  case 1:return m_coords[1];
411  case 2:return m_coords[2];
412  case 3:return m_yaw;
413  case 4:return m_pitch;
414  case 5:return m_roll;
415  default:
416  throw std::runtime_error("CPose3D::operator[]: Index of bounds.");
417  }
418  }
419  // CPose3D CANNOT have a write [] operator, since it'd leave the object in an inconsistent state (outdated rotation matrix).
420  // Use setFromValues() instead.
421  // inline double &operator[](unsigned int i)
422 
423  /** Returns a human-readable textual representation of the object (eg: "[x y z yaw pitch roll]", angles in degrees.)
424  * \sa fromString
425  */
426  void asString(std::string &s) const { using mrpt::utils::RAD2DEG; updateYawPitchRoll(); s = mrpt::format("[%f %f %f %f %f %f]",m_coords[0],m_coords[1],m_coords[2],RAD2DEG(m_yaw),RAD2DEG(m_pitch),RAD2DEG(m_roll)); }
427  inline std::string asString() const { std::string s; asString(s); return s; }
428 
429  /** Set the current object value from a string generated by 'asString' (eg: "[x y z yaw pitch roll]", angles in deg. )
430  * \sa asString
431  * \exception std::exception On invalid format
432  */
433  void fromString(const std::string &s) {
434  using mrpt::utils::DEG2RAD;
436  if (!m.fromMatlabStringFormat(s)) THROW_EXCEPTION("Malformed expression in ::fromString");
437  ASSERTMSG_(mrpt::math::size(m,1)==1 && mrpt::math::size(m,2)==6, "Wrong size of vector in ::fromString");
438  this->setFromValues(m.get_unsafe(0,0),m.get_unsafe(0,1),m.get_unsafe(0,2),DEG2RAD(m.get_unsafe(0,3)),DEG2RAD(m.get_unsafe(0,4)),DEG2RAD(m.get_unsafe(0,5)));
439  }
440 
441  /** Return true if the 6D pose represents a Z axis almost exactly vertical (upwards or downwards), with a given tolerance (if set to 0 exact horizontality is tested). */
442  bool isHorizontal( const double tolerance=0) const;
443 
444  /** The euclidean distance between two poses taken as two 6-length vectors (angles in radians). */
445  double distanceEuclidean6D( const CPose3D &o ) const;
446 
447  /** @} */ // modif. components
448 
449 
450 
451  /** @name Lie Algebra methods
452  @{ */
453 
454  /** Exponentiate a Vector in the SE(3) Lie Algebra to generate a new CPose3D (static method).
455  * \param pseudo_exponential If set to true, XYZ are copied from the first three elements in the vector instead of using the proper Lie Algebra formulas (this is actually the common practice in robotics literature).
456  * \note Method from TooN (C) Tom Drummond (GNU GPL) */
457  static CPose3D exp(const mrpt::math::CArrayNumeric<double,6> & vect, bool pseudo_exponential = false);
458 
459  /** \overload */
460  static void exp(const mrpt::math::CArrayNumeric<double,6> & vect, CPose3D &out_pose, bool pseudo_exponential = false);
461 
462  /** Exponentiate a vector in the Lie algebra to generate a new SO(3) (a 3x3 rotation matrix).
463  * \note Method from TooN (C) Tom Drummond (GNU GPL) */
464  static mrpt::math::CMatrixDouble33 exp_rotation(const mrpt::math::CArrayNumeric<double,3> & vect);
465 
466 
467  /** Take the logarithm of the 3x4 matrix defined by this pose, generating the corresponding vector in the SE(3) Lie Algebra.
468  * \note Method from TooN (C) Tom Drummond (GNU GPL)
469  * \sa ln_jacob
470  */
471  void ln(mrpt::math::CArrayDouble<6> &out_ln) const;
472 
473  /// \overload
474  inline mrpt::math::CArrayDouble<6> ln() const { mrpt::math::CArrayDouble<6> ret; ln(ret); return ret; }
475 
476  /** Jacobian of the logarithm of the 3x4 matrix defined by this pose.
477  * \note Method from TooN (C) Tom Drummond (GNU GPL)
478  * \sa ln
479  */
480  void ln_jacob(mrpt::math::CMatrixFixedNumeric<double,6,12> &J) const;
481 
482  /** Static function to compute the Jacobian of the SO(3) Logarithm function, evaluated at a given 3x3 rotation matrix R.
483  * \sa ln, ln_jacob
484  */
485  static void ln_rot_jacob(const mrpt::math::CMatrixDouble33 &R, mrpt::math::CMatrixFixedNumeric<double,3,9> &M);
486 
487  /** Take the logarithm of the 3x3 rotation matrix, generating the corresponding vector in the Lie Algebra.
488  * \note Method from TooN (C) Tom Drummond (GNU GPL) */
489  mrpt::math::CArrayDouble<3> ln_rotation() const;
490 
491  /** The Jacobian d (e^eps * D) / d eps , with eps=increment in Lie Algebra.
492  * \note Eq. 10.3.5 in tech report http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf */
493  static void jacob_dexpeD_de(const CPose3D &D, Eigen::Matrix<double,12,6> & jacob);
494 
495  /** The Jacobian d (A * e^eps * D) / d eps , with eps=increment in Lie Algebra.
496  * \note Eq. 10.3.7 in tech report http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf */
497  static void jacob_dAexpeD_de(const CPose3D &A, const CPose3D &D, Eigen::Matrix<double,12,6> & jacob);
498 
499  /** @} */
500 
501  void setToNaN();
502 
503  typedef CPose3D type_value; //!< Used to emulate CPosePDF types, for example, in mrpt::graphs::CNetworkOfPoses
504  enum { is_3D_val = 1 };
505  static inline bool is_3D() { return is_3D_val!=0; }
506  enum { rotation_dimensions = 3 };
507  enum { is_PDF_val = 0 };
508  static inline bool is_PDF() { return is_PDF_val!=0; }
509 
510  inline const type_value & getPoseMean() const { return *this; }
511  inline type_value & getPoseMean() { return *this; }
512 
513  /** @name STL-like methods and typedefs
514  @{ */
515  typedef double value_type; //!< The type of the elements
516  typedef double& reference;
517  typedef const double& const_reference;
518  typedef std::size_t size_type;
519  typedef std::ptrdiff_t difference_type;
520 
521 
522  // size is constant
523  enum { static_size = 6 };
524  static inline size_type size() { return static_size; }
525  static inline bool empty() { return false; }
526  static inline size_type max_size() { return static_size; }
527  static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPose3D to %u.",static_cast<unsigned>(n))); }
528  /** @} */
529 
530  }; // End of class def.
531  DEFINE_SERIALIZABLE_POST( CPose3D )
532 
533 
534  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const CPose3D& p);
535 
536  /** Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x y z yaw pitch roll) */
537  CPose3D BASE_IMPEXP operator -(const CPose3D &p);
538 
539  bool BASE_IMPEXP operator==(const CPose3D &p1,const CPose3D &p2);
540  bool BASE_IMPEXP operator!=(const CPose3D &p1,const CPose3D &p2);
541 
542 
543  } // End of namespace
544 } // End of namespace
545 
546 #endif
const double & const_reference
Definition: CPose3D.h:517
#define ASSERT_EQUAL_(__A, __B)
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:387
double y
X,Y coordinates.
void inverseComposeFrom(const CPose3D &A, const CPose3D &B)
Makes this method is slightly more efficient than "this= A - B;" since it avoids the temporary objec...
void composePoint(const mrpt::math::TPoint3D &local_point, mrpt::math::TPoint3D &global_point) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.h:219
double DEG2RAD(const double x)
Degrees to radians.
CPose2D BASE_IMPEXP operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
void setFromXYZQ(const VECTORLIKE &v, const size_t index_offset=0)
Set the pose from a 3D position (meters) and a quaternion, stored as [x y z qr qx qy qz] in a 7-eleme...
Definition: CPose3D.h:324
#define DEFINE_SERIALIZABLE_PRE(class_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[x y z yaw pitch roll]"...
Definition: CPose3D.h:426
mrpt::math::CArrayDouble< 6 > ln() const
Definition: CPose3D.h:474
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define THROW_EXCEPTION(msg)
#define ASSERT_BELOW_(__A, __B)
void setYawPitchRoll(const double yaw_, const double pitch_, const double roll_)
Set the 3 angles of the 3D pose (in radians) - This method recomputes the internal rotation coordinat...
Definition: CPose3D.h:341
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually...
Definition: CArrayNumeric.h:25
size_t size(const MATRIXLIKE &m, int dim)
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:51
STL namespace.
CPose3D(TConstructorFlags_Poses)
Fast constructor that leaves all the data uninitialized - call with UNINITIALIZED_POSE as argument...
Definition: CPose3D.h:140
double z
X,Y,Z coordinates.
const type_value & getPoseMean() const
Definition: CPose3D.h:510
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:170
double value_type
The type of the elements.
Definition: CPose3D.h:515
void setRotationMatrix(const mrpt::math::CMatrixDouble33 &ROT)
Sets the 3x3 rotation matrix.
Definition: CPose3D.h:175
double & reference
Definition: CPose3D.h:516
static bool is_PDF()
Definition: CPose3D.h:508
void composePoint(double lx, double ly, double lz, float &gx, float &gy, float &gz) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.h:229
const double & operator[](unsigned int i) const
Definition: CPose3D.h:404
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:385
CPose3D(const mrpt::math::CMatrixDouble33 &rot, const mrpt::math::CArrayDouble< 3 > &xyz)
Definition: CPose3D.h:115
void inverseComposePoint(const mrpt::math::TPoint3D &g, mrpt::math::TPoint3D &l) const
Definition: CPose3D.h:247
CPose3D(const mrpt::math::CArrayDouble< 12 > &vec12)
Constructor from an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 tx ty tz] wher...
Definition: CPose3D.h:146
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[x y z yaw pitch roll]"...
Definition: CPose3D.h:433
A numeric matrix of compile-time fixed size.
type_value & getPoseMean()
Definition: CPose3D.h:511
double RAD2DEG(const double x)
Radians to degrees.
void composePoint(const mrpt::math::TPoint3D &local_point, mrpt::math::TPoint2D &global_point) const
This version of the method assumes that the resulting point has no Z component (use with caution!) ...
Definition: CPose3D.h:223
class BASE_IMPEXP CSerializable
Definition: CStream.h:23
void getHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
Definition: CPose3D.h:160
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
Definition: ops_vectors.h:70
mrpt::math::TPoint2D BASE_IMPEXP operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
void changeCoordinatesReference(const CPose3D &p)
makes: this = p (+) this
Definition: CPose3D.h:288
A base class for representing a pose in 2D or 3D.
Definition: CPose.h:25
CPose3D type_value
Used to emulate CPosePDF types, for example, in mrpt::graphs::CNetworkOfPoses.
Definition: CPose3D.h:503
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:74
static void resize(const size_t n)
Definition: CPose3D.h:527
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
Definition: eigen_frwds.h:64
std::ptrdiff_t difference_type
Definition: CPose3D.h:519
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:41
#define DEG2RAD
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
A class used to store a 2D point.
Definition: CPoint2D.h:36
T abs(T x)
Definition: nanoflann.hpp:237
A class used to store a 3D point.
Definition: CPoint3D.h:32
void setFrom12Vector(const ARRAYORVECTOR &vec12)
Set pose from an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 tx ty tz] where r...
Definition: CPose3D.h:354
static size_type size()
Definition: CPose3D.h:524
std::size_t size_type
Definition: CPose3D.h:518
#define RAD2DEG
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
std::string asString() const
Definition: CPose3D.h:427
#define ASSERT_ABOVEEQ_(__A, __B)
A class used to store a 2D pose.
Definition: CPose2D.h:36
static size_type max_size()
Definition: CPose3D.h:526
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
void composeFrom(const CPose3D &A, const CPose3D &B)
Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids th...
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:386
CPose3D(const MATRIX33 &rot, const VECTOR3 &xyz)
Constructor from a 3x3 rotation matrix and a the translation given as a 3-vector, a 3-array...
Definition: CPose3D.h:106
static bool is_3D()
Definition: CPose3D.h:505
void inverseComposePoint(const mrpt::math::TPoint2D &g, mrpt::math::TPoint2D &l, const double eps=1e-6) const
Definition: CPose3D.h:252
#define DEFINE_SERIALIZABLE_POST(class_name)
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
Definition: CPose3D.h:167
A 3D pose, with a 3D translation and a rotation in 3D parameterized in rotation-vector form (equivale...
Definition: CPose3DRotVec.h:41
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ...
Definition: CQuaternion.h:42
Lightweight 3D point.
void getAs12Vector(ARRAYORVECTOR &vec12) const
Get the pose representation as an array with these 12 elements: [r11 r21 r31 r12 r22 r32 r13 r23 r33 ...
Definition: CPose3D.h:370
Lightweight 2D point.
#define ASSERTMSG_(f, __ERROR_MSG)
static bool empty()
Definition: CPose3D.h:525
std::vector< T1 > & operator*=(std::vector< T1 > &a, const std::vector< T2 > &b)
a*=b (element-wise multiplication)
Definition: ops_vectors.h:40
const mrpt::math::CMatrixDouble33 & getRotationMatrix() const
Definition: CPose3D.h:172



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015