Main MRPT website > C++ reference
MRPT logo
CPoint2D.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 CPOINT2D_H
29 #define CPOINT2D_H
30 
32 #include <mrpt/poses/CPoint.h>
33 
34 namespace mrpt
35 {
36 namespace poses
37 {
38  class CPose2D;
39 
41 
42  /** A class used to store a 2D point.
43  *
44  * For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
45  * to the <a href="http://www.mrpt.org/2D_3D_Geometry" >2D/3D Geometry tutorial</a> in the wiki.
46  *
47  * <div align=center>
48  * <img src="CPoint2D.gif">
49  * </div>
50  *
51  * \sa CPoseOrPoint,CPose, CPoint
52  * \ingroup poses_grp
53  */
54  class BASE_IMPEXP CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
55  {
56  // This must be added to any CSerializable derived class:
57  DEFINE_SERIALIZABLE( CPoint2D )
58 
59  public:
60  mrpt::math::CArrayDouble<2> m_coords; //!< [x,y]
61 
62  public:
63  /** Constructor for initializing point coordinates. */
64  inline CPoint2D(double x=0,double y=0) { m_coords[0]=x; m_coords[1]=y; }
65 
66  /** Constructor from x/y coordinates given from other pose. */
67  template <class OTHERCLASS>
68  inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS> &b)
69  {
70  m_coords[0]=b.x();
71  m_coords[1]=b.y();
72  }
73 
74  /** Implicit constructor from lightweight type. */
75  inline CPoint2D(const mrpt::math::TPoint2D &o) { m_coords[0]=o.x; m_coords[1]=o.y; }
76 
77  /** Explicit constructor from lightweight type (loses the z coord). */
78  inline explicit CPoint2D(const mrpt::math::TPoint3D &o) { m_coords[0]=o.x; m_coords[1]=o.y; m_coords[2]=0; }
79 
80  /** The operator D="this"-b is the pose inverse compounding operator,
81  * the resulting points "D" fulfils: "this" = b + D, so that: b == a + (b-a)
82  */
83  CPoint2D operator - (const CPose2D& b) const;
84 
85  enum { is_3D_val = 0 };
86  static inline bool is_3D() { return is_3D_val!=0; }
87  enum { is_PDF_val = 0 };
88  static inline bool is_PDF() { return is_PDF_val!=0; }
89 
90  /** @name STL-like methods and typedefs
91  @{ */
92  typedef double value_type; //!< The type of the elements
93  typedef double& reference;
94  typedef const double& const_reference;
95  typedef std::size_t size_type;
96  typedef std::ptrdiff_t difference_type;
97 
98  // size is constant
99  enum { static_size = 2 };
100  static inline size_type size() { return static_size; }
101  static inline bool empty() { return false; }
102  static inline size_type max_size() { return static_size; }
103  static inline void resize(const size_t n) { if (n!=static_size) throw std::logic_error(format("Try to change the size of CPoint2D to %u.",static_cast<unsigned>(n))); }
104  /** @} */
105 
106  }; // End of class def.
107 
108 
109  } // End of namespace
110 } // End of namespace
111 
112 #endif



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