Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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  /** Default constructor (empty polygon, 0 vertices) */
32  CPolygon() : TPolygon2D()
33  { }
34 
35  /** Add a new vertex to polygon */
36  void AddVertex(double x,double y) {
38  }
39 
40  /** Methods for accessing the vertices \sa verticesCount */
41  double GetVertex_x(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).x; }
42  double GetVertex_y(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).y; }
43 
44  /** Returns the vertices count in the polygon: */
45  size_t verticesCount() const { return TPolygon2D::size(); }
46 
47  /** Set all vertices at once. */
48  void setAllVertices( const std::vector<double> &x, const std::vector<double> &y );
49  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
50  void setAllVertices( size_t nVertices, const double *xs, const double *ys );
51  /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
52  void setAllVertices( size_t nVertices, const float *xs, const float *ys );
53 
54  /** Get all vertices at once */
55  void getAllVertices( std::vector<double> &x, std::vector<double> &y ) const;
56 
57  /** Clear the polygon, erasing all vertices */
58  void Clear() { TPolygon2D::clear(); }
59 
60  /** Check if a point is inside the polygon */
61  bool PointIntoPolygon(double x,double y) const {
62  return TPolygon2D::contains(TPoint2D(x,y));
63  }
64  };
66 
67  } // End of namespace
68 } // End of namespace
69 #endif
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1166
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
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon.
Definition: CPolygon.h:61
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
Definition: ts_hash_map.h:123
GLint GLint GLint GLint GLint x
Definition: glew.h:1166
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
double GetVertex_x(size_t i) const
Methods for accessing the vertices.
Definition: CPolygon.h:41
GLsizeiptr size
Definition: glew.h:1586
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge). This works for concave...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define ASSERT_(f)
void Clear()
Clear the polygon, erasing all vertices.
Definition: CPolygon.h:58
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:45
Lightweight 2D point.
void AddVertex(double x, double y)
Add a new vertex to polygon.
Definition: CPolygon.h:36
double GetVertex_y(size_t i) const
Definition: CPolygon.h:42
2D polygon, inheriting from std::vector<TPoint2D>.



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018