MRPT  1.9.9
TPolygon3D.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 |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10
11 #include <mrpt/math/TPoseOrPoint.h>
12 #include <vector>
13
14 namespace mrpt::math
15 {
16 /** 3D polygon, inheriting from std::vector<TPoint3D>
17  * \sa TPolygon2D,TSegment3D,TLine3D,TPlane,TPoint3D
18  */
19 class TPolygon3D : public std::vector<TPoint3D>
20 {
21  public:
22  /** Distance to point (always >=0) */
23  double distance(const TPoint3D& point) const;
24  /** Check whether a point is inside (or within geometryEpsilon of a polygon
25  * edge). This works for concave or convex polygons. */
26  bool contains(const TPoint3D& point) const;
27  /** Gets as set of segments, instead of set of points. */
28  void getAsSegmentList(std::vector<TSegment3D>& v) const;
29  /** Gets a plane which contains the polygon. Returns false if the polygon is
30  * skew and cannot be fit inside a plane. */
31  bool getPlane(TPlane& p) const;
32  /** Gets the best fitting plane, disregarding whether the polygon actually
33  * fits inside or not. \sa getBestFittingPlane */
34  void getBestFittingPlane(TPlane& p) const;
35  /** Projects into a 2D space, discarding the z. \sa getPlane,isSkew */
36  void generate2DObject(TPolygon2D& p) const;
37  /** Get polygon's central point. */
38  void getCenter(TPoint3D& p) const;
39  /** Check whether the polygon is skew. Returns true if there doesn't exist a
40  * plane in which the polygon can fit. \sa getBestFittingPlane */
41  bool isSkew() const;
42  /** Remove polygon's repeated vertices. */
44  /** Erase every redundant vertex, thus saving space. */
46  /** Default constructor. Creates a polygon with no vertices. */
47  TPolygon3D() : std::vector<TPoint3D>() {}
48  /** Constructor for a given size. Creates a polygon with a fixed number of
49  * vertices, which are initialized to garbage. */
50  explicit TPolygon3D(size_t N) : std::vector<TPoint3D>(N) {}
51  /** Implicit constructor from a 3D points vector. */
52  TPolygon3D(const std::vector<TPoint3D>& v) : std::vector<TPoint3D>(v) {}
53  /** Constructor from a 2D object. Zeroes the z. */
54  explicit TPolygon3D(const TPolygon2D& p);
55  /** Static method to create a regular polygon, given its size and radius.
56  * \throw std::logic_error if number of edges is less than three, or radius
57  * is near zero. */
58  static void createRegularPolygon(
59  size_t numEdges, double radius, TPolygon3D& poly);
60  /** Static method to create a regular polygon, given its size and radius.
61  * The center will be located on the given pose.
62  * \throw std::logic_error if number of edges is less than three, or radius
63  * is near zero.
64  */
65  static void createRegularPolygon(
66  size_t numEdges, double radius, TPolygon3D& poly,
67  const mrpt::math::TPose3D& pose);
68 };
69
70 } // namespace mrpt::math
71
72 namespace mrpt::typemeta
73 {
74 // Specialization must occur in the same namespace
76
77 } // namespace mrpt::typemeta
TPolygon3D(const std::vector< TPoint3D > &v)
Implicit constructor from a 3D points vector.
Definition: TPolygon3D.h:52
void getCenter(TPoint3D &p) const
Get polygon&#39;s central point.
Definition: TPolygon3D.cpp:81
TPolygon3D()
Default constructor.
Definition: TPolygon3D.h:47
STL namespace.
static void createRegularPolygon(size_t numEdges, double radius, TPolygon3D &poly)
Static method to create a regular polygon, given its size and radius.
Definition: TPolygon3D.cpp:102
This base provides a set of functions for maths stuff.
void removeRedundantVertices()
Erase every redundant vertex, thus saving space.
Definition: TPolygon3D.cpp:91
void getAsSegmentList(std::vector< TSegment3D > &v) const
Gets as set of segments, instead of set of points.
Definition: TPolygon3D.cpp:68
3D Plane, represented by its equation
Definition: TPlane.h:22
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
Definition: TPolygon3D.cpp:77
void removeRepeatedVertices()
Remove polygon&#39;s repeated vertices.
Definition: TPolygon3D.cpp:90
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:24
TPolygon3D(size_t N)
Constructor for a given size.
Definition: TPolygon3D.h:50
void generate2DObject(TPolygon2D &p) const
Projects into a 2D space, discarding the z.
Definition: TPolygon3D.cpp:24
bool isSkew() const
Check whether the polygon is skew.
Definition: TPolygon3D.cpp:89
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon.
Definition: TPolygon3D.cpp:76
bool contains(const TPoint3D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
Definition: TPolygon3D.cpp:43
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:19
double distance(const TPoint3D &point) const
Distance to point (always >=0)
Definition: TPolygon3D.cpp:29

 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 24b95e159 Thu Jan 23 01:15:46 2020 +0100 at jue ene 23 01:30:10 CET 2020 