TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc > Class Template Reference

#include <RegularGrid.h>

Classes

struct  Cell
 

Public Types

enum  { CELL_NUMBER = 64 }
 
typedef G3D::Table< const T
*, 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)
 
template<typename RayCallback >
void intersectRay (const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist, const G3D::Vector3 &end)
 
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]
 

Member Typedef Documentation

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

Member Enumeration Documentation

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
anonymous enum
Enumerator
CELL_NUMBER 
27  {
28  CELL_NUMBER = 64,
29  };
Definition: RegularGrid.h:28

Constructor & Destructor Documentation

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::RegularGrid2D ( )
inline
39  {
40  memset(nodes, 0, sizeof(nodes));
41  }
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::~RegularGrid2D ( )
inline
43  {
44  for (int x = 0; x < CELL_NUMBER; ++x)
45  for (int y = 0; y < CELL_NUMBER; ++y)
46  delete nodes[x][y];
47  }
G3D::int16 y
Definition: Vector2int16.h:38
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
Definition: RegularGrid.h:28
G3D::int16 x
Definition: Vector2int16.h:37

Member Function Documentation

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::balance ( )
inline
66  {
67  for (int x = 0; x < CELL_NUMBER; ++x)
68  for (int y = 0; y < CELL_NUMBER; ++y)
69  if (Node* n = nodes[x][y])
70  n->balance();
71  }
G3D::int16 y
Definition: Vector2int16.h:38
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
Definition: RegularGrid.h:28
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the caller graph for this function:

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
73 { return memberTable.containsKey(&value); }
MemberTable memberTable
Definition: RegularGrid.h:36
const FieldDescriptor value
Definition: descriptor.h:1522
bool containsKey(const Key &key) const
Definition: Table.h:874

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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
98  {
100  if (!nodes[x][y])
101  nodes[x][y] = NodeCreatorFunc::makeNode(x, y);
102  return *nodes[x][y];
103  }
G3D::int16 y
Definition: Vector2int16.h:38
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
Definition: RegularGrid.h:28
#define ASSERT
Definition: Errors.h:55
G3D::int16 x
Definition: Vector2int16.h:37
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
92  {
93  Cell c = Cell::ComputeCell(fx, fy);
94  return getGrid(c.x, c.y);
95  }
static Cell ComputeCell(float fx, float fy)
Definition: RegularGrid.h:81
Node & getGrid(int x, int y)
Definition: RegularGrid.h:97
Definition: Cell.h:49
template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::insert ( const T &  value)
inline
50  {
51  G3D::Vector3 pos;
52  PositionFunc::getPosition(value, pos);
53  Node& node = getGridFor(pos.x, pos.y);
54  node.insert(value);
55  memberTable.set(&value, &node);
56  }
float x
Definition: Vector3.h:62
void set(const Key &key, const Value &value)
Definition: Table.h:599
float y
Definition: Vector3.h:62
Definition: Vector3.h:58
Node & getGridFor(float fx, float fy)
Definition: RegularGrid.h:91
MemberTable memberTable
Definition: RegularGrid.h:36
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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
189  {
190  Cell cell = Cell::ComputeCell(point.x, point.y);
191  if (!cell.isValid())
192  return;
193  if (Node* node = nodes[cell.x][cell.y])
194  node->intersectPoint(point, intersectCallback);
195  }
static Cell ComputeCell(float fx, float fy)
Definition: RegularGrid.h:81
float x
Definition: Vector3.h:62
float y
Definition: Vector3.h:62
Definition: Cell.h:49
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37

