Main MRPT website > C++ reference for MRPT 1.9.9
CPoseOrPoint.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 CPOSEORPOINT_H
10 #define CPOSEORPOINT_H
11 
16 
18 
19 namespace mrpt
20 {
21 /** \defgroup poses_grp 2D/3D points and poses
22  * \ingroup mrpt_base_grp */
23 
24 /** \defgroup poses_pdf_grp 2D/3D point and pose PDFs
25  * \ingroup mrpt_base_grp */
26 
27 /** Classes for 2D/3D geometry representation, both of single values and
28  * probability density distributions (PDFs) in many forms.
29  * \ingroup poses_grp poses_pdf_grp
30  */
31 namespace poses
32 {
33 // For use in some constructors (eg. CPose3D)
35 {
37 };
38 
39 /** The base template class for 2D & 3D points and poses.
40  * This class use the Curiously Recurring Template Pattern (CRTP) to define
41  * a set of common methods to all the children classes without the cost
42  * of virtual methods. Since most important methods are inline, they will be
43  * expanded
44  * at compile time and optimized for every specific derived case.
45  *
46  * For more information and examples, refer
47  * to the <a href="http://www.mrpt.org/2D_3D_Geometry">2D/3D Geometry
48  * tutorial</a> online.
49  *
50  *
51  * <center><h2>Introduction to 2D and 3D representation classes</h2></center>
52  * <hr>
53  * <p>
54  * There are two class of spatial representation classes:
55  * - Point: A point in the common mathematical sense, with no directional
56  * information.
57  * - 2D: A 2D point is represented just by its coordinates (x,y).
58  * - 3D: A 3D point is represented by its coordinates (x,y,z).
59  * - Pose: It is a point, plus a direction.
60  * - 2D: A 2D pose is a 2D point plus a single angle, the yaw or &#966;
61  * angle:
62  * the angle from the positive X angle.
63  * - 3D: A 3D point is a 3D point plus three orientation angles (More
64  * details
65  * above).
66  * </p>
67  * In the case for a 3D orientation many representation angles can be used
68  * (Euler angles,yaw/pitch/roll,...)
69  * but all of them can be handled by a 4x4 matrix called "Homogeneous Matrix".
70  * This matrix includes both, the
71  * translation and the orientation for a point or a pose, and it can be
72  * obtained using
73  * the method getHomogeneousMatrix() which is defined for any pose or point.
74  * Note that when the YPR angles are
75  * used to define a 3D orientation, these three values can not be extracted
76  * from the matrix again.<br><br>
77  *
78  * <b>Homogeneous matrices:</b> These are 4x4 matrices which can represent any
79  * translation or rotation in 2D & 3D.
80  * See the tutorial online for more details. *
81  *
82  * <b>Operators:</b> There are operators defined for the pose compounding \f$
83  * \oplus \f$ and inverse pose
84  * compounding \f$ \ominus \f$ of poses and points. For example, let "a" and
85  * "b" be 2D or 3D poses. Then "a+b"
86  * returns the resulting pose of "moving b" from "a"; and "b-a" returns the
87  * pose of "b" as it is seen
88  * "from a". They can be mixed points and poses, being 2D or 3D, in these
89  * operators, with the following
90  * results: <br>
91  *
92  * <div align="center" >
93  * <pre>
94  * Does "a+b" return a Pose or a Point?
95  * +---------------------------------+
96  * | a \ b | Pose | Point |
97  * +----------+-----------+----------+
98  * | Pose | Pose | Point |
99  * | Point | Pose | Point |
100  * +---------------------------------+
101  *
102  * Does "a-b" return a Pose or a Point?
103  * +---------------------------------+
104  * | a \ b | Pose | Point |
105  * +----------+-----------+----------+
106  * | Pose | Pose | Pose |
107  * | Point | Point | Point |
108  * +---------------------------------+
109  *
110  * Does "a+b" and "a-b" return a 2D or 3D object?
111  * +-------------------------+
112  * | a \ b | 2D | 3D |
113  * +----------+--------------+
114  * | 2D | 2D | 3D |
115  * | 3D | 3D | 3D |
116  * +-------------------------+
117  *
118  * </pre>
119  * </div>
120  *
121  * \sa CPose,CPoint
122  * \ingroup poses_grp
123  */
124 template <class DERIVEDCLASS>
127  DERIVEDCLASS,
128  mrpt::poses::detail::T3DTypeHelper<DERIVEDCLASS>::is_3D_val>
129 {
130  public:
131  /** Common members of all points & poses classes.
132  @{ */
133  // Note: the access to "z" is implemented (only for 3D data types), in
134  // detail::pose_point_impl<>
135  inline double x() const /*!< Get X coord. */
136  {
137  return static_cast<const DERIVEDCLASS*>(this)->m_coords[0];
138  }
139  inline double y() const /*!< Get Y coord. */
140  {
141  return static_cast<const DERIVEDCLASS*>(this)->m_coords[1];
142  }
143 
144  inline double& x() /*!< Get ref to X coord. */
145  {
146  return static_cast<DERIVEDCLASS*>(this)->m_coords[0];
147  }
148  inline double& y() /*!< Get ref to Y coord. */
149  {
150  return static_cast<DERIVEDCLASS*>(this)->m_coords[1];
151  }
152 
153  inline void x(const double v) /*!< Set X coord. */
154  {
155  static_cast<DERIVEDCLASS*>(this)->m_coords[0] = v;
156  }
157  inline void y(const double v) /*!< Set Y coord. */
158  {
159  static_cast<DERIVEDCLASS*>(this)->m_coords[1] = v;
160  }
161 
162  inline void x_incr(const double v) /*!< X+=v */
163  {
164  static_cast<DERIVEDCLASS*>(this)->m_coords[0] += v;
165  }
166  inline void y_incr(const double v) /*!< Y+=v */
167  {
168  static_cast<DERIVEDCLASS*>(this)->m_coords[1] += v;
169  }
170 
171  /** Return true for poses or points with a Z component, false otherwise. */
172  static inline bool is3DPoseOrPoint()
173  {
174  return DERIVEDCLASS::is_3D_val != 0;
175  }
176 
177  /** Returns the squared euclidean distance to another pose/point: */
178  template <class OTHERCLASS>
179  inline double sqrDistanceTo(const CPoseOrPoint<OTHERCLASS>& b) const
180  {
181  using mrpt::math::square;
182 
183  if (b.is3DPoseOrPoint())
184  {
185  if (is3DPoseOrPoint())
186  return square(x() - b.x()) + square(y() - b.y()) +
187  square(
188  static_cast<const DERIVEDCLASS*>(this)->m_coords[2] -
189  static_cast<const OTHERCLASS*>(&b)->m_coords[2]);
190  else
191  return square(x() - b.x()) + square(y() - b.y()) +
192  square(static_cast<const OTHERCLASS*>(&b)->m_coords[2]);
193  }
194  else
195  {
196  if (is3DPoseOrPoint())
197  return square(x() - b.x()) + square(y() - b.y()) +
198  square(static_cast<const OTHERCLASS*>(&b)->m_coords[2]);
199  else
200  return square(x() - b.x()) + square(y() - b.y());
201  }
202  }
203 
204  /** Returns the Euclidean distance to another pose/point: */
205  template <class OTHERCLASS>
206  inline double distanceTo(const CPoseOrPoint<OTHERCLASS>& b) const
207  {
208  return std::sqrt(sqrDistanceTo(b));
209  }
210 
211  /** Returns the squared 2D distance from this pose/point to a 2D point
212  * (ignores Z, if it exists). */
213  inline double distance2DToSquare(double ax, double ay) const
214  {
215  using mrpt::math::square;
216  return square(ax - x()) + square(ay - y());
217  }
218 
219  /** Returns the squared 3D distance from this pose/point to a 3D point */
220  inline double distance3DToSquare(double ax, double ay, double az) const
221  {
222  using mrpt::math::square;
223  return square(ax - x()) + square(ay - y()) +
224  square(
225  az -
226  (is3DPoseOrPoint()
227  ? static_cast<const DERIVEDCLASS*>(this)->m_coords[2]
228  : 0));
229  }
230 
231  /** Returns the 2D distance from this pose/point to a 2D point (ignores Z,
232  * if it exists). */
233  inline double distance2DTo(double ax, double ay) const
234  {
235  return std::sqrt(distance2DToSquare(ax, ay));
236  }
237 
238  /** Returns the 3D distance from this pose/point to a 3D point */
239  inline double distance3DTo(double ax, double ay, double az) const
240  {
241  return std::sqrt(distance3DToSquare(ax, ay, az));
242  }
243 
244  /** Returns the euclidean distance to a 3D point: */
245  inline double distanceTo(const mrpt::math::TPoint3D& b) const
246  {
247  return distance3DTo(b.x, b.y, b.z);
248  }
249 
250  /** Returns the euclidean norm of vector: \f$ ||\mathbf{x}|| =
251  * \sqrt{x^2+y^2+z^2} \f$ */
252  inline double norm() const
253  {
254  using mrpt::math::square;
255  return std::sqrt(
256  square(x()) + square(y()) +
257  (!is3DPoseOrPoint()
258  ? 0
259  : square(
260  static_cast<const DERIVEDCLASS*>(this)->m_coords[2])));
261  }
262 
263  /** Return the pose or point as a 1xN vector with all the components (see
264  * derived classes for each implementation) */
266  {
268  static_cast<const DERIVEDCLASS*>(this)->getAsVector(v);
269  return v;
270  }
271 
272  /** Returns the corresponding 4x4 homogeneous transformation matrix for the
273  * point(translation) or pose (translation+orientation).
274  * \sa getInverseHomogeneousMatrix
275  */
277  {
279  static_cast<const DERIVEDCLASS*>(this)->getHomogeneousMatrix(m);
280  return m;
281  }
282 
283  /** Returns the corresponding 4x4 inverse homogeneous transformation matrix
284  * for this point or pose.
285  * \sa getHomogeneousMatrix
286  */
288  mrpt::math::CMatrixDouble44& out_HM) const
289  { // Get current HM & inverse in-place:
290  static_cast<const DERIVEDCLASS*>(this)->getHomogeneousMatrix(out_HM);
292  }
293 
294  //! \overload
296  {
299  return M;
300  }
301 
302  /** Set all data fields to quiet NaN */
303  virtual void setToNaN() = 0;
304 
305  /** @} */
306 }; // End of class def.
307 
308 } // End of namespace
309 } // End of namespace
310 
311 #endif
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
double distanceTo(const CPoseOrPoint< OTHERCLASS > &b) const
Returns the Euclidean distance to another pose/point:
Definition: CPoseOrPoint.h:206
mrpt::math::CVectorDouble getAsVectorVal() const
Return the pose or point as a 1xN vector with all the components (see derived classes for each implem...
Definition: CPoseOrPoint.h:265
void y_incr(const double v)
Definition: CPoseOrPoint.h:166
static bool is3DPoseOrPoint()
Return true for poses or points with a Z component, false otherwise.
Definition: CPoseOrPoint.h:172
double distanceTo(const mrpt::math::TPoint3D &b) const
Returns the euclidean distance to a 3D point:
Definition: CPoseOrPoint.h:245
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
mrpt::math::CMatrixDouble44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
Definition: CPoseOrPoint.h:276
void y(const double v)
Definition: CPoseOrPoint.h:157
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:55
mrpt::math::CMatrixDouble44 getInverseHomogeneousMatrix() const
Definition: CPoseOrPoint.h:295
A numeric matrix of compile-time fixed size.
double norm() const
Returns the euclidean norm of vector: .
Definition: CPoseOrPoint.h:252
double sqrDistanceTo(const CPoseOrPoint< OTHERCLASS > &b) const
Returns the squared euclidean distance to another pose/point:
Definition: CPoseOrPoint.h:179
void getInverseHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 inverse homogeneous transformation matrix for this point or pose...
Definition: CPoseOrPoint.h:287
void x_incr(const double v)
Definition: CPoseOrPoint.h:162
GLubyte GLubyte b
Definition: glext.h:6279
The base template class for 2D & 3D points and poses.
Definition: CPoseOrPoint.h:125
void x(const double v)
Definition: CPoseOrPoint.h:153
double distance2DTo(double ax, double ay) const
Returns the 2D distance from this pose/point to a 2D point (ignores Z, if it exists).
Definition: CPoseOrPoint.h:233
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void homogeneousMatrixInverse(const MATRIXLIKE1 &M, MATRIXLIKE2 &out_inverse_M)
Efficiently compute the inverse of a 4x4 homogeneous matrix by only transposing the rotation 3x3 part...
T square(const T x)
Inline function for the square of a number.
double distance3DToSquare(double ax, double ay, double az) const
Returns the squared 3D distance from this pose/point to a 3D point.
Definition: CPoseOrPoint.h:220
Lightweight 3D point.
virtual void setToNaN()=0
Set all data fields to quiet NaN.
double distance2DToSquare(double ax, double ay) const
Returns the squared 2D distance from this pose/point to a 2D point (ignores Z, if it exists)...
Definition: CPoseOrPoint.h:213
double distance3DTo(double ax, double ay, double az) const
Returns the 3D distance from this pose/point to a 3D point.
Definition: CPoseOrPoint.h:239



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