#include <space.h>

Inheritance diagram for argos::CSpace:
Collaboration diagram for argos::CSpace:

Public Types

typedef std::map< std::string, CAny, std::less< std::string > > TMapPerType
 A map of entities indexed by type description. More...
 
typedef std::map< std::string, TMapPerType, std::less< std::string > > TMapPerTypePerId
 A map of entities indexed by type description and by id. More...
 
typedef std::function< void(CControllableEntity *)> TControllableEntityIterCBType
 The callback type for iteration over controllable entities within the PreStep() and/or PostStep() parts of the CLoopFunctions, making the threads used by ARGoS accessible therein. More...
 

Public Member Functions

 CSpace ()
 Class constructor. More...
 
virtual ~CSpace ()
 Class destructor. More...
 
virtual void Init (TConfigurationNode &t_tree)
 Initializes the space using the <arena> section of the XML configuration file. More...
 
virtual void Reset ()
 Reset the space and all its entities. More...
 
virtual void Destroy ()
 Destroys the space and all its entities. More...
 
UInt32 GetNumberEntities () const
 Returns the number of entities contained in the space. More...
 
CEntity::TVectorGetEntityVector ()
 Returns a vector of all the entities in the space. More...
 
CEntity::TVectorGetRootEntityVector ()
 Returns a vector of all the root entities in the space. More...
 
CEntityGetEntity (const std::string &str_id)
 Returns the entity with the given id. More...
 
void GetEntitiesMatching (CEntity::TVector &t_buffer, const std::string &str_pattern)
 Returns the entities matching a given pattern. More...
 
CEntity::TMapGetEntityMapPerId ()
 Returns a map of all entities ordered by id. More...
 
TMapPerTypePerIdGetEntityMapPerTypePerId ()
 Returns a nested map of entities, ordered by type and by id. More...
 
TMapPerTypeGetEntitiesByType (const std::string &str_type)
 Returns a map containing all the objects of a given type. More...
 
const TMapPerTypeGetEntitiesByType (const std::string &str_type) const
 
CFloorEntityGetFloorEntity ()
 Returns the floor entity. More...
 
void SetFloorEntity (CFloorEntity &c_floor_entity)
 Sets the floor entity. More...
 
virtual void Update ()
 Updates the space. More...
 
template<typename ENTITY >
void AddEntity (ENTITY &c_entity)
 Adds an entity of the given type. More...
 
template<typename ENTITY >
void RemoveEntity (ENTITY &c_entity)
 Removes an entity of the given type. More...
 
UInt32 GetSimulationClock () const
 Returns the current value of the simulation clock. More...
 
void SetSimulationClock (UInt32 un_simulation_clock)
 Sets a new value for the simulation clock. More...
 
void IncreaseSimulationClock (UInt32 un_increase=1)
 Increases the simulation clock by the wanted value. More...
 
const CVector3GetArenaSize () const
 Returns the arena size. More...
 
void SetArenaSize (const CVector3 &c_size)
 Sets the arena size. More...
 
const CVector3GetArenaCenter () const
 Returns the arena center. More...
 
void SetArenaCenter (const CVector3 &c_center)
 Sets the arena center. More...
 
const CRange< CVector3 > & GetArenaLimits () const
 Returns the arena limits. More...
 
virtual void AddControllableEntity (CControllableEntity &c_entity)
 
virtual void RemoveControllableEntity (CControllableEntity &c_entity)
 
virtual void AddEntityToPhysicsEngine (CEmbodiedEntity &c_entity)
 
virtual void IterateOverControllableEntities (const TControllableEntityIterCBType &c_cb)=0
 Given a callback specified in the loop functions, iterate over all controllable entities currently present in the arena (including those that are currently disabled). More...
 
- Public Member Functions inherited from argos::CBaseConfigurableResource
virtual ~CBaseConfigurableResource ()
 Class destructor. More...
 

Protected Member Functions

virtual void UpdateControllableEntitiesAct ()=0
 
virtual void UpdatePhysics ()=0
 
virtual void UpdateMedia ()=0
 
virtual void UpdateControllableEntitiesSenseStep ()=0
 
virtual void ControllableEntityIterationWaitAbort ()
 If the loop functions do not perform entity iteration in either of the PreStep() or PostStep() functions, then the threads which are currently waiting for the "go" signal from the loop functions need to be told in CSpace::Update() that they should stop waiting and start the next phase of the per-timestep updates. More...
 
