Ignore:
Timestamp:
07/27/06 02:07:26 (18 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r1160 r1161  
    14371437 
    14381438        const int rootPvs = GetPvsSize(mRoot); 
    1439  
    1440         Debug << "vsb volume: " << vol << endl; 
     1439        const int rootEntries = GetPvsEntries(mRoot); 
     1440 
     1441        /*Debug << "vsb volume: " << vol << endl; 
    14411442        Debug << "root volume: " << mRoot->GetVolume() << endl; 
    14421443        Debug << "root pvs: " << rootPvs << endl; 
     1444        */ 
    14431445 
    14441446        int totalPvs; 
     
    14601462                << "#TotalRenderCost\n" << totalRenderCost << endl 
    14611463                << "#CurrentPvs\n" << rootPvs << endl 
     1464                << "#CurrentEntries\n" << rootEntries << endl 
    14621465                << "#ExpectedCost\n" << expectedCost << endl 
    14631466                << "#AvgRenderCost\n" << avgRenderCost << endl 
     
    14681471                << endl; 
    14691472 
     1473        //-- go through tree in the order of render cost decrease 
     1474        //-- which is the same order as the view cells were merged 
     1475        //-- or the reverse order of subdivision for subdivision-only  
     1476        //-- view cell hierarchies. 
    14701477 
    14711478        while (!tqueue.empty()) 
     
    16281635} 
    16291636 
    1630 // TODO 
     1637// TODO matt: implement for different storing methods 
    16311638void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const 
    16321639{ 
    1633         // pvs is stored in each cell 
     1640        // pvs is stored in each cell => just return pvs 
    16341641        if (mViewCellsStorage == PVS_IN_INTERIORS) 
    16351642        { 
     
    16381645        } 
    16391646 
     1647 
     1648        //-- pvs is not stored with the interiors => reconstruct 
    16401649        Intersectable::NewMail(); 
    1641  
    16421650 
    16431651        int pvsSize = 0; 
     
    16601668                tstack.pop(); 
    16611669 
    1662                 // add new pvs 
     1670                // add newly found pvs to merged pvs 
    16631671                pvs.AddPvs(vc->GetPvs()); 
    16641672 
    1665                 if (!vc->IsLeaf()) 
     1673                if (!vc->IsLeaf()) // interior cells: go down to leaf level 
    16661674                { 
    16671675                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     
    16851693 
    16861694        //////////////////////////////////////////////// 
    1687         //-- for interiors, pvs can be stored using different methods 
    1688         /////////////////////////////////////////////// 
     1695        //  for interiors, pvs can be stored using different methods 
     1696        // 
    16891697 
    16901698        switch (mViewCellsStorage) 
     
    16971705                                pvsSize = vc->GetPvs().CountPvs(); 
    16981706                        } 
    1699          
     1707                        else // interior node 
     1708                        { 
     1709                                // interior nodes: pvs is either stored as a scalar or 
     1710                                // has to be reconstructed from the leaves 
     1711 
     1712                                // the stored pvs size is the valid pvs size => just return scalar 
     1713                                if (vc->mPvsSizeValid) 
     1714                                { 
     1715                                        pvsSize = vc->mPvsSize; 
     1716                                        break; 
     1717                                } 
     1718                 
     1719                                //-- if no valid pvs size stored as a scalar =>  
     1720                                //-- compute current pvs size of interior from it's leaf nodes 
     1721                                ViewCellContainer leaves; 
     1722                                CollectLeaves(vc, leaves); 
     1723 
     1724                                ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     1725 
     1726                                Intersectable::NewMail(); 
     1727 
     1728                                // sum different intersectables 
     1729                                for (it = leaves.begin(); it != it_end; ++ it) 
     1730                                { 
     1731                                        ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
     1732 
     1733                                        // mail all from first pvs 
     1734                                        for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1735                                        { 
     1736                                                Intersectable *intersect = (*oit).first; 
     1737 
     1738                                                if (!intersect->Mailed()) 
     1739                                                { 
     1740                                                        ++ pvsSize; 
     1741                                                        intersect->Mail();                                       
     1742                                                } 
     1743                                        } 
     1744                                } 
     1745 
     1746                                break; 
     1747                        } 
     1748                } 
     1749        case COMPRESSED: 
     1750                { 
     1751                        //////////////////////// 
     1752                        //-- compressed pvs 
     1753 
    17001754                        // the stored pvs size is the valid pvs size => just return scalar 
    17011755                        if (vc->mPvsSizeValid) 
     
    17041758                                break; 
    17051759                        } 
    1706          
    1707                         //-- if no valid pvs size stored as a scalar => compute new pvs size 
    1708                         ViewCellContainer leaves; 
    1709                         CollectLeaves(vc, leaves); 
    1710  
    1711                         ViewCellContainer::const_iterator it, it_end = leaves.end(); 
    1712  
    1713                         Intersectable::NewMail(); 
    1714  
    1715                         // sum different intersectables 
    1716                         for (it = leaves.begin(); it != it_end; ++ it) 
     1760 
     1761                        // if no pvs size stored, compute new one 
     1762                        int pvsSize = 0; 
     1763                        ViewCell *root = vc; 
     1764         
     1765                        // also add pvs from this view cell to root 
     1766                        while (root->GetParent()) 
    17171767                        { 
    1718                                 ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
    1719  
    1720                                 // mail all from first pvs 
    1721                                 for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1768                                root = root->GetParent(); 
     1769                                // matt: bug! must evaluate kd pvss also 
     1770                                pvsSize += CountDiffPvs(root); 
     1771                        } 
     1772 
     1773                        stack<ViewCell *> tstack; 
     1774                        tstack.push(vc); 
     1775 
     1776                        while (!tstack.empty()) 
     1777                        { 
     1778                                vc = tstack.top(); 
     1779                                tstack.pop(); 
     1780         
     1781                                pvsSize += CountDiffPvs(vc); 
     1782 
     1783                                if (!vc->IsLeaf()) 
    17221784                                { 
    1723                                         Intersectable *intersect = (*oit).first; 
    1724  
    1725                                         if (!intersect->Mailed()) 
     1785                                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1786 
     1787                                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     1788 
     1789                                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    17261790                                        { 
    1727                                                 ++ pvsSize; 
    1728                                                 intersect->Mail();                                       
     1791                                                tstack.push(*it); 
     1792                                        }                
     1793                                } 
     1794                        } 
     1795                        break; 
     1796                } 
     1797        case PVS_IN_INTERIORS: 
     1798        default: 
     1799                // pvs is stored consistently in the tree up to the root 
     1800                // just return pvs size  
     1801                pvsSize = vc->GetPvs().CountPvs();       
     1802                break; 
     1803        } 
     1804 
     1805        return pvsSize;   
     1806} 
     1807 
     1808 
     1809int ViewCellsTree::GetPvsEntries(ViewCell *vc) const 
     1810{ 
     1811        int pvsSize = 0; 
     1812 
     1813        Intersectable::NewMail(); 
     1814 
     1815        //////////////////////////////////////////////// 
     1816        // for interiors, pvs can be stored using different methods 
     1817         
     1818        switch (mViewCellsStorage) 
     1819        { 
     1820        case PVS_IN_LEAVES: //-- store pvs only in leaves 
     1821                {                        
     1822                        // pvs is always stored directly in leaves 
     1823                        if (vc->IsLeaf()) 
     1824                        { 
     1825                                pvsSize = vc->GetPvs().GetSize(); 
     1826                        } 
     1827                        else // interior node 
     1828                        { 
     1829                                // interior nodes: pvs is either stored as a scalar or 
     1830                                // has to be reconstructed from the leaves 
     1831 
     1832                                // the stored pvs size is the valid pvs size => just return scalar 
     1833                                if (vc->mPvsSizeValid) 
     1834                                { 
     1835                                        pvsSize = vc->mPvsSize; 
     1836                                        break; 
     1837                                } 
     1838                 
     1839                                // if no valid pvs size stored as a scalar =>  
     1840                                // compute current pvs size of interior from it's leaf nodes 
     1841                                ViewCellContainer leaves; 
     1842                                CollectLeaves(vc, leaves); 
     1843 
     1844                                ViewCellContainer::const_iterator it, it_end = leaves.end(); 
     1845 
     1846                                Intersectable::NewMail(); 
     1847 
     1848                                // sum different intersectables 
     1849                                for (it = leaves.begin(); it != it_end; ++ it) 
     1850                                { 
     1851                                        ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end(); 
     1852 
     1853                                        // mail all from first pvs 
     1854                                        for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
     1855                                        { 
     1856                                                Intersectable *intersect = (*oit).first; 
     1857 
     1858                                                if (!intersect->Mailed()) 
     1859                                                { 
     1860                                                        ++ pvsSize; 
     1861                                                        intersect->Mail();                                       
     1862                                                } 
    17291863                                        } 
    17301864                                } 
    1731                         } 
    1732  
    1733                         break; 
     1865 
     1866                                break; 
     1867                        } 
    17341868                } 
    17351869        case COMPRESSED: 
     
    17381872                        //-- compressed pvs 
    17391873 
     1874                        // the stored pvs size is the valid pvs size => just return scalar 
    17401875                        if (vc->mPvsSizeValid) 
    17411876                        { 
    1742                                 return vc->mPvsSize; 
     1877                                pvsSize = vc->mPvsSize; 
     1878                                break; 
    17431879                        } 
    17441880 
     
    17801916        case PVS_IN_INTERIORS: 
    17811917        default: 
    1782                 Debug << "in interiors: " << vc->mPvsSize << " $$ " << vc->GetPvs().CountPvs() << endl; 
    1783                 pvsSize = vc->GetPvs().CountPvs();               
     1918                // pvs is stored consistently in the tree up to the root 
     1919                // just return pvs size  
     1920                pvsSize = vc->GetPvs().GetSize();        
     1921                break; 
    17841922        } 
    17851923 
     
    17931931                sizeof(PvsData<Intersectable *>) + sizeof(Intersectable *); 
    17941932 
    1795         return (float)GetNumPvsEntries(vc) * entrySize; 
    1796 } 
    1797  
    1798  
    1799 int ViewCellsTree::GetNumPvsEntries(ViewCell *vc) const 
    1800 { 
    1801         int pvsSize = 0; 
    1802         // only count leaves for uncompressed method for fairness 
    1803         if ((mViewCellsStorage == PVS_IN_INTERIORS) || vc->IsLeaf()) 
    1804         { 
    1805                 pvsSize = vc->GetPvs().CountPvs(); 
    1806         } 
    1807  
    1808         if (!vc->IsLeaf()) 
    1809         { 
    1810                 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     1933        return (float)GetStoredPvsEntriesNum(vc) * entrySize; 
     1934} 
     1935 
     1936 
     1937int ViewCellsTree::GetStoredPvsEntriesNum(ViewCell *root) const 
     1938{ 
     1939        int pvsSize = root->GetPvs().GetSize(); 
     1940 
     1941        // recursivly count leaves 
     1942        if (!root->IsLeaf()) 
     1943        { 
     1944                ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root); 
    18111945 
    18121946                ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     
    18141948                for (it = interior->mChildren.begin(); it != it_end; ++ it) 
    18151949                { 
    1816                         pvsSize += GetNumPvsEntries(*it); 
     1950                        pvsSize += GetStoredPvsEntriesNum(*it); 
    18171951                } 
    18181952        } 
     
    19262060 
    19272061 
    1928 /** Get costs resulting from each merge step. */ 
     2062/** Get costs resulting from each merge step.  
     2063*/ 
    19292064void 
    19302065ViewCellsTree::GetCostFunction(vector<float> &costFunction) 
    19312066{ 
    1932   TraversalQueue tqueue; 
    1933   tqueue.push(mRoot); 
    1934   while (!tqueue.empty()) { 
    1935         ViewCell *vc = tqueue.top(); 
    1936         tqueue.pop(); 
    1937         // save the view cells if it is a leaf or if enough view cells have already been traversed 
    1938         // because of the priority queue, this will be the optimal set of v 
    1939         if (!vc->IsLeaf()) {     
    1940           ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
    1941           costFunction.push_back(interior->GetMergeCost()); 
    1942            
    1943           ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    1944            
    1945           for (it = interior->mChildren.begin(); it != it_end; ++ it) { 
    1946                 tqueue.push(*it); 
    1947           } 
    1948            
    1949         } 
    1950   } 
    1951 } 
    1952  
    1953  
    1954 void  ViewCellsTree::UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat) 
     2067        TraversalQueue tqueue; 
     2068        tqueue.push(mRoot); 
     2069         
     2070        while (!tqueue.empty())  
     2071        { 
     2072                ViewCell *vc = tqueue.top(); 
     2073                tqueue.pop(); 
     2074                // save the view cells if it is a leaf or if enough view cells have already been traversed 
     2075                // because of the priority queue, this will be the optimal set of v 
     2076                if (!vc->IsLeaf()) {     
     2077                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     2078                        costFunction.push_back(interior->GetMergeCost()); 
     2079 
     2080                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
     2081 
     2082                        for (it = interior->mChildren.begin(); it != it_end; ++ it) { 
     2083                                tqueue.push(*it); 
     2084                        } 
     2085 
     2086                } 
     2087        } 
     2088} 
     2089 
     2090 
     2091void ViewCellsTree::UpdateViewCellsStats(ViewCell *vc,  
     2092                                                                                 ViewCellsStatistics &vcStat) 
    19552093{ 
    19562094        ++ vcStat.viewCells; 
     
    19722110                ++ vcStat.invalid; 
    19732111} 
     2112 
    19742113 
    19752114#if ZIPPED_VIEWCELLS 
     
    20042143                { 
    20052144                        ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 
     2145                         
    20062146                        ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 
    20072147                        for (it = interior->mChildren.begin(); it != it_end; ++ it) 
Note: See TracChangeset for help on using the changeset viewer.