Main MRPT website > C++ reference
MRPT logo

CPoint2D.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CPOINT2D_H
00029 #define CPOINT2D_H
00030 
00031 #include <mrpt/utils/CSerializable.h>
00032 #include <mrpt/poses/CPoint.h>
00033 
00034 namespace mrpt
00035 {
00036 namespace poses
00037 {
00038         class CPose2D;
00039 
00040         DEFINE_SERIALIZABLE_PRE( CPoint2D )
00041 
00042         /** A class used to store a 2D point.
00043          *
00044          *  For a complete description of Points/Poses, see mrpt::poses::CPoseOrPoint, or refer
00045          *    to the <a href="http://www.mrpt.org/2D_3D_Geometry">2D/3D Geometry tutorial</a> in the wiki.
00046          *
00047          *  <div align=center>
00048          *   <img src="CPoint2D.gif">
00049          *  </div>
00050          *
00051          * \sa CPoseOrPoint,CPose, CPoint
00052          */
00053         class BASE_IMPEXP CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
00054         {
00055                 // This must be added to any CSerializable derived class:
00056                 DEFINE_SERIALIZABLE( CPoint2D )
00057 
00058         public:
00059                 mrpt::math::CArrayDouble<2>   m_coords; //!< [x,y]
00060 
00061         public:
00062                  /** Constructor for initializing point coordinates. */
00063                  inline CPoint2D(double x=0,double y=0) { m_coords[0]=x; m_coords[1]=y; }
00064 
00065                  /** Constructor from x/y coordinates given from other pose. */
00066                 template <class OTHERCLASS>
00067                 inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS> &b)
00068                 {
00069                         m_coords[0]=b.x();
00070                         m_coords[1]=b.y();
00071                 }
00072 
00073                 /** Implicit constructor from lightweight type. */
00074                 inline CPoint2D(const mrpt::math::TPoint2D &o) { m_coords[0]=o.x; m_coords[1]=o.y; }
00075 
00076                 /** Explicit constructor from lightweight type (loses the z coord). */
00077                 inline explicit CPoint2D(const mrpt::math::TPoint3D &o) { m_coords[0]=o.x; m_coords[1]=o.y; m_coords[2]=0; }
00078 
00079                 /** The operator D="this"-b is the pose inverse compounding operator,
00080                 *   the resulting points "D" fulfils: "this" = b + D, so that: b == a + (b-a)
00081                 */
00082                 CPoint2D  operator - (const CPose2D& b) const;
00083 
00084                 enum { is_3D_val = 0 };
00085                 static inline bool is_3D() { return is_3D_val!=0; }
00086                 enum { is_PDF_val = 0 };
00087                 static inline bool is_PDF() { return is_PDF_val!=0; }
00088 
00089                  /** @name STL-like methods and typedefs
00090                    @{   */
00091                 typedef double         value_type;              //!< The type of the elements
00092                 typedef double&        reference;
00093                 typedef const double&  const_reference;
00094                 typedef std::size_t    size_type;
00095                 typedef std::ptrdiff_t difference_type;
00096 
00097                 // size is constant
00098                 enum { static_size = 2 };
00099                 static inline size_type size() { return static_size; }
00100                 static inline bool empty() { return false; }
00101                 static inline size_type max_size() { return static_size; }
00102                 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))); }
00103                 /** @} */
00104 
00105         }; // End of class def.
00106 
00107 
00108         } // End of namespace
00109 } // End of namespace
00110 
00111 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011