Changeset 1709


Ignore:
Timestamp:
11/02/06 19:09:30 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
7 edited

Legend:

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

    r1707 r1709  
    5252mTimeStamp(0) 
    5353{ 
     54         
    5455} 
    5556 
     
    103104 
    104105BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox): 
    105 BvhNode(bbox), mSubdivisionCandidate(NULL) 
    106 { 
     106BvhNode(bbox),  
     107mSubdivisionCandidate(NULL) 
     108{ 
     109        mActiveNode = this; 
    107110} 
    108111 
     
    111114BvhNode(bbox, parent) 
    112115{ 
     116        mActiveNode = this; 
    113117} 
    114118 
     
    120124{ 
    121125        mObjects.reserve(numObjects); 
     126        mActiveNode = this; 
    122127} 
    123128 
     
    13991404void BvHierarchy::PrintSubdivisionStats(const SubdivisionCandidate &sc) 
    14001405{ 
    1401         const float costDecr =  
    1402                 sc.GetRenderCostDecrease();// / mHierarchyManager->GetViewSpaceBox().GetVolume();        
     1406        const float costDecr = sc.GetRenderCostDecrease();       
    14031407 
    14041408        mSubdivisionStats  
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1707 r1709  
    16191619 
    16201620 
    1621 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays,                                                                                                                                               
    1622                                                                                    const ObjectContainer &objects, 
    1623                                                                                    const string &filename) 
    1624 { 
    1625         VspTree *oldVspTree = mVspTree; 
    1626         ViewCellsManager *vm = mVspTree->mViewCellsManager; 
    1627         BvHierarchy *oldHierarchy = mBvHierarchy; 
    1628  
    1629         mBvHierarchy = new BvHierarchy(); 
    1630         mBvHierarchy->mHierarchyManager = this; 
    1631         mBvHierarchy->mViewCellsManager = vm; 
    1632  
    1633         mVspTree = new VspTree(); 
    1634         mVspTree->mHierarchyManager = this; 
    1635         mVspTree->mViewCellsManager = vm; 
    1636  
    1637         // create first nodes 
    1638         mVspTree->Initialise(sampleRays, &oldVspTree->mBoundingBox); 
    1639         InitialiseObjectSpaceSubdivision(objects); 
    1640  
    1641         const long startTime = GetTime(); 
    1642         cout << "Constructing evaluation hierarchies ... \n"; 
    1643          
    1644         ofstream stats; 
    1645         stats.open(filename.c_str()); 
    1646         SplitQueue tQueue; 
    1647  
    1648         BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 
    1649         VspNode *oldVspRoot = oldVspTree->GetRoot(); 
    1650  
    1651         RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    1652          
    1653         SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 
    1654         SubdivisionCandidate *firstBvh = mBvHierarchy->PrepareConstruction(sampleRays, objects); 
    1655  
    1656     firstVsp->mEvaluationHack = oldVspRoot; 
    1657         firstBvh->mEvaluationHack = oldBvhRoot; 
    1658  
    1659         firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 
    1660         firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp); 
    1661  
    1662         tQueue.Push(firstVsp); 
    1663         tQueue.Push(firstBvh); 
    1664  
    1665         ExportStats(stats, tQueue, objects); 
    1666  
    1667         cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    1668         RemoveRayRefs(objects); 
    1669  
    1670         // view cells needed only for evaluation 
     1621class HierarchyNodeWrapper; 
     1622 
     1623 
     1624template <typename T> class myless 
     1625{ 
     1626public: 
     1627        bool operator() (T v1, T v2) const 
     1628        { 
     1629                return (v1->GetMergeCost() < v2->GetMergeCost()); 
     1630        } 
     1631}; 
     1632 
     1633 
     1634typedef priority_queue<HierarchyNodeWrapper *, vector<HierarchyNodeWrapper *>,  
     1635                                           myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 
     1636 
     1637class HierarchyNodeWrapper 
     1638{ 
     1639public: 
     1640        enum {VSP_NODE, BVH_NODE, VIEW_CELL}; 
     1641 
     1642        virtual float GetMergeCost() const = 0; 
     1643        virtual int Type() const  = 0; 
     1644        virtual bool IsLeaf() const = 0; 
     1645 
     1646        virtual void PushChildren(HierarchyNodeQueue &tQueue) = 0; 
     1647}; 
     1648 
     1649 
     1650class VspNodeWrapper: public HierarchyNodeWrapper 
     1651{ 
     1652public: 
     1653        VspNodeWrapper(VspNode *node): mNode(node) {} 
     1654 
     1655        int Type() const { return VSP_NODE; } 
     1656 
     1657        float GetMergeCost() const { return (float) -mNode->mTimeStamp; }; 
     1658 
     1659        bool IsLeaf() const { return mNode->IsLeaf(); } 
     1660 
     1661        void PushChildren(HierarchyNodeQueue &tQueue) 
     1662        { 
     1663                if (!mNode->IsLeaf()) 
     1664                { 
     1665                        VspInterior *interior = dynamic_cast<VspInterior *>(mNode); 
     1666 
     1667                        tQueue.push(new VspNodeWrapper(interior->GetFront())); 
     1668                        tQueue.push(new VspNodeWrapper(interior->GetBack())); 
     1669                } 
     1670        } 
     1671 
     1672        VspNode *mNode; 
     1673}; 
     1674 
     1675 
     1676class BvhNodeWrapper: public HierarchyNodeWrapper 
     1677{ 
     1678public: 
     1679        BvhNodeWrapper(BvhNode *node): mNode(node) {} 
     1680         
     1681        int Type()  const { return BVH_NODE; } 
     1682 
     1683        float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 
     1684 
     1685        bool IsLeaf() const { return mNode->IsLeaf(); } 
     1686 
     1687        void PushChildren(HierarchyNodeQueue &tQueue) 
     1688        { 
     1689                if (!mNode->IsLeaf()) 
     1690                { 
     1691                        BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode); 
     1692 
     1693                        tQueue.push(new BvhNodeWrapper(interior->GetFront())); 
     1694                        tQueue.push(new BvhNodeWrapper(interior->GetBack())); 
     1695                } 
     1696        } 
     1697 
     1698        BvhNode *mNode; 
     1699}; 
     1700 
     1701 
     1702class ViewCellWrapper: public HierarchyNodeWrapper 
     1703{ 
     1704public: 
     1705 
     1706        ViewCellWrapper(ViewCell *vc): mViewCell(vc) {} 
     1707         
     1708        int Type()  const { return VIEW_CELL; } 
     1709 
     1710        float GetMergeCost() const { return mViewCell->GetMergeCost(); }; 
     1711 
     1712        bool IsLeaf() const { return mViewCell->IsLeaf(); } 
     1713 
     1714        void PushChildren(HierarchyNodeQueue &tQueue) 
     1715        { 
     1716                if (!mViewCell->IsLeaf()) 
     1717                { 
     1718                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mViewCell); 
     1719 
     1720                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1721 
     1722                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
     1723                        { 
     1724                                tQueue.push(new ViewCellWrapper(*it)); 
     1725                        } 
     1726                } 
     1727        } 
     1728 
     1729        ViewCell *mViewCell; 
     1730}; 
     1731 
     1732 
     1733void HierarchyManager::CollectBestSet(const int maxSplits, 
     1734                                                                          const float maxMemoryCost, 
     1735                                                                          ViewCellContainer &viewCells, 
     1736                                                                          vector<BvhNode *> &bvhNodes) 
     1737{ 
     1738        HierarchyNodeQueue tqueue; 
     1739        //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 
     1740        tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 
     1741        tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 
     1742         
     1743        float memCost = 0; 
     1744 
     1745        while (!tqueue.empty()) 
     1746        { 
     1747                HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 
     1748                tqueue.pop(); 
     1749 
     1750                // save the view cells if it is a leaf or if enough view cells have already been traversed 
     1751                // because of the priority queue, this will be the optimal set of v 
     1752                if (nodeWrapper->IsLeaf() ||  
     1753                        ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 
     1754                        (memCost > maxMemoryCost) 
     1755                        ) 
     1756                { 
     1757                        if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 
     1758                        { 
     1759                                ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 
     1760                                viewCells.push_back(viewCellWrapper->mViewCell); 
     1761                        } 
     1762                        else 
     1763                        { 
     1764                                BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 
     1765                                bvhNodes.push_back(bvhNodeWrapper->mNode); 
     1766                        } 
     1767                } 
     1768                else  
     1769                {        
     1770                        nodeWrapper->PushChildren(tqueue); 
     1771                } 
     1772 
     1773                delete nodeWrapper; 
     1774        } 
     1775} 
     1776 
     1777 
     1778bool HierarchyManager::ExtractStatistics(const int maxSplits, 
     1779                                                                                 const float maxMemoryCost, 
     1780                                                                                 float &renderCost, 
     1781                                                                                 float &memory, 
     1782                                                                                 int &pvsEntries) 
     1783{ 
    16711784        ViewCellContainer viewCells; 
    1672         mVspTree->CollectViewCells(viewCells, false); 
    1673          
    1674         // helper trees can be destroyed 
    1675         DEL_PTR(mVspTree); 
    1676         DEL_PTR(mBvHierarchy); 
    1677  
    1678         CLEAR_CONTAINER(viewCells); 
    1679  
    1680         // reset hierarchies 
    1681         mVspTree = oldVspTree; 
    1682         mBvHierarchy = oldHierarchy; 
    1683  
    1684         // reinstall old bv refs 
    1685         vector<BvhLeaf *> leaves; 
    1686         mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 
    1687         vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 
    1688  
    1689         for (bit = leaves.begin(); bit != bit_end; ++ bit) 
    1690         { 
    1691                 mBvHierarchy->AssociateObjectsWithLeaf(*bit); 
    1692         } 
     1785        vector<BvhNode *> bvhNodes; 
     1786 
     1787        // collect best set of view cells for this #splits 
     1788    CollectBestSet(maxSplits, maxMemoryCost, viewCells, bvhNodes); 
     1789 
     1790        vector<BvhNode *>::const_iterator bit, bit_end = bvhNodes.end(); 
     1791         
     1792        for (bit = bvhNodes.begin(); bit != bit_end; ++ bit) 
     1793        { 
     1794                mBvHierarchy->SetActive(*bit); 
     1795        } 
     1796 
     1797        ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 
     1798 
     1799        int numEntries = 0; 
     1800        float pvsCost = 0.0f; 
     1801 
     1802        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
     1803        { 
     1804                ViewCell *vc = *vit; 
     1805                ObjectPvs pvs; 
     1806                mVspTree->mViewCellsTree->GetPvs(vc, pvs); 
     1807 
     1808                BvhNode::NewMail(); 
     1809 
     1810                // hack: should not be done here 
     1811                ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end(); 
     1812 
     1813                for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit) 
     1814                { 
     1815                        BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>((*oit).first); 
     1816                        BvhLeaf *leaf = intersect->GetItem(); 
     1817                        BvhNode *activeNode = leaf->GetActiveNode(); 
     1818 
     1819                        if (!activeNode->Mailed()) 
     1820                        { 
     1821                                activeNode->Mail(); 
     1822 
     1823                                ++ numEntries; 
     1824                                pvsCost += mBvHierarchy->EvalAbsCost(leaf->mObjects); 
     1825                        } 
     1826                } 
     1827        } 
     1828 
     1829        return (viewCells.size() + bvhNodes.size() < mHierarchyStats.Leaves()); 
    16931830} 
    16941831 
     
    17071844        ///////////// 
    17081845        //-- first view cell 
     1846 
    17091847        UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, true); 
    17101848 
     
    17701908 
    17711909 
    1772  
    1773 class HierarchyNodeWrapper; 
    1774  
    1775  
    1776 template <typename T> class myless 
    1777 { 
    1778 public: 
    1779         bool operator() (T v1, T v2) const 
    1780         { 
    1781                 return (v1->GetMergeCost() < v2->GetMergeCost()); 
    1782         } 
    1783 }; 
    1784  
    1785 typedef priority_queue<HierarchyNodeWrapper *, vector<HierarchyNodeWrapper *>,  
    1786                                            myless<vector<HierarchyNodeWrapper *>::value_type> > HierarchyNodeQueue; 
    1787  
    1788 class HierarchyNodeWrapper 
    1789 { 
    1790 public: 
    1791         enum {VSP_NODE, BVH_NODE, VIEW_CELL}; 
    1792  
    1793         virtual float GetMergeCost() const = 0; 
    1794         virtual int Type() const  = 0; 
    1795         virtual bool IsLeaf() const = 0; 
    1796  
    1797         virtual void PushChildren(HierarchyNodeQueue &tQueue) = 0; 
    1798 }; 
    1799  
    1800  
    1801 class VspNodeWrapper: public HierarchyNodeWrapper 
    1802 { 
    1803 public: 
    1804         VspNodeWrapper(VspNode *node): mNode(node) {} 
    1805  
    1806         int Type() const { return VSP_NODE; } 
    1807  
    1808         float GetMergeCost() const { return (float) -mNode->mTimeStamp; }; 
    1809  
    1810         bool IsLeaf() const { return mNode->IsLeaf(); } 
    1811  
    1812         void PushChildren(HierarchyNodeQueue &tQueue) 
    1813         { 
    1814                 if (!mNode->IsLeaf()) 
    1815                 { 
    1816                         VspInterior *interior = dynamic_cast<VspInterior *>(mNode); 
    1817  
    1818                         tQueue.push(new VspNodeWrapper(interior->GetFront())); 
    1819                         tQueue.push(new VspNodeWrapper(interior->GetBack())); 
    1820                 } 
    1821         } 
    1822  
    1823         VspNode *mNode; 
    1824 }; 
    1825  
    1826  
    1827 class BvhNodeWrapper: public HierarchyNodeWrapper 
    1828 { 
    1829 public: 
    1830         BvhNodeWrapper(BvhNode *node): mNode(node) {} 
    1831          
    1832         int Type()  const { return BVH_NODE; } 
    1833  
    1834         float GetMergeCost() const { return (float)-mNode->mTimeStamp; }; 
    1835  
    1836         bool IsLeaf() const { return mNode->IsLeaf(); } 
    1837  
    1838         void PushChildren(HierarchyNodeQueue &tQueue) 
    1839         { 
    1840                 if (!mNode->IsLeaf()) 
    1841                 { 
    1842                         BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode); 
    1843  
    1844                         tQueue.push(new BvhNodeWrapper(interior->GetFront())); 
    1845                         tQueue.push(new BvhNodeWrapper(interior->GetBack())); 
    1846                 } 
    1847         } 
    1848  
    1849         BvhNode *mNode; 
    1850 }; 
    1851  
    1852  
    1853 class ViewCellWrapper: public HierarchyNodeWrapper 
    1854 { 
    1855 public: 
    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  
    1884 void HierarchyManager::CollectBestSet(const int maxSplits, 
    1885                                                                           const float maxMemoryCost, 
    1886                                 //                                        vector<VspNode *> &vspNodes, 
    1887                                                                           ViewCellContainer &viewCells, 
    1888                                                                           vector<BvhNode *> &bvhNodes) 
    1889 { 
    1890         HierarchyNodeQueue tqueue; 
    1891         //tqueue.push(new VspNodeWrapper(mVspTree->GetRoot())); 
    1892         tqueue.push(new ViewCellWrapper(mVspTree->mViewCellsTree->GetRoot())); 
    1893         tqueue.push(new BvhNodeWrapper(mBvHierarchy->GetRoot())); 
    1894          
    1895         float memCost = 0; 
    1896  
    1897         while (!tqueue.empty()) 
    1898         { 
    1899                 HierarchyNodeWrapper *nodeWrapper = tqueue.top(); 
    1900                 tqueue.pop(); 
    1901  
    1902                 // save the view cells if it is a leaf or if enough view cells have already been traversed 
    1903                 // because of the priority queue, this will be the optimal set of v 
    1904                 if (nodeWrapper->IsLeaf() ||  
    1905                         ((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) || 
    1906                         (memCost > maxMemoryCost) 
    1907                         ) 
    1908                 { 
    1909                         if (nodeWrapper->Type() == HierarchyNodeWrapper::VSP_NODE) 
    1910                         { 
    1911                                 ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper); 
    1912                                 viewCells.push_back(viewCellWrapper->mViewCell); 
    1913                         } 
    1914                         else 
    1915                         { 
    1916                                 BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper); 
    1917                                 bvhNodes.push_back(bvhNodeWrapper->mNode); 
    1918                         } 
    1919                 } 
    1920                 else  
    1921                 {        
    1922                         nodeWrapper->PushChildren(tqueue); 
    1923                 } 
    1924  
    1925                 delete nodeWrapper; 
    1926         } 
    1927 } 
    1928  
    1929  
    1930 void HierarchyManager::ExtractStatistics(const int maxSplits, 
    1931                                                                                  const float maxMemoryCost, 
    1932                                                                                  float &renderCost, 
    1933                                                                                  float &memory, 
    1934                                                                                  int &pvsEntries) 
    1935 { 
    1936         //vector<VspNode *> vspNodes; 
     1910void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays,                                                                                                                                               
     1911                                                                                   const ObjectContainer &objects, 
     1912                                                                                   const string &filename) 
     1913{ 
     1914        VspTree *oldVspTree = mVspTree; 
     1915        ViewCellsManager *vm = mVspTree->mViewCellsManager; 
     1916        BvHierarchy *oldHierarchy = mBvHierarchy; 
     1917 
     1918        mBvHierarchy = new BvHierarchy(); 
     1919        mBvHierarchy->mHierarchyManager = this; 
     1920        mBvHierarchy->mViewCellsManager = vm; 
     1921 
     1922        mVspTree = new VspTree(); 
     1923        mVspTree->mHierarchyManager = this; 
     1924        mVspTree->mViewCellsManager = vm; 
     1925 
     1926        // create first nodes 
     1927        mVspTree->Initialise(sampleRays, &oldVspTree->mBoundingBox); 
     1928        InitialiseObjectSpaceSubdivision(objects); 
     1929 
     1930        const long startTime = GetTime(); 
     1931        cout << "Constructing evaluation hierarchies ... \n"; 
     1932         
     1933        ofstream stats; 
     1934        stats.open(filename.c_str()); 
     1935        SplitQueue tQueue; 
     1936 
     1937        BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 
     1938        VspNode *oldVspRoot = oldVspTree->GetRoot(); 
     1939 
     1940        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     1941         
     1942        SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 
     1943        SubdivisionCandidate *firstBvh = mBvHierarchy->PrepareConstruction(sampleRays, objects); 
     1944 
     1945    firstVsp->mEvaluationHack = oldVspRoot; 
     1946        firstBvh->mEvaluationHack = oldBvhRoot; 
     1947 
     1948        firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 
     1949        firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp); 
     1950 
     1951        tQueue.Push(firstVsp); 
     1952        tQueue.Push(firstBvh); 
     1953 
     1954        ExportStats(stats, tQueue, objects); 
     1955 
     1956        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     1957        RemoveRayRefs(objects); 
     1958 
     1959        // view cells needed only for evaluation 
    19371960        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  
    1983         /*TraversalQueue tqueue; 
    1984         tqueue.push(mRoot); 
    1985  
    1986         //cout << "exporting stats ... " << endl; 
    1987         int numViewCells = 1; 
    1988          
    1989         const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
    1990         const float vol = box.GetVolume(); 
    1991  
    1992         const int rootPvs = GetPvsSize(mRoot); 
    1993         const int rootEntries = GetPvsEntries(mRoot); 
    1994         float totalRenderCost, avgRenderCost, expectedCost; 
    1995  
    1996         float deviation = 0; 
    1997         int totalPvs = rootPvs; 
    1998         int entriesInPvs = rootEntries; 
    1999  
    2000         totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 
    2001  
    2002         ofstream stats; 
    2003         stats.open(mergeStats.c_str()); 
    2004  
    2005         const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
    2006  
    2007         ///////////// 
    2008         //-- first view cell 
    2009  
    2010         UpdateStats(stats, 
    2011                                 0,  
    2012                                 numViewCells,  
    2013                                 0,  
    2014                                 totalRenderCost,  
    2015                                 rootPvs,  
    2016                                 expectedCost,  
    2017                                 avgRenderCost,  
    2018                                 deviation, 
    2019                                 totalPvs,  
    2020                                 entriesInPvs, 
    2021                                 memoryCost, 
    2022                                 0,  
    2023                                 mRoot->GetVolume()); 
    2024                  
    2025  
    2026         //-- go through tree in the order of render cost decrease 
    2027         //-- which is the same order as the view cells were merged 
    2028         //-- or the reverse order of subdivision for subdivision-only  
    2029         //-- view cell hierarchies. 
    2030  
    2031         while (!tqueue.empty()) 
    2032         { 
    2033                 ViewCell *vc = tqueue.top(); 
    2034                 tqueue.pop(); 
    2035  
    2036                 if (!vc->IsLeaf())  
    2037                 {        
    2038                         ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    2039  
    2040                         const int parentPvs = GetPvsSize(interior); 
    2041                         const int parentPvsEntries = GetPvsEntries(interior); 
    2042             const float parentCost = (float)parentPvs * interior->GetVolume(); 
    2043  
    2044                         float childCost = 0; 
    2045                         int childPvs = 0; 
    2046                         int childPvsEntries = 0; 
    2047  
    2048                         -- numViewCells; 
    2049  
    2050                         ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    2051  
    2052                         for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    2053                         { 
    2054                                 ViewCell *vc = *it; 
    2055  
    2056                                 const int pvsSize = GetPvsSize(vc); 
    2057                                 const int pvsEntries = GetPvsEntries(vc); 
    2058  
    2059                                 childCost += (float) pvsSize * vc->GetVolume(); 
    2060                                 childPvs += pvsSize; 
    2061                                 childPvsEntries += pvsEntries; 
    2062  
    2063                                 tqueue.push(vc); 
    2064                                 ++ numViewCells; 
    2065                         } 
    2066  
    2067                         // update stats for this view cell 
    2068                         const float costDecr = (parentCost - childCost) / vol; 
    2069  
    2070                         totalRenderCost -= costDecr; 
    2071                         totalPvs += childPvs - parentPvs; 
    2072                         entriesInPvs += childPvsEntries - parentPvsEntries; 
    2073  
    2074                         expectedCost = totalRenderCost / (float)numViewCells; 
    2075                         avgRenderCost = (float)totalPvs / (float)numViewCells; 
    2076  
    2077                         const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
    2078  
    2079                         UpdateStats(stats, 
    2080                                                 0,  
    2081                                                 numViewCells,  
    2082                                                 costDecr,  
    2083                                                 totalRenderCost, 
    2084                                                 parentPvs,  
    2085                                                 expectedCost,  
    2086                                                 avgRenderCost,  
    2087                                                 deviation, 
    2088                         totalPvs,  
    2089                                                 entriesInPvs,  
    2090                                                 memoryCost, 
    2091                                                 childPvs - parentPvs, 
    2092                                                 vc->GetVolume()); 
    2093                 } 
    2094         } 
    2095  
    2096         stats.close(); 
    2097         */ 
    2098 } 
    2099          
    2100 } 
     1961        mVspTree->CollectViewCells(viewCells, false); 
     1962         
     1963        // helper trees can be destroyed 
     1964        DEL_PTR(mVspTree); 
     1965        DEL_PTR(mBvHierarchy); 
     1966 
     1967        CLEAR_CONTAINER(viewCells); 
     1968 
     1969        // reset hierarchies 
     1970        mVspTree = oldVspTree; 
     1971        mBvHierarchy = oldHierarchy; 
     1972 
     1973        // reinstall old bv refs 
     1974        vector<BvhLeaf *> leaves; 
     1975        mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 
     1976        vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 
     1977 
     1978        for (bit = leaves.begin(); bit != bit_end; ++ bit) 
     1979        { 
     1980                mBvHierarchy->AssociateObjectsWithLeaf(*bit); 
     1981        } 
     1982} 
     1983 
     1984 
     1985void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats, 
     1986                                                                                        ofstream &memStats, 
     1987                                                                                        const int splitsStepSize, 
     1988                                                                                        const float memStepSize) 
     1989{ 
     1990        int splits = 0; 
     1991        float mem = 15; 
     1992 
     1993        float renderCost; 
     1994        float memory; 
     1995        int pvsEntries; 
     1996 
     1997        while (1) 
     1998        { 
     1999                if (!ExtractStatistics(i, 99999999, renderCost, memory, pvsEntries)) 
     2000                        break; 
     2001 
     2002                UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 
     2003 
     2004                splits += splitsStepSize 
     2005        } 
     2006 
     2007        while (1) 
     2008        { 
     2009                if (!ExtractStatistics(99999999, mem, renderCost, memory, pvsEntries)) 
     2010                        break; 
     2011 
     2012                UpdateStats(splitsStats, splits, renderCost, pvsEntries, memory, 0); 
     2013 
     2014                mem += memStepSize 
     2015        } 
     2016 
     2017} 
     2018 
     2019} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1707 r1709  
    240240                                                         const string &filename); 
    241241 
     242        void EvaluateSubdivision2(ofstream &stats); 
     243 
     244 
    242245        float mInitialRenderCost; 
    243246 
     
    452455        void CollectBestSet(const int maxSplits, 
    453456                                                const float maxMemoryCost, 
    454                                                 //vector<VspNode *> &vspNodes, 
    455457                                                ViewCellContainer &viewCells, 
    456458                                                vector<BvhNode *> &bvhNodes); 
    457459 
    458         void ExtractStatistics(const int maxSplits, 
     460        bool ExtractStatistics(const int maxSplits, 
    459461                                                   const float maxMemoryCost, 
    460462                                                   float &renderCost, 
    461463                                                   float &memory, 
    462464                                                   int &pvsEntries); 
     465 
     466 
    463467protected: 
    464468 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1707 r1709  
    4242 
    4343// pvs penalty can be different from pvs size 
    44 inline static float EvalPvsPenalty(const int pvs,  
    45                                                                    const int lower,  
    46                                                                    const int upper) 
     44inline static float EvalPvsPenalty(const float pvs,  
     45                                                                   const float lower,  
     46                                                                   const float upper) 
    4747{ 
    4848        // clamp to minmax values 
     
    7676 
    7777/// Fast computation of merged pvs size 
    78 static int ComputeMergedPvsSize(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
     78static float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) 
    7979{ 
    8080        // add first pvs 
    81         int pvs = pvs1.GetSize(); 
     81        float pvs = (float)pvs1.GetSize(); 
    8282 
    8383        ObjectPvsMap::const_iterator it, it_end =  pvs1.mEntries.end(); 
     
    112112mParent(NULL), 
    113113mMergeCost(0), 
    114 mPvsSize(0), 
     114mPvsCost(0), 
    115115mEntriesInPvs(0), 
    116116mPvsSizeValid(false) 
    117 //mMailbox(0) 
    118117{ 
    119118        mId = -100; 
     
    127126mParent(NULL), 
    128127mMergeCost(0), 
    129 mPvsSize(0), 
     128mPvsCost(0), 
    130129mPvsSizeValid(false) 
    131130//mMailbox(0) 
     
    244243float ViewCell::GetRenderCost() const 
    245244{ 
    246         //return (float)mPvs.GetSize() * GetVolume(); 
    247         return (float)mPvsSize * GetVolume(); 
     245        return mPvsCost * GetVolume(); 
    248246} 
    249247 
     
    352350        //app << "#N_CTIME  ( Construction time [s] )\n" << Time() << " \n"; 
    353351 
    354         app << "#N_OVERALLPVS ( objects in PVS )\n" << pvsSize << endl; 
     352        app << "#N_OVERALLPVS ( cost of the PVS )\n" << pvsCost << endl; 
     353 
     354        //app << "#N_PVSENTRIES ( entries in the PVS)\n" << pvsEntries << endl; 
    355355 
    356356        app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl; 
     
    520520 
    521521        float variance = 0; 
    522         int totalPvs = 0; 
     522        float totalPvs = 0; 
    523523        float totalRenderCost = 0; 
    524524 
     
    669669                                                 
    670670                        //-- merge the view cells of leaf1 and leaf2 
    671                         int pvsDiff; 
     671                        float pvsDiff; 
    672672                        ViewCellInterior *mergedVc =  
    673                                 MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff); 
    674                          
     673                                MergeViewCells(mc.mLeftViewCell, mc.mRightViewCell, pvsDiff);    
    675674 
    676675                        // total render cost and deviation has changed 
     
    926925        for (vit = viewCells.begin(); vit != vit_end; ++ vit) 
    927926        { 
    928                 const int lower = mViewCellsManager->GetMinPvsSize(); 
    929                 const int upper = mViewCellsManager->GetMaxPvsSize(); 
     927                const float lower = (float)mViewCellsManager->GetMinPvsSize(); 
     928                const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 
    930929 
    931930                const float penalty = EvalPvsPenalty((*vit)->GetPvs().EvalPvsCost(), lower, upper); 
     
    992991ViewCellInterior *ViewCellsTree::MergeViewCells(ViewCell *left,  
    993992                                                                                                ViewCell *right,  
    994                                                                                                 int &pvsDiff) //const 
     993                                                                                                float &pvsDiff) //const 
    995994{ 
    996995        // create merged view cell 
     
    11831182{ 
    11841183        //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 
    1185         const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), leaf->GetPvs()); 
    1186         const int pvs2 = AddedPvsSize(vc2->GetPvs(), leaf->GetPvs()); 
    1187  
    1188         const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 
    1189         const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 
     1184        const float pvs1 = (float)SubtractedPvsSize(vc1->GetPvs(), leaf->GetPvs()); 
     1185        const float pvs2 = (float)AddedPvsSize(vc2->GetPvs(), leaf->GetPvs()); 
     1186 
     1187        const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize(); 
     1188        const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize(); 
    11901189 
    11911190        const float pvsPenalty1 =  
     
    13111310float ViewCellsTree::GetVariance(ViewCell *vc) const 
    13121311{ 
    1313         const int upper = mViewCellsManager->GetMaxPvsSize(); 
    1314         const int lower = mViewCellsManager->GetMinPvsSize(); 
     1312        const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 
     1313        const float lower = (float)mViewCellsManager->GetMinPvsSize(); 
    13151314 
    13161315        if (1) 
    13171316        { 
    13181317                const float penalty =  
    1319                         EvalPvsPenalty(vc->GetPvs().GetSize(), lower, upper); 
     1318                        EvalPvsPenalty(GetPvsCost(vc), lower, upper); 
    13201319 
    13211320                return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) /  
     
    13301329float ViewCellsTree::GetDeviation(ViewCell *vc) const 
    13311330{ 
    1332         const int upper = mViewCellsManager->GetMaxPvsSize(); 
    1333         const int lower = mViewCellsManager->GetMinPvsSize(); 
     1331        const float upper = (float)mViewCellsManager->GetMaxPvsSize(); 
     1332        const float lower = (float)mViewCellsManager->GetMinPvsSize(); 
    13341333 
    13351334        if (1) 
    13361335        { 
    1337                 const float penalty = EvalPvsPenalty(vc->GetPvs().EvalPvsCost(), lower, upper); 
     1336                const float penalty = EvalPvsPenalty(GetPvsCost(vc), lower, upper); 
    13381337                return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells; 
    13391338        } 
     
    13861385        //-- compute pvs difference 
    13871386 
    1388         int newPvs; 
    1389          
    1390         if (1) // not valid if not using const cost per object!! 
    1391         { 
    1392                 newPvs = ComputeMergedPvsSize(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
    1393         } 
    1394         else 
    1395         { 
    1396                 newPvs = (int)ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
    1397         } 
     1387        float newPvs; 
     1388         
     1389        // not valid if not using const cost per object!! 
     1390        newPvs = ComputeMergedPvsCost(mc.mLeftViewCell->GetPvs(), mc.mRightViewCell->GetPvs()); 
     1391 
    13981392 
    13991393        const float newPenalty = EvalPvsPenalty(newPvs,  
    1400                                                                                         mViewCellsManager->GetMinPvsSize(), 
    1401                                                                                         mViewCellsManager->GetMaxPvsSize()); 
     1394                                                                                        (float)mViewCellsManager->GetMinPvsSize(), 
     1395                                                                                        (float)mViewCellsManager->GetMaxPvsSize()); 
    14021396 
    14031397        ViewCell *vc1 = mc.mLeftViewCell; 
     
    14851479 
    14861480void ViewCellsTree::UpdateStats(ofstream &stats, 
    1487                                                                 const int pass, 
    1488                                                                 const int viewCells, 
    1489                                                                 const float renderCostDecrease, 
    1490                                                                 const float totalRenderCost, 
    1491                                                                 const int currentPvs, 
    1492                                                                 const float expectedCost, 
    1493                                                                 const float avgRenderCost, 
    1494                                                                 const float deviation, 
    1495                                                                 const int totalPvs, 
    1496                                                                 const int entriesInPvs, 
    1497                                                                 const float memoryCost, 
    1498                                                                 const int pvsSizeDecr, 
    1499                                                                 const float volume) 
    1500 { 
    1501          stats << "#Pass\n" << pass << endl 
    1502                    << "#Splits\n" << viewCells << endl  
    1503                    << "#RenderCostDecrease\n" << renderCostDecrease << endl // TODO 
    1504                    << "#TotalRenderCost\n" << totalRenderCost << endl 
    1505                    << "#CurrentPvs\n" << currentPvs << endl 
    1506                    << "#ExpectedCost\n" << expectedCost << endl 
    1507                    << "#AvgRenderCost\n" << avgRenderCost << endl 
    1508                    << "#Deviation\n" << deviation << endl 
    1509                    << "#TotalPvs\n" << totalPvs << endl 
    1510                    << "#TotalEntriesInPvs\n" << entriesInPvs << endl 
    1511                    << "#Memory\n" << memoryCost << endl 
    1512                    << "#PvsSizeDecrease\n" << pvsSizeDecr << endl 
    1513                    << "#Volume\n" << volume << endl 
     1481                                                                const ViewCellsTreeStats &vcStats) 
     1482{ 
     1483         stats << "#Pass\n" << vcStats.mPass << endl 
     1484                   << "#Splits\n" << vcStats.mNumViewCells << endl  
     1485                   << "#RenderCostDecrease\n" << vcStats.mRenderCostDecrease << endl // TODO 
     1486                   << "#TotalRenderCost\n" << vcStats.mTotalRenderCost << endl 
     1487                   << "#CurrentPvs\n" << vcStats.mCurrentPvsCost << endl 
     1488                   << "#ExpectedCost\n" << vcStats.mExpectedCost << endl 
     1489                   << "#AvgRenderCost\n" << vcStats.mAvgRenderCost << endl 
     1490                   << "#Deviation\n" << vcStats.mDeviation << endl 
     1491                   << "#TotalPvs\n" << vcStats.mTotalPvsCost << endl 
     1492                   << "#TotalEntriesInPvs\n" << vcStats.mEntriesInPvs << endl 
     1493                   << "#Memory\n" << vcStats.mMemoryCost << endl 
     1494                   << "#PvsSizeDecrease\n" << vcStats.mPvsSizeDecr << endl 
     1495                   << "#Volume\n" << vcStats.mVolume << endl 
    15141496                   << endl; 
    15151497} 
     
    15211503        tqueue.push(mRoot); 
    15221504 
     1505        ViewCellsTreeStats vcStats; 
     1506        vcStats.Reset(); 
     1507 
    15231508        //cout << "exporting stats ... " << endl; 
    1524         int numViewCells = 1; 
     1509        vcStats.mNumViewCells = 1; 
    15251510         
    15261511        const AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 
    15271512        const float vol = box.GetVolume(); 
    15281513 
    1529         const int rootPvs = GetPvsSize(mRoot); 
     1514        const float rootPvs = GetPvsCost(mRoot); 
    15301515        const int rootEntries = GetPvsEntries(mRoot); 
    1531         float totalRenderCost, avgRenderCost, expectedCost; 
    1532  
    1533         float deviation = 0; 
    1534         int totalPvs = rootPvs; 
    1535         int entriesInPvs = rootEntries; 
    1536  
    1537         totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 
     1516         
     1517        vcStats.mTotalPvsCost = rootPvs; 
     1518        vcStats.mTotalRenderCost = rootPvs; 
     1519        vcStats.mAvgRenderCost = rootPvs; 
     1520        vcStats.mExpectedCost = rootPvs; 
     1521         
     1522        vcStats.mEntriesInPvs = rootEntries; 
    15381523 
    15391524        ofstream stats; 
    15401525        stats.open(mergeStats.c_str()); 
    15411526 
    1542         const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
     1527        vcStats.mMemoryCost = (float)vcStats.mEntriesInPvs * ObjectPvs::GetEntrySize(); 
    15431528 
    15441529        ///////////// 
    15451530        //-- first view cell 
    15461531 
    1547         UpdateStats(stats, 
    1548                                 0,  
    1549                                 numViewCells,  
    1550                                 0,  
    1551                                 totalRenderCost,  
    1552                                 rootPvs,  
    1553                                 expectedCost,  
    1554                                 avgRenderCost,  
    1555                                 deviation, 
    1556                                 totalPvs,  
    1557                                 entriesInPvs, 
    1558                                 memoryCost, 
    1559                                 0,  
    1560                                 mRoot->GetVolume()); 
     1532        UpdateStats(stats, vcStats); 
     1533                                 
    15611534                 
    1562  
    15631535        //-- go through tree in the order of render cost decrease 
    15641536        //-- which is the same order as the view cells were merged 
     
    15751547                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    15761548 
    1577                         const int parentPvs = GetPvsSize(interior); 
     1549                        const float parentCost = GetPvsCost(interior); 
    15781550                        const int parentPvsEntries = GetPvsEntries(interior); 
    1579             const float parentCost = (float)parentPvs * interior->GetVolume(); 
    1580  
     1551            const float parentExpCost = (float)parentCost * interior->GetVolume(); 
     1552 
     1553                        float childExpCost = 0; 
    15811554                        float childCost = 0; 
    1582                         int childPvs = 0; 
    15831555                        int childPvsEntries = 0; 
    15841556 
    1585                         -- numViewCells; 
     1557                        -- vcStats.mNumViewCells; 
    15861558 
    15871559                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     
    15911563                                ViewCell *vc = *it; 
    15921564 
    1593                                 const int pvsSize = GetPvsSize(vc); 
     1565                                const float pvsCost = GetPvsCost(vc); 
    15941566                                const int pvsEntries = GetPvsEntries(vc); 
    15951567 
    1596                                 childCost += (float) pvsSize * vc->GetVolume(); 
    1597                                 childPvs += pvsSize; 
     1568                                childExpCost += childCost * vc->GetVolume(); 
     1569                                childCost += pvsCost; 
    15981570                                childPvsEntries += pvsEntries; 
    15991571 
    16001572                                tqueue.push(vc); 
    1601                                 ++ numViewCells; 
     1573                                ++ vcStats.mNumViewCells; 
    16021574                        } 
    16031575 
    16041576                        // update stats for this view cell 
    1605                         const float costDecr = (parentCost - childCost) / vol; 
    1606  
    1607                         totalRenderCost -= costDecr; 
    1608                         totalPvs += childPvs - parentPvs; 
    1609                         entriesInPvs += childPvsEntries - parentPvsEntries; 
    1610  
    1611                         expectedCost = totalRenderCost / (float)numViewCells; 
    1612                         avgRenderCost = (float)totalPvs / (float)numViewCells; 
    1613  
    1614                         const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
    1615  
    1616                         UpdateStats(stats, 
    1617                                                 0,  
    1618                                                 numViewCells,  
    1619                                                 costDecr,  
    1620                                                 totalRenderCost, 
    1621                                                 parentPvs,  
    1622                                                 expectedCost,  
    1623                                                 avgRenderCost,  
    1624                                                 deviation, 
    1625                         totalPvs,  
    1626                                                 entriesInPvs,  
    1627                                                 memoryCost, 
    1628                                                 childPvs - parentPvs, 
    1629                                                 vc->GetVolume()); 
     1577                        const float costDecr = (parentExpCost - childExpCost) / vol; 
     1578 
     1579                        vcStats.mTotalRenderCost -= costDecr; 
     1580                        vcStats.mTotalPvsCost += childCost - parentCost; 
     1581                        vcStats.mEntriesInPvs += childPvsEntries - parentPvsEntries; 
     1582 
     1583                        vcStats.mExpectedCost = vcStats.mTotalRenderCost / (float)vcStats.mNumViewCells; 
     1584                        vcStats.mAvgRenderCost = vcStats.mTotalPvsCost / (float)vcStats.mNumViewCells; 
     1585 
     1586                        vcStats.mMemoryCost = vcStats.mEntriesInPvs * ObjectPvs::GetEntrySize(); 
     1587 
     1588                        UpdateStats(stats, vcStats); 
    16301589                } 
    16311590        } 
     
    17891748 
    17901749 
    1791 int ViewCellsTree::GetPvsSizeForLeafStorage(ViewCell *vc) const 
     1750float ViewCellsTree::GetPvsCostForLeafStorage(ViewCell *vc) const 
    17921751{ 
    17931752        // pvs is always stored directly in leaves 
     
    18021761        if (vc->mPvsSizeValid) 
    18031762        { 
    1804                 return vc->mPvsSize; 
     1763                return vc->mPvsCost; 
    18051764        } 
    18061765         
     
    18861845 
    18871846 
    1888 int ViewCellsTree::GetPvsSizeForCompressedStorage(ViewCell *vc) const 
    1889 { 
    1890         int pvsSize = 0; 
     1847float ViewCellsTree::GetPvsCostForCompressedStorage(ViewCell *vc) const 
     1848{ 
     1849        float pvsCost = 0; 
    18911850 
    18921851        ///////////// 
     
    18961855        if (vc->mPvsSizeValid) 
    18971856        { 
    1898                 pvsSize = vc->mPvsSize; 
     1857                pvsCost = vc->mPvsCost; 
    18991858        } 
    19001859 
     
    19081867         
    19091868                // matt: bug! must evaluate kd pvss also 
    1910                 pvsSize += CountPvsContribution(root); 
     1869                pvsCost += CountPvsContribution(root); 
    19111870        } 
    19121871 
     
    19181877                vc = tstack.top(); 
    19191878                tstack.pop(); 
     1879 
    19201880                // matt: bug! must evaluate kd pvss also 
    1921                 pvsSize += CountPvsContribution(vc); 
     1881                pvsCost += CountPvsContribution(vc); 
    19221882 
    19231883                if (!vc->IsLeaf()) 
    19241884                { 
    19251885                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    1926  
    19271886                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    19281887 
     
    19341893        } 
    19351894 
    1936         return pvsSize; 
     1895        return pvsCost; 
    19371896} 
    19381897 
     
    19901949 
    19911950 
    1992 int ViewCellsTree::GetPvsSize(ViewCell *vc) const 
    1993 { 
    1994         int pvsSize = 0; 
     1951float ViewCellsTree::GetPvsCost(ViewCell *vc) const 
     1952{ 
     1953        float pvsCost = 0; 
    19951954        Intersectable::NewMail(); 
    19961955 
     
    20031962        case PVS_IN_LEAVES:  
    20041963                // pvs is stored only in leaves 
    2005                 pvsSize = GetPvsSizeForLeafStorage(vc);                  
     1964                pvsCost = GetPvsCostForLeafStorage(vc);                  
    20061965                break; 
    20071966        case COMPRESSED: 
    2008                 pvsSize = GetPvsSizeForCompressedStorage(vc); 
     1967                pvsCost = GetPvsCostForCompressedStorage(vc); 
    20091968                break; 
    20101969        case PVS_IN_INTERIORS: 
     
    20121971                // pvs is stored consistently in the tree up to the root 
    20131972                // just return pvs size  
    2014                 pvsSize = vc->GetPvs().EvalPvsCost();    
     1973                pvsCost = vc->GetPvs().EvalPvsCost();    
    20151974                break; 
    20161975        } 
    20171976 
    2018         return pvsSize 
     1977        return pvsCost 
    20191978} 
    20201979 
     
    21942153 
    21952154        const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
    2196         const int rootPvs = GetPvsSize(mRoot); 
     2155        const float rootPvs = GetPvsCost(mRoot); 
    21972156         
    21982157        float totalRenderCost; 
    21992158 
    2200         int totalPvs = rootPvs; 
     2159        float totalPvsCost = rootPvs; 
    22012160        totalRenderCost = (float)rootPvs; 
    22022161 
     
    22172176                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    22182177 
    2219                         const int parentPvs = GetPvsSize(interior); 
    2220                         const float parentCost = (float)parentPvs * interior->GetVolume(); 
     2178                        const float parentCost = GetPvsCost(interior); 
     2179                        const float parentExpCost = parentCost * interior->GetVolume(); 
    22212180 
    22222181                        -- numViewCells; 
    22232182 
     2183                        float childExpCost = 0; 
    22242184                        float childCost = 0; 
    2225                         int childPvs = 0; 
    22262185                         
    22272186                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     
    22312190                                ViewCell *vc = *it; 
    22322191 
    2233                                 const int pvsSize = GetPvsSize(vc); 
     2192                                const float pvsCost = GetPvsCost(vc); 
    22342193                                 
    2235                                 childCost += (float) pvsSize * vc->GetVolume(); 
    2236                                 childPvs += pvsSize; 
     2194                                childExpCost += (float) pvsCost * vc->GetVolume(); 
     2195                                childCost += pvsCost; 
    22372196                                 
    22382197                                tqueue.push(vc); 
     
    22412200 
    22422201                        // update stats for this view cell 
    2243                         const float costDecr = (parentCost - childCost) / vol; 
     2202                        const float costDecr = (parentExpCost - childExpCost) / vol; 
    22442203                        totalRenderCost -= costDecr; 
    2245                         const float expectedCost = totalRenderCost ;/// (float)numViewCells; 
    2246                  
    2247                         costFunction.push_back(expectedCost); 
     2204                         
     2205                        costFunction.push_back(totalRenderCost); 
    22482206                } 
    22492207        } 
     
    22832241                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    22842242 
    2285                         const int parentPvs = GetPvsSize(interior); 
     2243                        const float parentPvsCost = GetPvsCost(interior); 
    22862244                        const int parentPvsEntries = GetPvsEntries(interior); 
    2287             const float parentCost = (float)parentPvs * interior->GetVolume(); 
    2288  
    2289                         float childCost = 0; 
     2245            const float parentExpCost = (float)parentPvsCost * interior->GetVolume(); 
     2246 
     2247                        float childExpCost = 0; 
    22902248                        int childPvs = 0; 
    22912249                        int childPvsEntries = 0; 
     
    22992257                                ViewCell *vc = *it; 
    23002258 
    2301                                 //const int pvsSize = GetPvsSize(vc); 
    23022259                                const int pvsEntries = GetPvsEntries(vc); 
    2303  
    2304                                 //childPvs += pvsSize; 
    23052260                                childPvsEntries += pvsEntries; 
    23062261 
     
    23102265 
    23112266                        // update stats for this view cell 
    2312                         const float costDecr = (parentCost - childCost) / vol; 
    2313  
    2314                         //totalPvs += childPvs - parentPvs; 
     2267                        const float costDecr = (parentExpCost - childExpCost) / vol; 
     2268 
    23152269                        entriesInPvs += childPvsEntries - parentPvsEntries; 
    23162270 
     
    23282282        ++ vcStat.viewCells; 
    23292283                 
    2330         const int pvsSize = GetPvsSize(vc); 
    2331  
    2332         vcStat.pvsSize += pvsSize; 
    2333  
    2334         if (pvsSize == 0) 
     2284        const float pvsCost = GetPvsCost(vc); 
     2285 
     2286        vcStat.pvsCost += pvsCost; 
     2287 
     2288        if (pvsCost < Limits::Small) 
    23352289                ++ vcStat.emptyPvs; 
    23362290 
    2337         if (pvsSize > vcStat.maxPvs) 
    2338                 vcStat.maxPvs = pvsSize; 
    2339  
    2340         if (pvsSize < vcStat.minPvs) 
    2341                 vcStat.minPvs = pvsSize; 
     2291        if (pvsCost > vcStat.maxPvs) 
     2292                vcStat.maxPvs = pvsCost; 
     2293 
     2294        if (pvsCost < vcStat.minPvs) 
     2295                vcStat.minPvs = pvsCost; 
    23422296 
    23432297        if (!vc->GetValid()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1707 r1709  
    3535        /// number of view cells 
    3636        int viewCells; 
    37         /// size of the PVS 
    38         int pvsSize; 
     37        /// cost of the PVS 
     38        float pvsCost; 
    3939        /// largest PVS of all view cells 
    40         int maxPvs; 
     40        float maxPvs; 
    4141        /// smallest PVS of all view cells 
    42         int minPvs; 
     42        float minPvs; 
    4343        /// view cells with empty PVS 
    4444        int emptyPvs; 
     
    5757 
    5858        double AvgLeaves() const {return (double)leaves / (double)viewCells;}; 
    59         double AvgPvs() const {return (double)pvsSize / (double)viewCells;}; 
     59        double AvgPvs() const {return (double)pvsCost / (double)viewCells;}; 
    6060 
    6161        void Reset() 
    6262        { 
    6363                viewCells = 0; 
    64                 pvsSize = 0; 
     64                pvsCost = 0; 
    6565                maxPvs = 0; 
    6666 
     
    7575 
    7676        friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat) 
     77        { 
     78                stat.Print(s); 
     79                return s; 
     80        } 
     81}; 
     82 
     83 
     84class ViewCellsTreeStats 
     85{ 
     86public: 
     87        int mPass; 
     88     
     89        int mNumViewCells; 
     90                 
     91        float mRenderCostDecrease; 
     92 
     93    float mTotalRenderCost; 
     94     
     95        float mCurrentPvsCost; 
     96                                                         
     97        float mExpectedCost; 
     98     
     99        float mAvgRenderCost; 
     100         
     101        float mDeviation; 
     102                         
     103        float mTotalPvsCost; 
     104         
     105        int mEntriesInPvs; 
     106     
     107        float mMemoryCost; 
     108         
     109        int mPvsSizeDecr; 
     110         
     111        float mVolume; 
     112 
     113 
     114        void Reset() 
     115        { 
     116                mPass = 0; 
     117                mNumViewCells = 0; 
     118                mRenderCostDecrease = 0; 
     119                mTotalRenderCost = 0; 
     120                mCurrentPvsCost = 0; 
     121                mExpectedCost = 0; 
     122                mAvgRenderCost = 0; 
     123                mDeviation = 0; 
     124                mTotalPvsCost = 0; 
     125                mEntriesInPvs = 0; 
     126                mMemoryCost = 0; 
     127                mPvsSizeDecr = 0; 
     128                mVolume = 0; 
     129        } 
     130 
     131 
     132        void Print(ostream &app) const; 
     133 
     134        friend ostream &operator<<(ostream &s, const ViewCellsTreeStats &stat) 
    77135        { 
    78136                stat.Print(s); 
     
    181239                // HACK: take scalar value because pvs may not have been stored properly 
    182240#if 1 
    183                 return a->mPvsSize < b->mPvsSize; 
     241                return a->mPvsCost < b->mPvsCost; 
    184242#else 
    185243                return a->GetPvs().EvalPvsCost() < b->GetPvs().EvalPvsCost(); 
     
    251309        RgbColor mColor; 
    252310        /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 
    253         int mPvsSize; 
     311        float mPvsCost; 
    254312        /** stores number of entries in pvs 
    255313            this variable has the same value as mPvsSize for object pvs,  
     
    421479        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 
    422480 
    423         /** Returns pvs size (i.e. the number of stored objects) 
    424         */ 
    425         int GetPvsSize(ViewCell *vc) const; 
     481        /** Returns pvs size (i.e. the render cost of the stored objects) 
     482        */ 
     483        float GetPvsCost(ViewCell *vc) const; 
    426484 
    427485        /** Returns number of entries associated with this view cell.  
     
    538596                @returns difference in pvs size 
    539597        */ 
    540         ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, int &pvsDiff); //const; 
     598        ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); //const; 
    541599 
    542600        /** Shuffles, i.e. takes border leaf from view cell 1 and adds it  
     
    601659                The pvs is assumed to be stored using lossless compression. 
    602660        */ 
    603         int GetPvsSizeForCompressedStorage(ViewCell *vc) const; 
     661        float GetPvsCostForCompressedStorage(ViewCell *vc) const; 
    604662         
    605663        /** Computes pvs size of this view cell. 
    606664                The pvs is assumed to be stored in the leaves. 
    607665        */ 
    608         int GetPvsSizeForLeafStorage(ViewCell *vc) const; 
     666        float GetPvsCostForLeafStorage(ViewCell *vc) const; 
    609667 
    610668        /** Counts the logical number of entries in the pvs this view cell. 
     
    616674        */ 
    617675        void UpdateStats(ofstream &stats, 
    618                                          const int pass, 
    619                                          const int viewCells, 
    620                                          const float renderCostDecrease, 
    621                                          const float totalRenderCost, 
    622                                          const int currentPvs, 
    623                                          const float expectedCost, 
    624                                          const float avgRenderCost, 
    625                                          const float deviation, 
    626                                          const int totalPvs, 
    627                                          const int entriesInPvs, 
    628                                          const float memoryCost, 
    629                                          const int pvsSizeDecr, 
    630                                          const float volume); 
     676                                         const ViewCellsTreeStats &vcStats); 
    631677 
    632678 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1708 r1709  
    296296        int stype; 
    297297         
     298        const int numStrategies = 3; 
     299 
    298300        stype = SamplingStrategy::OBJECT_BASED_DISTRIBUTION; 
    299         mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 
     301        mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 
    300302         
    301303        stype = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION; 
    302         mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 
    303          
    304         stype = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 
    305         mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 
     304        mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 
     305         
     306        if (0) 
     307        { 
     308                stype = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION; 
     309                mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 
     310        } 
    306311 
    307312        stype = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 
    308         mPreprocessor->GenerateRays(samplesPerPass / 4, sampleType, simpleRays); 
     313        mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays); 
    309314 
    310315        cout << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     
    516521        if (mEvaluateViewCells) 
    517522        { 
    518 cout << "here42 ***********" << endl; 
    519523                EvalViewCellPartition(); 
    520524        } 
     
    794798        mViewCellsTree->CollectBestViewCellSet(viewCells, nViewCells); 
    795799 
    796         int maxPvs, maxVal, minVal; 
     800        float maxPvs, maxVal, minVal; 
    797801 
    798802        // sort by pvs size 
    799803        sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs); 
    800804 
    801         maxPvs = mViewCellsTree->GetPvsSize(viewCells.back()); 
     805        maxPvs = mViewCellsTree->GetPvsCost(viewCells.back()); 
    802806        minVal = 0; 
    803807 
     
    805809        int histoMaxVal; 
    806810        Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal); 
    807         maxVal = max(histoMaxVal, maxPvs); 
     811        maxVal = max((float)histoMaxVal, maxPvs); 
    808812                 
    809813        Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal  
     
    814818        const int intervals = min(histoIntervals, (int)viewCells.size()); 
    815819 
    816         const int range = maxVal - minVal; 
    817         int stepSize = range / intervals; 
     820        const float range = maxVal - minVal; 
     821        int stepSize = (int)(range / intervals); 
    818822 
    819823        // set step size to avoid endless loop 
     
    825829        const float totalVol = GetViewSpaceBox().GetVolume(); 
    826830 
    827         int currentPvs = minVal;//(int)ceil(minRenderCost); 
     831        float currentPvs = minVal; 
    828832         
    829833        int i = 0; 
     
    840844 
    841845                while ((i < (int)viewCells.size()) &&  
    842                            (mViewCellsTree->GetPvsSize(viewCells[i]) < currentPvs)) 
     846                           (mViewCellsTree->GetPvsCost(viewCells[i]) < currentPvs)) 
    843847                { 
    844848                        volDif += viewCells[i]->GetVolume(); 
     
    851855                 
    852856                if (0 && (i < (int)viewCells.size())) 
    853                         Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i])  
     857                        Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i])  
    854858                        << " " << currentPvs << endl; 
    855859         
     
    864868                outstream << "#VolumeSum\n" << volRatioSum << endl << endl; 
    865869         
    866                 //if ((i >= (int)viewCells.size()) || (currentPvs >= maxPvs))   break; 
    867  
    868870                //-- increase current pvs size to define next interval 
    869871                currentPvs += stepSize; 
     
    10091011                        ObjectPvs pvs; 
    10101012 
    1011                         cout << "updating pvs for contribution ... " << endl; 
     1013                        cout << "updating pvs for evaluation ... " << endl; 
    10121014 
    10131015                        UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
     
    14991501                                                                                                float &deviation, 
    15001502                                                                                                float &variance, 
    1501                                                                                                 int &totalPvs, 
     1503                                                                                                float &totalCost, 
    15021504                                                                                                float &avgRenderCost) 
    15031505{ 
     
    15061508 
    15071509        totalRenderCost = 0; 
    1508         totalPvs = 0; 
     1510        totalCost = 0; 
    15091511 
    15101512        ViewCellContainer::const_iterator it, it_end = mViewCells.end(); 
     
    15141516                ViewCell *vc = *it; 
    15151517                totalRenderCost += vc->GetPvs().EvalPvsCost() * vc->GetVolume(); 
    1516                 totalPvs += (int)vc->GetPvs().EvalPvsCost(); 
     1518                totalCost += (int)vc->GetPvs().EvalPvsCost(); 
    15171519        } 
    15181520 
     
    15201522        totalRenderCost /= mViewSpaceBox.GetVolume(); 
    15211523        expectedRenderCost = totalRenderCost / (float)mViewCells.size(); 
    1522         avgRenderCost = totalPvs / (float)mViewCells.size(); 
     1524        avgRenderCost = totalCost / (float)mViewCells.size(); 
    15231525 
    15241526 
     
    17441746void ViewCellsManager::GetPvsStatistics(PvsStatistics &stat) 
    17451747{ 
    1746   // update pvs of view cells tree if necessary 
    1747   UpdatePvs(); 
    1748    
    1749   ViewCellContainer::const_iterator it = mViewCells.begin(); 
    1750    
    1751   stat.viewcells = 0; 
    1752   stat.minPvs = 100000000; 
    1753   stat.maxPvs = 0; 
    1754   stat.avgPvs = 0.0f; 
    1755    
    1756   for (; it != mViewCells.end(); ++ it)  
    1757         { 
    1758           ViewCell *viewcell = *it; 
    1759  
    1760           //      bool mCountKdPvs = false; 
    1761           const int pvsSize = mViewCellsTree->GetPvsSize(viewcell); 
    1762  
    1763  
    1764           if (pvsSize < stat.minPvs) 
    1765                 stat.minPvs = pvsSize; 
    1766           if (pvsSize > stat.maxPvs) 
    1767                 stat.maxPvs = pvsSize; 
    1768            
    1769           stat.avgPvs += pvsSize; 
    1770            
    1771           ++ stat.viewcells; 
    1772         } 
    1773    
    1774   if (stat.viewcells) 
    1775         stat.avgPvs/=stat.viewcells; 
     1748        // update pvs of view cells tree if necessary 
     1749        UpdatePvs(); 
     1750 
     1751        ViewCellContainer::const_iterator it = mViewCells.begin(); 
     1752 
     1753        stat.viewcells = 0; 
     1754        stat.minPvs = 100000000; 
     1755        stat.maxPvs = 0; 
     1756        stat.avgPvs = 0.0f; 
     1757 
     1758        for (; it != mViewCells.end(); ++ it)  
     1759        { 
     1760                ViewCell *viewcell = *it; 
     1761 
     1762                const float pvsCost = mViewCellsTree->GetPvsCost(viewcell); 
     1763 
     1764                if (pvsCost < stat.minPvs) 
     1765                        stat.minPvs = pvsCost; 
     1766                if (pvsCost > stat.maxPvs) 
     1767                        stat.maxPvs = pvsCost; 
     1768 
     1769                stat.avgPvs += pvsCost; 
     1770 
     1771                ++ stat.viewcells; 
     1772        } 
     1773 
     1774        if (stat.viewcells) 
     1775                stat.avgPvs/=stat.viewcells; 
    17761776} 
    17771777 
     
    20532053float ViewCellsManager::GetRendercost(ViewCell *viewCell) const 
    20542054{ 
    2055         return (float)mViewCellsTree->GetPvsSize(viewCell); 
     2055        return (float)mViewCellsTree->GetPvsCost(viewCell); 
    20562056} 
    20572057 
     
    23272327 
    23282328void ViewCellsManager::UpdateScalarPvsSize(ViewCell *vc,  
    2329                                                                                    const int pvsSize,  
     2329                                                                                   const float pvsCost,  
    23302330                                                                                   const int entriesInPvs) const 
    23312331{ 
    2332         vc->mPvsSize = pvsSize; 
     2332        vc->mPvsCost = pvsCost; 
    23332333        vc->mEntriesInPvs = entriesInPvs; 
    23342334 
     
    25252525                        { 
    25262526                                importance =  
    2527                                         (float)mViewCellsTree->GetPvsSize(vc) /  
     2527                                        (float)mViewCellsTree->GetPvsCost(vc) /  
    25282528                                        (float)mCurrentViewCellsStats.maxPvs; 
    25292529                        } 
     
    25782578        if (root->IsLeaf()) 
    25792579        {  
     2580                //cout << "updating leaf" << endl; 
    25802581                // we assume that pvs is explicitly stored in leaves 
    25812582                pvs = root->GetPvs(); 
    25822583                UpdateScalarPvsSize(root, pvs.EvalPvsCost(), pvs.GetSize()); 
    2583                  
    25842584                return; 
    25852585        } 
    2586          
     2586 
     2587        //cout << "recursivly updating pvs" << endl; 
     2588 
    25872589        //////////////// 
    25882590        //-- interior node => propagate pvs up the tree 
     
    25972599        // pvss of child nodes 
    25982600        vector<ObjectPvs> pvsList; 
     2601        pvsList.resize((int)interior->mChildren.size()); 
    25992602 
    26002603        ViewCellContainer::const_iterator vit, vit_end = interior->mChildren.end(); 
    2601         pvsList.resize((int)interior->mChildren.size()); 
     2604         
    26022605        int i = 0; 
     2606 
    26032607        for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ i) 
    26042608        { 
    2605                 //ObjectPvs objPvs; 
    2606                  
    26072609                ////////////////// 
    26082610                //-- recursivly compute child pvss 
    2609  
    26102611                UpdatePvsForEvaluation(*vit, pvsList[i]/*objPvs*/); 
    2611  
    2612                 // store pvs in vector 
    2613                 //pvsList.push_back(objPvs); 
    26142612        } 
    26152613 
     
    30473045                Exporter *exporter = Exporter::GetExporter(s); 
    30483046                 
    3049                 cout << "view cell " << idx << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     3047                cout << "view cell " << idx << ": pvs cost=" << (int)mViewCellsTree->GetPvsCost(vc) << endl; 
    30503048 
    30513049                if (exportRays) 
     
    44004398                Exporter *exporter = Exporter::GetExporter(s); 
    44014399                 
    4402                 const int pvsSize = (int)mViewCellsTree->GetPvsSize(vc); 
    4403                 cout << "view cell " << vc->GetId() << ": pvs size=" << pvsSize << endl; 
     4400                const float pvsCost = mViewCellsTree->GetPvsCost(vc); 
     4401                cout << "view cell " << vc->GetId() << ": pvs cost=" << pvsCost << endl; 
    44044402 
    44054403                if (exportRays) 
     
    52855283                Exporter *exporter = Exporter::GetExporter(s); 
    52865284                 
    5287                 cout << "view cell " << vc->GetId() << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl; 
     5285                cout << "view cell " << vc->GetId() << ": pvs cost=" << mViewCellsTree->GetPvsCost(vc) << endl; 
    52885286 
    52895287                if (exportPvs) 
     
    56615659 
    56625660 
    5663 #if 0 
     5661#if 1 
    56645662#if TEST_EVALUATION 
    56655663void VspOspViewCellsManager::EvalViewCellPartition() 
     
    57305728        { 
    57315729                ViewCell *vc = *vit; 
    5732                 int pvs = vc->GetPvs().EvalPvsCost(); 
    5733                 float vol = vc->GetVolume(); 
    5734                 rc += pvs * vol; 
     5730                const float pvsCost = vc->GetPvs().EvalPvsCost(); 
     5731                const float vol = vc->GetVolume(); 
     5732                rc += pvsCost * vol; 
    57355733        } 
    57365734 
     
    58265824                sprintf(str, "-%09d-eval.log", castSamples); 
    58275825                string filename = string(statsPrefix) + string(str); 
    5828  
    5829                 mHierarchyManager->EvaluateSubdivision(evaluationSamples, mPreprocessor->mObjects, filename); 
     5826                ofstream ofstr(filename.c_str()); 
     5827                mHierarchyManager->EvaluateSubdivision2(ofstr); 
    58305828 
    58315829                timeDiff = TimeDiff(startTime, GetTime()); 
     
    58335831                Debug << "statistis compted in " << timeDiff * 1e-3 << " secs" << endl; 
    58345832         
    5835                 //disposeRays(evaluationSamples, NULL); 
    5836         } 
    5837          
    5838         disposeRays(evaluationSamples, NULL); 
    5839  
     5833                disposeRays(evaluationSamples, NULL); 
     5834        } 
    58405835} 
    58415836#endif 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1707 r1709  
    6464        struct PvsStatistics  
    6565        { 
    66                 int minPvs; 
    67                 int maxPvs; 
     66                float minPvs; 
     67                float maxPvs; 
    6868                float avgPvs; 
    6969                int viewcells; 
     
    7777 
    7878        friend class X3dViewCellsParseHandlers; 
     79 
    7980        /** Default constructor. 
    8081        */ 
     
    9091        /** Constructs view cell container with a given number of samples. 
    9192        */ 
    92         virtual int ConstructSubdivision( 
    93                 const ObjectContainer &objects,  
    94                 const VssRayContainer &rays) = 0; 
     93        virtual int ConstructSubdivision(const ObjectContainer &objects, 
     94                                                                         const VssRayContainer &rays) = 0; 
    9595 
    9696        /** Computes sample contributions of the rays to the view cells PVS. 
     
    360360                                                                  float &deviation, 
    361361                                                                  float &variance, 
    362                                                                   int &totalPvs, 
     362                                                                  float &totalPvs, 
    363363                                                                  float &avgRenderCost); 
    364364 
     
    414414                of the hierarchy. 
    415415        */ 
    416         void UpdateScalarPvsSize(ViewCell *vc, const int pvsSize, const int entriesInPvs) const; 
     416        void UpdateScalarPvsSize(ViewCell *vc, const float pvsCost, const int entriesInPvs) const; 
    417417 
    418418        /** Returns bounding box of a view cell. 
     
    11071107protected: 
    11081108 
    1109 //#if TEST_EVALUATION 
    1110         //virtual void EvalViewCellPartition(); 
    1111 //#endif 
     1109#if 1//TEST_EVALUATION 
     1110        virtual void EvalViewCellPartition(); 
     1111#endif 
    11121112 
    11131113        /** Exports view cell geometry. 
Note: See TracChangeset for help on using the changeset viewer.