Main MRPT website > C++ reference for MRPT 1.9.9
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 /** A wrapper of a TPolygon2D class, implementing CSerializable.
20  * \ingroup geometry_grp
21  */
24 {
26 
27  public:
28  /** Default constructor (empty polygon, 0 vertices) */
30  /** Add a new vertex to polygon */
31  void AddVertex(double x, double y)
32  {
34  }
35 
36  /** Methods for accessing the vertices \sa verticesCount */
37  double GetVertex_x(size_t i) const
38  {
40  return TPolygon2D::operator[](i).x;
41  }
42  double GetVertex_y(size_t i) const
43  {
45  return TPolygon2D::operator[](i).y;
46  }
47 
48  /** Returns the vertices count in the polygon: */
49  size_t verticesCount() const { return TPolygon2D::size(); }
50  /** Set all vertices at once. */
51  void setAllVertices(
52  const std::vector<double>& x, const std::vector<double>& y);
53  /** Set all vertices at once. Please use the std::vector version whenever
54  * possible unless efficiency is really an issue */
55  void setAllVertices(size_t nVertices, const double* xs, const double* ys);
56  /** Set all vertices at once. Please use the std::vector version whenever
57  * possible unless efficiency is really an issue */
58  void setAllVertices(size_t nVertices, const float* xs, const float* ys);
59 
60  /** Get all vertices at once */
61  void getAllVertices(std::vector<double>& x, std::vector<double>& y) const;
62 
63  /** Clear the polygon, erasing all vertices */
64  void Clear() { TPolygon2D::clear(); }
65  /** Check if a point is inside the polygon */
66  bool PointIntoPolygon(double x, double y) const
67  {
68  return TPolygon2D::contains(TPoint2D(x, y));
69  }
70 };
71 
72 } // End of namespace
73 } // End of namespace
74 #endif
double GetVertex_x(size_t i) const
Methods for accessing the vertices.
Definition: CPolygon.h:37
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:49
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:44
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
Definition: CPolygon.cpp:134
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:22
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:189
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
Definition: CPolygon.cpp:171
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon.
Definition: CPolygon.h:66
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn&#39;t exist already.
Definition: ts_hash_map.h:200
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
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()
Default constructor (empty polygon, 0 vertices)
Definition: CPolygon.h:29
#define ASSERT_(f)
void Clear()
Clear the polygon, erasing all vertices.
Definition: CPolygon.h:64
GLenum GLint GLint y
Definition: glext.h:3538
GLsizeiptr size
Definition: glext.h:3923
double GetVertex_y(size_t i) const
Definition: CPolygon.h:42
GLenum GLint x
Definition: glext.h:3538
Lightweight 2D point.
void AddVertex(double x, double y)
Add a new vertex to polygon.
Definition: CPolygon.h:31
2D polygon, inheriting from std::vector<TPoint2D>.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019