Main MRPT website > C++ reference
MRPT logo
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-2014, 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 
15 namespace mrpt
16 {
17 namespace poses
18 {
19  class CPose2D;
20 
22 
23  /** A class used to store a 2D point.
24  *
25  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
26  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry tutorial</a> in the wiki.
27  *
28  * <div align=center>
29  * <img src="CPoint2D.gif">
30  * </div>
31  *
32  * \sa CPoseOrPoint,CPose, CPoint
33  * \ingroup poses_grp
34  */
35  class BASE_IMPEXP CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
36  {
37  // This must be added to any CSerializable derived class:
39 
40  public:
42 
43  public:
44  /** Constructor for initializing point coordinates. */
45  inline CPoint2D(double x=0,double y=0) { m_coords[0]=x; m_coords[1]=y; }
46 
47  /** Constructor from x/y coordinates given from other pose. */
48  template <class OTHERCLASS>
49  inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS> &b)
50  {
51  m_coords[0]=b.x();
52  m_coords[1]=b.y();
53  }
54 
55  /** Implicit constructor from lightweight type. */
56  inline CPoint2D(const mrpt::math::TPoint2D &o) { m_coords[0]=o.x; m_coords[1]=o.y; }
57 
58  /** Explicit constructor from lightweight type (loses the z coord). */
59  inline explicit CPoint2D(const mrpt::math::TPoint3D &o) { m_coords[0]=o.x; m_coords[1]=o.y; m_coords[2]=0; }
60 
61  /** The operator D="this"-b is the pose inverse compounding operator,
62  * the resulting points "D" fulfils: "this" = b + D, so that: b == a + (b-a)
63  */
64  CPoint2D operator - (const CPose2D& b) const;
65 
66  enum { is_3D_val = 0 };
67  static inline bool is_3D() { return is_3D_val!=0; }
68  enum { is_PDF_val = 0 };
69  static inline bool is_PDF() { return is_PDF_val!=0; }
70 
71  /** @name STL-like methods and typedefs
72  @{ */
73  typedef double value_type; //!< The type of the elements
74  typedef double& reference;
75  typedef const double& const_reference;
76  typedef std::size_t size_type;
77  typedef std::ptrdiff_t difference_type;
78 
79  // size is constant
80  enum { static_size = 2 };
81  static inline size_type size() { return static_size; }
82  static inline bool empty() { return false; }
83  static inline size_type max_size() { return static_size; }
84  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))); }
85  /** @} */
86 
87  }; // End of class def.
88 
89 
90  } // End of namespace
91 } // End of namespace
92 
93 #endif
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:116
double y
Y coordinate.
double x
X coordinate.
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...
#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:84
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
CPoint2D(const CPoseOrPoint< OTHERCLASS > &b)
Constructor from x/y coordinates given from other pose.
Definition: CPoint2D.h:49
mrpt::math::CArrayDouble< 2 > m_coords
[x,y]
Definition: CPoint2D.h:41
static bool empty()
Definition: CPoint2D.h:82
CPoint2D(const mrpt::math::TPoint2D &o)
Implicit constructor from lightweight type.
Definition: CPoint2D.h:56
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:25
class BASE_IMPEXP CSerializable
Definition: CStream.h:21
static size_type max_size()
Definition: CPoint2D.h:83
static size_type size()
Definition: CPoint2D.h:81
double x
X coordinate.
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:45
The base template class for 2D & 3D points and poses.
A class used to store a 2D point.
Definition: CPoint2D.h:35
double & reference
Definition: CPoint2D.h:74
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:77
A class used to store a 2D pose.
Definition: CPose2D.h:35
double value_type
The type of the elements.
Definition: CPoint2D.h:73
CPoint2D(const mrpt::math::TPoint3D &o)
Explicit constructor from lightweight type (loses the z coord).
Definition: CPoint2D.h:59
static bool is_PDF()
Definition: CPoint2D.h:69
double y
Y coordinate.
Lightweight 3D point.
Lightweight 2D point.
std::size_t size_type
Definition: CPoint2D.h:76
const double & const_reference
Definition: CPoint2D.h:75
static bool is_3D()
Definition: CPoint2D.h:67



Page generated by Doxygen 1.8.14 for MRPT 1.1.0 SVN: at lun oct 28 00:54:49 CET 2019 Hosted on:
SourceForge.net Logo