Changeset 1161


Ignore:
Timestamp:
07/27/06 02:07:26 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
6 edited

Legend:

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

    r1159 r1161  
    22252225                                        optInt, 
    22262226                                        "vsp_max_tests=", 
    2227                                         "2000"); 
     2227                                        "5000"); 
    22282228 
    22292229 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h

    r1151 r1161  
    77#include "Renderer.h" 
    88#include "Beam.h" 
     9#include "Pvs.h" 
    910 
    1011 
     
    6768  // visible pixels 
    6869  int mVisiblePixels; 
     70 
     71  ObjectPvs mPvs; 
    6972   
    7073}; 
  • 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) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1160 r1161  
    279279        /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 
    280280        int mPvsSize; 
    281         // stores number of entries in pvs 
     281        /** stores number of entries in pvs 
     282            this variable has the same value as mPvsSize for object pvs,  
     283                but usually not for kd cell based pvs 
     284        */ 
    282285        int mEntriesInPvs; 
    283286 
    284         /// if the pvs size scalar is up to date and corresponding to the real pvs size 
     287        /// if the pvs size scalar (+ entries into pvs) 
     288        /// is up to date and corresponding to the real pvs size 
    285289        bool mPvsSizeValid; 
    286290         
     
    440444        void GetPvs(ViewCell *vc, ObjectPvs &pvs) const; 
    441445 
    442         /** Returns pvs size (i.e. the number of entries weighted by their "importance". 
     446        /** Returns pvs size (i.e. the number of stored objects 
    443447        */ 
    444448        int GetPvsSize(ViewCell *vc) const; 
    445449 
    446         /** Returns actual number of object in this pvs and the children. 
    447         */ 
    448         int GetNumPvsEntries(ViewCell *vc) const; 
     450        /** Returns number of entries associated with this view cell.  
     451                This returns the same value as the GetPvsSize function for object pvs, 
     452                but most likely different values for kd node based pvs. 
     453        */ 
     454        int GetPvsEntries(ViewCell *vc) const; 
     455 
     456        /** Returns the actual number of stored entries in the view cells sub tree. 
     457        */ 
     458        int GetStoredPvsEntriesNum(ViewCell *root) const; 
    449459 
    450460        /** Returns memory cost of this view cell. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1160 r1161  
    39853985        if (ViewCellsTreeConstructed() && mCompressViewCells) 
    39863986        { 
    3987                 int pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 
     3987                int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
    39883988                Debug << "number of entries before compress: " << pvsEntries << endl; 
    39893989 
    39903990                mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 
    39913991 
    3992                 pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 
     3992                pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
    39933993                Debug << "number of entries after compress: " << pvsEntries << endl; 
    39943994        } 
     
    45894589{ 
    45904590        int numSamples; 
    4591  
     4591         
    45924592        Environment::GetSingleton()->GetIntValue("RenderSampler.samples", numSamples); 
    45934593        cout << "samples" << numSamples << endl; 
     
    46074607 
    46084608 
    4609         // counting the pvss 
     4609        // for each sample: 
     4610        //    find view cells associated with the samples 
     4611        //    store the sample pvs with the pvs associated with the view cell 
     4612        // for each view cell: 
     4613        //    compute difference point sampled pvs - view cell pvs 
     4614        //    export geometry with color coded pvs difference 
     4615         
     4616    std::map<ViewCell *, ObjectPvs> sampleMap; 
     4617 
    46104618        vector<RenderCostSample>::const_iterator rit, rit_end = samples.end(); 
    46114619 
    4612         //std::map<ViewCell *, ObjectPvs> sampleMap; 
    4613  
     4620        for (rit = samples.begin(); rit != rit_end; ++ rit) 
     4621        { 
     4622                RenderCostSample sample = *rit; 
     4623         
     4624                ViewCell *vc = GetViewCell(sample.mPosition); 
     4625 
     4626                std::map<ViewCell *, ObjectPvs>::iterator it = sampleMap.find(vc); 
     4627 
     4628                if (it == sampleMap.end()) 
     4629                { 
     4630                        sampleMap[vc] = sample.mPvs; 
     4631                } 
     4632                else 
     4633                { 
     4634                        (*it).second.Merge(sample.mPvs); 
     4635                } 
     4636        } 
     4637 
     4638        // visualize the view cells 
     4639        std::map<ViewCell *, ObjectPvs>::const_iterator vit, vit_end = sampleMap.end(); 
     4640 
     4641        Material m;//= RandomMaterial(); 
     4642 
     4643        for (vit = sampleMap.begin(); vit != vit_end; ++ vit) 
     4644        { 
     4645                ViewCell *vc = (*vit).first; 
     4646                 
     4647                const int pvsVc = mViewCellsTree->GetPvsEntries(vc); 
     4648                const int pvs2 = (*vit).second.GetSize(); 
     4649 
     4650        m.mDiffuseColor.r = (float) (pvsVc - pvs2); 
     4651                m.mDiffuseColor.b = 1.0f; 
     4652                //exporter->SetForcedMaterial(m); 
     4653 
     4654//              ExportViewCellGeometry(exporter, vc, mClipPlane); 
     4655 
     4656/*      // counting the pvss 
    46144657        for (rit = samples.begin(); rit != rit_end; ++ rit) 
    46154658        { 
     
    46224665                 
    46234666                DEL_PTR(hMesh); 
    4624 #if 0 
    4625                 if (!sampleMap.find(vc)) 
    4626                         sampleMap.insert(vc, sample.mVisibleObjects); 
    4627                 else 
    4628                         sampleMap[vc].Merge(Merge(sample.mVisibleObjects); 
    4629 #endif 
     4667 
     4668*/ 
    46304669        } 
    46314670} 
     
    50445083        if (ViewCellsTreeConstructed() && mCompressViewCells) 
    50455084        { 
    5046                 int pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 
     5085                int pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
    50475086                Debug << "number of entries before compress: " << pvsEntries << endl; 
    50485087 
    50495088                mViewCellsTree->SetViewCellsStorage(ViewCellsTree::COMPRESSED); 
    50505089 
    5051                 pvsEntries = mViewCellsTree->GetNumPvsEntries(mViewCellsTree->GetRoot()); 
     5090                pvsEntries = mViewCellsTree->GetStoredPvsEntriesNum(mViewCellsTree->GetRoot()); 
    50525091                Debug << "number of entries after compress: " << pvsEntries << endl; 
    50535092        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r1145 r1161  
    484484 
    485485// if the view cells should be exported and inported as gzstream 
    486 #define ZIPPED_VIEWCELLS 0 
    487  
    488 #endif 
    489  
    490  
    491  
    492  
    493  
    494  
    495  
    496  
    497  
    498  
    499  
     486#define ZIPPED_VIEWCELLS 1 
     487 
     488#endif 
     489 
     490 
     491 
     492 
     493 
     494 
     495 
     496 
     497 
     498 
     499 
Note: See TracChangeset for help on using the changeset viewer.