void Distribute (TConfigurationNode &t_tree)
 
void AddBoxStrip (TConfigurationNode &t_tree)
 
bool ControllableEntityIterationEnabled () const
 

Protected Attributes

CSimulatorm_cSimulator
 
UInt32 m_unSimulationClock
 The current simulation clock. More...
 
CVector3 m_cArenaCenter
 Arena center. More...
 
CVector3 m_cArenaSize
 Arena size. More...
 
CRange< CVector3m_cArenaLimits
 Arena limits. More...
 
CEntity::TVector m_vecEntities
 A vector of entities. More...
 
CEntity::TVector m_vecRootEntities
 A vector of all the entities without a parent. More...
 
CEntity::TMap m_mapEntitiesPerId
 A map of entities. More...
 
TMapPerTypePerId m_mapEntitiesPerTypePerId
 A map of maps of all the simulated entities. More...
 
CControllableEntity::TVector m_vecControllableEntities
 A vector of controllable entities. More...
 
CFloorEntitym_pcFloorEntity
 The floor entity. More...
 
CPhysicsEngine::TVectorm_ptPhysicsEngines
 A pointer to the list of physics engines. More...
 
CMedium::TVectorm_ptMedia
 A pointer to the list of media. More...
 
TControllableEntityIterCBType m_cbControllableEntityIter {nullptr}
 Callback for iterating over entities from within the loop functions. More...
 

Detailed Description

Definition at line 32 of file space.h.

Member Typedef Documentation

◆ TControllableEntityIterCBType

The callback type for iteration over controllable entities within the PreStep() and/or PostStep() parts of the CLoopFunctions, making the threads used by ARGoS accessible therein.

See also
CLoopFunctions::PreStep()
CLoopFunctions::PostStep()
IterateOverControllableEntities()

Definition at line 90 of file space.h.

◆ TMapPerType

typedef std::map<std::string, CAny, std::less <std::string> > argos::CSpace::TMapPerType

A map of entities indexed by type description.

This map type is particularly useful when one wants to execute operations on a specific entity type. For instance, one could want to get the list of all robots of a specific type, and execute operations for that robot.

The elements in this map are indexed by type description (the string returned by CEntity::GetTypeDescription()). The elements themselves are stored as objects of the CAny class. This is because any_cast() is faster than dynamic_cast, and equally type-safe.

See also
CSpace::GetEntitiesByType()
CEntity::GetTypeDescription()
CAny
any_cast()
TMapPerTypePerId

Definition at line 56 of file space.h.

◆ TMapPerTypePerId

typedef std::map<std::string, TMapPerType, std::less <std::string> > argos::CSpace::TMapPerTypePerId

A map of entities indexed by type description and by id.

This map type is particularly useful when one wants to execute operations on a specific entity type with a specific id. For instance, one could want to operate on a list of robots with a specific type and id, and execute operations for each robot.

The elements in this map are indexed by type description (the string returned by CEntity::GetTypeDescription()), and by id (the string returned by CEntity::GetId()). The elements themselves are stored as objects of the CAny class. This is because any_cast() is faster than dynamic_cast, and equally type-safe.

See also
CSpace::GetEntitiesByType()
CEntity::GetTypeDescription()
CEntity::GetId()
CAny
any_cast()

Definition at line 79 of file space.h.

Constructor & Destructor Documentation

◆ CSpace()

argos::CSpace::CSpace ( )

Class constructor.

Definition at line 27 of file space.cpp.

◆ ~CSpace()

virtual argos::CSpace::~CSpace ( )
inlinevirtual

Class destructor.

Definition at line 105 of file space.h.

Member Function Documentation

◆ AddBoxStrip()

void argos::CSpace::AddBoxStrip ( TConfigurationNode t_tree)
protected

◆ AddControllableEntity()

void argos::CSpace::AddControllableEntity ( CControllableEntity c_entity)
virtual

Reimplemented in argos::CSpaceMultiThreadBalanceQuantity.

Definition at line 167 of file space.cpp.

◆ AddEntity()

template<typename ENTITY >
void argos::CSpace::AddEntity ( ENTITY &  c_entity)
inline

