Go to the documentation of this file.
1 #ifndef GRID_H
2 #define GRID_H
4 #include <argos3/core/utility/datatypes/set.h>
5 #include <argos3/core/utility/math/range.h>
6 #include <argos3/core/utility/math/ray3.h>
7 #include <argos3/core/simulator/space/positional_indices/positional_index.h>
9 namespace argos {
11  template<class ENTITY>
12  class CGrid : public CPositionalIndex<ENTITY> {
14  public:
18  struct SCell {
20  size_t Timestamp;
22  SCell() : Timestamp(0) {}
23  inline void Reset() {
24  Entities.clear();
25  Timestamp = 0;
26  }
27  };
30  public:
31  virtual ~CCellOperation() {}
32  virtual bool operator()(SInt32 n_i,
33  SInt32 n_j,
34  SInt32 n_k,
35  SCell& s_cell) = 0;
36  };
38  public:
40  CGrid(const CVector3& c_area_min_corner,
41  const CVector3& c_area_max_corner,
42  SInt32 n_size_i,
43  SInt32 n_size_j,
44  SInt32 n_size_k);
46  virtual ~CGrid();
48  virtual void Init(TConfigurationNode& t_tree);
49  virtual void Reset();
50  virtual void Destroy();
52  virtual void AddEntity(ENTITY& c_entity);
54  virtual void RemoveEntity(ENTITY& c_entity);
56  virtual void Update();
58  virtual void GetEntitiesAt(CSet<ENTITY*,SEntityComparator>& c_entities,
59  const CVector3& c_position) const;
61  virtual void ForAllEntities(CEntityOperation& c_operation);
63  virtual void ForEntitiesInSphereRange(const CVector3& c_center,
64  Real f_radius,
65  CEntityOperation& c_operation);
67  virtual void ForEntitiesInBoxRange(const CVector3& c_center,
68  const CVector3& c_half_size,
69  CEntityOperation& c_operation);
71  virtual void ForEntitiesInCircleRange(const CVector3& c_center,
72  Real f_radius,
73  CEntityOperation& c_operation);
75  virtual void ForEntitiesInRectangleRange(const CVector3& c_center,
76  const CVector2& c_half_size,
77  CEntityOperation& c_operation);
79  virtual void ForEntitiesAlongRay(const CRay3& c_ray,
80  CEntityOperation& c_operation,
81  bool b_stop_at_closest_match = false);
83  virtual void ForAllCells(CCellOperation& c_operation);
85  virtual void ForCellsInSphereRange(const CVector3& c_center,
86  Real f_radius,
87  CCellOperation& c_operation);
89  virtual void ForCellsInBoxRange(const CVector3& c_center,
90  const CVector3& c_half_size,
91  CCellOperation& c_operation);
93  virtual void ForCellsInCircleRange(const CVector3& c_center,
94  Real f_radius,
95  CCellOperation& c_operation);
97  virtual void ForCellsInRectangleRange(const CVector3& c_center,
98  const CVector2& c_half_size,
99  CCellOperation& c_operation);
101  virtual void ForCellsAlongRay(const CRay3& c_ray,
102  CCellOperation& c_operation);
104  inline SInt32 GetSizeI() const {
105  return m_nSizeI;
106  }
108  inline SInt32 GetSizeJ() const {
109  return m_nSizeJ;
110  }
112  inline SInt32 GetSizeK() const {
113  return m_nSizeK;
114  }
116  inline void SetUpdateEntityOperation(CEntityOperation* pc_operation);
118  void UpdateCell(SInt32 n_i,
119  SInt32 n_j,
120  SInt32 n_k,
121  ENTITY& c_entity);
123  inline void PositionToCell(SInt32& n_i,
124  SInt32& n_j,
125  SInt32& n_k,
126  const CVector3& c_position) const;
128  inline void PositionToCellUnsafe(SInt32& n_i,
129  SInt32& n_j,
130  SInt32& n_k,
131  const CVector3& c_position) const;
133  inline void ClampCoordinates(SInt32& n_i,
134  SInt32& n_j,
135  SInt32& n_k) const;
137  inline void ClampCoordinates(CVector3& c_pos) const;
139  inline SCell& GetCellAt(SInt32 n_i,
140  SInt32 n_j,
141  SInt32 n_k);
143  inline const SCell& GetCellAt(SInt32 n_i,
144  SInt32 n_j,
145  SInt32 n_k) const;
147  protected:
159  SCell* m_psCells;
162  CEntityOperation* m_pcUpdateEntityOperation;
164  };
166 }
168 #include <argos3/core/simulator/space/positional_indices/grid_impl.h>
170 #endif
CRange< Real > m_cRangeZ
Definition: grid.h:156
signed int SInt32
32-bit signed integer.
Definition: datatypes.h:93
CPositionalIndex< ENTITY >::COperation CEntityOperation
Definition: grid.h:16
A 3D vector class.
Definition: vector3.h:29
virtual void ForAllCells(CCellOperation &c_operation)
Definition: grid_impl.h:521
CSet< ENTITY *, SEntityComparator > Entities
Definition: grid.h:19
virtual void ForEntitiesInCircleRange(const CVector3 &c_center, Real f_radius, CEntityOperation &c_operation)
Executes an operation on all entities within the specified circle range.
Definition: grid_impl.h:283
SInt32 GetSizeJ() const
Definition: grid.h:108
SInt32 GetSizeK() const
Definition: grid.h:112
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
CVector3 m_cAreaMaxCorner
Definition: grid.h:150
virtual void ForEntitiesInRectangleRange(const CVector3 &c_center, const CVector2 &c_half_size, CEntityOperation &c_operation)
Executes an operation on all entities within the specified rectangle range.
Definition: grid_impl.h:321
void SetUpdateEntityOperation(CEntityOperation *pc_operation)
Definition: grid_impl.h:907
virtual void Reset()
Resets the resource.
Definition: grid_impl.h:91
SCell * m_psCells
Definition: grid.h:159
void UpdateCell(SInt32 n_i, SInt32 n_j, SInt32 n_k, ENTITY &c_entity)
Definition: grid_impl.h:884
A data structure that contains positional entities.
void PositionToCellUnsafe(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k, const CVector3 &c_position) const
Definition: grid_impl.h:935
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
void clear()
Erases the contents of the list.
Definition: set.h:351
Defines a very simple double-linked list that stores unique elements.
Definition: set.h:101
CEntityOperation * m_pcUpdateEntityOperation
Definition: grid.h:162
void Reset()
Definition: grid.h:23
CRange< Real > m_cRangeY
Definition: grid.h:155
virtual void ForEntitiesInSphereRange(const CVector3 &c_center, Real f_radius, CEntityOperation &c_operation)
Executes an operation on all entities within the specified sphere range.
Definition: grid_impl.h:171
CSet< ENTITY *, SEntityComparator > m_cEntities
Definition: grid.h:161
A 2D vector class.
Definition: vector2.h:25
virtual void GetEntitiesAt(CSet< ENTITY *, SEntityComparator > &c_entities, const CVector3 &c_position) const
Puts the entities located at the given point in the passed buffer.
Definition: grid_impl.h:139
virtual ~CCellOperation()
Definition: grid.h:31
CRange< Real > m_cRangeX
Definition: grid.h:154
SInt32 m_nSizeK
Definition: grid.h:153
CVector3 m_cInvCellSize
Definition: grid.h:158
virtual void ForEntitiesAlongRay(const CRay3 &c_ray, CEntityOperation &c_operation, bool b_stop_at_closest_match=false)
Executes an operation on all entities that intersect the given ray.
Definition: grid_impl.h:342
virtual bool operator()(SInt32 n_i, SInt32 n_j, SInt32 n_k, SCell &s_cell)=0
virtual void ForEntitiesInBoxRange(const CVector3 &c_center, const CVector3 &c_half_size, CEntityOperation &c_operation)
Executes an operation on all entities within the specified box range.
Definition: grid_impl.h:260
CVector3 m_cCellSize
Definition: grid.h:157
virtual void AddEntity(ENTITY &c_entity)
Adds an entity to this index.
Definition: grid_impl.h:114
void PositionToCell(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k, const CVector3 &c_position) const
Definition: grid_impl.h:915
virtual void ForCellsInCircleRange(const CVector3 &c_center, Real f_radius, CCellOperation &c_operation)
Definition: grid_impl.h:647
virtual void ForCellsInRectangleRange(const CVector3 &c_center, const CVector2 &c_half_size, CCellOperation &c_operation)
Definition: grid_impl.h:685
virtual void Update()
Updates this positional index.
Definition: grid_impl.h:130
virtual void RemoveEntity(ENTITY &c_entity)
Removes an entity from this index.
Definition: grid_impl.h:122
size_t Timestamp
Definition: grid.h:20
CVector3 m_cAreaMinCorner
Definition: grid.h:149
virtual void ForAllEntities(CEntityOperation &c_operation)
Executes an operation on all the indexed entities.
Definition: grid_impl.h:161
size_t m_unCurTimestamp
Definition: grid.h:160
virtual void Destroy()
Undoes whatever was done by Init().
Definition: grid_impl.h:107
SInt32 m_nSizeJ
Definition: grid.h:152
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
Definition: grid_impl.h:84
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
void ClampCoordinates(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k) const
Definition: grid_impl.h:948
virtual ~CGrid()
Definition: grid_impl.h:76
SInt32 m_nSizeI
Definition: grid.h:151
virtual void ForCellsAlongRay(const CRay3 &c_ray, CCellOperation &c_operation)
Definition: grid_impl.h:706
SCell & GetCellAt(SInt32 n_i, SInt32 n_j, SInt32 n_k)
Definition: grid_impl.h:976
The operation to perform on each entity found in range.
virtual void ForCellsInSphereRange(const CVector3 &c_center, Real f_radius, CCellOperation &c_operation)
Definition: grid_impl.h:535
SInt32 GetSizeI() const
Definition: grid.h:104
virtual void ForCellsInBoxRange(const CVector3 &c_center, const CVector3 &c_half_size, CCellOperation &c_operation)
Definition: grid_impl.h:624
CGrid(const CVector3 &c_area_min_corner, const CVector3 &c_area_max_corner, SInt32 n_size_i, SInt32 n_size_j, SInt32 n_size_k)
Definition: grid_impl.h:48