Main MRPT website > C++ reference
MRPT logo
CPoint3D.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 CPOINT3D_H
10 #define CPOINT3D_H
11 
12 #include <mrpt/poses/CPoint.h>
13 #include <mrpt/poses/CPose3D.h>
14 
15 namespace mrpt
16 {
17 namespace poses
18 {
20 
21  /** A class used to store a 3D point.
22  *
23  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
24  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry tutorial</a> in the wiki.
25  *
26  * <div align=center>
27  * <img src="CPoint3D.gif">
28  * </div>
29  *
30  * \ingroup poses_grp
31  * \sa CPoseOrPoint,CPose, CPoint
32  */
33  class BASE_IMPEXP CPoint3D : public CPoint<CPoint3D>, public mrpt::utils::CSerializable
34  {
35  // This must be added to any CSerializable derived class:
37 
38  public:
40 
41  public:
42  /** Constructor for initializing point coordinates. */
43  inline CPoint3D(const double x=0,const double y=0,const double z=0) { m_coords[0]= x; m_coords[1]=y; m_coords[2]=z; }
44 
45  /** Constructor from a XYZ 3-vector */
46  explicit inline CPoint3D(const mrpt::math::CArrayDouble<3> &xyz) : m_coords(xyz) { }
47 
48  /** Constructor from an CPoint2D object. */
49  CPoint3D( const CPoint2D &p);
50 
51  /** Constructor from an CPose3D object. */
52  explicit inline CPoint3D( const CPose3D &p) { m_coords[0]=p.x(); m_coords[1]=p.y(); m_coords[2]=p.z(); }
53 
54  /** Constructor from an CPose2D object. */
55  explicit CPoint3D( const CPose2D &p);
56 
57  /** Constructor from lightweight object. */
58  inline CPoint3D(const mrpt::math::TPoint3D &p) { m_coords[0]=p.x; m_coords[1]=p.y; m_coords[2]=p.z; }
59 
60  /** Returns this point as seen from "b", i.e. result = this - b */
61  CPoint3D operator - (const CPose3D& b) const;
62 
63  /** Returns this point minus point "b", i.e. result = this - b */
64  CPoint3D operator - (const CPoint3D& b) const;
65 
66  /** Returns this point plus point "b", i.e. result = this + b */
67  CPoint3D operator + (const CPoint3D& b) const;
68 
69  /** Returns this point plus pose "b", i.e. result = this + b */
70  CPose3D operator + (const CPose3D& b) const;
71 
72 
73  enum { is_3D_val = 1 };
74  static inline bool is_3D() { return is_3D_val!=0; }
75 
76  enum { is_PDF_val = 0 };
77  static inline bool is_PDF() { return is_PDF_val!=0; }
78 
79  /** @name STL-like methods and typedefs
80  @{ */
81  typedef double value_type; //!< The type of the elements
82  typedef double& reference;
83  typedef const double& const_reference;
84  typedef std::size_t size_type;
85  typedef std::ptrdiff_t difference_type;
86 
87 
88  // size is constant
89  enum { static_size = 3 };
90  static inline size_type size() { return static_size; }
91  static inline bool empty() { return false; }
92  static inline size_type max_size() { return static_size; }
93  static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPoint3D to %u.",static_cast<unsigned>(n))); }
94  /** @} */
95 
96  }; // End of class def.
97 
98 
99  } // End of namespace
100 } // End of namespace
101 
102 #endif
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:116
static bool is_PDF()
Definition: CPoint3D.h:77
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...
mrpt::math::CArrayDouble< 3 > m_coords
[x,y,z]
Definition: CPoint3D.h:39
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double & reference
Definition: CPoint3D.h:82
CPoint3D(const mrpt::math::TPoint3D &p)
Constructor from lightweight object.
Definition: CPoint3D.h:58
double value_type
The type of the elements.
Definition: CPoint3D.h:81
double z
Z coordinate.
A base class for representing a point in 2D or 3D.
Definition: CPoint.h:25
class BASE_IMPEXP CSerializable
Definition: CStream.h:21
CPoint3D(const mrpt::math::CArrayDouble< 3 > &xyz)
Constructor from a XYZ 3-vector.
Definition: CPoint3D.h:46
static bool empty()
Definition: CPoint3D.h:91
mrpt::math::TPoint2D BASE_IMPEXP operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
static bool is_3D()
Definition: CPoint3D.h:74
double x
X coordinate.
A class used to store a 2D point.
Definition: CPoint2D.h:35
A class used to store a 3D point.
Definition: CPoint3D.h:33
std::size_t size_type
Definition: CPoint3D.h:84
CPoint3D(const CPose3D &p)
Constructor from an CPose3D object.
Definition: CPoint3D.h:52
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...
static size_type size()
Definition: CPoint3D.h:90
std::ptrdiff_t difference_type
Definition: CPoint3D.h:85
A class used to store a 2D pose.
Definition: CPose2D.h:35
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:71
CPoint3D(const double x=0, const double y=0, const double z=0)
Constructor for initializing point coordinates.
Definition: CPoint3D.h:43
static void resize(const size_t n)
Definition: CPoint3D.h:93
double y
Y coordinate.
Lightweight 3D point.
static size_type max_size()
Definition: CPoint3D.h:92
const double & const_reference
Definition: CPoint3D.h:83



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