MRPT  1.9.9
CPolygon.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/TPolygon2D.h>
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  {
30  TPolygon2D::push_back(TPoint2D(x, y));
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 } // namespace mrpt::math
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
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:215
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:120
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:3542
GLsizeiptr size
Definition: glext.h:3934
double GetVertex_y(size_t i) const
Definition: CPolygon.h:39
GLenum GLint x
Definition: glext.h:3542
Lightweight 2D point.
Definition: TPoint2D.h:31
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:182
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 928d0abbd Sun Oct 13 02:28:49 2019 +0200 at dom oct 13 02:30:11 CEST 2019