00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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;
00131
static uint32 nCacheLineBytes;
00132
static uint32 nDepth;
00133
static uint32 nSubTreeId;
00134
static const uint32 nArrayDeep;
00135
00136 uint32 _nFirstFreeCacheLineIndex;
00137 uint32 _nLeafIndex;
00138 uint32 nCacheLines;
00139
00140
vhdAxisAlignedBox _bbox;
00141
00142
private:
00143
public:
00144
vhdABTTreeNode *_pNode;
00145
vhdABTTreeLeaf *_pLeaf;
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