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
mrpt::containers::clear
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:188
mrpt::containers::operator[]
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
Definition: ts_hash_map.h:199
mrpt::math::CPolygon::AddVertex
void AddVertex(double x, double y)
Add a new vertex to polygon.
Definition: CPolygon.h:30
mrpt::math::TPolygon2D::contains
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
Definition: lightweight_geom_data.cpp:1033
mrpt::math::CPolygon::GetVertex_y
double GetVertex_y(size_t i) const
Definition: CPolygon.h:41
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::math::CPolygon::PointIntoPolygon
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon.
Definition: CPolygon.h:65
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::math::CPolygon::GetVertex_x
double GetVertex_x(size_t i) const
Methods for accessing the vertices.
Definition: CPolygon.h:36
lightweight_geom_data.h
push_back
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
Definition: eigen_plugins.h:134
mrpt::math::CPolygon::Clear
void Clear()
Clear the polygon, erasing all vertices.
Definition: CPolygon.h:63
mrpt::math::CPolygon::verticesCount
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:48
mrpt::serialization::CSerializable
The virtual base class which provides a unified interface for all persistent objects in MRPT.
Definition: CSerializable.h:32
mrpt::math::TPoint2D
Lightweight 2D point.
Definition: lightweight_geom_data.h:42
mrpt::math::TPolygon2D
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: lightweight_geom_data.h:1403
mrpt::math::CPolygon::setAllVertices
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
Definition: CPolygon.cpp:121
mrpt::math::CPolygon
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:21
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
CSerializable.h
mrpt::math::CPolygon::CPolygon
CPolygon()
Default constructor (empty polygon, 0 vertices)
Definition: CPolygon.h:28
mrpt::math::CPolygon::getAllVertices
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
Definition: CPolygon.cpp:158
size
GLsizeiptr size
Definition: glext.h:3923
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST