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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019