TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node Class Reference

#include <PointKDTree.h>

Public Member Functions

 Node ()
 
 Node (const Node &other)
 
 Node (const Array< Handle > &pt)
 
 ~Node ()
 
bool isLeaf () const
 
void getHandles (Array< Handle > &handleArray) const
 
void verifyNode (const Vector3 &lo, const Vector3 &hi)
 
NodefindDeepestContainingNode (const Vector3 &point)
 
void getIntersectingMembers (const AABox &sphereBounds, const Sphere &sphere, Array< T > &members) const
 
void getIntersectingMembers (const AABox &box, const Sphere &sphere, Array< T > &members, bool useSphere) const
 
void assignSplitBounds (const AABox &myBounds)
 

Static Public Member Functions

static void serializeStructure (const Node *n, BinaryOutput &bo)
 
static NodedeserializeStructure (BinaryInput &bi)
 

Public Attributes

AABox splitBounds
 
Vector3::Axis splitAxis
 
float splitLocation
 
Nodechild [2]
 
Array< HandlevalueArray
 

Constructor & Destructor Documentation

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::Node ( )
inline

Creates node with NULL children

176  {
178  splitLocation = 0;
179  splitBounds = AABox(-Vector3::inf(), Vector3::inf());
180  for (int i = 0; i < 2; ++i) {
181  child[i] = NULL;
182  }
183  }
Definition: Vector3.h:122
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
static const Vector3 & inf()
Definition: Vector3.cpp:124
AABox splitBounds
Definition: PointKDTree.h:154

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::Node ( const Node other)
inline

Doesn't clone children.

188  : valueArray(other.valueArray) {
189  splitAxis = other.splitAxis;
190  splitLocation = other.splitLocation;
191  splitBounds = other.splitBounds;
192  for (int i = 0; i < 2; ++i) {
193  child[i] = NULL;
194  }
195  }
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
Array< Handle > valueArray
Definition: PointKDTree.h:173
AABox splitBounds
Definition: PointKDTree.h:154
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::Node ( const Array< Handle > &  pt)
inline

Copies the specified subarray of pt into point, NULLs the children. Assumes a second pass will set splitBounds.

199  {
201  splitLocation = 0;
202  for (int i = 0; i < 2; ++i) {
203  child[i] = NULL;
204  }
205  valueArray = pt;
206  }
Definition: Vector3.h:122
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
Array< Handle > valueArray
Definition: PointKDTree.h:173
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::~Node ( )
inline

Deletes the children (but not the values)

210  {
211  for (int i = 0; i < 2; ++i) {
212  delete child[i];
213  }
214  }
Node * child[2]
Definition: PointKDTree.h:170

Member Function Documentation

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::assignSplitBounds ( const AABox myBounds)
inline

Recurse through the tree, assigning splitBounds fields.

397  {
398  splitBounds = myBounds;
399 
400 # ifdef G3D_DEBUG
401  if (child[0] || child[1]) {
404  }
405 # endif
406 
407  AABox childBounds[2];
408  myBounds.split(splitAxis, splitLocation, childBounds[0], childBounds[1]);
409 
410  for (int c = 0; c < 2; ++c) {
411  if (child[c]) {
412  child[c]->assignSplitBounds(childBounds[c]);
413  }
414  }
415  }
float splitLocation
Definition: PointKDTree.h:159
const Point3 & low() const
Definition: AABox.h:136
#define debugAssert(exp)
Definition: debugAssert.h:160
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
const Point3 & high() const
Definition: AABox.h:141
void assignSplitBounds(const AABox &myBounds)
Definition: PointKDTree.h:397
AABox splitBounds
Definition: PointKDTree.h:154

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
static Node* G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::deserializeStructure ( BinaryInput bi)
inlinestatic

Clears the member table

291  {
292  if (bi.readUInt8() == 0) {
293  return NULL;
294  } else {
295  Node* n = new Node();
296  n->splitBounds.deserialize(bi);
297  deserialize(n->splitAxis, bi);
298  n->splitLocation = bi.readFloat32();
299  for (int c = 0; c < 2; ++c) {
300  n->child[c] = deserializeStructure(bi);
301  }
302  return n;
303  }
304  }
static Node * deserializeStructure(BinaryInput &bi)
Definition: PointKDTree.h:291
arena_t NULL
Definition: jemalloc_internal.h:624
void deserialize(std::string &s, BinaryInput &b)
Definition: serialize.h:16
Node()
Definition: PointKDTree.h:176

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Node* G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::findDeepestContainingNode ( const Vector3 point)
inline

