Polygon.hpp
Go to the documentation of this file.
1 /*
2  * Polygon.hpp
3  *
4  * Created on: Nov 7, 2014
5  * Author: Péter Fankhauser
6  * Institute: ETH Zurich, ANYbotics
7  */
8 
9 #pragma once
10 
12 
13 // STD
14 #include <vector>
15 
16 // Eigen
17 #include <Eigen/Core>
18 
19 namespace grid_map {
20 
21 class Polygon
22 {
23  public:
24 
25  enum class TriangulationMethods {
26  FAN // Fan triangulation (only for convex polygons).
27  };
28 
32  Polygon();
33 
38  Polygon(std::vector<Position> vertices);
39 
45  bool isInside(const Position& point) const;
46 
51  void addVertex(const Position& vertex);
52 
58  const Position& getVertex(size_t index) const;
59 
63  void removeVertices();
64 
70  const Position& operator [](size_t index) const;
71 
76  const std::vector<Position>& getVertices() const;
77 
82  size_t nVertices() const;
83 
88  void setTimestamp(uint64_t timestamp);
89 
94  uint64_t getTimestamp() const;
95 
99  void resetTimestamp();
100 
105  void setFrameId(const std::string& frameId);
106 
111  const std::string& getFrameId() const;
112 
118  double getArea() const;
119 
125  Position getCentroid() const;
126 
132  void getBoundingBox(Position& center, Length& length) const;
133 
145  bool convertToInequalityConstraints(Eigen::MatrixXd& A,
146  Eigen::VectorXd& b) const;
147 
154  bool offsetInward(double margin);
155 
162  bool thickenLine(double thickness);
163 
168  std::vector<Polygon> triangulate(const TriangulationMethods& method = TriangulationMethods::FAN) const;
169 
177  static Polygon fromCircle(Position center, double radius,
178  int nVertices = 20);
179 
188  static Polygon convexHullOfTwoCircles(Position center1,
189  Position center2,
190  double radius,
191  int nVertices = 20);
192 
199  static Polygon convexHull(Polygon& polygon1, Polygon& polygon2);
200 
206  static Polygon monotoneChainConvexHullOfPoints(const std::vector<Position>& points);
207 
208  protected:
209 
215  static bool sortVertices(const Eigen::Vector2d& vector1,
216  const Eigen::Vector2d& vector2);
217 
223  static double computeCrossProduct2D(const Eigen::Vector2d& vector1,
224  const Eigen::Vector2d& vector2);
225 
232  static double vectorsMakeClockwiseTurn(const Eigen::Vector2d& pointO,
233  const Eigen::Vector2d& pointA,
234  const Eigen::Vector2d& pointB);
235  // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
237  std::string frameId_;
238 
240  uint64_t timestamp_;
241 
243  std::vector<Position> vertices_;
244  // NOLINTEND(misc-non-private-member-variables-in-classes)
245  public:
246  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
247 };
248 
249 } /* namespace grid_map */
const std::string & getFrameId() const
Definition: Polygon.cpp:74
static Polygon convexHullOfTwoCircles(Position center1, Position center2, double radius, int nVertices=20)
Definition: Polygon.cpp:261
const Position & operator[](size_t index) const
Definition: Polygon.cpp:59
size_t nVertices() const
Definition: Polygon.cpp:69
static double computeCrossProduct2D(const Eigen::Vector2d &vector1, const Eigen::Vector2d &vector2)
Definition: Polygon.cpp:339
Position getCentroid() const
Definition: Polygon.cpp:111
static Polygon monotoneChainConvexHullOfPoints(const std::vector< Position > &points)
Definition: Polygon.cpp:297
void setTimestamp(uint64_t timestamp)
Definition: Polygon.cpp:89
uint64_t timestamp_
Timestamp of the polygon (nanoseconds).
Definition: Polygon.hpp:240
void resetTimestamp()
Definition: Polygon.cpp:94
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
void removeVertices()
Definition: Polygon.cpp:54
const Position & getVertex(size_t index) const
Definition: Polygon.cpp:49
std::string frameId_
Frame id of the polygon.
Definition: Polygon.hpp:237
void addVertex(const Position &vertex)
Definition: Polygon.cpp:44
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
static Polygon fromCircle(Position center, double radius, int nVertices=20)
Definition: Polygon.cpp:246
bool offsetInward(double margin)
Definition: Polygon.cpp:197
bool isInside(const Position &point) const
Definition: Polygon.cpp:30
std::vector< Position > vertices_
Vertices of the polygon.
Definition: Polygon.hpp:243
std::vector< Polygon > triangulate(const TriangulationMethods &method=TriangulationMethods::FAN) const
Definition: Polygon.cpp:221
static Polygon convexHull(Polygon &polygon1, Polygon &polygon2)
Definition: Polygon.cpp:287
static bool sortVertices(const Eigen::Vector2d &vector1, const Eigen::Vector2d &vector2)
Definition: Polygon.cpp:332
static double vectorsMakeClockwiseTurn(const Eigen::Vector2d &pointO, const Eigen::Vector2d &pointA, const Eigen::Vector2d &pointB)
Definition: Polygon.cpp:345
void setFrameId(const std::string &frameId)
Definition: Polygon.cpp:79
bool thickenLine(double thickness)
Definition: Polygon.cpp:182
uint64_t getTimestamp() const
Definition: Polygon.cpp:84
bool convertToInequalityConstraints(Eigen::MatrixXd &A, Eigen::VectorXd &b) const
Definition: Polygon.cpp:146
const std::vector< Position > & getVertices() const
Definition: Polygon.cpp:64
void getBoundingBox(Position &center, Length &length) const
Definition: Polygon.cpp:128
double getArea() const
Definition: Polygon.cpp:99


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:35