+ Here is the call graph for this function:

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 
)
inline
107  {
108  intersectRay(ray, intersectCallback, max_dist, ray.origin() + ray.direction() * max_dist);
109  }
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist)
Definition: RegularGrid.h:106
const Point3 & origin() const
Definition: Ray.h:56
const Vector3 & direction() const
Definition: Ray.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 
)
inline
113  {
114  Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
115  if (!cell.isValid())
116  return;
117 
118  Cell last_cell = Cell::ComputeCell(end.x, end.y);
119 
120  if (cell == last_cell)
121  {
122  if (Node* node = nodes[cell.x][cell.y])
123  node->intersectRay(ray, intersectCallback, max_dist);
124  return;
125  }
126 
127  float voxel = (float)CELL_SIZE;
128  float kx_inv = ray.invDirection().x, bx = ray.origin().x;
129  float ky_inv = ray.invDirection().y, by = ray.origin().y;
130 
131  int stepX, stepY;
132  float tMaxX, tMaxY;
133  if (kx_inv >= 0)
134  {
135  stepX = 1;
136  float x_border = (cell.x+1) * voxel;
137  tMaxX = (x_border - bx) * kx_inv;
138  }
139  else
140  {
141  stepX = -1;
142  float x_border = (cell.x-1) * voxel;
143  tMaxX = (x_border - bx) * kx_inv;
144  }
145 
146  if (ky_inv >= 0)
147  {
148  stepY = 1;
149  float y_border = (cell.y+1) * voxel;
150  tMaxY = (y_border - by) * ky_inv;
151  }
152  else
153  {
154  stepY = -1;
155  float y_border = (cell.y-1) * voxel;
156  tMaxY = (y_border - by) * ky_inv;
157  }
158 
159  //int Cycles = std::max((int)ceilf(max_dist/tMaxX),(int)ceilf(max_dist/tMaxY));
160  //int i = 0;
161 
162  float tDeltaX = voxel * std::fabs(kx_inv);
163  float tDeltaY = voxel * std::fabs(ky_inv);
164  do
165  {
166  if (Node* node = nodes[cell.x][cell.y])
167  {
168  //float enterdist = max_dist;
169  node->intersectRay(ray, intersectCallback, max_dist);
170  }
171  if (cell == last_cell)
172  break;
173  if (tMaxX < tMaxY)
174  {
175  tMaxX += tDeltaX;
176  cell.x += stepX;
177  }
178  else
179  {
180  tMaxY += tDeltaY;
181  cell.y += stepY;
182  }
183  //++i;
184  } while (cell.isValid());
185  }
static Cell ComputeCell(float fx, float fy)
Definition: RegularGrid.h:81
#define CELL_SIZE
Definition: RegularGrid.h:32
float x
Definition: Vector3.h:62
float y
Definition: Vector3.h:62
const Vector3 & invDirection() const
Definition: Ray.h:66
Definition: Cell.h:49
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
const Point3 & origin() const
Definition: Ray.h:56

+ Here is the call graph for this function:

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
200  {
201  Cell cell = Cell::ComputeCell(ray.origin().x, ray.origin().y);
202  if (!cell.isValid())
203  return;
204  if (Node* node = nodes[cell.x][cell.y])
205  node->intersectRay(ray, intersectCallback, max_dist);
206  }
static Cell ComputeCell(float fx, float fy)
Definition: RegularGrid.h:81
float x
Definition: Vector3.h:62
float y
Definition: Vector3.h:62
Definition: Cell.h:49
Node * nodes[CELL_NUMBER][CELL_NUMBER]
Definition: RegularGrid.h:37
const Point3 & origin() const
Definition: Ray.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
void RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::remove ( const T &  value)
inline
59  {
61  // Remove the member
63  }
bool remove(const Key &key, Key &removedKey, Value &removedValue, bool updateRemoved)
Definition: Table.h:606
MemberTable memberTable
Definition: RegularGrid.h:36
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
int RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::size ( ) const
inline
74 { return uint32(memberTable.size()); }
size_t size() const
Definition: Table.h:589
MemberTable memberTable
Definition: RegularGrid.h:36
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
MemberTable RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::memberTable
template<class T , class Node , class NodeCreatorFunc = NodeCreator<Node>, class PositionFunc = PositionTrait<T>>
Node* RegularGrid2D< T, Node, NodeCreatorFunc, PositionFunc >::nodes[CELL_NUMBER][CELL_NUMBER]

The documentation for this class was generated from the following file: