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::math
15 {
16 /** A wrapper of a TPolygon2D class, implementing CSerializable.
17  * \ingroup geometry_grp
18  */
21 {
23 
24  public:
25  /** Default constructor (empty polygon, 0 vertices) */
27  /** Add a new vertex to polygon */
28  void AddVertex(double x, double y)
29  {
31  }
32 
33  /** Methods for accessing the vertices \sa verticesCount */
34  double GetVertex_x(size_t i) const
35  {
37  return TPolygon2D::operator[](i).x;
38  }
39  double GetVertex_y(size_t i) const
40  {
42  return TPolygon2D::operator[](i).y;
43  }
44 
45  /** Returns the vertices count in the polygon: */
46  size_t verticesCount() const { return TPolygon2D::size(); }
47  /** Set all vertices at once. */
48  void setAllVertices(
49  const std::vector<double>& x, const std::vector<double>& y);
50  /** Set all vertices at once. Please use the std::vector version whenever
51  * possible unless efficiency is really an issue */
52  void setAllVertices(size_t nVertices, const double* xs, const double* ys);
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 float* xs, const float* ys);
56 
57  /** Get all vertices at once */
58  void getAllVertices(std::vector<double>& x, std::vector<double>& y) const;
59 
60  /** Clear the polygon, erasing all vertices */
61  void Clear() { TPolygon2D::clear(); }
62  /** Check if a point is inside the polygon */
63  bool PointIntoPolygon(double x, double y) const
64  {
65  return TPolygon2D::contains(TPoint2D(x, y));
66  }
67 };
68 
69 }
70 
double GetVertex_x(size_t i) const
Methods for accessing the vertices.
Definition: CPolygon.h:34
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:46
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:19
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:197
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
This base provides a set of functions for maths stuff.
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon.
Definition: CPolygon.h:63
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
#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:26
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:30
void Clear()
Clear the polygon, erasing all vertices.
Definition: CPolygon.h:61
GLenum GLint GLint y
Definition: glext.h:3538
GLsizeiptr size
Definition: glext.h:3923
double GetVertex_y(size_t i) const
Definition: CPolygon.h:39
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:28
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:186
2D polygon, inheriting from std::vector<TPoint2D>.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020