Fawkes API  Fawkes Development Version
polygon_node_constraint.cpp
1 /***************************************************************************
2  * polygon_node_constraint.cpp - Block nodes inside a polygon
3  *
4  * Created: Mon Jan 19 11:20:31 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 #include <navgraph/constraints/polygon_node_constraint.h>
22 
23 #include <algorithm>
24 
25 namespace fawkes{
26 #if 0 /* just to make Emacs auto-indent happy */
27 }
28 #endif
29 
30 /** @class NavGraphPolygonNodeConstraint <navgraph/constraints/polygon_constraint.h>
31  * Constraint that blocks nodes inside a polygon.
32  * @author Tim Niemueller
33  */
34 
35 
36 /** Constructor.
37  * @param name name of node constraint
38  */
41 {
42 }
43 
44 
45 
46 /** Constructor.
47  * @param name name of node constraint
48  * @param polygon polygon to add immediately
49  */
51  const Polygon &polygon)
53 {
54 }
55 
56 /** Virtual empty destructor. */
58 {
59 }
60 
61 
62 bool
64 {
65  if (! polygons_.empty()) {
66  return true;
67  } else {
68  return false;
69  }
70 }
71 
72 
73 bool
75 {
76  for (auto p : polygons_) {
77  Point point(node.x(), node.y());
78  if (in_poly(point, p.second)) {
79  return true;
80  }
81  }
82 
83  return false;
84 }
85 
86 
87 } // end of namespace fawkes
PolygonMap polygons_
currently registered polygons
virtual ~NavGraphPolygonNodeConstraint()
Virtual empty destructor.
Simple point representation for polygon.
Fawkes library namespace.
std::string name()
Get name of constraint.
NavGraphPolygonNodeConstraint(const std::string &name)
Constructor.
Constraint that blocks nodes within and edges touching a polygon.
virtual bool compute(void)
Perform compuations before graph search and to indicate re-planning.
Topological graph node.
Definition: navgraph_node.h:38
std::vector< Point > Polygon
A vector of points makes a polygon.
Constraint that can be queried to check if a node is blocked.
bool in_poly(const Point &point, const Polygon &polygon)
Check if given point lies inside the polygon.
virtual bool blocks(const fawkes::NavGraphNode &node)
Check if constraint blocks a node.