Changeset 1170


Ignore:
Timestamp:
07/28/06 17:06:01 (18 years ago)
Author:
szydlowski
Message:

continued work on the hierarchy interface

Location:
GTP/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h

    r1165 r1170  
    5454        Real mRotationPeriod; 
    5555        bool mShowTree; 
     56        bool mFreeMove; 
    5657 
    5758        int mSeqNum; 
     
    122123        } 
    123124 
     125                mFreeMove = false; 
    124126                mShowTree = false; 
    125127                mCullCamera = false; 
     
    210212                caption = OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->getCaption(); 
    211213                OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(caption + value); 
     214 
     215                String rm; 
     216                if (mSceneMgr->getOption("RenderMethod", &rm)) 
     217                        value = " " + rm; 
     218                else 
     219                        value = na; 
     220                caption = OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->getCaption(); 
     221                OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(caption + value); 
     222 
     223                value = na; 
     224                if (mFreeMove) 
     225                        value = " Free"; 
     226                else 
     227                        value = " Ground"; 
     228                caption = OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->getCaption(); 
     229                OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->setCaption(caption + value); 
    212230        } 
    213231 
     
    264282                static String sKT = "[5][6] KT: "; 
    265283                static String sKI = "[7][8] KI: "; 
    266                 static String sBM = "[Space] Build Method: "; 
    267  
    268                 static String bmRec = "Recursive"; 
    269                 static String bmPQ = "PriorityQueue"; 
     284                static String sBM = "[Y] Build Method: "; 
     285                static String sRM = "[X] Render Method: "; 
     286                static String sMov = "[Q] Movement: "; 
     287 
     288                static String bmOptions[] = { "Recursive", "PriorityQueue" }; 
     289                static int bmOptionsSize = sizeof(bmOptions) / sizeof(String); 
     290                static int bmCurrent = 0; 
     291 
     292                //static String rmOptions[] = { "Recursive", "Stack", "StopAndWait", "CHC" }; 
     293                static String rmOptions[] = { "Recursive", "Stack" }; 
     294                static int rmOptionsSize = sizeof(rmOptions) / sizeof (String); 
     295                static int rmCurrent = 0; 
    270296 
    271297                if ((mInputDevice->isKeyDown(KC_1) || mInputDevice->isKeyDown(KC_2)) && mTimeUntilNextToggle <= 0) 
     
    374400                } 
    375401 
    376                 if (mInputDevice->isKeyDown(KC_SPACE) && mTimeUntilNextToggle <= 0) 
     402                if (mInputDevice->isKeyDown(KC_Z) && mTimeUntilNextToggle <= 0) 
    377403                { 
    378404                        String bm; 
    379405                        if (mSceneMgr->getOption("BuildMethod", &bm)) 
    380406                        { 
    381                                 if (bm == bmRec) 
    382                                         bm = bmPQ; 
    383                                 else if (bm == bmPQ) 
    384                                         bm = bmRec; 
    385                                 if (mSceneMgr->setOption("BuildMethod", &bm)) 
    386                                         OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(sBM + bm); 
     407                                bmCurrent = (bmCurrent + 1) % bmOptionsSize; 
     408                                if (mSceneMgr->setOption("BuildMethod", &bmOptions[bmCurrent])) 
     409                                        OverlayManager::getSingleton().getOverlayElement("KdTree/BuildMethod")->setCaption(sBM + bmOptions[bmCurrent]); 
    387410                        } 
    388411                        else 
     
    391414                        } 
    392415 
    393                         mTimeUntilNextToggle = 0.2; 
    394                 } 
     416                        mTimeUntilNextToggle = 0.5; 
     417                } 
     418 
     419                if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0) 
     420                { 
     421                        String rm; 
     422                        if (mSceneMgr->getOption("RenderMethod", &rm)) 
     423                        { 
     424                                rmCurrent = (rmCurrent + 1) % rmOptionsSize; 
     425                                if (mSceneMgr->setOption("RenderMethod", &rmOptions[rmCurrent])) 
     426                                        OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(sRM + rmOptions[rmCurrent]); 
     427                        } 
     428                        else 
     429                        { 
     430                                OverlayManager::getSingleton().getOverlayElement("KdTree/RenderMethod")->setCaption(sRM + "N/A"); 
     431                        } 
     432 
     433                        mTimeUntilNextToggle = 0.5; 
     434                } 
     435 
     436                if (mInputDevice->isKeyDown(KC_Q) && mTimeUntilNextToggle <= 0) 
     437                { 
     438                        mFreeMove = !mFreeMove; 
     439                        String move = "N/A"; 
     440                        if (mFreeMove) 
     441                                move = "Free"; 
     442                        else 
     443                                move = "Ground"; 
     444 
     445                        OverlayManager::getSingleton().getOverlayElement("KdTree/Movement")->setCaption(sMov + move); 
     446 
     447                        mTimeUntilNextToggle = 0.5; 
     448                } 
     449 
    395450 
    396451                if (mInputDevice->isKeyDown(KC_BACK) && mTimeUntilNextToggle <= 0) 
     
    667722                mTopCam->moveRelative(mCullTransVec); 
    668723 
    669                 Vector3 pos = mCamera->getPosition(); 
    670                 RaySceneQuery * rsquery = mSceneMgr->createRayQuery(Ray(pos, Vector3::NEGATIVE_UNIT_Y)); 
    671                 RaySceneQueryResult& rsresult = rsquery->execute(); 
    672  
    673                 RaySceneQueryResult::iterator it = rsresult.begin(); 
    674                 RaySceneQueryResult::iterator end = rsresult.end(); 
    675  
    676                 while (it != end && it->movable) 
    677                 { 
    678                         if (it->movable->getName() != "PlayerCam") 
    679                         { 
    680                                 mCamera->setPosition(pos.x, it->movable->getWorldBoundingBox().getCenter().y + 3, pos.z); 
    681                                 break; 
    682                         } 
    683                         it++; 
    684                 } 
    685                 OGRE_DELETE(rsquery); 
     724                if (!mFreeMove) 
     725                { 
     726                        Vector3 pos = mCamera->getPosition(); 
     727                        RaySceneQuery * rsquery = mSceneMgr->createRayQuery(Ray(pos, Vector3::NEGATIVE_UNIT_Y)); 
     728                        RaySceneQueryResult& rsresult = rsquery->execute(); 
     729 
     730                        RaySceneQueryResult::iterator it = rsresult.begin(); 
     731                        RaySceneQueryResult::iterator end = rsresult.end(); 
     732 
     733                        while (it != end && it->movable) 
     734                        { 
     735                                if (it->movable->getName() != "PlayerCam") 
     736                                { 
     737                                        mCamera->setPosition(pos.x, it->movable->getWorldBoundingBox().getCenter().y + 3, pos.z); 
     738                                        break; 
     739                                } 
     740                                it++; 
     741                        } 
     742                        OGRE_DELETE(rsquery); 
     743                } 
    686744        } 
    687745 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h

    r1165 r1170  
    1111#define _OgreKdTree_H__ 
    1212 
     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 
    1320#include <OgreAxisAlignedBox.h> 
    1421#include <OgreWireBoundingBox.h> 
     
    2027#include <stack> 
    2128 
    22 #include "OgreKdTreeHierarchyInterface.h" 
     29//#include "OgreKdTreeHierarchyInterface.h" 
     30 
    2331 
    2432namespace Ogre 
     
    199207                        virtual bool isLeaf() const = 0; 
    200208                        virtual bool isEmpty() const = 0; 
     209                        virtual bool hasGeometry() const = 0; 
    201210                         
    202211                        // consider using typesafe callback functions 
     
    240249                        } 
    241250 
     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 
    242284                        Branch * mParent; 
    243285                        int mLevel; 
     
    245287                protected: 
    246288                        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; 
    247297                }; 
    248298 
     
    265315                        }; 
    266316 
     317                        // a branch is not a leaf  
    267318                        virtual bool isLeaf() const { return false; }; 
    268319 
     320                        // s branch is empty when it does not have children 
    269321                        virtual bool isEmpty() const { return (mLeft == 0 && mRight == 0); } 
     322 
     323                        // a branch never has geometry 
     324                        virtual bool hasGeometry() const { return false; }; 
    270325                         
    271326                        Node * mLeft; 
     
    284339                        virtual ~Leaf(); 
    285340 
     341                        // a leaf is a leaf, dammit 
    286342                        virtual bool isLeaf() const { return true; }; 
    287343 
     344                        // a leaf is empty when it does not posses renderables 
    288345                        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(); }; 
    289349 
    290350                        virtual void remove(KdRenderable * rend) 
     
    337397                }; 
    338398 
    339                 //typedef std::stack<SplitCandidate> SplitCandidatePQ; 
     399                // typedef std::stack<SplitCandidate> SplitCandidatePQ; 
    340400                typedef std::priority_queue<SplitCandidate> SplitCandidatePQ; 
    341401 
     402                // nodestack for the stack-based rendering function 
     403                typedef std::stack<KdTree::Node *> NodeStack; 
    342404        public: 
    343                 friend class Ogre::KdTreeHierarchyInterface; 
     405                friend class KdTreeHierarchyInterface; 
    344406 
    345407                typedef KdTree::Leaf * LeafPtr; 
    346408                typedef std::set<LeafPtr> LeafSet; 
     409 
     410                enum RenderMethod 
     411                { 
     412                        KDRM_RECURSE, 
     413                        KDRM_STACK, 
     414                        KDRM_SAW, 
     415                        KDRM_CHC 
     416                }; 
    347417 
    348418                enum BuildMethod 
     
    356426 
    357427                // DEBUG 
    358                 void KdTree::dump(); 
    359                 void KdTree::calcCost(); 
     428                void dump(); 
     429                void calcCost(); 
    360430 
    361431                // insert a new scene node into an existing kd-tree 
     
    367437 
    368438                // 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); 
    370441 
    371442                // self-explanatory ... 
     
    396467 
    397468                // 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); 
    399474 
    400475                // the root node of the kdtree 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h

    r1165 r1170  
    1111#define _OgreKdTreeHierarchyInterface_H_ 
    1212 
    13 #include "OgreSceneNodeHierarchyInterface.h" 
     13#include "OgrePlatformHierarchyInterface.h" 
    1414 
    1515namespace Ogre 
     
    1818class KdTreeSceneManager; 
    1919 
    20 class KdTreeHierarchyInterface : public SceneNodeHierarchyInterface 
     20class KdTreeHierarchyInterface : public PlatformHierarchyInterface 
    2121{ 
    2222public: 
    2323        KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys); 
     24 
    2425        virtual ~KdTreeHierarchyInterface() {}; 
    2526 
    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 
    2795}; 
    2896 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h

    r1165 r1170  
    7070                bool mShowBoxes; 
    7171 
     72                KdTree::RenderMethod mRenderMethod; 
     73 
    7274                KdTree::BuildMethod mBuildMethod; 
    7375#ifdef KDTREE_DEBUG 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp

    r1163 r1170  
    465465                else 
    466466                { 
    467                         KdTree::Branch * branch = static_cast<KdTree::Branch *>(node); 
     467                        KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 
    468468                        AxisAlignedBox aabb = rend->getBoundingBox(); 
    469469                        Plane::Side smin = branch->mSplitPlane->getSide(aabb.getMinimum()); 
     
    576576                else 
    577577                { 
    578                         KdTree::Branch * parent = static_cast<KdTree::Branch *>(node->mParent); 
     578                        KdTree::Branch * parent = KDBRANCHPTR_CAST(node->mParent); 
    579579 
    580580                        if (node == parent->mLeft) 
     
    619619                if (node->isLeaf()) 
    620620                { 
    621                         KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node); 
     621                        KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 
    622622                        KdRenderableList::iterator it  = leaf->mKdRenderables.begin(); 
    623623                        KdRenderableList::iterator end = leaf->mKdRenderables.end(); 
     
    630630                else 
    631631                { 
    632                         KdTree::Branch * branch = static_cast<KdTree::Branch *>(node); 
     632                        KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 
    633633                        if (branch->mLeft) 
    634634                                addRendToList(branch->mLeft, nodelist); 
     
    12721272        } 
    12731273 
    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 
    12761278                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) 
    12811295        { 
    12821296                // test visibility 
     
    12911305                        if (node->isLeaf()) 
    12921306                        { 
    1293                                 KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node); 
     1307                                KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 
    12941308                                KdRenderableList::iterator it  = leaf->mKdRenderables.begin(); 
    12951309                                KdRenderableList::iterator end = leaf->mKdRenderables.end(); 
     
    13121326                        else 
    13131327                        { 
    1314                                 KdTree::Branch * branch = static_cast<KdTree::Branch *>(node); 
     1328                                KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 
    13151329#ifdef KDTREE_DEBUG 
    13161330                                if (wbb) 
     
    13251339                                if (branch->mRight) 
    13261340                                        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                                } 
    13271404                        } 
    13281405                } 
     
    13511428                if (node->isLeaf()) 
    13521429                { 
    1353                         KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node); 
     1430                        KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 
    13541431                        KdRenderableList::iterator it  = leaf->mKdRenderables.begin(); 
    13551432                        KdRenderableList::iterator end = leaf->mKdRenderables.end(); 
     
    13651442                else 
    13661443                { 
    1367                         KdTree::Branch * branch = static_cast<KdTree::Branch *>(node); 
     1444                        KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 
    13681445                        if (branch->mLeft) 
    13691446                        { 
     
    13961473                if (node->isLeaf()) 
    13971474                { 
    1398                         KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node); 
     1475                        KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 
    13991476                        return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KI*leaf->mKdRenderables.size(); 
    14001477                } 
    14011478                else 
    14021479                { 
    1403                         KdTree::Branch * branch = static_cast<KdTree::Branch *>(node); 
     1480                        KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 
    14041481                        return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KT + calcCost(branch->mLeft, vs) + calcCost(branch->mRight, vs); 
    14051482                } 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp

    r1165 r1170  
    1515 
    1616KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys): 
    17         SceneNodeHierarchyInterface(sm, rsys) 
     17PlatformHierarchyInterface(sm, rsys) 
    1818{ 
    1919 
     
    2222bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const 
    2323{ 
    24         KdTree::Node * kdnode = static_cast<KdTree::Node *>(node); 
    25         return kdnode->isLeaf(); 
     24        return KDNODEPTR_CAST(node)->isLeaf(); 
    2625} 
    2726 
     27void KdTreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node) 
     28{ 
     29        ++ mNumTraversedNodes; 
    2830 
     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        } 
    2949} 
     50 
     51void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) 
     52{ 
     53        /*** TODO ***/ 
     54} 
     55 
     56void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const 
     57{ 
     58        /*** TODO ***/ 
     59} 
     60 
     61float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 
     62{ 
     63        /*** TODO ***/ 
     64        return 0.0; 
     65} 
     66 
     67AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) 
     68{ 
     69        /*** TODO ***/ 
     70        return new AxisAlignedBox(); 
     71} 
     72 
     73bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const 
     74{ 
     75        return KDNODEPTR_CAST(node)->hasGeometry(); 
     76} 
     77 
     78void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const 
     79{ 
     80        /*** TODO ***/ 
     81} 
     82 
     83bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const 
     84{ 
     85        /*** TODO ***/ 
     86        return true; 
     87} 
     88 
     89void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const 
     90{ 
     91        /*** TODO ***/ 
     92} 
     93 
     94unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const 
     95{ 
     96        /*** TODO ***/ 
     97        return 0; 
     98} 
     99 
     100void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node,  
     101                                                                                                   GtpVisibility::CullingType type) const 
     102{ 
     103        /*** TODO ***/ 
     104} 
     105 
     106void 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  
    3232                // kill the old kd-tree if exists  
    3333                OGRE_DELETE(mKdTree); 
     34 
     35                mRenderMethod = KdTree::KDRM_RECURSE; 
    3436 
    3537                //mBuildMethod = KdTree::KDBM_RECURSIVE; 
     
    160162                        } 
    161163                } 
     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                } 
    162192                else if (strKey == "ShowKdTree") 
    163193                { 
     
    208238                        { 
    209239                                *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"; 
    210260                        } 
    211261                        return true; 
     
    278328                        // inserting single nodes yields sub-optimal results 
    279329                        // rebuilding tree takes too long 
    280                         // "What now", spoke Zeus ... 
     330                        // "What now?", spoke Zeus ... 
    281331 
    282332                        //mKdTree->insert(node); 
     
    293343                getRenderQueue()->clear(); 
    294344                if (mKdTree) 
    295                         mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes); 
     345                        mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mRenderMethod, mShowBoxes); 
    296346                //SceneManager::_findVisibleObjects(cam, onlyShadowCasters); 
    297347        } 
Note: See TracChangeset for help on using the changeset viewer.