AI_SDB_SpatialAABBTree.h
Go to the documentation of this file.00001 #ifndef AI_SDB_SPATIALAABBTREE_H
00002 #define AI_SDB_SPATIALAABBTREE_H
00003
00004 #include "AI_SDB_SpatialElements.h"
00005
00006 class AI_SDB_SpatialAABBTreeNode;
00007
00008
00031 class AI_SDB_SpatialAABBTree : public AI_SDB_SpatialHierarchyElement
00032 {
00033 public:
00034 AI_SDB_SpatialAABBTree();
00035 ~AI_SDB_SpatialAABBTree();
00036
00038 void ClearNodes();
00039
00041 void AddElement(AI_SDB_SpatialElement *appendme);
00043 void RemoveElement(AI_SDB_SpatialElement *removeme);
00045 void MoveElement(AI_SDB_SpatialElement *moveme, const AI_BBox &newbox);
00046
00048 virtual void Accept(AI_SDB_VisibilityVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00050 virtual void Accept(AI_SDB_SpatialVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00052 virtual void Accept(AI_SDB_OcclusionVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00053
00054
00055
00056 AI_SDB_SpatialAABBTreeNode *alloc_node();
00057
00058
00059 void free_node(AI_SDB_SpatialAABBTreeNode *freeme);
00060
00061 protected:
00062
00063 AI_SDB_SpatialAABBTreeNode *m_treenodes;
00064
00065
00066 AI_SDB_SpatialAABBTreeNode *FindSuitableNode(const AI_Vector3 &v_center);
00067 void collapse_node(AI_SDB_SpatialAABBTreeNode *collapseme);
00068 void split_node(AI_SDB_SpatialAABBTreeNode *splitme);
00069 void balance_tree(AI_SDB_SpatialAABBTreeNode *treeroot);
00070 };
00071
00072
00073 class AI_SDB_SpatialAABBTreeNode {
00074 public:
00075 AI_SDB_SpatialAABBTreeNode() : m_elementsinnode(0), m_totalelements(0), m_parent(NULL)
00076 { m_children[0] = m_children[1] = NULL; }
00077
00078
00079 ~AI_SDB_SpatialAABBTreeNode() { ai_assert(!HasChildren()); }
00080
00081
00082 bool HasChildren() const { return (m_children[0] != NULL); }
00083
00084
00085 void AddElement(AI_SDB_SpatialElement *addme);
00086
00087
00088 AI_SDB_SpatialAABBTreeNode *FindElement(AI_SDB_SpatialElement *findme);
00089
00090
00091
00092
00093 void RemoveElement(AI_SDB_SpatialElement *removeme);
00094
00095
00096 void Subdivide(AI_SDB_SpatialAABBTree *nodemanager);
00097
00098
00099 void RecomputeElementCount();
00100
00101
00102 void RecomputeBoundingBox();
00103
00104 void ClearNodes(AI_SDB_SpatialAABBTree *nodemanager);
00105
00106
00107 void Accept(AI_SDB_VisibilityVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00108 void Accept(AI_SDB_SpatialVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00109 void Accept(AI_SDB_OcclusionVisitor &visitor, int recursiondepth, AI_SDB_VisitorFlags flags);
00110
00111
00112 AI_BBox m_bbox;
00113
00114
00115 int m_splitaxis;
00116 float m_splitposition;
00117
00118 enum { MAX_ELEMENTSPERNODE = 10 };
00119
00120
00121 AI_SDB_SpatialElement *m_elements[MAX_ELEMENTSPERNODE];
00122 int m_elementsinnode;
00123
00124
00125 int m_totalelements;
00126
00127
00128 AI_SDB_SpatialAABBTreeNode *m_children[2];
00129 AI_SDB_SpatialAABBTreeNode *m_parent;
00130 };
00131
00132 #endif