Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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#ifndef CPOLYGON_H
10#define CPOLYGON_H
11
14
15namespace mrpt
16{
17namespace math
18{
19 // This must be added to any CSerializable derived class:
20 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPolygon, mrpt::utils::CSerializable )
21
22 /** A wrapper of a TPolygon2D class, implementing CSerializable.
23 * \ingroup geometry_grp
24 */
25 class BASE_IMPEXP CPolygon : public mrpt::utils::CSerializable, public mrpt::math::TPolygon2D
26 {
27 // This must be added to any CSerializable derived class:
29
30 public:
31 /** Constructor
32 * cx and cy are the "central" point coordinates (laser sensor location if applicable)
33 * This parameters are NOT used in PointIntoPolygon, so they can be ignored.
34 * \sa PointIntoPolygon
35 */
37 {
38 }
39
40 /** Add a new vertex to polygon: */
41 void AddVertex(double x,double y) {
42 TPolygon2D::push_back(TPoint2D(x,y));
43 }
44
45 /** Methods for accessing the vertexs:
46 * \sa verticesCount
47 */
48 double GetVertex_x(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).x; }
49 double GetVertex_y(size_t i) const { ASSERT_(i<TPolygon2D::size()); return TPolygon2D::operator [](i).y; }
50
51 /** Returns the vertices count in the polygon: */
52 size_t verticesCount() const { return TPolygon2D::size(); }
53
54 /** Set all vertices at once. */
55 void setAllVertices( const std::vector<double> &x, const std::vector<double> &y );
56 /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
57 void setAllVertices( size_t nVertices, const double *xs, const double *ys );
58 /** Set all vertices at once. Please use the std::vector version whenever possible unless efficiency is really an issue */
59 void setAllVertices( size_t nVertices, const float *xs, const float *ys );
60
61 /** Get all vertices at once. */
62 void getAllVertices( std::vector<double> &x, std::vector<double> &y ) const;
63
64 /** Clear the polygon, erasing all vertexs. */
65 void Clear() { TPolygon2D::clear(); }
66
67 /** Check if a point is inside the polygon:
68 */
69 bool PointIntoPolygon(double x,double y) const {
70 return TPolygon2D::contains(TPoint2D(x,y));
71 }
72
73 };
74 DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPolygon, mrpt::utils::CSerializable )
75
76 } // End of namespace
77} // End of namespace
78#endif
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A wrapper of a TPolygon2D class, implementing CSerializable.
Definition: CPolygon.h:26
void setAllVertices(size_t nVertices, const float *xs, const float *ys)
Set all vertices at once.
bool PointIntoPolygon(double x, double y) const
Check if a point is inside the polygon:
Definition: CPolygon.h:69
size_t verticesCount() const
Returns the vertices count in the polygon:
Definition: CPolygon.h:52
CPolygon()
Constructor cx and cy are the "central" point coordinates (laser sensor location if applicable) This ...
Definition: CPolygon.h:36
void setAllVertices(size_t nVertices, const double *xs, const double *ys)
Set all vertices at once.
void getAllVertices(std::vector< double > &x, std::vector< double > &y) const
Get all vertices at once.
void setAllVertices(const std::vector< double > &x, const std::vector< double > &y)
Set all vertices at once.
void Clear()
Clear the polygon, erasing all vertexs.
Definition: CPolygon.h:65
void AddVertex(double x, double y)
Add a new vertex to polygon:
Definition: CPolygon.h:41
double GetVertex_x(size_t i) const
Methods for accessing the vertexs:
Definition: CPolygon.h:48
double GetVertex_y(size_t i) const
Definition: CPolygon.h:49
2D polygon, inheriting from std::vector<TPoint2D>.
bool contains(const TPoint2D &point) const
Check whether a point is inside the polygon.
#define ASSERT_(f)
Definition: mrpt_macros.h:261
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Lightweight 2D point.



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Wed Mar 22 09:54:56 UTC 2023