Adds an entity of the given type.

This method is used internally, don't use it in your code. throws CARGoSException if the entity id already exists in the space indexes.

Definition at line 274 of file space.h.

◆ AddEntityToPhysicsEngine()

void argos::CSpace::AddEntityToPhysicsEngine ( CEmbodiedEntity c_entity)
virtual

Definition at line 186 of file space.cpp.

◆ ControllableEntityIterationEnabled()

bool argos::CSpace::ControllableEntityIterationEnabled ( ) const
inlineprotected

Definition at line 449 of file space.h.

◆ ControllableEntityIterationWaitAbort()

virtual void argos::CSpace::ControllableEntityIterationWaitAbort ( void  )
inlineprotectedvirtual

If the loop functions do not perform entity iteration in either of the PreStep() or PostStep() functions, then the threads which are currently waiting for the "go" signal from the loop functions need to be told in CSpace::Update() that they should stop waiting and start the next phase of the per-timestep updates.

Unused if ARGoS was not configured to use threads in the input file.

See also
Update()

Definition at line 443 of file space.h.

◆ Destroy()

void argos::CSpace::Destroy ( )
virtual

Destroys the space and all its entities.

Implements argos::CBaseConfigurableResource.

Reimplemented in argos::CSpaceMultiThreadBalanceQuantity, and argos::CSpaceMultiThreadBalanceLength.

Definition at line 85 of file space.cpp.

◆ Distribute()

void argos::CSpace::Distribute ( TConfigurationNode t_tree)
protected

Definition at line 433 of file space.cpp.

◆ GetArenaCenter()

const CVector3& argos::CSpace::GetArenaCenter ( ) const
inline

Returns the arena center.

Returns
the arena center.

Definition at line 389 of file space.h.

◆ GetArenaLimits()

const CRange<CVector3>& argos::CSpace::GetArenaLimits ( ) const
inline

Returns the arena limits.

The arena limits are defined by arena center - arena size and arena center - arena size.

Returns
the arena limits.

Definition at line 409 of file space.h.

◆ GetArenaSize()

const CVector3& argos::CSpace::GetArenaSize ( ) const
inline

Returns the arena size.

Returns
the arena size.

Definition at line 371 of file space.h.

◆ GetEntitiesByType() [1/2]

TMapPerType& argos::CSpace::GetEntitiesByType ( const std::string &  str_type)
inline

Returns a map containing all the objects of a given type.

The 'type' here refers to the string returned by CEntity::GetTypeDescription(). Take this example: CSpace::TMapPerType& theMap = space.GetEntitiesByType("box"); CBoxEntity* box = any_cast<CBoxEntity*>(theMap["my_box"]); // do stuff with the box ...

Parameters
str_typeThe wanted type to search for.
Returns
A map containing all the objects of a given type.
Exceptions
CARGoSExceptionif the given type is not valid.
See also
CEntity::GetTypeDescription()
TMapPerType
GetEntityMapPerTypePerId()

Definition at line 226 of file space.h.

◆ GetEntitiesByType() [2/2]

const TMapPerType& argos::CSpace::GetEntitiesByType ( const std::string &  str_type) const
inline

Definition at line 230 of file space.h.

◆ GetEntitiesMatching()

void argos::CSpace::GetEntitiesMatching ( CEntity::TVector t_buffer,
const std::string &  str_pattern 
)

Returns the entities matching a given pattern.

The pattern must be a valid regexp.

Parameters
t_bufferA vector filled with all the entities that match the given pattern.
str_patternThe pattern to match.
Returns
The entity with the given id.
Exceptions
CARGoSExceptionif the regexp is not valid.

Definition at line 95 of file space.cpp.

◆ GetEntity()

CEntity& argos::CSpace::GetEntity ( const std::string &  str_id)
inline

Returns the entity with the given id.

Parameters
str_idThe id of the wanted entity
Returns
The entity with the given id.
Exceptions
CARGoSExceptionif an entity with the wanted id does not exist

Definition at line 160 of file space.h.

◆ GetEntityMapPerId()

CEntity::TMap& argos::CSpace::GetEntityMapPerId ( )
inline

Returns a map of all entities ordered by id.

Returns
a map of all entities ordered by id.

Definition at line 184 of file space.h.

◆ GetEntityMapPerTypePerId()

