MRPT  1.9.9
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-2018, 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>
16 
17 // Add for declaration of mexplus::from template specialization
19 
20 namespace mrpt::poses
21 {
22 class CPose3DQuat;
23 class CPose3DRotVec;
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
28  * matrix.
29  *
30  * This class allows parameterizing 6D poses as a 6-vector: [x y z yaw pitch
31  * roll] (read below
32  * for the angles convention). Note however,
33  * that the yaw/pitch/roll angles are only computed (on-demand and
34  * transparently)
35  * when the user requests them. Normally, rotations and transformations are
36  * always handled
37  * via the 3x3 rotation matrix.
38  *
39  * Yaw/Pitch/Roll angles are defined as successive rotations around *local*
40  * (dynamic) axes in the Z/Y/X order:
41  *
42  * <div align=center>
43  * <img src="CPose3D.gif">
44  * </div>
45  *
46  * It may be extremely confusing and annoying to find a different criterion also
47  * involving
48  * the names "yaw, pitch, roll" but regarding rotations around *global* (static)
49  * axes.
50  * Fortunately, it's very easy to see (by writing down the product of the three
51  * rotation matrices) that both conventions lead to exactly the same numbers.
52  * Only, that it's conventional to write the numbers in reverse order.
53  * That is, the same rotation can be described equivalently with any of these
54  * two
55  * parameterizations:
56  *
57  * - In local axes Z/Y/X convention: [yaw pitch roll] (This is the convention
58  * used in mrpt::poses::CPose3D)
59  * - In global axes X/Y/Z convention: [roll pitch yaw] (One of the Euler angles
60  * conventions)
61  *
62  * For further descriptions of point & pose classes, see
63  * mrpt::poses::CPoseOrPoint or refer
64  * to the [2D/3D Geometry tutorial](http://www.mrpt.org/2D_3D_Geometry) online.
65  *
66  * To change the individual components of the pose, use CPose3D::setFromValues.
67  * This class assures that the internal
68  * 3x3 rotation matrix is always up-to-date with the "yaw pitch roll" members.
69  *
70  * Rotations in 3D can be also represented by quaternions. See
71  * mrpt::math::CQuaternion, and method CPose3D::getAsQuaternion.
72  *
73  * This class and CPose3DQuat are very similar, and they can be converted to the
74  * each other automatically via transformation constructors.
75  *
76  * There are Lie algebra methods: \a exp and \a ln (see the methods for
77  * documentation).
78  *
79  * \note Read also: "A tutorial on SE(3) transformation parameterizations and
80  * on-manifold optimization", (Technical report), 2010-2014.
81  * [PDF](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf)
82  *
83  * \ingroup poses_grp
84  * \sa CPoseOrPoint,CPoint3D, mrpt::math::CQuaternion
85  */
86 class CPose3D : public CPose<CPose3D>, public mrpt::serialization::CSerializable
87 {
89 
90  // This must be added for declaration of MEX-related functions
92 
93  public:
94  /** The translation vector [x,y,z] access directly or with x(), y(), z()
95  * setter/getter methods. */
97 
98  protected:
99  /** The 3x3 rotation matrix, access with getRotationMatrix(),
100  * setRotationMatrix() (It's not safe to set this field as public) */
102 
103  /** Whether yaw/pitch/roll members are up-to-date since the last rotation
104  * matrix update. */
105  mutable bool m_ypr_uptodate;
106  /** These variables are updated every time that the object rotation matrix
107  * is modified (construction, loading from values, pose composition, etc )
108  */
109  mutable double m_yaw, m_pitch, m_roll;
110 
111  /** Rebuild the homog matrix from the angles. */
112  void rebuildRotationMatrix();
113 
114  /** Updates Yaw/pitch/roll members from the m_ROT */
115  inline void updateYawPitchRoll() const
116  {
117  if (!m_ypr_uptodate)
118  {
119  m_ypr_uptodate = true;
121  }
122  }
123 
124  public:
125  /** @name Constructors
126  @{ */
127 
128  /** Default constructor, with all the coordinates set to zero. */
129  CPose3D();
130 
131  /** Constructor with initilization of the pose; (remember that angles are
132  * always given in radians!) */
133  CPose3D(
134  const double x, const double y, const double z, const double yaw = 0,
135  const double pitch = 0, const double roll = 0);
136 
137  /** Constructor from a 4x4 homogeneous matrix - the passed matrix can be
138  * actually of any size larger than or equal 3x4, since only those first
139  * values are used (the last row of a homogeneous 4x4 matrix are always
140  * fixed). */
141  explicit CPose3D(const math::CMatrixDouble& m);
142 
143  /** Constructor from a 4x4 homogeneous matrix: */
144  explicit CPose3D(const math::CMatrixDouble44& m);
145 
146  /** Constructor from a 3x3 rotation matrix and a the translation given as a
147  * 3-vector, a 3-array, a CPoint3D or a mrpt::math::TPoint3D */
148  template <class MATRIX33, class VECTOR3>
149  inline CPose3D(const MATRIX33& rot, const VECTOR3& xyz)
151  {
152  ASSERT_EQUAL_(rot.rows(), 3);
153  ASSERT_EQUAL_(rot.cols(), 3);
154  ASSERT_EQUAL_(xyz.size(), 3);
155  for (int r = 0; r < 3; r++)
156  for (int c = 0; c < 3; c++) m_ROT(r, c) = rot(r, c);
157  for (int r = 0; r < 3; r++) m_coords[r] = xyz[r];
158  }
159  //! \overload
160  inline CPose3D(
161  const mrpt::math::CMatrixDouble33& rot,
162  const mrpt::math::CArrayDouble<3>& xyz)
163  : m_coords(xyz), m_ROT(rot), m_ypr_uptodate(false)
164  {
165  }
166 
167  /** Constructor from a CPose2D object.
168  */
169  explicit CPose3D(const CPose2D&);
170 
171  /** Constructor from a CPoint3D object.
172  */
173  explicit CPose3D(const CPoint3D&);
174 
175  /** Constructor from lightweight object.
176  */
177  explicit CPose3D(const mrpt::math::TPose3D&);
178 
180 
181  /** Constructor from a quaternion (which only represents the 3D rotation
182  * part) and a 3D displacement. */
183  CPose3D(
184  const mrpt::math::CQuaternionDouble& q, const double x, const double y,
185  const double z);
186 
187  /** Constructor from a CPose3DQuat. */
188  explicit CPose3D(const CPose3DQuat&);
189 
190  /** Constructor from a CPose3DRotVec. */
191  explicit CPose3D(const CPose3DRotVec& p);
192 
193  /** Fast constructor that leaves all the data uninitialized - call with
194  * UNINITIALIZED_POSE as argument */
197  {
198  }
199 
200  /** Constructor from an array with these 12 elements: [r11 r21 r31 r12 r22
201  * r32 r13 r23 r33 tx ty tz]
202  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are
203  * the 3D translation of the pose
204  * \sa setFrom12Vector, getAs12Vector
205  */
206  inline explicit CPose3D(const mrpt::math::CArrayDouble<12>& vec12)
208  {
209  setFrom12Vector(vec12);
210  }
211 
212  /** @} */ // end Constructors
213 
214  /** @name Access 3x3 rotation and 4x4 homogeneous matrices
215  @{ */
216 
217  /** Returns the corresponding 4x4 homogeneous transformation matrix for the
218  * point(translation) or pose (translation+orientation).
219  * \sa getInverseHomogeneousMatrix, getRotationMatrix
220  */
222  {
223  out_HM.insertMatrix(0, 0, m_ROT);
224  for (int i = 0; i < 3; i++) out_HM(i, 3) = m_coords[i];
225  out_HM(3, 0) = out_HM(3, 1) = out_HM(3, 2) = 0.;
226  out_HM(3, 3) = 1.;
227  }
228 
229  /** Get the 3x3 rotation matrix \sa getHomogeneousMatrix */
231  {
232  ROT = m_ROT;
233  }
234  //! \overload
236  {
237  return m_ROT;
238  }
239 
240  /** Sets the 3x3 rotation matrix \sa getRotationMatrix, getHomogeneousMatrix
241  */
243  {
244  m_ROT = ROT;
245  m_ypr_uptodate = false;
246  }
247 
248  /** @} */ // end rot and HM
249 
250  /** @name Pose-pose and pose-point compositions and operators
251  @{ */
252 
253  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
254  inline CPose3D operator+(const CPose3D& b) const
255  {
257  ret.composeFrom(*this, b);
258  return ret;
259  }
260 
261  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
262  CPoint3D operator+(const CPoint3D& b) const;
263 
264  /** The operator \f$ a \oplus b \f$ is the pose compounding operator. */
265  CPoint3D operator+(const CPoint2D& b) const;
266 
267  /** Computes the spherical coordinates of a 3D point as seen from the 6D
268  * pose specified by this object. For the coordinate system see the top of
269  * this page. */
271  const mrpt::math::TPoint3D& point, double& out_range, double& out_yaw,
272  double& out_pitch) const;
273 
274  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L
275  * \f$ with G and L being 3D points and P this 6D pose.
276  * If pointers are provided, the corresponding Jacobians are returned.
277  * "out_jacobian_df_dse3" stands for the Jacobian with respect to the 6D
278  * locally Euclidean vector in the tangent space of SE(3).
279  * See [this
280  * report](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf)
281  * for mathematical details.
282  * \param If set to true, the Jacobian "out_jacobian_df_dpose" uses a
283  * fastest linearized appoximation (valid only for small rotations!).
284  */
285  void composePoint(
286  double lx, double ly, double lz, double& gx, double& gy, double& gz,
287  mrpt::math::CMatrixFixedNumeric<double, 3, 3>* out_jacobian_df_dpoint =
288  nullptr,
289  mrpt::math::CMatrixFixedNumeric<double, 3, 6>* out_jacobian_df_dpose =
290  nullptr,
291  mrpt::math::CMatrixFixedNumeric<double, 3, 6>* out_jacobian_df_dse3 =
292  nullptr,
293  bool use_small_rot_approx = false) const;
294 
295  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L
296  * \f$ with G and L being 3D points and P this 6D pose.
297  * \note local_point is passed by value to allow global and local point to
298  * be the same variable
299  */
300  inline void composePoint(
301  const mrpt::math::TPoint3D& local_point,
302  mrpt::math::TPoint3D& global_point) const
303  {
304  composePoint(
305  local_point.x, local_point.y, local_point.z, global_point.x,
306  global_point.y, global_point.z);
307  }
308  /** This version of the method assumes that the resulting point has no Z
309  * component (use with caution!) */
310  inline void composePoint(
311  const mrpt::math::TPoint3D& local_point,
312  mrpt::math::TPoint2D& global_point) const
313  {
314  double dummy_z;
315  composePoint(
316  local_point.x, local_point.y, local_point.z, global_point.x,
317  global_point.y, dummy_z);
318  }
319 
320  /** An alternative, slightly more efficient way of doing \f$ G = P \oplus L
321  * \f$ with G and L being 3D points and P this 6D pose. */
322  inline void composePoint(
323  double lx, double ly, double lz, float& gx, float& gy, float& gz) const
324  {
325  double ggx, ggy, ggz;
326  composePoint(lx, ly, lz, ggx, ggy, ggz);
327  gx = static_cast<float>(ggx);
328  gy = static_cast<float>(ggy);
329  gz = static_cast<float>(ggz);
330  }
331 
332  /** Computes the 3D point L such as \f$ L = G \ominus this \f$.
333  * If pointers are provided, the corresponding Jacobians are returned.
334  * "out_jacobian_df_dse3" stands for the Jacobian with respect to the 6D
335  * locally Euclidean vector in the tangent space of SE(3).
336  * See [this
337  * report](http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf)
338  * for mathematical details.
339  * \sa composePoint, composeFrom
340  */
341  void inverseComposePoint(
342  const double gx, const double gy, const double gz, double& lx,
343  double& ly, double& lz,
344  mrpt::math::CMatrixFixedNumeric<double, 3, 3>* out_jacobian_df_dpoint =
345  nullptr,
346  mrpt::math::CMatrixFixedNumeric<double, 3, 6>* out_jacobian_df_dpose =
347  nullptr,
348  mrpt::math::CMatrixFixedNumeric<double, 3, 6>* out_jacobian_df_dse3 =
349  nullptr) const;
350 
351  /** \overload */
352  inline void inverseComposePoint(
354  {
355  inverseComposePoint(g.x, g.y, g.z, l.x, l.y, l.z);
356  }
357 
358  /** overload for 2D points \exception If the z component of the result is
359  * greater than some epsilon */
360  inline void inverseComposePoint(
362  const double eps = 1e-6) const
363  {
364  double lz;
365  inverseComposePoint(g.x, g.y, 0, l.x, l.y, lz);
366  ASSERT_BELOW_(std::abs(lz), eps);
367  }
368 
369  /** Makes "this = A (+) B"; this method is slightly more efficient than
370  * "this= A + B;" since it avoids the temporary object.
371  * \note A or B can be "this" without problems.
372  */
373  void composeFrom(const CPose3D& A, const CPose3D& B);
374 
375  /** Make \f$ this = this \oplus b \f$ (\a b can be "this" without problems)
376  */
377  inline CPose3D& operator+=(const CPose3D& b)
378  {
379  composeFrom(*this, b);
380  return *this;
381  }
382 
383  /** Makes \f$ this = A \ominus B \f$ this method is slightly more efficient
384  * than "this= A - B;" since it avoids the temporary object.
385  * \note A or B can be "this" without problems.
386  * \sa composeFrom, composePoint
387  */
388  void inverseComposeFrom(const CPose3D& A, const CPose3D& B);
389 
390  /** Compute \f$ RET = this \oplus b \f$ */
391  inline CPose3D operator-(const CPose3D& b) const
392  {
394  ret.inverseComposeFrom(*this, b);
395  return ret;
396  }
397 
398  /** Convert this pose into its inverse, saving the result in itself. \sa
399  * operator- */
400  void inverse();
401 
402  /** makes: this = p (+) this */
404  {
405  composeFrom(p, CPose3D(*this));
406  }
407 
408  /** @} */ // compositions
409 
410  /** Return the opposite of the current pose instance by taking the negative
411  * of all its components \a individually
412  */
413  CPose3D getOppositeScalar() const;
414 
415  /** @name Access and modify contents
416  @{ */
417 
418  /** Scalar sum of all 6 components: This is diferent from poses composition,
419  * which is implemented as "+" operators.
420  * \sa normalizeAngles
421  */
422  void addComponents(const CPose3D& p);
423 
424  /** Rebuild the internal matrix & update the yaw/pitch/roll angles within
425  * the ]-PI,PI] range (Must be called after using addComponents)
426  * \sa addComponents
427  */
428  void normalizeAngles();
429 
430  /** Scalar multiplication of x,y,z,yaw,pitch & roll (angles will be wrapped
431  * to the ]-pi,pi] interval). */
432  void operator*=(const double s);
433 
434  /** Set the pose from a 3D position (meters) and yaw/pitch/roll angles
435  * (radians) - This method recomputes the internal rotation matrix.
436  * \sa getYawPitchRoll, setYawPitchRoll
437  */
438  void setFromValues(
439  const double x0, const double y0, const double z0, const double yaw = 0,
440  const double pitch = 0, const double roll = 0);
441 
442  /** Set the pose from a 3D position (meters) and a quaternion, stored as [x
443  * y z qr qx qy qz] in a 7-element vector.
444  * \sa setFromValues, getYawPitchRoll, setYawPitchRoll, CQuaternion,
445  * getAsQuaternion
446  */
447  template <typename VECTORLIKE>
448  inline void setFromXYZQ(const VECTORLIKE& v, const size_t index_offset = 0)
449  {
450  ASSERT_ABOVEEQ_(v.size(), 7 + index_offset);
451  // The 3x3 rotation part:
453  v[index_offset + 3], v[index_offset + 4], v[index_offset + 5],
454  v[index_offset + 6]);
455  q.rotationMatrixNoResize(m_ROT);
456  m_ypr_uptodate = false;
457  m_coords[0] = v[index_offset + 0];
458  m_coords[1] = v[index_offset + 1];
459  m_coords[2] = v[index_offset + 2];
460  }
461 
462  /** Set the 3 angles of the 3D pose (in radians) - This method recomputes
463  * the internal rotation coordinates matrix.
464  * \sa getYawPitchRoll, setFromValues
465  */
466  inline void setYawPitchRoll(
467  const double yaw_, const double pitch_, const double roll_)
468  {
469  setFromValues(x(), y(), z(), yaw_, pitch_, roll_);
470  }
471 
472  /** Set pose from an array with these 12 elements: [r11 r21 r31 r12 r22 r32
473  * r13 r23 r33 tx ty tz]
474  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are
475  * the 3D translation of the pose
476  * \sa getAs12Vector
477  */
478  template <class ARRAYORVECTOR>
479  inline void setFrom12Vector(const ARRAYORVECTOR& vec12)
480  {
481  m_ROT.set_unsafe(0, 0, vec12[0]);
482  m_ROT.set_unsafe(0, 1, vec12[3]);
483  m_ROT.set_unsafe(0, 2, vec12[6]);
484  m_ROT.set_unsafe(1, 0, vec12[1]);
485  m_ROT.set_unsafe(1, 1, vec12[4]);
486  m_ROT.set_unsafe(1, 2, vec12[7]);
487  m_ROT.set_unsafe(2, 0, vec12[2]);
488  m_ROT.set_unsafe(2, 1, vec12[5]);
489  m_ROT.set_unsafe(2, 2, vec12[8]);
490  m_ypr_uptodate = false;
491  m_coords[0] = vec12[9];
492  m_coords[1] = vec12[10];
493  m_coords[2] = vec12[11];
494  }
495 
496  /** Get the pose representation as an array with these 12 elements: [r11 r21
497  * r31 r12 r22 r32 r13 r23 r33 tx ty tz]
498  * where r{ij} are the entries of the 3x3 rotation matrix and t{x,y,z} are
499  * the 3D translation of the pose
500  * \sa setFrom12Vector
501  */
502  template <class ARRAYORVECTOR>
503  inline void getAs12Vector(ARRAYORVECTOR& vec12) const
504  {
505  vec12[0] = m_ROT.get_unsafe(0, 0);
506  vec12[3] = m_ROT.get_unsafe(0, 1);
507  vec12[6] = m_ROT.get_unsafe(0, 2);
508  vec12[1] = m_ROT.get_unsafe(1, 0);
509  vec12[4] = m_ROT.get_unsafe(1, 1);
510  vec12[7] = m_ROT.get_unsafe(1, 2);
511  vec12[2] = m_ROT.get_unsafe(2, 0);
512  vec12[5] = m_ROT.get_unsafe(2, 1);
513  vec12[8] = m_ROT.get_unsafe(2, 2);
514  vec12[9] = m_coords[0];
515  vec12[10] = m_coords[1];
516  vec12[11] = m_coords[2];
517  }
518 
519  /** Returns the three angles (yaw, pitch, roll), in radians, from the
520  * rotation matrix.
521  * \sa setFromValues, yaw, pitch, roll
522  */
523  void getYawPitchRoll(double& yaw, double& pitch, double& roll) const;
524 
525  /** Get the YAW angle (in radians) \sa setFromValues */
526  inline double yaw() const
527  {
529  return m_yaw;
530  }
531  /** Get the PITCH angle (in radians) \sa setFromValues */
532  inline double pitch() const
533  {
535  return m_pitch;
536  }
537  /** Get the ROLL angle (in radians) \sa setFromValues */
538  inline double roll() const
539  {
541  return m_roll;
542  }
543 
544  /** Returns a 1x6 vector with [x y z yaw pitch roll] */
546  /// \overload
548 
549  /** Returns the quaternion associated to the rotation of this object (NOTE:
550  * XYZ translation is ignored)
551  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2)
552  * \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin
553  * (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta
554  * /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) +
555  * \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos
556  * (\theta /2) \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi
557  * /2) \\ \end{array}\right) \f]
558  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw
559  * \f$.
560  * \param out_dq_dr If provided, the 4x3 Jacobian of the transformation
561  * will be computed and stored here. It's the Jacobian of the transformation
562  * from (yaw pitch roll) to (qr qx qy qz).
563  */
564  void getAsQuaternion(
567  nullptr) const;
568 
569  inline const double& operator[](unsigned int i) const
570  {
572  switch (i)
573  {
574  case 0:
575  return m_coords[0];
576  case 1:
577  return m_coords[1];
578  case 2:
579  return m_coords[2];
580  case 3:
581  return m_yaw;
582  case 4:
583  return m_pitch;
584  case 5:
585  return m_roll;
586  default:
587  throw std::runtime_error(
588  "CPose3D::operator[]: Index of bounds.");
589  }
590  }
591  // CPose3D CANNOT have a write [] operator, since it'd leave the object in
592  // an inconsistent state (outdated rotation matrix).
593  // Use setFromValues() instead.
594  // inline double &operator[](unsigned int i)
595 
596  /** Returns a human-readable textual representation of the object (eg: "[x y
597  * z yaw pitch roll]", angles in degrees.)
598  * \sa fromString
599  */
600  void asString(std::string& s) const
601  {
602  using mrpt::RAD2DEG;
604  s = mrpt::format(
605  "[%f %f %f %f %f %f]", m_coords[0], m_coords[1], m_coords[2],
607  }
608  inline std::string asString() const
609  {
610  std::string s;
611  asString(s);
612  return s;
613  }
614 
615  /** Set the current object value from a string generated by 'asString' (eg:
616  * "[x y z yaw pitch roll]", angles in deg. )
617  * \sa asString
618  * \exception std::exception On invalid format
619  */
620  void fromString(const std::string& s)
621  {
622  using mrpt::DEG2RAD;
624  if (!m.fromMatlabStringFormat(s))
625  THROW_EXCEPTION("Malformed expression in ::fromString");
626  ASSERTMSG_(m.rows() == 1 && m.cols() == 6, "Expected vector length=6");
627  this->setFromValues(
628  m.get_unsafe(0, 0), m.get_unsafe(0, 1), m.get_unsafe(0, 2),
629  DEG2RAD(m.get_unsafe(0, 3)), DEG2RAD(m.get_unsafe(0, 4)),
630  DEG2RAD(m.get_unsafe(0, 5)));
631  }
632  /** Same as fromString, but without requiring the square brackets in the
633  * string */
635  {
636  this->fromString("[" + s + "]");
637  }
638 
639  /** Return true if the 6D pose represents a Z axis almost exactly vertical
640  * (upwards or downwards), with a given tolerance (if set to 0 exact
641  * horizontality is tested). */
642  bool isHorizontal(const double tolerance = 0) const;
643 
644  /** The euclidean distance between two poses taken as two 6-length vectors
645  * (angles in radians). */
646  double distanceEuclidean6D(const CPose3D& o) const;
647 
648  /** @} */ // modif. components
649 
650  /** @name Lie Algebra methods
651  @{ */
652 
653  /** Exponentiate a Vector in the SE(3) Lie Algebra to generate a new CPose3D
654  * (static method).
655  * \param pseudo_exponential If set to true, XYZ are copied from the first
656  * three elements in the vector instead of using the proper Lie Algebra
657  * formulas (this is actually the common practice in robotics literature).
658  */
659  static CPose3D exp(
661  bool pseudo_exponential = false);
662 
663  /** \overload */
664  static void exp(
665  const mrpt::math::CArrayNumeric<double, 6>& vect, CPose3D& out_pose,
666  bool pseudo_exponential = false);
667 
668  /** Exponentiate a vector in the Lie algebra to generate a new SO(3) (a 3x3
669  * rotation matrix). */
672 
673  /** Take the logarithm of the 3x4 matrix defined by this pose, generating
674  * the corresponding vector in the SE(3) Lie Algebra.
675  * \sa ln_jacob
676  */
677  void ln(mrpt::math::CArrayDouble<6>& out_ln) const;
678 
679  /// \overload
681  {
683  ln(ret);
684  return ret;
685  }
686 
687  /** Jacobian of the logarithm of the 3x4 matrix defined by this pose.
688  * \sa ln
689  */
691 
692  /** Static function to compute the Jacobian of the SO(3) Logarithm function,
693  * evaluated at a given 3x3 rotation matrix R.
694  * \sa ln, ln_jacob
695  */
696  static void ln_rot_jacob(
699 
700  /** Take the logarithm of the 3x3 rotation matrix, generating the
701  * corresponding vector in the Lie Algebra */
703 
704  /** The Jacobian d (e^eps * D) / d eps , with eps=increment in Lie Algebra.
705  * \note Eq. 10.3.5 in tech report
706  * http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf
707  */
708  static void jacob_dexpeD_de(
709  const CPose3D& D, Eigen::Matrix<double, 12, 6>& jacob);
710 
711  /** The Jacobian d (A * e^eps * D) / d eps , with eps=increment in Lie
712  * Algebra.
713  * \note Eq. 10.3.7 in tech report
714  * http://ingmec.ual.es/~jlblanco/papers/jlblanco2010geometry3D_techrep.pdf
715  */
716  static void jacob_dAexpeD_de(
717  const CPose3D& A, const CPose3D& D,
718  Eigen::Matrix<double, 12, 6>& jacob);
719 
720  /** @} */
721 
722  void setToNaN() override;
723 
724  /** Used to emulate CPosePDF types, for example, in
725  * mrpt::graphs::CNetworkOfPoses */
727  enum
728  {
729  is_3D_val = 1
730  };
731  static constexpr bool is_3D() { return is_3D_val != 0; }
732  enum
733  {
735  };
736  enum
737  {
738  is_PDF_val = 0
739  };
740  static constexpr bool is_PDF() { return is_PDF_val != 0; }
741  inline const type_value& getPoseMean() const { return *this; }
742  inline type_value& getPoseMean() { return *this; }
743  /** @name STL-like methods and typedefs
744  @{ */
745  /** The type of the elements */
746  using value_type = double;
747  using reference = double&;
748  using const_reference = const double&;
749  using size_type = std::size_t;
751 
752  // size is constant
753  enum
754  {
755  static_size = 6
756  };
757  static constexpr size_type size() { return static_size; }
758  static constexpr bool empty() { return false; }
759  static constexpr size_type max_size() { return static_size; }
760  static inline void resize(const size_t n)
761  {
762  if (n != static_size)
763  throw std::logic_error(format(
764  "Try to change the size of CPose3D to %u.",
765  static_cast<unsigned>(n)));
766  }
767  /** @} */
768 
769 }; // End of class def.
770 
771 std::ostream& operator<<(std::ostream& o, const CPose3D& p);
772 
773 /** Unary - operator: return the inverse pose "-p" (Note that is NOT the same
774  * than a pose with negative x y z yaw pitch roll) */
775 CPose3D operator-(const CPose3D& p);
776 
777 bool operator==(const CPose3D& p1, const CPose3D& p2);
778 bool operator!=(const CPose3D& p1, const CPose3D& p2);
779 
780 } // namespace mrpt::poses
781 #endif
const float R
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DECLARE_MEXPLUS_FROM(complete_type)
This must be inserted if a custom conversion method for MEX API is implemented in the class.
#define DECLARE_MEX_CONVERSION
This must be inserted if a custom conversion method for MEX API is implemented in the class.
CArrayNumeric is an array for numeric types supporting several mathematical operations (actually,...
Definition: CArrayNumeric.h:26
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ,...
Definition: CQuaternion.h:45
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: types_math.h:68
A class used to store a 2D point.
Definition: CPoint2D.h:35
A class used to store a 3D point.
Definition: CPoint3D.h:33
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:87
CPose3D & operator+=(const CPose3D &b)
Make (b can be "this" without problems)
Definition: CPose3D.h:377
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...
Definition: CPose3D.cpp:621
static constexpr bool empty()
Definition: CPose3D.h:758
std::size_t size_type
Definition: CPose3D.h:749
type_value & getPoseMean()
Definition: CPose3D.h:742
static void jacob_dexpeD_de(const CPose3D &D, Eigen::Matrix< double, 12, 6 > &jacob)
The Jacobian d (e^eps * D) / d eps , with eps=increment in Lie Algebra.
Definition: CPose3D.cpp:997
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:322
const double & operator[](unsigned int i) const
Definition: CPose3D.h:569
void operator*=(const double s)
Scalar multiplication of x,y,z,yaw,pitch & roll (angles will be wrapped to the ]-pi,...
Definition: CPose3D.cpp:291
bool isHorizontal(const double tolerance=0) const
Return true if the 6D pose represents a Z axis almost exactly vertical (upwards or downwards),...
Definition: CPose3D.cpp:608
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:230
CPose3D operator-(const CPose3D &b) const
Compute
Definition: CPose3D.h:391
void sphericalCoordinates(const mrpt::math::TPoint3D &point, double &out_range, double &out_yaw, double &out_pitch) const
Computes the spherical coordinates of a 3D point as seen from the 6D pose specified by this object.
Definition: CPose3D.cpp:314
double m_yaw
These variables are updated every time that the object rotation matrix is modified (construction,...
Definition: CPose3D.h:109
static constexpr bool is_PDF()
Definition: CPose3D.h:740
void getAsVector(mrpt::math::CVectorDouble &v) const
Returns a 1x6 vector with [x y z yaw pitch roll].
Definition: CPose3D.cpp:477
std::string asString() const
Definition: CPose3D.h:608
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:448
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods.
Definition: CPose3D.h:96
void inverseComposePoint(const mrpt::math::TPoint3D &g, mrpt::math::TPoint3D &l) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CPose3D.h:352
double pitch() const
Get the PITCH angle (in radians)
Definition: CPose3D.h:532
void inverseComposePoint(const mrpt::math::TPoint2D &g, mrpt::math::TPoint2D &l, const double eps=1e-6) const
overload for 2D points
Definition: CPose3D.h:360
void addComponents(const CPose3D &p)
Scalar sum of all 6 components: This is diferent from poses composition, which is implemented as "+" ...
Definition: CPose3D.cpp:348
double roll() const
Get the ROLL angle (in radians)
Definition: CPose3D.h:538
static CPose3D exp(const mrpt::math::CArrayNumeric< double, 6 > &vect, bool pseudo_exponential=false)
Exponentiate a Vector in the SE(3) Lie Algebra to generate a new CPose3D (static method).
Definition: CPose3D.cpp:758
void ln_jacob(mrpt::math::CMatrixFixedNumeric< double, 6, 12 > &J) const
Jacobian of the logarithm of the 3x4 matrix defined by this pose.
Definition: CPose3D.cpp:905
double & reference
Definition: CPose3D.h:747
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
Definition: CPose3D.cpp:239
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:206
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
Definition: CPose3D.cpp:379
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:149
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:310
void rebuildRotationMatrix()
Rebuild the homog matrix from the angles.
Definition: CPose3D.cpp:258
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .
Definition: CPose3D.cpp:649
static void ln_rot_jacob(const mrpt::math::CMatrixDouble33 &R, mrpt::math::CMatrixFixedNumeric< double, 3, 9 > &M)
Static function to compute the Jacobian of the SO(3) Logarithm function, evaluated at a given 3x3 rot...
Definition: CPose3D.cpp:972
CPose3D operator+(const CPose3D &b) const
The operator is the pose compounding operator.
Definition: CPose3D.h:254
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:600
void inverse()
Convert this pose into its inverse, saving the result in itself.
Definition: CPose3D.cpp:593
CPose3D(TConstructorFlags_Poses)
Fast constructor that leaves all the data uninitialized - call with UNINITIALIZED_POSE as argument.
Definition: CPose3D.h:195
double distanceEuclidean6D(const CPose3D &o) const
The euclidean distance between two poses taken as two 6-length vectors (angles in radians).
Definition: CPose3D.cpp:363
static void resize(const size_t n)
Definition: CPose3D.h:760
const double & const_reference
Definition: CPose3D.h:748
static constexpr bool is_3D()
Definition: CPose3D.h:731
std::ptrdiff_t difference_type
Definition: CPose3D.h:750
void changeCoordinatesReference(const CPose3D &p)
makes: this = p (+) this
Definition: CPose3D.h:403
double value_type
The type of the elements.
Definition: CPose3D.h:746
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:479
bool m_ypr_uptodate
Whether yaw/pitch/roll members are up-to-date since the last rotation matrix update.
Definition: CPose3D.h:105
mrpt::math::CArrayDouble< 3 > ln_rotation() const
Take the logarithm of the 3x3 rotation matrix, generating the corresponding vector in the Lie Algebra...
Definition: CPose3D.cpp:785
CPose3D()
Default constructor, with all the coordinates set to zero.
Definition: CPose3D.cpp:54
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:300
CPose3D(const mrpt::math::CMatrixDouble33 &rot, const mrpt::math::CArrayDouble< 3 > &xyz)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CPose3D.h:160
const type_value & getPoseMean() const
Definition: CPose3D.h:741
void fromStringRaw(const std::string &s)
Same as fromString, but without requiring the square brackets in the string.
Definition: CPose3D.h:634
mrpt::math::TPose3D asTPose() const
Definition: CPose3D.cpp:1043
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:620
double yaw() const
Get the YAW angle (in radians)
Definition: CPose3D.h:526
void setRotationMatrix(const mrpt::math::CMatrixDouble33 &ROT)
Sets the 3x3 rotation matrix.
Definition: CPose3D.h:242
static mrpt::math::CMatrixDouble33 exp_rotation(const mrpt::math::CArrayNumeric< double, 3 > &vect)
Exponentiate a vector in the Lie algebra to generate a new SO(3) (a 3x3 rotation matrix).
Definition: CPose3D.cpp:794
mrpt::math::CArrayDouble< 6 > ln() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CPose3D.h:680
void getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixedNumeric< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored)
Definition: CPose3D.cpp:510
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPose3D.cpp:1033
void updateYawPitchRoll() const
Updates Yaw/pitch/roll members from the m_ROT
Definition: CPose3D.h:115
const mrpt::math::CMatrixDouble33 & getRotationMatrix() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CPose3D.h:235
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:466
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:503
CPose3D getOppositeScalar() const
Return the opposite of the current pose instance by taking the negative of all its components individ...
Definition: CPose3D.cpp:339
static void jacob_dAexpeD_de(const CPose3D &A, const CPose3D &D, Eigen::Matrix< double, 12, 6 > &jacob)
The Jacobian d (A * e^eps * D) / d eps , with eps=increment in Lie Algebra.
Definition: CPose3D.cpp:1017
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...
Definition: CPose3D.cpp:565
void getYawPitchRoll(double &yaw, double &pitch, double &roll) const
Returns the three angles (yaw, pitch, roll), in radians, from the rotation matrix.
Definition: CPose3D.cpp:306
void normalizeAngles()
Rebuild the internal matrix & update the yaw/pitch/roll angles within the ]-PI,PI] range (Must be cal...
Definition: CPose3D.cpp:235
mrpt::math::CMatrixDouble33 m_ROT
The 3x3 rotation matrix, access with getRotationMatrix(), setRotationMatrix() (It's not safe to set t...
Definition: CPose3D.h:101
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:221
static constexpr size_type max_size()
Definition: CPose3D.h:759
static constexpr size_type size()
Definition: CPose3D.h:757
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
Definition: CPose3DQuat.h:48
A 3D pose, with a 3D translation and a rotation in 3D parameterized in rotation-vector form (equivale...
Definition: CPose3DRotVec.h:44
A base class for representing a pose in 2D or 3D.
Definition: CPose.h:26
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:140
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:31
const double eps
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:153
#define ASSERT_BELOW_(__A, __B)
Definition: exceptions.h:165
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
#define ASSERT_ABOVEEQ_(__A, __B)
Definition: exceptions.h:183
_W64 int ptrdiff_t
Definition: glew.h:137
GLenum GLsizei n
Definition: glext.h:5074
const GLdouble * v
Definition: glext.h:3678
const GLubyte * c
Definition: glext.h:6313
GLenum GLint GLint y
Definition: glext.h:3538
GLubyte GLubyte b
Definition: glext.h:6279
GLenum GLint x
Definition: glext.h:3538
GLubyte g
Definition: glext.h:6279
GLfloat GLfloat p
Definition: glext.h:6305
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
GLdouble GLdouble z
Definition: glext.h:3872
GLdouble s
Definition: glext.h:3676
GLsizei const GLchar ** string
Definition: glext.h:4101
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3721
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
@ UNINITIALIZED_MATRIX
Definition: math_frwds.h:75
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool operator!=(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:172
CPose2D operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
Definition: CPose2D.cpp:315
std::ostream & operator<<(std::ostream &o, const CPoint< DERIVEDCLASS > &p)
Dumps a point as a string [x,y] or [x,y,z]
Definition: CPoint.h:138
@ UNINITIALIZED_POSE
Definition: CPoseOrPoint.h:36
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:164
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double RAD2DEG(const double x)
Radians to degrees.
double DEG2RAD(const double x)
Degrees to radians.
Lightweight 2D point.
double x
X,Y coordinates.
Lightweight 3D point.
double x
X,Y,Z coordinates.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 814d80880 Fri Aug 24 01:51:28 2018 +0200 at mar 26 may 2026 12:30:59 CEST