Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Menge::NavMeshLocalizer Class Reference

Class responsible for tracking agent relatinoships to the navigation mesh: its current location and its path. More...

#include <NavMeshLocalizer.h>

Inheritance diagram for Menge::NavMeshLocalizer:
Menge::Resource

Public Member Functions

 NavMeshLocalizer (const std::string &name)
 Constructor. More...
 
virtual const std::string & getLabel () const
 Returns a unique resource label to be used to identify different resource types which use the same underlying file data.
 
unsigned int getNode (const Agents::BaseAgent *agent) const
 Reports the node the agent is currently in. More...
 
unsigned int getNode (const Vector2 &p) const
 Reports the node with the highest elevation for the given point. More...
 
const NavMeshNode getNode (unsigned int i)
 Returns the NavMeshNode of the given id. More...
 
PortalPathgetPath (size_t id)
 Retrieves the path for the given agent. More...
 
void setPath (size_t agentID, PortalPath *path)
 Sets the path for the given agent. More...
 
void clearPath (size_t agentID)
 Clears the path for the given agent. More...
 
void setNode (size_t agentID, unsigned int nodeID)
 Sets the location of the agent to be anode. More...
 
void setTrackAll ()
 Sets the tracking status of the localizer to all agents. More...
 
unsigned int updateLocation (const Agents::BaseAgent *agent, bool force=false) const
 Updates the location of the agent relative to the nav mesh. More...
 
void setPlanner (PathPlanner *planner)
 Set the path planner for the localizer. More...
 
PathPlannergetPlanner ()
 Get the planner for the localizer. More...
 
const OccupantSetgetNodeOccupants (unsigned int nodeID) const
 Returns the occupant set for the given node. More...
 
const NavMeshPtr getNavMesh () const
 Returns a const pointer to the underlying navigation mesh. More...
 
NavMeshPtr getNavMesh ()
 Returns a pointer to the underlying navigation mesh. More...
 
- Public Member Functions inherited from Menge::Resource
 Resource (const std::string &fileName)
 Constructor. More...
 
void destroy ()
 This supplants the destructor. More...
 
const std::string & getName () const
 Return the file name for this resource. More...
 
int incRef ()
 Increment references to the managed data. More...
 
int decRef ()
 Decrement references to the managed data. More...
 
bool isUnreferenced () const
 Reports if the data is referenced. More...
 

Static Public Member Functions

static Resourceload (const std::string &fileName)
 Parses a navigation mesh localizer definition and returns a pointer to it. More...
 

Static Public Attributes

static const std::string LABEL
 The unique label for this data type to be used with resource management.
 

Protected Member Functions

 ~NavMeshLocalizer ()
 Destructor.
 
unsigned int findNodeBlind (const Vector2 &p, float tgtElev=1e5f) const
 Determines which node an agent is in without previous knowledge. More...
 
unsigned int testNeighbors (const NavMeshNode &node, const Vector2 &p) const
 Determines if the point is in a neighboring node to the given node. More...
 
- Protected Member Functions inherited from Menge::Resource
virtual ~Resource ()
 Virtual destructor.
 

Protected Attributes

NavMeshPtr _navMesh
 The underlying navigation mesh to perform operations on.
 
bool _trackAll
 Determines if just the position of agents on paths is tracked (true) or the position of all agents (false).
 
PathPlanner_planner
 Optional planner. This is only non-NULL if there is a PathPlanner created either by a NavMeshGoalGenerator or NavMeshVelComponent.
 
HASH_MAP< size_t, NavMeshLocation_locations
 A mapping from agent id to the agent's location w.r.t. the navigation mesh.
 
ReadersWriterLock _locLock
 Lock for location map (_locations).
 
OccupantSet_nodeOccupants
 A mapping from node id to agent ids, specifying the population of each agent.
 
- Protected Attributes inherited from Menge::Resource
const std::string _fileName
 The file which contains the resource's data.
 
int _refCount
 The number of data wrappers using this managed data.
 
SimpleLock _lock
 Simple lock to handle reference counts safely.
 

Friends

class PortalPath
 

Detailed Description

Class responsible for tracking agent relatinoships to the navigation mesh: its current location and its path.

Constructor & Destructor Documentation

Menge::NavMeshLocalizer::NavMeshLocalizer ( const std::string &  name)

Constructor.

Parameters
nameThe name of the underlying navigation mesh.

Member Function Documentation

void Menge::NavMeshLocalizer::clearPath ( size_t  agentID)

Clears the path for the given agent.

Parameters
agentIDThe index of the agent whose path is to be cleared.
unsigned int Menge::NavMeshLocalizer::findNodeBlind ( const Vector2 p,
float  tgtElev = 1e5f 
) const
protected

