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

#include <KDTree.h>

Public Member Functions

bool operator!= (const BoxIntersectionIterator &other) const
 
bool operator== (const BoxIntersectionIterator &other) const
 
BoxIntersectionIteratoroperator++ ()
 
const T & operator* () const
 
T constoperator-> () const
 
 operator T * () const
 

Private Member Functions

 BoxIntersectionIterator ()
 
 BoxIntersectionIterator (const AABox &b, const Node *root)
 
BoxIntersectionIterator operator++ (int)
 

Private Attributes

bool isEnd
 
AABox box
 
Nodenode
 
Array< Node * > stack
 
int nextValueArrayIndex
 

Friends

class TreeType
 

Detailed Description

template<class T, class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
class G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator

C++ STL style iterator variable. See beginBoxIntersection(). The iterator overloads the -> (dereference) operator, so this acts like a pointer to the current member.

Constructor & Destructor Documentation

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::BoxIntersectionIterator ( )
inlineprivate
1278 : isEnd(true) {}
bool isEnd
Definition: KDTree.h:1258
template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::BoxIntersectionIterator ( const AABox b,
const Node root 
)
inlineprivate
1280  :
1281  isEnd(root == NULL), box(b),
1282  node(const_cast<Node*>(root)), nextValueArrayIndex(-1) {
1283 
1284  // We intentionally start at the "-1" index of the current
1285  // node so we can use the preincrement operator to move
1286  // ourselves to element 0 instead of repeating all of the
1287  // code from the preincrement method. Note that this might
1288  // cause us to become the "end" instance.
1289  ++(*this);
1290  }
int nextValueArrayIndex
Definition: KDTree.h:1276
Node * root
Definition: KDTree.h:882
arena_t NULL
Definition: jemalloc_internal.h:624
Node * node
Definition: KDTree.h:1265
bool isEnd
Definition: KDTree.h:1258
AABox box
Definition: KDTree.h:1261

Member Function Documentation

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator T * ( ) const
inline

Overloaded cast operator so the iterator can masquerade as a pointer to a member

1411  {
1412  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1413  return &(stack.last()->valueArray[nextValueArrayIndex]->value);
1414  }
int nextValueArrayIndex
Definition: KDTree.h:1276
Array< Node * > stack
Definition: KDTree.h:1272
bool isEnd
Definition: KDTree.h:1258
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the call graph for this function:

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
bool G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator!= ( const BoxIntersectionIterator other) const
inline
1294  {
1295  return ! (*this == other);
1296  }
template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
const T& G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator* ( ) const
inline

Overloaded dereference operator so the iterator can masquerade as a pointer to a member

1397  {
1398  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1399  return node->valueArray[nextValueArrayIndex]->value;
1400  }
Array< Handle * > valueArray
Definition: KDTree.h:361
int nextValueArrayIndex
Definition: KDTree.h:1276
Node * node
Definition: KDTree.h:1265
bool isEnd
Definition: KDTree.h:1258
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
BoxIntersectionIterator& G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator++ ( )
inline

Pre increment.

