6 static const Real EPSILON = 1e-6;
11#define APPLY_ENTITY_OPERATION_TO_CELL(nI,nJ,nK) \
13 SCell& sCell = GetCellAt((nI), (nJ), (nK)); \
14 if((sCell.Timestamp == m_unCurTimestamp) && \
15 (! sCell.Entities.empty())) { \
16 for(typename CSet<ENTITY*,SEntityComparator>::iterator it = sCell.Entities.begin(); \
17 it != sCell.Entities.end(); \
19 if(!c_operation(**it)) return; \
24#define APPLY_ENTITY_OPERATION_TO_CELL_ALONG_RAY(nI,nJ,nK) \
26 SCell& sCell = GetCellAt(nI, nJ, nK); \
27 if((sCell.Timestamp == m_unCurTimestamp) && \
28 (! sCell.Entities.empty())) { \
29 for(typename CSet<ENTITY*,SEntityComparator>::iterator it = sCell.Entities.begin(); \
30 it != sCell.Entities.end(); \
32 if(!c_operation(**it)) return; \
34 if(b_stop_at_closest_match) return; \
38#define APPLY_CELL_OPERATION_TO_CELL(nI,nJ,nK) \
40 SCell& sCell = GetCellAt((nI), (nJ), (nK)); \
41 if(!c_operation((nI), (nJ), (nK), sCell)) return; \
75 template<
class ENTITY>
83 template<
class ENTITY>
90 template<
class ENTITY>
106 template<
class ENTITY>
113 template<
class ENTITY>
121 template<
class ENTITY>
129 template<
class ENTITY>
138 template<
class ENTITY>
149 c_entities = sCell.Entities;
153 THROW_ARGOSEXCEPTION_NESTED(
"CGrid<ENTITY>::GetEntitiesAt() : Position <" << c_position <<
"> out of bounds X -> " << m_cRangeX <<
" Y -> " << m_cRangeY <<
" Z -> " << m_cRangeZ, ex);
160 template<
class ENTITY>
170 template<
class ENTITY>
175 SInt32 nIC, nJC, nKC, nIR, nJR, nKR;
185 for(
SInt32 j = nJR; j > 0; --j) {
192 for(
SInt32 i = nIR; i > 0; --i) {
198 for(
SInt32 j = nJR; j > 0; --j) {
200 for(
SInt32 i = nIR; i > 0; --i) {
211 for(
SInt32 k = nKR; k > 0; --k) {
223 for(
SInt32 i = nIR; i > 0; --i) {
232 for(
SInt32 j = nJR; j > 0; --j) {
242 for(
SInt32 i = nIR; i > 0; --i) {
259 template<
class ENTITY>
264 SInt32 nI1, nJ1, nK1, nI2, nJ2, nK2;
270 for(
SInt32 k = nK1; k <= nK2; ++k) {
271 for(
SInt32 j = nJ1; j <= nJ2; ++j) {
272 for(
SInt32 i = nI1; i <= nI2; ++i) {
282 template<
class ENTITY>
287 if(!
m_cRangeZ.WithinMinBoundIncludedMaxBoundIncluded(c_center.
GetZ()))
return;
295 for(
SInt32 h = nID; h > 0; --h) {
301 for(
SInt32 h = nJD; h > 0; --h) {
306 for(
SInt32 i = nID; i > 0; --i) {
308 for(
SInt32 j = nJD; j > 0; --j) {
320 template<
class ENTITY>
331 for(
SInt32 j = nJ1; j <= nJ2; ++j) {
332 for(
SInt32 i = nI1; i <= nI2; ++i) {
341 template<
class ENTITY>
344 bool b_stop_at_closest_match) {
346 SInt32 nI1, nJ1, nK1, nI2, nJ2, nK2;
360 SInt32 nSI(nI2 >= nI1 ? 1 : -1);
361 SInt32 nSJ(nJ2 >= nJ1 ? 1 : -1);
362 SInt32 nSK(nK2 >= nK1 ? 1 : -1);
364 SInt32 nI(nI1), nJ(nJ1), nK(nK1);
365 if(nDI >= nDJ && nDI >= nDK) {
368 SInt32 nEJ(3 * nDJ - nDI);
369 SInt32 nEK(3 * nDK - nDI);
372 for(
SInt32 nCell = nDI; nCell > 0; --nCell) {
377 if(nEJ > 0 && nEK > 0) {
379 if(nEJ * nDK > nEK * nDJ) {
391 nEJ += 2 * (nDJ - nDI);
392 nEK += 2 * (nDK - nDI);
398 nEJ += 2 * (nDJ - nDI);
407 nEK += 2 * (nDK - nDI);
415 else if(nDJ >= nDI && nDJ >= nDK) {
418 SInt32 nEI(3 * nDI - nDJ);
419 SInt32 nEK(3 * nDK - nDJ);
422 for(
SInt32 nCell = nDJ; nCell > 0; --nCell) {
427 if(nEI > 0 && nEK > 0) {
429 if(nEI * nDK > nEK * nDI) {
441 nEI += 2 * (nDI - nDJ);
442 nEK += 2 * (nDK - nDJ);
448 nEI += 2 * (nDI - nDJ);
457 nEK += 2 * (nDK - nDJ);
468 SInt32 nEI(3 * nDI - nDK);
469 SInt32 nEJ(3 * nDJ - nDK);
472 for(
SInt32 nCell = nDK; nCell > 0; --nCell) {
477 if(nEI > 0 && nEJ > 0) {
479 if(nEI * nDJ > nEJ * nDI) {
491 nEI += 2 * (nDI - nDK);
492 nEJ += 2 * (nDJ - nDK);
498 nEI += 2 * (nDI - nDK);
507 nEJ += 2 * (nDJ - nDK);
520 template<
class ENTITY>
534 template<
class ENTITY>
539 SInt32 nIC, nJC, nKC, nIR, nJR, nKR;
549 for(
SInt32 j = nJR; j > 0; --j) {
556 for(
SInt32 i = nIR; i > 0; --i) {
562 for(
SInt32 j = nJR; j > 0; --j) {
564 for(
SInt32 i = nIR; i > 0; --i) {
575 for(
SInt32 k = nKR; k > 0; --k) {
587 for(
SInt32 i = nIR; i > 0; --i) {
596 for(
SInt32 j = nJR; j > 0; --j) {
606 for(
SInt32 i = nIR; i > 0; --i) {
623 template<
class ENTITY>
628 SInt32 nI1, nJ1, nK1, nI2, nJ2, nK2;
634 for(
SInt32 k = nK1; k <= nK2; ++k) {
635 for(
SInt32 j = nJ1; j <= nJ2; ++j) {
636 for(
SInt32 i = nI1; i <= nI2; ++i) {
646 template<
class ENTITY>
651 if(!
m_cRangeZ.WithinMinBoundIncludedMaxBoundIncluded(c_center.
GetZ()))
return;
659 for(
SInt32 h = nID; h > 0; --h) {
665 for(
SInt32 h = nJD; h > 0; --h) {
670 for(
SInt32 i = nID; i > 0; --i) {
672 for(
SInt32 j = nJD; j > 0; --j) {
684 template<
class ENTITY>
695 for(
SInt32 j = nJ1; j <= nJ2; ++j) {
696 for(
SInt32 i = nI1; i <= nI2; ++i) {
705 template<
class ENTITY>
709 SInt32 nI1, nJ1, nK1, nI2, nJ2, nK2;
723 SInt32 nSI(nI2 >= nI1 ? 1 : -1);
724 SInt32 nSJ(nJ2 >= nJ1 ? 1 : -1);
725 SInt32 nSK(nK2 >= nK1 ? 1 : -1);
727 SInt32 nI(nI1), nJ(nJ1), nK(nK1);
728 if(nDI >= nDJ && nDI >= nDK) {
731 SInt32 nEJ(3 * nDJ - nDI);
732 SInt32 nEK(3 * nDK - nDI);
735 for(
SInt32 nCell = nDI; nCell > 0; --nCell) {
740 if(nEJ > 0 && nEK > 0) {
742 if(nEJ * nDK > nEK * nDJ) {
754 nEJ += 2 * (nDJ - nDI);
755 nEK += 2 * (nDK - nDI);
761 nEJ += 2 * (nDJ - nDI);
770 nEK += 2 * (nDK - nDI);
778 else if(nDJ >= nDI && nDJ >= nDK) {
781 SInt32 nEI(3 * nDI - nDJ);
782 SInt32 nEK(3 * nDK - nDJ);
785 for(
SInt32 nCell = nDJ; nCell > 0; --nCell) {
790 if(nEI > 0 && nEK > 0) {
792 if(nEI * nDK > nEK * nDI) {
804 nEI += 2 * (nDI - nDJ);
805 nEK += 2 * (nDK - nDJ);
811 nEI += 2 * (nDI - nDJ);
820 nEK += 2 * (nDK - nDJ);
831 SInt32 nEI(3 * nDI - nDK);
832 SInt32 nEJ(3 * nDJ - nDK);
835 for(
SInt32 nCell = nDK; nCell > 0; --nCell) {
840 if(nEI > 0 && nEJ > 0) {
842 if(nEI * nDJ > nEJ * nDI) {
854 nEI += 2 * (nDI - nDK);
855 nEJ += 2 * (nDJ - nDK);
861 nEI += 2 * (nDI - nDK);
870 nEJ += 2 * (nDJ - nDK);
883 template<
class ENTITY>
888 if((n_i >= 0) && (n_i <
m_nSizeI) &&
906 template<
class ENTITY>
914 template<
class ENTITY>
919 if(
m_cRangeX.WithinMinBoundIncludedMaxBoundIncluded(c_position.
GetX()) &&
920 m_cRangeY.WithinMinBoundIncludedMaxBoundIncluded(c_position.
GetY()) &&
921 m_cRangeZ.WithinMinBoundIncludedMaxBoundIncluded(c_position.
GetZ())) {
934 template<
class ENTITY>
947 template<
class ENTITY>
962 template<
class ENTITY>
975 template<
class ENTITY>
987 template<
class ENTITY>
signed int SInt32
32-bit signed integer.
float Real
Collects all ARGoS code.
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
#define APPLY_ENTITY_OPERATION_TO_CELL(nI, nJ, nK)
#define APPLY_ENTITY_OPERATION_TO_CELL_ALONG_RAY(nI, nJ, nK)
#define APPLY_CELL_OPERATION_TO_CELL(nI, nJ, nK)
The namespace containing all the ARGoS related code.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
SInt32 Floor(Real f_value)
Rounds the passed floating-point value to the closest lower integer.
T Max(const T &t_v1, const T &t_v2)
Returns the bigger of the two passed arguments.
T Abs(const T &t_v)
Returns the absolute value of the passed argument.
T Min(const T &t_v1, const T &t_v2)
Returns the smaller of the two passed arguments.
virtual void Reset()
Resets the resource.
SCell & GetCellAt(SInt32 n_i, SInt32 n_j, SInt32 n_k)
virtual void Update()
Updates this positional index.
virtual void ForCellsInBoxRange(const CVector3 &c_center, const CVector3 &c_half_size, CCellOperation &c_operation)
void UpdateCell(SInt32 n_i, SInt32 n_j, SInt32 n_k, ENTITY &c_entity)
void ClampCoordinates(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k) const
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.
virtual void Init(TConfigurationNode &t_tree)
Initializes the resource.
CEntityOperation * m_pcUpdateEntityOperation
virtual void Destroy()
Undoes whatever was done by Init().
virtual void ForEntitiesInSphereRange(const CVector3 &c_center, Real f_radius, CEntityOperation &c_operation)
Executes an operation on all entities within the specified sphere range.
CVector3 m_cAreaMaxCorner
CSet< ENTITY *, SEntityComparator > m_cEntities
virtual void ForEntitiesInCircleRange(const CVector3 &c_center, Real f_radius, CEntityOperation &c_operation)
Executes an operation on all entities within the specified circle range.
virtual void ForCellsAlongRay(const CRay3 &c_ray, CCellOperation &c_operation)
virtual void ForCellsInCircleRange(const CVector3 &c_center, Real f_radius, CCellOperation &c_operation)
virtual void AddEntity(ENTITY &c_entity)
Adds an entity to this index.
void PositionToCellUnsafe(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k, const CVector3 &c_position) const
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.
CVector3 m_cAreaMinCorner
CPositionalIndex< ENTITY >::COperation CEntityOperation
void PositionToCell(SInt32 &n_i, SInt32 &n_j, SInt32 &n_k, const CVector3 &c_position) const
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.
void SetUpdateEntityOperation(CEntityOperation *pc_operation)
virtual void RemoveEntity(ENTITY &c_entity)
Removes an entity from this index.
virtual void ForAllEntities(CEntityOperation &c_operation)
Executes an operation on all the indexed entities.
virtual void ForCellsInSphereRange(const CVector3 &c_center, Real f_radius, CCellOperation &c_operation)
virtual void ForCellsInRectangleRange(const CVector3 &c_center, const CVector2 &c_half_size, CCellOperation &c_operation)
virtual void ForAllCells(CCellOperation &c_operation)
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.
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)
CSet< ENTITY *, SEntityComparator > Entities
The exception that wraps all errors in ARGoS.
Defines a very simple double-linked list that stores unique elements.
void clear()
Erases the contents of the list.
CSetIterator< T, T > iterator
Real GetY() const
Returns the y coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
void SetY(const Real f_y)
Sets the y coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
void SetX(const Real f_x)
Sets the x coordinate of this vector.
void SetZ(const Real f_z)
Sets the z coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.