Public Member Functions

RVO::RVOSimulator Class Reference

Defines the simulation. More...

#include <RVOSimulator.h>

List of all members.

Public Member Functions

 RVOSimulator ()
 Constructs a simulator instance.
 RVOSimulator (float timeStep, float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Constructs a simulator instance and sets the default properties for any new agent that is added.
 ~RVOSimulator ()
 Destroys this simulator instance.
size_t addAgent (const Vector2 &position)
 Adds a new agent with default properties to the simulation.
size_t addAgent (const Vector2 &position, float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Adds a new agent to the simulation.
size_t addObstacle (const std::vector< Vector2 > &vertices)
 Adds a new obstacle to the simulation.
void doStep ()
 Lets the simulator perform a simulation step and updates the two-dimensional position and two-dimensional velocity of each agent.
size_t getAgentAgentNeighbor (size_t agentNo, size_t neighborNo) const
 Returns the specified agent neighbor of the specified agent.
size_t getAgentMaxNeighbors (size_t agentNo) const
 Returns the maximum neighbor count of a specified agent.
float getAgentMaxSpeed (size_t agentNo) const
 Returns the maximum speed of a specified agent.
float getAgentNeighborDist (size_t agentNo) const
 Returns the maximum neighbor distance of a specified agent.
size_t getAgentNumAgentNeighbors (size_t agentNo) const
 Returns the count of agent neighbors taken into account to compute the current velocity for the specified agent.
size_t getAgentNumObstacleNeighbors (size_t agentNo) const
 Returns the count of obstacle neighbors taken into account to compute the current velocity for the specified agent.
size_t getAgentNumORCALines (size_t agentNo) const
 Returns the count of ORCA constraints used to compute the current velocity for the specified agent.
size_t getAgentObstacleNeighbor (size_t agentNo, size_t neighborNo) const
 Returns the specified obstacle neighbor of the specified agent.
const LinegetAgentORCALine (size_t agentNo, size_t lineNo) const
 Returns the specified ORCA constraint of the specified agent.
const Vector2getAgentPosition (size_t agentNo) const
 Returns the two-dimensional position of a specified agent.
const Vector2getAgentPrefVelocity (size_t agentNo) const
 Returns the two-dimensional preferred velocity of a specified agent.
float getAgentRadius (size_t agentNo) const
 Returns the radius of a specified agent.
float getAgentTimeHorizon (size_t agentNo) const
 Returns the time horizon of a specified agent.
float getAgentTimeHorizonObst (size_t agentNo) const
 Returns the time horizon with respect to obstacles of a specified agent.
const Vector2getAgentVelocity (size_t agentNo) const
 Returns the two-dimensional linear velocity of a specified agent.
float getGlobalTime () const
 Returns the global time of the simulation.
size_t getNextObstacleVertexNo (size_t vertexNo) const
 Returns the number of the obstacle vertex succeeding the specified obstacle vertex in its polygon.
size_t getNumAgents () const
 Returns the count of agents in the simulation.
size_t getNumObstacleVertices () const
 Returns the count of obstacle vertices in the simulation.
const Vector2getObstacleVertex (size_t vertexNo) const
 Returns the two-dimensional position of a specified obstacle vertex.
size_t getPrevObstacleVertexNo (size_t vertexNo) const
 Returns the number of the obstacle vertex preceding the specified obstacle vertex in its polygon.
float getTimeStep () const
 Returns the time step of the simulation.
void processObstacles ()
 Processes the obstacles that have been added so that they are accounted for in the simulation.
bool queryVisibility (const Vector2 &point1, const Vector2 &point2, float radius=0.0f) const
 Performs a visibility query between the two specified points with respect to the obstacles.
void setAgentDefaults (float neighborDist, size_t maxNeighbors, float timeHorizon, float timeHorizonObst, float radius, float maxSpeed, const Vector2 &velocity=Vector2())
 Sets the default properties for any new agent that is added.
void setAgentMaxNeighbors (size_t agentNo, size_t maxNeighbors)
 Sets the maximum neighbor count of a specified agent.
void setAgentMaxSpeed (size_t agentNo, float maxSpeed)
 Sets the maximum speed of a specified agent.
void setAgentNeighborDist (size_t agentNo, float neighborDist)
 Sets the maximum neighbor distance of a specified agent.
void setAgentPosition (size_t agentNo, const Vector2 &position)
 Sets the two-dimensional position of a specified agent.
void setAgentPrefVelocity (size_t agentNo, const Vector2 &prefVelocity)
 Sets the two-dimensional preferred velocity of a specified agent.
void setAgentRadius (size_t agentNo, float radius)
 Sets the radius of a specified agent.
void setAgentTimeHorizon (size_t agentNo, float timeHorizon)
 Sets the time horizon of a specified agent with respect to other agents.
void setAgentTimeHorizonObst (size_t agentNo, float timeHorizonObst)
 Sets the time horizon of a specified agent with respect to obstacles.
void setAgentVelocity (size_t agentNo, const Vector2 &velocity)
 Sets the two-dimensional linear velocity of a specified agent.
void setTimeStep (float timeStep)
 Sets the time step of the simulation.

Detailed Description

Defines the simulation.

The main class of the library that contains all simulation functionality.


Constructor & Destructor Documentation

RVO::RVOSimulator::RVOSimulator (  ) 

Constructs a simulator instance.

RVO::RVOSimulator::RVOSimulator ( float  timeStep,
float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Constructs a simulator instance and sets the default properties for any new agent that is added.

Parameters:
timeStep The time step of the simulation. Must be positive.
neighborDist The default maximal distance (center point to center point) to other agents a new agent takes into account in the navigation. The larger this number, the longer he running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighbors The default maximal number of other agents a new agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizon The default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner an agent will respond to the presence of other agents, but the less freedom the agent has in choosing its velocities. Must be positive.
timeHorizonObst The default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner an agent will respond to the presence of obstacles, but the less freedom the agent has in choosing its velocities. Must be positive.
radius The default radius of a new agent. Must be non-negative.
maxSpeed The default maximal speed of a new agent. Must be non-negative.
velocity The default initial two-dimensional linear velocity of a new agent (optional).
RVO::RVOSimulator::~RVOSimulator (  ) 

Destroys this simulator instance.


Member Function Documentation

size_t RVO::RVOSimulator::addAgent ( const Vector2 position  ) 

Adds a new agent with default properties to the simulation.

Parameters:
position The two-dimensional starting position of this agent.
Returns:
The number of the agent, or RVO::RVO_ERROR when the agent defaults have not been set.
size_t RVO::RVOSimulator::addAgent ( const Vector2 position,
float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Adds a new agent to the simulation.

Parameters:
position The two-dimensional starting position of this agent.
neighborDist The maximal distance (center point to center point) to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighbors The maximal number of other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizon The minimal amount of time for which this agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner this agent will respond to the presence of other agents, but the less freedom this agent has in choosing its velocities. Must be positive.
timeHorizonObst The minimal amount of time for which this agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner this agent will respond to the presence of obstacles, but the less freedom this agent has in choosing its velocities. Must be positive.
radius The radius of this agent. Must be non-negative.
maxSpeed The maximal speed of this agent. Must be non-negative.
velocity The initial two-dimensional linear velocity of this agent (optional).
Returns:
The number of the agent.
size_t RVO::RVOSimulator::addObstacle ( const std::vector< Vector2 > &  vertices  ) 

Adds a new obstacle to the simulation.

Parameters:
vertices List of the vertices of the polygonal obstacle in counterclockwise order.
Returns:
The number of the first vertex of the obstacle, or RVO::RVO_ERROR when the number of vertices is less than two.
Note:
To add a "negative" obstacle, e.g. a bounding polygon around the environment, the vertices should be listed in clockwise order.
void RVO::RVOSimulator::doStep (  ) 

Lets the simulator perform a simulation step and updates the two-dimensional position and two-dimensional velocity of each agent.

size_t RVO::RVOSimulator::getAgentAgentNeighbor ( size_t  agentNo,
size_t  neighborNo 
) const

Returns the specified agent neighbor of the specified agent.

Parameters:
agentNo The number of the agent whose agent neighbor is to be retrieved.
neighborNo The number of the agent neighbor to be retrieved.
Returns:
The number of the neighboring agent.
size_t RVO::RVOSimulator::getAgentMaxNeighbors ( size_t  agentNo  )  const

Returns the maximum neighbor count of a specified agent.

Parameters:
agentNo The number of the agent whose maximum neighbor count is to be retrieved.
Returns:
The present maximum neighbor count of the agent.
float RVO::RVOSimulator::getAgentMaxSpeed ( size_t  agentNo  )  const

Returns the maximum speed of a specified agent.

Parameters:
agentNo The number of the agent whose maximum speed is to be retrieved.
Returns:
The present maximum speed of the agent.
float RVO::RVOSimulator::getAgentNeighborDist ( size_t  agentNo  )  const

Returns the maximum neighbor distance of a specified agent.

Parameters:
agentNo The number of the agent whose maximum neighbor distance is to be retrieved.
Returns:
The present maximum neighbor distance of the agent.
size_t RVO::RVOSimulator::getAgentNumAgentNeighbors ( size_t  agentNo  )  const

Returns the count of agent neighbors taken into account to compute the current velocity for the specified agent.

Parameters:
agentNo The number of the agent whose count of agent neighbors is to be retrieved.
Returns:
The count of agent neighbors taken into account to compute the current velocity for the specified agent.
size_t RVO::RVOSimulator::getAgentNumObstacleNeighbors ( size_t  agentNo  )  const

Returns the count of obstacle neighbors taken into account to compute the current velocity for the specified agent.

Parameters:
agentNo The number of the agent whose count of obstacle neighbors is to be retrieved.
Returns:
The count of obstacle neighbors taken into account to compute the current velocity for the specified agent.
size_t RVO::RVOSimulator::getAgentNumORCALines ( size_t  agentNo  )  const

Returns the count of ORCA constraints used to compute the current velocity for the specified agent.

Parameters:
agentNo The number of the agent whose count of ORCA constraints is to be retrieved.
Returns:
The count of ORCA constraints used to compute the current velocity for the specified agent.
size_t RVO::RVOSimulator::getAgentObstacleNeighbor ( size_t  agentNo,
size_t  neighborNo 
) const

Returns the specified obstacle neighbor of the specified agent.

Parameters:
agentNo The number of the agent whose obstacle neighbor is to be retrieved.
neighborNo The number of the obstacle neighbor to be retrieved.
Returns:
The number of the first vertex of the neighboring obstacle edge.
const Line& RVO::RVOSimulator::getAgentORCALine ( size_t  agentNo,
size_t  lineNo 
) const

Returns the specified ORCA constraint of the specified agent.

Parameters:
agentNo The number of the agent whose ORCA constraint is to be retrieved.
lineNo The number of the ORCA constraint to be retrieved.
Returns:
A line representing the specified ORCA constraint.
Note:
The halfplane to the left of the line is the region of permissible velocities with respect to the specified ORCA constraint.
const Vector2& RVO::RVOSimulator::getAgentPosition ( size_t  agentNo  )  const

Returns the two-dimensional position of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional position is to be retrieved.
Returns:
The present two-dimensional position of the (center of the) agent.
const Vector2& RVO::RVOSimulator::getAgentPrefVelocity ( size_t  agentNo  )  const

Returns the two-dimensional preferred velocity of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional preferred velocity is to be retrieved.
Returns:
The present two-dimensional preferred velocity of the agent.
float RVO::RVOSimulator::getAgentRadius ( size_t  agentNo  )  const

Returns the radius of a specified agent.

Parameters:
agentNo The number of the agent whose radius is to be retrieved.
Returns:
The present radius of the agent.
float RVO::RVOSimulator::getAgentTimeHorizon ( size_t  agentNo  )  const

Returns the time horizon of a specified agent.

Parameters:
agentNo The number of the agent whose time horizon is to be retrieved.
Returns:
The present time horizon of the agent.
float RVO::RVOSimulator::getAgentTimeHorizonObst ( size_t  agentNo  )  const

Returns the time horizon with respect to obstacles of a specified agent.

Parameters:
agentNo The number of the agent whose time horizon with respect to obstacles is to be retrieved.
Returns:
The present time horizon with respect to obstacles of the agent.
const Vector2& RVO::RVOSimulator::getAgentVelocity ( size_t  agentNo  )  const

Returns the two-dimensional linear velocity of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional linear velocity is to be retrieved.
Returns:
The present two-dimensional linear velocity of the agent.
float RVO::RVOSimulator::getGlobalTime (  )  const

Returns the global time of the simulation.

Returns:
The present global time of the simulation (zero initially).
size_t RVO::RVOSimulator::getNextObstacleVertexNo ( size_t  vertexNo  )  const

Returns the number of the obstacle vertex succeeding the specified obstacle vertex in its polygon.

Parameters:
vertexNo The number of the obstacle vertex whose successor is to be retrieved.
Returns:
The number of the obstacle vertex succeeding the specified obstacle vertex in its polygon.
size_t RVO::RVOSimulator::getNumAgents (  )  const

Returns the count of agents in the simulation.

Returns:
The count of agents in the simulation.
size_t RVO::RVOSimulator::getNumObstacleVertices (  )  const

Returns the count of obstacle vertices in the simulation.

Returns:
The count of obstacle vertices in the simulation.
const Vector2& RVO::RVOSimulator::getObstacleVertex ( size_t  vertexNo  )  const

Returns the two-dimensional position of a specified obstacle vertex.

Parameters:
vertexNo The number of the obstacle vertex to be retrieved.
Returns:
The two-dimensional position of the specified obstacle vertex.
size_t RVO::RVOSimulator::getPrevObstacleVertexNo ( size_t  vertexNo  )  const

Returns the number of the obstacle vertex preceding the specified obstacle vertex in its polygon.

Parameters:
vertexNo The number of the obstacle vertex whose predecessor is to be retrieved.
Returns:
The number of the obstacle vertex preceding the specified obstacle vertex in its polygon.
float RVO::RVOSimulator::getTimeStep (  )  const

Returns the time step of the simulation.

Returns:
The present time step of the simulation.
void RVO::RVOSimulator::processObstacles (  ) 

Processes the obstacles that have been added so that they are accounted for in the simulation.

Note:
Obstacles added to the simulation after this function has been called are not accounted for in the simulation.
bool RVO::RVOSimulator::queryVisibility ( const Vector2 point1,
const Vector2 point2,
float  radius = 0.0f 
) const

Performs a visibility query between the two specified points with respect to the obstacles.

Parameters:
point1 The first point of the query.
point2 The second point of the query.
radius The minimal distance between the line connecting the two points and the obstacles in order for the points to be mutually visible (optional). Must be non-negative.
Returns:
A boolean specifying whether the two points are mutually visible. Returns true when the obstacles have not been processed.
void RVO::RVOSimulator::setAgentDefaults ( float  neighborDist,
size_t  maxNeighbors,
float  timeHorizon,
float  timeHorizonObst,
float  radius,
float  maxSpeed,
const Vector2 velocity = Vector2() 
)

Sets the default properties for any new agent that is added.

Parameters:
neighborDist The default maximal distance (center point to center point) to other agents a new agent takes into account in the navigation. The larger this number, the longer he running time of the simulation. If the number is too low, the simulation will not be safe. Must be non-negative.
maxNeighbors The default maximal number of other agents a new agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe.
timeHorizon The default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to other agents. The larger this number, the sooner an agent will respond to the presence of other agents, but the less freedom the agent has in choosing its velocities. Must be positive.
timeHorizonObst The default minimal amount of time for which a new agent's velocities that are computed by the simulation are safe with respect to obstacles. The larger this number, the sooner an agent will respond to the presence of obstacles, but the less freedom the agent has in choosing its velocities. Must be positive.
radius The default radius of a new agent. Must be non-negative.
maxSpeed The default maximal speed of a new agent. Must be non-negative.
velocity The default initial two-dimensional linear velocity of a new agent (optional).
void RVO::RVOSimulator::setAgentMaxNeighbors ( size_t  agentNo,
size_t  maxNeighbors 
)

Sets the maximum neighbor count of a specified agent.

Parameters:
agentNo The number of the agent whose maximum neighbor count is to be modified.
maxNeighbors The replacement maximum neighbor count.
void RVO::RVOSimulator::setAgentMaxSpeed ( size_t  agentNo,
float  maxSpeed 
)

Sets the maximum speed of a specified agent.

Parameters:
agentNo The number of the agent whose maximum speed is to be modified.
maxSpeed The replacement maximum speed. Must be non-negative.
void RVO::RVOSimulator::setAgentNeighborDist ( size_t  agentNo,
float  neighborDist 
)

Sets the maximum neighbor distance of a specified agent.

Parameters:
agentNo The number of the agent whose maximum neighbor distance is to be modified.
neighborDist The replacement maximum neighbor distance. Must be non-negative.
void RVO::RVOSimulator::setAgentPosition ( size_t  agentNo,
const Vector2 position 
)

Sets the two-dimensional position of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional position is to be modified.
position The replacement of the two-dimensional position.
void RVO::RVOSimulator::setAgentPrefVelocity ( size_t  agentNo,
const Vector2 prefVelocity 
)

Sets the two-dimensional preferred velocity of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional preferred velocity is to be modified.
prefVelocity The replacement of the two-dimensional preferred velocity.
void RVO::RVOSimulator::setAgentRadius ( size_t  agentNo,
float  radius 
)

Sets the radius of a specified agent.

Parameters:
agentNo The number of the agent whose radius is to be modified.
radius The replacement radius. Must be non-negative.
void RVO::RVOSimulator::setAgentTimeHorizon ( size_t  agentNo,
float  timeHorizon 
)

Sets the time horizon of a specified agent with respect to other agents.

Parameters:
agentNo The number of the agent whose time horizon is to be modified.
timeHorizon The replacement time horizon with respect to other agents. Must be positive.
void RVO::RVOSimulator::setAgentTimeHorizonObst ( size_t  agentNo,
float  timeHorizonObst 
)

Sets the time horizon of a specified agent with respect to obstacles.

Parameters:
agentNo The number of the agent whose time horizon with respect to obstacles is to be modified.
timeHorizonObst The replacement time horizon with respect to obstacles. Must be positive.
void RVO::RVOSimulator::setAgentVelocity ( size_t  agentNo,
const Vector2 velocity 
)

Sets the two-dimensional linear velocity of a specified agent.

Parameters:
agentNo The number of the agent whose two-dimensional linear velocity is to be modified.
velocity The replacement two-dimensional linear velocity.
void RVO::RVOSimulator::setTimeStep ( float  timeStep  ) 

Sets the time step of the simulation.

Parameters:
timeStep The time step of the simulation. Must be positive.