VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
octree.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
28 
29 #pragma once
30 
32 #include <vrfutil/kinematicTools.h>
33 #include <vrfutil/uuid.h>
34 
36 #include <cmdLine/cmdStdOutput.h>
37 
39 #include <geometry/extent.h>
40 
42 #include <atomic>
43 #include <tbb/spin_rw_mutex.h>
44 
46 #include <cstdarg>
47 #include <map>
48 #include <unordered_map>
49 #include <vector>
50 
51 
52 template<class T> class DtOctreeNode;
53 
56 
57 #define OCTREE_DEBUG 0
58 
59 #if OCTREE_DEBUG
60 
61 static int octree_debug_level = 0;
62 
64 
65 static void DEBUG_OUTPUT(const char* fmt, ...)
66 {
67  char buffer[8192];
68  va_list ap;
69  va_start(ap, fmt);
70  vsprintf(buffer, fmt, ap);
71  va_end(ap);
72 
73  DtInfo("OCT %*s%s\n", octree_debug_level*2, "", buffer);
74 }
75 
76 # define DEBUG_PUSH do { octree_debug_level++; } while(0)
77 # define DEBUG_POP do { octree_debug_level--; } while(0)
78 #else
79 
80 static inline void DEBUG_OUTPUT(const char* fmt, ...)
81 { }
82 
83 # define DEBUG_PUSH do { } while(0)
84 # define DEBUG_POP do { } while(0)
85 #endif
86 
88 static const int NUM_BRANCHES = 8;
89 
90 static const int MAX_BRANCH_DEPTH = 12;
91 
93 static const int MAX_CHILD_MEMBERS = 16;
94 
96 static bool theBitmaskListCreated = false;
97 
98 #define EXT_FMT "[%lf, %lf, %lf] - [%lf, %lf, %lf]"
99 #define EXT_ARGS(x) (x).minX(), (x).minY(), (x).minZ(), (x).maxX(), (x).maxY(), (x).maxZ()
100 #define OBJ_ARGS(x) ((const char*) (x)->objectName().c_str())
101 
107 
108 template<class T> class DtOctreeMember
109 {
110 public:
111  DtOctreeMember(T* object, const DtExtent& extent)
112  : myObject(object)
113  , myExtent(extent)
114  {
115  }
116 
118  void bind(DtOctreeNode<T>* node);
119 
121  void unbind(DtOctreeNode<T>* node);
122 
124  void unbind();
125 
126  bool testKey(const unsigned int key)
127  {
128  unsigned int threadId = DtVRFGetThreadId();
129 
130  tbb::spin_rw_mutex::scoped_lock lock(mySearchKeysMutex, false);
131  std::unordered_map<unsigned int, unsigned int>::const_iterator iter = mySearchKeys.find(threadId);
132 
133  if ((iter != mySearchKeys.end()) && (key == iter->second))
134  {
135  return false;
136  }
137 
138  lock.upgrade_to_writer();
140  mySearchKeys[threadId] = key;
141 
142  return true;
143  }
144 
145 protected:
146  template<class U> friend class DtOctreeNode;
147  template<class U> friend class DtOctree;
148 
151 
154 
155  typedef std::pair<DtOctreeNode<T>*, typename std::list<DtOctreeMember*>::iterator> NodeBinding;
156 
159  std::list<NodeBinding> myBindings;
160 
162  std::unordered_map<unsigned int, unsigned int> mySearchKeys;
163  tbb::spin_rw_mutex mySearchKeysMutex;
164 };
165 
166 
167 template<class T>
169 {
170 public:
173 
175  virtual bool operator()(const T *object) = 0;
176 };
177 
204 
205 template<class T> class DtOctreeNode
206 {
207 protected:
208 
209  typedef std::list<DtOctreeMember<T>*> MemberContainer;
210  typedef typename std::list<DtOctreeMember<T>*>::iterator MemberIterator;
211 
212  static int sNumNodes;
213  static const int MAX_NUM_NODES = 1000;
214 
216  DtOctreeNode(const DtExtent &region, const unsigned int depth)
217  : myRegion(region)
218  , myDepth(depth)
219  , myCenter(region.center())
220  , myChildren(0)
221  {
222  DEBUG_OUTPUT("Create node " EXT_FMT, EXT_ARGS(region));
223 
224  ++sNumNodes;
225  }
226 
229  {
230  DEBUG_OUTPUT("Destroy node " EXT_FMT, EXT_ARGS(myRegion));
231  DEBUG_PUSH;
232 
233  if (myChildren)
234  {
235  for(int i=0; i<NUM_BRANCHES; i++)
236  delete myChildren[i];
237  }
238  delete[] myChildren;
239 
240  DEBUG_POP;
241 
242  --sNumNodes;
243  }
244 
253 
254  virtual void visitObjects(const unsigned int key, const DtExtent& extent, DtSpatialSelectionFunctorTemplate<T> &callback)
255  {
256  DEBUG_OUTPUT(EXT_FMT "::visit(" EXT_FMT ", cb)", EXT_ARGS(myRegion), EXT_ARGS(extent));
257  DEBUG_PUSH;
258 
259  MemberIterator iter, end;
260 
261  for(iter = myMembers.begin(), end = myMembers.end(); iter != end; ++iter)
262  {
263  DEBUG_OUTPUT("Member %s " EXT_FMT, OBJ_ARGS((*iter)->myObject), EXT_ARGS((*iter)->myExtent));
264  if ((*iter)->testKey(key))
265  {
266  if (!(*iter)->myObject->isDeleted() && callback((*iter)->myObject))
267  {
268  break;
269  }
270  }
271  else
272  {
274  return;
275  }
276  }
277 
278  if (myChildren)
279  {
280  int mask = intersectionMask(extent);
281  for(int i = 0; i < NUM_BRANCHES; ++i)
282  {
283  if (myChildren[i] && (mask & theBitmaskList[i]))
284  {
285  myChildren[i]->visitObjects(key, extent, callback);
286  }
287  }
288  }
289 
290  DEBUG_POP;
291  }
292 
294  virtual void addMember(DtOctreeMember<T>* member, int& depth)
295  {
296  depth++;
297 
298  DEBUG_OUTPUT(EXT_FMT "::addMember(%s)", EXT_ARGS(myRegion), OBJ_ARGS(member->myObject));
299  DEBUG_PUSH;
300 
301 #if OCTREE_DEBUG
302  if (!myRegion.contains(member->myExtent))
303  {
304  DEBUG_OUTPUT("FAIL! " EXT_FMT " does not contain " EXT_FMT, EXT_ARGS(myRegion), EXT_ARGS(member->myExtent));
305  }
306 #endif
307 
308  if (myChildren)
309  {
310  int mask = intersectionMask(member->myExtent);
311 
312  if (mask == 0xff)
313  {
315  member->bind(this);
316  }
317  else
318  {
319  for (int childIndex = 0; childIndex < NUM_BRANCHES; ++childIndex)
320  {
321  if (mask & theBitmaskList[childIndex])
322  {
323  addMemberToChild(member, childIndex, depth);
324  }
325  }
326  }
327  }
328  else
329  {
330  DEBUG_OUTPUT("add as child member (not enough child members yet)");
331 
332  member->bind(this);
333 
334  //if (numChildCandidates() >= MAX_CHILD_MEMBERS && myDepth < MAX_BRANCH_DEPTH)
335  if (numChildCandidates() >= MAX_CHILD_MEMBERS && sNumNodes < MAX_NUM_NODES - 8)
336  {
337  split(depth);
338  }
339  }
340 
341  DEBUG_POP;
342  }
343 
347  {
348  DEBUG_OUTPUT(EXT_FMT "::coalesceEmptyChildren()", EXT_ARGS(myRegion));
349  DEBUG_PUSH;
350 
351  bool retVal = (myMembers.size() == 0);
352 
353  if (myChildren)
354  {
355  for(int i=0; i<NUM_BRANCHES; i++)
356  {
357  if (myChildren[i])
358  {
360  {
361  DEBUG_OUTPUT("Deleting child %d\n", i);
362  delete myChildren[i];
363  myChildren[i] = 0;
364  } else {
365  retVal = false;
366  }
367  }
368  }
369  }
370 
371  DEBUG_POP;
372 
373  return retVal;
374  }
375 
378  {
379  double retVal = 0;
380  DtExtent matchExtent;
381 
382  MemberIterator iter, end;
383  for(iter = myMembers.begin(), end = myMembers.end(); iter != end; ++iter)
384  {
385  double numBuckets = 0;
386  int mask = intersectionMask((*iter)->myExtent);
387 
390  if ((*iter)->myExtent == matchExtent)
391  {
392  continue;
393  }
394 
395  matchExtent = (*iter)->myExtent;
396 
397  if (mask != 0xff)
398  {
399  for(int childIndex = 0; childIndex < NUM_BRANCHES; ++childIndex)
400  {
401  if (mask & theBitmaskList[childIndex])
402  {
403  numBuckets++;
404  }
405  }
406 
407  retVal += (1.0 / numBuckets);
408 
409  if (retVal >= MAX_CHILD_MEMBERS)
410  {
411  break;
412  }
413  }
414  }
415 
416  return retVal;
417  }
418 
424  int intersectionMask(const DtExtent &extent) const
425  {
426  int result = 0xff;
427 
428  if (extent.minX() >= myCenter.x())
429  result &= 0xf0;
430  if (extent.maxX() <= myCenter.x())
431  result &= 0x0f;
432 
433  if (extent.minY() >= myCenter.y())
434  result &= 0xcc;
435  if (extent.maxY() <= myCenter.y())
436  result &= 0x33;
437 
438  if (extent.minZ() >= myCenter.z())
439  result &= 0xaa;
440  if (extent.maxZ() <= myCenter.z())
441  result &= 0x55;
442 
443  if (result == 0)
444  {
448  return 0xff;
449  }
450 
451  return result;
452  }
453 
457  void addMemberToChild(DtOctreeMember<T>* member, int childIndex, int& depth)
458  {
459  DEBUG_OUTPUT(EXT_FMT "::addMemberToChild(%s, %d)", EXT_ARGS(myRegion), OBJ_ARGS(member->myObject), childIndex);
460  DEBUG_PUSH;
461 
462  if (myChildren[childIndex] == 0)
463  {
464  DtPoint childCorner;
465 
466  if (childIndex & 4)
467  childCorner.setX(myRegion.maxX());
468  else
469  childCorner.setX(myRegion.minX());
470 
471  if (childIndex & 2)
472  childCorner.setY(myRegion.maxY());
473  else
474  childCorner.setY(myRegion.minY());
475 
476  if (childIndex & 1)
477  childCorner.setZ(myRegion.maxZ());
478  else
479  childCorner.setZ(myRegion.minZ());
480 
481  myChildren[childIndex] = new DtOctreeNode(DtExtent(childCorner, myCenter), myDepth + 1);
482  }
483 
484  myChildren[childIndex]->addMember(member, depth);
485 
486  DEBUG_POP;
487  }
488 
491  void split(int& depth)
492  {
493  DEBUG_OUTPUT(EXT_FMT "::split()", EXT_ARGS(myRegion));
494  DEBUG_PUSH;
495 
497 
498  for(int i=0; i<NUM_BRANCHES; i++)
499  {
500  myChildren[i] = 0;
501  }
502 
503  MemberIterator iter, next, end;
504  for(iter = myMembers.begin(), end = myMembers.end(); iter != end; iter = next)
505  {
506  next = iter;
507  ++next;
508 
509  DtOctreeMember<T>* member = *iter;
510 
511  int mask = intersectionMask(member->myExtent);
512 
515  if (mask != 0xff)
516  {
517  member->unbind(this);
518 
519  for(int childIndex = 0; childIndex < NUM_BRANCHES; ++childIndex)
520  {
521  if (mask & theBitmaskList[childIndex])
522  {
523  addMemberToChild(member, childIndex, depth);
524  }
525  }
526  }
527  }
528 
529  DEBUG_POP;
530  }
531 
534 
537 
538 
539  unsigned int myDepth;
540 
545 
549 
550  template<class U> friend class DtOctree;
551  template<class U> friend class DtOctreeMember;
552  template<class U> friend class DtOctreeDebugger;
553 };
554 
555 template<class T> int DtOctreeNode<T>::sNumNodes = 0;
556 
568 
569 template<class T> class DtOctree
570 {
571 public:
572 
574  typedef std::map<T*, DtOctreeMember<T>*> MemberContainer;
575  typedef typename std::map<T*, DtOctreeMember<T>*>::iterator MemberIterator;
576 
577  typedef std::list<T*> OutsideAreaContainer;
578  typedef typename std::list<T*>::iterator OutsideAreaIterator;
579 
581 
583  DtOctree(const DtExtent &region) : mySearchKey(0)
584  {
585  myRootNode = new DtOctreeNode<T>(region, 0);
586 
587  if (!theBitmaskListCreated)
588  {
589  theBitmaskListCreated = true;
590  for (int childIndex = 0; childIndex < NUM_BRANCHES; ++childIndex)
591  {
592  theBitmaskList[childIndex] = (1 << childIndex);
593  }
594  }
595  }
596 
598  virtual ~DtOctree()
599  {
600  delete myRootNode;
601 
602  MemberIterator iter, end;
603  for(iter = myMemberMap.begin(), end = myMemberMap.end(); iter != end; ++iter)
604  {
605  delete (*iter).second;
606  }
607  }
608 
612  virtual void visitObjects(const DtExtent& extent, DtSpatialSelectionFunctorTemplate<T> &callback)
613  {
614  tbb::spin_rw_mutex::scoped_lock lock(myMutex, false);
615  ++mySearchKey;
616 
620  if (myRootNode->myRegion.intersects(extent))
621  {
622  myRootNode->visitObjects(mySearchKey, extent, callback);
623  }
624 
625  OutsideAreaIterator iter, end;
626  for(iter = myObjectsOutsideArea.begin(), end = myObjectsOutsideArea.end(); iter != end; ++iter)
627  {
628  callback(*iter);
629  }
630  }
631 
634 
636  virtual void addObject(T* object, const DtExtent& extent)
637  {
638  DEBUG_OUTPUT("DtOctree::addObject(%s, " EXT_FMT ")", OBJ_ARGS(object), EXT_ARGS(extent));
639  DEBUG_PUSH;
640 
641  tbb::spin_rw_mutex::scoped_lock lock(myMutex);
642 
644  if (DtDebug.okToPrint())
645  {
646  const bool contained = myRootNode->myRegion.contains(extent);
647  const DtUUID host = object->embarkedOn();
648  DtDebug("[octree addObject] name=%s embarked=%s host=%s\n"
649  " passedExtent = " EXT_FMT "\n"
650  " rootRegion = " EXT_FMT "\n"
651  " => %s\n",
652  OBJ_ARGS(object),
653  host.isValid() ? "yes" : "no",
654  host.isValid() ? host.uuidString().c_str() : "none",
655  EXT_ARGS(extent),
656  EXT_ARGS(myRootNode->myRegion),
657  contained ? "INSIDE" : "OUTSIDE");
658  }
659 
660  if (myRootNode->myRegion.contains(extent))
661  {
662  DtOctreeMember<T>* newMember = new DtOctreeMember<T>(object, extent);
663  int depth = 0;
664 
665  myRootNode->addMember(newMember, depth);
666  myMemberMap[object] = newMember;
667 
669  }
670  else
671  {
672  DtWarn("Member %s (" EXT_FMT ") added outside octree (" EXT_FMT ")\n",
673  OBJ_ARGS(object), EXT_ARGS(extent), EXT_ARGS(myRootNode->myRegion));
674  myObjectsOutsideArea.push_back(object);
675  }
676 
677  DEBUG_POP;
678  }
679 
681  virtual void removeObject(T* object, bool needsLock = true)
682  {
683  DEBUG_OUTPUT("DtOctree::removeObject(%s)", OBJ_ARGS(object));
684  DEBUG_PUSH;
685 
686  tbb::spin_rw_mutex::scoped_lock* lock = 0;
687 
688  if (needsLock)
689  {
690  lock = new tbb::spin_rw_mutex::scoped_lock(myMutex, true);
691  }
692 
693  MemberIterator iter;
694  iter = myMemberMap.find(object);
695  if (iter != myMemberMap.end())
696  {
697  DtOctreeMember<T>* member = (*iter).second;
698  member->unbind();
699  myMemberMap.erase(iter);
700  delete member;
701  }
702  else if (!removeObjectOutsideArea(object))
703  {
707 
708  //DtWarn("Tried to remove %s from octree, but couldn't find!\n", OBJ_ARGS(object));
709  }
710 
711  DEBUG_POP;
712 
713  if (lock)
714  {
715  delete lock;
716  }
717  }
718 
724  virtual void updatePositions()
725  {
726  tbb::spin_rw_mutex::scoped_lock lock(myMutex, false);
727  MemberIterator cur = myMemberMap.begin();
728  while (cur != myMemberMap.end())
729  {
730  MemberIterator iter = cur++;
731 
732  T* object = (*iter).first;
733 
734  if (object->checkValidity())
735  {
736  DtOctreeMember<T>* member = (*iter).second;
737  DtExtent roughExtent = object->extent();
738 
740  if (member->myExtent != roughExtent)
741  {
743  if (DtDebug.okToPrint() && object->embarkedOn().isValid())
744  {
745  DtDebug("[octree updatePositions] EMBARKED %s extent changed to " EXT_FMT " => %s\n",
746  OBJ_ARGS(object), EXT_ARGS(roughExtent),
747  myRootNode->myRegion.contains(roughExtent) ? "re-place INSIDE" : "move OUTSIDE");
748  }
749 
750  member->myExtent = roughExtent;
751 
752  if (!myRootNode->myRegion.contains(member->myExtent))
753  {
755 
756  DtWarn("Object %s (" EXT_FMT ") moving outside octree (" EXT_FMT ")\n",
757  OBJ_ARGS(object), EXT_ARGS(member->myExtent), EXT_ARGS(myRootNode->myRegion));
758  lock.upgrade_to_writer();
759  removeObject(object, false);
760  myObjectsOutsideArea.push_back(object);
761  lock.downgrade_to_reader();
762  }
763  else
764  {
766 
767  member->unbind();
768  int depth = 0;
769 
770  myRootNode->addMember(member, depth);
772  }
773  }
774  }
775  }
776 
777  myRootNode->coalesceEmptyChildren();
778  }
779 
780  bool containsObject(T* object)
781  {
782  tbb::spin_rw_mutex::scoped_lock lock(myMutex, false);
783  if (myMemberMap.find(object) != myMemberMap.end())
784  {
785  return true;
786  }
787  else
788  {
789  OutsideAreaIterator iter, end;
790  for(iter = myObjectsOutsideArea.begin(), end = myObjectsOutsideArea.end(); iter != end; ++iter)
791  {
792  if (*iter == object)
793  {
794  return true;
795  }
796  }
797  }
798  return false;
799  }
800 
802  {
803  return myMemberMap.size() + myObjectsOutsideArea.size();
804  }
805 
807  {
808  return myObjectsOutsideArea.size();
809  }
810 
811 protected:
812  bool removeObjectOutsideArea(T* object)
813  {
814  OutsideAreaIterator iter, end;
815  for(iter = myObjectsOutsideArea.begin(), end = myObjectsOutsideArea.end(); iter != end; ++iter)
816  {
817  if (*iter == object)
818  {
819  myObjectsOutsideArea.erase(iter);
820  return true;
821  }
822  }
823 
824  return false;
825  }
826 
827  tbb::spin_rw_mutex myMutex;
830 
833 
836 
838  std::atomic<unsigned int> mySearchKey;
839 };
840 
844 
845 #if OCTREE_DEBUG
846 
847 class DtDebugOctreeFunctor : public DtSpatialSelectionFunctor
848 {
849 public:
850  DtDebugOctreeFunctor(DtSpatialSelectionFunctor& inner)
851  : myInner(inner)
852  {
853  }
854 
856  virtual bool operator()(const DtSimObject* object)
857  {
858  mySeenObjects.insert(object);
859  return myInner(object);
860  }
861 
862  std::set<const DtSimObject*> mySeenObjects;
863  DtSpatialSelectionFunctor& myInner;
864 };
865 
866 template<class T> class DtOctreeDebugger : public DtOctree<T>
867 {
868 public:
869  DtOctreeDebugger(const DtExtent& extent)
870  : DtOctree<T>(extent)
871  { }
872 
873  void addObject(T* object, const DtExtent& extent)
874  {
875  allObjects[object] = extent;
876  DtOctree<T>::addObject(object, extent);
877  }
878 
879  void removeObject(T* object)
880  {
881  allObjects.erase(object);
883  }
884 
885  void updatePositions()
886  {
887  std::map<T*, DtExtent>::iterator iter = allObjects.begin();
888  std::map<T*, DtExtent>::iterator end = allObjects.end();
889 
890  for(; iter != end; ++iter)
891  {
892  T* object = (*iter).first;
893  DtExtent& extent = (*iter).second;
894 
895  extent = object->roughExtent();
896  }
897 
899  }
900 
901  void visitObjects(const DtExtent& extent, DtSpatialSelectionFunctor &callback)
902  {
903  DtDebugOctreeFunctor debugFunctor(callback);
904  DtOctree<T>::visitObjects(extent, debugFunctor);
905 
906  std::map<T*, DtExtent>::iterator iter = allObjects.begin();
907  std::map<T*, DtExtent>::iterator end = allObjects.end();
908 
909  for(; iter != end; ++iter)
910  {
911  T* object = (*iter).first;
912  const DtExtent& objectExtent = (*iter).second;
913 
914  if (objectExtent.intersects(extent) && debugFunctor.mySeenObjects.count(object) == 0)
915  {
916  DEBUG_OUTPUT("FAILED to visit object %s", OBJ_ARGS(object));
917  DEBUG_PUSH;
918  DEBUG_OUTPUT("Old extent is " EXT_FMT, EXT_ARGS(objectExtent));
919  DEBUG_OUTPUT("New extent is " EXT_FMT, EXT_ARGS(object->roughExtent()));
920  DEBUG_POP;
921  }
922  }
923  }
924 protected:
925  std::map<T*, DtExtent> allObjects;
926 };
927 
929 
930 static DtOctree<DtSimObject>* createOctree(const DtExtent& extent)
931 {
932  return new DtOctreeDebugger<DtSimObject>(extent);
933 }
934 
935 #else
936 
937 
938 
939 #endif
940 
942 
943 template<class T> void DtOctreeMember<T>::bind(DtOctreeNode<T>* node)
944 {
945  for (typename std::list<NodeBinding>::const_iterator it = myBindings.begin(); it != myBindings.end(); ++it)
946  {
947  if (node == (*it).first)
948  {
949  return;
950  }
951  }
952 
953  myBindings.push_back(NodeBinding(node, node->myMembers.insert(node->myMembers.end(), this)));
954 }
955 
956 template<class T> void DtOctreeMember<T>::unbind(DtOctreeNode<T>* node)
957 {
958  for (typename std::list<NodeBinding>::iterator it = myBindings.begin(); it != myBindings.end(); ++it)
959  {
960  if (node == (*it).first)
961  {
962  node->myMembers.erase((*it).second);
963  myBindings.erase(it);
964  return;
965  }
966  }
967 }
968 
969 template<class T> void DtOctreeMember<T>::unbind()
970 {
971  for (typename std::list<NodeBinding>::const_iterator it = myBindings.begin(); it != myBindings.end(); ++it)
972  {
973  (*it).first->myMembers.erase((*it).second);
974  }
975  myBindings.clear();
976 }
UUID is a unique ID wrapper class.
Definition: uuid.h:59
const double & x() const
Definition: point.h:188
static const int NUM_BRANCHES
The number of children of each node. Don&#39;t change this without rewriting everything.
Definition: octree.h:88
virtual bool contains(const DtExtent &otherExtent) const
Determine if another extents box is entirely contained by this one. On the border counts as &quot;containe...
virtual ~DtOctree()
Destructor. Deletes the octree and any members in it (though not the corresponding objects)...
Definition: octree.h:598
T * myObject
The object corresponding to this member.
Definition: octree.h:150
DtExtent myExtent
The extent of the member at the time it was added or last updated.
Definition: octree.h:153
void unbind()
Remove this member from all nodes.
Definition: octree.h:969
static bool theBitmaskListCreated
Definition: octree.h:96
bool coalesceEmptyChildren()
Look for any empty, childless nodes and coalesce them up to their parents. Returns true if this node ...
Definition: octree.h:346
void split(int &depth)
Create child nodes to hold all the members that can go into child nodes, and move those members into ...
Definition: octree.h:491
bool removeObjectOutsideArea(T *object)
Definition: octree.h:812
DtOctreeNode(const DtExtent &region, const unsigned int depth)
Constructor. The extent covered by an octree node may not be changed once the octree is created...
Definition: octree.h:216
friend class DtOctreeDebugger
Definition: octree.h:552
MemberContainer myMemberMap
Mapping of T* pointers to DtOctreeMember objects in the tree.
Definition: octree.h:835
DtOctreeNode< T > * myRootNode
Root node of the octree.
Definition: octree.h:829
DtSpatialSelectionFunctorTemplate< T > SpatialSelectionFunctor
Definition: octree.h:580
Contains the DtUUID class declaration.
#define EXT_FMT
Definition: octree.h:98
tbb::spin_rw_mutex myMutex
Definition: octree.h:827
virtual bool isValid() const
The DtSpatialVrfObjectManager is responsible for maintaining a spatial organization of all specified ...
Definition: spatialVrfObjectManager.h:31
DtOctree class.
Definition: octree.h:569
DtOctreeNode< T > ** myChildren
Child nodes of this node, if any. This is NULL for a childless node. For nodes with children...
Definition: octree.h:544
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
virtual void addMember(DtOctreeMember< T > *member, int &depth)
Add a member to this node or one of its children (splitting the node if necessary).
Definition: octree.h:294
static const int MAX_BRANCH_DEPTH
Definition: octree.h:90
static void DEBUG_OUTPUT(const char *fmt,...)
Definition: octree.h:80
#define DEBUG_POP
Definition: octree.h:84
#define OBJ_ARGS(x)
Definition: octree.h:100
int numObjects()
Definition: octree.h:801
Octree support.
Definition: octree.h:52
double maxZ() const
Access and/or mutate individual values.
double minZ() const
Access and/or mutate individual values.
DtOctreeMember class.
Definition: octree.h:108
#define DEBUG_PUSH
Definition: octree.h:83
DT_DLL_vrfutil unsigned int DtVRFGetThreadId()
Gets the current thread id.
std::unordered_map< unsigned int, unsigned int > mySearchKeys
Definition: octree.h:162
virtual bool operator()(const T *object)=0
Abstract function call interface.
std::atomic< unsigned int > mySearchKey
Definition: octree.h:838
DtOctree(const DtExtent &region)
Constructor. The extent covered by an octree may not be changed once the octree is created...
Definition: octree.h:583
bool intersects(const DtExtent &otherExtent) const
Determine if the two extents overlap (either partially or fully). A shared &quot;wall&quot; counts as intersect...
virtual bool operator()(const DtSimObject *object) override=0
Abstract function call interface.
static const int MAX_NUM_NODES
Definition: octree.h:213
Definition: octree.h:168
int numObjectsOutside()
Definition: octree.h:806
bool containsObject(T *object)
Definition: octree.h:780
~DtOctreeNode()
Destructor. No DtOctreeMember objects are deleted.
Definition: octree.h:228
static DtOctree< const DtSimObject > * createOctree(const DtExtent &extent)
Definition: spatialVrfObjectManager.h:294
void bind(DtOctreeNode< T > *node)
Add this member to the specified node.
Definition: octree.h:943
double minX() const
Access and/or mutate individual values.
const DtExtent myRegion
The region intersecting members contained by this node (and this node&#39;s children).
Definition: octree.h:533
virtual void addObject(T *object, const DtExtent &extent)
TODO: Add search key to outside octree list so that objects which fall completely outside the octree ...
Definition: octree.h:636
std::list< NodeBinding > myBindings
A list of the nodes this member is bound to, if any, and iterators to this member&#39;s position in the b...
Definition: octree.h:159
double minY() const
Access and/or mutate individual values.
void setY(const double &y)
Definition: point.h:203
tbb::spin_rw_mutex mySearchKeysMutex
Definition: octree.h:163
std::pair< DtOctreeNode< T > *, typename std::list< DtOctreeMember * >::iterator > NodeBinding
Definition: octree.h:155
const DtPoint myCenter
The center of myRegion.
Definition: octree.h:536
virtual void visitObjects(const unsigned int key, const DtExtent &extent, DtSpatialSelectionFunctorTemplate< T > &callback)
Call the given functor for every member that shares a node with the specified extent. This does not test for exact intersection; it only returns a list of objects that might intersect the given extent.
Definition: octree.h:254
const double & y() const
Definition: point.h:198
virtual ~DtSpatialSelectionFunctorTemplate()
Virtual Destructor which does nothing.
Definition: octree.h:172
std::list< DtOctreeMember< T > * >::iterator MemberIterator
Definition: octree.h:210
bool testKey(const unsigned int key)
Definition: octree.h:126
Represents a single simulation object in the exercise. Object may be VRF simulation, or non-VRF simulated, and may be simulated by the local sim engine, or by a remote sim engine. Only public (external) state of the object is available. All data is read-only. All access to data of the object is thread safe within the simulation frame.
Definition: simObject.h:80
int numChildCandidates()
Return the number of members of this node that can go into child nodes.
Definition: octree.h:377
std::list< DtOctreeMember< T > * > MemberContainer
This class is only for use from DtOctree and DtOctreeDebugger.
Definition: octree.h:209
Contains the declaration of the DtExtent class.
static int theBitmaskList[NUM_BRANCHES]
Definition: octree.h:95
std::list< T * > OutsideAreaContainer
Definition: octree.h:577
MemberContainer myMembers
Members which are in this node. If myChildren is not NULL, then this must not contain any members tha...
Definition: octree.h:548
unsigned int myDepth
Definition: octree.h:539
virtual void visitObjects(const DtExtent &extent, DtSpatialSelectionFunctorTemplate< T > &callback)
Call the given functor for every member that shares a node with the specified extent. This does not test for exact intersection; it only iterates over any objects that might intersect the given extent (i.e. there may be extras).
Definition: octree.h:612
double maxX() const
Access and/or mutate individual values.
void setZ(const double &z)
Definition: point.h:213
virtual void updatePositions()
Process any updates to the objects&#39; positions that have happened since they were added to the octree...
Definition: octree.h:724
void setX(const double &x)
Definition: point.h:193
const double & z() const
Definition: point.h:208
double maxY() const
Access and/or mutate individual values.
virtual const DtString & uuidString() const
virtual void removeObject(T *object, bool needsLock=true)
Remove a member from the octree.
Definition: octree.h:681
void addMemberToChild(DtOctreeMember< T > *member, int childIndex, int &depth)
Add a member to a child of this node, creating the child if necessary. This function will call addMem...
Definition: octree.h:457
std::map< T *, DtOctreeMember< T > * >::iterator MemberIterator
Definition: octree.h:575
std::map< T *, DtOctreeMember< T > * > MemberContainer
Container and iterator typedefs for the STL structures used.
Definition: octree.h:574
OutsideAreaContainer myObjectsOutsideArea
List of objects which are at least partially outside the octree&#39;s root extent.
Definition: octree.h:832
#define EXT_ARGS(x)
Definition: octree.h:99
std::list< T * >::iterator OutsideAreaIterator
Definition: octree.h:578
int intersectionMask(const DtExtent &extent) const
Returns a bit-mask where the ith bit is set iff the ith child of this node intersects the specified e...
Definition: octree.h:424
DtOctreeMember(T *object, const DtExtent &extent)
Definition: octree.h:111
Definition: point.h:34
static const int MAX_CHILD_MEMBERS
The maximum length of myChildMembers; see implementation notes at the top of the class.
Definition: octree.h:93
static int sNumNodes
Definition: octree.h:212
void unbind(DtOctreeNode< T > *node)
Remove this member from the specified node.
Definition: octree.h:956

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)