embodied_entity.h
Go to the documentation of this file.
1 
7 #ifndef EMBODIED_ENTITY_H
8 #define EMBODIED_ENTITY_H
9 
10 namespace argos {
11  class CEmbodiedEntity;
12 }
13 
14 #include <argos3/core/simulator/entity/entity.h>
15 #include <argos3/core/simulator/space/positional_indices/grid.h>
16 #include <argos3/core/simulator/space/positional_indices/space_hash.h>
17 #include <argos3/core/utility/datatypes/set.h>
18 #include <argos3/core/utility/math/ray3.h>
19 #include <argos3/core/utility/math/quaternion.h>
20 #include <argos3/core/simulator/physics_engine/physics_engine.h>
21 #include <argos3/core/simulator/physics_engine/physics_model.h>
22 #include <algorithm>
23 
24 namespace argos {
25 
48  class CEmbodiedEntity : public CEntity {
49 
50  public:
51 
53 
54  public:
55 
62 
75  const std::string& str_id,
76  const CVector3& c_position = CVector3(),
77  const CQuaternion& c_orientation = CQuaternion(),
78  bool b_movable = true);
79 
83  virtual ~CEmbodiedEntity();
84 
93  virtual void Init(TConfigurationNode& t_tree);
94 
95  virtual void Reset();
96 
101  inline bool IsMovable() const {
102  return m_bMovable;
103  }
104 
111  inline void SetMovable(bool b_movable) {
112  m_bMovable = b_movable;
113  }
114 
119  inline const SAnchor& GetOriginAnchor() const {
120  return *m_psOriginAnchor;
121  }
122 
128  return *m_psOriginAnchor;
129  }
130 
142  SAnchor& AddAnchor(const std::string& str_id,
143  const CVector3& c_rel_position = CVector3(),
144  const CQuaternion& c_rel_orientation = CQuaternion());
145 
153  void EnableAnchor(const std::string& str_id);
154 
162  void DisableAnchor(const std::string& str_id);
163 
173  const SAnchor& GetAnchor(const std::string& str_id) const;
174 
184  SAnchor& GetAnchor(const std::string& str_id);
185 
193  inline std::map<std::string, SAnchor*>& GetAnchors() {
194  return m_mapAnchors;
195  }
196 
205  inline std::vector<SAnchor*>& GetEnabledAnchors() {
206  return m_vecEnabledAnchors;
207  }
208 
215  bool IsAnchorEnabled(const std::string& str_id);
216 
226  const SBoundingBox& GetBoundingBox() const;
227 
232  UInt32 GetPhysicsModelsNum() const;
233 
241  virtual void AddPhysicsModel(const std::string& str_engine_id,
242  CPhysicsModel& c_physics_model);
243 
250  void RemovePhysicsModel(const std::string& str_engine_id);
251 
258  const CPhysicsModel& GetPhysicsModel(size_t un_idx) const;
259 
266  CPhysicsModel& GetPhysicsModel(size_t un_idx);
267 
274  const CPhysicsModel& GetPhysicsModel(const std::string& str_engine_id) const;
275 
282  CPhysicsModel& GetPhysicsModel(const std::string& str_engine_id);
283 
296  virtual bool MoveTo(const CVector3& c_position,
297  const CQuaternion& c_orientation,
298  bool b_check_only = false,
299  bool b_ignore_collisions = false);
300 
305  virtual bool IsCollidingWithSomething() const;
306 
307  virtual std::string GetTypeDescription() const {
308  return "body";
309  }
310 
317  void CalculateBoundingBox();
318 
319  protected:
320 
326  std::map<std::string, SAnchor*> m_mapAnchors;
327  std::vector<SAnchor*> m_vecEnabledAnchors;
330 
331  };
332 
340  extern bool operator==(const SAnchor* ps_anchor,
341  const std::string& str_id);
342 
343  /****************************************/
344  /****************************************/
345 
346  typedef std::vector<CEmbodiedEntity*> TEmbodiedEntityVector;
347  typedef std::map<std::string, CEmbodiedEntity*> TEmbodiedEntityMap;
349 
350  /****************************************/
351  /****************************************/
352 
356  class CEmbodiedEntitySpaceHashUpdater : public CSpaceHashUpdater<CEmbodiedEntity> {
357 
358  public:
359 
360  virtual void operator()(CAbstractSpaceHash<CEmbodiedEntity>& c_space_hash,
361  CEmbodiedEntity& c_element);
362 
363  private:
364 
365  SInt32 m_nMinX, m_nMinY, m_nMinZ;
366  SInt32 m_nMaxX, m_nMaxY, m_nMaxZ;
367 
368  };
373  /****************************************/
374  /****************************************/
375 
376  class CEmbodiedEntityGridUpdater : public CGrid<CEmbodiedEntity>::COperation {
377 
378  public:
379 
381  virtual bool operator()(CEmbodiedEntity& c_entity);
382 
383  private:
384 
385  CGrid<CEmbodiedEntity>& m_cGrid;
386  SInt32 m_nMinI, m_nMinJ, m_nMinK;
387  SInt32 m_nMaxI, m_nMaxJ, m_nMaxK;
388  };
389 
390  /****************************************/
391  /****************************************/
392 
393 }
394 
395 #endif
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
bool operator==(const SAnchor *ps_anchor, const std::string &str_id)
Returns true if the anchor id matches the given id.
std::vector< CEmbodiedEntity * > TEmbodiedEntityVector
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
std::map< std::string, CEmbodiedEntity * > TEmbodiedEntityMap
CSet< CEmbodiedEntity * > TEmbodiedEntitySet
Basic class for an entity that contains other entities.
This entity is a link to a body in the physics engine.
CQuaternion m_cInitOriginOrientation
void DisableAnchor(const std::string &str_id)
Disables an anchor.
virtual void AddPhysicsModel(const std::string &str_engine_id, CPhysicsModel &c_physics_model)
Adds a new physics model to this embodied entity.
bool IsAnchorEnabled(const std::string &str_id)
Returns true if the given anchor is enabled, false otherwise.
void RemovePhysicsModel(const std::string &str_engine_id)
Removes a physics model from this embodied entity.
CEmbodiedEntity(CComposableEntity *pc_parent)
Class constructor.
const SAnchor & GetAnchor(const std::string &str_id) const
Returns the wanted anchor as a const reference.
SAnchor & GetOriginAnchor()
Returns a non-const reference to the origin anchor associated to this entity.
const SBoundingBox & GetBoundingBox() const
Returns the bounding box of this embodied entity.
bool IsMovable() const
Returns true if the entity is movable.
CPhysicsModel::TVector m_tPhysicsModelVector
std::map< std::string, SAnchor * > m_mapAnchors
virtual std::string GetTypeDescription() const
Returns a string label for this class.
void CalculateBoundingBox()
Calculates the bounding box of this entity.
std::vector< SAnchor * > m_vecEnabledAnchors
virtual bool IsCollidingWithSomething() const
Returns true if this entity is colliding with another object.
virtual ~CEmbodiedEntity()
Class destructor.
const CPhysicsModel & GetPhysicsModel(size_t un_idx) const
Returns a physics model associated to this entity.
std::map< std::string, SAnchor * > & GetAnchors()
Returns a map of anchors associated to this embodied entity.
UInt32 GetPhysicsModelsNum() const
Returns the number of physics models associated to this entity.
SBoundingBox * m_sBoundingBox
virtual bool MoveTo(const CVector3 &c_position, const CQuaternion &c_orientation, bool b_check_only=false, bool b_ignore_collisions=false)
Moves the entity to the wanted position and orientation.
virtual void Init(TConfigurationNode &t_tree)
Initializes the state of the entity from the XML configuration tree.
void SetMovable(bool b_movable)
Sets whether this entity is movable or not.
std::vector< SAnchor * > & GetEnabledAnchors()
Returns a vector of enabled anchors for fast looping.
CPhysicsModel::TMap m_tPhysicsModelMap
void EnableAnchor(const std::string &str_id)
Enables an anchor.
const SAnchor & GetOriginAnchor() const
Returns a const reference to the origin anchor associated to this entity.
SAnchor & AddAnchor(const std::string &str_id, const CVector3 &c_rel_position=CVector3(), const CQuaternion &c_rel_orientation=CQuaternion())
Adds an anchor to the embodied entity.
virtual void Reset()
Resets the state of the entity to whatever it was after Init() or the standalone constructor was call...
virtual bool operator()(CEmbodiedEntity &c_entity)
CEmbodiedEntityGridUpdater(CGrid< CEmbodiedEntity > &c_grid)
The basic entity type.
Definition: entity.h:90
An anchor related to the body of an entity.
Definition: physics_model.h:38
std::map< std::string, CPhysicsModel * > TMap
std::vector< CPhysicsModel * > TVector
The abstract definition of a space hash.
Definition: space_hash.h:34
Defines the basic cell updater of the space hash.
Definition: space_hash.h:269
Defines a very simple double-linked list that stores unique elements.
Definition: set.h:101
A 3D vector class.
Definition: vector3.h:31