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-2018, 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 #pragma once
10 
13 
14 namespace mrpt
15 {
16 namespace math
17 {
18 /** A wrapper of a TPolygon2D class, implementing CSerializable.
19  * \ingroup geometry_grp
20  */
23 {
25 
26  public:
27  /** Default constructor (empty polygon, 0 vertices) */
29  /** Add a new vertex to polygon */
30  void AddVertex(double x, double y)
31  {
33  }
34 
35  /** Methods for accessing the vertices \sa verticesCount */
36  double GetVertex_x(size_t i) const
37  {
39  return TPolygon2D::operator[](i).x;
40  }
41  double GetVertex_y(size_t i) const
42  {
44  return TPolygon2D::operator[](i).y;
45  }
46 
47  /** Returns the vertices count in the polygon: */
48  size_t verticesCount() const { return TPolygon2D::size(); }
49  /** Set all vertices at once. */
50  void setAllVertices(
51  const std::vector<double>& x, const std::vector<double>& y);
52  /** Set all vertices at once. Please use the std::vector version whenever
53  * possible unless efficiency is really an issue */
54  void setAllVertices(size_t nVertices, const double* xs, const double* ys);
55  /** Set all vertices at once. Please use the std::vector version whenever
56  * possible unless efficiency is really an issue */
57  void setAllVertices(size_t nVertices, const float* xs, const float* ys);
58 
59  /** Get all vertices at once */
60  void getAllVertices(std::vector<double>& x, std::vector<double>& y) const;
61 
62  /** Clear the polygon, erasing all vertices */
63  void Clear() { TPolygon2D::clear(); }
64  /** Check if a point is inside the polygon */
65  bool PointIntoPolygon(double x, double y) const
66  {
67  return TPolygon2D::contains(TPoint2D(x, y));
68  }
69 };
70 
71 } // End of namespace
72 } // End of namespace
double GetVertex_x(size_t i) const
Methods for accessing the vertices.
Definition: CPolygon.h:36
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:48
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
Definition: CPolygon.cpp:121
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:21
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:199
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
Definition: CPolygon.cpp:158
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon.
Definition: CPolygon.h:65
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:28
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:32
void Clear()
Clear the polygon, erasing all vertices.
Definition: CPolygon.h:63
GLenum GLint GLint y
Definition: glext.h:3538
GLsizeiptr size
Definition: glext.h:3923
double GetVertex_y(size_t i) const
Definition: CPolygon.h:41
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:30
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:188
2D polygon, inheriting from std::vector<TPoint2D>.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019