Changeset 2306 for GTP/trunk/Lib/Vis
- Timestamp:
- 04/02/07 11:50:36 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC
- Files:
-
- 9 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 { -
GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
r2292 r2306 58 58 virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node, 59 59 const bool wasVisible = false) = 0; 60 /** Sets the root of the scene hierarchy.61 @param root the hierarchy root62 */63 void SetHierarchyRoot(HierarchyNode *root);64 /** Get the root of the scene hierarchy.65 @return the hierarchy root66 */67 HierarchyNode *GetHierarchyRoot() const;68 /** Sets the scene root and initialises this hierarchy interface for a traversal.69 @remark also resets the statistics evaluated in the last traversal70 */71 void InitTraversal();72 /** Returns current frame id.73 @returns frame id74 */75 unsigned int GetFrameId() const;76 /** Returns a pointer to the distance queue.77 @returns current distance queue.78 @remark the distance queue stores hierarchy nodes in a front-to-back order79 */80 DistanceQueue *GetQueue();81 82 60 /** Returns distance of the node to the view plane. 83 61 @param node the hierarchy node … … 90 68 virtual bool CheckFrustumVisible(HierarchyNode *node, 91 69 bool &intersects) = 0; 92 /** Checks if the node is visible from the current view frustum. 93 @param node the current node 94 */ 95 bool CheckFrustumVisible(HierarchyNode *node); 96 /** Returns next available occlusion query or creates new one. 97 @return the next occlusion query 98 */ 99 virtual OcclusionQuery *GetNextOcclusionQuery() = 0; 70 100 71 /** Returns true if there is renderable geometry attached to this node 101 72 @param node the current node … … 118 89 virtual void SetLastVisited(HierarchyNode *node, 119 90 const unsigned int frameId) const = 0; 91 92 93 virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0; 94 95 virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0; 96 virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0; 97 98 virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; 99 100 virtual void RenderNodeRecursive(HierarchyNode *node) = 0; 101 120 102 /** Returns frame id when this node was last visited by the traverser. See set 121 103 */ 122 104 virtual unsigned int LastVisited(HierarchyNode *node) const = 0; 123 /** Returns number of traversed nodes.124 */125 unsigned int GetNumTraversedNodes();126 /** Returns number of rendered nodes.127 */128 unsigned int GetNumRenderedNodes();129 105 130 //bool mIsShadowPass;131 132 106 /** Visualization of a culled node, dependent on the culling type. 133 107 @param node the hierarchy node to be visualized … … 137 111 CullingType type) const = 0; 138 112 139 /** Returns vector of visible hierarchy nodes from previous render. 113 /** Sets the root of the scene hierarchy. 114 @param root the hierarchy root 140 115 */ 141 std::vector<HierarchyNode *> *GetVisibleNodes(); 142 /** Returns vector of previoulsy rendered geometry. 116 void SetHierarchyRoot(HierarchyNode *root); 117 /** Get the root of the scene hierarchy. 118 @return the hierarchy root 143 119 */ 144 120 HierarchyNode *GetHierarchyRoot() const; 145 121 146 122 /** This is an optimization when issuing the occlusion test. … … 153 129 void TestGeometryForVisibleLeaves(bool testGeometry); 154 130 131 /** Sets the scene root and initialises this hierarchy interface for a traversal. 132 @remark also resets the statistics evaluated in the last traversal 133 */ 134 void InitTraversal(); 135 /** Returns current frame id. 136 @returns frame id 137 */ 138 unsigned int GetFrameId() const; 139 /** Returns a pointer to the distance queue. 140 @returns current distance queue. 141 @remark the distance queue stores hierarchy nodes in a front-to-back order 142 */ 143 DistanceQueue *GetQueue(); 155 144 156 virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0; 145 /** Checks if the node is visible from the current view frustum. 146 @param node the current node 147 */ 148 bool CheckFrustumVisible(HierarchyNode *node); 157 149 158 virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0; 159 virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0; 150 /** Returns number of traversed nodes. 151 */ 152 unsigned int GetNumTraversedNodes(); 153 /** Returns number of rendered nodes. 154 */ 155 unsigned int GetNumRenderedNodes(); 160 156 161 virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0; 157 /** Returns vector of visible hierarchy nodes from previous render. 158 */ 159 std::vector<HierarchyNode *> *GetVisibleNodes(); 162 160 163 virtual void RenderNodeRecursive(HierarchyNode *node) = 0; 161 virtual void PullUpLastVisited(GtpVisibility::HierarchyNode *node, const int frameId) const = 0; 162 virtual void DetermineVisibilityRatio(GtpVisibility::HierarchyNode *node) const = 0; 163 virtual float GetNodeVisibilityRatio(GtpVisibility::HierarchyNode *node) const = 0; 164 164 165 165 protected: … … 185 185 /// buffer for a node pointer 186 186 HierarchyNode *mSavedNode; 187 187 188 /// list of rendered hierarchy nodes (e.g., useful for exact visibility queries) 188 189 std::vector<HierarchyNode *> mVisibleNodes; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/BatchedQueriesCullingManager.cpp
r2280 r2306 100 100 101 101 // reset node's visibility classification 102 // set visib e if geometry in node so we only traverse once102 // set visible if geometry in node so we only traverse once 103 103 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 104 104 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
r2292 r2306 110 110 111 111 // reset node's visibility classification 112 // set visib e if geometry in node so we only traverse once112 // set visible if geometry in node so we only traverse once 113 113 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 114 114 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp
r938 r2306 29 29 void HierarchyInterface::InitTraversal() 30 30 { 31 //-- initialise for front-to-back rendering 31 ////////////// 32 //-- initialise for hierarchical traversal 32 33 33 34 ++ mFrameId; -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
r2292 r2306 133 133 134 134 // update node's visited flag 135 mHierarchyInterface->SetLastVisited(randomLeaf, 136 mHierarchyInterface->GetFrameId()); 135 mHierarchyInterface->PullUpLastVisited(randomLeaf, mHierarchyInterface->GetFrameId()); 137 136 138 137 queryQueue.push(QueryPair(randomLeaf, … … 152 151 153 152 // update node's visited flag 154 mHierarchyInterface-> SetLastVisited(leaf, mHierarchyInterface->GetFrameId());153 mHierarchyInterface->PullUpLastVisited(leaf, mHierarchyInterface->GetFrameId()); 155 154 156 155 queryQueue.push(QueryPair(leaf, … … 168 167 169 168 // reset node's visibility classification 170 // set visib e if geometry in node => we only traverse the node once169 // set visible if geometry in node => we only traverse the node once 171 170 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 172 171 … … 193 192 } 194 193 195 //while (!mHierarchyInterface->GetQueue()->empty())196 // mHierarchyInterface->GetQueue()->pop();197 198 194 // update the fully visible classifications 199 // TODO: this should be done during traversal!200 195 mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot()); 196 //mHierarchyInterface->DetermineVisibilityRatio(mHierarchyInterface->GetHierarchyRoot()); 201 197 } 202 198 //----------------------------------------------------------------------- … … 210 206 { 211 207 mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility; 212 if (mAssumedVisibility > 100) // fix visibility208 if (mAssumedVisibility > 100) // no random decicion 213 209 mThreshold = RAND_MAX; 214 210 }
Note: See TracChangeset
for help on using the changeset viewer.