Changeset 1192 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src
- Timestamp:
- 08/09/06 17:08:34 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
r1190 r1192 304 304 //---------------------------------------------------------------------------- 305 305 306 KdTree::KdTree(int maxdepth ):306 KdTree::KdTree(int maxdepth, BuildMethod bm): 307 307 mMaxDepth(maxdepth), 308 mBuildMethod(bm), 309 mHiLiteLevel(HILITE_OFF), 310 mShowAllBoxes(false), 311 mShowNodes(true), 308 312 mKdRoot(0), 309 mBuildMethod(KDBM_RECURSIVE), 310 mBuildLog(0), 311 mShowNodeAABB(true) 312 { 313 mBuildLog(0) 314 { 315 init(); 316 } 317 318 KdTree::KdTree(int maxdepth, BuildMethod bm, int hilite, bool allboxes, bool shownodes): 319 mMaxDepth(maxdepth), 320 mBuildMethod(bm), 321 mHiLiteLevel(hilite), 322 mShowAllBoxes(allboxes), 323 mShowNodes(shownodes), 324 mKdRoot(0), 325 mBuildLog(0) 326 { 327 init(); 328 } 329 330 KdTree::~KdTree() 331 { 332 delete mKdRoot; 333 } 334 335 void KdTree::init() 336 { 337 // init visualization materials 313 338 MaterialPtr mphi = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite"); 314 339 if (mphi.isNull()) … … 318 343 mphi->setAmbient(green); 319 344 mphi->setDiffuse(green); 320 mphi->setSelfIllumination(ColourValue::Black);321 345 mphi->setLightingEnabled(true); 322 346 mphi->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); … … 330 354 mpviz->setAmbient(yellow); 331 355 mpviz->setDiffuse(yellow); 332 mpviz->setSelfIllumination(ColourValue::Black);333 356 mpviz->setLightingEnabled(true); 334 357 mpviz->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 335 358 } 336 359 360 // retrieve or create build log 337 361 try 338 362 { … … 343 367 mBuildLog = LogManager::getSingleton().createLog(KDTREE_LOGNAME); 344 368 } 345 }346 347 KdTree::~KdTree()348 {349 delete mKdRoot;350 369 } 351 370 … … 399 418 else 400 419 { 401 KdTree::Branch * parent = node->mParent;420 KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent()); 402 421 if (node == parent->mLeft) 403 422 { … … 571 590 else 572 591 { 573 KdTree::Branch * parent = KDBRANCHPTR_CAST(node-> mParent);592 KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent()); 574 593 575 594 if (node == parent->mLeft) … … 738 757 if (parent) 739 758 { 740 level = parent-> mLevel+ 1;759 level = parent->getLevel() + 1; 741 760 } 742 761 … … 795 814 { 796 815 // Terminating condition reached, create leaf and add renderables to list 797 KdTree::Leaf * leaf = new KdTree::Leaf( level, aabb, parent);816 KdTree::Leaf * leaf = new KdTree::Leaf(this, level, aabb, parent); 798 817 KdRenderable *rend; 799 818 it = begin; … … 879 898 880 899 // create a new branch node and continue recursion 881 KdTree::Branch * branch = new KdTree::Branch(level, aabb, parent, best.event.getSplitPlane(), best.side); 900 KdTree::Branch * branch = new KdTree::Branch(this, level, aabb, parent, 901 best.event.getSplitPlane(), best.side); 882 902 883 903 // now create the child nodes and continue recursion … … 931 951 if (sc.parent) 932 952 { 933 level = sc.parent-> mLevel+ 1;953 level = sc.parent->getLevel() + 1; 934 954 } 935 955 … … 941 961 { 942 962 // Terminating condition reached, create leaf and add renderables to list 943 KdTree::Leaf * leaf = new KdTree::Leaf( level, sc.aabb, sc.parent);963 KdTree::Leaf * leaf = new KdTree::Leaf(this, level, sc.aabb, sc.parent); 944 964 KdRenderable *rend; 945 965 PlaneEventList::iterator begin = sc.events->begin(); … … 1032 1052 1033 1053 // create a new branch node 1034 KdTree::Branch * branch = 1035 new KdTree::Branch(level, sc.aabb, sc.parent,sc.best->event.getSplitPlane(), sc.best->side);1054 KdTree::Branch * branch = new KdTree::Branch(this, level, sc.aabb, sc.parent, 1055 sc.best->event.getSplitPlane(), sc.best->side); 1036 1056 1037 1057 globalTreeCost -= sc.decrease; … … 1174 1194 if (cam->isVisible(node->mAABB)) 1175 1195 { 1196 #if 0 1197 node->queueVisibleObjects(currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1198 1199 if (node->getLeftChild()) 1200 recQueueVisibleObjects(node->getLeftChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1201 if (node->getRightChild()) 1202 recQueueVisibleObjects(node->getRightChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1203 #else 1176 1204 #ifdef KDTREE_DEBUG 1177 1205 WireBoundingBox * wbb = 0; 1178 1206 if (showBoxes) 1179 wbb = node->getWireBoundingBox( mShowNodeAABB);1207 wbb = node->getWireBoundingBox(); 1180 1208 #endif 1181 1209 … … 1198 1226 #else 1199 1227 if (showBoxes) 1200 queue->addRenderable(leaf->getWireBoundingBox( mShowNodeAABB));1228 queue->addRenderable(leaf->getWireBoundingBox()); 1201 1229 #endif 1202 1230 } … … 1209 1237 #else 1210 1238 if (showBoxes) 1211 queue->addRenderable(branch->getWireBoundingBox( mShowNodeAABB));1239 queue->addRenderable(branch->getWireBoundingBox()); 1212 1240 #endif 1213 1241 … … 1217 1245 recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1218 1246 } 1247 #endif 1219 1248 } 1220 1249 } … … 1241 1270 1242 1271 pad = ""; 1243 for (p = 0; p < node-> mLevel; p++)1272 for (p = 0; p < node->getLevel(); p++) 1244 1273 { 1245 1274 pad += " "; … … 1255 1284 scenenode = dynamic_cast<KdTreeSceneNode *>(*it); 1256 1285 log->logMessage(pad + "# Leaf level " + 1257 StringConverter::toString(node-> mLevel) +1286 StringConverter::toString(node->getLevel()) + 1258 1287 " SceneNode " + scenenode->getName()); 1259 1288 log->logMessage(pad + "## Objects: " + scenenode->dumpToString()); … … 1267 1296 { 1268 1297 log->logMessage(pad + "# Branch level " + 1269 StringConverter::toString(node-> mLevel) + " Left Child");1298 StringConverter::toString(node->getLevel()) + " Left Child"); 1270 1299 dump(branch->mLeft); 1271 1300 } … … 1273 1302 { 1274 1303 log->logMessage(pad + "# Branch level " + 1275 StringConverter::toString(node-> mLevel) + " Right Child");1304 StringConverter::toString(node->getLevel()) + " Right Child"); 1276 1305 dump(branch->mRight); 1277 1306 } … … 1342 1371 1343 1372 if (showBoxes) 1344 { 1345 WireBoundingBox * wbb = getWireBoundingBox(); 1346 if (wbb) 1347 queue->addRenderable(wbb); 1348 } 1373 if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes()) 1374 queue->addRenderable(getWireBoundingBox()); 1349 1375 } 1350 1376 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r1190 r1192 29 29 mMaxDepth(KDTREE_MAX_DEPTH), 30 30 mShowBoxes(false), 31 #ifdef KDTREE_DEBUG 32 mHighlighLevel(0), 31 mHiLiteLevel(0), 33 32 mShowAllBoxes(false), 34 #endif35 33 mBuildMethod(KdTree::KDBM_PRIORITYQUEUE), 36 34 mRenderMethod(KdTree::KDRM_INTERNAL), … … 102 100 { 103 101 mMaxDepth = maxdepth; 104 #ifdef KDTREE_DEBUG 105 if (mHighlighLevel > mMaxDepth) 106 mHighlighLevel = mMaxDepth; 107 #endif 102 if (mHiLiteLevel > mMaxDepth) 103 mHiLiteLevel = mMaxDepth; 108 104 return true; 109 105 } … … 139 135 { 140 136 OGRE_DELETE(mKdTree); 141 mKdTree = new KdTree(mMaxDepth); 142 mKdTree->setBuildMethod(mBuildMethod); 137 mKdTree = new KdTree(mMaxDepth, mBuildMethod, mHiLiteLevel, mShowAllBoxes, mShowNodes); 143 138 mKdTree->build(static_cast<KdTreeSceneNode *>(mSceneRoot)); 144 139 return true; 145 140 } 146 #ifdef KDTREE_DEBUG147 else if (strKey == "HighlightLevel")148 {149 int hl = *static_cast<const int *>(pValue);150 if (hl >= 0 && hl <= mMaxDepth)151 {152 mHighlighLevel = hl;153 return true;154 }155 else156 {157 return false;158 }159 }160 else if (strKey == "ShowAllBoxes")161 {162 bool sa = *static_cast<const bool *>(pValue);163 mShowAllBoxes = sa;164 return true;165 }166 #endif167 141 else if (strKey == "BuildMethod") 168 142 { … … 236 210 mRenderMethod = KdTree::KDRM_INTERNAL; 237 211 } 212 else 213 { 214 mRenderMethod = KdTree::KDRM_INTERNAL; 215 } 238 216 return success; 239 217 } … … 244 222 return true; 245 223 } 246 else if (strKey == "ShowNodeAABB") 224 else if (strKey == "HiLiteLevel") 225 { 226 int hl = *static_cast<const int *>(pValue); 227 if (hl >= 0 && hl <= mMaxDepth) 228 { 229 mHiLiteLevel = hl; 230 if (mKdTree) 231 mKdTree->setHiLiteLevel(mHiLiteLevel); 232 return true; 233 } 234 else 235 { 236 return false; 237 } 238 } 239 else if (strKey == "ShowAllBoxes") 240 { 241 bool sa = *static_cast<const bool *>(pValue); 242 mShowAllBoxes = sa; 243 if (mKdTree) 244 mKdTree->setShowAllBoxes(mShowAllBoxes); 245 return true; 246 } 247 else if (strKey == "ShowNodes") 247 248 { 248 249 bool sn = *static_cast<const bool *>(pValue); 250 mShowNodes = sn; 249 251 if (mKdTree) 250 mKdTree->setShowNode AABB(sn);252 mKdTree->setShowNodes(mShowNodes); 251 253 return true; 252 254 } … … 341 343 return true; 342 344 } 343 #ifdef KDTREE_DEBUG 344 else if (strKey == "HighlightLevel") 345 { 346 *static_cast<int *>(pDestValue) = mHighlighLevel; 345 else if (strKey == "BuildMethod") 346 { 347 if (mBuildMethod == KdTree::KDBM_PRIORITYQUEUE) 348 { 349 *static_cast<String *>(pDestValue) = "PriorityQueue"; 350 } 351 else if (mBuildMethod == KdTree::KDBM_RECURSIVE) 352 { 353 *static_cast<String *>(pDestValue) = "Recursive"; 354 } 355 return true; 356 } 357 else if (strKey == "RenderMethod") 358 { 359 if (mRenderMethod == KdTree::KDRM_INTERNAL) 360 { 361 *static_cast<String *>(pDestValue) = "INT"; 362 } 363 else if (mRenderMethod == KdTree::KDRM_GTP_VFC) 364 { 365 *static_cast<String *>(pDestValue) = "VFC"; 366 } 367 else if (mRenderMethod == KdTree::KDRM_GTP_SWC) 368 { 369 *static_cast<String *>(pDestValue) = "SWC"; 370 } 371 else if (mRenderMethod == KdTree::KDRM_GTP_CHC) 372 { 373 *static_cast<String *>(pDestValue) = "CHC"; 374 } 375 else 376 { 377 return false; 378 } 379 return true; 380 } 381 else if (strKey == "ShowKdTree") 382 { 383 *static_cast<bool *>(pDestValue) = mShowBoxes; 384 return true; 385 } 386 else if (strKey == "HiLiteLevel") 387 { 388 *static_cast<int *>(pDestValue) = mHiLiteLevel; 347 389 return true; 348 390 } 349 391 else if (strKey == "ShowAllBoxes") 350 392 { 351 if (mRenderMethod == KdTree::KDRM_INTERNAL) 352 *static_cast<bool *>(pDestValue) = mShowAllBoxes; 353 else 354 *static_cast<bool *>(pDestValue) = mVisualizeCulledNodes; 355 return true; 356 } 357 #endif 358 else if (strKey == "BuildMethod") 359 { 360 if (mBuildMethod == KdTree::KDBM_PRIORITYQUEUE) 361 { 362 *static_cast<String *>(pDestValue) = "PriorityQueue"; 363 } 364 else if (mBuildMethod == KdTree::KDBM_RECURSIVE) 365 { 366 *static_cast<String *>(pDestValue) = "Recursive"; 367 } 368 return true; 369 } 370 else if (strKey == "RenderMethod") 371 { 372 if (mRenderMethod == KdTree::KDRM_INTERNAL) 373 { 374 *static_cast<String *>(pDestValue) = "INT"; 375 } 376 else if (mRenderMethod == KdTree::KDRM_GTP_VFC) 377 { 378 *static_cast<String *>(pDestValue) = "VFC"; 379 } 380 else if (mRenderMethod == KdTree::KDRM_GTP_SWC) 381 { 382 *static_cast<String *>(pDestValue) = "SWC"; 383 } 384 else if (mRenderMethod == KdTree::KDRM_GTP_CHC) 385 { 386 *static_cast<String *>(pDestValue) = "CHC"; 387 } 388 else 389 { 390 return false; 391 } 392 return true; 393 } 394 else if (strKey == "ShowKdTree") 395 { 396 *static_cast<bool *>(pDestValue) = mShowBoxes; 397 return true; 398 } 399 else if (strKey == "ShowNodeAABB") 400 { 401 if (mKdTree) 402 *static_cast<bool *>(pDestValue) = mKdTree->getShowNodeAABB(); 403 else 404 *static_cast<bool *>(pDestValue) = false; 405 return true; 406 } 407 else if (strKey == "TreeBox") 408 { 409 if (mKdTree) 410 *static_cast<AxisAlignedBox *>(pDestValue) = mKdTree->getBox(); 411 else 412 *static_cast<AxisAlignedBox *>(pDestValue) = AxisAlignedBox(); 393 *static_cast<bool *>(pDestValue) = mShowAllBoxes; 394 return true; 395 } 396 else if (strKey == "ShowNodes") 397 { 398 *static_cast<bool *>(pDestValue) = mShowNodes; 399 return true; 413 400 } 414 401 … … 426 413 refKeys.push_back("RenderMethod"); 427 414 refKeys.push_back("ShowKdTree"); 428 refKeys.push_back("ShowNodeAABB"); 429 refKeys.push_back("TreeBox"); 430 #ifdef KDTREE_DEBUG 431 refKeys.push_back("HighlightLevel"); 415 refKeys.push_back("ShowNodes"); 416 refKeys.push_back("HiLiteLevel"); 432 417 refKeys.push_back("ShowAllBoxes"); 433 #endif434 418 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface) 435 419 .getOptionKeys(refKeys); … … 515 499 if (!mKdTree) 516 500 { 517 mKdTree = new KdTree(mMaxDepth); 518 mKdTree->setBuildMethod(mBuildMethod); 501 mKdTree = new KdTree(mMaxDepth, mBuildMethod); 519 502 mKdTree->build(static_cast<KdTreeSceneNode *>(mSceneRoot)); 520 503 } … … 724 707 725 708 getRenderQueue()->clear(); // finally clear render queue 726 if ( 0) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...709 if (1) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ... 727 710 728 711 if (0) WriteLog(); // write out stats
Note: See TracChangeset
for help on using the changeset viewer.