MRPT  2.0.4
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-2020, 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 = double;
90  using size_type = std::size_t;
91  using difference_type = std::ptrdiff_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
mrpt::poses::CPoint2D::const_reference
double const_reference
Definition: CPoint2D.h:89
mrpt::poses::CPoint2D::size_type
std::size_t size_type
Definition: CPoint2D.h:90
mrpt::poses::CPoint2D::asVector
void asVector(vector_t &v) const
Return the pose or point as a 2x1 vector [x, y]'.
Definition: CPoint2D.h:66
mrpt::poses::CPoint
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:24
mrpt::poses::CPoint2D::is_3D_val
@ is_3D_val
Definition: CPoint2D.h:76
mrpt::math::TPoint3D_< double >
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::math::TPoint2D_
Base template for TPoint2D and TPoint2Df.
Definition: TPoint2D.h:32
mrpt::poses::CPoseOrPoint< CPoint2D, DIM >::x
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
mrpt::poses::CPoint2D::m_coords
mrpt::math::CVectorFixedDouble< 2 > m_coords
[x,y]
Definition: CPoint2D.h:39
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::poses::operator<<
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
mrpt::math::CVectorFixedDouble
CVectorFixed< double, N > CVectorFixedDouble
Specialization of CVectorFixed for double numbers.
Definition: CVectorFixed.h:32
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
mrpt::poses::CPoint2D::is_PDF
static constexpr bool is_PDF()
Definition: CPoint2D.h:83
mrpt::poses::CPoint2D::is_PDF_val
@ is_PDF_val
Definition: CPoint2D.h:81
mrpt::poses::CPoseOrPoint
The base template class for 2D & 3D points and poses.
Definition: CPoseOrPoint.h:123
mrpt::poses::CPoint2D::reference
double & reference
Definition: CPoint2D.h:88
mrpt::poses::CPoint2D::max_size
static constexpr size_type max_size()
Definition: CPoint2D.h:100
CVectorFixed.h
mrpt::poses::CPoint2D::is_3D
static constexpr bool is_3D()
Definition: CPoint2D.h:78
mrpt::math::CMatrixFixed
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
mrpt::poses::CPoint2D::operator-
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
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:39
mrpt::poses::CPoseOrPoint< CPoint2D, DIM >::y
double y() const
Definition: CPoseOrPoint.h:147
mrpt::serialization::CSerializable
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:30
mrpt::poses::CPoint2D::asTPoint
mrpt::math::TPoint2D asTPoint() const
Definition: CPoint2D.cpp:97
mrpt::poses::CPoint2D::setToNaN
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint2D.cpp:91
CPoint.h
DEFINE_SCHEMA_SERIALIZABLE
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:121
mrpt::poses::CPoint2D::resize
static void resize(const size_t n)
Definition: CPoint2D.h:101
mrpt::poses::CPoint2D::CPoint2D
CPoint2D(double x=0, double y=0)
Constructor for initializing point coordinates.
Definition: CPoint2D.h:43
mrpt::poses::CPoint2D::CPoint2D
CPoint2D(const CPoseOrPoint< OTHERCLASS, DIM2 > &b)
Constructor from x/y coordinates given from other pose.
Definition: CPoint2D.h:51
mrpt::poses::CPoint2D::static_size
@ static_size
Definition: CPoint2D.h:96
mrpt::poses::CPoint2D
A class used to store a 2D point.
Definition: CPoint2D.h:32
mrpt::poses::CPoint2D::empty
static constexpr bool empty()
Definition: CPoint2D.h:99
mrpt::poses::CPoint2D::size
static constexpr size_type size()
Definition: CPoint2D.h:98
mrpt::format
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
mrpt::poses::CPoint2D::difference_type
std::ptrdiff_t difference_type
Definition: CPoint2D.h:91
mrpt::poses::CPoint2D::value_type
double value_type
The type of the elements.
Definition: CPoint2D.h:87



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sat Jun 27 14:00:59 UTC 2020