Main MRPT website > C++ reference for MRPT 1.4.0
CPoint2D.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-2016, 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 CPOINT2D_H
10#define CPOINT2D_H
11
13#include <mrpt/poses/CPoint.h>
14#include <mrpt/math/CArray.h>
15
16namespace mrpt
17{
18namespace poses
19{
20 class CPose2D;
21
23
24 /** A class used to store a 2D point.
25 *
26 * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
27 * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry tutorial</a> in the wiki.
28 *
29 * <div align=center>
30 * <img src="CPoint2D.gif">
31 * </div>
32 *
33 * \sa CPoseOrPoint,CPose, CPoint
34 * \ingroup poses_grp
35 */
36 class BASE_IMPEXP CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
37 {
38 // This must be added to any CSerializable derived class:
40
41 public:
43
44 public:
45 /** Constructor for initializing point coordinates. */
46 inline CPoint2D(double x=0,double y=0) { m_coords[0]=x; m_coords[1]=y; }
47
48 /** Constructor from x/y coordinates given from other pose. */
49 template <class OTHERCLASS>
50 inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS> &b)
51 {
52 m_coords[0]=b.x();
53 m_coords[1]=b.y();
54 }
55
56 /** Implicit constructor from lightweight type. */
57 inline CPoint2D(const mrpt::math::TPoint2D &o) { m_coords[0]=o.x; m_coords[1]=o.y; }
58
59 /** Explicit constructor from lightweight type (loses the z coord). */
60 inline explicit CPoint2D(const mrpt::math::TPoint3D &o) { m_coords[0]=o.x; m_coords[1]=o.y; m_coords[2]=0; }
61
62 /** The operator D="this"-b is the pose inverse compounding operator,
63 * the resulting points "D" fulfils: "this" = b + D, so that: b == a + (b-a)
64 */
65 CPoint2D operator - (const CPose2D& b) const;
66
67 enum { is_3D_val = 0 };
68 static inline bool is_3D() { return is_3D_val!=0; }
69 enum { is_PDF_val = 0 };
70 static inline bool is_PDF() { return is_PDF_val!=0; }
71
72 /** @name STL-like methods and typedefs
73 @{ */
74 typedef double value_type; //!< The type of the elements
75 typedef double& reference;
76 typedef const double& const_reference;
77 typedef std::size_t size_type;
78 typedef std::ptrdiff_t difference_type;
79
80 // size is constant
81 enum { static_size = 2 };
82 static inline size_type size() { return static_size; }
83 static inline bool empty() { return false; }
84 static inline size_type max_size() { return static_size; }
85 static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPoint2D to %u.",static_cast<unsigned>(n))); }
86 /** @} */
87
89
90 }; // End of class def.
92
93
94 } // End of namespace
95} // End of namespace
96
97#endif
#define DEFINE_SERIALIZABLE_PRE(class_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST(class_name)
A partial specialization of CArrayNumeric for double numbers.
A class used to store a 2D point.
Definition CPoint2D.h:37
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition CPoint2D.h:46
static size_type size()
Definition CPoint2D.h:82
std::ptrdiff_t difference_type
Definition CPoint2D.h:78
static size_type max_size()
Definition CPoint2D.h:84
static void resize(const size_t n)
Definition CPoint2D.h:85
const double & const_reference
Definition CPoint2D.h:76
CPoint2D(const mrpt::math::TPoint2D &o)
Implicit constructor from lightweight type.
Definition CPoint2D.h:57
mrpt::math::CArrayDouble< 2 > m_coords
[x,y]
Definition CPoint2D.h:42
CPoint2D(const mrpt::math::TPoint3D &o)
Explicit constructor from lightweight type (loses the z coord).
Definition CPoint2D.h:60
std::size_t size_type
Definition CPoint2D.h:77
double value_type
The type of the elements.
Definition CPoint2D.h:74
void setToNaN() MRPT_OVERRIDE
Set all data fields to quiet NaN.
static bool empty()
Definition CPoint2D.h:83
static bool is_3D()
Definition CPoint2D.h:68
CPoint2D(const CPoseOrPoint< OTHERCLASS > &b)
Constructor from x/y coordinates given from other pose.
Definition CPoint2D.h:50
static bool is_PDF()
Definition CPoint2D.h:70
A base class for representing a point in 2D or 3D.
Definition CPoint.h:27
A class used to store a 2D pose.
Definition CPose2D.h:37
The base template class for 2D & 3D points and poses.
double x() const
Common members of all points & poses classes.
@ static_size
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition mrpt_macros.h:28
CPose2D BASE_IMPEXP operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
class BASE_IMPEXP CPose2D
Definition CPose2D.h:19
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Lightweight 2D point.
double y
X,Y coordinates.
Lightweight 3D point.



Page generated by Doxygen 1.9.8 for MRPT 1.4.0 SVN: at Thu Dec 14 16:54:58 UTC 2023