Main MRPT website > C++ reference
MRPT logo
CPolygon.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 CPOLYGON_H
29 #define CPOLYGON_H
30 
31 #include <mrpt/utils/utils_defs.h>
34 
35 namespace mrpt
36 {
37 namespace math
38 {
39  // This must be added to any CSerializable derived class:
41 
42  /** A wrapper of a TPolygon2D class, implementing CSerializable.
43  * \ingroup geometry_grp
44  */
45  class BASE_IMPEXP CPolygon : public mrpt::utils::CSerializable, public mrpt::math::TPolygon2D
46  {
47  // This must be added to any CSerializable derived class:
49 
50  public:
51  /** Constructor
52  * cx and cy are the "central" point coordinates (laser sensor location if applicable)
53  * This parameters are NOT used in PointIntoPolygon, so they can be ignored.
54  * \sa PointIntoPolygon
55  */
56  CPolygon() : TPolygon2D()
57  {
58  }
59 
60  /** Add a new vertex to polygon: */
61  void AddVertex(double x,double y) {
63  }
64 
65  /** Methods for accessing the vertexs:
66  * \sa verticesCount
67  */
68  double GetVertex_x(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).x; }
69  double GetVertex_y(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).y; }
70 
71  /** Returns the vertices count in the polygon: */
72  size_t verticesCount() const { return TPolygon2D::size(); }
73 
74  /** Set all vertices at once. */
75  void setAllVertices( const std::vector<double> &x, const std::vector<double> &y );
76  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
77  void setAllVertices( size_t nVertices, const double *xs, const double *ys );
78  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
79  void setAllVertices( size_t nVertices, const float *xs, const float *ys );
80 
81  /** Get all vertices at once. */
82  void getAllVertices( std::vector<double> &x, std::vector<double> &y ) const;
83 
84  /** Clear the polygon, erasing all vertexs. */
85  void Clear() { TPolygon2D::clear(); }
86 
87  /** Check if a point is inside the polygon:
88  */
89  bool PointIntoPolygon(double x,double y) const {
90  return TPolygon2D::contains(TPoint2D(x,y));
91  }
92 
93  };
94 
95  } // End of namespace
96 } // End of namespace
97 #endif



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