Main MRPT website > C++ reference for MRPT 1.5.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  DEFINE_SERIALIZABLE_PRE( CPoint2D )
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 explicit 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;
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 
88  void setToNaN() MRPT_OVERRIDE;
89 
90  }; // End of class def.
92 
93 
94  } // End of namespace
95 } // End of namespace
96 
97 #endif
double y
X,Y coordinates.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
#define DEFINE_SERIALIZABLE_PRE(class_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
static void resize(const size_t n)
Definition: CPoint2D.h:85
CPoint2D(const CPoseOrPoint< OTHERCLASS > &b)
Constructor from x/y coordinates given from other pose.
Definition: CPoint2D.h:50
mrpt::math::CArrayDouble< 2 > m_coords
[x,y]
Definition: CPoint2D.h:42
GLenum GLsizei n
Definition: glext.h:4618
static bool empty()
Definition: CPoint2D.h:83
CPoint2D(const mrpt::math::TPoint2D &o)
Implicit constructor from lightweight type.
Definition: CPoint2D.h:57
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:26
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...
Definition: CPose2D.cpp:307
static size_type max_size()
Definition: CPoint2D.h:84
static size_type size()
Definition: CPoint2D.h:82
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
GLubyte GLubyte b
Definition: glext.h:5575
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:107
A class used to store a 2D point.
Definition: CPoint2D.h:36
_W64 int ptrdiff_t
Definition: glew.h:133
double & reference
Definition: CPoint2D.h:75
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:78
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:36
double value_type
The type of the elements.
Definition: CPoint2D.h:74
GLenum GLint GLint y
Definition: glext.h:3516
CPoint2D(const mrpt::math::TPoint3D &o)
Explicit constructor from lightweight type (loses the z coord).
Definition: CPoint2D.h:60
#define DEFINE_SERIALIZABLE_POST(class_name)
static bool is_PDF()
Definition: CPoint2D.h:70
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
Lightweight 2D point.
std::size_t size_type
Definition: CPoint2D.h:77
const double & const_reference
Definition: CPoint2D.h:76
static bool is_3D()
Definition: CPoint2D.h:68



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020