Changeset 2767


Ignore:
Timestamp:
06/17/08 15:20:32 (16 years ago)
Author:
mattausch
Message:
 
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  
    2727        friend class Bvh; 
    2828        friend class BvhLoader; 
    29         friend class myless; 
     29        friend class mygreaterdistance; 
    3030 
    3131public: 
     
    393393        a lower distance has a higher value in the queue 
    394394*/ 
    395 class myless 
     395class mygreaterdistance 
    396396{ 
    397397public: 
     
    401401    } 
    402402}; 
     403 
     404typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, mygreaterdistance> TraversalQueue; 
    403405 
    404406 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp

    r2755 r2767  
    44{ 
    55 
    6 CHCPlusPlusTraverser::CHCPlusPlusTraverser(): RenderTraverser()  
     6CHCPlusPlusTraverser::CHCPlusPlusTraverser()  
    77{ 
    88} 
    99 
    1010 
    11 CHCPlusPlusTraverser::~CHCPlusPlusTraverser() 
     11void CHCPlusPlusTraverser::Traverse() 
    1212{ 
    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(); 
    1524 
     25                        if (visiblePixels > mVisibilityThreshold) 
     26                        { 
     27                                BvhNode *node = query->GetFrontNode(); 
    1628 
    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        } 
    1991} 
    2092 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h

    r2755 r2767  
    88{ 
    99 
    10 /** Class implementing traversal using the CHC algorithm. 
     10/** Class implementing traversal using the CHC++ algorithm. 
    1111*/ 
    1212class CHCPlusPlusTraverser: public RenderTraverser 
    1313{ 
    1414public: 
     15         
    1516        CHCPlusPlusTraverser(); 
    16         ~CHCPlusPlusTraverser(); 
     17        //~CHCPlusPlusTraverser(); 
    1718 
    18         /** Renders the scene with the specified method 
     19protected: 
     20        /** Traverses and renders the scene with the specified method 
    1921        */ 
    20         virtual void Render(); 
     22        virtual void Traverse(); 
    2123}; 
    2224 
     
    2527 
    2628 
    27 #endif // __CHCTRAVERSER_H 
     29#endif // __CHCPLUSPLUSTRAVERSER_H 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.cpp

    r2765 r2767  
    66{ 
    77 
    8 CHCTraverser::CHCTraverser(): RenderTraverser()  
    9 { 
    10 } 
     8CHCTraverser::CHCTraverser()  
     9{} 
    1110 
    1211 
    13 CHCTraverser::~CHCTraverser() 
     12void CHCTraverser::Traverse() 
    1413{ 
    15         //DelQueries(); 
    16 } 
    17  
    18  
    19 void CHCTraverser::Render() 
    20 { 
    21         QueryQueue queryQueue; 
    22  
    2314        //-- PART 1: process finished occlusion queries 
    24         while (!mDistanceQueue.empty() || !queryQueue.empty()) 
     15        while (!mDistanceQueue.empty() || !mQueryQueue.empty()) 
    2516        { 
    26                 while (!queryQueue.empty() &&  
    27                            (queryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 
     17                while (!mQueryQueue.empty() &&  
     18                           (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 
    2819                { 
    29                         OcclusionQuery *query = queryQueue.front(); 
    30                         queryQueue.pop(); 
     20                        OcclusionQuery *query = mQueryQueue.front(); 
     21                        mQueryQueue.pop(); 
    3122                         
    3223                        // wait until result available 
     
    8475                                        { 
    8576                                                OcclusionQuery *query = IssueOcclusionQuery(node, wasVisible); 
    86                                                 queryQueue.push(query); 
     77                                                mQueryQueue.push(query); 
    8778                                        } 
    8879                                         
  • GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h

    r2755 r2767  
    1414public: 
    1515        CHCTraverser(); 
    16         ~CHCTraverser(); 
     16        //~CHCTraverser(); 
    1717 
    18         /** Renders the scene with the specified method 
     18         
     19protected: 
     20        /** Traverses and renders the scene with the specified method 
    1921        */ 
    20         virtual void Render(); 
     22        virtual void Traverse(); 
    2123}; 
    2224 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp

    r2765 r2767  
    1313 
    1414 
    15 void FrustumCullingTraverser::Render() 
     15void FrustumCullingTraverser::Traverse() 
    1616{ 
    1717        while (!mDistanceQueue.empty()) 
     
    3636                } 
    3737        } 
     38 
     39        mRenderQueue.Render(); 
     40        mRenderQueue.Clear(); 
    3841} 
    3942 
     43 
    4044} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.h

    r2757 r2767  
    1616        FrustumCullingTraverser(); 
    1717 
    18         /** Renders the scene with the specified method 
     18protected: 
     19        /** Traverses and renders the scene with the specified method 
    1920        */ 
    20         virtual void Render(); 
     21        virtual void Traverse(); 
    2122}; 
    2223 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp

    r2760 r2767  
    1818        mTexture = NULL; 
    1919 
    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); 
    2424} 
    2525 
     
    7373                glBindTexture(GL_TEXTURE_2D, 0); 
    7474 
     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*/ 
    7583        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); 
    7684        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Material.h

    r2756 r2767  
    1515  float r, g, b; 
    1616 
    17   RgbColor():r(0.5f),g(0.5f),b(0.5f) 
     17  RgbColor(): r(0.5f), g(0.5f), b(0.5f) 
    1818  { 
    1919  } 
    2020 
    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) 
    2422  { 
    2523  } 
    2624 
    2725  friend RgbColor 
    28   RandomColor(const float a=0.0f, const float b=1.0f); 
     26  RandomColor(float a = 0.0f, float b = 1.0f); 
    2927 
    3028  // Mapping from interval 0.0-1.0 to RGB using "rainbow" color map 
    3129  // (range of hue from 0-240) 
    3230 
    33   friend RgbColor RainbowColorMapping(const float value); 
     31  friend RgbColor RainbowColorMapping(float value); 
    3432   
    3533}; 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2765 r2767  
    4646 
    4747 
    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  
    6048void RenderTraverser::EnqueueNode(BvhNode *node) 
    6149{ 
     
    7159        if (node->IsVirtualLeaf()) 
    7260        { 
    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                }                
    7573        } 
    7674        else  
     
    8886{ 
    8987        mBvh = bvh; 
    90         //DelQueries(); 
    9188} 
    9289 
     
    9592{ 
    9693        mRenderState = state; 
    97         //DelQueries(); 
    98 } 
    99  
     94        mRenderQueue.SetRenderState(state); 
     95} 
    10096 
    10197 
     
    157153 
    158154 
    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  
    170155void RenderTraverser::SetVisibilityThreshold(int threshold) 
    171156{ 
     
    180165 
    181166 
    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 nodes 
    193                 bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1); 
    194  
    195                 if(wasVisible) 
    196                         TraverseNode(node); 
    197                 else 
    198                 { 
    199                         // also render culled nodes 
    200                         glColor3f(1.0,0.0,0.0); 
    201                         node->RenderBoundingVolumeForVisualization();            
    202                 } 
    203         } 
    204 }*/ 
    205  
    206  
    207167void RenderTraverser::SetUseOptimization(bool useOptimization) 
    208168{ 
    209169        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 
     174void 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 
     210void 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  
    33 
    44#include <queue> 
    5 #include <stack> 
    6 #include "glInterface.h" 
    75#include "Bvh.h" 
    86#include "OcclusionQuery.h" 
    97#include "Camera.h" 
     8#include "RenderQueue.h" 
     9 
     10 
    1011 
    1112namespace CHCDemo 
     
    3738 
    3839 
    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; 
    4140 
    4241/** Abstract class implementing a scene traversal for rendering. 
     
    4544{ 
    4645public: 
    47         enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, NUM_RENDERMODES}; 
     46         
     47        enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_RENDERMODES}; 
    4848 
    4949        RenderTraverser(); 
     
    5252        //! Renders the scene with the specified method 
    5353        /** 
    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 
    5859        */ 
    59         virtual void Render() = 0; 
     60        void RenderScene(); 
    6061        /** Sets the scene hierarchy. 
    6162        */ 
     
    7980        */ 
    8081        void SetRenderState(RenderState *state); 
    81          
    82         void RenderFrustum(); 
    8382 
     83        void SetUseRenderQueue(bool useRenderQueue); 
    8484        const TraversalStatistics &GetStats() const { return mStats; } 
    85  
    86         void InitFrame(Camera *camera, int currentFrameId); 
    8785 
    8886protected: 
    8987 
    90         /** does some important initializations 
     88        /** This is the actual rendering algorithm. It must be implemented by all 
     89                the subclasses. 
    9190        */ 
    92         void Preprocess(); 
     91        virtual void Traverse() = 0; 
    9392        /** Hierarchy traversal 
    9493        */ 
    9594        void TraverseNode(BvhNode *node); 
    96         /** Visibility is pulled up from visibility of children  
    97         */ 
    98         void PullUpVisibility(BvhNode *node); 
    9995        /** Issues occlusion query for specified node 
    10096        */ 
    10197        OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); 
    102         /** Resets occlusion queries after a traversal 
    103         */ 
    104         void DelQueries(); 
    105         /** Does view frustum culling. returns intersect (if intersects view plane) 
    106         */ 
    107         bool InsideViewFrustum(BvhNode *node, bool &intersects); 
    10898        /** switches to normal render mode 
    10999        */ 
     
    112102        */ 
    113103        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        */ 
    117109        void EnqueueNode(BvhNode *node); 
    118  
    119         void RenderBox(const AxisAlignedBox3 &box); 
    120110 
    121111 
     
    128118        /// the root of the scene hierarchy 
    129119        Bvh *mBvh; 
    130         /// use a priority queue rather than a renderstack 
     120        /// the priority queue used for front to back traversal 
    131121        TraversalQueue mDistanceQueue;  
    132          
     122        /// the current frame id 
    133123        int mFrameId; 
    134         int mVisibilityThreshold; 
    135124 
    136125        bool mIsQueryMode; 
    137          
    138         //bool mIntersects; 
    139         bool mUseOptimization; 
    140126 
    141127        RenderState *mRenderState; 
     
    144130 
    145131        TraversalStatistics mStats; 
     132 
     133        QueryQueue mQueryQueue; 
     134 
     135        int mVisibilityThreshold; 
     136         
     137        bool mUseOptimization; 
     138 
     139        RenderQueue mRenderQueue; 
     140 
     141        bool mUseRenderQueue; 
    146142}; 
     143 
     144 
     145inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const 
     146{  
     147        return mBvh->GetDistance(node) < mCamera->GetNear(); 
     148} 
     149 
    147150 
    148151} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/SceneEntity.h

    r2764 r2767  
    5757        */ 
    5858        int GetLastRendered() const; 
    59          
     59 
     60        Material *GetMaterial() const  { return mMaterial; } 
    6061 
    6162protected: 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp

    r2765 r2767  
    1010 
    1111 
    12 StopAndWaitTraverser::StopAndWaitTraverser(): RenderTraverser()  
     12StopAndWaitTraverser::StopAndWaitTraverser() 
    1313{ 
    1414} 
    1515 
    1616 
    17 StopAndWaitTraverser::~StopAndWaitTraverser() 
    18 { 
    19         //DelQueries(); 
    20 } 
    21  
    22  
    23 void StopAndWaitTraverser::Render() 
     17void StopAndWaitTraverser::Traverse() 
    2418{ 
    2519        while (!mDistanceQueue.empty()) 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h

    r2763 r2767  
    1313{ 
    1414public: 
     15 
    1516        StopAndWaitTraverser(); 
    16         ~StopAndWaitTraverser(); 
    1717 
    18         /** Renders the scene with the specified method 
     18        //~StopAndWaitTraverser(); 
     19 
     20protected: 
     21        /** Traverses and renders the scene with the specified method 
    1922        */ 
    20         virtual void Render(); 
     23        virtual void Traverse(); 
     24 
    2125}; 
    2226 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp

    r2764 r2767  
    6161        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    6262        //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
     63        //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); 
    6364        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    6465        //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj

    r2764 r2767  
    358358                                </File> 
    359359                                <File 
     360                                        RelativePath=".\RenderQueue.h" 
     361                                        > 
     362                                </File> 
     363                                <File 
    360364                                        RelativePath=".\SceneEntity.h" 
    361365                                        > 
     
    363367                                <File 
    364368                                        RelativePath=".\Texture.h" 
     369                                        > 
     370                                </File> 
     371                                <File 
     372                                        RelativePath=".\Visualization.h" 
    365373                                        > 
    366374                                </File> 
     
    396404                                </File> 
    397405                                <File 
     406                                        RelativePath=".\RenderQueue.cpp" 
     407                                        > 
     408                                </File> 
     409                                <File 
    398410                                        RelativePath=".\SceneEntity.cpp" 
    399411                                        > 
     
    401413                                <File 
    402414                                        RelativePath=".\Texture.cpp" 
     415                                        > 
     416                                </File> 
     417                                <File 
     418                                        RelativePath=".\Visualization.cpp" 
    403419                                        > 
    404420                                </File> 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2765 r2767  
    1717#include "StopAndWaitTraverser.h" 
    1818#include "CHCTraverser.h" 
     19#include "CHCPlusPlusTraverser.h" 
     20#include "Visualization.h" 
     21 
    1922 
    2023 
     
    2730SceneEntityContainer sceneEntities; 
    2831// traverses and renders the hierarchy 
    29 RenderTraverser *traverser; 
     32RenderTraverser *traverser = NULL; 
    3033/// the hierarchy 
    31 Bvh *bvh; 
     34Bvh *bvh = NULL; 
    3235/// the scene camera 
    33 Camera *camera; 
    34 /// the scene bounding box 
    35 AxisAlignedBox3 sceneBox; 
     36Camera *camera = NULL; 
     37/// the visualization 
     38Visualization *visualization = NULL; 
    3639/// the current render state 
    3740RenderState state; 
     
    4346float nearDist = 0.1f;  
    4447 
     48const float keyForwardMotion = 1.0f; 
     49const float keyRotation = 0.2f; 
     50 
     51bool useRenderQueue = false; 
     52 
    4553int winWidth = 1024; 
    4654int winHeight = 768; 
     
    5563 
    5664 
    57 int currentFrame = -1; 
    58  
    5965// visualisation view matrix 
    6066Matrix4x4 visView;  
     
    6369int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0; 
    6470 
    65 const int renderTimeSize = 100; 
    66 long renderTimes[renderTimeSize]; 
    67 int renderTimesIdx = 0; 
    68 int renderTimesValid = 0; 
    69  
    7071bool useOptimization = true; 
    7172 
    72  
    73 Vector3 amb[2]; 
    74 Vector3 dif[2]; 
    75 Vector3 spec[2]; 
    7673 
    7774void InitExtensions(); 
     
    10097void setupVisView(void); 
    10198long calcRenderTime(void); 
    102 void resetTimer(void); 
    10399void CalcDecimalPoint(std::string &str, int d); 
    104100void ResetTraverser(); 
     
    148144        //bvh = bvhLoader.Load("house_test.bvh", sceneEntities); 
    149145 
    150         sceneBox = bvh->GetBox(); 
    151  
    152146        ResetTraverser(); 
    153147 
    154148        //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)); 
    160153 
    161154        glutMainLoop(); 
     
    170163void InitGLstate(void)  
    171164{ 
    172         glClearColor(0.5f, 0.5f, 0.8f, 0.0); 
     165        glClearColor(0.5f, 0.5f, 0.8f, 0.0f); 
    173166         
    174167        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     
    185178        glMaterialf(GL_FRONT, GL_SHININESS, 64); 
    186179        glEnable(GL_NORMALIZE); 
    187                          
     180                 
     181        //glEnable(GL_ALPHA_TEST); 
     182        //glAlphaFunc(GL_GEQUAL, 0.01); 
     183 
     184        glDisable(GL_ALPHA_TEST); 
     185 
    188186        glFrontFace(GL_CCW); 
    189187        glCullFace(GL_BACK); 
     
    288286                traverser = new CHCTraverser(); 
    289287                break; 
     288        case RenderTraverser::CHCPLUSPLUS: 
     289                traverser = new CHCPlusPlusTraverser(); 
     290                break; 
     291         
    290292        default: 
    291293                traverser = new FrustumCullingTraverser(); 
    292294        } 
    293295 
     296        traverser->SetCamera(camera); 
    294297        traverser->SetHierarchy(bvh); 
    295298        traverser->SetRenderState(&state); 
     
    302305        glEnable(GL_LIGHT0); 
    303306        glEnable(GL_LIGHT1); 
     307 
    304308        //glDisable(GL_LIGHT1); 
    305309        //glDisable(GL_LIGHTING); 
     
    349353        glLoadIdentity(); 
    350354 
    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())); 
    352356 
    353357        glMatrixMode(GL_MODELVIEW); 
     
    357361        glLightfv(GL_LIGHT0, GL_POSITION, position); 
    358362 
    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}; 
    361364        glLightfv(GL_LIGHT1, GL_POSITION, position1); 
    362365} 
     
    365368void display(void)  
    366369{ 
    367         ++ currentFrame; 
    368  
    369370        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    370371 
     
    372373        SetupEyeView(); 
    373374 
    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         
    405379        //if(visMode) displayVisualization(); 
    406380         
    407381        DisplayStats(); 
     382 
    408383        glutSwapBuffers(); 
    409384} 
     
    413388void keyboard(const unsigned char c, const int x, const int y)  
    414389{ 
     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         
    415394        switch(c)  
    416395        { 
     
    420399        case 32: //space 
    421400                renderMode = (renderMode + 1) % RenderTraverser::NUM_RENDERMODES; 
    422                 resetTimer(); 
    423401                ResetTraverser(); 
    424402                break; 
     
    432410                //HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 
    433411                break; 
    434         case 's': 
    435         case 'S': 
     412        case 'O': 
     413        case 'o': 
    436414                showStatistics = !showStatistics; 
    437415                break; 
     
    449427                visMode = !visMode; 
    450428                break; 
    451          
    452429        case '2': 
    453430                visZoomFactor += 0.1;    
     
    460437                setupVisView(); 
    461438                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                }        
    462453        case 'g': 
    463454        case 'G': 
    464455                useOptimization = !useOptimization; 
    465456                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                } 
    466500        default: 
    467501                return; 
     
    475509{ 
    476510        // 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); 
    478512         
    479513        switch(c)  
     
    482516                showHelp = !showHelp; 
    483517                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; 
    508518        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                } 
    510526                break; 
    511527        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                } 
    513535                break; 
    514536        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                } 
    516542                break; 
    517543        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                } 
    519549                break; 
    520550        default: 
     
    525555        glutPostRedisplay(); 
    526556} 
     557 
    527558#pragma warning( default : 4100 ) 
    528559 
     
    542573        glLoadIdentity(); 
    543574 
    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())); 
    545576        glMatrixMode(GL_MODELVIEW); 
    546577 
     
    587618 
    588619        // don't move in the vertical direction 
    589         //Vector3 horView(viewDir[0], 0, viewDir[2]); 
    590620        Vector3 horView(viewDir[0], viewDir[1], 0); 
    591621         
     
    593623 
    594624        // rotate view vector 
    595         //Matrix4x4 rot = RotationYMatrix(eyeXAngle); 
    596625        Matrix4x4 rot = RotationZMatrix(eyeXAngle); 
    597626        viewDir = rot * viewDir; 
     
    609638 
    610639 
    611 /**     rotation for left/right mouse drag 
    612         motion for up/down mouse drag 
     640/**     rotation for left / right mouse drag 
     641        motion for up / down mouse drag 
    613642*/ 
    614643void rightMotion(int x, int y)  
     
    707736void output(const int x, const int y, const char *string)  
    708737{ 
    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); 
    714743                 
    715                 for (i = 0; i < len; i++)  
     744                for (i = 0; i < len; ++ i)  
    716745                { 
    717746                        glutBitmapCharacter(GLUT_BITMAP_8_BY_13, string[i]); 
     
    719748        } 
    720749} 
     750 
    721751 
    722752// displays the visualisation of the kd tree node culling 
     
    738768        glClear(GL_DEPTH_BUFFER_BIT); 
    739769 
     770        //////////// 
    740771        // --- visualization of the occlusion culling 
    741         /*HierarchyNode::SetRenderBoundingVolume(true); 
    742         traverser.RenderVisualization(); 
    743         HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 
    744 */ 
     772        visualization->Render(); 
     773         
    745774        glPopMatrix(); 
     775         
    746776        glViewport(0, 0, winWidth, winHeight); 
    747777} 
     778 
    748779 
    749780/** Sets up view matrix in order to get a good position  
     
    752783void setupVisView() 
    753784{ 
    754         const Vector3 up(0.0, 1.0, 0.0); 
     785        const Vector3 up(0.0, 0.0, 1.0); 
    755786         
    756787        Vector3 visPos(24, 23, -6); 
     
    760791        visPos[2] *= visZoomFactor; 
    761792 
    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); 
    788794} 
    789795 
     
    796802 
    797803        DEL_PTR(bvh); 
     804        DEL_PTR(visualization); 
    798805} 
    799806 
     
    829836{ 
    830837        char *msg[] = {"Frustum Culling", "Stop and Wait", 
    831                                     "Coherent Culling"}; 
     838                                    "CHC", "CHC ++"}; 
    832839 
    833840        char msg2[200]; 
     
    843850         
    844851        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 
    846858        if (renderTime) fps /= (float)renderTime; 
    847859 
     
    868880        else 
    869881        { 
    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]); 
    872884 
    873885                if(showStatistics) 
Note: See TracChangeset for help on using the changeset viewer.