Fawkes API
Fawkes Development Version
|
Class representing a path for a NavGraph. More...
#include <>>
Classes | |
class | Traversal |
Sub-class representing a navgraph path traversal. More... | |
Public Member Functions | |
NavGraphPath () | |
Default constructor. More... | |
NavGraphPath (const NavGraph *graph, std::vector< NavGraphNode > &nodes, float cost=-1) | |
Constructor. More... | |
void | add_node (const NavGraphNode &node, float cost_from_end=0) |
Add a node to the path. More... | |
void | set_nodes (const std::vector< NavGraphNode > &nodes, float cost=-1) |
Set nodes erasing the current path. More... | |
const NavGraph & | graph () const |
Get graph this path is based on. More... | |
const NavGraphNode & | goal () const |
Get goal of path. More... | |
std::string | get_path_as_string (const char delim=':') const |
Get string representation of path. More... | |
std::vector< std::string > | get_node_names () const |
Get names of nodes in path. More... | |
const std::vector< NavGraphNode > & | nodes () const |
Get nodes along the path. More... | |
std::vector< NavGraphNode > & | nodes_mutable () |
Get nodes along the path as mutable vector. More... | |
bool | contains (const NavGraphNode &node) const |
Check if the path contains a given node. More... | |
bool | empty () const |
Check if path is empty. More... | |
size_t | size () const |
Get size of path. More... | |
void | clear () |
Clear all nodes on this path. More... | |
Traversal | traversal () const |
Get a new path traversal handle. More... | |
float | cost () const |
Get cost of path from start to to end. More... | |
bool | operator< (const NavGraphPath &p) const |
Check if this path is cheaper than the other path. More... | |
bool | operator== (const NavGraphPath &p) const |
Check if two paths are the same. More... | |
Class representing a path for a NavGraph.
A path is a consecutive sequence of nodes, where each node is either the first node in the path or reachable by its predecessor. A path may or may not specify a total cost. If the value is unavailable it shall be less than zero. If positive, the cost is valid. The unit of the cost is not specified but depends on the search metrics used to determine the path. Make sure to only compare paths that have been created with the same metrics.
Definition at line 39 of file navgraph_path.h.
fawkes::NavGraphPath::NavGraphPath | ( | ) |
fawkes::NavGraphPath::NavGraphPath | ( | const NavGraph * | graph, |
std::vector< NavGraphNode > & | nodes, | ||
float | cost = -1 |
||
) |
Constructor.
graph | navgraph this path is based on |
nodes | nodes that the path should follow. The nodes must build a sequence where each node is directly reachable from its predecessor. This is not verified internally. |
cost | cost of the path, set to a value less than zero if unknown |
Definition at line 65 of file navgraph_path.cpp.
void fawkes::NavGraphPath::add_node | ( | const NavGraphNode & | node, |
float | cost_from_end = 0 |
||
) |
Add a node to the path.
The node must be reachable directly from the last node in the path (not verified internally) or the first node.
node | node to add to the path |
cost_from_end | cost to the node from the current end of the path. It is added to the current total cost. The value is ignored if it is less than zero. |
Definition at line 122 of file navgraph_path.cpp.
Referenced by NavGraphThread::loop(), and fawkes::NavGraphPath::Traversal::operator bool().
void fawkes::NavGraphPath::clear | ( | void | ) |
Clear all nodes on this path.
This sets the length of the path to zero and cost to unknown.
Definition at line 171 of file navgraph_path.cpp.
Referenced by nodes_mutable().
bool fawkes::NavGraphPath::contains | ( | const NavGraphNode & | node | ) | const |
Check if the path contains a given node.
node | node to check for in current path |
Definition at line 183 of file navgraph_path.cpp.
Referenced by NavGraphVisualizationThread::loop(), and nodes_mutable().
|
inline |
Get cost of path from start to to end.
The cost depends on the metrics used during path search. It's unit could be arbitrary, for example distance, required travel time, or some generalized number. Costs are mainly useful for comparison of paths. But make sure that the very same metrics were used to generate the path.
Definition at line 121 of file navgraph_path.h.
References operator<(), and operator==().
Referenced by NavGraphThread::loop(), fawkes::NavGraphPath::Traversal::operator bool(), fawkes::NavGraphPath::Traversal::remaining_cost(), and set_nodes().
bool fawkes::NavGraphPath::empty | ( | ) | const |
Check if path is empty.
Definition at line 151 of file navgraph_path.cpp.
Referenced by NavGraphVisualizationThread::loop(), NavGraphThread::loop(), and nodes_mutable().
std::vector< std::string > fawkes::NavGraphPath::get_node_names | ( | ) | const |
Get names of nodes in path.
Definition at line 446 of file navgraph_path.cpp.
References nodes().
Referenced by get_path_as_string(), and fawkes::NavGraphPath::Traversal::operator bool().
std::string fawkes::NavGraphPath::get_path_as_string | ( | const char | delim = ':' | ) | const |
Get string representation of path.
delim | custom delimiter |
Definition at line 437 of file navgraph_path.cpp.
References get_node_names(), and fawkes::str_join().
Referenced by fawkes::NavGraphPath::Traversal::operator bool().
const NavGraphNode & fawkes::NavGraphPath::goal | ( | ) | const |
Get goal of path.
Exeption | if there are no nodes in this path |
Definition at line 194 of file navgraph_path.cpp.
Referenced by NavGraphThread::fam_event(), NavGraphVisualizationThread::loop(), NavGraphThread::loop(), and fawkes::NavGraphPath::Traversal::operator bool().
const NavGraph & fawkes::NavGraphPath::graph | ( | ) | const |
Get graph this path is based on.
Definition at line 208 of file navgraph_path.cpp.
Referenced by fawkes::NavGraphPath::Traversal::operator bool().
|
inline |
Get nodes along the path.
Definition at line 94 of file navgraph_path.h.
Referenced by NavGraphThread::fam_event(), get_node_names(), NavGraphVisualizationThread::loop(), NavGraphThread::loop(), fawkes::NavGraphPath::Traversal::operator bool(), and set_nodes().
|
inline |
Get nodes along the path as mutable vector.
Use this with caution. Modifying the nodes invalidates any running traversal.
Definition at line 102 of file navgraph_path.h.
References clear(), contains(), empty(), size(), and traversal().
Referenced by NavGraphThread::loop().
bool fawkes::NavGraphPath::operator< | ( | const NavGraphPath & | p | ) | const |
Check if this path is cheaper than the other path.
If both paths have negative costs (the cost is unknown), then they are considered to be equal. Only if both cost values are positive are they compared.
p | path to compare to |
Definition at line 81 of file navgraph_path.cpp.
Referenced by cost().
bool fawkes::NavGraphPath::operator== | ( | const NavGraphPath & | p | ) | const |
Check if two paths are the same.
Two paths are the same iff they contain the same nodes in the exact same order and if they have the same cost (within a small epsilon of 0.00001 and only if both costs are positive). Costs are ignored should any of the two cost values be less than zero (unknown).
p | path to compare to |
Definition at line 99 of file navgraph_path.cpp.
Referenced by cost().
void fawkes::NavGraphPath::set_nodes | ( | const std::vector< NavGraphNode > & | nodes, |
float | cost = -1 |
||
) |
Set nodes erasing the current path.
nodes | nodes that the path should follow. The nodes must build a sequence where each node is directly reachable from its predecessor. This is not verified internally. This also invalidates any running traversal. |
cost | cost of the path, set to a value less than zero if unknown |
Definition at line 139 of file navgraph_path.cpp.
References cost(), and nodes().
Referenced by fawkes::NavGraphPath::Traversal::operator bool().
size_t fawkes::NavGraphPath::size | ( | ) | const |
Get size of path.
Definition at line 161 of file navgraph_path.cpp.
Referenced by NavGraphThread::fam_event(), NavGraphVisualizationThread::loop(), NavGraphThread::loop(), and nodes_mutable().
NavGraphPath::Traversal fawkes::NavGraphPath::traversal | ( | ) | const |
Get a new path traversal handle.
Definition at line 218 of file navgraph_path.cpp.
Referenced by NavGraphThread::loop(), and nodes_mutable().