Changeset 1195 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/10/06 17:08:57 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdRenderable.h
r1173 r1195 12 12 13 13 #include "OgreKdTree.h" 14 #include "HierarchyInterface.h"15 14 16 15 namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
r1192 r1195 27 27 #include <stack> 28 28 29 #include "HierarchyInterface.h" 29 30 30 31 … … 210 211 211 212 // Gets this node's parent (NULL if this is the root). 212 Node *getParent(void) const { return mParent; }; 213 // Gets the nodes left & right child nodes, or NULL if not present 214 // or node is leaf 215 virtual Node *getLeftChild(void) const = 0; 216 virtual Node *getRightChild(void) const = 0; 217 218 // returns the level the node is on 219 int getLevel(void) const { return mLevel; }; 220 213 KdTree::Node *getParent(void) const { return mParent; }; 214 215 // Gets the nodes left & right child nodes, or NULL if not present or node is leaf 216 virtual KdTree::Node *getLeftChild(void) const = 0; 217 virtual KdTree::Node *getRightChild(void) const = 0; 218 219 // add contained objects to render queue 221 220 virtual void queueVisibleObjects(unsigned long currentFrame, 222 221 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) = 0; 222 223 // add contained geometry (Entities) to list 224 virtual void getGeometryList(GtpVisibility::GeometryVector *geometryList) = 0; 223 225 226 // create (when necessary), setup and return wire bounding box representing the node 224 227 WireBoundingBox * getWireBoundingBox() 225 228 { … … 238 241 239 242 return mWBB; 240 241 243 } 244 245 // returns the level the node is on 246 int getLevel(void) const { return mLevel; }; 242 247 243 248 // functions for the CHC hierarchy interface … … 270 275 */ 271 276 virtual void _updateBounds(bool recurse = true) = 0; 272 277 278 /** bounding box of the node**/ 273 279 AxisAlignedBox mAABB; 274 280 275 // for the CHC hierarchy interface 276 /** the real extent of the node. */ 281 /** mounding box of all objects inside the node */ 277 282 AxisAlignedBox mWorldAABB; 278 283 protected: … … 283 288 WireBoundingBox * mWBB; 284 289 290 // for the CHC hierarchy interface 285 291 unsigned int mLastRendered; 286 292 unsigned int mLastVisited; … … 317 323 318 324 // a branch should have at least one child 319 virtual Node * getLeftChild() const { return mLeft; };320 virtual Node * getRightChild() const { return mRight; };325 virtual KdTree::Node * getLeftChild() const { return mLeft; }; 326 virtual KdTree::Node * getRightChild() const { return mRight; }; 321 327 322 328 virtual void queueVisibleObjects(unsigned long currentFrame, … … 327 333 queue->addRenderable(getWireBoundingBox()); 328 334 } 335 336 // a branch has no geometry, do nothing 337 virtual void getGeometryList(GtpVisibility::GeometryVector *geometryList) { } 329 338 330 339 // branches do not posses geometry => just merge child aabbs … … 369 378 370 379 // a leaf never has children 371 virtual Node * getLeftChild() const { return 0; };372 virtual Node * getRightChild() const { return 0; };380 virtual KdTree::Node * getLeftChild() const { return 0; }; 381 virtual KdTree::Node * getRightChild() const { return 0; }; 373 382 374 383 virtual void queueVisibleObjects(unsigned long currentFrame, 375 384 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes); 376 385 386 virtual void getGeometryList(GtpVisibility::GeometryVector *geometryList); 387 377 388 // update the world aabb based on the contained geometry 378 389 virtual void _updateBounds(bool recurse = true); … … 394 405 struct SplitCandidate 395 406 { 396 SplitCandidate(PlaneEventList * e, int n, AxisAlignedBox& a, KdTree::Branch * p, Real c, Real d, SplitInfo * b, PlaneEvent::Side s): 397 events(e), nObjects(n), aabb(a), parent(p), cost(c), decrease(d), best(b), side(s) { }; 407 SplitCandidate(PlaneEventList * e, int n, AxisAlignedBox& a, 408 KdTree::Branch * p, Real c, Real d, SplitInfo * b, PlaneEvent::Side s): 409 events(e), nObjects(n), aabb(a), parent(p), cost(c), decrease(d), best(b), side(s) 410 { }; 398 411 399 412 bool operator < (const SplitCandidate& rhs) const … … 504 517 505 518 // test visibility of objects and add to render queue 506 void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes = false); 519 void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 520 bool showBoxes, KdTree::NodeList& visibleNodes); 521 522 // find visible nodes & place in list 523 //void findVisibleNodes(NodeList& visibleNodes, Camera * cam); 507 524 508 525 // self-explanatory ... … … 536 553 537 554 // recursive rendering function 538 void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 539 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes); 555 void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, Camera* cam, 556 RenderQueue* queue, bool onlyShadowCasters, bool showBoxes, KdTree::NodeList& visibleNodes); 557 558 // recursively find visible nodes 559 //void recFindVisibleNodes(KdTree::Node * node, NodeList& visibleNodes, Camera * cam); 540 560 541 561 // the root node of the kdtree -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
r1165 r1195 21 21 Optimization="0" 22 22 AdditionalIncludeDirectories=""$(OGRE_PATH)\PlugIns\OctreeSceneManager\include";"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Dependencies\include";..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src" 23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE ;KDTREE_DEBUG"23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE" 24 24 MinimalRebuild="TRUE" 25 25 BasicRuntimeChecks="3" … … 89 89 OptimizeForProcessor="2" 90 90 AdditionalIncludeDirectories=""$(OGRE_PATH)\PlugIns\OctreeSceneManager\include";"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Dependencies\include";..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src" 91 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE ;KDTREE_DEBUG"91 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE" 92 92 StringPooling="TRUE" 93 93 RuntimeLibrary="2" -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
r1192 r1195 307 307 mMaxDepth(maxdepth), 308 308 mBuildMethod(bm), 309 mHiLiteLevel( HILITE_OFF),309 mHiLiteLevel(0), 310 310 mShowAllBoxes(false), 311 311 mShowNodes(true), … … 335 335 void KdTree::init() 336 336 { 337 // init visualization materials 338 MaterialPtr mphi = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite"); 339 if (mphi.isNull()) 337 MaterialPtr mat; 338 TextureUnitState *tex; 339 340 // init visualization materials (unlit solid green/yellow) 341 mat = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite"); 342 if (mat.isNull()) 340 343 { 341 344 ColourValue green(0, 1, 0); 342 mphi = MaterialManager::getSingleton().create("KdTree/BoxHiLite", "General"); 343 mphi->setAmbient(green); 344 mphi->setDiffuse(green); 345 mphi->setLightingEnabled(true); 346 mphi->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 347 } 348 349 MaterialPtr mpviz = MaterialManager::getSingleton().getByName("KdTree/BoxViz"); 350 if (mpviz.isNull()) 345 mat = MaterialManager::getSingleton().create("KdTree/BoxHiLite", "General"); 346 //mat->setAmbient(green); 347 //mat->setDiffuse(green); 348 mat->setLightingEnabled(false); 349 tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState(); 350 tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, green, green); 351 } 352 353 mat = MaterialManager::getSingleton().getByName("KdTree/BoxViz"); 354 if (mat.isNull()) 351 355 { 352 356 ColourValue yellow(1, 1, 0); 353 mpviz = MaterialManager::getSingleton().create("KdTree/BoxViz", "General"); 354 mpviz->setAmbient(yellow); 355 mpviz->setDiffuse(yellow); 356 mpviz->setLightingEnabled(true); 357 mpviz->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 357 mat = MaterialManager::getSingleton().create("KdTree/BoxViz", "General"); 358 //mat->setAmbient(yellow); 359 //mat->setDiffuse(yellow); 360 mat->setLightingEnabled(false); 361 tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState(); 362 tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, yellow, yellow); 358 363 } 359 364 … … 1180 1185 1181 1186 //------------------------------------------------------------------------- 1182 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1187 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 1188 bool showBoxes, KdTree::NodeList& visibleNodes) 1183 1189 { 1184 1190 if (mKdRoot) 1185 1191 recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), 1186 cam, queue, onlyShadowCasters, showBoxes );1192 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1187 1193 } 1188 1194 1189 1195 //------------------------------------------------------------------------- 1190 1196 void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 1191 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes )1197 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes, KdTree::NodeList& visibleNodes) 1192 1198 { 1193 1199 // test visibility 1194 1200 if (cam->isVisible(node->mAABB)) 1195 1201 { 1196 #if 0 1202 visibleNodes.push_back(node); 1203 1197 1204 node->queueVisibleObjects(currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1198 1205 1199 1206 if (node->getLeftChild()) 1200 recQueueVisibleObjects(node->getLeftChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1207 recQueueVisibleObjects(node->getLeftChild(), currentFrame, 1208 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1201 1209 if (node->getRightChild()) 1202 recQueueVisibleObjects(node->getRightChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1203 #else 1204 #ifdef KDTREE_DEBUG 1205 WireBoundingBox * wbb = 0; 1206 if (showBoxes) 1207 wbb = node->getWireBoundingBox(); 1208 #endif 1209 1210 if (node->isLeaf()) 1211 { 1212 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1213 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 1214 KdRenderableList::iterator end = leaf->mKdRenderables.end(); 1215 while (it != end) 1216 { 1217 if (!(*it)->isQueued(currentFrame, cam)) 1218 { 1219 (*it)->queueObjects(cam, queue, onlyShadowCasters); 1220 } 1221 it++; 1222 } 1223 #ifdef KDTREE_DEBUG 1224 if (wbb) 1225 queue->addRenderable(wbb); 1226 #else 1227 if (showBoxes) 1228 queue->addRenderable(leaf->getWireBoundingBox()); 1229 #endif 1230 } 1231 else 1232 { 1233 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1234 #ifdef KDTREE_DEBUG 1235 if (wbb) 1236 queue->addRenderable(wbb); 1237 #else 1238 if (showBoxes) 1239 queue->addRenderable(branch->getWireBoundingBox()); 1240 #endif 1241 1242 if (branch->mLeft) 1243 recQueueVisibleObjects(branch->mLeft, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1244 if (branch->mRight) 1245 recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1246 } 1247 #endif 1248 } 1249 } 1210 recQueueVisibleObjects(node->getRightChild(), currentFrame, 1211 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1212 } 1213 } 1214 1215 ////------------------------------------------------------------------------- 1216 //void KdTree::findVisibleNodes(NodeList& visibleNodes, Camera * cam) 1217 //{ 1218 // if (mKdRoot) 1219 // recFindVisibleNodes(mKdRoot, visibleNodes, cam); 1220 //} 1221 1222 ////------------------------------------------------------------------------- 1223 //void KdTree::recFindVisibleNodes(KdTree::Node * node, NodeList& visibleNodes, Camera * cam) 1224 //{ 1225 // // test visibility 1226 // if (cam->isVisible(node->mAABB)) 1227 // { 1228 // visibleNodes.push_back(node); 1229 1230 // if (node->getLeftChild()) 1231 // recFindVisibleNodes(node->getLeftChild(), visibleNodes, cam); 1232 // if (node->getRightChild()) 1233 // recFindVisibleNodes(node->getRightChild(), visibleNodes, cam); 1234 // } 1235 //} 1250 1236 1251 1237 /************************************************************************/ … … 1356 1342 } 1357 1343 1344 //------------------------------------------------------------------------- 1358 1345 void KdTree::Leaf::queueVisibleObjects(unsigned long currentFrame, 1359 1346 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) … … 1376 1363 1377 1364 //------------------------------------------------------------------------- 1365 void KdTree::Leaf::getGeometryList(GtpVisibility::GeometryVector *geometryList) 1366 { 1367 KdRenderableList::iterator it = mKdRenderables.begin(); 1368 KdRenderableList::iterator end = mKdRenderables.end(); 1369 while (it != end) 1370 { 1371 (*it)->getGeometryList(geometryList); 1372 it++; 1373 } 1374 } 1375 1376 //------------------------------------------------------------------------- 1378 1377 // update the world aabb based on the contained geometry 1379 1378 void KdTree::Leaf::_updateBounds(bool recurse) -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp
r1187 r1195 42 42 else 43 43 { 44 KdTree::Branch * kdbranch = KDBRANCHPTR_CAST(node); 45 if (kdbranch->mLeft) 46 mDistanceQueue->push(kdbranch->mLeft); 47 if (kdbranch->mRight) 48 mDistanceQueue->push(kdbranch->mRight); 44 //KdTree::Branch * kdbranch = KDBRANCHPTR_CAST(node); 45 //if (kdbranch->mLeft) 46 // mDistanceQueue->push(kdbranch->mLeft); 47 //if (kdbranch->mRight) 48 // mDistanceQueue->push(kdbranch->mRight); 49 if (kdnode->getLeftChild()) 50 mDistanceQueue->push(kdnode->getLeftChild()); 51 if (kdnode->getRightChild()) 52 mDistanceQueue->push(kdnode->getRightChild()); 49 53 } 50 54 } … … 133 137 } 134 138 135 // TODO: maybe boxlist?136 139 dynamic_cast<KdTreeSceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box); 137 140 } … … 141 144 bool includeChildren) 142 145 { 143 KdTree::Node * kdnode = KDNODEPTR_CAST(node); 144 if (kdnode->isLeaf()) 145 { 146 KdTree::Leaf * kdleaf = KDLEAFPTR_CAST(node); 147 KdRenderableList::iterator it = kdleaf->mKdRenderables.begin(); 148 KdRenderableList::iterator end = kdleaf->mKdRenderables.end(); 149 while (it != end) 150 { 151 (*it)->getGeometryList(geometryList); 152 it++; 153 } 154 } 146 KDNODEPTR_CAST(node)->getGeometryList(geometryList); 155 147 } 156 148 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r1192 r1195 539 539 { 540 540 getRenderQueue()->clear(); 541 if (mKdTree) 542 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes); 541 if (mShowVisualization) 542 { 543 PrepareVisualization(cam); 544 } 545 else 546 { 547 mVisibleNodes.clear(); 548 if (mKdTree) 549 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes, mVisibleNodes); 550 } 543 551 } 544 552 else … … 561 569 getRenderQueue()->clear(); 562 570 if (mKdTree) 563 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes );571 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes, mVisibleNodes); 564 572 } 565 573 … … 571 579 //updatePvs(cam); 572 580 } 573 } 574 575 mVisibleNodes.clear(); 581 mVisibleNodes.clear(); 582 } 576 583 } 577 584 … … 726 733 mVisibleNodes.push_back(node); 727 734 728 //KdRenderableList::const_iterator it = nodelist.begin();729 //KdRenderableList::const_iterator end = nodelist.end();730 //while (it != end)731 //{732 // if (!(*it)->isQueued(mHierarchyInterface->GetFrameId(), cam))733 // {734 // mVisibleNodes.push_back(*it);735 // (*it)->queueObjects(cam, getRenderQueue(), onlyShadowCasters);736 // }737 // it++;738 //}739 740 735 _renderQueueGroupObjects(currentGroup, QueuedRenderableCollection::OM_PASS_GROUP); 741 736 } … … 937 932 if (mRenderNodesForViz || mRenderNodesContentForViz) 938 933 { 939 // HACK: change node material so it is better suited for visualization 940 //MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial"); 934 RenderQueue * queue = getRenderQueue(); 935 unsigned long frameid = 0; 936 937 if (mRenderMethod == KdTree::KDRM_INTERNAL) 938 frameid = Root::getSingleton().getCurrentFrameNumber(); 939 else 940 frameid = mHierarchyInterface->GetFrameId(); 941 941 942 942 for (KdTree::NodeList::iterator it = mVisibleNodes.begin(); it != mVisibleNodes.end(); ++it) 943 943 { 944 if (mRenderNodesForViz )944 if (mRenderNodesForViz && (*it)->isLeaf()) 945 945 { 946 946 WireBoundingBox * wirebox = (*it)->getWireBoundingBox(); 947 if (wirebox)948 947 wirebox->setMaterial("KdTree/BoxViz"); 948 getRenderQueue()->addRenderable(wirebox); 949 949 } 950 950 // add renderables itself 951 951 if (mRenderNodesContentForViz) 952 952 { 953 (*it)->queueVisibleObjects(mHierarchyInterface->GetFrameId(), 954 cam, getRenderQueue(), false, true); 953 (*it)->queueVisibleObjects(frameid, cam, queue, false, false); 955 954 } 956 955 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneNode.cpp
r1190 r1195 142 142 { 143 143 Entity *ent = static_cast<Entity *>(movable); 144 //std::stringstream d; d << "ent " << ent->getName();145 //LogManager::getSingleton().logMessage(d.str());146 144 geometryList->push_back(ent); 147 145 }
Note: See TracChangeset
for help on using the changeset viewer.