Main MRPT website > C++ reference for MRPT 1.4.0
CPolygon.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CPOLYGON_H
10 #define CPOLYGON_H
11 
14 
15 namespace mrpt
16 {
17 namespace math
18 {
19  // This must be added to any CSerializable derived class:
21 
22  /** A wrapper of a TPolygon2D class, implementing CSerializable.
23  * \ingroup geometry_grp
24  */
25  class BASE_IMPEXP CPolygon : public mrpt::utils::CSerializable, public mrpt::math::TPolygon2D
26  {
27  // This must be added to any CSerializable derived class:
29 
30  public:
31  /** Constructor
32  * cx and cy are the "central" point coordinates (laser sensor location if applicable)
33  * This parameters are NOT used in PointIntoPolygon, so they can be ignored.
34  * \sa PointIntoPolygon
35  */
36  CPolygon() : TPolygon2D()
37  {
38  }
39 
40  /** Add a new vertex to polygon: */
41  void AddVertex(double x,double y) {
43  }
44 
45  /** Methods for accessing the vertexs:
46  * \sa verticesCount
47  */
48  double GetVertex_x(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).x; }
49  double GetVertex_y(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).y; }
50 
51  /** Returns the vertices count in the polygon: */
52  size_t verticesCount() const { return TPolygon2D::size(); }
53 
54  /** Set all vertices at once. */
55  void setAllVertices( const std::vector<double> &x, const std::vector<double> &y );
56  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
57  void setAllVertices( size_t nVertices, const double *xs, const double *ys );
58  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
59  void setAllVertices( size_t nVertices, const float *xs, const float *ys );
60 
61  /** Get all vertices at once. */
62  void getAllVertices( std::vector<double> &x, std::vector<double> &y ) const;
63 
64  /** Clear the polygon, erasing all vertexs. */
65  void Clear() { TPolygon2D::clear(); }
66 
67  /** Check if a point is inside the polygon:
68  */
69  bool PointIntoPolygon(double x,double y) const {
70  return TPolygon2D::contains(TPoint2D(x,y));
71  }
72 
73  };
75 
76  } // End of namespace
77 } // End of namespace
78 #endif
double GetVertex_x(size_t i) const
Methods for accessing the vertexs:
Definition: CPolygon.h:48
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:52
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:25
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon:
Definition: CPolygon.h:69
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
bool contains(const TPoint2D &point) const
Check whether a point is inside the polygon.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
CPolygon()
Constructor cx and cy are the "central" point coordinates (laser sensor location if applicable) This ...
Definition: CPolygon.h:36
size_t size(const MATRIXLIKE &m, int dim)
Definition: bits.h:38
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define ASSERT_(f)
void Clear()
Clear the polygon, erasing all vertexs.
Definition: CPolygon.h:65
double GetVertex_y(size_t i) const
Definition: CPolygon.h:49
Lightweight 2D point.
void AddVertex(double x, double y)
Add a new vertex to polygon:
Definition: CPolygon.h:41
2D polygon, inheriting from std::vector<TPoint2D>.



Page generated by Doxygen 1.8.13 for MRPT 1.4.0 SVN: at Fri Mar 17 07:27:15 UTC 2017