23 #ifndef _LIBS_NAVGRAPH_NAVGRAPH_H_ 24 #define _LIBS_NAVGRAPH_NAVGRAPH_H_ 26 #include <core/utils/lockptr.h> 27 #include <navgraph/navgraph_edge.h> 28 #include <navgraph/navgraph_node.h> 29 #include <navgraph/navgraph_path.h> 44 extern const char *PROP_ORIENTATION;
47 class NavGraphConstraintRepo;
71 NavGraph(
const std::string &graph_name);
75 std::string
name()
const;
76 const std::vector<NavGraphNode> &
nodes()
const;
77 const std::vector<NavGraphEdge> &
edges()
const;
101 const std::string &property =
"")
const;
105 bool consider_unconnected,
106 const std::string &property =
"")
const;
109 bool consider_unconnected,
110 const std::string &property =
"")
const;
116 const std::string &property =
"")
const;
121 std::vector<NavGraphNode>
search_nodes(
const std::string &property)
const;
123 std::vector<std::string>
reachable_nodes(
const std::string &node_name)
const;
126 const std::string &to,
127 bool use_constraints =
true,
128 bool compute_constraints =
true);
131 const std::string & to,
132 navgraph::EstimateFunction estimate_func,
133 navgraph::CostFunction cost_func,
134 bool use_constraints =
true,
135 bool compute_constraints =
true);
139 bool use_constraints =
true,
140 bool compute_constraints =
true);
144 navgraph::EstimateFunction estimate_func,
145 navgraph::CostFunction cost_func,
146 bool use_constraints =
true,
147 bool compute_constraints =
true);
155 bool allow_existing =
false);
160 void remove_edge(
const std::string &from,
const std::string &to);
169 bool edge_exists(
const std::string &from,
const std::string &to)
const;
182 virtual void graph_changed()
throw() = 0;
195 return search_default_funcs_;
198 void set_search_funcs(navgraph::EstimateFunction estimate_func, navgraph::CostFunction cost_func);
204 static std::string
format_name(
const char *format, ...);
208 void assert_valid_edges();
209 void assert_connected();
214 std::string graph_name_;
215 std::vector<NavGraphNode> nodes_;
216 std::vector<NavGraphEdge> edges_;
218 std::list<ChangeListener *> change_listeners_;
219 std::map<std::string, std::string> default_properties_;
221 bool search_default_funcs_;
222 navgraph::EstimateFunction search_estimate_func_;
223 navgraph::CostFunction search_cost_func_;
225 bool reachability_calced_;
227 bool notifications_enabled_;
void add_node_and_connect(const NavGraphNode &node, ConnectionMode conn_mode)
Add a node and connect it to the graph.
NavGraphEdge closest_edge(float pos_x, float pos_y) const
Get edge closest to a specified point.
fawkes::LockPtr< NavGraphConstraintRepo > constraint_repo() const
Get locked pointer to constraint repository.
void remove_edge(const NavGraphEdge &edge)
Remove an edge.
float default_property_as_float(const std::string &prop) const
Get property converted to float.
bool default_property_as_bool(const std::string &prop) const
Get property converted to bol.
const std::map< std::string, std::string > & default_properties() const
Get all default properties.
Fawkes library namespace.
void set_default_property(const std::string &property, const std::string &value)
Set property.
void remove_node(const NavGraphNode &node)
Remove a node.
NavGraph & operator=(const NavGraph &g)
Assign/copy structures from another graph.
void set_default_properties(const std::map< std::string, std::string > &properties)
Set default properties.
void add_node(const NavGraphNode &node)
Add a node.
static std::string format_name(const char *format,...)
Create node name from a format string.
Class representing a path for a NavGraph.
fawkes::NavGraphPath search_path(const std::string &from, const std::string &to, bool use_constraints=true, bool compute_constraints=true)
Search for a path between two nodes with default distance costs.
std::vector< NavGraphNode > search_nodes(const std::string &property) const
Search nodes for given property.
bool edge_exists(const NavGraphEdge &edge) const
Check if a certain edge exists.
try to connect to closest edge, if that fails, connect to closest node
const std::vector< NavGraphNode > & nodes() const
Get nodes of the graph.
void add_change_listener(ChangeListener *listener)
Add a change listener.
std::vector< std::string > reachable_nodes(const std::string &node_name) const
Get nodes reachable from specified nodes.
LockPtr<> is a reference-counting shared lockable smartpointer.
void update_edge(const NavGraphEdge &edge)
Update a given edge.
void set_search_funcs(navgraph::EstimateFunction estimate_func, navgraph::CostFunction cost_func)
Set cost and cost estimation function for searching paths.
void update_node(const NavGraphNode &node)
Update a given node.
std::string name() const
Get graph name.
EdgeMode
Mode to use to add edges.
bool uses_default_search() const
Check if the default euclidean distance search is used.
void unset_search_funcs()
Reset actual and estimated cost function to defaults.
std::string gen_unique_name(const char *prefix="U-")
Generate a unique node name for the given prefix.
NavGraph(const std::string &graph_name)
Constructor.
void add_edge(const NavGraphEdge &edge, EdgeMode mode=EDGE_NO_INTERSECTION, bool allow_existing=false)
Add an edge.
void set_notifications_enabled(bool enabled)
Enable or disable notifications.
add nodes no matter what (be careful)
void remove_orphan_nodes()
Remove orphan nodes.
std::string default_property(const std::string &prop) const
Get specified default property as string.
Add the edge, but if it intersects with an existing edges add new points at the intersection points f...
void remove_change_listener(ChangeListener *listener)
Remove a change listener.
void connect_node_to_closest_edge(const NavGraphNode &n)
Connect node to closest edge.
NavGraphEdge edge(const std::string &from, const std::string &to) const
Get a specified edge.
NavGraphNode node(const std::string &name) const
Get a specified node.
bool node_exists(const NavGraphNode &node) const
Check if a certain node exists.
void clear()
Remove all nodes and edges from navgraph.
NavGraphNode closest_node_with_unconnected(float pos_x, float pos_y, const std::string &property="") const
Get node closest to a specified point with a certain property.
void apply_default_properties(NavGraphNode &node)
Set default properties on node for which no local value exists.
void notify_of_change()
Notify all listeners of a change.
const std::vector< NavGraphEdge > & edges() const
Get edges of the graph.
NavGraphNode closest_node(float pos_x, float pos_y, const std::string &property="") const
Get node closest to a specified point with a certain property.
int default_property_as_int(const std::string &prop) const
Get property converted to int.
Only add edge if it does not intersect.
NavGraphNode closest_node_to(const std::string &node_name, const std::string &property="") const
Get node closest to another node with a certain property.
virtual ~NavGraph()
Virtual empty destructor.
bool has_default_property(const std::string &property) const
Check if graph has specified default property.
Topological graph change listener.
ConnectionMode
Connect mode enum for connect_node_* methods.
void calc_reachability(bool allow_multi_graph=false)
Calculate eachability relations.
void connect_node_to_closest_node(const NavGraphNode &n)
Connect node to closest node.
NavGraphNode closest_node_to_with_unconnected(const std::string &node_name, const std::string &property="") const
Get node closest to another node with a certain property.
float cost(const NavGraphNode &from, const NavGraphNode &to) const
Calculate cost between two adjacent nodes.