Main MRPT website > C++ reference
MRPT logo
CPoint3D.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPOINT3D_H
29 #define CPOINT3D_H
30 
31 #include <mrpt/poses/CPoint.h>
32 #include <mrpt/poses/CPose3D.h>
33 
34 namespace mrpt
35 {
36 namespace poses
37 {
39 
40  /** A class used to store a 3D point.
41  *
42  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
43  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry tutorial</a> in the wiki.
44  *
45  * <div align=center>
46  * <img src="CPoint3D.gif">
47  * </div>
48  *
49  * \ingroup poses_grp
50  * \sa CPoseOrPoint,CPose, CPoint
51  */
52  class BASE_IMPEXP CPoint3D : public CPoint<CPoint3D>, public mrpt::utils::CSerializable
53  {
54  // This must be added to any CSerializable derived class:
55  DEFINE_SERIALIZABLE( CPoint3D )
56 
57  public:
58  mrpt::math::CArrayDouble<3> m_coords; //!< [x,y,z]
59 
60  public:
61  /** Constructor for initializing point coordinates. */
62  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; }
63 
64  /** Constructor from a XYZ 3-vector */
65  explicit inline CPoint3D(const mrpt::math::CArrayDouble<3> &xyz) : m_coords(xyz) { }
66 
67  /** Constructor from an CPoint2D object. */
68  CPoint3D( const CPoint2D &p);
69 
70  /** Constructor from an CPose3D object. */
71  explicit inline CPoint3D( const CPose3D &p) { m_coords[0]=p.x(); m_coords[1]=p.y(); m_coords[2]=p.z(); }
72 
73  /** Constructor from an CPose2D object. */
74  explicit CPoint3D( const CPose2D &p);
75 
76  /** Constructor from lightweight object. */
77  inline CPoint3D(const mrpt::math::TPoint3D &p) { m_coords[0]=p.x; m_coords[1]=p.y; m_coords[2]=p.z; }
78 
79  /** Returns this point as seen from "b", i.e. result = this - b */
80  CPoint3D operator - (const CPose3D& b) const;
81 
82  /** Returns this point minus point "b", i.e. result = this - b */
83  CPoint3D operator - (const CPoint3D& b) const;
84 
85  /** Returns this point plus point "b", i.e. result = this + b */
86  CPoint3D operator + (const CPoint3D& b) const;
87 
88  /** Returns this point plus pose "b", i.e. result = this + b */
89  CPose3D operator + (const CPose3D& b) const;
90 
91 
92  enum { is_3D_val = 1 };
93  static inline bool is_3D() { return is_3D_val!=0; }
94 
95  enum { is_PDF_val = 0 };
96  static inline bool is_PDF() { return is_PDF_val!=0; }
97 
98  /** @name STL-like methods and typedefs
99  @{ */
100  typedef double value_type; //!< The type of the elements
101  typedef double& reference;
102  typedef const double& const_reference;
103  typedef std::size_t size_type;
104  typedef std::ptrdiff_t difference_type;
105 
106 
107  // size is constant
108  enum { static_size = 3 };
109  static inline size_type size() { return static_size; }
110  static inline bool empty() { return false; }
111  static inline size_type max_size() { return static_size; }
112  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))); }
113  /** @} */
114 
115  }; // End of class def.
116 
117 
118  } // End of namespace
119 } // End of namespace
120 
121 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013