00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023
00024
#include <iostream>
00025
#include "vhdABTTree.h"
00026
#include "vhdSceneConverterABTTree.h"
00027
00028
00029
00030
00031
#define NB_OBJECTS 3202
00032
00033
unsigned int g_uiNumberOfVisibleLeaf=0;
00034
00035
void
00036 _ABTTreeVisit(
unsigned int uiCurrentPos,
unsigned int uiIndex,
const vhdAxisAlignedBox &bbox)
00037 {
00038
00039 std::cout <<
"Leaf at Position : " << uiCurrentPos << std::endl;
00040 std::cout <<
"Leaf Index : " << uiIndex << std::endl;
00041 std::cout <<
"Lead ID : ";
00042
00043 vhdSceneConverterABTTree::ListAABB::iterator it = vhdSceneConverterABTTree::getSingleton().
mapNodeChild[uiCurrentPos].listAABB.begin();
00044 std::cout << it->strPath;
00045 ++it;
00046
for ( it; it!= vhdSceneConverterABTTree::getSingleton().
mapNodeChild[uiCurrentPos].listAABB.end(); ++it)
00047 {
00048 std::cout <<
" , " << it->strPath;
00049 }
00050 std::cout << std::endl << std::endl;
00051
00052 g_uiNumberOfVisibleLeaf+=(
unsigned int) vhdSceneConverterABTTree::getSingleton().
mapNodeChild[uiCurrentPos].listAABB.size();
00053 }
00054
00055
00056
bool _ABTTreeIsVisibleVisit (
const vhdAxisAlignedBox &bbox)
00057 {
00058
00059
return true;
00060 }
00061
00062
bool _ABTTreeIsVisibleVisitRandom (
const vhdAxisAlignedBox &bbox)
00063 {
00064
00065
00066
static unsigned int uiAss(0);
00067
if (++uiAss%10 == 0)
00068 {
00069
return false;
00070 }
00071
return true;
00072 }
00073
00074
vhdSceneConverterABTTree singl;
00075
int main()
00076 {
00077
vhdABTTree *pABTTree =
new vhdABTTree();
00078
00079 vhdSceneConverterABTTree::vhdSceneABTTreeNode node;
00080
00081
00082
00083
unsigned int i(0);
00084
for ( i ; i < NB_OBJECTS ; ++i )
00085 {
00086
vhdAxisAlignedBox axis(i*100, i*100,i*100,i*100+50,i*100+50,i*100+50);
00087
char buf[256];
00088 sprintf(buf,
"%d",i);
00089 std::string str=std::string(
"Leaf Id ")+std::string(buf);
00090
00091 node.listAABB.push_back(
vhdSceneConverterABTTree::NodeChildStruct(axis,str));
00092 }
00093 vhdSceneConverterABTTree::getSingleton().
pDataRootNode = &node;
00094
00095
00096 pABTTree->
create(NB_OBJECTS);
00097 pABTTree->
funcIsVisible = _ABTTreeIsVisibleVisit;
00098 pABTTree->
funcVisit = _ABTTreeVisit;
00099
00100 std::cout << std::endl << std::endl << std::endl << std::endl;
00101 std::cout <<
"Complete Search" << std::endl << std::endl;
00102 g_uiNumberOfVisibleLeaf=0;
00103 pABTTree->
traversal();
00104 std::cout << std::endl <<
"Complete Search: number of leaves visited " << g_uiNumberOfVisibleLeaf << std::endl << std::endl << std::endl;
00105
00106 std::cout << std::endl << std::endl << std::endl << std::endl;
00107 std::cout <<
"Random Search" << std::endl << std::endl;
00108
00109 pABTTree->
funcIsVisible = _ABTTreeIsVisibleVisitRandom;
00110 g_uiNumberOfVisibleLeaf=0;
00111 pABTTree->
traversal();
00112 std::cout << std::endl <<
"Random Search : number of leaves visited " << g_uiNumberOfVisibleLeaf << std::endl << std::endl << std::endl;
00113
00114
00115 pABTTree->
funcIsVisible = _ABTTreeIsVisibleVisit;
00116 std::cout << std::endl << std::endl << std::endl << std::endl;
00117 std::cout <<
"Complete Search" << std::endl << std::endl;
00118 g_uiNumberOfVisibleLeaf=0;
00119 pABTTree->
traversal();
00120 std::cout << std::endl <<
"Complete Search: Number of Leaves Visited " << g_uiNumberOfVisibleLeaf << std::endl << std::endl << std::endl;
00121
00122
00123 pABTTree->
destroy();
00124
delete pABTTree;
00125 }
00126