Main MRPT website > C++ reference for MRPT 1.9.9
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-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 CPOINT2D_H
10 #define CPOINT2D_H
11 
13 #include <mrpt/poses/CPoint.h>
15 
16 namespace mrpt
17 {
18 namespace poses
19 {
20 class CPose2D;
21 
22 /** A class used to store a 2D point.
23  *
24  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint,
25  * or refer
26  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry
27  * 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 CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
37 {
39 
40  public:
41  /** [x,y] */
43 
44  public:
45  /** Constructor for initializing point coordinates. */
46  inline CPoint2D(double x = 0, double y = 0)
47  {
48  m_coords[0] = x;
49  m_coords[1] = y;
50  }
51 
52  /** Constructor from x/y coordinates given from other pose. */
53  template <class OTHERCLASS>
54  inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS>& b)
55  {
56  m_coords[0] = b.x();
57  m_coords[1] = b.y();
58  }
59 
60  /** Implicit constructor from lightweight type. */
61  inline explicit CPoint2D(const mrpt::math::TPoint2D& o)
62  {
63  m_coords[0] = o.x;
64  m_coords[1] = o.y;
65  }
66 
67  /** Explicit constructor from lightweight type (loses the z coord). */
68  inline explicit CPoint2D(const mrpt::math::TPoint3D& o)
69  {
70  m_coords[0] = o.x;
71  m_coords[1] = o.y;
72  m_coords[2] = 0;
73  }
74 
75  /** The operator D="this"-b is the pose inverse compounding operator,
76  * the resulting points "D" fulfils: "this" = b + D, so that: b == a +
77  * (b-a)
78  */
79  CPoint2D operator-(const CPose2D& b) const;
80 
81  enum
82  {
84  };
85  static inline bool is_3D() { return is_3D_val != 0; }
86  enum
87  {
89  };
90  static inline bool is_PDF() { return is_PDF_val != 0; }
91  /** @name STL-like methods and typedefs
92  @{ */
93  /** The type of the elements */
94  typedef double value_type;
95  typedef double& reference;
96  typedef const double& const_reference;
97  typedef std::size_t size_type;
99 
100  // size is constant
101  enum
102  {
104  };
105  static inline size_type size() { return static_size; }
106  static inline bool empty() { return false; }
107  static inline size_type max_size() { return static_size; }
108  static inline void resize(const size_t n)
109  {
110  if (n != static_size)
111  throw std::logic_error(
112  format(
113  "Try to change the size of CPoint2D to %u.",
114  static_cast<unsigned>(n)));
115  }
116  /** @} */
117 
118  void setToNaN() override;
119 
120 }; // End of class def.
121 
122 } // End of namespace
123 } // End of namespace
124 
125 #endif
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
double x
X,Y coordinates.
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
static void resize(const size_t n)
Definition: CPoint2D.h:108
CPoint2D(const CPoseOrPoint< OTHERCLASS > &b)
Constructor from x/y coordinates given from other pose.
Definition: CPoint2D.h:54
mrpt::math::CArrayDouble< 2 > m_coords
[x,y]
Definition: CPoint2D.h:42
GLenum GLsizei n
Definition: glext.h:5074
static bool empty()
Definition: CPoint2D.h:106
CPoint2D(const mrpt::math::TPoint2D &o)
Implicit constructor from lightweight type.
Definition: CPoint2D.h:61
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:27
static size_type max_size()
Definition: CPoint2D.h:107
static size_type size()
Definition: CPoint2D.h:105
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
double x
X,Y,Z coordinates.
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:46
The base template class for 2D & 3D points and poses.
Definition: CPoseOrPoint.h:125
A class used to store a 2D point.
Definition: CPoint2D.h:36
_W64 int ptrdiff_t
Definition: glew.h:137
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:81
double & reference
Definition: CPoint2D.h:95
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
std::ptrdiff_t difference_type
Definition: CPoint2D.h:98
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
double value_type
The type of the elements.
Definition: CPoint2D.h:94
CPoint2D operator-(const CPose2D &b) const
The operator D="this"-b is the pose inverse compounding operator, the resulting points "D" fulfils: "...
Definition: CPoint2D.cpp:71
GLenum GLint GLint y
Definition: glext.h:3538
CPoint2D(const mrpt::math::TPoint3D &o)
Explicit constructor from lightweight type (loses the z coord).
Definition: CPoint2D.h:68
static bool is_PDF()
Definition: CPoint2D.h:90
GLenum GLint x
Definition: glext.h:3538
Lightweight 3D point.
Lightweight 2D point.
std::size_t size_type
Definition: CPoint2D.h:97
const double & const_reference
Definition: CPoint2D.h:96
static bool is_3D()
Definition: CPoint2D.h:85



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