Main MRPT website > C++ reference
MRPT logo

CPolygon.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 CPOLYGON_H
00029 #define CPOLYGON_H
00030 
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/utils/CSerializable.h>
00033 #include <mrpt/math/lightweight_geom_data.h>
00034 
00035 namespace mrpt
00036 {
00037 namespace math
00038 {
00039         // This must be added to any CSerializable derived class:
00040         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPolygon, mrpt::utils::CSerializable )
00041 
00042         /** A wrapper of a TPolygon2D class, implementing CSerializable.
00043          */
00044         class BASE_IMPEXP CPolygon : public mrpt::utils::CSerializable, public mrpt::math::TPolygon2D
00045         {
00046                 // This must be added to any CSerializable derived class:
00047                 DEFINE_SERIALIZABLE( CPolygon )
00048 
00049         public:
00050                 /** Constructor
00051                   *  cx and cy are the "central" point coordinates (laser sensor location if applicable)
00052                   *  This parameters are NOT used in PointIntoPolygon, so they can be ignored.
00053                   * \sa PointIntoPolygon
00054                  */
00055                 CPolygon() : TPolygon2D() 
00056                 {
00057                 }
00058 
00059                 /** Add a new vertex to polygon: */
00060                 void  AddVertex(double x,double y) {
00061                         TPolygon2D::push_back(TPoint2D(x,y));
00062                 }
00063 
00064                 /** Methods for accessing the vertexs:
00065                   * \sa verticesCount
00066                   */
00067                 double  GetVertex_x(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).x; }
00068                 double  GetVertex_y(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).y; }
00069 
00070                 /** Returns the vertices count in the polygon: */
00071                 size_t   verticesCount() const { return TPolygon2D::size(); }
00072 
00073                 /** Set all vertices at once. */
00074                 void  setAllVertices( const std::vector<double> &x, const std::vector<double> &y );
00075                 /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
00076                 void  setAllVertices( size_t nVertices, const double *xs, const double *ys );
00077                 /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
00078                 void  setAllVertices( size_t nVertices, const float *xs, const float *ys );
00079 
00080                 /** Get all vertices at once. */
00081                 void  getAllVertices( std::vector<double> &x, std::vector<double> &y ) const;
00082 
00083                 /** Clear the polygon, erasing all vertexs. */
00084                 void   Clear() { TPolygon2D::clear(); }
00085 
00086                 /**     Check if a point is inside the polygon:
00087                  */
00088                 bool  PointIntoPolygon(double x,double y) const {
00089                         return TPolygon2D::contains(TPoint2D(x,y));
00090                 }
00091 
00092         };
00093 
00094         } // End of namespace
00095 } // End of namespace
00096 #endif



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