Changeset 2761


Ignore:
Timestamp:
06/15/08 00:27:36 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp

    r2760 r2761  
    8181mIndicesPtr(-1), 
    8282mIndices(NULL), 
    83 mId(0) 
     83mId(0), 
     84mIsMaxDepthForVirtualLeaf(false), 
     85mIsVirtualLeaf(false) 
     86{ 
     87} 
     88 
     89 
     90BvhNode::~BvhNode()  
    8491{ 
    8592} 
     
    9198 
    9299        mLastRenderedFrame = -999; 
    93 } 
    94  
    95  
    96 BvhNode::~BvhNode()  
    97 { 
    98100} 
    99101 
     
    838840 
    839841 
    840 } 
     842void Bvh::CollectVirtualLeaves(BvhNode *node, BvhNodeContainer &leaves) 
     843{ 
     844        stack<BvhNode *> tStack; 
     845        tStack.push(node); 
     846 
     847        while (!tStack.empty()) 
     848        { 
     849                BvhNode *node = tStack.top(); 
     850                tStack.pop(); 
     851 
     852                if (node->mIsVirtualLeaf) 
     853                { 
     854                        leaves.push_back(node); 
     855                } 
     856                else if (!node->IsLeaf()) 
     857                { 
     858                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     859 
     860                        tStack.push(interior->mFront); 
     861                        tStack.push(interior->mBack); 
     862                } 
     863        } 
     864} 
     865 
     866 
     867void Bvh::SetVirtualLeaves(int numTriangles)  
     868{ 
     869        // first invalidate old leaves 
     870        BvhNodeContainer leaves; 
     871 
     872        CollectVirtualLeaves(mRoot, leaves); 
     873 
     874        BvhNodeContainer::const_iterator bit, bit_end = leaves.end(); 
     875 
     876        for (bit = leaves.begin(); bit != bit_end; ++ bit) 
     877        { 
     878                (*bit)->mIsVirtualLeaf = false; 
     879        } 
     880 
     881        // assign new virtual leaves based on specified number of triangles per leaf 
     882        std::stack<BvhNode *> nodeStack; 
     883        nodeStack.push(mRoot); 
     884 
     885        while (!nodeStack.empty())  
     886        { 
     887                BvhNode *node = nodeStack.top(); 
     888                nodeStack.pop(); 
     889 
     890                if (node->IsLeaf())  
     891                { 
     892                        BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 
     893                        leaf->mIsVirtualLeaf = true; 
     894                }  
     895                else  
     896                { 
     897                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     898 
     899                        BvhNode *f = interior->mFront; 
     900                        BvhNode *b = interior->mBack; 
     901 
     902                        if (node->mIsMaxDepthForVirtualLeaf || (CountTriangles(node) <= numTriangles)) 
     903                        { 
     904                                 node->mIsVirtualLeaf = true; 
     905                        } 
     906                        else 
     907                        { 
     908                                nodeStack.push(interior->mBack); 
     909                                nodeStack.push(interior->mFront); 
     910                        } 
     911                } 
     912        } 
     913} 
     914 
     915 
     916void Bvh::PostProcess()  
     917{ 
     918        std::stack<BvhNode *> nodeStack; 
     919        nodeStack.push(mRoot); 
     920 
     921        while (!nodeStack.empty())  
     922        { 
     923                BvhNode *node = nodeStack.top(); 
     924                nodeStack.pop(); 
     925 
     926                if (node->IsLeaf())  
     927                { 
     928                        node->mIsMaxDepthForVirtualLeaf = true; 
     929                }  
     930                else  
     931                { 
     932                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     933 
     934                        BvhNode *f = interior->mFront; 
     935                        BvhNode *b = interior->mBack; 
     936 
     937                        // point reached where we cannot subdivide further on object level 
     938                        if ((f->mFirst == b->mFirst) && (f->mLast == b->mLast)) 
     939                        { 
     940                                node->mIsMaxDepthForVirtualLeaf = true; 
     941                        } 
     942                        else 
     943                        { 
     944                                nodeStack.push(f); 
     945                                nodeStack.push(b); 
     946                        } 
     947                } 
     948        } 
     949} 
     950 
     951 
     952} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h

    r2760 r2761  
    7979        virtual void ResetVisibility(); 
    8080 
    81         virtual bool IsLeaf() = 0; //{ return BVH_NODE; } 
     81        virtual bool IsLeaf() const = 0; 
     82 
     83        bool IsVirtualLeaf() const { return mIsVirtualLeaf; } 
    8284 
    8385 
     
    211213        /// the bounding box 
    212214        AxisAlignedBox3 mBox; 
     215        /// if this node is a virtual leaf 
     216        bool mIsVirtualLeaf; 
     217        /** This marks the maximal depth where a virtual leaf can be defined. 
     218            From this point on it makes no sense to traverse down further, as all 
     219                nodes below contain the same geometry, so no further refinement of visibility  
     220                can be archieved. All nodes below this point can merely used to define the  
     221                tighter bounds. 
     222        */ 
     223        bool mIsMaxDepthForVirtualLeaf; 
    213224}; 
    214225 
     
    335346        BvhInterior(BvhNode *parent): mBack(NULL), mFront(NULL), BvhNode(parent) 
    336347        {} 
    337         virtual bool IsLeaf() {return false;} 
     348        virtual bool IsLeaf() const { return false; } 
    338349        /** Back child. 
    339350        */ 
    340         inline BvhNode *GetBack() { return mBack;} 
     351        inline BvhNode *GetBack() { return mBack; } 
    341352        /** Front child. 
    342353        */ 
    343         inline BvhNode *GetFront() { return mFront;} 
     354        inline BvhNode *GetFront() { return mFront; } 
    344355        /** recursivly delete tree. 
    345356        */ 
     
    375386        ~BvhLeaf(); 
    376387 
    377         virtual bool IsLeaf() { return true; } 
     388        virtual bool IsLeaf() const { return true; } 
    378389}; 
    379390 
     
    450461        void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 
    451462        void CollectLeaves(BvhNode *node, BvhLeafContainer &leaves); 
     463        /** Collect only the virtual leaves. 
     464        */ 
     465        void CollectVirtualLeaves(BvhNode *node, BvhNodeContainer &leaves); 
    452466 
    453467 
     
    511525        */ 
    512526        void ComputeIds(); 
    513  
     527        /** Assign virtual leaves based on specified number of triangles per leaf. 
     528        */ 
     529        void SetVirtualLeaves(int numTriangles); 
    514530 
    515531        //////// 
     
    576592        /** Does some postprocessing on the nodes. 
    577593        */ 
    578         //void PostProcess(); 
     594        void PostProcess(); 
    579595        /** Helper method that updates the number of leaves in the subtree under 
    580596                this node. 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp

    r2760 r2761  
    6262                                         const SceneEntityContainer &entities) 
    6363{ 
    64         // export binary version of mesh 
    65         queue<BvhNode *> tStack; 
     64        queue<BvhNode *> tQueue; 
    6665        ifstream stream(filename.c_str(), ifstream::binary); 
    6766 
     
    7372        bvh->mRoot = LoadNextNode(stream, NULL); 
    7473 
    75         tStack.push(bvh->mRoot); 
     74        tQueue.push(bvh->mRoot); 
    7675        bvh->mNumNodes = 1; 
    7776 
    78         while(!tStack.empty()) 
     77        while(!tQueue.empty()) 
    7978        { 
    80                 BvhNode *node = tStack.front(); 
    81                 tStack.pop(); 
     79                BvhNode *node = tQueue.front(); 
     80                tQueue.pop(); 
    8281 
    8382                if (!node->IsLeaf()) 
     
    8786                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
    8887 
    89             BvhNode *front = LoadNextNode(stream, interior); 
     88                        BvhNode *front = LoadNextNode(stream, interior); 
    9089                        BvhNode *back = LoadNextNode(stream, interior); 
    91          
     90 
    9291                        interior->mFront = front; 
    9392                        interior->mBack = back; 
     
    9695                        back->mDepth = interior->mDepth + 1; 
    9796 
    98                         tStack.push(front);                      
    99                         tStack.push(back); 
     97                        tQueue.push(front);                      
     98                        tQueue.push(back); 
    10099                } 
    101100        } 
     
    104103 
    105104        /////////// 
    106         //-- post process 
     105        //-- post process nodes 
     106 
     107        bvh->PostProcess(); 
     108        // set virtual leaves for 500 triangles 
     109        bvh->SetVirtualLeaves(500); 
    107110 
    108111        bvh->UpdateNumLeaves(bvh->mRoot); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp

    r2760 r2761  
    1616        mDistanceQueue.push(mBvh->GetRoot()); 
    1717 
     18        int traversed = 0; 
    1819        while (!mDistanceQueue.empty()) 
    1920        { 
     
    2728                //bool intersects; 
    2829         
    29                 if (1)//mBvh->InsideViewFrustum(node, intersects)) 
     30                if (mBvh->IsWithinViewFrustum(node)) 
    3031                { 
    3132                        // update node's visited flag => needed for rendering 
     
    3334                        //node->SetLastVisited(mFrameID); 
    3435                        //node->SetVisible(true); 
    35  
     36                        ++ traversed; 
    3637                        TraverseNode(node); 
    3738                } 
     
    4142                } 
    4243        } 
     44 
     45        std::cout << "traversed: " << traversed << std::endl; 
    4346} 
    4447 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2760 r2761  
    6666void RenderTraverser::TraverseNode(BvhNode *node) 
    6767{ 
    68         if (node->IsLeaf()) 
     68        if (node->IsVirtualLeaf()||node->IsLeaf()) 
    6969        { 
    7070                //mNumRenderedGeometry += 
Note: See TracChangeset for help on using the changeset viewer.