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

#include <PointKDTree.h>

Public Member Functions

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

Private Member Functions

 BoxIntersectionIterator ()
 
 BoxIntersectionIterator (const AABox &b, const Node *root)
 

Private Attributes

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

Friends

class TreeType
 

Detailed Description

template<class T, class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
class G3D::PointKDTree< T, PositionFunc, 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 PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::BoxIntersectionIterator ( )
inlineprivate
913 : isEnd(true) {}
bool isEnd
Definition: PointKDTree.h:893
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::BoxIntersectionIterator ( const AABox b,
const Node root 
)
inlineprivate
915  :
916  isEnd(root == NULL), box(b),
917  node(const_cast<Node*>(root)), nextValueArrayIndex(-1) {
918 
919  // We intentionally start at the "-1" index of the current
920  // node so we can use the preincrement operator to move
921  // ourselves to element 0 instead of repeating all of the
922  // code from the preincrement method. Note that this might
923  // cause us to become the "end" instance.
924  ++(*this);
925  }
Node * root
Definition: PointKDTree.h:564
int nextValueArrayIndex
Definition: PointKDTree.h:911
arena_t NULL
Definition: jemalloc_internal.h:624
Node * node
Definition: PointKDTree.h:900
AABox box
Definition: PointKDTree.h:896
bool isEnd
Definition: PointKDTree.h:893

Member Function Documentation

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

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

1041  {
1042  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1043  return &(stack.last()->valueArray[nextValueArrayIndex].value);
1044  }
int nextValueArrayIndex
Definition: PointKDTree.h:911
Array< Node * > stack
Definition: PointKDTree.h:907
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
bool isEnd
Definition: PointKDTree.h:893

+ 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 >::BoxIntersectionIterator::operator!= ( const BoxIntersectionIterator other) const
inline
929  {
930  return ! (*this == other);
931  }
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
const T& G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator* ( ) const
inline

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

1027  {
1028  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1029  return node->valueArray[nextValueArrayIndex].value;
1030  }
int nextValueArrayIndex
Definition: PointKDTree.h:911
Node * node
Definition: PointKDTree.h:900
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
bool isEnd
Definition: PointKDTree.h:893
Array< Handle > valueArray
Definition: PointKDTree.h:173
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
BoxIntersectionIterator& G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator++ ( )
inline

Pre increment.

963  {
965 
966  bool foundIntersection = false;
967  while (! isEnd && ! foundIntersection) {
968 
969  // Search for the next node if we've exhausted this one
970  while ((! isEnd) && (nextValueArrayIndex >= node->valueArray.length())) {
971  // If we entered this loop, then the iterator has exhausted the elements at
972  // node (possibly because it just switched to a child node with no members).
973  // This loop continues until it finds a node with members or reaches
974  // the end of the whole intersection search.
975 
976  // If the right child overlaps the box, push it onto the stack for
977  // processing.
978  if ((node->child[1] != NULL) &&
980  stack.push(node->child[1]);
981  }
982 
983  // If the left child overlaps the box, push it onto the stack for
984  // processing.
985  if ((node->child[0] != NULL) &&
986  (box.low()[node->splitAxis] < node->splitLocation)) {
987  stack.push(node->child[0]);
988  }
989 
990  if (stack.length() > 0) {
991  // Go on to the next node (which may be either one of the ones we
992  // just pushed, or one from farther back the tree).
993  node = stack.pop();
995  } else {
996  // That was the last node; we're done iterating
997  isEnd = true;
998  }
999  }
1000 
1001  // Search for the next intersection at this node until we run out of children
1002  while (! isEnd && ! foundIntersection && (nextValueArrayIndex < node->valueArray.length())) {
1004  foundIntersection = true;
1005  } else {
1007  // If we exhaust this node, we'll loop around the master loop
1008  // to find a new node.
1009  }
1010  }
1011  }
1012 
1013  return *this;
1014  }
bool intersects(const AABox &other) const
Definition: AABox.cpp:175
int nextValueArrayIndex
Definition: PointKDTree.h:911
float splitLocation
Definition: PointKDTree.h:159
arena_t NULL
Definition: jemalloc_internal.h:624
const Point3 & low() const
Definition: AABox.h:136
Node * node
Definition: PointKDTree.h:900
Node * child[2]
Definition: PointKDTree.h:170
Array< Node * > stack
Definition: PointKDTree.h:907
Vector3::Axis splitAxis
Definition: PointKDTree.h:156
AABox box
Definition: PointKDTree.h:896
const Point3 & high() const
Definition: AABox.h:141
bool isEnd
Definition: PointKDTree.h:893
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>>
BoxIntersectionIterator G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator++ ( int  )
inline

Post increment (much slower than preincrement!).

1019  {
1020  BoxIntersectionIterator old = *this;
1021  ++this;
1022  return old;
1023  }
BoxIntersectionIterator()
Definition: PointKDTree.h:913
template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
T const* G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::operator-> ( ) const
inline

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

1034  {
1035  alwaysAssertM(! isEnd, "Can't dereference the end element of an iterator");
1036  return &(stack.last()->valueArray[nextValueArrayIndex].value);
1037  }
int nextValueArrayIndex
Definition: PointKDTree.h:911
Array< Node * > stack
Definition: PointKDTree.h:907
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
bool isEnd
Definition: PointKDTree.h:893

+ 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 >::BoxIntersectionIterator::operator== ( const BoxIntersectionIterator other) const
inline
933  {
934  if (isEnd) {
935  return other.isEnd;
936  } else if (other.isEnd) {
937  return false;
938  } else {
939  // Two non-end iterators; see if they match. This is kind of
940  // silly; users shouldn't call == on iterators in general unless
941  // one of them is the end iterator.
942  if ((box != other.box) || (node != other.node) ||
943  (nextValueArrayIndex != other.nextValueArrayIndex) ||
944  (stack.length() != other.stack.length())) {
945  return false;
946  }
947 
948  // See if the stacks are the same
949  for (int i = 0; i < stack.length(); ++i) {
950  if (stack[i] != other.stack[i]) {
951  return false;
952  }
953  }
954 
955  // We failed to find a difference; they must be the same
956  return true;
957  }
958  }
int nextValueArrayIndex
Definition: PointKDTree.h:911
Node * node
Definition: PointKDTree.h:900
Array< Node * > stack
Definition: PointKDTree.h:907
AABox box
Definition: PointKDTree.h:896
bool isEnd
Definition: PointKDTree.h:893

+ Here is the call graph for this function:

Friends And Related Function Documentation

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
friend class TreeType
friend

Member Data Documentation

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
AABox G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::box
private

The box that we're testing against.

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
bool G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::isEnd
private

True if this is the "end" iterator instance

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
int G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::nextValueArrayIndex
private

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

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Node* G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::node
private

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

template<class T , class PositionFunc = PositionTrait<T>, class HashFunc = HashTrait<T>, class EqualsFunc = EqualsTrait<T>>
Array<Node*> G3D::PointKDTree< T, PositionFunc, HashFunc, EqualsFunc >::BoxIntersectionIterator::stack
private

Nodes waiting to be processed


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