- Timestamp:
- 06/17/08 15:20:32 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 4 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2764 r2767 27 27 friend class Bvh; 28 28 friend class BvhLoader; 29 friend class my less;29 friend class mygreaterdistance; 30 30 31 31 public: … … 393 393 a lower distance has a higher value in the queue 394 394 */ 395 class my less395 class mygreaterdistance 396 396 { 397 397 public: … … 401 401 } 402 402 }; 403 404 typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, mygreaterdistance> TraversalQueue; 403 405 404 406 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp
r2755 r2767 4 4 { 5 5 6 CHCPlusPlusTraverser::CHCPlusPlusTraverser() : RenderTraverser()6 CHCPlusPlusTraverser::CHCPlusPlusTraverser() 7 7 { 8 8 } 9 9 10 10 11 CHCPlusPlusTraverser::~CHCPlusPlusTraverser()11 void CHCPlusPlusTraverser::Traverse() 12 12 { 13 //DelQueries(); 14 } 13 //-- PART 1: process finished occlusion queries 14 while (!mDistanceQueue.empty() || !mQueryQueue.empty()) 15 { 16 while (!mQueryQueue.empty() && 17 (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 18 { 19 OcclusionQuery *query = mQueryQueue.front(); 20 mQueryQueue.pop(); 21 22 // wait until result available 23 int visiblePixels = query->GetQueryResult(); 15 24 25 if (visiblePixels > mVisibilityThreshold) 26 { 27 BvhNode *node = query->GetFrontNode(); 16 28 17 void CHCPlusPlusTraverser::Render() 18 { 29 mBvh->MakeParentsVisible(node); 30 TraverseNode(node); 31 } 32 else 33 { 34 ++ mStats.mNumQueryCulledNodes; 35 } 36 } 37 38 //-- PART 2: hierarchical traversal 39 if (!mDistanceQueue.empty()) 40 { 41 BvhNode *node = mDistanceQueue.top(); 42 mDistanceQueue.pop(); 43 44 if (mBvh->IsWithinViewFrustum(node)) 45 { 46 // for near plane intersecting bounding box possible 47 // wrong results => skip occlusion query 48 if (IntersectsNearPlane(node)) 49 { 50 // update node's visited flag 51 node->SetLastVisitedFrame(mFrameId); 52 node->SetVisible(true); 53 mBvh->MakeParentsVisible(node); 54 55 TraverseNode(node); 56 } 57 else 58 { 59 // identify previously visible nodes 60 const bool wasVisible = node->IsVisible() && (node->GetLastVisitedFrame() == mFrameId - 1); 61 62 // identify nodes that we cannot skip queries for 63 const bool leafOrWasInvisible = 64 (node->GetLastVisitedFrame() != mFrameId) && (!wasVisible || node->IsVirtualLeaf()); 65 66 // reset node's visibility classification 67 node->SetVisible(false); 68 69 // update node's visited flag 70 node->SetLastVisitedFrame(mFrameId); 71 72 // skip testing previously visible interior nodes 73 if (leafOrWasInvisible) 74 { 75 OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible); 76 mQueryQueue.push(query); 77 } 78 79 // always traverse a node if it was visible 80 if (wasVisible) 81 TraverseNode(node); 82 } 83 } 84 else 85 { 86 // for stats 87 ++ mStats.mNumFrustumCulledNodes; 88 } 89 } 90 } 19 91 } 20 92 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h
r2755 r2767 8 8 { 9 9 10 /** Class implementing traversal using the CHC algorithm.10 /** Class implementing traversal using the CHC++ algorithm. 11 11 */ 12 12 class CHCPlusPlusTraverser: public RenderTraverser 13 13 { 14 14 public: 15 15 16 CHCPlusPlusTraverser(); 16 ~CHCPlusPlusTraverser();17 //~CHCPlusPlusTraverser(); 17 18 18 /** Renders the scene with the specified method 19 protected: 20 /** Traverses and renders the scene with the specified method 19 21 */ 20 virtual void Render();22 virtual void Traverse(); 21 23 }; 22 24 … … 25 27 26 28 27 #endif // __CHC TRAVERSER_H29 #endif // __CHCPLUSPLUSTRAVERSER_H -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.cpp
r2765 r2767 6 6 { 7 7 8 CHCTraverser::CHCTraverser(): RenderTraverser() 9 { 10 } 8 CHCTraverser::CHCTraverser() 9 {} 11 10 12 11 13 CHCTraverser::~CHCTraverser()12 void CHCTraverser::Traverse() 14 13 { 15 //DelQueries();16 }17 18 19 void CHCTraverser::Render()20 {21 QueryQueue queryQueue;22 23 14 //-- PART 1: process finished occlusion queries 24 while (!mDistanceQueue.empty() || ! queryQueue.empty())15 while (!mDistanceQueue.empty() || !mQueryQueue.empty()) 25 16 { 26 while (! queryQueue.empty() &&27 ( queryQueue.front()->ResultAvailable() || mDistanceQueue.empty()))17 while (!mQueryQueue.empty() && 18 (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 28 19 { 29 OcclusionQuery *query = queryQueue.front();30 queryQueue.pop();20 OcclusionQuery *query = mQueryQueue.front(); 21 mQueryQueue.pop(); 31 22 32 23 // wait until result available … … 84 75 { 85 76 OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible); 86 queryQueue.push(query);77 mQueryQueue.push(query); 87 78 } 88 79 -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h
r2755 r2767 14 14 public: 15 15 CHCTraverser(); 16 ~CHCTraverser();16 //~CHCTraverser(); 17 17 18 /** Renders the scene with the specified method 18 19 protected: 20 /** Traverses and renders the scene with the specified method 19 21 */ 20 virtual void Render();22 virtual void Traverse(); 21 23 }; 22 24 -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2765 r2767 13 13 14 14 15 void FrustumCullingTraverser:: Render()15 void FrustumCullingTraverser::Traverse() 16 16 { 17 17 while (!mDistanceQueue.empty()) … … 36 36 } 37 37 } 38 39 mRenderQueue.Render(); 40 mRenderQueue.Clear(); 38 41 } 39 42 43 40 44 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.h
r2757 r2767 16 16 FrustumCullingTraverser(); 17 17 18 /** Renders the scene with the specified method 18 protected: 19 /** Traverses and renders the scene with the specified method 19 20 */ 20 virtual void Render();21 virtual void Traverse(); 21 22 }; 22 23 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
r2760 r2767 18 18 mTexture = NULL; 19 19 20 mAmbientColor = RgbColor( 0.2, 0.2, 0.2);21 mDiffuseColor = RgbColor(1 , 1, 1);22 mSpecularColor = RgbColor(0.0 , 0.0, 0.0);23 //mSpecularColor = RgbColor(1, 1, 1);20 mAmbientColor = RgbColor(.2f, .2f, .2f); 21 mDiffuseColor = RgbColor(1.0f, 1.0f, 1.0f); 22 mSpecularColor = RgbColor(0.0f, 0.0f, 0.0f); 23 mSpecularColor = RgbColor(1.0f, 1.0f, 1.0f); 24 24 } 25 25 … … 73 73 glBindTexture(GL_TEXTURE_2D, 0); 74 74 75 /* float amb[] = {0.2f, 0.2f, 0.2f, 1.0f}; 76 float dif[] = {1.0f, 1.0f, 1.0f, 1.0f}; 77 float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; 78 79 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&amb); 80 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&dif); 81 glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&spec); 82 */ 75 83 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 76 84 glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); -
GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h
r2756 r2767 15 15 float r, g, b; 16 16 17 RgbColor(): r(0.5f),g(0.5f),b(0.5f)17 RgbColor(): r(0.5f), g(0.5f), b(0.5f) 18 18 { 19 19 } 20 20 21 RgbColor(const float _r, 22 const float _g, 23 const float _b):r(_r),g(_g),b(_b) 21 RgbColor(float _r, float _g, float _b): r(_r), g(_g), b(_b) 24 22 { 25 23 } 26 24 27 25 friend RgbColor 28 RandomColor( const float a=0.0f, const float b=1.0f);26 RandomColor(float a = 0.0f, float b = 1.0f); 29 27 30 28 // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 31 29 // (range of hue from 0-240) 32 30 33 friend RgbColor RainbowColorMapping( constfloat value);31 friend RgbColor RainbowColorMapping(float value); 34 32 35 33 }; -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2765 r2767 46 46 47 47 48 void RenderTraverser::InitFrame(Camera *camera, int currentFrameId)49 {50 mFrameId = currentFrameId;51 mBvh->InitFrame(camera, currentFrameId);52 53 mStats.Reset();54 mQueryHandler.ResetQueries();55 mRenderState->mTexturesEnabled = false;56 EnqueueNode(mBvh->GetRoot());57 }58 59 60 48 void RenderTraverser::EnqueueNode(BvhNode *node) 61 49 { … … 71 59 if (node->IsVirtualLeaf()) 72 60 { 73 //RenderBox(node->GetBox()); 74 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 61 if (mUseRenderQueue) 62 { 63 int geometrySize; 64 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 65 mRenderQueue.Enqueue(geom, geometrySize); 66 mStats.mNumRenderedGeometry += geometrySize; 67 } 68 else 69 { 70 // RenderBox(node->GetBox()); 71 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 72 } 75 73 } 76 74 else … … 88 86 { 89 87 mBvh = bvh; 90 //DelQueries();91 88 } 92 89 … … 95 92 { 96 93 mRenderState = state; 97 //DelQueries(); 98 } 99 94 mRenderQueue.SetRenderState(state); 95 } 100 96 101 97 … … 157 153 158 154 159 160 void RenderTraverser::PullUpVisibility(BvhNode *node)161 {162 while(node && ! node->IsVisible())163 {164 node->SetVisible(true);165 node = node->GetParent();166 }167 }168 169 170 155 void RenderTraverser::SetVisibilityThreshold(int threshold) 171 156 { … … 180 165 181 166 182 /*183 void RenderTraverser::RenderVisualization()184 {185 mDistanceQueue.push(mHierarchyRoot);186 187 while(! mDistanceQueue.empty())188 {189 HierarchyNode *node = mDistanceQueue.top();190 mDistanceQueue.pop();191 192 // identify previously visible nodes193 bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1);194 195 if(wasVisible)196 TraverseNode(node);197 else198 {199 // also render culled nodes200 glColor3f(1.0,0.0,0.0);201 node->RenderBoundingVolumeForVisualization();202 }203 }204 }*/205 206 207 167 void RenderTraverser::SetUseOptimization(bool useOptimization) 208 168 { 209 169 mUseOptimization = useOptimization; 210 printf("using opt %d\n", mUseOptimization); 211 } 212 213 214 void RenderTraverser::RenderBox(const AxisAlignedBox3 &box) 215 { 216 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 217 glDisable(GL_CULL_FACE); 218 glColor3f(1.0f, 0.0f, 0.0f); 219 220 glBegin(GL_QUADS); 221 glVertex3f(box.Min().x, box.Max().y, box.Min().z); 222 glVertex3f(box.Max().x, box.Max().y, box.Min().z); 223 glVertex3f(box.Max().x, box.Min().y, box.Min().z); 224 glVertex3f(box.Min().x, box.Min().y, box.Min().z); 225 glEnd(); 226 227 glBegin(GL_QUADS); 228 glVertex3f(box.Min().x, box.Min().y, box.Max().z); 229 glVertex3f(box.Max().x, box.Min().y, box.Max().z); 230 glVertex3f(box.Max().x, box.Max().y, box.Max().z); 231 glVertex3f(box.Min().x, box.Max().y, box.Max().z); 232 glEnd(); 233 234 glBegin(GL_QUADS); 235 glVertex3f(box.Max().x, box.Min().y, box.Min().z); 236 glVertex3f(box.Max().x, box.Min().y, box.Max().z); 237 glVertex3f(box.Max().x, box.Max().y, box.Max().z); 238 glVertex3f(box.Max().x, box.Max().y, box.Min().z); 239 glEnd(); 240 241 glBegin(GL_QUADS); 242 glVertex3f(box.Min().x, box.Min().y, box.Min().z); 243 glVertex3f(box.Min().x, box.Min().y, box.Max().z); 244 glVertex3f(box.Min().x, box.Max().y, box.Max().z); 245 glVertex3f(box.Min().x, box.Max().y, box.Min().z); 246 glEnd(); 247 248 glBegin(GL_QUADS); 249 glVertex3f(box.Min().x, box.Min().y, box.Min().z); 250 glVertex3f(box.Max().x, box.Min().y, box.Min().z); 251 glVertex3f(box.Max().x, box.Min().y, box.Max().z); 252 glVertex3f(box.Min().x, box.Min().y, box.Max().z); 253 glEnd(); 254 255 glBegin(GL_QUADS); 256 glVertex3f(box.Min().x, box.Max().y, box.Min().z); 257 glVertex3f(box.Max().x, box.Max().y, box.Min().z); 258 glVertex3f(box.Max().x, box.Max().y, box.Max().z); 259 glVertex3f(box.Min().x, box.Max().y, box.Max().z); 260 glEnd(); 261 262 glEnable(GL_CULL_FACE); 263 264 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 265 } 266 267 268 void RenderTraverser::RenderFrustum() 269 { 270 Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 271 mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 272 273 glLineWidth(2); 274 275 glBegin(GL_LINE_LOOP); 276 glVertex3d(fbl.x, fbl.y, fbl.z); 277 glVertex3d(fbr.x, fbr.y, fbr.z); 278 glVertex3d(ftr.x, ftr.y, ftr.z); 279 glVertex3d(ftl.x, ftl.y, ftl.z); 280 glEnd(); 281 282 glBegin(GL_LINE_LOOP); 283 glVertex3d(nbl.x, nbl.y, nbl.z); 284 glVertex3d(nbr.x, nbr.y, nbr.z); 285 glVertex3d(ntr.x, ntr.y, ntr.z); 286 glVertex3d(ntl.x, ntl.y, ntl.z); 287 glEnd(); 288 289 glBegin(GL_LINE_LOOP); 290 glVertex3d(fbl.x, fbl.y, fbl.z); 291 glVertex3d(ftl.x, ftl.y, ftl.z); 292 glVertex3d(ntl.x, ntl.y, ntl.z); 293 glVertex3d(nbl.x, nbl.y, nbl.z); 294 glEnd(); 295 296 glBegin(GL_LINE_LOOP); 297 glVertex3d(fbr.x, fbr.y, fbr.z); 298 glVertex3d(ftr.x, ftr.y, ftr.z); 299 glVertex3d(ntr.x, ntr.y, ntr.z); 300 glVertex3d(nbr.x, nbr.y, nbr.z); 301 glEnd(); 302 303 glBegin(GL_LINE_LOOP); 304 glVertex3d(fbr.x, fbr.y, fbr.z); 305 glVertex3d(fbl.x, fbl.y, fbl.z); 306 glVertex3d(nbl.x, nbl.y, nbl.z); 307 glVertex3d(nbr.x, nbr.y, nbr.z); 308 glEnd(); 309 310 glBegin(GL_LINE_LOOP); 311 glVertex3d(ftr.x, ftr.y, ftr.z); 312 glVertex3d(ftl.x, ftl.y, ftl.z); 313 glVertex3d(ntl.x, ntl.y, ntl.z); 314 glVertex3d(ntr.x, ntr.y, ntr.z); 315 glEnd(); 316 } 317 318 319 320 } 170 } 171 172 173 174 void RenderTraverser::RenderScene() 175 { 176 InitTiming(); 177 long t1, t2; 178 179 t1 = GetTime(); 180 181 glEnableClientState(GL_VERTEX_ARRAY); 182 glEnableClientState(GL_NORMAL_ARRAY); 183 184 ++ mFrameId; 185 186 mBvh->InitFrame(mCamera, mFrameId); 187 188 mStats.Reset(); 189 mQueryHandler.ResetQueries(); 190 mRenderState->mTexturesEnabled = false; 191 EnqueueNode(mBvh->GetRoot()); 192 193 194 /////////// 195 //-- the actual rendering algorithm 196 197 Traverse(); 198 199 glDisableClientState(GL_VERTEX_ARRAY); 200 glDisableClientState(GL_NORMAL_ARRAY); 201 202 glDisable(GL_TEXTURE_2D); 203 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 204 205 t2 = GetTime(); 206 mStats.mRenderTime = TimeDiff(t1, t2); 207 } 208 209 210 void RenderTraverser::SetUseRenderQueue(bool useRenderQueue) 211 { 212 mUseRenderQueue = useRenderQueue; 213 std::cout << "using render queue: " << mUseRenderQueue << std::endl; 214 } 215 216 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2765 r2767 3 3 4 4 #include <queue> 5 #include <stack>6 #include "glInterface.h"7 5 #include "Bvh.h" 8 6 #include "OcclusionQuery.h" 9 7 #include "Camera.h" 8 #include "RenderQueue.h" 9 10 10 11 11 12 namespace CHCDemo … … 37 38 38 39 39 //typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue;40 typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless> TraversalQueue;41 40 42 41 /** Abstract class implementing a scene traversal for rendering. … … 45 44 { 46 45 public: 47 enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, NUM_RENDERMODES}; 46 47 enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_RENDERMODES}; 48 48 49 49 RenderTraverser(); … … 52 52 //! Renders the scene with the specified method 53 53 /** 54 The mode is one of 55 RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only 56 RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm 57 RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm 54 The method is one of 55 CULL_FRUSTUM: view frustum culling only 56 STOP_AND_WAIT: hierarchical stop and wait algorithm 57 CHC: coherent hierarchical algorithm 58 CHCPLUSPLUS: coherent hierarchical algorithm revisited 58 59 */ 59 v irtual void Render() = 0;60 void RenderScene(); 60 61 /** Sets the scene hierarchy. 61 62 */ … … 79 80 */ 80 81 void SetRenderState(RenderState *state); 81 82 void RenderFrustum();83 82 83 void SetUseRenderQueue(bool useRenderQueue); 84 84 const TraversalStatistics &GetStats() const { return mStats; } 85 86 void InitFrame(Camera *camera, int currentFrameId);87 85 88 86 protected: 89 87 90 /** does some important initializations 88 /** This is the actual rendering algorithm. It must be implemented by all 89 the subclasses. 91 90 */ 92 v oid Preprocess();91 virtual void Traverse() = 0; 93 92 /** Hierarchy traversal 94 93 */ 95 94 void TraverseNode(BvhNode *node); 96 /** Visibility is pulled up from visibility of children97 */98 void PullUpVisibility(BvhNode *node);99 95 /** Issues occlusion query for specified node 100 96 */ 101 97 OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 102 /** Resets occlusion queries after a traversal103 */104 void DelQueries();105 /** Does view frustum culling. returns intersect (if intersects view plane)106 */107 bool InsideViewFrustum(BvhNode *node, bool &intersects);108 98 /** switches to normal render mode 109 99 */ … … 112 102 */ 113 103 void Switch2GLQueryState(); 114 115 inline bool IntersectsNearPlane(BvhNode *node) const {return mBvh->GetDistance(node) < mCamera->GetNear();} 116 104 /** Retunrs true if the current bvh node intersects the near plane. 105 */ 106 inline bool IntersectsNearPlane(BvhNode *node) const; 107 /** Enqueues a bvh node. 108 */ 117 109 void EnqueueNode(BvhNode *node); 118 119 void RenderBox(const AxisAlignedBox3 &box);120 110 121 111 … … 128 118 /// the root of the scene hierarchy 129 119 Bvh *mBvh; 130 /// use a priority queue rather than a renderstack120 /// the priority queue used for front to back traversal 131 121 TraversalQueue mDistanceQueue; 132 122 /// the current frame id 133 123 int mFrameId; 134 int mVisibilityThreshold;135 124 136 125 bool mIsQueryMode; 137 138 //bool mIntersects;139 bool mUseOptimization;140 126 141 127 RenderState *mRenderState; … … 144 130 145 131 TraversalStatistics mStats; 132 133 QueryQueue mQueryQueue; 134 135 int mVisibilityThreshold; 136 137 bool mUseOptimization; 138 139 RenderQueue mRenderQueue; 140 141 bool mUseRenderQueue; 146 142 }; 143 144 145 inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const 146 { 147 return mBvh->GetDistance(node) < mCamera->GetNear(); 148 } 149 147 150 148 151 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h
r2764 r2767 57 57 */ 58 58 int GetLastRendered() const; 59 59 60 Material *GetMaterial() const { return mMaterial; } 60 61 61 62 protected: -
GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp
r2765 r2767 10 10 11 11 12 StopAndWaitTraverser::StopAndWaitTraverser() : RenderTraverser()12 StopAndWaitTraverser::StopAndWaitTraverser() 13 13 { 14 14 } 15 15 16 16 17 StopAndWaitTraverser::~StopAndWaitTraverser() 18 { 19 //DelQueries(); 20 } 21 22 23 void StopAndWaitTraverser::Render() 17 void StopAndWaitTraverser::Traverse() 24 18 { 25 19 while (!mDistanceQueue.empty()) -
GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h
r2763 r2767 13 13 { 14 14 public: 15 15 16 StopAndWaitTraverser(); 16 ~StopAndWaitTraverser();17 17 18 /** Renders the scene with the specified method 18 //~StopAndWaitTraverser(); 19 20 protected: 21 /** Traverses and renders the scene with the specified method 19 22 */ 20 virtual void Render(); 23 virtual void Traverse(); 24 21 25 }; 22 26 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp
r2764 r2767 61 61 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 62 62 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 63 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); 63 64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 64 65 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); -
GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
r2764 r2767 358 358 </File> 359 359 <File 360 RelativePath=".\RenderQueue.h" 361 > 362 </File> 363 <File 360 364 RelativePath=".\SceneEntity.h" 361 365 > … … 363 367 <File 364 368 RelativePath=".\Texture.h" 369 > 370 </File> 371 <File 372 RelativePath=".\Visualization.h" 365 373 > 366 374 </File> … … 396 404 </File> 397 405 <File 406 RelativePath=".\RenderQueue.cpp" 407 > 408 </File> 409 <File 398 410 RelativePath=".\SceneEntity.cpp" 399 411 > … … 401 413 <File 402 414 RelativePath=".\Texture.cpp" 415 > 416 </File> 417 <File 418 RelativePath=".\Visualization.cpp" 403 419 > 404 420 </File> -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2765 r2767 17 17 #include "StopAndWaitTraverser.h" 18 18 #include "CHCTraverser.h" 19 #include "CHCPlusPlusTraverser.h" 20 #include "Visualization.h" 21 19 22 20 23 … … 27 30 SceneEntityContainer sceneEntities; 28 31 // traverses and renders the hierarchy 29 RenderTraverser *traverser ;32 RenderTraverser *traverser = NULL; 30 33 /// the hierarchy 31 Bvh *bvh ;34 Bvh *bvh = NULL; 32 35 /// the scene camera 33 Camera *camera ;34 /// the scene bounding box35 AxisAlignedBox3 sceneBox;36 Camera *camera = NULL; 37 /// the visualization 38 Visualization *visualization = NULL; 36 39 /// the current render state 37 40 RenderState state; … … 43 46 float nearDist = 0.1f; 44 47 48 const float keyForwardMotion = 1.0f; 49 const float keyRotation = 0.2f; 50 51 bool useRenderQueue = false; 52 45 53 int winWidth = 1024; 46 54 int winHeight = 768; … … 55 63 56 64 57 int currentFrame = -1;58 59 65 // visualisation view matrix 60 66 Matrix4x4 visView; … … 63 69 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 64 70 65 const int renderTimeSize = 100;66 long renderTimes[renderTimeSize];67 int renderTimesIdx = 0;68 int renderTimesValid = 0;69 70 71 bool useOptimization = true; 71 72 72 73 Vector3 amb[2];74 Vector3 dif[2];75 Vector3 spec[2];76 73 77 74 void InitExtensions(); … … 100 97 void setupVisView(void); 101 98 long calcRenderTime(void); 102 void resetTimer(void);103 99 void CalcDecimalPoint(std::string &str, int d); 104 100 void ResetTraverser(); … … 148 144 //bvh = bvhLoader.Load("house_test.bvh", sceneEntities); 149 145 150 sceneBox = bvh->GetBox();151 152 146 ResetTraverser(); 153 147 154 148 //camera->LookAtBox(sceneBox); 155 camera->LookInBox(sceneBox); 156 157 /// initialise rendertime array 158 for(int i=0; i<renderTimeSize; i++) 159 renderTimes[i] = 0; 149 //camera->LookInBox(bvh->GetBox()); 150 151 camera->SetDirection(Vector3(0.961829f, 0.273652f, 0.0f)); 152 camera->SetPosition(Vector3(483.398f, 242.364f, 186.078f)); 160 153 161 154 glutMainLoop(); … … 170 163 void InitGLstate(void) 171 164 { 172 glClearColor(0.5f, 0.5f, 0.8f, 0.0 );165 glClearColor(0.5f, 0.5f, 0.8f, 0.0f); 173 166 174 167 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); … … 185 178 glMaterialf(GL_FRONT, GL_SHININESS, 64); 186 179 glEnable(GL_NORMALIZE); 187 180 181 //glEnable(GL_ALPHA_TEST); 182 //glAlphaFunc(GL_GEQUAL, 0.01); 183 184 glDisable(GL_ALPHA_TEST); 185 188 186 glFrontFace(GL_CCW); 189 187 glCullFace(GL_BACK); … … 288 286 traverser = new CHCTraverser(); 289 287 break; 288 case RenderTraverser::CHCPLUSPLUS: 289 traverser = new CHCPlusPlusTraverser(); 290 break; 291 290 292 default: 291 293 traverser = new FrustumCullingTraverser(); 292 294 } 293 295 296 traverser->SetCamera(camera); 294 297 traverser->SetHierarchy(bvh); 295 298 traverser->SetRenderState(&state); … … 302 305 glEnable(GL_LIGHT0); 303 306 glEnable(GL_LIGHT1); 307 304 308 //glDisable(GL_LIGHT1); 305 309 //glDisable(GL_LIGHTING); … … 349 353 glLoadIdentity(); 350 354 351 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude( sceneBox.Diagonal()));355 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 352 356 353 357 glMatrixMode(GL_MODELVIEW); … … 357 361 glLightfv(GL_LIGHT0, GL_POSITION, position); 358 362 359 GLfloat position1[] = {sceneBox.Center().x, sceneBox.Max().y, sceneBox.Center().z, 1.0f}; 360 //GLfloat position1[] = {-2.0f, 1.0f, 0.0f, 0.0f}; 363 GLfloat position1[] = {bvh->GetBox().Center().x, bvh->GetBox().Max().y, bvh->GetBox().Center().z, 1.0f}; 361 364 glLightfv(GL_LIGHT1, GL_POSITION, position1); 362 365 } … … 365 368 void display(void) 366 369 { 367 ++ currentFrame;368 369 370 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 370 371 … … 372 373 SetupEyeView(); 373 374 374 375 traverser->InitFrame(camera, currentFrame); 376 377 378 InitTiming(); 379 long t1, t2; 380 381 t1 = GetTime(); 382 383 glEnableClientState(GL_VERTEX_ARRAY); 384 glEnableClientState(GL_NORMAL_ARRAY); 385 386 traverser->Render(); 387 388 glDisableClientState(GL_VERTEX_ARRAY); 389 glDisableClientState(GL_NORMAL_ARRAY); 390 391 glDisable(GL_TEXTURE_2D); 392 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 393 394 395 t2 = GetTime(); 396 long loop_time = TimeDiff(t1, t2); 397 398 // cycle through rendertime array 399 renderTimes[renderTimesIdx] = loop_time;// traverser.GetRenderTime(); 400 renderTimesIdx = (renderTimesIdx + 1) % renderTimeSize; 401 402 if(renderTimesIdx > renderTimesValid) 403 renderTimesValid = renderTimesIdx; 404 375 //cout << camera->GetDirection() << " " << camera->GetPosition() << endl; 376 // actually render the scene geometry using one of the specified algorithms 377 traverser->RenderScene(); 378 405 379 //if(visMode) displayVisualization(); 406 380 407 381 DisplayStats(); 382 408 383 glutSwapBuffers(); 409 384 } … … 413 388 void keyboard(const unsigned char c, const int x, const int y) 414 389 { 390 // used to avoid vertical motion with the keys 391 Vector3 hvec = Vector3(camera->GetDirection()[0], camera->GetDirection()[1], 0.0f); 392 Vector3 uvec = Vector3(0, 0, 1); 393 415 394 switch(c) 416 395 { … … 420 399 case 32: //space 421 400 renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 422 resetTimer();423 401 ResetTraverser(); 424 402 break; … … 432 410 //HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 433 411 break; 434 case ' s':435 case ' S':412 case 'O': 413 case 'o': 436 414 showStatistics = !showStatistics; 437 415 break; … … 449 427 visMode = !visMode; 450 428 break; 451 452 429 case '2': 453 430 visZoomFactor += 0.1; … … 460 437 setupVisView(); 461 438 break; 439 case '8': 440 { 441 Vector3 pos = camera->GetPosition(); 442 pos += uvec * keyForwardMotion; 443 camera->SetPosition(pos); 444 break; 445 } 446 case '9': 447 { 448 Vector3 pos = camera->GetPosition(); 449 pos -= uvec * keyForwardMotion; 450 camera->SetPosition(pos); 451 break; 452 } 462 453 case 'g': 463 454 case 'G': 464 455 useOptimization = !useOptimization; 465 456 traverser->SetUseOptimization(useOptimization); 457 break; 458 case 'a': 459 case 'A': 460 { 461 Vector3 viewDir = camera->GetDirection(); 462 // rotate view vector 463 Matrix4x4 rot = RotationZMatrix(keyRotation); 464 viewDir = rot * viewDir; 465 camera->SetDirection(viewDir); 466 } 467 break; 468 case 'd': 469 case 'D': 470 { 471 Vector3 viewDir = camera->GetDirection(); 472 // rotate view vector 473 Matrix4x4 rot = RotationZMatrix(-keyRotation); 474 viewDir = rot * viewDir; 475 camera->SetDirection(viewDir); 476 } 477 break; 478 case 'w': 479 case 'W': 480 { 481 Vector3 pos = camera->GetPosition(); 482 pos += hvec * keyForwardMotion; 483 camera->SetPosition(pos); 484 } 485 break; 486 case 'x': 487 case 'X': 488 { 489 Vector3 pos = camera->GetPosition(); 490 pos -= hvec * keyForwardMotion; 491 camera->SetPosition(pos); 492 } 493 break; 494 case 'r': 495 case 'R': 496 { 497 useRenderQueue = !useRenderQueue; 498 traverser->SetUseRenderQueue(useRenderQueue); 499 } 466 500 default: 467 501 return; … … 475 509 { 476 510 // used to avoid vertical motion with the keys 477 //Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]);511 Vector3 hvec = Vector3(camera->GetDirection()[0], camera->GetDirection()[1], 0.0f); 478 512 479 513 switch(c) … … 482 516 showHelp = !showHelp; 483 517 break; 484 case GLUT_KEY_F2:485 //numNextObjects -= 100;486 //if(numNextObjects < 100) numNextObjects = 100;487 break;488 case GLUT_KEY_F3:489 // numNextObjects += 100;490 break;491 case GLUT_KEY_F4:492 //zLength -= 1;493 //if(zLength < 0) zLength = 0;494 break;495 case GLUT_KEY_F5:496 //zLength += 1;497 break;498 case GLUT_KEY_F6:499 //objectSize -= 0.1;500 //if(objectSize < 0.1) objectSize = 0.1;501 break;502 case GLUT_KEY_F7:503 //objectSize += 0.1;504 break;505 case GLUT_KEY_F8:506 //nextObjectType = (nextObjectType + 1) % Geometry::NUM_OBJECTS;507 break;508 518 case GLUT_KEY_LEFT: 509 // rotateVectorY(viewDir, 0.2); 519 { 520 Vector3 viewDir = camera->GetDirection(); 521 // rotate view vector 522 Matrix4x4 rot = RotationZMatrix(keyRotation); 523 viewDir = rot * viewDir; 524 camera->SetDirection(viewDir); 525 } 510 526 break; 511 527 case GLUT_KEY_RIGHT: 512 //rotateVectorY(viewDir, -0.2); 528 { 529 Vector3 viewDir = camera->GetDirection(); 530 // rotate view vector 531 Matrix4x4 rot = RotationZMatrix(-keyRotation); 532 viewDir = rot * viewDir; 533 camera->SetDirection(viewDir); 534 } 513 535 break; 514 536 case GLUT_KEY_UP: 515 // linCombVector3(eyePos, eyePos, hvec, 0.6); 537 { 538 Vector3 pos = camera->GetPosition(); 539 pos += hvec * 0.6f; 540 camera->SetPosition(pos); 541 } 516 542 break; 517 543 case GLUT_KEY_DOWN: 518 //linCombVector3(eyePos, eyePos, hvec, -0.6); 544 { 545 Vector3 pos = camera->GetPosition(); 546 pos -= hvec * 0.6f; 547 camera->SetPosition(pos); 548 } 519 549 break; 520 550 default: … … 525 555 glutPostRedisplay(); 526 556 } 557 527 558 #pragma warning( default : 4100 ) 528 559 … … 542 573 glLoadIdentity(); 543 574 544 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude( sceneBox.Diagonal()));575 gluPerspective(60.0f, 1.0f / winAspectRatio, nearDist, 2.0f * Magnitude(bvh->GetBox().Diagonal())); 545 576 glMatrixMode(GL_MODELVIEW); 546 577 … … 587 618 588 619 // don't move in the vertical direction 589 //Vector3 horView(viewDir[0], 0, viewDir[2]);590 620 Vector3 horView(viewDir[0], viewDir[1], 0); 591 621 … … 593 623 594 624 // rotate view vector 595 //Matrix4x4 rot = RotationYMatrix(eyeXAngle);596 625 Matrix4x4 rot = RotationZMatrix(eyeXAngle); 597 626 viewDir = rot * viewDir; … … 609 638 610 639 611 /** rotation for left /right mouse drag612 motion for up /down mouse drag640 /** rotation for left / right mouse drag 641 motion for up / down mouse drag 613 642 */ 614 643 void rightMotion(int x, int y) … … 707 736 void output(const int x, const int y, const char *string) 708 737 { 709 if (string != 0)710 { 711 int len, i;712 glRasterPos2f(x, y);713 len = (int)strlen(string);738 if (string != 0) 739 { 740 size_t len, i; 741 glRasterPos2f(x, y); 742 len = strlen(string); 714 743 715 for (i = 0; i < len; i++)744 for (i = 0; i < len; ++ i) 716 745 { 717 746 glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]); … … 719 748 } 720 749 } 750 721 751 722 752 // displays the visualisation of the kd tree node culling … … 738 768 glClear(GL_DEPTH_BUFFER_BIT); 739 769 770 //////////// 740 771 // --- visualization of the occlusion culling 741 /*HierarchyNode::SetRenderBoundingVolume(true); 742 traverser.RenderVisualization(); 743 HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 744 */ 772 visualization->Render(); 773 745 774 glPopMatrix(); 775 746 776 glViewport(0, 0, winWidth, winHeight); 747 777 } 778 748 779 749 780 /** Sets up view matrix in order to get a good position … … 752 783 void setupVisView() 753 784 { 754 const Vector3 up(0.0, 1.0, 0.0);785 const Vector3 up(0.0, 0.0, 1.0); 755 786 756 787 Vector3 visPos(24, 23, -6); … … 760 791 visPos[2] *= visZoomFactor; 761 792 762 Vector3 visDir = Vector3(-1.3, -1, -1); 763 764 //normalize(visDir); 765 //look(visView, visPos, visDir, up); 766 } 767 768 // we take a couple of measurements and compute the average 769 long calcRenderTime() 770 { 771 long result = 0; 772 773 for(int i=0; i<renderTimesValid; i++) 774 result += renderTimes[i]; 775 776 if(renderTimesValid) 777 result /= renderTimesValid; 778 779 return result; 780 } 781 782 783 // reset the timer array for a new traversal method 784 void resetTimer() 785 { 786 renderTimesValid = 0; 787 renderTimesIdx = 0; 793 Vector3 visDir = Vector3(-1.3f, -1, -1); 788 794 } 789 795 … … 796 802 797 803 DEL_PTR(bvh); 804 DEL_PTR(visualization); 798 805 } 799 806 … … 829 836 { 830 837 char *msg[] = {"Frustum Culling", "Stop and Wait", 831 "C oherent Culling"};838 "CHC", "CHC ++"}; 832 839 833 840 char msg2[200]; … … 843 850 844 851 float fps = 1e3f; 845 long renderTime = calcRenderTime(); 852 static long renderTime = traverser->GetStats().mRenderTime; 853 854 const float expFactor = 0.9f; 855 856 renderTime = renderTime * expFactor + (1.0f - expFactor) * traverser->GetStats().mRenderTime; 857 846 858 if (renderTime) fps /= (float)renderTime; 847 859 … … 868 880 else 869 881 { 870 glColor3f(1.0f ,1.0f ,1.0f);871 output( 20, winHeight - 10, msg[renderMode]);882 glColor3f(1.0f, 1.0f , 1.0f); 883 output(10, winHeight - 10, msg[renderMode]); 872 884 873 885 if(showStatistics)
Note: See TracChangeset
for help on using the changeset viewer.