MRPT  2.0.1
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-2020, 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
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
size_t size(const MATRIXLIKE &m, const int dim)
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
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
Definition: TPolygon2D.cpp:69
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:216
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
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
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
double GetVertex_y(size_t i) const
Definition: CPolygon.h:39
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:183
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020