1328  {
1330 
1331  bool foundIntersection = false;
1332  while (! isEnd && ! foundIntersection) {
1333 
1334  // Search for the next node if we've exhausted this one
1335  while ((! isEnd) && (nextValueArrayIndex >= node->valueArray.length())) {
1336  // If we entered this loop, then the iterator has exhausted the elements at
1337  // node (possibly because it just switched to a child node with no members).
1338  // This loop continues until it finds a node with members or reaches
1339  // the end of the whole intersection search.
1340 
1341  // If the right child overlaps the box, push it onto the stack for
1342  // processing.
1343  if ((node->child[1] != NULL) &&
1344  (box.high()[node->splitAxis] > node->splitLocation)) {
1345  stack.push(node->child[1]);
1346  }
1347 
1348  // If the left child overlaps the box, push it onto the stack for
1349  // processing.
1350  if ((node->child[0] != NULL) &&
1351  (box.low()[node->splitAxis] < node->splitLocation)) {
1352  stack.push(node->child[0]);
1353  }
1354 
1355  if (stack.length() > 0) {
1356  // Go on to the next node (which may be either one of the ones we
1357  // just pushed, or one from farther back the tree).
1358  node = stack.pop();
1359  nextValueArrayIndex = 0;
1360  } else {
1361  // That was the last node; we're done iterating
1362  isEnd = true;
1363  }
1364  }
1365 
1366  // Search for the next intersection at this node until we run out of children
1367  while (! isEnd && ! foundIntersection && (nextValueArrayIndex < node->valueArray.length())) {
1369  foundIntersection = true;
1370  } else {
1372  // If we exhaust this node, we'll loop around the master loop
1373  // to find a new node.
1374  }
1375  }
1376  }
1377 
1378  return *this;
1379  }
Array< Handle * > valueArray
Definition: KDTree.h:361
bool intersects(const AABox &other) const
Definition: AABox.cpp:175
int nextValueArrayIndex
Definition: KDTree.h:1276
Node * child[2]
Definition: KDTree.h:351
arena_t NULL
Definition: jemalloc_internal.h:624
const Point3 & low() const
Definition: AABox.h:136
Array< AABox > boundsArray
Definition: KDTree.h:369
Vector3::Axis splitAxis
Definition: KDTree.h:337
float splitLocation
Definition: KDTree.h:340
Node * node
Definition: KDTree.h:1265
Array< Node * > stack
Definition: KDTree.h:1272
bool isEnd
Definition: KDTree.h:1258
const Point3 & high() const
Definition: AABox.h:141
AABox box
Definition: KDTree.h:1261

+ Here is the call graph for this function:

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
BoxIntersectionIterator G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator++ ( int  )
private

Post increment (much slower than preincrement!). Intentionally overloaded to preclude accidentally slow code.

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
T const* G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator-> ( ) const
inline

Overloaded dereference operator so the iterator can masquerade as a pointer to a member

1404  {
1405  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1406  return &(stack.last()->valueArray[nextValueArrayIndex]->value);
1407  }
int nextValueArrayIndex
Definition: KDTree.h:1276
Array< Node * > stack
Definition: KDTree.h:1272
bool isEnd
Definition: KDTree.h:1258
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the call graph for this function:

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
bool G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator== ( const BoxIntersectionIterator other) const
inline
1298  {
1299  if (isEnd) {
1300  return other.isEnd;
1301  } else if (other.isEnd) {
1302  return false;
1303  } else {
1304  // Two non-end iterators; see if they match. This is kind of
1305  // silly; users shouldn't call == on iterators in general unless
1306  // one of them is the end iterator.
1307  if ((box != other.box) || (node != other.node) ||
1308  (nextValueArrayIndex != other.nextValueArrayIndex) ||
1309  (stack.length() != other.stack.length())) {
1310  return false;
1311  }
1312 
1313  // See if the stacks are the same
1314  for (int i = 0; i < stack.length(); ++i) {
1315  if (stack[i] != other.stack[i]) {
1316  return false;
1317  }
1318  }
1319 
1320  // We failed to find a difference; they must be the same
1321  return true;
1322  }
1323  }
int nextValueArrayIndex
Definition: KDTree.h:1276
Node * node
Definition: KDTree.h:1265
Array< Node * > stack
Definition: KDTree.h:1272
bool isEnd
Definition: KDTree.h:1258
AABox box
Definition: KDTree.h:1261

+ Here is the call graph for this function:

Friends And Related Function Documentation

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
friend class TreeType
friend

Member Data Documentation

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
AABox G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::box
private

The box that we're testing against.

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
bool G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::isEnd
private

True if this is the "end" iterator instance

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
int G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::nextValueArrayIndex
private

The next index of current->valueArray to return. Undefined when isEnd is true.

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Node* G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::node
private

Node that we're currently looking at. Undefined if isEnd is true.

template<class T , class BoundsFunc = BoundsTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Array<Node*> G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::stack
private

Nodes waiting to be processed


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