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

test_app.cpp

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 #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 //the leaf is visible 00039 std::cout << "Leaf at Position : " << uiCurrentPos << std::endl; 00040 std::cout << "Leaf Index : " << uiIndex << std::endl; 00041 std::cout << "Lead ID : "; 00042 //loop 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 //In real world, you will test if the bbox is contains in your view of interest 00059 return true; 00060 } 00061 00062 bool _ABTTreeIsVisibleVisitRandom (const vhdAxisAlignedBox &bbox) 00063 { 00064 00065 //assure some parsing 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 //we build the number of object we would like to try! 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 //we try the random isVisible Routine 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 //put the complete search back 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

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