- Timestamp:
- 06/16/08 08:56:35 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 21 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
r2762 r2763 175 175 geometry.resize(shapeCount); 176 176 177 for (size_t i = 0; i < geometry.size(); ++ i) 178 geometry[i] = NULL; 179 180 177 181 int progress = 0; 178 182 179 183 for (int i = 0; i < shapeCount; ++ i) 180 184 { 181 int id; 182 istr.read(reinterpret_cast<char *>(&id), sizeof(int)); 183 185 //int id;istr.read(reinterpret_cast<char *>(&id), sizeof(int)); 184 186 SceneEntity *ent = LoadSceneEntity(istr); 185 ent->id = i d;186 187 geometry[i d] = ent;187 ent->id = i; 188 189 geometry[i] = ent; 188 190 189 191 int p = (i + 1) * 100 / shapeCount; … … 191 193 if (p >= progress) 192 194 { 193 //cout << "% loaded: " << p << endl;195 cout << "% loaded: " << p << endl; 194 196 progress += 10; 195 197 } 196 198 } 197 199 200 for (size_t i = 0; i < geometry.size(); ++ i) 201 { 202 if (!geometry[i]) 203 Debug << "error: index " << i << " missing" << endl; 204 } 205 198 206 cout << "bin loading finished" << endl; 199 207 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2762 r2763 295 295 { 296 296 // do the test only if necessary 297 if (1)//node->mPlaneMask & (1 << i)) 298 {//cout<<"plane "<< i << endl; 299 bool outs = true; 300 //-- test the n-vertex 301 for (int j = 0; j < 8; ++ j) 302 { 303 if (sFrustum.mClipPlanes[i].Distance(node->mBox.GetVertex(j)) <= 0) outs = false; 304 } 305 if (outs) return 0; 306 //if ((node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)) 307 //&& (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) > 0.0f)) 308 { 309 // outside 310 // node->mPreferredPlane = i; 311 //cout<<"f " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl; 312 // return false; 313 }//else cout<<"ok " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl; 314 315 //-- test the p-vertex 316 if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 317 { 318 // completely inside: children don't need to check against this plane no more 319 node->mPlaneMask^= 1 << i; 320 } 321 else 322 { 323 bIntersect = true; 324 } 325 } 326 297 if (!(node->mPlaneMask & (1 << i))) 298 return true; 299 300 //////// 301 //-- test the n-vertex 302 303 if ((node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)) 304 { 305 // outside 306 node->mPreferredPlane = i; 307 return false; 308 } 309 310 //////////// 311 //-- test the p-vertex 312 313 if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 314 { 315 // completely inside: children don't need to check against this plane no more 316 node->mPlaneMask^= 1 << i; 317 } 318 else 319 { 320 bIntersect = true; 321 } 322 327 323 return true; 328 324 } … … 337 333 338 334 339 for (int i = 0; i < 6; ++ i) 340 { 341 if (!TestPlane(node, i, bIntersect)) return 0; 342 } 335 //for (int i = 0; i < 6; ++ i) 336 // if (!TestPlane(node, i, bIntersect)) return 0; 337 343 338 344 339 //////// 345 340 //-- apply frustum culling for the planes [mPreferredPlane - 5] 346 /* 341 347 342 for (int i = node->mPreferredPlane; i < 6; ++ i) 348 {349 343 if (!TestPlane(node, i, bIntersect)) return 0; 350 } 351 344 352 345 ////////// 353 346 //-- do the view frustum culling for the planes [0 - m_iPreferredPlane) 354 347 355 348 for (int i = 0; i < node->mPreferredPlane; ++ i) 356 {357 349 if (!TestPlane(node, i, bIntersect)) return 0; 358 } 359 */ 350 360 351 return bIntersect ? -1 : 1; 361 352 } … … 373 364 sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices); 374 365 375 for (int i = 0; i<12; ++ i) 376 //cout<<" x " << sClipPlaneAABBVertexIndices[i]; 377 // cout<<"\n********\n"; 378 // near plane 366 // store near plane 379 367 sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 380 381 368 // Debug << "near: " << sNearPlane << " d " << mCamera->GetDirection() << " " << mCamera->GetPosition() << std::endl; 382 369 // for (int i = 0; i < 6; ++ i) Debug << "plane: " << sFrustum.mClipPlanes[i] << std::endl; … … 392 379 void Bvh::RenderBoundingBox(BvhNode *node) 393 380 { 394 static BvhNodeContainer dummy(1); 381 RenderBoundingBoxImmediate(node->GetBox()); 382 /**static BvhNodeContainer dummy(1); 395 383 dummy[0] = node; 396 RenderBoundingBoxes(dummy); 384 RenderBoundingBoxes(dummy);*/ 397 385 } 398 386 … … 870 858 871 859 872 void Bvh::Dummy()873 {874 for (int i = 0; i < mGeometrySize; ++ i)875 Debug << mGeometry[i]->id << " " << mGeometry[i]->GetGeometry()->GetBoundingBox() << endl;876 877 AxisAlignedBox3 boxl; boxl.Initialize();878 AxisAlignedBox3 boxr; boxr.Initialize();879 880 881 for (int i = 0; i <= 107; ++ i)882 boxl.Include(mGeometry[i]->GetBoundingBox());883 884 for (int i = 108; i <= 193; ++ i)885 boxr.Include(mGeometry[i]->GetBoundingBox());886 887 Debug << "dummy " << boxl << " " << boxr << endl;888 889 queue<BvhNode *> tStack;890 tStack.push(mRoot);891 892 while (!tStack.empty())893 {894 BvhNode *node = tStack.front();//top();895 tStack.pop();896 897 AxisAlignedBox3 box;898 box.Initialize();899 900 int i = 0;901 for (int i = node->mFirst; i <= node->mLast; ++ i)902 {903 if ((mGeometry[i]->id < node->mFirst) || (mGeometry[i]->id > node->mLast))904 cout << "big error!! " << mGeometry[i]->id << endl;905 else cout << "ok"<<mGeometry[i]->id;906 box.Include(mGeometry[i]->GetBoundingBox());907 }908 909 Debug<< box << " " << node->GetBox() << " f " << node->mFirst << " l " << node->mLast << " id " << node->GetId() << " l " << node->IsLeaf() << endl;910 911 //node->mBox = box;912 if (!node->IsLeaf())913 {914 BvhInterior *interior = static_cast<BvhInterior *>(node);915 916 tStack.push(interior->mFront);917 tStack.push(interior->mBack);918 }919 }920 }921 922 923 860 void Bvh::SetVirtualLeaves(int numTriangles) 924 861 { … … 1006 943 1007 944 1008 } 945 void Bvh::RenderBoundingBoxImmediate(const AxisAlignedBox3 &box) 946 { 947 const Vector3 l = box.Min(); 948 const Vector3 u = box.Max(); 949 950 /////////// 951 //-- render AABB as triangle strips 952 953 glVertex3f(l.x, l.y, u.z); 954 glVertex3f(u.x, l.y, u.z); 955 glVertex3f(l.x, u.y, u.z); 956 glVertex3f(u.x, u.y, u.z); 957 glVertex3f(l.x, u.y, l.z); 958 glVertex3f(u.x, u.y, l.z); 959 glVertex3f(l.x, l.y, l.z); 960 glVertex3f(u.x, l.y, l.z); 961 962 glPrimitiveRestartNV(); 963 964 //-- render second half of AABB 965 glVertex3f(l.x, u.y, u.z); 966 glVertex3f(l.x, u.y, l.z); 967 glVertex3f(l.x, l.y, u.z); 968 glVertex3f(l.x, l.y, l.z); 969 glVertex3f(u.x, l.y, u.z); 970 glVertex3f(u.x, l.y, l.z); 971 glVertex3f(u.x, u.y, u.z); 972 glVertex3f(u.x, u.y, l.z); 973 } 974 975 976 977 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2762 r2763 440 440 441 441 public: 442 void Dummy(); 442 443 443 /** Destructor. 444 444 */ … … 601 601 inline bool TestPlane(BvhNode *node, int i, bool &bIntersect); 602 602 603 void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box); 603 604 604 605 //////////////////////// -
GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp
r2762 r2763 27 27 28 28 if (nodeType == TYPE_LEAF) 29 {30 // cout << "l";31 29 node = new BvhLeaf(parent); 32 }33 30 else if (nodeType == TYPE_INTERIOR) 34 {35 //cout << "i";36 31 node = new BvhInterior(parent); 37 }38 32 else 39 { 40 cerr << "wrong node type: " << nodeType << endl; 41 //exit(0); 42 } 33 cerr << "error: wrong node type: " << nodeType << endl; 34 43 35 44 36 Vector3 bMin, bMax; … … 50 42 stream.read(reinterpret_cast<char *>(&bMax), sizeof(Vector3)); 51 43 52 //if ((bMin.x >= bMax.x)||(bMin.y >= bMax.y)||(bMin.z >= bMax.z))53 // cout << "error: " << bMin << " " << bMax << endl;54 55 44 node->mBox = AxisAlignedBox3(bMin, bMax); 56 57 45 node->mArea = node->mBox.SurfaceArea(); 58 46 59 47 //cout << "box: " << node->mBox << " area: " << node->mArea << endl; 60 cout << node->mBox << " f " << node->mFirst << " l " << node->mLast << endl; 61 48 62 49 return node; 63 50 } … … 122 109 bvh->ComputeBvhStats(); 123 110 bvh->PrintBvhStats(); 124 bvh->Dummy(); 111 125 112 return bvh; 126 113 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2762 r2763 29 29 //mNumTraversedNodes ++; 30 30 31 //bool intersects; 32 int intersect; 33 if (mBvh->IsWithinViewFrustum(node)!=0) 31 if (mBvh->IsWithinViewFrustum(node)) 34 32 { 35 33 // update node's visited flag => needed for rendering … … 39 37 ++ traversed; 40 38 TraverseNode(node); 41 RenderBox(node->GetBox());42 39 } 43 40 else 44 {RenderBox(node->GetBox()); 45 if (node->IsLeaf()) 46 { 47 48 //cout <<"b: " << node->GetBox() << endl; 49 } 41 { 50 42 //mNumFrustumCulledNodes ++; 51 43 } 52 44 //cout << "intersect: " << intersect << " bx " << node->GetBox() << endl; 53 45 } 54 55 //RenderFrustum(); 56 46 57 47 //std::cout << "traversed: " << traversed << std::endl; 58 48 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.cpp
r2753 r2763 69 69 } 70 70 71 72 73 QueryHandler::QueryHandler(): mCurrentQueryIdx(0) 74 {} 75 76 77 OcclusionQuery *QueryHandler::RequestQuery() 78 { 79 OcclusionQuery *query; 80 81 if (mCurrentQueryIdx == mOcclusionQueries.size()) 82 { 83 query = new OcclusionQuery(); 84 mOcclusionQueries.push_back(query); 85 } 86 else 87 query = mOcclusionQueries[mCurrentQueryIdx]; 88 89 return query; 90 } 91 92 93 void QueryHandler::ResetQueries() 94 { 95 mCurrentQueryIdx = 0; 96 } 97 98 99 void QueryHandler::DestroyQueries() 100 { 101 CLEAR_CONTAINER(mOcclusionQueries); 102 mCurrentQueryIdx = 0; 103 mOcclusionQueries.clear(); 104 } 105 106 107 71 108 } // namespace -
GTP/trunk/App/Demos/Vis/CHC_revisited/OcclusionQuery.h
r2753 r2763 22 22 virtual ~OcclusionQuery(); 23 23 24 virtualbool ResultAvailable() const;24 bool ResultAvailable() const; 25 25 26 virtualunsigned int GetQueryResult() const;26 unsigned int GetQueryResult() const; 27 27 28 v irtual void BeginQuery();28 void BeginQuery(); 29 29 30 v irtual void EndQuery();30 void EndQuery(); 31 31 32 32 unsigned int GetQueryId() const; … … 59 59 }; 60 60 61 62 class QueryHandler 63 { 64 public: 65 66 QueryHandler(); 67 68 OcclusionQuery *RequestQuery(); 69 70 /** Must be called every frame. 71 */ 72 void ResetQueries(); 73 void DestroyQueries(); 74 75 protected: 76 77 int mCurrentQueryIdx; 78 79 QueryContainer mOcclusionQueries; 80 }; 81 82 61 83 } // namespace 62 84 #endif // OcclusionQuery_H -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2762 r2763 100 100 101 101 102 103 void RenderTraverser::Switch2GLRenderState() 104 { 105 // boolean used to avoid unnecessary state changes 106 if (mIsQueryMode) 107 { 108 // switch back to rendermode 109 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 110 glDepthMask(GL_TRUE); 111 glEnable(GL_LIGHTING); 112 mIsQueryMode = false; 113 } 114 } 115 116 117 OcclusionQuery *RenderTraverser::IssueOcclusionQuery(BvhNode *node, bool wasVisible) 118 { 119 OcclusionQuery *query = mQueryHandler.RequestQuery(); 120 121 query->BeginQuery(); 122 123 // if leaf and was visible => will be rendered anyway, thus we 124 // can also test with the real geometry 125 /*if(node->IsLeaf() && wasVisible && mUseOptimization) 126 { 127 mNumRenderedGeometry += node->Render(); 128 } 129 else 130 {*/ 131 132 // change state so the bounding box gets not actually rendered on the screen 133 //Switch2GLQueryState(); 134 mBvh->RenderBoundingBox(node); 135 //Switch2GLRenderState(); 136 137 query->EndQuery(); 138 139 return query; 140 } 141 142 143 void RenderTraverser::Switch2GLQueryState() 144 { 145 // boolean used to avoid unnecessary state changes 146 if (!mIsQueryMode) 147 { 148 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 149 glDepthMask(GL_FALSE); 150 glDisable(GL_LIGHTING); 151 mIsQueryMode = true; 152 } 153 } 154 155 156 102 157 #if 0 103 158 … … 160 215 } 161 216 162 163 unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const164 {165 unsigned int result;166 167 if (mUseArbQueries)168 {169 glGetQueryObjectuivARB(node->GetOcclusionQuery(), GL_QUERY_RESULT_ARB, &result);170 }171 else172 {173 glGetOcclusionQueryuivNV(node->GetOcclusionQuery(), GL_PIXEL_COUNT_NV, &result);174 }175 176 return result;177 }178 179 180 void RenderTraverser::Switch2GLQueryState()181 {182 // boolean used to avoid unnecessary state changes183 if(!mIsQueryMode)184 {185 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);186 glDepthMask(GL_FALSE);187 glDisable(GL_LIGHTING);188 mIsQueryMode = true;189 }190 }191 192 193 void RenderTraverser::Switch2GLRenderState()194 {195 // boolean used to avoid unnecessary state changes196 if(mIsQueryMode)197 {198 // switch back to rendermode199 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);200 glDepthMask(GL_TRUE);201 glEnable(GL_LIGHTING);202 mIsQueryMode = false;203 }204 }205 206 void RenderTraverser::IssueOcclusionQuery(HierarchyNode *node, const bool wasVisible)207 {208 // get next available test id209 unsigned int occlusionQuery = mOcclusionQueries[mCurrentQueryIdx ++];210 211 node->SetOcclusionQuery(occlusionQuery);212 213 // do the actual occlusion query for this node214 if (mUseArbQueries)215 {216 glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionQuery);217 }218 else219 {220 glBeginOcclusionQueryNV(occlusionQuery);221 }222 223 // if leaf and was visible => will be rendered anyway, thus we224 // can also test with the real geometry225 if(node->IsLeaf() && wasVisible && mUseOptimization)226 {227 mNumRenderedGeometry += node->Render();228 }229 else230 {231 // change state so the bounding box gets not actually rendered on the screen232 Switch2GLQueryState();233 node->RenderBoundingVolume();234 Switch2GLRenderState();235 }236 237 if (mUseArbQueries)238 {239 glEndQueryARB(GL_SAMPLES_PASSED_ARB);240 }241 else242 {243 glEndOcclusionQueryNV();244 }245 }246 217 247 218 void RenderTraverser::Preprocess() -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2762 r2763 6 6 #include "glInterface.h" 7 7 #include "Bvh.h" 8 #include "OcclusionQuery.h" 9 8 10 9 11 namespace CHCDemo … … 104 106 /** Issues occlusion query for specified node 105 107 */ 106 voidIssueOcclusionQuery(BvhNode *node, bool wasVisible);108 OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 107 109 /** Resets occlusion queries after a traversal 108 110 */ … … 151 153 152 154 RenderState *mRenderState; 155 156 QueryHandler mQueryHandler; 153 157 }; 154 158 -
GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp
r2757 r2763 1 1 #include "StopAndWaitTraverser.h" 2 #include "SceneEntity.h" 3 2 4 3 5 namespace CHCDemo 4 6 { 7 8 using namespace std; 9 10 11 5 12 StopAndWaitTraverser::StopAndWaitTraverser(): RenderTraverser() 6 13 { … … 16 23 void StopAndWaitTraverser::Render() 17 24 { 18 #if 0 19 while(! mDistanceQueue.empty()) 25 mRenderState->mTexturesEnabled = false; 26 mDistanceQueue.push(mBvh->GetRoot()); 27 28 29 int traversed = 0; 30 while (!mDistanceQueue.empty()) 20 31 { 21 HierarchyNode *node = mDistanceQueue.top();32 BvhNode *node = mDistanceQueue.top(); 22 33 mDistanceQueue.pop(); 23 mNumTraversedNodes ++;34 24 35 // interesting for the visualization, so rest and set 25 36 node->SetVisible(false); 37 //mNumTraversedNodes ++; 26 38 27 bool intersects; 28 29 if(InsideViewFrustum(node, intersects)) 39 if (mBvh->IsWithinViewFrustum(node)) 30 40 { 31 // update node's visited flag 32 node->SetLastVisited(mFrameID); 33 34 // for near plane intersecting abbs possible 35 // wrong results => skip occlusion query 36 if(intersects) 41 // if intersects near plane assume visible and don't issue test 42 if (mBvh->CalcDistance(node) < 0.1f) 37 43 { 38 node->SetVisible(true);39 44 TraverseNode(node); 40 45 } 41 46 else 42 47 { 43 IssueOcclusionQuery(node, false); 44 45 // wait if result not available 46 int visiblePixels = GetOcclusionQueryResult(node); 47 48 // node visible 49 if(visiblePixels > mVisibilityThreshold) 48 OcclusionQuery *query = IssueOcclusionQuery(node, false); 49 50 int visiblePixels = query->GetQueryResult(); 51 52 if (visiblePixels > 0) 50 53 { 51 node->SetVisible(true); 54 cout<< "visible: " << visiblePixels << endl; 55 // update node's visited flag => needed for rendering 56 // so set it also here 57 //node->SetLastVisited(mFrameID); 58 //node->SetVisible(true); 59 ++ traversed; 52 60 TraverseNode(node); 53 61 } 54 else 55 { 56 mNumQueryCulledNodes ++; 57 } 58 } 62 } 59 63 } 60 64 else 61 65 { 62 mNumFrustumCulledNodes ++;66 //mNumFrustumCulledNodes ++; 63 67 } 68 //cout << "intersect: " << intersect << " bx " << node->GetBox() << endl; 64 69 } 65 #endif 70 71 mQueryHandler.ResetQueries(); 72 //std::cout << "traversed: " << traversed << std::endl; 66 73 } 67 74 -
GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h
r2757 r2763 18 18 /** Renders the scene with the specified method 19 19 */ 20 virtual void Render() = 0;20 virtual void Render(); 21 21 }; 22 22 -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2762 r2763 15 15 #include "BvhLoader.h" 16 16 #include "FrustumCullingTraverser.h" 17 #include "StopAndWaitTraverser.h" 17 18 18 19 … … 128 129 //const string filename("house_test.dem"); 129 130 //const string filename("city_demo.dem"); 130 //const string filename("city.dem");131 const string filename("roofs.dem");131 const string filename("city.dem"); 132 //const string filename("roofs.dem"); 132 133 133 134 if (loader.Load(filename, sceneEntities)) … … 137 138 138 139 BvhLoader bvhLoader; 139 bvh = bvhLoader.Load("roofs.bvh", sceneEntities); 140 141 142 //bvh = bvhLoader.Load("city.bvh", sceneEntities); 140 //bvh = bvhLoader.Load("roofs.bvh", sceneEntities); 141 bvh = bvhLoader.Load("city.bvh", sceneEntities); 142 //bvh = bvhLoader.Load("city_demo.bvh", sceneEntities); 143 143 //bvh = bvhLoader.Load("house_test.bvh", sceneEntities); 144 144 145 145 sceneBox = bvh->GetBox(); 146 146 147 traverser = new FrustumCullingTraverser(); 147 //traverser = new FrustumCullingTraverser(); 148 traverser = new StopAndWaitTraverser(); 148 149 traverser->SetHierarchy(bvh); 149 150 traverser->SetRenderState(&state); -
GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
r2756 r2763 469 469 typedef std::vector<BvhLeaf *> BvhLeafContainer; 470 470 typedef std::vector<Triangle3> TriangleContainer; 471 typedef std::vector<OcclusionQuery *> QueryContainer; 471 472 472 473 typedef std::queue<OcclusionQuery *> QueryQueue;
Note: See TracChangeset
for help on using the changeset viewer.