TMapPerTypePerId& argos::CSpace::GetEntityMapPerTypePerId ( )
inline

Returns a nested map of entities, ordered by type and by id.

The 'type' here refers to the string returned by CEntity::GetTypeDescription(). Take this example: CSpace::TMapPerTypePerId& theMap = space.GetEntityMapPerTypePerId(); // theMap["box"] is a CSpace::TMapPerType containing all the box entities, ordered by id // theMap["led"] is a CSpace::TMapPerType containing all the led entities, ordered by id // etc. CBoxEntity* box = any_cast<CBoxEntity*>(theMap["box"]["my_box_22"]); // do stuff with the box ...

Returns
a nested map of entities, ordered by type and by id.
See also
CEntity::GetTypeDescription()
TMapPerTypePerId
GetEntitiesByType()

Definition at line 205 of file space.h.

◆ GetEntityVector()

CEntity::TVector& argos::CSpace::GetEntityVector ( )
inline

Returns a vector of all the entities in the space.

All entities are returned, i.e., all the components of a robot.

Returns
a vector of all the entities in the space.
See also
GetRootEntityVector()

Definition at line 136 of file space.h.

◆ GetFloorEntity()

CFloorEntity& argos::CSpace::GetFloorEntity ( )
inline

Returns the floor entity.

Exceptions
CARGoSExceptionif the floor entity has not been added to the arena.
Returns
The floor entity.

Definition at line 239 of file space.h.

◆ GetNumberEntities()

UInt32 argos::CSpace::GetNumberEntities ( ) const
inline

Returns the number of entities contained in the space.

Definition at line 126 of file space.h.

◆ GetRootEntityVector()

CEntity::TVector& argos::CSpace::GetRootEntityVector ( )
inline

Returns a vector of all the root entities in the space.

A root entity is an entity that has no parent. This method differs from GetEntityVector() in that the latter returns all entities including the components of a composable entity, while this method does not return any component, but only the parentless composables.

Returns
a vector of all the root entities in the space.
See also
GetEntityVector()

Definition at line 150 of file space.h.

◆ GetSimulationClock()

UInt32 argos::CSpace::GetSimulationClock ( ) const
inline

Returns the current value of the simulation clock.

The clock is measured in ticks. You can set how much a tick is long in seconds in the XML.

Returns
The current value of the simulation clock.

Definition at line 345 of file space.h.

◆ IncreaseSimulationClock()

void argos::CSpace::IncreaseSimulationClock ( UInt32  un_increase = 1)
inline

Increases the simulation clock by the wanted value.

The clock is measured in ticks. You can set how much a tick is long in seconds in the XML.

Parameters
un_increaseThe quantity to add to the current value of the simulation clock.

Definition at line 363 of file space.h.

◆ Init()

void argos::CSpace::Init ( TConfigurationNode t_tree)
virtual

Initializes the space using the <arena> section of the XML configuration file.

Parameters
t_treethe <arena> section of the XML configuration file.

Implements argos::CBaseConfigurableResource.

Reimplemented in argos::CSpaceMultiThreadBalanceQuantity, and argos::CSpaceMultiThreadBalanceLength.

Definition at line 37 of file space.cpp.

◆ IterateOverControllableEntities()

virtual void argos::CSpace::IterateOverControllableEntities ( const TControllableEntityIterCBType c_cb)
pure virtual

Given a callback specified in the loop functions, iterate over all controllable entities currently present in the arena (including those that are currently disabled).

Implemented in argos::CSpaceNoThreads, argos::CSpaceMultiThreadBalanceQuantity, and argos::CSpaceMultiThreadBalanceLength.

◆ RemoveControllableEntity()

void argos::CSpace::RemoveControllableEntity ( CControllableEntity c_entity)
virtual

Reimplemented in argos::CSpaceMultiThreadBalanceQuantity.

Definition at line 174 of file space.cpp.

◆ RemoveEntity()

template<typename ENTITY >
void argos::CSpace::RemoveEntity ( ENTITY &  c_entity)
inline

Removes an entity of the given type.

This method is used internally, don't use it in your code. throws CARGoSException if the entity id does not exist in the space indexes.

Definition at line 307 of file space.h.

◆ Reset()

void argos::CSpace::Reset ( )
virtual

