Changeset 2306 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Timestamp:
- 04/02/07 11:50:36 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOctreeHierarchyInterface.h
r2292 r2306 63 63 GtpVisibility::HierarchyNodeContainer &nodes); 64 64 65 void PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const; 66 void DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const; 67 float GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const; 68 65 69 protected: 66 70 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformHierarchyInterface.h
r2280 r2306 26 26 { 27 27 public: 28 /** Construction taking the current scene manager and the current rendersystem as argument 28 /** Construction taking the current scene manager and the 29 current rendersystem as argument 29 30 @param sm current scene manager 30 31 @param rsys current render system … … 36 37 @return the next occlusion query 37 38 */ 38 GtpVisibility::OcclusionQuery *GetNextOcclusionQuery();39 virtual GtpVisibility::OcclusionQuery *GetNextOcclusionQuery(); 39 40 40 41 /** Sets the current camera used for the rendering. … … 124 125 bool includeChildren) = 0; 125 126 127 void PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const {} 128 void DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const {} 129 130 float GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const { return 1.0f;} 131 126 132 protected: 127 133 /** Renders the given geometry -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp
r2292 r2306 31 31 Octree *nextChild; 32 32 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 } 49 46 } 50 47 } … … 63 60 nodes.reserve(8); 64 61 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 //----------------------------------------------------------------------- 84 bool 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 //----------------------------------------------------------------------- 92 bool OctreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const 93 { 94 return !(static_cast<Octree *>(node))->mNodes.empty(); 95 } 96 //----------------------------------------------------------------------- 97 float 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 //----------------------------------------------------------------------- 107 void 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 //----------------------------------------------------------------------- 115 void 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 //----------------------------------------------------------------------- 123 void 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 //----------------------------------------------------------------------- 136 void 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 //----------------------------------------------------------------------- 149 void 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 65 167 for (int i = 0; i < 8; ++ i) 66 168 { … … 68 170 int y = (i & 2) / 2; 69 171 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()) 72 183 { 73 nodes.push_back(child);184 octant->setOctreeFullyVisible(false); 74 185 } 75 186 } 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 //----------------------------------------------------------------------- 189 void OctreeHierarchyInterface::DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const 125 190 { 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 142 210 for (int i = 0; i < 8; ++ i) 143 211 { … … 145 213 int y = (i & 2) / 2; 146 214 int z = i & 1; 215 216 nextChild = octant->mChildren[x][y][z]; 217 218 if (!nextChild) 219 continue; 147 220 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); 185 223 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); 194 231 } 195 232 //----------------------------------------------------------------------- … … 249 286 { 250 287 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 288 //return static_cast<Octree *>(node)->getVisibilityRatio() > 0.9f; 251 289 return static_cast<Octree *>(node)->isOctreeFullyVisible(); 290 #else 291 return true; 292 #endif 293 } 294 //----------------------------------------------------------------------- 295 float 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(); 252 300 #else 253 301 return true; … … 329 377 Octree *octree = static_cast<Octree *>(node); 330 378 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) 338 382 { 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 } 340 390 } 341 391 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
r2278 r2306 141 141 } 142 142 //----------------------------------------------------------------------- 143 void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam, 143 void PlatformHierarchyInterface::InitTraversal(Camera *cam, 144 Camera *cullCam, 144 145 int leavePassesInQueue) 145 146 {
Note: See TracChangeset
for help on using the changeset viewer.