Changeset 1173


Ignore:
Timestamp:
07/31/06 17:34:56 (18 years ago)
Author:
szydlowski
Message:

Finished kdtree hierarchy interface, started modifications to kdtree scene manager

Location:
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdRenderable.h

    r1163 r1173  
    1212 
    1313#include "OgreKdTree.h" 
     14#include "HierarchyInterface.h" 
    1415 
    1516namespace Ogre 
     
    3334                // put all objects this element holds in the renedering queue 
    3435                virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters) = 0; 
     36 
     37                // place all entities in geometry queue (for CHC) 
     38                virtual void getGeometryList(GtpVisibility::GeometryVector *geometryList) = 0; 
    3539 
    3640                // return a bounding box enclosing all objects 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h

    r1170 r1173  
    2727#include <stack> 
    2828 
    29 //#include "OgreKdTreeHierarchyInterface.h" 
    3029 
    3130 
     
    264263                        */ 
    265264                        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; }; 
    269265                        /** Frame id when this octree was last rendered.  
    270266                        @return last rendered frame id 
     
    275271                        */ 
    276272                        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.  
     273                        /** Gets this node's parent (NULL if this is the root). 
     274                        */       
     275                        KdTree::Branch *getParent(void) { return mParent; }; 
     276                        /** Returns real extent of the kdtree, i.e., the merged extent of the bounding boxes.  
    280277                        */ 
    281                         //AxisAlignedBox _getWorldAABB(void) const = 0; 
     278                        AxisAlignedBox _getWorldAABB(void) const { return mWorldAABB; }; 
     279                        /** Updates bound of the real aabb of kdtree 
     280                        */ 
     281                        virtual void _updateBounds() = 0; 
    282282 
    283283 
     
    290290                        // for the CHC hierarchy interface 
    291291                        /** the real extent of the node. */ 
    292                         //AxisAlignedBox mWorldAABB; 
    293  
     292                        AxisAlignedBox mWorldAABB; 
     293                         
    294294                        unsigned int mLastRendered; 
    295295                        unsigned int mLastVisited; 
     
    323323                        // a branch never has geometry 
    324324                        virtual bool hasGeometry() const { return false; }; 
     325 
     326                        // branches do not posses geometry => just merge child aabbs 
     327                        virtual void _updateBounds() 
     328                        { 
     329                                // reset box 
     330                                mWorldAABB.setNull(); 
     331 
     332                                if (mLeft) 
     333                                        mWorldAABB.merge(mLeft->_getWorldAABB()); 
     334                                if (mRight) 
     335                                        mWorldAABB.merge(mRight->_getWorldAABB()); 
     336 
     337                                // update parent recursively 
     338                                if (mParent) 
     339                                        mParent->_updateBounds(); 
     340                        } 
    325341                         
    326342                        Node * mLeft; 
     
    347363                        // a leaf has geometry when it has renderables 
    348364                        virtual bool hasGeometry() const { return !mKdRenderables.empty(); }; 
     365 
     366                        // update the world aabb based on the contained geometry 
     367                        virtual void _updateBounds(); 
    349368 
    350369                        virtual void remove(KdRenderable * rend) 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h

    r1170 r1173  
    2828        public: 
    2929                KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm); 
    30                 //KdTreeSceneManager(const String& name, int maxdepth); 
    3130                ~KdTreeSceneManager(void); 
    3231 
     
    3433                virtual SceneNode* createSceneNode(void); 
    3534                virtual SceneNode* createSceneNode(const String& name); 
    36                 void init( int maxdepth ); 
    37                 void walkTree(KdTree * node, Camera *cam); 
    3835 
    3936                virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters); 
     37 
     38                virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam, 
     39                        bool onlyShadowCasters, int leavePassesInQueue); 
    4040 
    4141                virtual void setShowBoxes(bool showboxes); 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneNode.h

    r1163 r1173  
    3737                virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters); 
    3838 
     39                // place all entities in geometry queue (for CHC) 
     40                virtual void getGeometryList(GtpVisibility::GeometryVector *geometryList); 
     41 
    3942                // return a bounding box enclosing all objects 
    4043                virtual AxisAlignedBox getBoundingBox() const; 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp

    r1170 r1173  
    14961496                mKdRenderables.clear(); 
    14971497        } 
    1498 } 
     1498 
     1499        // update the world aabb based on the contained geometry 
     1500        void KdTree::Leaf::_updateBounds() 
     1501        { 
     1502                // reset box 
     1503                mWorldAABB.setNull(); 
     1504 
     1505                // merge boxes from attached geometry 
     1506                KdRenderableList::iterator it = mKdRenderables.begin(); 
     1507                KdRenderableList::iterator end = mKdRenderables.end(); 
     1508                while (it != end) 
     1509                { 
     1510                        mWorldAABB.merge((*it)->getBoundingBox()); 
     1511                        it++; 
     1512                } 
     1513 
     1514                // update parent recursively 
     1515                if (mParent) 
     1516                        mParent->_updateBounds(); 
     1517        } 
     1518} // namespace Ogre 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp

    r1170 r1173  
    88*/ 
    99 
     10#include "OgreKdRenderable.h" 
    1011#include "OgreKdTreeSceneManager.h" 
    1112#include "OgreKdTreeHierarchyInterface.h" 
     
    5152void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node) 
    5253{ 
    53         /*** TODO ***/ 
     54        KdTree::Node * kdnode = KDNODEPTR_CAST(node); 
     55        if (kdnode->lastRendered() != mFrameId) 
     56        { 
     57                kdnode->setLastRendered(mFrameId); 
     58                KdTreeSceneManager * ksm = static_cast<KdTreeSceneManager *>(mSceneManager); 
     59 
     60                // render only if the node is a leaf 
     61                if (kdnode->isLeaf()) 
     62                { 
     63                        ksm->_renderNodes(KDLEAFPTR_CAST(node)->mKdRenderables, mCamera,  
     64                                mOnlyShadowCasters, mLeavePassesInQueue); 
     65                }        
     66 
     67                mVisibleNodes.push_back(node); 
     68        } 
    5469} 
    5570 
    5671void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const 
    5772{ 
    58         /*** TODO ***/ 
     73        KdTree::Node * kdnode = KDNODEPTR_CAST(node); 
     74 
     75        while (kdnode && !kdnode->isNodeVisible()) 
     76        { 
     77                kdnode->setNodeVisible(true); 
     78                kdnode = kdnode->getParent(); 
     79        } 
    5980} 
    6081 
    6182float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 
    6283{ 
    63         /*** TODO ***/ 
    64         return 0.0; 
     84        const Vector3 pos = KDNODEPTR_CAST(node)->mAABB.getCenter(); 
     85        return (mCameraPosition - pos).squaredLength(); 
    6586} 
    6687 
    6788AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node) 
    6889{ 
    69         /*** TODO ***/ 
    70         return new AxisAlignedBox(); 
     90        // reuse box if node is the same 
     91        // only create renderable bounding box for new node 
     92        if (node != mSavedNode) 
     93        { 
     94                mSavedNode = node; 
     95                mBox = KDNODEPTR_CAST(node)->_getWorldAABB(); 
     96        } 
     97 
     98        return &mBox; 
    7199} 
    72100 
     
    78106void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const 
    79107{ 
    80         /*** TODO ***/ 
     108        KDNODEPTR_CAST(node)->setNodeVisible(visible); 
    81109} 
    82110 
    83111bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const 
    84112{ 
    85         /*** TODO ***/ 
    86         return true; 
     113        return KDNODEPTR_CAST(node)->isNodeVisible(); 
    87114} 
    88115 
    89116void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const 
    90117{ 
    91         /*** TODO ***/ 
     118        KDNODEPTR_CAST(node)->setLastVisited(frameId); 
    92119} 
    93120 
    94121unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const 
    95122{ 
    96         /*** TODO ***/ 
    97         return 0; 
     123        return KDNODEPTR_CAST(node)->lastVisited(); 
    98124} 
    99125 
     
    101127                                                                                                   GtpVisibility::CullingType type) const 
    102128{ 
    103         /*** TODO ***/ 
     129        WireBoundingBox *box = KDNODEPTR_CAST(node)->getWireBoundingBox(); 
     130 
     131        if (type == GtpVisibility::FRUSTUM_CULLED) 
     132        { 
     133                box->setMaterial("FrustumCulledNodesMaterial"); 
     134        } 
     135        else // type == GtpVisibility::QUERY_CULLED 
     136        { 
     137                box->setMaterial("QueryCulledNodesMaterial"); 
     138        } 
     139 
     140        // TODO: maybe boxlist? 
     141        dynamic_cast<KdTreeSceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box); 
    104142} 
    105143 
     
    108146                                                                                                   bool includeChildren)  
    109147{ 
    110         /*** TODO ***/ 
     148        KdTree::Node * kdnode = KDNODEPTR_CAST(node); 
     149        if (kdnode->isLeaf()) 
     150        { 
     151                KdTree::Leaf * kdleaf = KDLEAFPTR_CAST(node); 
     152                KdRenderableList::iterator it = kdleaf->mKdRenderables.begin(); 
     153                KdRenderableList::iterator end = kdleaf->mKdRenderables.end(); 
     154                while (it != end) 
     155                { 
     156                        (*it)->getGeometryList(geometryList); 
     157                        it++; 
     158                } 
     159        } 
    111160} 
    112161 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp

    r1170 r1173  
    347347        } 
    348348 
     349        // TODO: looks too easy, verify if it works  
     350        void KdTreeSceneManager::_renderNodes(const KdRenderableList& nodelist, Camera * cam,  
     351                bool onlyShadowCasters, int leavePassesInQueue) 
     352        { 
     353#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     354                _deleteRenderedQueueGroups(leavePassesInQueue); //try avoiding modified ogre code 
     355#else 
     356                getRenderQueue()->clear(); 
     357#endif 
     358                KdRenderableList::const_iterator it = nodelist.begin(); 
     359                KdRenderableList::const_iterator end = nodelist.end(); 
     360                while (it != end) 
     361                { 
     362                        (*it)->queueObjects(cam, getRenderQueue(), onlyShadowCasters); 
     363                        it++; 
     364                } 
     365 
     366                SceneManager::_renderVisibleObjects(); 
     367 
     368        } 
     369 
    349370        //----------------------------------------------------------------------- 
    350371        //----------------------------------------------------------------------- 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneNode.cpp

    r1163 r1173  
    140140        } 
    141141 
     142        void KdTreeSceneNode::getGeometryList(GtpVisibility::GeometryVector *geometryList) 
     143        { 
     144                SceneNode::ObjectIterator objIt = getAttachedObjectIterator(); 
     145 
     146                while (objIt.hasMoreElements()) 
     147                { 
     148                        MovableObject *movable = objIt.getNext(); 
     149 
     150                        // we are interested only in the entities, i.e., instances of geometry 
     151                        if (movable->getMovableType() == "Entity") 
     152                        { 
     153                                Entity *ent = static_cast<Entity *>(movable); 
     154                                //std::stringstream d; d << "ent " << ent->getName();  
     155                                //LogManager::getSingleton().logMessage(d.str()); 
     156                                geometryList->push_back(ent); 
     157                        } 
     158                } 
     159        } 
     160 
    142161        AxisAlignedBox KdTreeSceneNode::getBoundingBox() const 
    143162        { 
Note: See TracChangeset for help on using the changeset viewer.