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://www.mrpt.org/                                |
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          * \ingroup poses_grp
00053          */
00054         class BASE_IMPEXP CPoint2D : public CPoint<CPoint2D>, public mrpt::utils::CSerializable
00055         {
00056                 // This must be added to any CSerializable derived class:
00057                 DEFINE_SERIALIZABLE( CPoint2D )
00058 
00059         public:
00060                 mrpt::math::CArrayDouble<2>   m_coords; //!< [x,y]
00061 
00062         public:
00063                  /** Constructor for initializing point coordinates. */
00064                  inline CPoint2D(double x=0,double y=0) { m_coords[0]=x; m_coords[1]=y; }
00065 
00066                  /** Constructor from x/y coordinates given from other pose. */
00067                 template <class OTHERCLASS>
00068                 inline explicit CPoint2D(const CPoseOrPoint<OTHERCLASS> &b)
00069                 {
00070                         m_coords[0]=b.x();
00071                         m_coords[1]=b.y();
00072                 }
00073 
00074                 /** Implicit constructor from lightweight type. */
00075                 inline CPoint2D(const mrpt::math::TPoint2D &o) { m_coords[0]=o.x; m_coords[1]=o.y; }
00076 
00077                 /** Explicit constructor from lightweight type (loses the z coord). */
00078                 inline explicit CPoint2D(const mrpt::math::TPoint3D &o) { m_coords[0]=o.x; m_coords[1]=o.y; m_coords[2]=0; }
00079 
00080                 /** The operator D="this"-b is the pose inverse compounding operator,
00081                 *   the resulting points "D" fulfils: "this" = b + D, so that: b == a + (b-a)
00082                 */
00083                 CPoint2D  operator - (const CPose2D& b) const;
00084 
00085                 enum { is_3D_val = 0 };
00086                 static inline bool is_3D() { return is_3D_val!=0; }
00087                 enum { is_PDF_val = 0 };
00088                 static inline bool is_PDF() { return is_PDF_val!=0; }
00089 
00090                  /** @name STL-like methods and typedefs
00091                    @{   */
00092                 typedef double         value_type;              //!< The type of the elements
00093                 typedef double&        reference;
00094                 typedef const double&  const_reference;
00095                 typedef std::size_t    size_type;
00096                 typedef std::ptrdiff_t difference_type;
00097 
00098                 // size is constant
00099                 enum { static_size = 2 };
00100                 static inline size_type size() { return static_size; }
00101                 static inline bool empty() { return false; }
00102                 static inline size_type max_size() { return static_size; }
00103                 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))); }
00104                 /** @} */
00105 
00106         }; // End of class def.
00107 
00108 
00109         } // End of namespace
00110 } // End of namespace
00111 
00112 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011