Ignore:
Timestamp:
04/02/07 11:50:36 (17 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp

    r2292 r2306  
    3131                Octree *nextChild; 
    3232 
    33                 if ((nextChild = octree->mChildren[0][0][0]) != NULL) 
    34                         mDistanceQueue->push(nextChild); 
    35                 if ((nextChild = octree->mChildren[0][0][1]) != NULL) 
    36                         mDistanceQueue->push(nextChild); 
    37                 if ((nextChild = octree->mChildren[0][1][0]) != NULL) 
    38                         mDistanceQueue->push(nextChild); 
    39                 if ((nextChild = octree->mChildren[0][1][1]) != NULL) 
    40                 mDistanceQueue->push(nextChild); 
    41                 if ((nextChild = octree->mChildren[1][0][0]) != NULL) 
    42                         mDistanceQueue->push(nextChild); 
    43                 if ((nextChild = octree->mChildren[1][0][1]) != NULL) 
    44                         mDistanceQueue->push(nextChild); 
    45                 if ((nextChild = octree->mChildren[1][1][0]) != NULL) 
    46                         mDistanceQueue->push(nextChild); 
    47                 if ((nextChild = octree->mChildren[1][1][1]) != NULL) 
    48                         mDistanceQueue->push(nextChild); 
     33                for (int z = 0; z < 2; ++ z) 
     34                {        
     35                        for (int y = 0; y < 2; ++ y) 
     36                        { 
     37                                for (int x = 0; x < 2; ++ x) 
     38                                { 
     39                                        nextChild = octree->mChildren[x][y][z]; 
     40         
     41                                        if (nextChild) 
     42                        GetQueue()->push(nextChild); 
     43                                } 
     44            } 
     45        } 
    4946        } 
    5047} 
     
    6360        nodes.reserve(8); 
    6461 
     62        for (int z = 0; z < 2; ++ z) 
     63        {        
     64                for (int y = 0; y < 2; ++ y) 
     65                { 
     66                        for (int x = 0; x < 2; ++ x) 
     67                        { 
     68                                if ((child = octree->mChildren[x][y][z]) != NULL) 
     69                                { 
     70                                        nodes.push_back(child); 
     71                                } 
     72                        } 
     73                } 
     74        } 
     75 
     76        if (nodes.empty()) 
     77                return NULL; 
     78 
     79        int r = (int)(((float)rand() / RAND_MAX) * ((float)nodes.size() - 0.5f)); 
     80 
     81        return GetRandomLeaf(nodes[r]); 
     82} 
     83//----------------------------------------------------------------------- 
     84bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const 
     85{ 
     86        Octree *octree = static_cast<Octree *>(node); 
     87 
     88        // HACK: if there are subtrees, they are empty => we are not interested in them 
     89        return octree->numNodes() == (int)octree->mNodes.size(); 
     90} 
     91//----------------------------------------------------------------------- 
     92bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const 
     93{ 
     94        return !(static_cast<Octree *>(node))->mNodes.empty(); 
     95} 
     96//----------------------------------------------------------------------- 
     97float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 
     98{ 
     99        const Vector3 bmin = static_cast<Octree *>(node)->mBox.getMinimum(); 
     100        const Vector3 bmax = static_cast<Octree *>(node)->mBox.getMaximum(); 
     101 
     102        const Vector3 pos = (bmax - bmin) * 0.5f + bmin; 
     103         
     104        return (mCameraPosition - pos).squaredLength(); 
     105} 
     106//----------------------------------------------------------------------- 
     107void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,  
     108                                                                                          const bool visible) const 
     109{ 
     110#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     111        static_cast<Octree *>(node)->setOctreeVisible(visible); 
     112#endif 
     113} 
     114//----------------------------------------------------------------------- 
     115void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,  
     116                                                                                          const unsigned int frameId) const 
     117{ 
     118#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     119        static_cast<Octree *>(node)->setLastVisited(frameId); 
     120#endif 
     121} 
     122//----------------------------------------------------------------------- 
     123void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const 
     124{                
     125#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     126        Octree *octant = static_cast<Octree *>(node); 
     127 
     128        while (octant && !octant->isOctreeVisible()) 
     129        { 
     130                octant->setOctreeVisible(true); 
     131                octant = octant->getParent(); 
     132        } 
     133#endif 
     134} 
     135//----------------------------------------------------------------------- 
     136void OctreeHierarchyInterface::PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const 
     137{                
     138#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     139        Octree *octant = static_cast<Octree *>(node); 
     140 
     141        while (octant && (octant->lastVisited() != frameId)) 
     142        { 
     143                octant->setLastVisited(frameId); 
     144                octant = octant->getParent(); 
     145        } 
     146#endif 
     147} 
     148//----------------------------------------------------------------------- 
     149void OctreeHierarchyInterface::DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const 
     150{                
     151        Octree *octant = static_cast<Octree *>(node); 
     152 
     153        // node not visited in this frame => no change 
     154        if (octant->lastVisited() != mFrameId)  
     155                return; 
     156 
     157        // leaf node: terminate recursion 
     158        if (IsLeaf(node)) 
     159        { 
     160                octant->setOctreeFullyVisible(octant->isOctreeVisible());        
     161                return; 
     162        } 
     163 
     164        octant->setOctreeFullyVisible(true); 
     165        Octree *nextChild; 
     166         
    65167        for (int i = 0; i < 8; ++ i) 
    66168        { 
     
    68170                int y = (i & 2) / 2; 
    69171                int z = i & 1; 
    70          
    71                 if ((child = octree->mChildren[x][y][z]) != NULL) 
     172 
     173                nextChild = octant->mChildren[x][y][z]; 
     174 
     175                if (!nextChild) 
     176                        continue; 
     177                 
     178                // recursive traversal 
     179                DetermineFullVisibility(nextChild); 
     180                 
     181                // this leaf is not fully visible 
     182                if (!nextChild->isOctreeFullyVisible()) 
    72183                { 
    73                         nodes.push_back(child); 
     184                        octant->setOctreeFullyVisible(false); 
    74185                } 
    75186        } 
    76  
    77         if (nodes.empty()) 
    78                 return NULL; 
    79  
    80         int r = (int)(((float)rand() / RAND_MAX) * ((float)nodes.size() - 0.5f)); 
    81  
    82         return GetRandomLeaf(nodes[r]); 
    83 } 
    84 //----------------------------------------------------------------------- 
    85 bool OctreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const 
    86 { 
    87         Octree *octree = static_cast<Octree *>(node); 
    88  
    89         // HACK: if there are subtrees, they are empty => we are not interested in them 
    90         return octree->numNodes() == (int)octree->mNodes.size(); 
    91 } 
    92 //----------------------------------------------------------------------- 
    93 bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const 
    94 { 
    95         return !(static_cast<Octree *>(node))->mNodes.empty(); 
    96 } 
    97 //----------------------------------------------------------------------- 
    98 float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 
    99 { 
    100         const Vector3 bmin = static_cast<Octree *>(node)->mBox.getMinimum(); 
    101         const Vector3 bmax = static_cast<Octree *>(node)->mBox.getMaximum(); 
    102  
    103         const Vector3 pos = (bmax - bmin) * 0.5f + bmin; 
    104          
    105         return (mCameraPosition - pos).squaredLength(); 
    106 } 
    107 //----------------------------------------------------------------------- 
    108 void OctreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node,  
    109                                                                                           const bool visible) const 
    110 { 
    111 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    112         static_cast<Octree *>(node)->setOctreeVisible(visible); 
    113 #endif 
    114 } 
    115 //----------------------------------------------------------------------- 
    116 void OctreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node,  
    117                                                                                           const unsigned int frameId) const 
    118 { 
    119 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    120         static_cast<Octree *>(node)->setLastVisited(frameId); 
    121 #endif 
    122 } 
    123 //----------------------------------------------------------------------- 
    124 void OctreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const 
     187} 
     188//----------------------------------------------------------------------- 
     189void OctreeHierarchyInterface::DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const 
    125190{                
    126 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    127         Octree *octant = static_cast<Octree *>(node); 
    128  
    129         while (octant && !octant->isOctreeVisible()) 
    130         { 
    131                 octant->setOctreeVisible(true); 
    132                 octant = octant->getParent(); 
    133         } 
    134 #endif 
    135 } 
    136 //----------------------------------------------------------------------- 
    137 /*void OctreeHierarchyInterface::PullUpFullVisibility(GtpVisibility::HierarchyNode *node) const 
    138 {                
    139 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 
    140         Octree *octant = static_cast<Octree *>(node); 
    141  
     191        Octree *octant = static_cast<Octree *>(node); 
     192 
     193        // node not visited in this frame => no change 
     194        if (octant->lastVisited() != mFrameId) 
     195                return; 
     196         
     197        // leaf node: terminate recursion 
     198        if (IsLeaf(node)) 
     199        { 
     200                octant->setNumLeaves(1);         
     201                octant->setNumVisibleLeaves(octant->isOctreeVisible() ? 1 : 0);  
     202                return; 
     203        } 
     204 
     205        int numVisibleLeaves = 0; 
     206        int numLeaves = 0; 
     207 
     208        Octree *nextChild; 
     209         
    142210        for (int i = 0; i < 8; ++ i) 
    143211        { 
     
    145213                int y = (i & 2) / 2; 
    146214                int z = i & 1; 
     215 
     216                nextChild = octant->mChildren[x][y][z]; 
     217 
     218                if (!nextChild) 
     219                        continue; 
    147220                 
    148                 if ((nextChild = octant->mChildren[x][y][z]) != NULL) 
    149                 { 
    150                         DetermineFullVisibility(nextChild); 
    151                         // this leaf is not fully visible => break 
    152                         if (!nextChild->isOctreeFullyVisible()) 
    153                                 octant->setOctreeFullyVisible(false); 
    154                 } 
    155         } 
    156  
    157         while (octant && !octant->isOctreeVisible()) 
    158         { 
    159                 octant->setOctreeVisible(true); 
    160                 octant = octant->getParent(); 
    161         } 
    162 #endif 
    163 }*/ 
    164 //----------------------------------------------------------------------- 
    165 void OctreeHierarchyInterface::DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const 
    166 {                
    167         Octree *octant = static_cast<Octree *>(node); 
    168  
    169         // leaf node: terminate recursion 
    170         if (IsLeaf(node)) 
    171         { 
    172                 octant->setOctreeFullyVisible(octant->isOctreeVisible());        
    173                 return; 
    174         } 
    175  
    176         octant->setOctreeFullyVisible(true); 
    177          
    178         Octree *nextChild; 
    179          
    180         for (int i = 0; i < 8; ++ i) 
    181         { 
    182                 int x = (i & 4) / 4; 
    183                 int y = (i & 2) / 2; 
    184                 int z = i & 1; 
     221                // recursive traversal 
     222                DetermineVisibilityRatio(nextChild); 
    185223                 
    186                 if ((nextChild = octant->mChildren[x][y][z]) != NULL) 
    187                 { 
    188                         DetermineFullVisibility(nextChild); 
    189                         // this leaf is not fully visible => break 
    190                         if (!nextChild->isOctreeFullyVisible()) 
    191                                 octant->setOctreeFullyVisible(false); 
    192                 } 
    193         } 
     224                // this leaf is not fully visible 
     225                numLeaves += nextChild->getNumLeaves(); 
     226                numVisibleLeaves += nextChild->getNumVisibleLeaves(); 
     227        } 
     228 
     229        octant->setNumLeaves(numLeaves); 
     230        octant->setNumVisibleLeaves(numVisibleLeaves); 
    194231} 
    195232//----------------------------------------------------------------------- 
     
    249286{ 
    250287#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     288        //return static_cast<Octree *>(node)->getVisibilityRatio() > 0.9f; 
    251289        return static_cast<Octree *>(node)->isOctreeFullyVisible(); 
     290#else 
     291        return true; 
     292#endif 
     293} 
     294//----------------------------------------------------------------------- 
     295float OctreeHierarchyInterface::GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const 
     296{ 
     297#ifdef GTP_VISIBILITY_MODIFIED_OGRE 
     298        return static_cast<Octree *>(node)->getVisibilityRatio(); 
     299        //return static_cast<Octree *>(node)->isOctreeFullyVisible(); 
    252300#else 
    253301        return true; 
     
    329377                        Octree *octree = static_cast<Octree *>(node); 
    330378                         
    331                         for (int i = 0; i < 8; ++ i) 
    332                         { 
    333                                 int x = (i & 4) / 4; 
    334                                 int y = (i & 2) / 2; 
    335                                 int z = i & 1; 
    336          
    337                                 if ((child = octree->mChildren[x][y][z]) != NULL) 
     379                        for (int z = 0; z < 2; ++ z) 
     380                        {        
     381                                for (int y = 0; y < 2; ++ y) 
    338382                                { 
    339                                         tStack.push(child); 
     383                                        for (int x = 0; x < 2; ++ x) 
     384                                        { 
     385                                                if ((child = octree->mChildren[x][y][z]) != NULL) 
     386                                                { 
     387                                                        tStack.push(child); 
     388                                                } 
     389                                        } 
    340390                                } 
    341391                        } 
  • GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp

    r2278 r2306  
    141141} 
    142142//----------------------------------------------------------------------- 
    143 void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam,  
     143void PlatformHierarchyInterface::InitTraversal(Camera *cam,  
     144                                                                                           Camera *cullCam,  
    144145                                                                                           int leavePassesInQueue) 
    145146{ 
Note: See TracChangeset for help on using the changeset viewer.