Ignore:
Timestamp:
11/01/06 23:20:53 (18 years ago)
Author:
mattausch
Message:

worked on full render cost evaluation
warning: some change sin render cost evaluation for pvs which could have bugs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1706 r1707  
    2121#include "OspTree.h" 
    2222#include "BvHierarchy.h" 
     23#include "ViewCell.h" 
    2324 
    2425 
     
    16831684        // reinstall old bv refs 
    16841685        vector<BvhLeaf *> leaves; 
    1685         mBvHierarchy->CollectLeaves(leaves); 
     1686        mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 
    16861687        vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 
    16871688 
     
    17881789{ 
    17891790public: 
    1790         enum {VSP_NODE, BVH_NODE}; 
     1791        enum {VSP_NODE, BVH_NODE, VIEW_CELL}; 
    17911792 
    17921793        virtual float GetMergeCost() const = 0; 
     
    18501851 
    18511852 
     1853class ViewCellWrapper: public HierarchyNodeWrapper 
     1854{ 
     1855public: 
     1856 
     1857        ViewCellWrapper(ViewCell *vc): mViewCell(vc) {} 
     1858         
     1859        int Type()  const { return VIEW_CELL; } 
     1860 
     1861        float GetMergeCost() const { return mViewCell->GetMergeCost(); }; 
     1862 
     1863        bool IsLeaf() const { return mViewCell->IsLeaf(); } 
     1864 
     1865        void PushChildren(HierarchyNodeQueue &tQueue) 
     1866        { 
     1867                if (!mViewCell->IsLeaf()) 
     1868                { 
     1869                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mViewCell); 
     1870 
     1871                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1872 
     1873                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1874                        { 
     1875                                tQueue.push(new ViewCellWrapper(*it)); 
     1876                        } 
     1877                } 
     1878        } 
     1879 
     1880        ViewCell *mViewCell; 
     1881}; 
     1882 
     1883 
    18521884void HierarchyManager::CollectBestSet(const int maxSplits, 
    18531885                                                                          const float maxMemoryCost, 
    1854                                                                           vector<VspNode *> &vspNodes, 
     1886                                //                                        vector<VspNode *> &vspNodes, 
     1887                                                                          ViewCellContainer &viewCells, 
    18551888                                                                          vector<BvhNode *> &bvhNodes) 
    18561889{ 
    18571890        HierarchyNodeQueue tqueue; 
    1858         tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 
     1891        //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 
     1892        tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 
    18591893        tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 
    18601894         
     
    18691903                // because of the priority queue, this will be the optimal set of v 
    18701904                if (nodeWrapper->IsLeaf() ||  
    1871                         ((vspNodes.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 
     1905                        ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 
    18721906                        (memCost > maxMemoryCost) 
    18731907                        ) 
     
    18751909                        if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 
    18761910                        { 
    1877                                 VspNodeWrapper *vspNodeWrapper = dynamic_cast<VspNodeWrapper *>(nodeWrapper); 
    1878                                 vspNodes.push_back(vspNodeWrapper->mNode); 
     1911                                ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 
     1912                                viewCells.push_back(viewCellWrapper->mViewCell); 
    18791913                        } 
    18801914                        else 
     
    19001934                                                                                 int &pvsEntries) 
    19011935{ 
     1936        //vector<VspNode *> vspNodes; 
     1937        ViewCellContainer viewCells; 
     1938        vector<BvhNode *> bvhNodes; 
     1939 
     1940    CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 
     1941 
     1942        vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 
     1943         
     1944        for (bit = bvhNodes.begin(); bit != bit_end; ++ bit) 
     1945        { 
     1946                mBvHierarchy->SetActive(*bit); 
     1947        } 
     1948 
     1949        //vector<VspNode *>::const_iterator vit, vit_end = vspNodes.end(); 
     1950 
     1951        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     1952 
     1953        int numEntries = 0; 
     1954        float pvsCost = 0.0f; 
     1955 
     1956        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     1957        { 
     1958                ViewCell *vc = *vit; 
     1959                ObjectPvs pvs; 
     1960                mVspTree->mViewCellsTree->GetPvs(vc, pvs); 
     1961 
     1962                BvhNode::NewMail(); 
     1963 
     1964                // hack: should not be done here 
     1965                ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     1966 
     1967                for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
     1968                { 
     1969                        BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 
     1970                        BvhLeaf *leaf = intersect->GetItem(); 
     1971                        BvhNode *activeNode = leaf->GetActiveNode(); 
     1972 
     1973                        if (!activeNode->Mailed()) 
     1974                        { 
     1975                                activeNode->Mail(); 
     1976 
     1977                                ++ numEntries; 
     1978                                pvsCost += mBvHierarchy->EvalAbsCost(leaf->mObjects); 
     1979                        } 
     1980                } 
     1981        } 
     1982 
    19021983        /*TraversalQueue tqueue; 
    19031984        tqueue.push(mRoot); 
Note: See TracChangeset for help on using the changeset viewer.