Returns the deepest node that completely contains bounds.

307  {
308 
309  // See which side of the splitting plane the bounds are on
310  if (point[splitAxis] < splitLocation) {
311  // Point is on the low side. Recurse into the child
312  // if it exists.
313  if (child[0] != NULL) {
314  return child[0]->findDeepestContainingNode(point);
315  }
316  } else if (point[splitAxis] > splitLocation) {
317  // Point is on the high side, recurse into the child
318  // if it exists.
319  if (child[1] != NULL) {
320  return child[1]->findDeepestContainingNode(point);
321  }
322  }
323 
324  // There was no containing child, so this node is the
325  // deepest containing node.
326  return this;
327  }
Node * findDeepestContainingNode(const Vector3 &point)
Definition: PointKDTree.h:307
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::getHandles ( Array< Handle > &  handleArray) const
inline

Recursively appends all handles and children's handles to the array.

227  {
228  handleArray.append(valueArray);
229  for (int i = 0; i < 2; ++i) {
230  if (child[i] != NULL) {
231  child[i]->getHandles(handleArray);
232  }
233  }
234  }
arena_t NULL
Definition: jemalloc_internal.h:624
void getHandles(Array< Handle > &handleArray) const
Definition: PointKDTree.h:227
Node * child[2]
Definition: PointKDTree.h:170
Array< Handle > valueArray
Definition: PointKDTree.h:173

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::getIntersectingMembers ( const AABox sphereBounds,
const Sphere sphere,
Array< T > &  members 
) const
inline

Appends all members that intersect the box. If useSphere is true, members are tested against the sphere instead.

334  {
335 
336  // Test all values at this node. Extract the
337  // underlying C array for speed
338  const int N = valueArray.size();
339  const Handle* handleArray = valueArray.getCArray();
340 
341  const float r2 = square(sphere.radius);
342 
343  // Copy the sphere center so that it is on the stack near the radius
344  const Vector3 center = sphere.center;
345  for (int v = 0; v < N; ++v) {
346  if ((center - handleArray[v].position()).squaredLength() <= r2) {
347  members.append(handleArray[v].value);
348  }
349  }
350 
351  // If the left child overlaps the box, recurse into it
352  if (child[0] && (sphereBounds.low()[splitAxis] < splitLocation)) {
353  child[0]->getIntersectingMembers(sphereBounds, sphere, members);
354  }
355 
356  // If the right child overlaps the box, recurse into it
357  if (child[1] && (sphereBounds.high()[splitAxis] > splitLocation)) {
358  child[1]->getIntersectingMembers(sphereBounds, sphere, members);
359  }
360  }
float splitLocation
Definition: PointKDTree.h:159
void getIntersectingMembers(const AABox &sphereBounds, const Sphere &sphere, Array< T > &members) const
Definition: PointKDTree.h:331
double square(double fValue)
Definition: g3dmath.h:698
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
const FieldDescriptor value
Definition: descriptor.h:1522
void append(const T &value)
Definition: Array.h:583
Array< Handle > valueArray
Definition: PointKDTree.h:173

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::getIntersectingMembers ( const AABox box,
const Sphere sphere,
Array< T > &  members,
bool  useSphere 
) const
inline

Appends all members that intersect the box. If useSphere is true, members are tested against the sphere instead.

Implemented using both box and sphere tests to simplify the implementation of a future beginSphereInteresection iterator using the same underlying BoxIterator class.