Determines which node an agent is in without previous knowledge.

Parameters
pGiven the initial position, returns the node this point lies on (with the highest elevation).
tgtElevThe target elevation for the agent. The default value leads to the highest node being selected. But giving an alternative value will change it to select a node nearest the current elevation.
Returns
The index of the node on which the point lies closest in elevation. to the tgtElev value. If the point does not lie on any mesh node, NavMeshLocation::NO_NODE is returned.
const NavMeshPtr Menge::NavMeshLocalizer::getNavMesh ( ) const
inline

Returns a const pointer to the underlying navigation mesh.

Returns
The pointer to the navigation mesh.
NavMeshPtr Menge::NavMeshLocalizer::getNavMesh ( )
inline

Returns a pointer to the underlying navigation mesh.

Returns
The pointer to the navigation mesh.
unsigned int Menge::NavMeshLocalizer::getNode ( const Agents::BaseAgent agent) const

Reports the node the agent is currently in.

Parameters
agentThe agent whose position relative to the nav mesh is returned.
Returns
The index of the node associated with this location. If the location is not on a node, NavMeshLocation::NO_NODE is returned.
unsigned int Menge::NavMeshLocalizer::getNode ( const Vector2 p) const

Reports the node with the highest elevation for the given point.

Parameters
pThe point to test against the mesh.
Returns
The index of the node associated with this location. If the location is not on a node, NavMeshLocation::NO_NODE is returned.
const NavMeshNode Menge::NavMeshLocalizer::getNode ( unsigned int  i)
inline

Returns the NavMeshNode of the given id.

Parameters
iThe index of the desired mesh node.
Returns
A copy the specified mesh node.
const OccupantSet* Menge::NavMeshLocalizer::getNodeOccupants ( unsigned int  nodeID) const
inline

Returns the occupant set for the given node.

Parameters
nodeIDThe index of the desired node.
Returns
A pointer to the OccupantSet of the given node.
PortalPath * Menge::NavMeshLocalizer::getPath ( size_t  id)

Retrieves the path for the given agent.

Parameters
idThe identifier for the agent.
Returns
A pointer to the PortalPath for the agent. If the agent is not currently following a path, NULL is returned.
PathPlanner* Menge::NavMeshLocalizer::getPlanner ( )
inline

Get the planner for the localizer.

Returns
A pointer to the planner
Resource * Menge::NavMeshLocalizer::load ( const std::string &  fileName)
static

Parses a navigation mesh localizer definition and returns a pointer to it.

This function works in conjunction with the ResourceManager. That is why it returns a pointer, not to a NavMeshLocalizer, but to a Resource. The ResourceManager uses it to load and instantiate NavMeshLocalizer instances.

Parameters
fileNameThe path to the file containing the NavMesh definition.
Returns
A pointer to the new NavMeshLocalizer (if the file is valid), NULL if invalid.
void Menge::NavMeshLocalizer::setNode ( size_t  agentID,
unsigned int  nodeID 
)

Sets the location of the agent to be anode.

Parameters
agentIDThe index of the agent to update.
nodeIDThe index of the node.
void Menge::NavMeshLocalizer::setPath ( size_t  agentID,
PortalPath path 
)

Sets the path for the given agent.

Parameters
agentIDThe index of the agent for whom the path is set.
pathThe path for the agent.
void Menge::NavMeshLocalizer::setPlanner ( PathPlanner planner)
inline

Set the path planner for the localizer.

Parameters
plannerThe path planner.
void Menge::NavMeshLocalizer::setTrackAll ( )
inline

Sets the tracking status of the localizer to all agents.

By default, the localizer only tracks agents on paths. Calling this function will cause all agents to be tracked, even if they are not currently following navigation mesh paths. However, it can't be set back.

unsigned int Menge::NavMeshLocalizer::testNeighbors ( const NavMeshNode node,
const Vector2 p 
) const
protected

Determines if the point is in a neighboring node to the given node.

Parameters
nodeThe navigation mesh node whose neighbors need to be tested.
pThe point to test against the neighboring nodes.
Returns
The index of the neighboring node which contains p. If p does not lie on any neighboring mesh node, NavMeshLocation::NO_NODE is returned.
unsigned int Menge::NavMeshLocalizer::updateLocation ( const Agents::BaseAgent agent,
bool  force = false 
) const

Updates the location of the agent relative to the nav mesh.

Parameters
agentThe agent whose location is updated.
forceForce causes the update regardless of whether the localizer is set to track all or not.
Returns
The index of the node in which the agent is found. If it is not on the navigation mesh, NavMeshLocation::NO_NODE is returned.

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