Reset the space and all its entities.

Implements argos::CBaseConfigurableResource.

Definition at line 73 of file space.cpp.

◆ SetArenaCenter()

void argos::CSpace::SetArenaCenter ( const CVector3 c_center)
inline

Sets the arena center.

Returns
the arena center.

Definition at line 397 of file space.h.

◆ SetArenaSize()

void argos::CSpace::SetArenaSize ( const CVector3 c_size)
inline

Sets the arena size.

Returns
the arena size.

Definition at line 379 of file space.h.

◆ SetFloorEntity()

void argos::CSpace::SetFloorEntity ( CFloorEntity c_floor_entity)
inline

Sets the floor entity.

Parameters
c_floor_entityThe floor entity.

Definition at line 248 of file space.h.

◆ SetSimulationClock()

void argos::CSpace::SetSimulationClock ( UInt32  un_simulation_clock)
inline

Sets a new value for the simulation clock.

The clock is measured in ticks. You can set how much a tick is long in seconds in the XML.

Parameters
un_simulation_clockThe new value for the simulation clock.

Definition at line 354 of file space.h.

◆ Update()

void argos::CSpace::Update ( )
virtual

◆ UpdateControllableEntitiesAct()

virtual void argos::CSpace::UpdateControllableEntitiesAct ( )
protectedpure virtual

◆ UpdateControllableEntitiesSenseStep()

virtual void argos::CSpace::UpdateControllableEntitiesSenseStep ( )
protectedpure virtual

◆ UpdateMedia()

virtual void argos::CSpace::UpdateMedia ( )
protectedpure virtual

◆ UpdatePhysics()

virtual void argos::CSpace::UpdatePhysics ( )
protectedpure virtual

Member Data Documentation

◆ m_cArenaCenter

CVector3 argos::CSpace::m_cArenaCenter
protected

Arena center.

Definition at line 468 of file space.h.

◆ m_cArenaLimits

CRange<CVector3> argos::CSpace::m_cArenaLimits
protected

Arena limits.

Definition at line 474 of file space.h.

◆ m_cArenaSize

CVector3 argos::CSpace::m_cArenaSize
protected

Arena size.

Definition at line 471 of file space.h.

◆ m_cbControllableEntityIter

TControllableEntityIterCBType argos::CSpace::m_cbControllableEntityIter {nullptr}
protected

Callback for iterating over entities from within the loop functions.

Definition at line 503 of file space.h.

◆ m_cSimulator

CSimulator& argos::CSpace::m_cSimulator
protected

Definition at line 462 of file space.h.

◆ m_mapEntitiesPerId

CEntity::TMap argos::CSpace::m_mapEntitiesPerId
protected

A map of entities.

Definition at line 483 of file space.h.

◆ m_mapEntitiesPerTypePerId

TMapPerTypePerId argos::CSpace::m_mapEntitiesPerTypePerId
protected

A map of maps of all the simulated entities.

The top-level map is indexed by type, as returned by CEntity::GetTypeDescription(). The second-level maps are indexed by entity id

Definition at line 488 of file space.h.

◆ m_pcFloorEntity

CFloorEntity* argos::CSpace::m_pcFloorEntity
protected

The floor entity.

Definition at line 494 of file space.h.

◆ m_ptMedia

CMedium::TVector* argos::CSpace::m_ptMedia
protected

A pointer to the list of media.

Definition at line 500 of file space.h.

◆ m_ptPhysicsEngines

CPhysicsEngine::TVector* argos::CSpace::m_ptPhysicsEngines
protected

A pointer to the list of physics engines.

Definition at line 497 of file space.h.

◆ m_unSimulationClock

UInt32 argos::CSpace::m_unSimulationClock
protected

The current simulation clock.

Definition at line 465 of file space.h.

◆ m_vecControllableEntities

CControllableEntity::TVector argos::CSpace::m_vecControllableEntities
protected

A vector of controllable entities.

Definition at line 491 of file space.h.

◆ m_vecEntities

CEntity::TVector argos::CSpace::m_vecEntities
protected

A vector of entities.

Definition at line 477 of file space.h.

◆ m_vecRootEntities

CEntity::TVector argos::CSpace::m_vecRootEntities
protected

A vector of all the entities without a parent.

Definition at line 480 of file space.h.