Changeset 452


Ignore:
Timestamp:
12/05/05 20:33:53 (19 years ago)
Author:
mattausch
Message:

started to add view cell merging to vsp kd tree

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env

    r451 r452  
    1919 
    2020Preprocessor { 
    21         type sampling 
    22 #       type vss 
     21#       type sampling 
     22        type vss 
    2323#       type rss 
    2424} 
    2525 
    2626VssPreprocessor { 
    27         samplesPerPass  100000 
    28         initialSamples 500000 
    29         vssSamples 1000000 
    30         vssSamplesPerPass 50000 
     27        samplesPerPass  10000 
     28        initialSamples 100000 
     29        vssSamples 300000 
     30        vssSamplesPerPass 10000 
    3131        useImportanceSampling true 
    3232} 
     
    6464RssPreprocessor { 
    6565        samplesPerPass  100000 
    66         initialSamples 500000 
    67         vssSamples 5000000 
     66        initialSamples 400000 
     67        vssSamples 1000000 
    6868        vssSamplesPerPass 100000 
    6969        useImportanceSampling true 
     
    279279 
    280280        Construction { 
    281                 samples 100000 
     281                samples 300000 
    282282        } 
    283283         
    284284        Termination { 
    285285                maxDepth                40 
    286                 minPvs                  50 
    287                 minRays                 1 
     286                minPvs                  40 
     287                minRays                 100 
    288288                minSize                 0.1 
    289289                maxCostRatio            999.0 
     
    330330        Termination { 
    331331                # parameters used for autopartition 
    332                 minRays 200 
     332                minRays 100 
    333333                minPolygons -1 
    334                 maxDepth 40 
     334                maxDepth 30 
    335335                minPvs 100 
    336336                minArea 0.01 
  • trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp

    r451 r452  
    1010#include "RssTree.h" 
    1111#include "ViewCellsManager.h" 
    12  
    13 static bool useViewSpaceBox = true;//true; 
     12#include "RenderSimulator.h" 
     13 
     14static bool useViewSpaceBox = true; 
    1415static bool use2dSampling = false; 
    1516static bool fromBoxVisibility = true; 
     
    423424          Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 
    424425                         
    425           CastRay(viewpoint, direction, mVssRays); 
     426          sampleContributions = CastRay(viewpoint, direction, mVssRays); 
    426427                         
    427428                         
     
    587588        cout<<"*****************************\n"; 
    588589        cout<<samples<<" avgPVS ="<<pvs<<endl; 
     590        cout<<"sample contributions ="<<sampleContributions<<endl; 
     591        cout<<"contributing sample ="<<contributingSamples<<endl; 
    589592        cout<<"RssTree root PVS size = "<<rssTree->GetRootPvsSize()<<endl; 
    590593        cout<<"*****************************\n"; 
     
    603606  } 
    604607   
     608  //-- post process view cells 
     609  mViewCellsManager->PostProcess(mObjects, storedRays); 
     610 
     611  //-- several visualizations and statistics 
     612  Debug << "===== Final view cells statistics ==========" << endl; 
     613 
     614  mViewCellsManager->PrintStatistics(Debug); 
     615 
     616  //-- render simulation after merge 
     617  cout << "\nevaluating render time of final view cells ... "; 
     618                  
     619  const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
     620                  
     621  cout << " finished" << endl; 
     622 
     623  cout << ss << endl; 
     624  Debug << ss << endl; 
     625 
     626  mViewCellsManager->Visualize(mObjects, storedRays); 
     627 
    605628  delete rssTree; 
    606629   
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r451 r452  
    390390                delete exporter; 
    391391        } 
    392  
    393         //-- post process view cells 
     392         
     393        // construct view cells if not already constructed 
     394        if (!mViewCellsManager->ViewCellsConstructed()) 
     395                mViewCellsManager->Construct(objects, mVssSampleRays); 
     396 
    394397        mViewCellsManager->PostProcess(objects, mSampleRays); 
    395                  
    396  
     398         
    397399        //-- several visualizations and statistics 
    398                   
     400        Debug << "===== Final view cells statistics ==========" << endl; 
     401 
     402        mViewCellsManager->PrintStatistics(Debug); 
     403 
    399404        //-- render simulation after merge 
    400405        cout << "\nevaluating bsp view cells render time after merge ... "; 
     
    406411        Debug << ss << endl; 
    407412         
    408  
    409413        mViewCellsManager->Visualize(objects, mSampleRays);      
    410414     
     
    423427        if (!mViewCellsManager->ViewCellsConstructed()) 
    424428        { 
    425                 RayContainer::const_iterator it, it_end = newRays.end(); 
    426  
    427                 if ((int)mVssSampleRays.size() <  
    428                         mViewCellsManager->GetConstructionSamples()) 
     429                if ((int)mVssSampleRays.size() < mViewCellsManager->GetConstructionSamples()) 
    429430                { 
     431                        RayContainer::const_iterator it, it_end = newRays.end(); 
     432 
    430433                        for (it = newRays.begin(); it != it_end; ++ it) 
    431                         { 
    432434                                mVssSampleRays.push_back(new VssRay(*(*it))); 
    433                         } 
    434435                } 
    435436                else 
     
    443444        } 
    444445        // Need rays (with ordered intersections) for post processing => collect new rays 
    445         else if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
    446                         ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 
     446        if (((int)mSampleRays.size() < mViewCellsManager->GetPostProcessSamples()) || 
     447            ((int)mSampleRays.size() < mViewCellsManager->GetVisualizationSamples())) 
    447448        { 
    448449                RayContainer::const_iterator it, it_end = newRays.end(); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp

    r450 r452  
    15891589 
    15901590                // give penalty to unbalanced split 
    1591                 if (1) 
     1591                if (0) 
    15921592                if (((pFront * 0.2 + Limits::Small) > pBack) ||  
    15931593                        (pFront < (pBack * 0.2 + Limits::Small))) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp

    r449 r452  
    7878        RayContainer::const_iterator it, it_end = rays.end(); 
    7979 
     80        sampleContributions = 0; 
     81        contributingSamples = 0; 
     82 
    8083    for (it = rays.begin(); it != it_end; ++ it) 
    8184        { 
     
    329332        } 
    330333 
    331  
    332334        //-- post processing of bsp view cells 
    333335    int vcSize = 0; 
     
    420422                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    421423 
    422         // statistics after post process 
    423         vcStats.Reset(); 
    424         mBspTree->EvaluateViewCellsStats(vcStats); 
    425         Debug << "post processed view cell partition:\n" << vcStats << endl; 
    426  
    427424        return merged; 
    428425} 
     
    775772} 
    776773 
    777  
     774void BspViewCellsManager::PrintStatistics(ostream &s) const 
     775{ 
     776        BspViewCellsStatistics vcStats; 
     777        mBspTree->EvaluateViewCellsStats(vcStats); 
     778        s << vcStats << endl; 
     779} 
    778780 
    779781/**********************************************************************/ 
     
    963965 
    964966 
     967void KdViewCellsManager::PrintStatistics(ostream &s) const 
     968{ 
     969} 
    965970 
    966971/**********************************************************************/ 
     
    983988        if (ViewCellsConstructed()) 
    984989                return 0; 
    985  
     990                 
     991        VssRayContainer sampleRays; 
     992 
     993        int limit = min (mConstructionSamples, (int)rays.size()); 
     994 
     995    for (int i = 0; i < limit; ++ i) 
     996                sampleRays.push_back(rays[i]); 
     997 
     998        Debug << "constructing vsp kd tree using " << (int)sampleRays.size() << " samples" << endl; 
    986999        mVspKdTree->Construct(rays, sceneBbox); 
     1000 
     1001        Debug << mVspKdTree->GetStatistics() << endl; 
     1002 
    9871003        return 0; 
    9881004} 
     
    10221038                return; 
    10231039 
     1040        //-- export tree leaves 
    10241041        if (1) 
    10251042        { 
     
    10331050                        exporter->ExportGeometry(objects); 
    10341051 
    1035                 bool exportRays = true; 
     1052                bool exportRays = false; 
    10361053 
    10371054                if (exportRays)  
     
    10861103 
    10871104                        for (it = vssRays.begin(); it != it_end; ++ it) 
    1088                         { 
    1089                                 //if (!(*it)->mOriginObject && !(*it)->mTerminationObject) 
    1090                                         rays.push_back(*it); 
    1091  
    1092                                 //if (!(*it)->mOriginObject && !(*it)->mTerminationObject) 
    1093                                 //      Debug << "ERR: " << (*it)->mOrigin << " " << (*it)->mTermination << endl; 
    1094                         } 
    1095  
     1105                                rays.push_back(*it); 
     1106                         
    10961107                        exporter->ExportRays(rays, RgbColor(1, 0, 0)); 
    10971108 
     
    11121123} 
    11131124 
     1125void VspKdViewCellsManager::PrintStatistics(ostream &s) const 
     1126{ 
     1127} 
     1128 
    11141129 
    11151130/**********************************************************************/ 
     
    12311246        int pvsSize = 0; 
    12321247 
     1248         
    12331249        BspViewCellsStatistics vcStats; 
    12341250        mVspBspTree->EvaluateViewCellsStats(vcStats); 
     
    13071323                 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl; 
    13081324 
    1309         // statistics after post process 
    1310         vcStats.Reset(); 
    1311         mVspBspTree->EvaluateViewCellsStats(vcStats); 
    1312         Debug << "post processed view cell partition:\n" << vcStats << endl; 
    13131325 
    13141326        return merged; 
     
    14291441                        RayContainer vcRays; 
    14301442                        cout << "creating output for view cell " << i << " ... "; 
     1443                         
    14311444                        // check whether we can add the current ray to the output rays 
    1432                         /*for (int k = 0; k < raysOut; ++ k)  
     1445                        for (int k = 0; k < raysOut; ++ k)  
    14331446                        { 
    14341447                                Ray *ray = sampleRays[k]; 
     
    14441457                                } 
    14451458                        } 
    1446                         */ 
     1459                         
    14471460 
    14481461                        Intersectable::NewMail(); 
     
    16131626 
    16141627 
     1628void VspBspViewCellsManager::PrintStatistics(ostream &s) const 
     1629{ 
     1630        BspViewCellsStatistics vcStats; 
     1631        mVspBspTree->EvaluateViewCellsStats(vcStats); 
     1632        s << vcStats << endl; 
     1633} 
     1634 
    16151635bool VspBspViewCellsManager::MergeVspBspLeafViewCells(BspLeaf *front,  
    16161636                                                                                                          BspLeaf *back) const 
  • trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h

    r448 r452  
    7171        virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0; 
    7272 
     73        /** Prints out statistics of the view cells. 
     74        */ 
     75        virtual void PrintStatistics(ostream &s) const = 0; 
     76 
    7377        /** Post processes view cells givemŽa number of rays. 
    7478        */ 
     
    215219        bool ViewCellsConstructed() const; 
    216220 
     221        void PrintStatistics(ostream &s) const; 
     222 
    217223protected: 
    218224 
     
    269275 
    270276 
     277        /** Prints out statistics of this approach. 
     278        */ 
     279        virtual void PrintStatistics(ostream &s) const; 
     280 
    271281protected: 
    272282 
     
    309319        bool ViewCellsConstructed() const; 
    310320 
     321        virtual void PrintStatistics(ostream &s) const; 
    311322 
    312323protected: 
     
    346357        bool ViewCellsConstructed() const; 
    347358 
     359        void PrintStatistics(ostream &s) const; 
     360 
    348361protected: 
    349362 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r450 r452  
    946946 
    947947                // give penalty to unbalanced split 
    948                 if (1) 
     948                if (0) 
    949949                if (((pFront * 0.2 + Limits::Small) > pBack) ||  
    950950                        (pFront < (pBack * 0.2 + Limits::Small))) 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp

    r449 r452  
    180180/**************************************************************/ 
    181181VspKdTreeLeaf::VspKdTreeLeaf(VspKdTreeInterior *p,      const int nRays): 
    182 VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false)  
     182VspKdTreeNode(p), mRays(), mPvsSize(0), mValidPvs(false), mViewCell(NULL) 
    183183{ 
    184184        mRays.reserve(nRays); 
     
    447447VspKdTree::Construct(const VssRayContainer &rays, 
    448448                                         AxisAlignedBox3 *forcedBoundingBox) 
    449 {Debug << "here888" << endl; 
     449{ 
    450450        mStat.Start(); 
    451   Debug << "here1000" << endl; 
     451  
    452452        mMaxMemory = mMaxStaticMemory; 
    453         Debug << "here1" << endl; 
    454453        DEL_PTR(mRoot); 
    455454 
     
    461460        mStat.nodes = 1; 
    462461        mBox.Initialize(); 
    463 Debug << "here2" << endl; 
     462 
    464463        //-- compute bounding box 
    465464        if (forcedBoundingBox) 
     
    468467                for (VssRayContainer::const_iterator ri = rays.begin(); ri != rays.end(); ++ ri) 
    469468                { 
    470                         mBox.Include((*ri)->GetOrigin()); 
    471                         mBox.Include((*ri)->GetTermination());  
     469                        if ((*ri)->mOriginObject) 
     470                mBox.Include((*ri)->GetOrigin()); 
     471                        if ((*ri)->mTerminationObject) 
     472                                mBox.Include((*ri)->GetTermination());  
    472473                } 
    473474 
     
    676677        }        
    677678 
    678         float ratio = 0; 
    679          
    680679        if (0) 
    681680        { 
     
    702701                const float oldCost = (float)pvsSize; 
    703702                 
    704                 float ratio = newCost / oldCost; 
    705         } 
    706          
    707         return ratio; 
     703                return newCost / oldCost; 
     704        } 
    708705} 
    709706 
     
    731728                if (!mOnlyDrivingAxis || axis == sAxis)  
    732729                { 
     730                         
    733731                        nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis]) * 0.5f; 
    734732                                                 
     
    740738                                                                                         nPvsBack[axis], 
    741739                                                                                         nPvsFront[axis]); 
     740                        if (bestAxis == -1) 
     741                        { 
     742                                bestAxis = axis; 
     743                        } 
     744                        else if (nCostRatio[axis] < nCostRatio[bestAxis]) 
     745                        { 
     746                                /*Debug << "pvs front " << nPvsBack[axis]  
     747                                          << " pvs back " << nPvsFront[axis] 
     748                                          << " overall pvs " << leaf->GetPvsSize() << endl;*/ 
     749                                bestAxis = axis; 
     750                        } 
    742751                         
    743                         if (bestAxis == -1) 
    744                                 bestAxis = axis; 
    745                         else 
    746                                 if (nCostRatio[axis] < nCostRatio[bestAxis]) 
    747                                 { 
    748                                         Debug << "pvs front " << nPvsBack[axis] 
    749                                                   << " pvs back " << nPvsFront[axis] 
    750                                                   << " overall pvs " << leaf->GetPvsSize() << endl; 
    751                                         bestAxis = axis; 
    752                                 } 
    753752                } 
    754753        } 
     
    17861785        } 
    17871786} 
     1787 
     1788int VspKdTree::FindNeighbors(VspKdTreeLeaf *n, 
     1789                                                         vector<VspKdTreeLeaf *> &neighbors, 
     1790                                                         bool onlyUnmailed) 
     1791{ 
     1792        stack<VspKdTreeNode *> nodeStack; 
     1793   
     1794        nodeStack.push(mRoot); 
     1795 
     1796        AxisAlignedBox3 box = GetBBox(n); 
     1797 
     1798        while (!nodeStack.empty())  
     1799        { 
     1800                VspKdTreeNode *node = nodeStack.top(); 
     1801                nodeStack.pop(); 
     1802 
     1803                if (node->IsLeaf())  
     1804                { 
     1805                        VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node); 
     1806 
     1807                        if (leaf != n && (!onlyUnmailed || !leaf->Mailed()))  
     1808                                neighbors.push_back(leaf); 
     1809                }  
     1810                else  
     1811                { 
     1812                        VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node); 
     1813 
     1814                        if (interior->mPosition > box.Max(interior->mAxis)) 
     1815                                nodeStack.push(interior->mBack); 
     1816                        else 
     1817                        { 
     1818                                if (interior->mPosition < box.Min(interior->mAxis)) 
     1819                                        nodeStack.push(interior->mFront); 
     1820                                else  
     1821                                { 
     1822                                        // random decision 
     1823                                        nodeStack.push(interior->mBack); 
     1824                                        nodeStack.push(interior->mFront); 
     1825                                } 
     1826                        } 
     1827                } 
     1828        } 
     1829 
     1830        return (int)neighbors.size(); 
     1831} 
     1832 
     1833void VspKdTree::MergeLeaves() 
     1834{ 
     1835        vector<VspKdTreeLeaf *> leaves; 
     1836        priority_queue<LeafPair> mergeCandidates; 
     1837        vector<VspKdTreeLeaf *> neighbors; 
     1838 
     1839        CollectLeaves(leaves); 
     1840 
     1841        VspKdTreeLeaf::NewMail(); 
     1842 
     1843        vector<VspKdTreeLeaf *>::const_iterator it, it_end = leaves.end(); 
     1844 
     1845 
     1846        for (it = leaves.begin(); it != it_end; ++ it) 
     1847        { 
     1848                VspKdTreeLeaf *leaf = *it; 
     1849 
     1850                if (!leaf->Mailed()) 
     1851                { 
     1852                        FindNeighbors(leaf, neighbors, true); 
     1853 
     1854                        vector<VspKdTreeLeaf *>::const_iterator nit, nit_end = neighbors.end(); 
     1855 
     1856                        for (nit = neighbors.begin(); nit != neighbors.end(); ++ nit) 
     1857                                mergeCandidates.push(LeafPair(leaf, *nit)); 
     1858                         
     1859                        leaf->Mail(); 
     1860                } 
     1861        } 
     1862} 
     1863 
     1864 
     1865 
     1866/*********************************************************************/ 
     1867/*                MergeCandidate implementation                      */ 
     1868/*********************************************************************/ 
     1869 
     1870 
     1871MergeCandidate::MergeCandidate(VspKdTreeLeaf *l1, VspKdTreeLeaf *l2): 
     1872mLeaf1(l1), mLeaf2(l2) 
     1873{} 
     1874 
     1875int MergeCandidate::ComputePvsDifference() const 
     1876{ 
     1877        return 0; 
     1878} 
     1879 
     1880float MergeCandidate::EvaluateMergeCost() const 
     1881{ 
     1882        return 0; 
     1883} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h

    r440 r452  
    3333#include "RayInfo.h" 
    3434#include "Containers.h" 
     35 
     36class VspKdTreeLeaf; 
     37 
     38/** 
     39        Candidate for leaf merging based on priority. 
     40*/ 
     41class MergeCandidate 
     42 
     43public: 
     44        VspKdTreeLeaf *mLeaf1; 
     45        VspKdTreeLeaf *mLeaf2; 
     46 
     47        MergeCandidate(VspKdTreeLeaf *l1, VspKdTreeLeaf *l2); 
     48 
     49        /** Computes PVS difference between the leaves. 
     50        */ 
     51        int ComputePvsDifference() const; 
     52 
     53        /** Evaluates the merge costs of this leaf. 
     54        */ 
     55        float EvaluateMergeCost() const; 
     56 
     57        friend bool operator<(const MergeCandidate &leafa, const MergeCandidate &leafb)  
     58        { 
     59                return leafa.ComputePvsDifference() < leafb.ComputePvsDifference(); 
     60        } 
     61}; 
     62 
     63 
    3564 
    3665/** 
     
    294323        static int mailID; 
    295324 
    296  
    297325protected: 
    298326 
     
    306334        RayInfoContainer mRays; 
    307335        bool mValidPvs; 
    308          
     336 
     337        ViewCell *mViewCell; 
    309338private: 
    310339        int mPvsSize; 
     
    453482        void CollectLeaves(vector<VspKdTreeLeaf *> &leaves) const; 
    454483 
     484        /** Merges leaves of this tree according to some criteria. 
     485        */ 
     486        void MergeLeaves(); 
     487 
     488        /** Finds neighbours of this node. 
     489                @param n the input node 
     490                @param neighbours the neighbors of the input node 
     491                @param onlyUnmailed if only unmailed neighbors are collected 
     492        */ 
     493        int FindNeighbors(VspKdTreeLeaf *n,  
     494                                          vector<VspKdTreeLeaf *> &neighbors,  
     495                                          bool onlyUnmailed); 
     496 
    455497protected: 
    456498 
     
    547589 
    548590protected: 
     591         
     592 
    549593        ///////////////////////////// 
    550594        // The core pointer 
     
    610654        float mTermMaxRayContribution; 
    611655 
    612  
    613656        bool mOnlyDrivingAxis; 
     657 
     658        typedef std::pair<VspKdTreeLeaf *, VspKdTreeLeaf *> LeafPair; 
     659 
    614660        ///////////////////////////// 
    615661        VspKdStatistics mStat;   
  • trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp

    r451 r452  
    1010#include "VssTree.h" 
    1111#include "ViewCellsManager.h" 
     12#include "RenderSimulator.h" 
    1213 
    1314bool useViewSpaceBox = true;//true; 
     
    440441  cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 
    441442         
    442   int numExportRays = 10000; 
    443   // int numExportRays = 0; 
     443  //int numExportRays = 10000; 
     444  int numExportRays = 0; 
    444445 
    445446  if (numExportRays) { 
     
    564565        cout<<"*****************************\n"; 
    565566        cout<<samples<<" avgPVS ="<<pvs<<endl; 
     567        cout<<"sample contributions ="<<sampleContributions<<endl; 
     568        cout<<"contributing sample ="<<contributingSamples<<endl; 
    566569        cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 
    567570        cout<<"*****************************\n"; 
     
    573576  //-- post process view cells 
    574577  mViewCellsManager->PostProcess(objects, storedRays); 
     578 
     579  //-- several visualizations and statistics 
     580  Debug << "===== Final view cells statistics ==========" << endl; 
     581 
     582  mViewCellsManager->PrintStatistics(Debug); 
     583 
     584  //-- render simulation after merge 
     585  cout << "\nevaluating bsp view cells render time after merge ... "; 
     586                  
     587  const SimulationStatistics ss = mViewCellsManager->SimulateRendering(); 
     588                  
     589  cout << " finished" << endl; 
     590  cout << ss << endl; 
     591  Debug << ss << endl; 
     592 
    575593  mViewCellsManager->Visualize(objects, storedRays); 
    576594 
    577595  CLEAR_CONTAINER(storedRays); 
    578  
     596   
    579597  delete vssTree; 
    580598 
Note: See TracChangeset for help on using the changeset viewer.