Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

vhdABTTree.h

00001 00002 // Copyright : Sebastien Schertenleib 00003 // : VRLab-EPFL 00004 // 00005 // Email :Sebastien.Schertenleib@epfl.ch 00006 // 00007 // This source code is a part of the Game Programming Gems 5 Source Code 00008 // 00009 // Permission to copy, modify, reproduce or redistribute this source code is 00010 // granted provided the above copyright notice is retained in the resulting 00011 // source code. 00012 // 00013 // This file is provided 'as is' with no expressed or implied warranty. 00014 // The author accepts no liability if it causes any damage to your computer. 00015 // 00016 // Do expect bugs. 00017 // Please let me know of any bugs/mods/improvements. 00018 // and I will try to fix/incorporate them into this file. 00019 // Enjoy! 00020 // 00022 00023 00024 #ifndef VHDABTTREE_H 00025 #define VHDABTTREE_H 00026 00027 class vhdSceneEntity; 00028 00029 #include <string> 00030 #include <list> 00031 #include "vhdAxisAlignedBox.h" 00032 00033 00034 // Define data chunk 00035 typedef unsigned int uint32; 00036 typedef unsigned char byte; 00037 00038 00042 class vhdABTTreeLeafData 00043 { 00044 public: 00045 uint32 index; 00046 uint32 callback; 00047 }; 00048 00052 class vhdABTTreeNodeData 00053 { 00054 public: 00055 byte data[8]; 00056 }; 00057 00058 00062 union vhdABTTreeNode 00063 { 00064 vhdABTTreeLeafData leaf; 00065 vhdABTTreeNodeData node; 00066 }; 00067 00071 class vhdABTTreeLeaf 00072 { 00073 public: 00074 vhdSceneEntity* pEntity; 00075 }; 00076 00077 00089 class vhdABTTree 00090 { 00094 class Element 00095 { 00096 public: 00097 Element (uint32 _id, vhdAxisAlignedBox _bbox):bbox(_bbox),id(_id){} 00098 uint32 id; 00099 vhdAxisAlignedBox bbox; 00100 }; 00101 typedef std::list<Element> ListElement; 00102 00103 public: 00107 typedef bool (vhdABTTreeIsVisibleVisitFunc) (const vhdAxisAlignedBox &); 00115 vhdABTTreeIsVisibleVisitFunc *funcIsVisible; 00116 typedef void (vhdABTTreeVisitFunc) (unsigned int uiCurrentPos, unsigned int uiIndex, const vhdAxisAlignedBox &bbox); 00120 vhdABTTreeVisitFunc *funcVisit; 00121 private: 00127 static uint32 _computeSubTreeDepth(); 00128 00129 00130 static uint32 nCacheLineNodes; // #nodes per cache line 00131 static uint32 nCacheLineBytes; // bytes per cache line 00132 static uint32 nDepth; //depth of the sub tree 00133 static uint32 nSubTreeId; // first id for a member of the last line. 00134 static const uint32 nArrayDeep; //max theorical multiplier ratio. 00135 00136 uint32 _nFirstFreeCacheLineIndex; //first free cache line index available 00137 uint32 _nLeafIndex; // leaf index 00138 uint32 nCacheLines; // #cache line sized memory segments used 00139 00140 vhdAxisAlignedBox _bbox; //global aabbox 00141 00142 private: 00143 public: 00144 vhdABTTreeNode *_pNode; //node array 00145 vhdABTTreeLeaf *_pLeaf; // leaf aray 00146 00147 public: 00148 00152 vhdABTTree(); 00153 00154 private: 00161 static bool _isVisible(const vhdAxisAlignedBox & box); 00169 static void visit(unsigned int uiCurrentPos, unsigned int uiIndex, const vhdAxisAlignedBox &bbox); 00170 00171 00172 private: 00181 void _makeNodeDataFlags(uint32 nCurrentChildPosition, const vhdAxisAlignedBox &box, const vhdAxisAlignedBox &boxLeft, const vhdAxisAlignedBox & boxRight); 00190 bool _needToSplit(const vhdAxisAlignedBox &box, uint32 nCurrentPos, bool bLeft); 00199 byte _extendLeft(float fMinExtend, float fMinParent, float fMaxParent); 00208 byte _extendRight(float fMaxExtend, float fMinParent, float fMaxParent); 00219 void _makeChildren(ListElement & listElement, const vhdAxisAlignedBox &box, uint32 nCurrentPosition, uint32 nCurrentChildPosition, uint32 index, bool bLeft); 00227 void _makeLeaf(uint32 nCurrentPosition, uint32 nCurrentChildPosition, bool bLeft); 00236 void _computeChildBox(const vhdAxisAlignedBox & boxParent,vhdAxisAlignedBox &boxLeft,vhdAxisAlignedBox &boxRight, uint32 nCurrentPos); 00243 void subTreeBuild(uint32 nCurrentCacheLineIndex, const vhdAxisAlignedBox &box); 00250 void _traversal(uint32 nCurrentCacheLineIndex,const vhdAxisAlignedBox & box); 00251 public: 00255 void traversal(); 00261 void create(uint32 nObjects); 00268 void create(unsigned int nCacheLineSize, unsigned int nLeafSize ); 00272 void destroy(); 00273 00274 00275 }; 00276 00277 #endif

Generated on Sun Oct 3 16:32:22 2004 for vhdABTTree by doxygen 1.3.8