Changeset 1548


Ignore:
Timestamp:
10/02/06 08:38:25 (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/BvHierarchy.cpp

    r1522 r1548  
    16631663        mBvhStats.Reset(); 
    16641664        mBvhStats.Start(); 
    1665  
    16661665        mBvhStats.nodes = 1; 
    16671666                 
     
    16691668        BvhSubdivisionCandidate::sBvHierarchy = this; 
    16701669         
     1670        // create new root 
     1671        CreateRoot(objects); 
     1672 
    16711673        // compute bounding box from objects 
    1672         // note: we assume that root was already created 
    16731674        mBoundingBox = mRoot->GetBoundingBox(); 
    1674         BvhLeaf *bvhleaf = dynamic_cast<BvhLeaf *>(mRoot); 
     1675        BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot); 
    16751676 
    16761677        // multiply termination criterium for comparison, 
     
    16931694 
    16941695        // create bvh traversal data 
    1695         BvhTraversalData oData(bvhleaf, 0, prop, nRays); 
     1696        BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 
    16961697 
    16971698        // create sorted object lists for the first data 
     
    17091710 
    17101711        EvalSubdivisionCandidate(*oSubdivisionCandidate); 
    1711         bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate); 
     1712        bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 
    17121713 
    17131714        const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 
     
    17841785 
    17851786 
     1787SubdivisionCandidate *BvHierarchy::Reset(const VssRayContainer &sampleRays,  
     1788                                                                                 const ObjectContainer &objects) 
     1789{ 
     1790        // reset stats 
     1791        mBvhStats.Reset(); 
     1792        mBvhStats.Start(); 
     1793        mBvhStats.nodes = 1; 
     1794 
     1795        // reset root 
     1796        DEL_PTR(mRoot); 
     1797        CreateRoot(objects); 
     1798         
     1799#if PROBABILIY_IS_BV_VOLUME 
     1800        mTermMinProbability *= mBoundingBox.GetVolume(); 
     1801        // probability that bounding volume is seen 
     1802        const float prop = GetBoundingBox().GetVolume(); 
     1803#else 
     1804        mTermMinProbability *= mVspTree->GetBoundingBox().GetVolume(); 
     1805        // probability that volume is "seen" from the view cells 
     1806        const float prop = EvalViewCellsVolume(objects); 
     1807#endif 
     1808 
     1809        const int nRays = CountRays(objects); 
     1810        BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot); 
     1811 
     1812        // create bvh traversal data 
     1813        BvhTraversalData oData(bvhLeaf, 0, prop, nRays); 
     1814 
     1815        /////////////////// 
     1816        //-- add first candidate for object space partition      
     1817 
     1818        BvhSubdivisionCandidate *oSubdivisionCandidate =  
     1819                new BvhSubdivisionCandidate(oData); 
     1820 
     1821        EvalSubdivisionCandidate(*oSubdivisionCandidate); 
     1822        bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 
     1823 
     1824        const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume(); 
     1825        mTotalCost = (float)objects.size() * prop / viewSpaceVol; 
     1826 
     1827        PrintSubdivisionStats(*oSubdivisionCandidate); 
     1828 
     1829        return oSubdivisionCandidate; 
     1830} 
     1831 
     1832 
    17861833void BvhStatistics::Print(ostream &app) const 
    17871834{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1486 r1548  
    646646        float GetMemUsage() const; 
    647647 
    648         /** Creates new root of hierarchy. 
    649         */ 
    650         void CreateRoot(const ObjectContainer &objects); 
    651  
     648        /** Associates the objects with their bvh leaves. 
     649        */ 
    652650        static void AssociateObjectsWithLeaf(BvhLeaf *leaf); 
    653651 
     
    655653        ///////////////////////////// 
    656654        // Helper functions for local cost heuristics 
    657  
    658655         
    659656        /** Prepare split candidates for cost heuristics using axis aligned splits. 
     
    769766                const ObjectContainer &objects); 
    770767 
     768        /** Resets bv hierarchy. E.g. deletes root and resets stats. 
     769        */ 
     770        SubdivisionCandidate *Reset( 
     771                const VssRayContainer &rays,  
     772                const ObjectContainer &objects); 
     773 
    771774        /** Evaluates volume of view cells that see the objects. 
    772775        */ 
     
    783786                BvhTraversalData &frontData, 
    784787                BvhTraversalData &backData); 
    785  
     788         
     789        /** Creates new root of hierarchy. 
     790        */ 
     791        void CreateRoot(const ObjectContainer &objects); 
    786792 
    787793protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1522 r1548  
    317317#endif 
    318318 
     319        mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
     320        mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
     321 
    319322        mHierarchyStats.Stop(); 
    320323        mVspTree->mVspStats.Stop(); 
    321324        FinishObjectSpaceSubdivision(objects); 
    322  
    323         mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; 
    324         mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    325325} 
    326326 
     
    330330{ 
    331331        cout << "\nstarting view space hierarchy construction ... " << endl; 
    332  
    333         mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses 
     332         // hack: reset global cost misses 
     333        mHierarchyStats.mGlobalCostMisses = 0; 
    334334 
    335335        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
     
    367367 
    368368        cout << "preparing bv hierarchy construction ... " << endl; 
    369                 mBvHierarchy->CreateRoot(objects); 
    370  
     369         
    371370        // compute first candidate 
    372371        SubdivisionCandidate *sc = 
     
    377376 
    378377    mTQueue.Push(sc); 
    379         cout << "finished bv hierarchy preparation in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     378        cout << "finished bv hierarchy preparation in "  
     379                 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    380380} 
    381381 
     
    605605 
    606606 
    607 void HierarchyManager::ResetObjectSpaceSubdivision(const ObjectContainer &objects) 
    608 { 
    609         Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
    610         cout << "\nresetting bv hierarchy" << endl; 
    611         mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 
    612          
    613         DEL_PTR(mBvHierarchy); 
    614         mBvHierarchy = new BvHierarchy(); 
    615         mBvHierarchy->mHierarchyManager = this; 
     607void HierarchyManager::ResetObjectSpaceSubdivision(const VssRayContainer &sampleRays,  
     608                                                                                                   const ObjectContainer &objects) 
     609{ 
     610        switch (mObjectSpaceSubdivisionType) 
     611        { 
     612        case BV_BASED_OBJ_SUBDIV: 
     613        Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl; 
     614                cout << "\nresetting bv hierarchy" << endl; 
     615                mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes; 
     616#if 0    
     617                DEL_PTR(mBvHierarchy); 
     618                mBvHierarchy = new BvHierarchy(); 
     619                mBvHierarchy->mHierarchyManager = this; 
     620 
     621                PrepareObjectSpaceSubdivision(sampleRays, objects); 
     622#else 
     623                mBvHierarchy->Reset(sampleRays, objects); 
     624#endif 
     625                break; 
     626        case KD_BASED_OBJ_SUBDIV: 
     627                // TODO 
     628                break; 
     629        default: 
     630                break; 
     631        } 
    616632} 
    617633 
     
    646662        RunConstruction(false); 
    647663 
    648         ///////////////// 
    649     // now do view space subdivison on the sah bvh nodes 
    650664        mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType; 
    651         PrepareViewSpaceSubdivision(sampleRays, objects); 
    652          
    653         // process view space candidates 
    654         RunConstruction(false); 
    655          
    656         // again run object space subdivision on the view cells 
    657         ResetObjectSpaceSubdivision(objects); 
    658         PrepareObjectSpaceSubdivision(sampleRays, objects); 
    659  
    660         // process object space candidates 
    661         RunConstruction(false); 
     665 
     666        const int limit = 2; 
     667        for (int i = 0; i < limit; ++ i) 
     668        { 
     669        // again run object space subdivision on the view cells 
     670                ResetObjectSpaceSubdivision(sampleRays, objects); 
     671         
     672                // process object space candidates 
     673                RunConstruction(false); 
     674 
     675                 ///////////////// 
     676                // now do view space subdivison using the current object space partition 
     677//              ResetViewSpaceSubdivision(sampleRays, objects); 
     678         
     679                // process view space candidates 
     680                RunConstruction(false); 
     681         
     682                cout << "íteration " << i << " of " << limit << " finished" << endl; 
     683        } 
    662684         
    663685        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1473 r1548  
    316316                AxisAlignedBox3 *forcedViewSpace); 
    317317 
     318        /** Use iteration to construct the object space hierarchy. 
     319        */ 
    318320        void ConstructMultiLevel( 
    319321                const VssRayContainer &sampleRays, 
     
    321323                AxisAlignedBox3 *forcedViewSpace); 
    322324 
    323         void ResetObjectSpaceSubdivision(const ObjectContainer &objects); 
     325        /** Reset the object space subdivision.  
     326                E.g., deletes hierarchy and resets stats. 
     327                so construction can be restarted. 
     328        */ 
     329        void ResetObjectSpaceSubdivision( 
     330                const VssRayContainer &rays,  
     331                const ObjectContainer &objects); 
    324332 
    325333protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp

    r1501 r1548  
    640640          float sum = info.raysBack*(info.position - minBox) + info.raysFront*(maxBox - info.position); 
    641641          float newCost = ct_div_ci + sum/sizeBox; 
    642           float oldCost = info.rays; 
     642          float oldCost = (float)info.rays; 
    643643          info.costRatio = newCost/oldCost; 
    644644          break; 
     
    668668                info.viewCellsFront*(maxBox - info.position); 
    669669          float newCost = ct_div_ci + sum/sizeBox; 
    670           float oldCost = info.viewCells; 
     670          float oldCost = (float)info.viewCells; 
    671671          info.costRatio = newCost/oldCost; 
    672672          break; 
    673673        } 
    674674        case 3: { 
    675           float newCost = info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront; 
     675          float newCost = (float)(info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront); 
    676676          float oldCost = (float)leaf->rays.size()*pvsSize; 
    677677          info.costRatio = newCost/oldCost; 
     
    695695        case 2: { 
    696696          float newCost = (info.pvsBack  + info.pvsFront)*0.5f; 
    697           float oldCost = pvsSize; 
     697          float oldCost = (float)pvsSize; 
    698698          info.costRatio = newCost/oldCost; 
    699699          break; 
    700700        } 
    701701        case 3: { 
    702           float newCost = abs(info.raysBack  - info.raysFront); 
     702          float newCost = (float)abs(info.raysBack  - info.raysFront); 
    703703          float oldCost = (float)leaf->rays.size(); 
    704704          info.costRatio = newCost/oldCost; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1545 r1548  
    26892689        } 
    26902690 
    2691 if (mUsePredefinedViewCells) return 0; 
    26922691        ////////////////// 
    26932692        //-- merge leaves of the view cell hierarchy     
     
    31973196        mBspTree->CollectLeaves(leaves); 
    31983197        vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end(); 
    3199          
     3198        ViewCell::NewMail(); 
     3199 
    32003200        for (lit = leaves.begin(); lit != lit_end; ++ lit) 
    32013201        { 
     
    32033203                ViewCell *vc = leaf->GetViewCell(); 
    32043204 
    3205                 vc->SetMergeCost(0.0f); 
    3206                 vcRoot->SetupChildLink(vc); 
    3207          
    3208                 volume += vc->GetVolume(); 
    3209                 volume += vc->GetVolume();       
    3210  
    3211                 vcRoot->SetVolume(volume); 
     3205                if (!vc->Mailed()) 
     3206                { 
     3207                        vc->Mail(); 
     3208                        vc->SetMergeCost(0.0f); 
     3209                        vcRoot->SetupChildLink(vc); 
     3210 
     3211                        volume += vc->GetVolume(); 
     3212                        volume += vc->GetVolume();       
     3213                        vcRoot->SetVolume(volume); 
     3214                } 
    32123215        } 
    32133216         
Note: See TracChangeset for help on using the changeset viewer.