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