AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc > Class Template Reference

#include "RegularGrid.h"

Inheritance diagram for RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >:
DynTreeImpl

Classes

struct  Cell
 

Public Types

enum  { CELL_NUMBER = 64 }
 
typedef G3D::Table< const T *, NodeArray< Node > > MemberTable
 

Public Member Functions

 RegularGrid2D ()
 
 ~RegularGrid2D ()
 
void insert (const T &value)
 
void remove (const T &value)
 
void balance ()
 
bool contains (const T &value) const
 
int size () const
 
Node & getGridFor (float fx, float fy)
 
Node & getGrid (int x, int y)
 
template<typename RayCallback >
void intersectRay (const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist, bool stopAtFirstHit)
 
template<typename RayCallback >
void intersectRay (const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist, const G3D::Vector3 &end, bool stopAtFirstHit)
 
template<typename IsectCallback >
void intersectPoint (const G3D::Vector3 &point, IsectCallback &intersectCallback)
 
template<typename RayCallback >
void intersectZAllignedRay (const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist)
 

Public Attributes

MemberTable memberTable
 
Node * nodes [CELL_NUMBER][CELL_NUMBER]
 

Detailed Description

template<class T, class Node, class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
class RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >

Member Typedef Documentation

◆ MemberTable

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
typedef G3D::Table<const T*, NodeArray<Node> > RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::MemberTable

Member Enumeration Documentation

◆ anonymous enum

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
anonymous enum
Enumerator
CELL_NUMBER 
48 {
49 CELL_NUMBER = 64,
50 };
@ CELL_NUMBER
Definition: RegularGrid.h:49

Constructor & Destructor Documentation

◆ RegularGrid2D()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::RegularGrid2D ( )
inline
61 {
62 memset(nodes, 0, sizeof(nodes));
63 }
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:58

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes.

◆ ~RegularGrid2D()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::~RegularGrid2D ( )
inline
66 {
67 for (int x = 0; x < CELL_NUMBER; ++x)
68 for (int y = 0; y < CELL_NUMBER; ++y)
69 {
70 delete nodes[x][y];
71 }
72 }

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::CELL_NUMBER, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes.

Member Function Documentation

◆ balance()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::balance ( )
inline
134 {
135 for (int x = 0; x < CELL_NUMBER; ++x)
136 for (int y = 0; y < CELL_NUMBER; ++y)
137 if (Node* n = nodes[x][y])
138 {
139 n->balance();
140 }
141 }

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::CELL_NUMBER, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes.

Referenced by DynTreeImpl::balance().

◆ contains()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
bool RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::contains ( const T &  value) const
inline
143{ return memberTable.containsKey(&value); }
MemberTable memberTable
Definition: RegularGrid.h:57

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::memberTable.

Referenced by DynamicMapTree::contains().

◆ getGrid()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
Node & RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::getGrid ( int  x,
int  y 
)
inline
167 {
168 ASSERT(x < CELL_NUMBER && y < CELL_NUMBER);
169 if (!nodes[x][y])
170 {
171 nodes[x][y] = NodeCreatorFunc::makeNode(x, y);
172 }
173 return *nodes[x][y];
174 }
#define ASSERT
Definition: Errors.h:68

References ASSERT, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::CELL_NUMBER, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes.

Referenced by RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::getGridFor().

◆ getGridFor()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
Node & RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::getGridFor ( float  fx,
float  fy 
)
inline

◆ insert()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::insert ( const T &  value)
inline
75 {
76 G3D::Vector3 pos[9];
77 pos[0] = value.GetBounds().corner(0);
78 pos[1] = value.GetBounds().corner(1);
79 pos[2] = value.GetBounds().corner(2);
80 pos[3] = value.GetBounds().corner(3);
81 pos[4] = (pos[0] + pos[1]) / 2.0f;
82 pos[5] = (pos[1] + pos[2]) / 2.0f;
83 pos[6] = (pos[2] + pos[3]) / 2.0f;
84 pos[7] = (pos[3] + pos[0]) / 2.0f;
85 pos[8] = (pos[0] + pos[2]) / 2.0f;
86
88 for (uint8 i = 0; i < 9; ++i)
89 {
90 Cell c = Cell::ComputeCell(pos[i].x, pos[i].y);
91 if (!c.isValid())
92 {
93 continue;
94 }
95 Node& node = getGridFor(pos[i].x, pos[i].y);
96 na.AddNode(&node);
97 }
98
99 for (uint8 i = 0; i < 9; ++i)
100 {
101 if (na._nodes[i])
102 {
103 na._nodes[i]->insert(value);
104 }
105 else
106 {
107 break;
108 }
109 }
110
111 memberTable.set(&value, na);
112 }
std::uint8_t uint8
Definition: Define.h:110
Definition: RegularGrid.h:13
void AddNode(Node *n)
Definition: RegularGrid.h:16
Node * _nodes[9]
Definition: RegularGrid.h:29
Node & getGridFor(float fx, float fy)
Definition: RegularGrid.h:160

