MRPT  2.0.4
CPoint3D.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>
14 
15 namespace mrpt::poses
16 {
17 /** A class used to store a 3D point.
18  *
19  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint,
20  * or refer
21  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry
22  * tutorial</a> in the wiki.
23  *
24  * <div align=center>
25  * <img src="CPoint3D.gif">
26  * </div>
27  *
28  * \ingroup poses_grp
29  * \sa CPoseOrPoint,CPose, CPoint
30  */
31 class CPoint3D : public CPoint<CPoint3D, 3>,
33 {
36  public:
37  /** [x,y,z] */
39 
40  public:
41  /** Constructor for initializing point coordinates. */
42  inline CPoint3D(const double x = 0, const double y = 0, const double z = 0)
43  {
44  m_coords[0] = x;
45  m_coords[1] = y;
46  m_coords[2] = z;
47  }
48 
49  /** Constructor from a XYZ 3-vector */
50  explicit inline CPoint3D(const mrpt::math::CVectorFixedDouble<3>& xyz)
51  : m_coords(xyz)
52  {
53  }
54 
55  /** Constructor from an CPoint2D object. */
56  explicit CPoint3D(const CPoint2D& p);
57 
58  /** Constructor from an CPose3D object. */
59  explicit CPoint3D(const CPose3D& p);
60 
61  /** Constructor from an CPose2D object. */
62  explicit CPoint3D(const CPose2D& p);
63 
64  /** Constructor from lightweight object. */
65  inline explicit CPoint3D(const mrpt::math::TPoint3D& p)
66  {
67  m_coords[0] = p.x;
68  m_coords[1] = p.y;
69  m_coords[2] = p.z;
70  }
72 
73  /** Returns this point as seen from "b", i.e. result = this - b */
74  CPoint3D operator-(const CPose3D& b) const;
75 
76  /** Returns this point minus point "b", i.e. result = this - b */
77  CPoint3D operator-(const CPoint3D& b) const;
78 
79  /** Returns this point plus point "b", i.e. result = this + b */
80  CPoint3D operator+(const CPoint3D& b) const;
81 
82  /** Returns this point plus pose "b", i.e. result = this + b */
83  CPose3D operator+(const CPose3D& b) const;
84 
85  /** Return the pose or point as a 3x1 vector [x y z]' */
86  void asVector(vector_t& v) const { v = m_coords; }
87 
88  enum
89  {
91  };
92  static constexpr bool is_3D() { return is_3D_val != 0; }
93  enum
94  {
96  };
97  static constexpr bool is_PDF() { return is_PDF_val != 0; }
98  /** @name STL-like methods and typedefs
99  @{ */
100  /** The type of the elements */
101  using value_type = double;
102  using reference = double&;
103  using const_reference = double;
104  using size_type = std::size_t;
105  using difference_type = std::ptrdiff_t;
106 
107  // size is constant
108  enum
109  {
111  };
112  static constexpr size_type size() { return static_size; }
113  static constexpr bool empty() { return false; }
114  static constexpr size_type max_size() { return static_size; }
115  static inline void resize(const size_t n)
116  {
117  if (n != static_size)
118  throw std::logic_error(format(
119  "Try to change the size of CPoint3D to %u.",
120  static_cast<unsigned>(n)));
121  }
122  /** @} */
123 
124  void setToNaN() override;
125 
126 }; // End of class def.
127 
128 /** Dumps a point as a string (x,y,z) */
129 std::ostream& operator<<(std::ostream& o, const CPoint3D& p);
130 
131 } // namespace mrpt::poses
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
static constexpr bool is_3D()
Definition: CPoint3D.h:92
void setToNaN() override
Set all data fields to quiet NaN.
Definition: CPoint3D.cpp:158
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
mrpt::math::CVectorFixedDouble< 3 > m_coords
[x,y,z]
Definition: CPoint3D.h:38
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
void asVector(vector_t &v) const
Return the pose or point as a 3x1 vector [x y z]&#39;.
Definition: CPoint3D.h:86
CPoint3D(const mrpt::math::TPoint3D &p)
Constructor from lightweight object.
Definition: CPoint3D.h:65
static constexpr bool empty()
Definition: CPoint3D.h:113
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
static constexpr size_type size()
Definition: CPoint3D.h:112
CPoint3D(const mrpt::math::CVectorFixedDouble< 3 > &xyz)
Constructor from a XYZ 3-vector.
Definition: CPoint3D.h:50
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:24
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:143
A class used to store a 2D point.
Definition: CPoint2D.h:32
A class used to store a 3D point.
Definition: CPoint3D.h:31
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
mrpt::math::TPoint3D asTPoint() const
Definition: CPoint3D.cpp:164
std::size_t size_type
Definition: CPoint3D.h:104
T x
X,Y,Z coordinates.
Definition: TPoint3D.h:29
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
CPoint3D operator-(const CPose3D &b) const
Returns this point as seen from "b", i.e.
Definition: CPoint3D.cpp:110
double value_type
The type of the elements.
Definition: CPoint3D.h:101
CPoint3D(const double x=0, const double y=0, const double z=0)
Constructor for initializing point coordinates.
Definition: CPoint3D.h:42
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
static void resize(const size_t n)
Definition: CPoint3D.h:115
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
static constexpr bool is_PDF()
Definition: CPoint3D.h:97
CPoint3D operator+(const CPoint3D &b) const
Returns this point plus point "b", i.e.
Definition: CPoint3D.cpp:141
std::ptrdiff_t difference_type
Definition: CPoint3D.h:105
static constexpr size_type max_size()
Definition: CPoint3D.h:114



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020