Changeset 1170 for GTP/trunk/Lib/Vis
- Timestamp:
- 07/28/06 17:06:01 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
r1165 r1170 11 11 #define _OgreKdTree_H__ 12 12 13 #define KDNODE_CAST(a) (static_cast<KdTree::Node>(a)) 14 #define KDBRANCH_CAST(a) (static_cast<KdTree::Branch>(a)) 15 #define KDLEAF_CAST(a) (static_cast<KdTree::Leaf>(a)) 16 #define KDNODEPTR_CAST(a) (static_cast<KdTree::Node *>(a)) 17 #define KDBRANCHPTR_CAST(a) (static_cast<KdTree::Branch *>(a)) 18 #define KDLEAFPTR_CAST(a) (static_cast<KdTree::Leaf *>(a)) 19 13 20 #include <OgreAxisAlignedBox.h> 14 21 #include <OgreWireBoundingBox.h> … … 20 27 #include <stack> 21 28 22 #include "OgreKdTreeHierarchyInterface.h" 29 //#include "OgreKdTreeHierarchyInterface.h" 30 23 31 24 32 namespace Ogre … … 199 207 virtual bool isLeaf() const = 0; 200 208 virtual bool isEmpty() const = 0; 209 virtual bool hasGeometry() const = 0; 201 210 202 211 // consider using typesafe callback functions … … 240 249 } 241 250 251 // functions for the CHC hierarchy interface 252 253 /** Returns last visited frame id. */ 254 unsigned int lastVisited(void) { return mLastVisited; }; 255 /** Set to current frame id. 256 @param current frame id. 257 */ 258 void setLastVisited(unsigned int frameid) { mLastVisited = frameid; }; 259 /** Makes this octree become visible / invisble. 260 @param visible Whether this node is to be made visible or invisible 261 */ 262 void setNodeVisible(bool visible) { mVisible = visible; }; 263 /** Returns true if this node is marked visible, false otherwise. 264 */ 265 bool isNodeVisible(void) { return mVisible; }; 266 /** Gets this node's parent (NULL if this is the root). 267 */ 268 KdTree::Node *getParent(void) { return mParent; }; 269 /** Frame id when this octree was last rendered. 270 @return last rendered frame id 271 */ 272 unsigned int lastRendered(void) { return mLastRendered; }; 273 /** Sets frame id when this octree was last rendered. 274 @param last rendered frame id 275 */ 276 void setLastRendered(unsigned int frameid) { mLastRendered = frameid; }; 277 278 /* do we need this? */ 279 /** Returns real extent of the octree, i.e., the merged extent of the bounding boxes. 280 */ 281 //AxisAlignedBox _getWorldAABB(void) const = 0; 282 283 242 284 Branch * mParent; 243 285 int mLevel; … … 245 287 protected: 246 288 WireBoundingBox * mWBB; 289 290 // for the CHC hierarchy interface 291 /** the real extent of the node. */ 292 //AxisAlignedBox mWorldAABB; 293 294 unsigned int mLastRendered; 295 unsigned int mLastVisited; 296 bool mVisible; 247 297 }; 248 298 … … 265 315 }; 266 316 317 // a branch is not a leaf 267 318 virtual bool isLeaf() const { return false; }; 268 319 320 // s branch is empty when it does not have children 269 321 virtual bool isEmpty() const { return (mLeft == 0 && mRight == 0); } 322 323 // a branch never has geometry 324 virtual bool hasGeometry() const { return false; }; 270 325 271 326 Node * mLeft; … … 284 339 virtual ~Leaf(); 285 340 341 // a leaf is a leaf, dammit 286 342 virtual bool isLeaf() const { return true; }; 287 343 344 // a leaf is empty when it does not posses renderables 288 345 virtual bool isEmpty() const { return mKdRenderables.empty(); }; 346 347 // a leaf has geometry when it has renderables 348 virtual bool hasGeometry() const { return !mKdRenderables.empty(); }; 289 349 290 350 virtual void remove(KdRenderable * rend) … … 337 397 }; 338 398 339 // typedef std::stack<SplitCandidate> SplitCandidatePQ;399 // typedef std::stack<SplitCandidate> SplitCandidatePQ; 340 400 typedef std::priority_queue<SplitCandidate> SplitCandidatePQ; 341 401 402 // nodestack for the stack-based rendering function 403 typedef std::stack<KdTree::Node *> NodeStack; 342 404 public: 343 friend class Ogre::KdTreeHierarchyInterface;405 friend class KdTreeHierarchyInterface; 344 406 345 407 typedef KdTree::Leaf * LeafPtr; 346 408 typedef std::set<LeafPtr> LeafSet; 409 410 enum RenderMethod 411 { 412 KDRM_RECURSE, 413 KDRM_STACK, 414 KDRM_SAW, 415 KDRM_CHC 416 }; 347 417 348 418 enum BuildMethod … … 356 426 357 427 // DEBUG 358 void KdTree::dump();359 void KdTree::calcCost();428 void dump(); 429 void calcCost(); 360 430 361 431 // insert a new scene node into an existing kd-tree … … 367 437 368 438 // test visibility of objects and add to render queue 369 void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes = false); 439 void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 440 RenderMethod renderMethod, bool showBoxes = false); 370 441 371 442 // self-explanatory ... … … 396 467 397 468 // recursive rendering function 398 void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes); 469 void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 470 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes); 471 // stack based rendering function 472 void stackQueueVisibleObjects(KdTree::Node * root, unsigned long currentFrame, 473 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes); 399 474 400 475 // the root node of the kdtree -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h
r1165 r1170 11 11 #define _OgreKdTreeHierarchyInterface_H_ 12 12 13 #include "Ogre SceneNodeHierarchyInterface.h"13 #include "OgrePlatformHierarchyInterface.h" 14 14 15 15 namespace Ogre … … 18 18 class KdTreeSceneManager; 19 19 20 class KdTreeHierarchyInterface : public SceneNodeHierarchyInterface20 class KdTreeHierarchyInterface : public PlatformHierarchyInterface 21 21 { 22 22 public: 23 23 KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys); 24 24 25 virtual ~KdTreeHierarchyInterface() {}; 25 26 26 bool IsLeaf(GtpVisibility::HierarchyNode *node) const; 27 /** Returns true if current node is leaf of the hierarchy. 28 @param node hierarchy node 29 @returns true if node is leaf 30 */ 31 virtual bool IsLeaf(GtpVisibility::HierarchyNode *node) const; 32 /** Traverses and renders the hierarchy from the given node. 33 @param node the hierarchy node 34 */ 35 virtual void TraverseNode(GtpVisibility::HierarchyNode *node); 36 /** Renders the given hierarchy node. 37 @param node current hierarchy node to be rendered 38 */ 39 virtual void RenderNode(GtpVisibility::HierarchyNode *node); 40 /** Pulls up the visibility from the current node recursively to the parent nodes. 41 @param node the current node 42 */ 43 virtual void PullUpVisibility(GtpVisibility::HierarchyNode *node) const; 44 45 /** Returns distance of the node to the view plane. 46 @param node the hierarchy node 47 */ 48 virtual float GetSquaredDistance(GtpVisibility::HierarchyNode *node) const; 49 /** Returns pointer to bounding box of node. 50 @param node current hierarchy node 51 @returns bounding box of current node 52 */ 53 virtual AxisAlignedBox *GetBoundingBox(GtpVisibility::HierarchyNode *node); 54 /** Returns true if there is renderable geometry attached to this node 55 @param node the current node 56 @returns if the node has renderable geometry 57 */ 58 virtual bool HasGeometry(GtpVisibility::HierarchyNode *node) const; 59 /** Sets the visible flag for this node. 60 @param node the current node 61 @param visible the visible flag 62 */ 63 virtual void SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const; 64 /** Returns true if node has the visible flag set. See set 65 */ 66 virtual bool IsNodeVisible(GtpVisibility::HierarchyNode *node) const; 67 /** Sets the last visited frame id for this node. 68 @param node the current node 69 @param frameId the current frame id 70 */ 71 virtual void SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const; 72 /** Returns frame id when this node was last visited by the traverser. See set 73 */ 74 virtual unsigned int LastVisited(GtpVisibility::HierarchyNode *node) const; 75 76 77 /** Visualization of a culled node, dependent on the culling type. 78 @param node the hierarchy node to be visualized 79 @param type can be one of FRUSTUM_CULLED, QUERY_CULLED 80 */ 81 virtual void VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 82 GtpVisibility::CullingType type) const; 83 84 85 /** Returns the geometry of a given hierarchy node. 86 @param node the hierarchy node containing the geometry 87 @param geometryList geometry is returned in this list 88 @param includeChildren if the geometry of the children should be taken into account 89 */ 90 virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node, 91 GtpVisibility::GeometryVector *geometryList, 92 bool includeChildren); 93 94 27 95 }; 28 96 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
r1165 r1170 70 70 bool mShowBoxes; 71 71 72 KdTree::RenderMethod mRenderMethod; 73 72 74 KdTree::BuildMethod mBuildMethod; 73 75 #ifdef KDTREE_DEBUG -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
r1163 r1170 465 465 else 466 466 { 467 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);467 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 468 468 AxisAlignedBox aabb = rend->getBoundingBox(); 469 469 Plane::Side smin = branch->mSplitPlane->getSide(aabb.getMinimum()); … … 576 576 else 577 577 { 578 KdTree::Branch * parent = static_cast<KdTree::Branch *>(node->mParent);578 KdTree::Branch * parent = KDBRANCHPTR_CAST(node->mParent); 579 579 580 580 if (node == parent->mLeft) … … 619 619 if (node->isLeaf()) 620 620 { 621 KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);621 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 622 622 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 623 623 KdRenderableList::iterator end = leaf->mKdRenderables.end(); … … 630 630 else 631 631 { 632 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);632 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 633 633 if (branch->mLeft) 634 634 addRendToList(branch->mLeft, nodelist); … … 1272 1272 } 1273 1273 1274 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1275 { 1274 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 1275 KdTree::RenderMethod renderMethod, bool showBoxes) 1276 { 1277 // for now only recurse or stack render methods 1276 1278 if (mKdRoot) 1277 recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), cam, queue, onlyShadowCasters, showBoxes); 1278 } 1279 1280 void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1279 { 1280 //if (renderMethod == KdTree::KDRM_STACK) 1281 //{ 1282 // stackQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), 1283 // cam, queue, onlyShadowCasters, showBoxes); 1284 //} 1285 //else 1286 //{ 1287 recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), 1288 cam, queue, onlyShadowCasters, showBoxes); 1289 //} 1290 } 1291 } 1292 1293 void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 1294 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1281 1295 { 1282 1296 // test visibility … … 1291 1305 if (node->isLeaf()) 1292 1306 { 1293 KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);1307 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1294 1308 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 1295 1309 KdRenderableList::iterator end = leaf->mKdRenderables.end(); … … 1312 1326 else 1313 1327 { 1314 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);1328 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1315 1329 #ifdef KDTREE_DEBUG 1316 1330 if (wbb) … … 1325 1339 if (branch->mRight) 1326 1340 recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1341 } 1342 } 1343 } 1344 1345 void KdTree::stackQueueVisibleObjects(KdTree::Node * root, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1346 { 1347 static NodeStack nodestack; 1348 if (!nodestack.empty()) OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 1349 "Stuff left in stack from previos frame", "KdTree::stackQueueVisibleObjects"); 1350 1351 nodestack.push(root); 1352 1353 while (!nodestack.empty()) 1354 { 1355 KdTree::Node * node = nodestack.top(); 1356 nodestack.pop(); 1357 1358 // test visibility 1359 if (cam->isVisible(node->mAABB)) 1360 { 1361 #ifdef KDTREE_DEBUG 1362 WireBoundingBox * wbb = 0; 1363 if (showBoxes) 1364 wbb = node->getWireBoundingBox(); 1365 #endif 1366 1367 if (node->isLeaf()) 1368 { 1369 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1370 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 1371 KdRenderableList::iterator end = leaf->mKdRenderables.end(); 1372 while (it != end) 1373 { 1374 if (!(*it)->isQueued(currentFrame, cam)) 1375 { 1376 (*it)->queueObjects(cam, queue, onlyShadowCasters); 1377 } 1378 it++; 1379 } 1380 #ifdef KDTREE_DEBUG 1381 if (wbb) 1382 queue->addRenderable(wbb); 1383 #else 1384 if (showBoxes) 1385 queue->addRenderable(leaf->getWireBoundingBox()); 1386 #endif 1387 } 1388 else 1389 { 1390 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1391 #ifdef KDTREE_DEBUG 1392 if (wbb) 1393 queue->addRenderable(wbb); 1394 #else 1395 if (showBoxes) 1396 queue->addRenderable(branch->getWireBoundingBox()); 1397 #endif 1398 1399 if (branch->mLeft) 1400 nodestack.push(branch->mLeft); 1401 if (branch->mRight) 1402 nodestack.push(branch->mRight); 1403 } 1327 1404 } 1328 1405 } … … 1351 1428 if (node->isLeaf()) 1352 1429 { 1353 KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);1430 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1354 1431 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 1355 1432 KdRenderableList::iterator end = leaf->mKdRenderables.end(); … … 1365 1442 else 1366 1443 { 1367 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);1444 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1368 1445 if (branch->mLeft) 1369 1446 { … … 1396 1473 if (node->isLeaf()) 1397 1474 { 1398 KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);1475 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1399 1476 return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KI*leaf->mKdRenderables.size(); 1400 1477 } 1401 1478 else 1402 1479 { 1403 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);1480 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1404 1481 return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KT + calcCost(branch->mLeft, vs) + calcCost(branch->mRight, vs); 1405 1482 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp
r1165 r1170 15 15 16 16 KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys): 17 SceneNodeHierarchyInterface(sm, rsys)17 PlatformHierarchyInterface(sm, rsys) 18 18 { 19 19 … … 22 22 bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const 23 23 { 24 KdTree::Node * kdnode = static_cast<KdTree::Node *>(node); 25 return kdnode->isLeaf(); 24 return KDNODEPTR_CAST(node)->isLeaf(); 26 25 } 27 26 27 void KdTreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node) 28 { 29 ++ mNumTraversedNodes; 28 30 31 KdTree::Node * kdnode = KDNODEPTR_CAST(node); 32 33 // if the node is a leaf and has geometry => render it 34 if (kdnode->isLeaf()) 35 { 36 if (!kdnode->isEmpty()) 37 { 38 RenderNode(node); 39 } 40 } 41 else 42 { 43 KdTree::Branch * kdbranch = KDBRANCHPTR_CAST(node); 44 if (kdbranch->mLeft) 45 mDistanceQueue->push(kdbranch->mLeft); 46 if (kdbranch->mRight) 47 mDistanceQueue->push(kdbranch->mRight); 48 } 29 49 } 50 51 void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) 52 { 53 /*** TODO ***/ 54 } 55 56 void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const 57 { 58 /*** TODO ***/ 59 } 60 61 float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 62 { 63 /*** TODO ***/ 64 return 0.0; 65 } 66 67 AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) 68 { 69 /*** TODO ***/ 70 return new AxisAlignedBox(); 71 } 72 73 bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const 74 { 75 return KDNODEPTR_CAST(node)->hasGeometry(); 76 } 77 78 void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const 79 { 80 /*** TODO ***/ 81 } 82 83 bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const 84 { 85 /*** TODO ***/ 86 return true; 87 } 88 89 void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const 90 { 91 /*** TODO ***/ 92 } 93 94 unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const 95 { 96 /*** TODO ***/ 97 return 0; 98 } 99 100 void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 101 GtpVisibility::CullingType type) const 102 { 103 /*** TODO ***/ 104 } 105 106 void KdTreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, 107 GtpVisibility::GeometryVector *geometryList, 108 bool includeChildren) 109 { 110 /*** TODO ***/ 111 } 112 113 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
r1165 r1170 32 32 // kill the old kd-tree if exists 33 33 OGRE_DELETE(mKdTree); 34 35 mRenderMethod = KdTree::KDRM_RECURSE; 34 36 35 37 //mBuildMethod = KdTree::KDBM_RECURSIVE; … … 160 162 } 161 163 } 164 else if (strKey == "RenderMethod") 165 { 166 String rm = *static_cast<const String *>(pValue); 167 if (rm == "Recursive") 168 { 169 mRenderMethod = KdTree::KDRM_RECURSE; 170 return true; 171 } 172 else if (rm == "Stack") 173 { 174 mRenderMethod = KdTree::KDRM_STACK; 175 return true; 176 } 177 else if (rm == "StopAndWait") 178 { 179 mRenderMethod = KdTree::KDRM_SAW; 180 return true; 181 } 182 else if (rm == "CHC") 183 { 184 mRenderMethod = KdTree::KDRM_CHC; 185 return true; 186 } 187 else 188 { 189 return false; 190 } 191 } 162 192 else if (strKey == "ShowKdTree") 163 193 { … … 208 238 { 209 239 *static_cast<String *>(pDestValue) = "Recursive"; 240 } 241 return true; 242 } 243 else if (strKey == "RenderMethod") 244 { 245 if (mRenderMethod == KdTree::KDRM_RECURSE) 246 { 247 *static_cast<String *>(pDestValue) = "Recursive"; 248 } 249 else if (mRenderMethod == KdTree::KDRM_STACK) 250 { 251 *static_cast<String *>(pDestValue) = "Stack"; 252 } 253 else if (mRenderMethod == KdTree::KDRM_SAW) 254 { 255 *static_cast<String *>(pDestValue) = "StopAndWait"; 256 } 257 else if (mRenderMethod == KdTree::KDRM_CHC) 258 { 259 *static_cast<String *>(pDestValue) = "CHC"; 210 260 } 211 261 return true; … … 278 328 // inserting single nodes yields sub-optimal results 279 329 // rebuilding tree takes too long 280 // "What now ", spoke Zeus ...330 // "What now?", spoke Zeus ... 281 331 282 332 //mKdTree->insert(node); … … 293 343 getRenderQueue()->clear(); 294 344 if (mKdTree) 295 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, m ShowBoxes);345 mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mRenderMethod, mShowBoxes); 296 346 //SceneManager::_findVisibleObjects(cam, onlyShadowCasters); 297 347 }
Note: See TracChangeset
for help on using the changeset viewer.