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 
43  virtual ~Polygon();
44 
50  bool isInside(const Position& point) const;
51 
56  void addVertex(const Position& vertex);
57 
63  const Position& getVertex(const size_t index) const;
64 
68  void removeVertices();
69 
75  const Position& operator [](const size_t index) const;
76 
81  const std::vector<Position>& getVertices() const;
82 
87  size_t nVertices() const;
88 
93  void setTimestamp(const uint64_t timestamp);
94 
99  uint64_t getTimestamp() const;
100 
104  void resetTimestamp();
105 
110  void setFrameId(const std::string& frameId);
111 
116  const std::string& getFrameId() const;
117 
123  double getArea() const;
124 
130  Position getCentroid() const;
131 
137  void getBoundingBox(Position& center, Length& length) const;
138 
150  bool convertToInequalityConstraints(Eigen::MatrixXd& A,
151  Eigen::VectorXd& b) const;
152 
159  bool offsetInward(const double margin);
160 
167  bool thickenLine(const double thickness);
168 
173  std::vector<Polygon> triangulate(const TriangulationMethods& method = TriangulationMethods::FAN) const;
174 
182  static Polygon fromCircle(const Position center, const double radius,
183  const int nVertices = 20);
184 
193  static Polygon convexHullOfTwoCircles(const Position center1,
194  const Position center2,
195  const double radius,
196  const int nVertices = 20);
197 
204  static Polygon convexHull(Polygon& polygon1, Polygon& polygon2);
205 
211  static Polygon monotoneChainConvexHullOfPoints(const std::vector<Position>& points);
212 
213  protected:
214 
220  static bool sortVertices(const Eigen::Vector2d& vector1,
221  const Eigen::Vector2d& vector2);
222 
228  static double computeCrossProduct2D(const Eigen::Vector2d& vector1,
229  const Eigen::Vector2d& vector2);
230 
237  static double vectorsMakeClockwiseTurn(const Eigen::Vector2d& pointO,
238  const Eigen::Vector2d& pointA,
239  const Eigen::Vector2d& pointB);
240 
242  std::string frameId_;
243 
245  uint64_t timestamp_;
246 
248  std::vector<Position> vertices_;
249 
250  public:
251  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
252 };
253 
254 } /* namespace grid_map */
static Polygon convexHullOfTwoCircles(const Position center1, const Position center2, const double radius, const int nVertices=20)
Definition: Polygon.cpp:263
std::vector< Polygon > triangulate(const TriangulationMethods &method=TriangulationMethods::FAN) const
Definition: Polygon.cpp:223
static double computeCrossProduct2D(const Eigen::Vector2d &vector1, const Eigen::Vector2d &vector2)
Definition: Polygon.cpp:341
const std::string & getFrameId() const
Definition: Polygon.cpp:76
Position getCentroid() const
Definition: Polygon.cpp:113
static Polygon monotoneChainConvexHullOfPoints(const std::vector< Position > &points)
Definition: Polygon.cpp:299
uint64_t timestamp_
Timestamp of the polygon (nanoseconds).
Definition: Polygon.hpp:245
bool convertToInequalityConstraints(Eigen::MatrixXd &A, Eigen::VectorXd &b) const
Definition: Polygon.cpp:148
static Polygon fromCircle(const Position center, const double radius, const int nVertices=20)
Definition: Polygon.cpp:248
const Position & operator[](const size_t index) const
Definition: Polygon.cpp:61
bool thickenLine(const double thickness)
Definition: Polygon.cpp:184
void resetTimestamp()
Definition: Polygon.cpp:96
const Position & getVertex(const size_t index) const
Definition: Polygon.cpp:51
Eigen::Vector2d Position
Definition: TypeDefs.hpp:18
void removeVertices()
Definition: Polygon.cpp:56
bool isInside(const Position &point) const
Definition: Polygon.cpp:32
size_t nVertices() const
Definition: Polygon.cpp:71
std::string frameId_
Frame id of the polygon.
Definition: Polygon.hpp:242
void addVertex(const Position &vertex)
Definition: Polygon.cpp:46
std::vector< Position > vertices_
Vertices of the polygon.
Definition: Polygon.hpp:248
static Polygon convexHull(Polygon &polygon1, Polygon &polygon2)
Definition: Polygon.cpp:289
static bool sortVertices(const Eigen::Vector2d &vector1, const Eigen::Vector2d &vector2)
Definition: Polygon.cpp:334
void getBoundingBox(Position &center, Length &length) const
Definition: Polygon.cpp:130
static double vectorsMakeClockwiseTurn(const Eigen::Vector2d &pointO, const Eigen::Vector2d &pointA, const Eigen::Vector2d &pointB)
Definition: Polygon.cpp:347
void setFrameId(const std::string &frameId)
Definition: Polygon.cpp:81
virtual ~Polygon()
Definition: Polygon.cpp:30
uint64_t getTimestamp() const
Definition: Polygon.cpp:86
bool offsetInward(const double margin)
Definition: Polygon.cpp:199
const std::vector< Position > & getVertices() const
Definition: Polygon.cpp:66
void setTimestamp(const uint64_t timestamp)
Definition: Polygon.cpp:91
Eigen::Array2d Length
Definition: TypeDefs.hpp:24
double getArea() const
Definition: Polygon.cpp:101


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Tue Jun 25 2019 20:02:08