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_node_constraint.h>
25 #include <navgraph/constraints/static_list_edge_constraint.h>
26 
27 #include <vector>
28 #include <string>
29 
30 #include <navgraph/navgraph.h>
31 
32 namespace fawkes{
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
38 {
39  public:
40  /** Simple point representation for polygon. */
41  typedef struct Point_ {
42  /** Constructor.
43  * @param x X coordinate of point
44  * @param y Y coordinate of point
45  */
46  Point_(float x, float y) : x(x), y(y) {}
47  float x; ///< X coordinate of point
48  float y; ///< Y coordinate of point
49  } Point;
50  /// Handle for polygon for selective removal
51  typedef unsigned int PolygonHandle;
52  /// A vector of points makes a polygon.
53  typedef std::vector<Point> Polygon;
54  /// Map for accessing all polygons at once with their handles.
55  typedef std::map<PolygonHandle, Polygon> PolygonMap;
56 
58 
59  const PolygonMap & polygons() const;
60  PolygonHandle add_polygon(const Polygon &polygon);
61  void remove_polygon(const PolygonHandle &handle);
62  void clear_polygons();
63 
64  protected:
66  NavGraphPolygonConstraint(const Polygon &polygon);
67 
68  bool in_poly(const Point &point, const Polygon &polygon);
69  bool on_poly(const Point &p1, const Point &p2, const Polygon &polygon);
70 
71  protected:
72  PolygonMap polygons_; ///< currently registered polygons
73 
74  private:
75  unsigned int cur_polygon_handle_;
76 };
77 
78 } // end namespace fawkes
79 
80 #endif
PolygonMap polygons_
currently registered polygons
PolygonHandle add_polygon(const Polygon &polygon)
Add a polygon to constraint list.
virtual ~NavGraphPolygonConstraint()
Virtual empty destructor.
Simple point representation for polygon.
Fawkes library namespace.
struct fawkes::NavGraphPolygonConstraint::Point_ Point
Simple point representation for polygon.
void remove_polygon(const PolygonHandle &handle)
Remove a polygon from the constraint list.
std::map< PolygonHandle, Polygon > PolygonMap
Map for accessing all polygons at once with their handles.
Constraint that blocks nodes within and edges touching a polygon.
bool on_poly(const Point &p1, const Point &p2, const Polygon &polygon)
Check if a line segments lies on a given polygon.
unsigned int PolygonHandle
Handle for polygon for selective removal.
std::vector< Point > Polygon
A vector of points makes a polygon.
void clear_polygons()
Remove all polygons.
bool in_poly(const Point &point, const Polygon &polygon)
Check if given point lies inside the polygon.
const PolygonMap & polygons() const
Get reference to the map of polygons.
Point_(float x, float y)
Constructor.