Fawkes API Fawkes Development Version
navgraph_edge.h
1
2/***************************************************************************
3 * navgraph_edge.h - Topological graph edge
4 *
5 * Created: Fri Sep 21 16:08:27 2012
6 * Copyright 2012 Tim Niemueller [www.niemueller.de]
7 ****************************************************************************/
8
9/* This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. A runtime exception applies to
13 * this software (see LICENSE.GPL_WRE file mentioned below for details).
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21 */
22
23#ifndef _UTILS_GRAPH_TOPOLOGICAL_MAP_EDGE_H_
24#define _UTILS_GRAPH_TOPOLOGICAL_MAP_EDGE_H_
25
26#include <navgraph/navgraph_node.h>
27#include <utils/math/types.h>
28#include <utils/misc/string_conversions.h>
29
30#include <map>
31#include <string>
32
33namespace fawkes {
34
35class NavGraph;
36
38{
39 friend NavGraph;
40
41public:
43
44 NavGraphEdge(const std::string & from,
45 const std::string & to,
46 std::map<std::string, std::string> properties,
47 bool directed = false);
48
49 NavGraphEdge(const std::string &from, const std::string &to, bool directed = false);
50
51 /** Get edge originating node name.
52 * @return edge originating node name */
53 const std::string &
54 from() const
55 {
56 return from_;
57 }
58
59 /** Get edge target node name.
60 * @return edge target node name */
61 const std::string &
62 to() const
63 {
64 return to_;
65 }
66
67 /** Get edge originating node.
68 * @return edge originating node */
69 const NavGraphNode &
70 from_node() const
71 {
72 return from_node_;
73 }
74
75 /** Get edge target node.
76 * @return edge target node */
77 const NavGraphNode &
78 to_node() const
79 {
80 return to_node_;
81 }
82
83 fawkes::cart_coord_2d_t closest_point_on_edge(float x, float y) const;
84 float distance(float x, float y) const;
85 bool intersects(float x1, float y1, float x2, float y2) const;
86 bool intersection(float x1, float y1, float x2, float y2, fawkes::cart_coord_2d_t &ip) const;
87
88 void set_from(const std::string &from);
89 void set_to(const std::string &to);
90 void set_directed(bool directed);
91
92 /** Get all properties.
93 * @return property map
94 */
95 const std::map<std::string, std::string> &
96 properties() const
97 {
98 return properties_;
99 }
100
101 /** Check if node has specified property.
102 * @param property property key
103 * @return true if node has specified property, false otherwise
104 */
105 bool
106 has_property(const std::string &property) const
107 {
108 return properties_.find(property) != properties_.end();
109 }
110
111 void set_properties(const std::map<std::string, std::string> &properties);
112 void set_property(const std::string &property, const std::string &value);
113 void set_property(const std::string &property, const char *value);
114 void set_property(const std::string &property, float value);
115 void set_property(const std::string &property, int value);
116 void set_property(const std::string &property, bool value);
117
118 /** Get property converted to float.
119 * @param prop property key
120 * @return property value
121 */
122 float
123 property_as_float(const std::string &prop) const
124 {
126 }
127
128 /** Get property converted to int.
129 * @param prop property key
130 * @return property value
131 */
132 int
133 property_as_int(const std::string &prop) const
134 {
136 }
137
138 /** Get property converted to bol.
139 * @param prop property key
140 * @return property value
141 */
142 bool
143 property_as_bool(const std::string &prop) const
144 {
146 }
147
148 /** Check if edge is valid.
149 * An edge is valid iff it has originating and target node name values.
150 * @return true if edge is valid, false otherwise
151 */
152 bool
153 is_valid() const
154 {
155 return from_ != "" && to_ != "";
156 }
157
158 /** Check if edge is directed.
159 * @return true if edge is directed, false otherwise.
160 */
161 bool
163 {
164 return directed_;
165 }
166
167 std::string property(const std::string &prop) const;
168
169 /** Get property converted to float.
170 * @param prop property key
171 * @return property value
172 */
173 float
174 property_as_float(const std::string &prop)
175 {
177 }
178
179 /** Get property converted to int.
180 * @param prop property key
181 * @return property value
182 */
183 int
184 property_as_int(const std::string &prop)
185 {
187 }
188
189 /** Get property converted to bol.
190 * @param prop property key
191 * @return property value
192 */
193 bool
194 property_as_bool(const std::string &prop)
195 {
197 }
198
199 /** Check edges for equality.
200 * Edges are equal if they have the same origination and destination
201 * nodes and the same directed status.
202 * @param e edge to compare with
203 * @return true if the node is the same as this one, false otherwise
204 */
205 bool
206 operator==(const NavGraphEdge &e) const
207 {
208 return from_ == e.from_ && to_ == e.to_ && directed_ == e.directed_;
209 }
210
211 /** Less than operator based on node from and to names.
212 * One edge is less than another if this is true for their respective names.
213 * @param e edge to compare with
214 * @return true if this edge is less than the given one
215 */
216 bool
217 operator<(const NavGraphEdge &e) const
218 {
219 return (from_ == e.from_ && to_ < e.to_) || (from_ < e.from_);
220 }
221
222 /** Check of edge is valid.
223 * An edge is valid if both the originating and the target node
224 * name is set to a non-empty string.
225 * @return true if the node is valid, false otherwise
226 */
227 operator bool() const
228 {
229 return from_ != "" && to_ != "";
230 }
231
233
234private:
235 std::string from_;
236 std::string to_;
237 bool directed_;
238 std::map<std::string, std::string> properties_;
239
240 NavGraphNode from_node_;
241 NavGraphNode to_node_;
242};
243
244} // end of namespace fawkes
245
246#endif
Topological graph edge.
Definition: navgraph_edge.h:38
bool property_as_bool(const std::string &prop)
Get property converted to bol.
bool has_property(const std::string &property) const
Check if node has specified property.
bool operator<(const NavGraphEdge &e) const
Less than operator based on node from and to names.
float property_as_float(const std::string &prop) const
Get property converted to float.
float distance(float x, float y) const
Get distance of point to closest point on edge.
NavGraphEdge()
Constructor for an invalid edge.
bool is_directed() const
Check if edge is directed.
void set_property(const std::string &property, const std::string &value)
Set property.
bool operator==(const NavGraphEdge &e) const
Check edges for equality.
bool intersection(float x1, float y1, float x2, float y2, fawkes::cart_coord_2d_t &ip) const
Check if the edge intersects with another line segment.
int property_as_int(const std::string &prop) const
Get property converted to int.
const std::string & to() const
Get edge target node name.
Definition: navgraph_edge.h:62
void set_nodes(const NavGraphNode &from_node, const NavGraphNode &to_node)
Set nodes.
bool property_as_bool(const std::string &prop) const
Get property converted to bol.
float property_as_float(const std::string &prop)
Get property converted to float.
fawkes::cart_coord_2d_t closest_point_on_edge(float x, float y) const
Get the point on edge closest to a given point.
void set_from(const std::string &from)
Set originating node name.
const std::map< std::string, std::string > & properties() const
Get all properties.
Definition: navgraph_edge.h:96
const std::string & from() const
Get edge originating node name.
Definition: navgraph_edge.h:54
bool is_valid() const
Check if edge is valid.
bool intersects(float x1, float y1, float x2, float y2) const
Check if the edge intersects with another line segment.
int property_as_int(const std::string &prop)
Get property converted to int.
void set_properties(const std::map< std::string, std::string > &properties)
Overwrite properties with given ones.
const NavGraphNode & from_node() const
Get edge originating node.
Definition: navgraph_edge.h:70
void set_to(const std::string &to)
Set target node name.
std::string property(const std::string &prop) const
Get specified property as string.
void set_directed(bool directed)
Set directed state.
const NavGraphNode & to_node() const
Get edge target node.
Definition: navgraph_edge.h:78
Topological graph node.
Definition: navgraph_node.h:36
Topological map graph.
Definition: navgraph.h:50
static float to_float(std::string s)
Convert string to a float value.
static bool to_bool(std::string s)
Convert string to a bool value.
static int to_int(std::string s)
Convert string to an int value.
Fawkes library namespace.
Cartesian coordinates (2D).
Definition: types.h:65