MRPT  1.9.9
CPoint2D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/CVectorFixed.h>
12 #include <mrpt/poses/CPoint.h>
13 
14 namespace mrpt::poses
15 {
16 class CPose2D;
17 
18 /** A class used to store a 2D point.
19  *
20  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint,
21  * or refer
22  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry
23  * tutorial</a> in the wiki.
24  *
25  * <div align=center>
26  * <img src="CPoint2D.gif">
27  * </div>
28  *
29  * \sa CPoseOrPoint,CPose, CPoint
30  * \ingroup poses_grp
31  */
32 class CPoint2D : public CPoint<CPoint2D, 2>,
34 {
37  public:
38  /** [x,y] */
40 
41  public:
42  /** Constructor for initializing point coordinates. */
43  inline CPoint2D(double x = 0, double y = 0)
44  {
45  m_coords[0] = x;
46  m_coords[1] = y;
47  }
48 
49  /** Constructor from x/y coordinates given from other pose. */
50  template <class OTHERCLASS, std::size_t DIM2>
51  inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS, DIM2>& b)
52  {
53  m_coords[0] = b.x();
54  m_coords[1] = b.y();
55  }
56 
57  /** Implicit constructor from lightweight type. */
58  explicit CPoint2D(const mrpt::math::TPoint2D& o);
59 
60  /** Explicit constructor from lightweight type (loses the z coord). */
61  explicit CPoint2D(const mrpt::math::TPoint3D& o);
62 
64 
65  /** Return the pose or point as a 2x1 vector [x, y]' */
66  void asVector(vector_t& v) const { v = m_coords; }
67 
68  /** The operator D="this"-b is the pose inverse compounding operator,
69  * the resulting points "D" fulfils: "this" = b + D, so that: b == a +
70  * (b-a)
71  */
72  CPoint2D operator-(const CPose2D& b) const;
73 
74  enum
75  {
77  };
78  static constexpr bool is_3D() { return is_3D_val != 0; }
79  enum
80  {
82  };
83  static constexpr bool is_PDF() { return is_PDF_val != 0; }
84  /** @name STL-like methods and typedefs
85  @{ */
86  /** The type of the elements */
87  using value_type = double;
88  using reference = double&;
89  using const_reference = const double&;
90  using size_type = std::size_t;
92 
93  // size is constant
94  enum
95  {
97  };
98  static constexpr size_type size() { return static_size; }
99  static constexpr bool empty() { return false; }
100  static constexpr size_type max_size() { return static_size; }
101  static inline void resize(const size_t n)
102  {
103  if (n != static_size)
104  throw std::logic_error(format(
105  "Try to change the size of CPoint2D to %u.",
106  static_cast<unsigned>(n)));
107  }
108  /** @} */
109 
110  void setToNaN() override;
111 
112 }; // End of class def.
113 
114 /** Dumps a point as a string (x,y) */
115 std::ostream& operator<<(std::ostream& o, const CPoint2D& p);
116 
117 } // namespace mrpt::poses
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
mrpt::math::CVectorFixedDouble< 2 > m_coords
[x,y]
Definition: CPoint2D.h:39
void asVector(vector_t &v) const
Return the pose or point as a 2x1 vector [x, y]&#39;.
Definition: CPoint2D.h:66
static constexpr bool is_PDF()
Definition: CPoint2D.h:83
static void resize(const size_t n)
Definition: CPoint2D.h:101
static constexpr bool empty()
Definition: CPoint2D.h:99
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
GLenum GLsizei n
Definition: glext.h:5136
CPoint2D(const CPoseOrPoint< OTHERCLASS, DIM2 > &b)
Constructor from x/y coordinates given from other pose.
Definition: CPoint2D.h:51
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
static constexpr size_type max_size()
Definition: CPoint2D.h:100
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:24
GLubyte GLubyte b
Definition: glext.h:6372
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:43
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
The base template class for 2D & 3D points and poses.
Definition: CPoseOrPoint.h:123
A class used to store a 2D point.
Definition: CPoint2D.h:32
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
double & reference
Definition: CPoint2D.h:88
_W64 int ptrdiff_t
Definition: glew.h:136
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:91
const GLdouble * v
Definition: glext.h:3684
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...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
std::ptrdiff_t difference_type
Definition: CPoint2D.h:91
double value_type
The type of the elements.
Definition: CPoint2D.h:87
CVectorFixed< double, N > CVectorFixedDouble
Specialization of CVectorFixed for double numbers.
Definition: CVectorFixed.h:32
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
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:81
GLenum GLint GLint y
Definition: glext.h:3542
mrpt::math::TPoint2D asTPoint() const
Definition: CPoint2D.cpp:97
GLenum GLint x
Definition: glext.h:3542
static constexpr bool is_3D()
Definition: CPoint2D.h:78
Lightweight 3D point.
Definition: TPoint3D.h:90
Lightweight 2D point.
Definition: TPoint2D.h:31
GLfloat GLfloat p
Definition: glext.h:6398
static constexpr size_type size()
Definition: CPoint2D.h:98
const double & const_reference
Definition: CPoint2D.h:89
std::size_t size_type
Definition: CPoint2D.h:90



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ce1a28c9f Fri Aug 23 08:02:09 2019 +0200 at vie ago 23 08:10:11 CEST 2019