373  {
374 
375  // Test all values at this node
376  for (int v = 0; v < valueArray.size(); ++v) {
377  if ((useSphere && sphere.contains(valueArray[v].position())) ||
378  (! useSphere && box.contains(valueArray[v].position()))) {
379  members.append(valueArray[v].value);
380  }
381  }
382 
383  // If the left child overlaps the box, recurse into it
384  if ((child[0] != NULL) && (box.low()[splitAxis] < splitLocation)) {
385  child[0]->getIntersectingMembers(box, sphere, members, useSphere);
386  }
387 
388  // If the right child overlaps the box, recurse into it
389  if ((child[1] != NULL) && (box.high()[splitAxis] > splitLocation)) {
390  child[1]->getIntersectingMembers(box, sphere, members, useSphere);
391  }
392  }
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
void getIntersectingMembers(const AABox &sphereBounds, const Sphere &sphere, Array< T > &members) const
Definition: PointKDTree.h:331
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
const FieldDescriptor value
Definition: descriptor.h:1522
void append(const T &value)
Definition: Array.h:583
Array< Handle > valueArray
Definition: PointKDTree.h:173

+ Here is the call graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
bool G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::isLeaf ( ) const
inline

Returns true if this node is a leaf (no children)

218  {
219  return (child[0] == NULL) && (child[1] == NULL);
220  }
arena_t NULL
Definition: jemalloc_internal.h:624
Node * child[2]
Definition: PointKDTree.h:170
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
static void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::serializeStructure ( const Node n,
BinaryOutput bo 
)
inlinestatic

Stores the locations of the splitting planes (the structure but not the content) so that the tree can be quickly rebuilt from a previous configuration without calling balance.

276  {
277  if (n == NULL) {
278  bo.writeUInt8(0);
279  } else {
280  bo.writeUInt8(1);
281  n->splitBounds.serialize(bo);
282  serialize(n->splitAxis, bo);
283  bo.writeFloat32(n->splitLocation);
284  for (int c = 0; c < 2; ++c) {
285  serializeStructure(n->child[c], bo);
286  }
287  }
288  }
static void serializeStructure(const Node *n, BinaryOutput &bo)
Definition: PointKDTree.h:276
arena_t NULL
Definition: jemalloc_internal.h:624
void serialize(const std::string &s, BinaryOutput &b)
Definition: serialize.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
void G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::verifyNode ( const Vector3 lo,
const Vector3 hi 
)
inline
237  {
238  // debugPrintf("Verifying: split %d @ %f [%f, %f, %f], [%f, %f, %f]\n",
239  // splitAxis, splitLocation, lo.x, lo.y, lo.z, hi.x, hi.y, hi.z);
240 
241  debugAssert(lo == splitBounds.low());
242  debugAssert(hi == splitBounds.high());
243 
244 # ifdef G3D_DEBUG
245  for (int i = 0; i < valueArray.length(); ++i) {
246  const Vector3& b = valueArray[i].position();
248  }
249 # endif
250 
251  if (child[0] || child[1]) {
254  }
255 
256  Vector3 newLo = lo;
257  newLo[splitAxis] = splitLocation;
258  Vector3 newHi = hi;
259  newHi[splitAxis] = splitLocation;
260 
261  if (child[0] != NULL) {
262  child[0]->verifyNode(lo, newHi);
263  }
264 
265  if (child[1] != NULL) {
266  child[1]->verifyNode(newLo, hi);
267  }
268  }
float splitLocation
Definition: PointKDTree.h:159
bool contains(const AABox &other) const
Definition: AABox.h:238
arena_t NULL
Definition: jemalloc_internal.h:624
const Point3 & low() const
Definition: AABox.h:136
#define debugAssert(exp)
Definition: debugAssert.h:160
Node * child[2]
Definition: PointKDTree.h:170
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
void verifyNode(const Vector3 &lo, const Vector3 &hi)
Definition: PointKDTree.h:237
const Point3 & high() const
Definition: AABox.h:141
Array< Handle > valueArray
Definition: PointKDTree.h:173
AABox splitBounds
Definition: PointKDTree.h:154

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Node* G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::child[2]

child[0] contains all values strictly smaller than splitLocation along splitAxis.

child[1] contains all values strictly larger.

Both may be NULL if there are not enough values to bother recursing.

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Vector3::Axis G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::splitAxis
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
AABox G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::splitBounds

Spatial bounds on all values at this node and its children, based purely on the parent's splitting planes. May be infinite

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
float G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::splitLocation

Location along the specified axis

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Array<Handle> G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::Node::valueArray

Values if this is a leaf node).


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