References NodeArray< Node >::_nodes, NodeArray< Node >::AddNode(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::ComputeCell(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::getGridFor(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::isValid(), and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::memberTable.

Referenced by DynTreeImpl::insert().

◆ intersectPoint()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
template<typename IsectCallback >
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectPoint ( const G3D::Vector3 &  point,
IsectCallback &  intersectCallback 
)
inline

◆ intersectRay() [1/2]

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
template<typename RayCallback >
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay ( const G3D::Ray &  ray,
RayCallback &  intersectCallback,
float &  max_dist,
const G3D::Vector3 &  end,
bool  stopAtFirstHit 
)
inline
184 {
185 Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
186 if (!cell.isValid())
187 {
188 return;
189 }
190
191 Cell last_cell = Cell::ComputeCell(end.x, end.y);
192
193 if (cell == last_cell)
194 {
195 if (Node* node = nodes[cell.x][cell.y])
196 {
197 node->intersectRay(ray, intersectCallback, max_dist, stopAtFirstHit);
198 }
199 return;
200 }
201
202 float voxel = (float)CELL_SIZE;
203 float kx_inv = ray.invDirection().x, bx = ray.origin().x;
204 float ky_inv = ray.invDirection().y, by = ray.origin().y;
205
206 int stepX, stepY;
207 float tMaxX, tMaxY;
208 if (kx_inv >= 0)
209 {
210 stepX = 1;
211 float x_border = (cell.x + 1) * voxel;
212 tMaxX = (x_border - bx) * kx_inv;
213 }
214 else
215 {
216 stepX = -1;
217 float x_border = (cell.x - 1) * voxel;
218 tMaxX = (x_border - bx) * kx_inv;
219 }
220
221 if (ky_inv >= 0)
222 {
223 stepY = 1;
224 float y_border = (cell.y + 1) * voxel;
225 tMaxY = (y_border - by) * ky_inv;
226 }
227 else
228 {
229 stepY = -1;
230 float y_border = (cell.y - 1) * voxel;
231 tMaxY = (y_border - by) * ky_inv;
232 }
233
234 //int Cycles = std::max((int)ceilf(max_dist/tMaxX),(int)ceilf(max_dist/tMaxY));
235 //int i = 0;
236
237 float tDeltaX = voxel * std::fabs(kx_inv);
238 float tDeltaY = voxel * std::fabs(ky_inv);
239 do
240 {
241 if (Node* node = nodes[cell.x][cell.y])
242 {
243 //float enterdist = max_dist;
244 node->intersectRay(ray, intersectCallback, max_dist, stopAtFirstHit);
245 }
246 if (cell == last_cell)
247 {
248 break;
249 }
250 if (tMaxX < tMaxY)
251 {
252 tMaxX += tDeltaX;
253 cell.x += stepX;
254 }
255 else
256 {
257 tMaxY += tDeltaY;
258 cell.y += stepY;
259 }
260 //++i;
261 } while (cell.isValid());
262 }
#define CELL_SIZE
Definition: RegularGrid.h:53

References CELL_SIZE, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::ComputeCell(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::isValid(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::x, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::y.

◆ intersectRay() [2/2]

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
template<typename RayCallback >
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay ( const G3D::Ray &  ray,
RayCallback &  intersectCallback,
float  max_dist,
bool  stopAtFirstHit 
)
inline
178 {
179 intersectRay(ray, intersectCallback, max_dist, ray.origin() + ray.direction() * max_dist, stopAtFirstHit);
180 }
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist, bool stopAtFirstHit)
Definition: RegularGrid.h:177

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay().

Referenced by DynamicMapTree::GetIntersectionTime(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectRay(), and DynamicMapTree::isInLineOfSight().

◆ intersectZAllignedRay()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
template<typename RayCallback >
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::intersectZAllignedRay ( const G3D::Ray &  ray,
RayCallback &  intersectCallback,
float &  max_dist 
)
inline
281 {
282 Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
283 if (!cell.isValid())
284 {
285 return;
286 }
287 if (Node* node = nodes[cell.x][cell.y])
288 {
289 node->intersectRay(ray, intersectCallback, max_dist, false);
290 }
291 }

References RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::ComputeCell(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::isValid(), RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes, RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::x, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::Cell::y.

Referenced by DynamicMapTree::getHeight().

◆ remove()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::remove ( const T &  value)
inline
115 {
116 NodeArray<Node>& na = memberTable[&value];
117 for (uint8 i = 0; i < 9; ++i)
118 {
119 if (na._nodes[i])
120 {
121 na._nodes[i]->remove(value);
122 }
123 else
124 {
125 break;
126 }
127 }
128
129 // Remove the member
130 memberTable.remove(&value);
131 }

References NodeArray< Node >::_nodes, and RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::memberTable.

Referenced by DynTreeImpl::remove().

◆ size()

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
int RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::size ( ) const
inline

Member Data Documentation

◆ memberTable

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
MemberTable RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::memberTable

◆ nodes