Fawkes API Fawkes Development Version
navgraph_node.h
1
2/***************************************************************************
3 * navgraph_node.h - Topological graph node
4 *
5 * Created: Fri Sep 21 16:01:26 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_NODE_H_
24#define _UTILS_GRAPH_TOPOLOGICAL_MAP_NODE_H_
25
26#include <utils/misc/string_conversions.h>
27
28#include <cmath>
29#include <map>
30#include <string>
31#include <vector>
32
33namespace fawkes {
34
36{
37public:
39
40 NavGraphNode(const std::string & name,
41 float x,
42 float y,
43 std::map<std::string, std::string> properties);
44
45 NavGraphNode(const std::string &name, float x, float y);
46
47 /** Get name of node.
48 * @return name of node */
49 const std::string &
50 name() const
51 {
52 return name_;
53 }
54
55 /** Get X coordinate in global frame.
56 * @return X coordinate in global frame */
57 float
58 x() const
59 {
60 return x_;
61 }
62
63 /** Get Y coordinate in global frame.
64 * @return Y coordinate in global frame */
65 float
66 y() const
67 {
68 return y_;
69 }
70
71 /** Check if this node shall be unconnected.
72 * @return true if the node is unconnected, false otherwise */
73 bool
75 {
76 return unconnected_;
77 }
78
79 void set_x(float x);
80 void set_y(float y);
81 void set_name(const std::string &name);
83
84 /** Get euclidean distance from this node to another.
85 * @param n node to get distance to
86 * @return distance */
87 float
89 {
90 return sqrtf(powf(x_ - n.x_, 2) + powf(y_ - n.y_, 2));
91 }
92
93 /** Get euclidean distance from this node to a point.
94 * @param x point X coordinate
95 * @param y point Y coordinate
96 * @return distance */
97 float
98 distance(float x, float y)
99 {
100 return sqrtf(powf(x_ - x, 2) + powf(y_ - y, 2));
101 }
102
103 /** Get all properties.
104 * @return property map
105 */
106 const std::map<std::string, std::string> &
108 {
109 return properties_;
110 }
111
112 /** Check if node has specified property.
113 * @param property property key
114 * @return true if node has specified property, false otherwise
115 */
116 bool
117 has_property(const std::string &property) const
118 {
119 return properties_.find(property) != properties_.end();
120 }
121
122 /** Check if node is valid, i.e. it has a name.
123 * @return true if node is valid, false otherwise
124 */
125 bool
126 is_valid() const
127 {
128 return name_ != "";
129 }
130
131 void set_properties(const std::map<std::string, std::string> &properties);
132 void set_property(const std::string &property, const std::string &value);
133 void set_property(const std::string &property, float value);
134 void set_property(const std::string &property, int value);
135 void set_property(const std::string &property, bool value);
136
137 std::string property(const std::string &prop) const;
138
139 /** Get property converted to float.
140 * @param prop property key
141 * @return property value
142 */
143 float
144 property_as_float(const std::string &prop) const
145 {
147 }
148
149 /** Get property converted to int.
150 * @param prop property key
151 * @return property value
152 */
153 int
154 property_as_int(const std::string &prop) const
155 {
157 }
158
159 /** Get property converted to bol.
160 * @param prop property key
161 * @return property value
162 */
163 bool
164 property_as_bool(const std::string &prop) const
165 {
167 }
168
169 /** Check nodes for equality.
170 * Nodes are equal if they have the same name.
171 * @param n node to compare with
172 * @return true if the node is the same as this one, false otherwise
173 */
174 bool
175 operator==(const NavGraphNode &n) const
176 {
177 return name_ == n.name_;
178 }
179
180 /** Check nodes for inequality.
181 * Nodes are inequal if they have different names.
182 * @param n node to compare with
183 * @return true if the node is different from this one, false otherwise
184 */
185 bool
186 operator!=(const NavGraphNode &n) const
187 {
188 return name_ != n.name_;
189 }
190
191 /** Check if node is valid.
192 * A node is valid if it has a name set.
193 * @return true if the node is valid, false otherwise
194 */
195 operator bool() const
196 {
197 return name_ != "";
198 }
199
200 void set_reachable_nodes(std::vector<std::string> reachable_nodes);
201
202 /** Get reachable nodes.
203 * @return vector of directly reachable nodes.
204 */
205 const std::vector<std::string> &
207 {
208 return reachable_nodes_;
209 }
210
211private:
212 std::string name_;
213 float x_;
214 float y_;
215 bool unconnected_;
216 std::map<std::string, std::string> properties_;
217 std::vector<std::string> reachable_nodes_;
218};
219
220} // end of namespace fawkes
221
222#endif
Topological graph node.
Definition: navgraph_node.h:36
float x() const
Get X coordinate in global frame.
Definition: navgraph_node.h:58
void set_x(float x)
Set X position.
std::string property(const std::string &prop) const
Get specified property as string.
float distance(float x, float y)
Get euclidean distance from this node to a point.
Definition: navgraph_node.h:98
void set_property(const std::string &property, const std::string &value)
Set property.
void set_name(const std::string &name)
Set name of node.
bool operator!=(const NavGraphNode &n) const
Check nodes for inequality.
bool property_as_bool(const std::string &prop) const
Get property converted to bol.
const std::map< std::string, std::string > & properties() const
Get all properties.
bool unconnected() const
Check if this node shall be unconnected.
Definition: navgraph_node.h:74
bool is_valid() const
Check if node is valid, i.e.
int property_as_int(const std::string &prop) const
Get property converted to int.
const std::string & name() const
Get name of node.
Definition: navgraph_node.h:50
NavGraphNode()
Constructor for invalid node.
void set_reachable_nodes(std::vector< std::string > reachable_nodes)
Set directly reachable nodes of node.
float distance(const NavGraphNode &n)
Get euclidean distance from this node to another.
Definition: navgraph_node.h:88
float property_as_float(const std::string &prop) const
Get property converted to float.
bool has_property(const std::string &property) const
Check if node has specified property.
float y() const
Get Y coordinate in global frame.
Definition: navgraph_node.h:66
void set_properties(const std::map< std::string, std::string > &properties)
Overwrite properties with given ones.
void set_unconnected(bool unconnected)
Set unconnected state of the node.
void set_y(float y)
Set Y position.
bool operator==(const NavGraphNode &n) const
Check nodes for equality.
const std::vector< std::string > & reachable_nodes() const
Get reachable nodes.
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.