TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PointHashGrid.h
Go to the documentation of this file.
1 
11 #ifndef G3D_PointHashGrid_h
12 #define G3D_PointHashGrid_h
13 
14 #include "G3D/platform.h"
15 #include "G3D/EqualsTrait.h"
16 #include "G3D/HashTrait.h"
17 #include "G3D/Vector3.h"
18 #include "G3D/Vector3int32.h"
19 #include "G3D/Array.h"
20 #include "G3D/Table.h"
21 #include "G3D/AABox.h"
22 #include "G3D/Sphere.h"
23 #include "G3D/SmallArray.h"
24 
25 namespace G3D {
26 
91 template<class Value,
92  class PosFunc = PositionTrait<Value>,
93  class EqualsFunc = EqualsTrait<Value> >
95 private:
96 
97 # define expectedCellSize (10)
98 
99 # define ThisType PointHashGrid<Value, PosFunc, EqualsFunc>
100 
102  class Entry {
103  public:
106  };
107 
111 
114 
118  int m_epoch;
119 
121  float m_cellWidth;
122 
125 
128 
130  int m_size;
131 
134  CellTable m_data;
135 
137 
139  PointHashGrid(const ThisType&);
140 
141 
144 
145 
148  bool find
149  (const Value& v,
150  Point3int32& foundCellCoord,
151  Cell*& foundCell,
152  int& index) {
153 
154  Point3 pos;
155  PosFunc::getPosition(v, pos);
156 
157  Point3int32 cellCoord;
158  getCellCoord(pos, cellCoord);
159  for (int i = 0; i < 27; ++i) {
160  Point3int32 c = cellCoord + m_offsetArray[i];
161  Cell* cell = m_data.getPointer(c);
162  if (cell != NULL) {
163  // The cell exists
164  for (int j = 0; j < cell->size(); ++j) {
165  if (EqualsFunc::equals((*cell)[j].value, v)) {
166  foundCell = cell;
167  index = j;
168  foundCellCoord = c;
169  return true;
170  }
171  }
172  }
173  }
174 
175  // Not found
176  return false;
177  }
178 
179 public:
180 
186  inline void getCellCoord(const Point3& pos, Point3int32& cellCoord) const {
187  for (int a = 0; a < 3; ++a) {
188  cellCoord[a] = iFloor(pos[a] * m_invCellWidth);
189  }
190  }
191 
192 protected:
193 
196  int i = 0;
197  Point3int32 d;
198  for (d.x = -1; d.x <= +1; ++d.x) {
199  for (d.y = -1; d.y <= +1; ++d.y) {
200  for (d.z = -1; d.z <= +1; ++d.z) {
201  m_offsetArray[i] = d;
202  ++i;
203  }
204  }
205  }
206 
207  // Put (0, 0, 0) first, so that contains() is most likely to find
208  // the value quickly.
209  i = (1 * 3 + 1) * 3 + 1;
210  debugAssert(m_offsetArray[i] == Vector3int32(0,0,0));
211  Vector3int32 temp = m_offsetArray[0];
212  m_offsetArray[0] = m_offsetArray[i];
213  m_offsetArray[i] = temp;
214  }
215 
216 public:
217 
224  PointHashGrid(float radiusHint, const MemoryManager::Ref& m = MemoryManager::create()) : m_size(0), m_memoryManager(m) {
225  initOffsetArray();
226  m_data.clearAndSetMemoryManager(m_memoryManager);
227 
228  debugAssertM(radiusHint > 0, "Cell radius must be positive");
229  m_cellWidth = radiusHint;
230  m_invCellWidth = 1.0f / m_cellWidth;
231  }
232 
234  float radiusHint() const {
235  return m_cellWidth;
236  }
237 
238  void clear(float radiusHint) {
239  debugAssertM(radiusHint > 0, "Cell radius must be positive");
240  clear();
241  m_cellWidth = radiusHint;
242  m_invCellWidth = 1.0f / m_cellWidth;
243  }
244 
245  void clearAndSetRadiusHint(float radiusHint) {
246  return clear(radiusHint);
247  }
248 
256  PointHashGrid(const Array<Value>& init, float radiusHint = -1.0f, const MemoryManager::Ref& m = MemoryManager::create()) : m_size(0), m_memoryManager(m) {
257  initOffsetArray();
258  m_data.clearAndSetMemoryManager(m_memoryManager);
259 
260  Point3 lo(Vector3::inf());
261  Point3 hi(-lo);
262 
263  // Compute bounds
264  Array<Entry> entry(init.size());
265  for (int i = 0; i < entry.size(); ++i) {
266  const Value& value = init[i];
267  Point3 pos;
268 
269  entry[i].value = value;
270  entry[i].hashCode = m_hashFunc(value);
271  PosFunc::getPosition(value, entry[i].position);
272 
273  lo = lo.min(pos);
274  hi = hi.max(pos);
275  }
276 
277  m_bounds = AABox(lo, hi);
278 
279  if (radiusHint <= 0) {
280  // Compute a good cell width based on the bounds.
281  //
282  // N numPerCell
283  // ----- = ---------
284  // volume r^3
285 
286  float numPerCell = 5;
287  radiusHint =
288  (float)pow(numPerCell * m_bounds.volume() / init.size(), 1.0 / 3.0);
289 
290  if (radiusHint == 0) {
291  // Volume must have been zero because all points were colocated.
292  radiusHint = 0.1f;
293  }
294  }
295 
296  insert(init);
297  }
298 
300  int size() const {
301  return m_size;
302  }
303 
306  const AABox& conservativeBoxBounds() const {
307  return m_bounds;
308  }
309 
310  void debugPrintStatistics() const {
311  debugPrintf("Deepest bucket size = %d\n", (int)m_data.debugGetDeepestBucketSize());
312  debugPrintf("Average bucket size = %g\n", m_data.debugGetAverageBucketSize());
313  debugPrintf("Load factor = %g\n", m_data.debugGetLoad());
314  }
315 
319  void insert(const Value& v) {
320  Point3 pos;
321  PosFunc::getPosition(v, pos);
322  Point3int32 cellCoord;
323  getCellCoord(pos, cellCoord);
324 
325  // See if the cell already exists
326  Cell& cell = m_data.getCreate(cellCoord);
327 
328  if (cell.size() == 0) {
329  // Use the same memory manager as for the whole class
330  cell.clearAndSetMemoryManager(m_memoryManager);
331  }
332 
333  Entry& entry = cell.next();
334  entry.value = v;
335  entry.position = pos;
336 
337  // Update the bounds
338  if (size() == 0) {
339  m_bounds = AABox(pos);
340  } else {
341  m_bounds.merge(pos);
342  }
343 
344  ++m_size;
345  ++m_epoch;
346  }
347 
348 
350  void insert(const Array<Value>& v) {
351  for (int i = 0; i < v.size(); ++i) {
352  insert(v[i]);
353  }
354  }
355 
356 
366  bool remove(const Value& v, bool shrinkIfNecessary = true) {
367  Cell* cell = NULL;
368  int index = 0;
369  Vector3int32 cellCoord;
370 
371  if (find(v, cellCoord, cell, index)) {
372  cell->fastRemove(index, shrinkIfNecessary);
373  --m_size;
374  ++m_epoch;
375 
376  if ((cell->size() == 0) && shrinkIfNecessary) {
377  // Remove the cell itself
378 
379  // Drop our pointer, which is about to dangle
380  cell = NULL;
381  const bool success = m_data.remove(cellCoord);
382  (void)success;
383  debugAssertM(success, "Data structure corrupt: "
384  "tried to remove a cell that doesn't exist.");
385  }
386 
387  return true;
388 
389  } else {
390  return false;
391  }
392  }
393 
395  void remove(const Array<Value>& v, bool shrink = true) {
396  for (int i = 0; i < v.size(); ++i) {
397  remove(v[i], shrink);
398  }
399  }
400 
403 
404  class Iterator {
405  private:
406  friend class ThisType;
407 
408  bool m_isEnd;
409 
410  const ThisType* m_grid;
411 
412  typename CellTable::Iterator m_tableIterator;
413 
416 
417  const int m_epoch;
418 
422  Iterator() : m_isEnd(true), m_grid(NULL), m_tableIterator(CellTable().end()),
423  m_arrayIndex(0), m_epoch(0) {}
424 
425  Iterator(const ThisType* grid) :
426  m_isEnd(grid->size() == 0),
427  m_grid(grid),
428  m_tableIterator( grid->m_data.begin() ),
429  m_arrayIndex(0),
430  m_epoch(grid->m_epoch) { }
431 
432  private:
433 
434  const Value& value() const {
435  debugAssert(! m_isEnd);
436  debugAssertM(m_tableIterator->value.size() > m_arrayIndex,
437  "No more elements");
438  return m_tableIterator->value[m_arrayIndex].value;
439  }
440 
441  public:
442 
443  inline bool operator!=(const Iterator& other) const {
444  if (other.m_isEnd && m_isEnd) {
445  return false;
446  } else {
447  return (m_isEnd != other.m_isEnd) ||
448  (m_tableIterator != other.m_tableIterator) ||
449  (m_arrayIndex != other.m_arrayIndex);
450  }
451  }
452 
453  bool isValid() const {
454  return ! m_isEnd;
455  }
456 
458  bool hasMore() const {
459  return ! m_isEnd;
460  }
461 
462  bool operator==(const Iterator& other) const {
463  return !(*this != other);
464  }
465 
468  debugAssert(! m_isEnd);
469  debugAssertM(m_epoch == m_grid->m_epoch,
470  "It is illegal to mutate the HashGrid "
471  "while iterating through it.");
472 
473  ++m_arrayIndex;
474 
475  if (m_arrayIndex >= m_tableIterator->value.size()) {
476  // Move on to the next cell
477  ++m_tableIterator;
478  m_arrayIndex = 0;
479 
480  // Check to see if we're at the end
481  m_isEnd = (m_tableIterator == m_grid->m_data.end());
482  }
483 
484  return *this;
485  }
486 
489  debugAssert(! m_isEnd);
490  Iterator old = *this;
491  ++(*this);
492  return old;
493  }
494 
495  const Value& operator*() const { return value(); }
496  const Value* operator->() const { return &value(); }
497  operator Value*() const { return &value(); }
498  }; // Iterator
499 
500 
512  Iterator begin() const {
513  return Iterator(this);
514  }
515 
516  const Iterator& end() const {
517  static const Iterator it;
518  return it;
519  }
520 
523 
524  // Forward declaration required by older gcc versions for friend declaration in BoxIterator
525  class SphereIterator;
526  class BoxIterator {
527  private:
528  friend class ThisType;
529  friend class SphereIterator;
530 
531  bool m_isEnd;
532 
533  const ThisType* m_grid;
534 
537 
540 
542  bool m_exact;
543 
546 
551 
553  Cell* m_cell;
554 
557 
558  const int m_epoch;
559 
560 
562  void advanceCell() {
563  do {
564  ++m_current.x;
565  if (m_current.x > m_hi.x) {
566  m_current.x = m_lo.x;
567  ++m_current.y;
568  if (m_current.y > m_hi.y) {
569  m_current.y = m_lo.y;
570  ++m_current.z;
571  if (m_current.z > m_hi.z) {
572  m_isEnd = true;
573  return;
574  }
575  }
576  }
577 
578  // Pick up the new cell
579  m_cell = m_grid->m_data.getPointer(m_current);
580  // Keep advancing if the cell does not exist
581  } while ((m_cell == NULL) || (m_cell->size() == 0));
582  }
583 
585  void advance() {
586  debugAssert(! m_isEnd);
587 
588  do {
589  ++m_arrayIndex;
590  bool inConstructor = (m_cell == NULL);
591  if (inConstructor || m_arrayIndex >= m_cell->size()) {
592  advanceCell();
593  m_arrayIndex = 0;
594 
595  if (m_isEnd) {
596  // Ran out of values
597  return;
598  }
599  debugAssert(m_cell != NULL);
600  }
601 
602  // Advance until we have a value that can be returned, either
603  // because we don't care about exactness or because it is
604  // guaranteed to be within the box.
605  } while (m_exact && ! m_box.contains(position()));
606  }
607 
608 
610  BoxIterator() : m_isEnd(true), m_grid(NULL), m_exact(true), m_current(0,0,0), m_cell(NULL), m_arrayIndex(0), m_epoch(0) {}
611 
613  BoxIterator(const ThisType* grid, bool exact, const AABox& box) :
614  m_isEnd(false),
615  m_grid(grid),
616  m_exact(exact),
617  m_box(box),
618  m_current(-1, 0 ,0),
619  m_cell(NULL),
620  m_arrayIndex(0),
621  m_epoch(grid->m_epoch) {
622 
623  m_grid->getCellCoord(box.low(), m_lo);
624  m_grid->getCellCoord(box.high(), m_hi);
625 
626  // Get to the first value
627  m_current = m_lo;
628  // Back up one so that advancing takes us to the first
629  --m_current.x;
630  advance();
631  }
632 
633  const Value& value() const {
634  debugAssert(! m_isEnd);
635  return (*m_cell)[m_arrayIndex].value;
636  }
637 
639  const Vector3& position() const {
640  debugAssert(! m_isEnd);
641  return (*m_cell)[m_arrayIndex].position;
642  }
643 
644  // Intentionally unimplemented
646 
647  public:
648 
649  inline bool operator!=(const BoxIterator& other) const {
650  if (other.m_isEnd && m_isEnd) {
651  return false;
652  } else {
653  return (m_isEnd != other.m_isEnd) ||
654  (m_cell != other.m_cell) ||
655  (m_arrayIndex != other.m_arrayIndex);
656  }
657  }
658 
659  bool operator==(const BoxIterator& other) const {
660  return !(*this != other);
661  }
662 
665  debugAssert(! m_isEnd);
666  debugAssertM(m_epoch == m_grid->m_epoch,
667  "It is illegal to mutate the HashGrid "
668  "while iterating through it.");
669 
670  advance();
671 
672  return *this;
673  }
674 
677  Iterator old = *this;
678  ++(*this);
679  return old;
680  }
681 
682  const Value& operator*() const { return value(); }
683  const Value* operator->() const { return &value(); }
684  operator Value*() const { return &value(); }
685 
687  bool hasMore() const {
688  return ! m_isEnd;
689  }
690 
691  bool isValid() const {
692  return ! m_isEnd;
693  }
694  }; // BoxIterator
695 
704  BoxIterator beginBoxIntersection(const AABox& box, bool exact = true) const {
705  return BoxIterator(this, exact, box);
706  }
707 
708  const BoxIterator& endBoxIntersection() const {
709  static const BoxIterator it;
710  return it;
711  }
712 
715 
717  private:
718 
719  friend class ThisType;
720 
721  bool m_isEnd;
724 
725  SphereIterator() : m_isEnd(true) {}
726 
727  void advance() {
728  if (! m_boxIterator.isValid()) {
729  m_isEnd = true;
730  return;
731  }
732 
733  while (! m_sphere.contains(m_boxIterator.position())) {
734  ++m_boxIterator;
735 
736  if (! m_boxIterator.isValid()) {
737  m_isEnd = true;
738  return;
739  }
740  }
741  }
742 
743  static AABox getBoundingBox(const Sphere& s) {
744  AABox box;
745  s.getBounds(box);
746  return box;
747  }
748 
749  SphereIterator(const ThisType* grid, const Sphere& sphere) :
750  m_isEnd(false),
751  m_sphere(sphere),
752  m_boxIterator(grid, false, getBoundingBox(sphere)) {
753 
754  // Find the first element that is actually in the sphere,
755  // not just the box.
756  advance();
757  }
758 
759  const Value& value() const {
760  return *m_boxIterator;
761  }
762 
763  // TODO: if the sphere is very big compared to radius, check each
764  // cell's box to see if the cell itself is actually inside the sphere
765  // before iterating through it, since there may be many boxes outside the sphere.
766 
767  // Intentionally unimplemented
769 
770  public:
771 
772  inline bool operator!=(const SphereIterator& other) const {
773  if (other.m_isEnd && m_isEnd) {
774  return false;
775  } else {
776  return
777  (m_isEnd != other.m_isEnd) ||
778  (m_sphere != other.m_sphere) ||
779  (m_boxIterator != other.m_boxIterator);
780  }
781  }
782 
783  bool operator==(const SphereIterator& other) const {
784  return !(*this != other);
785  }
786 
789  debugAssert(! m_isEnd);
790 
791  ++m_boxIterator;
792  advance();
793 
794  return *this;
795  }
796 
799  Iterator old = *this;
800  ++(*this);
801  return old;
802  }
803 
804  const Value& operator*() const { return value(); }
805  const Value* operator->() const { return &value(); }
806  operator Value*() const { return &value(); }
807 
809  bool G3D_DEPRECATED hasMore() const {
810  return ! m_isEnd;
811  }
812 
813  bool isValid() const {
814  return ! m_isEnd;
815  }
816  }; // SphereIterator
817 
821  SphereIterator begin(const Sphere& sphere) const {
822  return SphereIterator(this, sphere);
823  }
824 
825 
827  SphereIterator G3D_DEPRECATED beginSphereIntersection(const Sphere& sphere) const {
828  return SphereIterator(this, sphere);
829  }
830 
831 
833  const SphereIterator& endSphereIntersection() const {
834  static const SphereIterator it;
835  return it;
836  }
837 
838 
840  void getIntersectingMembers(const Sphere& sphere, Array<Value>& result) const {
841  for (SphereIterator it = beginSphereIntersection(sphere); it.isValid(); ++it) {
842  result.append(*it);
843  }
844  }
845 
846 
849 
861  class CellIterator {
862  private:
863  friend class ThisType;
864 
865  bool m_isEnd;
866  const ThisType* m_grid;
867  typename CellTable::Iterator m_tableIterator;
868  const int m_epoch;
869 
870 
871  Cell& cell() {
872  return m_tableIterator->value;
873  }
874 
875  public:
876 
877  class CellObject {
878  friend class CellIterator;
879  private:
881 
882  CellObject() : m_parent(NULL) {}
883 
884  public:
885 
887  AABox bounds() const {
888  const Vector3int32& k = m_parent->m_tableIterator->key;
889  return AABox(Vector3(k) * m_parent->m_grid->m_cellWidth,
890  Vector3(k + Vector3int32(1, 1, 1)) * m_parent->m_grid->m_cellWidth);
891  }
892 
894  int size() const {
895  debugAssert(! m_parent->m_isEnd);
896  return m_parent->m_tableIterator->value.size();
897  }
898  };
899 
900  private:
903 
908  m_isEnd(true),
909  m_grid(NULL),
910  m_tableIterator( CellTable().end() ),
911  m_epoch(0) {}
912 
913  CellIterator(const ThisType* grid) :
914  m_isEnd(false),
915  m_grid(grid),
916  m_tableIterator( grid->m_data.begin()),
917  m_epoch(grid->m_epoch) {
918  m_indirection.m_parent = this;
919  m_isEnd = ! m_tableIterator.isValid();
920  }
921 
922  // Intentionally unimplemented
924 
925  public:
926 
927  const CellObject& operator*() const { return m_indirection; }
928  const CellObject* operator->() const { return &m_indirection; }
929  operator CellObject*() const { return &m_indirection; }
930 
931  inline bool operator!=(const CellIterator& other) const {
932  // != is called more often than == during iteration
933  return !(
934  (m_isEnd && other.m_isEnd) ||
935  ((m_isEnd == other.m_isEnd) &&
936  (m_tableIterator != other.m_tableIterator)));
937  }
938 
939  bool operator==(const CellIterator& other) const {
940  return !(*this != other);
941  }
942 
945  debugAssertM(m_epoch == m_grid->m_epoch,
946  "It is illegal to mutate the HashGrid while "
947  "iterating through it.");
948  ++m_tableIterator;
949  m_isEnd = ! m_tableIterator.isValid();
950  return *this;
951  }
952 
955  Iterator old = *this;
956  ++(*this);
957  return old;
958  }
959 
961  bool hasMore() const {
962  return ! m_isEnd;
963  }
964 
965  bool isValid() const {
966  return ! m_isEnd;
967  }
968  }; // CellIterator
969 
972  CellIterator beginCells() const {
973  return CellIterator(this);
974  }
975 
976  const CellIterator& endCells() const {
977  static const CellIterator it;
978  return it;
979  }
980 
983 
987  bool contains(const Value& v) const {
988  Cell* cell = NULL;
989  int index = 0;
990  Vector3int32 cellCoord;
991  return const_cast<ThisType*>(this)->find(v, cellCoord, cell, index);
992  }
993 
1001  void deleteAll() {
1002  for (Iterator it = begin(); it.isValid(); ++it) {
1003  delete *it;
1004  }
1005  clear();
1006  }
1007 
1009  ++m_epoch;
1010  m_size = 0;
1011  m_bounds = AABox();
1012 
1013  m_data.clearAndSetMemoryManager(m);
1014  m_memoryManager = m;
1015  }
1016 
1020  void clear(bool shrink = true) {
1021  m_size = 0;
1022  m_bounds = AABox();
1023  if (! shrink) {
1024  // Remove all data
1025  for (CellIterator it = beginCells(); it.isValid(); ++it) {
1026  it.cell().clear(true);
1027  }
1028  } else {
1029  m_data.clear();
1030  }
1031  ++m_epoch;
1032  }
1033 
1035  return (int)m_data.debugGetDeepestBucketSize();
1036  }
1037 
1039  return m_data.debugGetAverageBucketSize();
1040  }
1041 #undef ThisType
1042 };
1043 
1044 } // G3D
1045 #endif
CellTable::Iterator m_tableIterator
Definition: PointHashGrid.h:412
bool operator!=(const Iterator &other) const
Definition: PointHashGrid.h:443
std::string __cdecl debugPrintf(const char *fmt...) G3D_CHECK_PRINTF_ARGS
Definition: debugAssert.cpp:355
void fastRemove(int i, bool shrinkIfNecessary=false)
Definition: SmallArray.h:115
CellObject m_indirection
Definition: PointHashGrid.h:902
Vector3int32
Definition: Vector3int32.h:29
bool operator==(const CellIterator &other) const
Definition: PointHashGrid.h:939
AABox m_box
Definition: PointHashGrid.h:545
Value * getPointer(const Key &key) const
Definition: Table.h:731
BoxIterator beginBoxIntersection(const AABox &box, bool exact=true) const
Definition: PointHashGrid.h:704
const Iterator & end() const
Definition: PointHashGrid.h:516
void merge(const AABox &a)
Definition: AABox.h:106
Vector3int32 m_offsetArray[3 *3 *3]
Definition: PointHashGrid.h:113
void getCellCoord(const Point3 &pos, Point3int32 &cellCoord) const
Compute the grid cell index of a real position. This is used extensively internally by PointHashGrid...
Definition: PointHashGrid.h:186
float debugGetAverageBucketSize() const
Definition: Table.h:382
void insert(const Value &v)
Definition: PointHashGrid.h:319
friend class ThisType
Definition: PointHashGrid.h:406
const BoxIterator & endBoxIntersection() const
Definition: PointHashGrid.h:708
static MemoryManager::Ref create()
Definition: MemoryManager.cpp:35
Cell * m_cell
Definition: PointHashGrid.h:553
const int m_epoch
Definition: PointHashGrid.h:868
AABox bounds() const
Definition: PointHashGrid.h:887
Definition: SmallArray.h:23
Definition: PointHashGrid.h:716
void clearAndSetRadiusHint(float radiusHint)
Definition: PointHashGrid.h:245
A sparse 3D grid of point-based data.
Definition: PointHashGrid.h:94
bool operator!=(const BoxIterator &other) const
Definition: PointHashGrid.h:649
bool contains(const AABox &other) const
Definition: AABox.h:238
Iterator & operator++()
Definition: PointHashGrid.h:467
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
const Value & operator*() const
Definition: PointHashGrid.h:682
void clear()
Definition: Table.h:578
Vector3int32 m_current
Definition: PointHashGrid.h:550
const CellObject & operator*() const
Definition: PointHashGrid.h:927
bool m_isEnd
Definition: PointHashGrid.h:721
const CellIterator & endCells() const
Definition: PointHashGrid.h:976
Definition: PositionTrait.h:5
Definition: AABox.h:25
Dynamic 1D array tuned for performance.
Definition: Array.h:95
double debugGetLoad() const
Definition: Table.h:402
CellIterator()
Definition: PointHashGrid.h:907
BoxIterator & operator++()
Definition: PointHashGrid.h:664
const Value * operator->() const
Definition: PointHashGrid.h:683
arena_t NULL
Definition: jemalloc_internal.h:624
const ThisType * m_grid
Definition: PointHashGrid.h:533
#define false
Definition: CascPort.h:18
int iFloor(double fValue)
Definition: g3dmath.h:603
Vector3int32 Point3int32
Definition: Vector3int32.h:176
const int m_epoch
Definition: PointHashGrid.h:417
void debugPrintStatistics() const
Definition: PointHashGrid.h:310
T & next()
Definition: SmallArray.h:153
static AABox getBoundingBox(const Sphere &s)
Definition: PointHashGrid.h:743
void advanceCell()
Definition: PointHashGrid.h:562
shared_ptr< class MemoryManager > Ref
Definition: MemoryManager.h:31
bool hasMore() const
Definition: PointHashGrid.h:961
const Point3 & low() const
Definition: AABox.h:136
void getBounds(class AABox &out) const
Definition: Sphere.cpp:252
Iterator()
Definition: PointHashGrid.h:422
bool m_isEnd
Definition: PointHashGrid.h:865
Cell & cell()
Definition: PointHashGrid.h:871
MemoryManager::Ref m_memoryManager
Definition: PointHashGrid.h:136
void clearAndSetMemoryManager(const MemoryManager::Ref &m)
Definition: PointHashGrid.h:1008
int size() const
Definition: PointHashGrid.h:300
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
Definition: PointHashGrid.h:526
void initOffsetArray()
Definition: PointHashGrid.h:195
Iterator(const ThisType *grid)
Definition: PointHashGrid.h:425
bool operator!=(const SphereIterator &other) const
Definition: PointHashGrid.h:772
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
int m_arrayIndex
Definition: PointHashGrid.h:415
SphereIterator(const ThisType *grid, const Sphere &sphere)
Definition: PointHashGrid.h:749
Definition: PointHashGrid.h:102
Table< Point3int32, Cell > CellTable
Definition: PointHashGrid.h:110
Sphere m_sphere
Definition: PointHashGrid.h:722
Definition: Vector3.h:58
#define true
Definition: CascPort.h:17
bool m_exact
Definition: PointHashGrid.h:542
bool m_isEnd
Definition: PointHashGrid.h:531
bool find(const Value &v, Point3int32 &foundCellCoord, Cell *&foundCell, int &index)
Definition: PointHashGrid.h:149
const Value & value() const
Definition: PointHashGrid.h:759
const Value & value() const
Definition: PointHashGrid.h:434
bool isValid() const
Definition: PointHashGrid.h:813
Value value
Definition: PointHashGrid.h:105
void deleteAll()
Definition: PointHashGrid.h:1001
const ThisType * m_grid
Definition: PointHashGrid.h:866
int m_size
Definition: PointHashGrid.h:130
Definition: Sphere.h:24
void clearAndSetMemoryManager(MemoryManager::Ref &m)
Definition: SmallArray.h:50
Entry
Definition: boss_headless_horseman.cpp:50
int m_epoch
Definition: PointHashGrid.h:118
Definition: PointHashGrid.h:877
const CellIterator * m_parent
Definition: PointHashGrid.h:880
PointHashGrid(const Array< Value > &init, float radiusHint=-1.0f, const MemoryManager::Ref &m=MemoryManager::create())
Definition: PointHashGrid.h:256
const Value * operator->() const
Definition: PointHashGrid.h:805
AABox m_bounds
Definition: PointHashGrid.h:127
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1706
PointHashGrid & operator=(const ThisType &)
SphereIterator & operator=(const SphereIterator &)
bool operator==(const Iterator &other) const
Definition: PointHashGrid.h:462
size_t debugGetDeepestBucketSize() const
Definition: Table.h:360
bool operator==(const SphereIterator &other) const
Definition: PointHashGrid.h:783
#define debugAssert(exp)
Definition: debugAssert.h:160
void advance()
Definition: PointHashGrid.h:585
CellIterator & operator++()
Definition: PointHashGrid.h:944
CellIterator operator++(int)
Definition: PointHashGrid.h:954
float m_invCellWidth
Definition: PointHashGrid.h:124
int debugGetDeepestBucketSize() const
Definition: PointHashGrid.h:1034
float m_cellWidth
Definition: PointHashGrid.h:121
CellTable::Iterator m_tableIterator
Definition: PointHashGrid.h:867
bool remove(const Key &key, Key &removedKey, Value &removedValue, bool updateRemoved)
Definition: Table.h:606
SmallArray< Entry, expectedCellSize > Cell
Definition: PointHashGrid.h:109
const AABox & conservativeBoxBounds() const
Definition: PointHashGrid.h:306
void clear(bool shrink=true)
Definition: PointHashGrid.h:1020
PointHashGrid(float radiusHint, const MemoryManager::Ref &m=MemoryManager::create())
Definition: PointHashGrid.h:224
int size() const
Definition: PointHashGrid.h:894
Iterator operator++(int)
Definition: PointHashGrid.h:488
BoxIterator m_boxIterator
Definition: PointHashGrid.h:723
Definition: PointHashGrid.h:404
CellTable m_data
Definition: PointHashGrid.h:134
int size() const
Definition: Array.h:430
Value & getCreate(const Key &key)
Definition: Table.h:861
Definition: PointHashGrid.h:861
Definition: AABox.h:32
void getIntersectingMembers(const Sphere &sphere, Array< Value > &result) const
Definition: PointHashGrid.h:840
BoxIterator operator++(int)
Definition: PointHashGrid.h:676
const Value * operator->() const
Definition: PointHashGrid.h:496
const Value & value() const
Definition: PointHashGrid.h:633
CellIterator beginCells() const
Definition: PointHashGrid.h:972
const Vector3 & position() const
Definition: PointHashGrid.h:639
bool contains(const Point3 &point) const
Definition: Sphere.cpp:79
bool isValid() const
Definition: PointHashGrid.h:691
int size() const
Definition: SmallArray.h:37
G3D::Quat pow(const G3D::Quat &q, double x)
Definition: Quat.h:761
float debugGetAverageBucketSize() const
Definition: PointHashGrid.h:1038
friend class ThisType
Definition: PointHashGrid.h:528
void advance()
Definition: PointHashGrid.h:727
CellIterator & operator=(const CellIterator &)
bool hasMore() const
Definition: PointHashGrid.h:687
bool operator!=(const CellIterator &other) const
Definition: PointHashGrid.h:931
Vector3int32 m_hi
Definition: PointHashGrid.h:539
BoxIterator & operator=(const BoxIterator &)
BoxIterator(const ThisType *grid, bool exact, const AABox &box)
Definition: PointHashGrid.h:613
const SphereIterator & endSphereIntersection() const
Definition: PointHashGrid.h:833
bool operator==(const BoxIterator &other) const
Definition: PointHashGrid.h:659
Point3 position
Definition: PointHashGrid.h:104
PointHashGrid(const ThisType &)
friend class ThisType
Definition: PointHashGrid.h:863
bool contains(const Value &v) const
Definition: PointHashGrid.h:987
SphereIterator begin(const Sphere &sphere) const
Definition: PointHashGrid.h:821
bool hasMore() const
Definition: PointHashGrid.h:458
bool isValid() const
Definition: PointHashGrid.h:965
bool m_isEnd
Definition: PointHashGrid.h:408
CellObject()
Definition: PointHashGrid.h:882
SphereIterator()
Definition: PointHashGrid.h:725
bool isValid() const
Definition: PointHashGrid.h:453
const Value & operator*() const
Definition: PointHashGrid.h:804
const Value & operator*() const
Definition: PointHashGrid.h:495
const CellObject * operator->() const
Definition: PointHashGrid.h:928
const FieldDescriptor value
Definition: descriptor.h:1522
const int m_epoch
Definition: PointHashGrid.h:558
void clearAndSetMemoryManager(const MemoryManager::Ref &m)
Definition: Table.h:309
#define ThisType
Definition: PointHashGrid.h:99
SphereIterator operator++(int)
Definition: PointHashGrid.h:798
void insert(const Array< Value > &v)
Definition: PointHashGrid.h:350
const Point3 & high() const
Definition: AABox.h:141
Definition: EqualsTrait.h:19
BoxIterator()
Definition: PointHashGrid.h:610
static const Vector3 & inf()
Definition: Vector3.cpp:124
bool G3D_DEPRECATED hasMore() const
Definition: PointHashGrid.h:809
friend class ThisType
Definition: PointHashGrid.h:719
void append(const T &value)
Definition: Array.h:583
CellIterator(const ThisType *grid)
Definition: PointHashGrid.h:913
float radiusHint() const
Definition: PointHashGrid.h:234
SphereIterator & operator++()
Definition: PointHashGrid.h:788
Iterator begin() const
Definition: PointHashGrid.h:512
const ThisType * m_grid
Definition: PointHashGrid.h:410
int m_arrayIndex
Definition: PointHashGrid.h:556
float volume() const
Definition: AABox.h:264
SphereIterator G3D_DEPRECATED beginSphereIntersection(const Sphere &sphere) const
Definition: PointHashGrid.h:827
Vector3int32 m_lo
Definition: PointHashGrid.h:536
void clear(float radiusHint)
Definition: PointHashGrid.h:238