Fawkes API  Fawkes Development Version
fawkes::NavGraphPath Class Reference

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 NavGraphgraph () const
 Get graph this path is based on. More...
 
const NavGraphNodegoal () 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...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 39 of file navgraph_path.h.

Constructor & Destructor Documentation

◆ NavGraphPath() [1/2]

fawkes::NavGraphPath::NavGraphPath ( )

Default constructor.

Creates an invalid path.

Definition at line 51 of file navgraph_path.cpp.

◆ NavGraphPath() [2/2]

fawkes::NavGraphPath::NavGraphPath ( const NavGraph graph,
std::vector< NavGraphNode > &  nodes,
float  cost = -1 
)

Constructor.

Parameters
graphnavgraph this path is based on
nodesnodes 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.
costcost of the path, set to a value less than zero if unknown

Definition at line 65 of file navgraph_path.cpp.

Member Function Documentation

◆ add_node()

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.

Parameters
nodenode to add to the path
cost_from_endcost 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().

◆ clear()

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().

◆ contains()

bool fawkes::NavGraphPath::contains ( const NavGraphNode node) const

Check if the path contains a given node.

Parameters
nodenode to check for in current path
Returns
true if the node is contained in the current path, false otherwise

Definition at line 183 of file navgraph_path.cpp.

Referenced by NavGraphVisualizationThread::loop(), and nodes_mutable().

◆ cost()

float fawkes::NavGraphPath::cost ( ) const
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.

Returns
cost of the path, or a value less than zero if cost is not known

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().

◆ empty()

bool fawkes::NavGraphPath::empty ( ) const

Check if path is empty.

Returns
true if path is empty, i.e. it has no nodes at all, false otherwise.

Definition at line 151 of file navgraph_path.cpp.

Referenced by NavGraphVisualizationThread::loop(), NavGraphThread::loop(), and nodes_mutable().

◆ get_node_names()

std::vector< std::string > fawkes::NavGraphPath::get_node_names ( ) const

Get names of nodes in path.

Returns
vector of strings for all nodes

Definition at line 446 of file navgraph_path.cpp.

References nodes().

Referenced by get_path_as_string(), and fawkes::NavGraphPath::Traversal::operator bool().

◆ get_path_as_string()

std::string fawkes::NavGraphPath::get_path_as_string ( const char  delim = ':') const

Get string representation of path.

Parameters
delimcustom delimiter
Returns
all nodes of the path in one string

Definition at line 437 of file navgraph_path.cpp.

References get_node_names(), and fawkes::str_join().

Referenced by fawkes::NavGraphPath::Traversal::operator bool().

◆ goal()

const NavGraphNode & fawkes::NavGraphPath::goal ( ) const

Get goal of path.

Returns
goal of this path, i.e. the last node in the sequence of nodes.
Exceptions
Exeptionif 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().

◆ graph()

const NavGraph & fawkes::NavGraphPath::graph ( ) const

Get graph this path is based on.

Returns
const reference to graph this path is based on

Definition at line 208 of file navgraph_path.cpp.

Referenced by fawkes::NavGraphPath::Traversal::operator bool().

◆ nodes()

const std::vector<NavGraphNode>& fawkes::NavGraphPath::nodes ( ) const
inline

Get nodes along the path.

Returns
sequence of nodes that compose 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().

◆ nodes_mutable()

std::vector<NavGraphNode>& fawkes::NavGraphPath::nodes_mutable ( )
inline

Get nodes along the path as mutable vector.

Use this with caution. Modifying the nodes invalidates any running traversal.

Returns
sequence of nodes that compose the path

Definition at line 102 of file navgraph_path.h.

References clear(), contains(), empty(), size(), and traversal().

Referenced by NavGraphThread::loop().

◆ operator<()

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.

Parameters
ppath to compare to
Returns
true if this path is cheaper in terms of cost than the other path, false if both costs are negative or the other path is cheaper.

Definition at line 81 of file navgraph_path.cpp.

Referenced by cost().

◆ operator==()

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).

Parameters
ppath to compare to
Returns
true if the paths are the same by the definition above, false otherwise.

Definition at line 99 of file navgraph_path.cpp.

Referenced by cost().

◆ set_nodes()

void fawkes::NavGraphPath::set_nodes ( const std::vector< NavGraphNode > &  nodes,
float  cost = -1 
)

Set nodes erasing the current path.

Parameters
nodesnodes 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.
costcost 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()

size_t fawkes::NavGraphPath::size ( ) const

Get size of path.

Returns
number of nodes in path

Definition at line 161 of file navgraph_path.cpp.

Referenced by NavGraphThread::fam_event(), NavGraphVisualizationThread::loop(), NavGraphThread::loop(), and nodes_mutable().

◆ traversal()

NavGraphPath::Traversal fawkes::NavGraphPath::traversal ( ) const

Get a new path traversal handle.

Returns
new path traversal handle

Definition at line 218 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop(), and nodes_mutable().


The documentation for this class was generated from the following files: