Fawkes API  Fawkes Development Version
polygon_constraint.h
1 /***************************************************************************
2  * polygon_constraint.h - Block nodes and edges inside or touching a polygon
3  *
4  * Created: Mon Jan 19 11:14:51 2015 (next to Super-C waiting for demo)
5  * Copyright 2015 Tim Niemueller
6  ****************************************************************************/
7 
8 /* This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Library General Public License for more details.
17  *
18  * Read the full text in the LICENSE.GPL file in the doc directory.
19  */
20 
21 #ifndef _NAVGRAPH_CONSTRAINTS_POLYGON_CONSTRAINT_H_
22 #define _NAVGRAPH_CONSTRAINTS_POLYGON_CONSTRAINT_H_
23 
24 #include <navgraph/constraints/static_list_edge_constraint.h>
25 #include <navgraph/constraints/static_list_node_constraint.h>
26 #include <navgraph/navgraph.h>
27 
28 #include <string>
29 #include <vector>
30 
31 namespace fawkes {
32 
33 class NavGraphPolygonConstraint
34 {
35 public:
36  /** Simple point representation for polygon. */
37  typedef struct Point_
38  {
39  /** Constructor.
40  * @param x X coordinate of point
41  * @param y Y coordinate of point
42  */
43  Point_(float x, float y) : x(x), y(y)
44  {
45  }
46  float x; ///< X coordinate of point
47  float y; ///< Y coordinate of point
48  } Point;
49  /// Handle for polygon for selective removal
50  typedef unsigned int PolygonHandle;
51  /// A vector of points makes a polygon.
52  typedef std::vector<Point> Polygon;
53  /// Map for accessing all polygons at once with their handles.
54  typedef std::map<PolygonHandle, Polygon> PolygonMap;
55 
57 
58  const PolygonMap &polygons() const;
60  void remove_polygon(const PolygonHandle &handle);
62 
63 protected:
65  NavGraphPolygonConstraint(const Polygon &polygon);
66 
67  bool in_poly(const Point &point, const Polygon &polygon);
68  bool on_poly(const Point &p1, const Point &p2, const Polygon &polygon);
69 
70 protected:
71  PolygonMap polygons_; ///< currently registered polygons
72 
73 private:
74  unsigned int cur_polygon_handle_;
75 };
76 
77 } // end namespace fawkes
78 
79 #endif
fawkes::NavGraphPolygonConstraint::PolygonHandle
unsigned int PolygonHandle
Handle for polygon for selective removal.
Definition: polygon_constraint.h:57
fawkes::NavGraphPolygonConstraint::Polygon
std::vector< Point > Polygon
A vector of points makes a polygon.
Definition: polygon_constraint.h:59
fawkes::NavGraphPolygonConstraint::Point_::Point_
Point_(float x, float y)
Constructor.
Definition: polygon_constraint.h:54
fawkes::NavGraphPolygonConstraint::Point_
Simple point representation for polygon.
Definition: polygon_constraint.h:44
fawkes::NavGraphPolygonConstraint::PolygonMap
std::map< PolygonHandle, Polygon > PolygonMap
Map for accessing all polygons at once with their handles.
Definition: polygon_constraint.h:61
fawkes::NavGraphPolygonConstraint::polygons
const PolygonMap & polygons() const
Get reference to the map of polygons.
Definition: polygon_constraint.cpp:84
fawkes::NavGraphPolygonConstraint::remove_polygon
void remove_polygon(const PolygonHandle &handle)
Remove a polygon from the constraint list.
Definition: polygon_constraint.cpp:73
fawkes::NavGraphPolygonConstraint::Point_::y
float y
Y coordinate of point.
Definition: polygon_constraint.h:58
fawkes::NavGraphPolygonConstraint::Point_::x
float x
X coordinate of point.
Definition: polygon_constraint.h:57
fawkes::NavGraphPolygonConstraint::polygons_
PolygonMap polygons_
currently registered polygons
Definition: polygon_constraint.h:78
fawkes::NavGraphPolygonConstraint::on_poly
bool on_poly(const Point &p1, const Point &p2, const Polygon &polygon)
Check if a line segments lies on a given polygon.
Definition: polygon_constraint.cpp:170
fawkes::NavGraphPolygonConstraint::Point
struct fawkes::NavGraphPolygonConstraint::Point_ Point
Simple point representation for polygon.
fawkes
fawkes::NavGraphPolygonConstraint::NavGraphPolygonConstraint
NavGraphPolygonConstraint()
Constructor.
Definition: polygon_constraint.cpp:37
fawkes::NavGraphPolygonConstraint::clear_polygons
void clear_polygons()
Remove all polygons.
Definition: polygon_constraint.cpp:91
fawkes::NavGraphPolygonConstraint::in_poly
bool in_poly(const Point &point, const Polygon &polygon)
Check if given point lies inside the polygon.
Definition: polygon_constraint.cpp:109
fawkes::NavGraphPolygonConstraint::add_polygon
PolygonHandle add_polygon(const Polygon &polygon)
Add a polygon to constraint list.
Definition: polygon_constraint.cpp:62
fawkes::NavGraphPolygonConstraint::~NavGraphPolygonConstraint
virtual ~NavGraphPolygonConstraint()
Virtual empty destructor.
Definition: polygon_constraint.cpp:52