Polygon.hpp
Go to the documentation of this file.
00001 /*
00002  * Polygon.hpp
00003  *
00004  *  Created on: Nov 7, 2014
00005  *      Author: Péter Fankhauser
00006  *   Institute: ETH Zurich, Autonomous Systems Lab
00007  */
00008 
00009 #pragma once
00010 
00011 #include <grid_map_core/TypeDefs.hpp>
00012 
00013 // STD
00014 #include <vector>
00015 
00016 // Eigen
00017 #include <Eigen/Core>
00018 
00019 namespace grid_map {
00020 
00021 class Polygon
00022 {
00023  public:
00024 
00025   enum class TriangulationMethods {
00026     FAN // Fan triangulation (only for convex polygons).
00027   };
00028 
00032   Polygon();
00033 
00038   Polygon(std::vector<Position> vertices);
00039 
00043   virtual ~Polygon();
00044 
00050   bool isInside(const Position& point) const;
00051 
00056   void addVertex(const Position& vertex);
00057 
00063   const Position& getVertex(const size_t index) const;
00064 
00068   void removeVertices();
00069 
00075   const Position& operator [](const size_t index) const;
00076 
00081   const std::vector<Position>& getVertices() const;
00082 
00087   const size_t nVertices() const;
00088 
00093   void setTimestamp(const uint64_t timestamp);
00094 
00099   uint64_t getTimestamp() const;
00100 
00104   void resetTimestamp();
00105 
00110   void setFrameId(const std::string& frameId);
00111 
00116   const std::string& getFrameId() const;
00117 
00123   const double getArea() const;
00124 
00130   Position getCentroid() const;
00131 
00137   void getBoundingBox(Position& center, Length& length) const;
00138 
00150   bool convertToInequalityConstraints(Eigen::MatrixXd& A,
00151                                       Eigen::VectorXd& b) const;
00152 
00159   bool offsetInward(const double margin);
00160 
00167   bool thickenLine(const double thickness);
00168 
00173   std::vector<Polygon> triangulate(const TriangulationMethods& method = TriangulationMethods::FAN) const;
00174 
00182   static Polygon fromCircle(const Position center, const double radius,
00183                             const int nVertices = 20);
00184 
00193   static Polygon convexHullOfTwoCircles(const Position center1,
00194                                         const Position center2,
00195                                         const double radius,
00196                                         const int nVertices = 20);
00197 
00204   static Polygon convexHull(Polygon& polygon1, Polygon& polygon2);
00205 
00206  protected:
00207 
00213   static bool sortVertices(const Eigen::Vector2d& vector1,
00214                            const Eigen::Vector2d& vector2);
00215 
00221   static double computeCrossProduct2D(const Eigen::Vector2d& vector1,
00222                                       const Eigen::Vector2d& vector2);
00223 
00225   std::string frameId_;
00226 
00228   uint64_t timestamp_;
00229 
00231   std::vector<Position> vertices_;
00232 
00233  public:
00234   EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00235 };
00236 
00237 } /* namespace grid_map */


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Mon Oct 9 2017 03:09:16