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
31namespace fawkes {
32
34{
35public:
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
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;
59 PolygonHandle add_polygon(const Polygon &polygon);
60 void remove_polygon(const PolygonHandle &handle);
61 void clear_polygons();
62
63protected:
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
70protected:
71 PolygonMap polygons_; ///< currently registered polygons
72
73private:
74 unsigned int cur_polygon_handle_;
75};
76
77} // end namespace fawkes
78
79#endif
Constraint that blocks nodes within and edges touching a polygon.
PolygonMap polygons_
currently registered polygons
virtual ~NavGraphPolygonConstraint()
Virtual empty destructor.
bool on_poly(const Point &p1, const Point &p2, const Polygon &polygon)
Check if a line segments lies on a given polygon.
void remove_polygon(const PolygonHandle &handle)
Remove a polygon from the constraint list.
unsigned int PolygonHandle
Handle for polygon for selective removal.
struct fawkes::NavGraphPolygonConstraint::Point_ Point
Simple point representation for polygon.
const PolygonMap & polygons() const
Get reference to the map of polygons.
std::vector< Point > Polygon
A vector of points makes a polygon.
bool in_poly(const Point &point, const Polygon &polygon)
Check if given point lies inside the polygon.
void clear_polygons()
Remove all polygons.
std::map< PolygonHandle, Polygon > PolygonMap
Map for accessing all polygons at once with their handles.
PolygonHandle add_polygon(const Polygon &polygon)
Add a polygon to constraint list.
Fawkes library namespace.
Simple point representation for polygon.
Point_(float x, float y)
Constructor.