1 #ifndef _REGULAR_GRID_H
2 #define _REGULAR_GRID_H
14 static Node *
makeNode(
int ,
int ) {
return new Node();}
31 #define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed
32 #define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER)
37 Node* nodes[CELL_NUMBER][CELL_NUMBER];
40 memset(nodes, 0,
sizeof(nodes));
44 for (
int x = 0;
x < CELL_NUMBER; ++
x)
45 for (
int y = 0;
y < CELL_NUMBER; ++
y)
52 PositionFunc::getPosition(value, pos);
53 Node& node = getGridFor(pos.
x, pos.
y);
55 memberTable.
set(&value, &node);
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])
87 bool isValid()
const {
return x >= 0 && x < CELL_NUMBER && y >= 0 && y < CELL_NUMBER;}
93 Cell c = Cell::ComputeCell(fx, fy);
94 return getGrid(c.
x, c.
y);
99 ASSERT(x < CELL_NUMBER && y < CELL_NUMBER);
101 nodes[
x][
y] = NodeCreatorFunc::makeNode(x, y);
105 template<
typename RayCallback>
108 intersectRay(ray, intersectCallback, max_dist, ray.
origin() + ray.
direction() * max_dist);
111 template<
typename RayCallback>
118 Cell last_cell = Cell::ComputeCell(end.
x, end.
y);
120 if (cell == last_cell)
122 if (Node* node = nodes[cell.
x][cell.
y])
123 node->intersectRay(ray, intersectCallback, max_dist);
136 float x_border = (cell.
x+1) * voxel;
137 tMaxX = (x_border - bx) * kx_inv;
142 float x_border = (cell.
x-1) * voxel;
143 tMaxX = (x_border - bx) * kx_inv;
149 float y_border = (cell.
y+1) * voxel;
150 tMaxY = (y_border - by) * ky_inv;
155 float y_border = (cell.
y-1) * voxel;
156 tMaxY = (y_border - by) * ky_inv;
162 float tDeltaX = voxel * std::fabs(kx_inv);
163 float tDeltaY = voxel * std::fabs(ky_inv);
166 if (Node* node = nodes[cell.
x][cell.
y])
169 node->intersectRay(ray, intersectCallback, max_dist);
171 if (cell == last_cell)
187 template<
typename IsectCallback>
190 Cell cell = Cell::ComputeCell(point.
x, point.
y);
193 if (Node* node = nodes[cell.
x][cell.
y])
194 node->intersectPoint(point, intersectCallback);
198 template<
typename RayCallback>
204 if (Node* node = nodes[cell.
x][cell.
y])
205 node->intersectRay(ray, intersectCallback, max_dist);
210 #undef HGRID_MAP_SIZE
int y
Definition: RegularGrid.h:78
static Cell ComputeCell(float fx, float fy)
Definition: RegularGrid.h:81
int x
Definition: RegularGrid.h:78
#define CELL_SIZE
Definition: RegularGrid.h:32
Node & getGrid(int x, int y)
Definition: RegularGrid.h:97
float x
Definition: Vector3.h:62
size_t size() const
Definition: Table.h:589
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float max_dist)
Definition: RegularGrid.h:106
Definition: PositionTrait.h:5
static Node * makeNode(int, int)
Definition: RegularGrid.h:14
void intersectPoint(const G3D::Vector3 &point, IsectCallback &intersectCallback)
Definition: RegularGrid.h:188
void set(const Key &key, const Value &value)
Definition: Table.h:599
G3D::Table< const T *, Node * > MemberTable
Definition: RegularGrid.h:34
float y
Definition: Vector3.h:62
void intersectRay(const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist, const G3D::Vector3 &end)
Definition: RegularGrid.h:112
bool isValid() const
Definition: RegularGrid.h:87
~RegularGrid2D()
Definition: RegularGrid.h:43
void balance()
Definition: RegularGrid.h:65
bool remove(const Key &key, Key &removedKey, Value &removedValue, bool updateRemoved)
Definition: Table.h:606
bool operator==(const CoordPair< LIMIT > &p1, const CoordPair< LIMIT > &p2)
Definition: GridDefines.h:160
G3D::int16 y
Definition: Vector2int16.h:38
const Vector3 & invDirection() const
Definition: Ray.h:66
#define TC_COMMON_API
Definition: Define.h:116
Node & getGridFor(float fx, float fy)
Definition: RegularGrid.h:91
Definition: RegularGrid.h:13
void intersectZAllignedRay(const G3D::Ray &ray, RayCallback &intersectCallback, float &max_dist)
Definition: RegularGrid.h:199
MemberTable memberTable
Definition: RegularGrid.h:36
const Point3 & origin() const
Definition: Ray.h:56
Definition: RegularGrid.h:76
void insert(const T &value)
Definition: RegularGrid.h:49
bool contains(const T &value) const
Definition: RegularGrid.h:73
int size() const
Definition: RegularGrid.h:74
RegularGrid2D()
Definition: RegularGrid.h:39
#define ASSERT
Definition: Errors.h:55
const FieldDescriptor value
Definition: descriptor.h:1522
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37
Definition: RegularGrid.h:23
const Vector3 & direction() const
Definition: Ray.h:61
bool containsKey(const Key &key) const
Definition: Table.h:874