Changeset 1667


Ignore:
Timestamp:
10/23/06 20:24:14 (18 years ago)
Author:
mattausch
Message:

updated priority meaurement: taking total cost and memory into account

Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh

    r1666 r1667  
    1212 
    1313#SCENE=vsposp_typical 
    14 #SCENE=soda5_vsposp 
    15 SCENE=soda_vsposp 
     14SCENE=soda5_vsposp 
     15#SCENE=soda_vsposp 
    1616#SCENE=vienna_vsposp 
    1717#SCENE=arena_vsposp 
     
    6464 echo "$SCENE $METHOD" 
    6565 
    66 #  $PROGRAM $ENVIRONMENT \ 
     66  $PROGRAM $ENVIRONMENT \ 
    6767  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    6868  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     
    7171  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \ 
    7272  -hierarchy_construction_type=2 \ 
    73   -hierarchy_construction_consider_memory=true \ 
     73  -hierarchy_construction_consider_memory=false \ 
    7474  -hierarchy_construction_multilevel=false \ 
     75  -hierarchy_term_memory_const=0.9 \ 
    7576  -hierarchy_construction_recompute_split_on_repair=true 
    7677 
     
    102103  echo "$SCENE $METHOD" 
    103104 
    104  $PROGRAM $ENVIRONMENT \ 
     105 #$PROGRAM $ENVIRONMENT \ 
    105106  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    106107  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     
    138139 echo ********" $SCENE $METHOD ************" 
    139140 
    140  $PROGRAM $ENVIRONMENT \ 
     141# $PROGRAM $ENVIRONMENT \ 
    141142 -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    142143 -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     
    161162 echo ********" $SCENE $METHOD ************" 
    162163 
    163  $PROGRAM $ENVIRONMENT \ 
     164 #$PROGRAM $ENVIRONMENT \ 
    164165 -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    165166 -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
     
    184185echo "$SCENE $METHOD" 
    185186 
    186 $PROGRAM $ENVIRONMENT \ 
     187#$PROGRAM $ENVIRONMENT \ 
    187188 -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \ 
    188189 -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp

    r1666 r1667  
    411411                                                                const bool globalCriteriaMet) 
    412412{ 
    413         BvhSubdivisionCandidate *sc =  
    414                 dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate); 
     413        BvhSubdivisionCandidate *sc = dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate); 
    415414        BvhTraversalData &tData = sc->mParentData; 
    416415 
     
    439438                //-- push the new split candidates on the queue 
    440439                 
    441                 BvhSubdivisionCandidate *frontCandidate =  
    442                         new BvhSubdivisionCandidate(tFrontData); 
    443                 BvhSubdivisionCandidate *backCandidate =  
    444                         new BvhSubdivisionCandidate(tBackData); 
     440                BvhSubdivisionCandidate *frontCandidate = new BvhSubdivisionCandidate(tFrontData); 
     441                BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData); 
    445442 
    446443                EvalSubdivisionCandidate(*frontCandidate); 
     
    485482 
    486483 
    487 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate) 
    488 { 
    489         // compute best object partition 
    490         const float ratio =     SelectObjectPartition( 
    491                                                         splitCandidate.mParentData,  
    492                                                         splitCandidate.mFrontObjects,  
    493                                                         splitCandidate.mBackObjects); 
    494          
     484void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate,  
     485                                                                                   bool computeSplitPlane) 
     486{ 
     487        if (computeSplitPlane) 
     488        { 
     489                // compute best object partition 
     490                const float ratio =     SelectObjectPartition(splitCandidate.mParentData,  
     491                                                                                                  splitCandidate.mFrontObjects,  
     492                                                                                                  splitCandidate.mBackObjects); 
     493         
     494                // cost ratio violated? 
     495                const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
     496 
     497                const int previousMisses = splitCandidate.mParentData.mMaxCostMisses; 
     498 
     499                splitCandidate.SetMaxCostMisses(maxCostRatioViolated ?  
     500                                                                                previousMisses + 1 : previousMisses); 
     501 
     502        } 
     503 
    495504        BvhLeaf *leaf = splitCandidate.mParentData.mNode; 
    496  
    497         // cost ratio violated? 
    498         const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
    499  
    500         const int previousMisses = splitCandidate.mParentData.mMaxCostMisses; 
    501  
    502         splitCandidate.SetMaxCostMisses(maxCostRatioViolated ?  
    503                 previousMisses + 1 : previousMisses); 
    504505 
    505506        const float oldProp = EvalViewCellsVolume(leaf->mObjects); 
     
    507508                 
    508509        // compute global decrease in render cost 
    509         const float newRenderCost =  
    510                 EvalRenderCost(splitCandidate.mFrontObjects) + 
    511                 EvalRenderCost(splitCandidate.mBackObjects); 
     510        const float newRenderCost = EvalRenderCost(splitCandidate.mFrontObjects) + 
     511                                                                EvalRenderCost(splitCandidate.mBackObjects); 
    512512 
    513513        const float renderCostDecr = oldRenderCost - newRenderCost; 
     
    527527        float priority; 
    528528 
     529        // surface area heuristics is used when there is no view space subdivision available.  
     530        // In order to have some prioritized traversal, use this formula instead 
    529531        if (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
    530532                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     
    541543        else 
    542544        { 
     545                // take render cost of node into account  
     546                // otherwise danger of being stuck in a local minimum! 
    543547                const float factor = mRenderCostDecreaseWeight; 
    544                  
    545548                priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
    546549 
    547                 // take render cost of node into account  
    548                 // otherwise danger of being stuck in a local minimum!! 
    549                 if (mHierarchyManager->mConsiderMemory) 
    550                 { 
    551                         //cout << "here7 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl; 
    552                         //priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();// / mBvhStats.Leaves(); 
     550                if (1)//0 && mHierarchyManager->mConsiderMemory) 
     551                { 
    553552                        priority /= ((float)splitCandidate.GetPvsEntriesIncr() + mHierarchyManager->mMemoryConst); 
    554553                } 
     
    557556        // compute global decrease in render cost 
    558557        splitCandidate.SetPriority(priority); 
    559 } 
    560  
    561  
    562 float BvHierarchy::EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const 
    563 { 
    564         BvhLeaf *leaf = splitCandidate.mParentData.mNode; 
    565  
    566         const float oldRenderCost = EvalRenderCost(leaf->mObjects); 
    567  
    568         // compute global decrease in render cost 
    569         const float newRenderCost = EvalRenderCost(splitCandidate.mFrontObjects) + 
    570                                                                 EvalRenderCost(splitCandidate.mBackObjects); 
    571  
    572         const float renderCostDecr = oldRenderCost - newRenderCost; 
    573  
    574 #ifdef _DEBUG 
    575         Debug << "old render cost: " << oldRenderCost << endl; 
    576         Debug << "new render cost: " << newRenderCost << endl; 
    577         Debug << "render cost decrease: " << renderCostDecr << endl; 
    578 #endif 
    579  
    580         // take render cost of node into account  
    581         // otherwise danger of being stuck in a local minimum!! 
    582         const float factor = mRenderCostDecreaseWeight; 
    583          
    584         float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
    585  
    586         // $$ matt temp 
    587         if (mHierarchyManager->mConsiderMemory) 
    588         { 
    589                 //cout << "here5 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl; 
    590                 //const float priority = factor * renderCostDecr - (1.0f - factor) * (float)splitCandidate.GetPvsEntriesIncr(); 
    591                 priority /= ((float)splitCandidate.GetPvsEntriesIncr() + mHierarchyManager->mMemoryConst); 
    592         } 
    593          
    594         return priority; 
    595558} 
    596559 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1666 r1667  
    1313#include "AxisAlignedBox3.h" 
    1414#include "IntersectableWrapper.h" 
    15  
     15#include "HierarchyManager.h" 
    1616 
    1717 
     
    408408                int Type() const { return OBJECT_SPACE; } 
    409409         
    410                 void EvalPriority(bool computeSplitplane = true) 
     410                void EvalCandidate(bool computeSplitplane = true) 
    411411                { 
    412                         if (computeSplitplane) 
    413                         { 
    414                                 sBvHierarchy->EvalSubdivisionCandidate(*this);   
    415                         } 
    416                         else 
    417                         { 
    418                                 mPvsEntriesIncr = sBvHierarchy->EvalPvsEntriesIncr(*this); 
    419                                 mPriority = sBvHierarchy->EvalPriority(*this); 
    420                         } 
     412                        sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane); 
    421413                } 
    422414 
    423415                bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) 
    424416                { 
    425                         BvhNode *n =  
    426                                 sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet); 
     417                        BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet); 
     418 
    427419                        // local or global termination criteria failed 
    428420                        return !n->IsLeaf();             
     
    440432                } 
    441433 
    442                 BvhSubdivisionCandidate( 
    443                         const ObjectContainer &frontObjects,  
    444                         const ObjectContainer &backObjects,  
    445                         const BvhTraversalData &tData):  
     434                BvhSubdivisionCandidate(const ObjectContainer &frontObjects,  
     435                                                                const ObjectContainer &backObjects,  
     436                                                                const BvhTraversalData &tData):  
    446437                mFrontObjects(frontObjects), mBackObjects(backObjects), mParentData(tData) 
    447438                {} 
     439 
     440                float GetPriority() const 
     441                { 
     442                        HierarchyManager *hm = sBvHierarchy->mHierarchyManager; 
     443                        if (hm->ConsiderMemory()) 
     444                        { 
     445                                const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease; 
     446                                const float mc = hm->GetHierarchyStats().mMemory + 
     447                                                                 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte(); 
     448                                //cout << "x"; 
     449                                return - (rc * mc) / float(1024 * 1024); 
     450                        } 
     451                        else 
     452                        { 
     453                                return mPriority; 
     454                        } 
     455                } 
     456 
    448457 
    449458                /// pointer to parent tree. 
     
    494503        /** Evaluates candidate for splitting. 
    495504        */ 
    496         void EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitData); 
     505        void EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitData, bool computeSplitPlane = true); 
    497506 
    498507        /** Returns list of leaves with pvs smaller than 
     
    726735                @returns priority 
    727736        */ 
    728         float EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const; 
     737        //float EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const; 
    729738 
    730739        //////////////////////////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h

    r1313 r1667  
    2424 
    2525        inline void  SetPriority(const float k) { mPriority = k; } 
    26         inline float GetPriority() const  { return mPriority; } 
    27  
     26        //inline float GetPriority() const  { return mPriority; } 
     27        virtual float GetPriority() const = 0; 
    2828protected: 
    2929 
     
    5454        unsigned int Size() const { return (unsigned int)mBuffer.size(); } 
    5555        bool Empty() const {return mBuffer.empty(); } 
    56         T Item(const unsigned int i)       { return mBuffer[i]; } 
     56        T Item(const unsigned int i) { return mBuffer[i]; } 
    5757        const T Item(const unsigned int i) const { return mBuffer[i]; } 
    5858        T Pop(); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1666 r1667  
    358358        // hack: assume that object space can be seen from view space 
    359359        mHierarchyStats.mTotalCost = (float)objects.size(); 
     360        // only one entry for start 
    360361        mHierarchyStats.mPvsEntries = 1; 
    361  
    362         const int entrySize = sizeof(PvsData) + sizeof(Intersectable *); 
    363         mHierarchyStats.mMemory = entrySize / (1024.0f * 1024.0f); 
     362        mHierarchyStats.mMemory = (float)ObjectPvs::GetEntrySizeByte(); 
    364363 
    365364        EvalSubdivisionStats(); 
     
    396395        // for first round, use sah splits. Once view space partition 
    397396        // has started, use render cost heuristics instead 
    398         const int ospSteps =  
    399                 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 
     397        const int ospSteps = RunConstruction(objectSpaceQueue, dirtyVspList, NULL, minSteps); 
    400398 
    401399        cout << "\n" << ospSteps << " object space partition steps taken" << endl; 
    402400 
    403401        // create view space 
    404         SubdivisionCandidate *vsc =  
    405                         PrepareViewSpaceSubdivision(sampleRays, objects); 
     402        SubdivisionCandidate *vsc = PrepareViewSpaceSubdivision(sampleRays, objects); 
    406403 
    407404        viewSpaceQueue.Push(vsc); 
     
    414411        // account so we can compare to view space splits 
    415412        ResetQueue(objectSpaceQueue, false); 
    416  
    417         //minSteps = 1; 
    418413 
    419414        // This method subdivides view space / object space  
     
    425420        while (!(viewSpaceQueue.Empty() && objectSpaceQueue.Empty())) 
    426421        { 
    427                 float vspPriority; 
     422                // decide upon next split type 
     423                const float vspPriority =  viewSpaceQueue.Top() ? viewSpaceQueue.Top()->GetPriority() : -1e20; 
     424                const float ospPriority =  viewSpaceQueue.Top() ? objectSpaceQueue.Top()->GetPriority() : -1e20; 
    428425                 
    429                 // decide upon next split type 
    430                 if (!viewSpaceQueue.Empty()) 
    431                 { 
    432                         vspPriority = viewSpaceQueue.Top()->GetPriority(); 
    433  
    434                         // rather take this into account directly when computing priority 
    435                         if (0 && mConsiderMemory) 
    436                                 vspPriority /= ((float)viewSpaceQueue.Top()->GetPvsEntriesIncr() + Limits::Small); 
    437                 } 
    438                 else 
    439                 { 
    440                         vspPriority = 0; 
    441                 } 
    442  
    443                 float ospPriority; 
    444                  
    445                 if (!objectSpaceQueue.Empty()) 
    446                 { 
    447                         ospPriority = objectSpaceQueue.Top()->GetPriority(); 
    448                          
    449                         // rather take this into account directly when computing priority 
    450                         if (0 && mConsiderMemory) 
    451                                 ospPriority /= ((float)objectSpaceQueue.Top()->GetPvsEntriesIncr() + Limits::Small); 
    452                 } 
    453                 else 
    454                 { 
    455                         ospPriority = 0; 
    456                 } 
    457  
    458426                cout << "new decicion, vsp: " << vspPriority << ", osp: " << ospPriority << endl; 
    459427 
     
    471439                        // has started, use render cost heuristics instead 
    472440                        const int ospSteps =  
    473                                 RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps); 
     441                                RunConstruction(objectSpaceQueue, dirtyVspList, viewSpaceQueue.Top(), minSteps); 
    474442 
    475443                        cout << "\n" << ospSteps << " object space partition steps taken" << endl; 
     
    493461                        // process view space candidates 
    494462                        const int vspSteps =  
    495                                 RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, minSteps); 
     463                                RunConstruction(viewSpaceQueue, dirtyOspList, objectSpaceQueue.Top(), minSteps); 
    496464 
    497465                        cout << "\n" << vspSteps << " view space partition steps taken" << endl; 
     
    526494        mHierarchyStats.mNodes = 2;  
    527495        mHierarchyStats.mPvsEntries = 1; 
    528         mHierarchyStats.mMemory = sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f); 
     496        mHierarchyStats.mMemory = (float)ObjectPvs::GetEntrySizeByte(); 
    529497        mHierarchyStats.mTotalCost = (float)objects.size(); 
    530498 
     
    570538 
    571539        // begin subdivision 
    572         RunConstruction(mRepairQueue,  
    573                                         sampleRays,  
    574                                         objects,  
    575                                         forcedViewSpace); 
     540        RunConstruction(mRepairQueue, sampleRays, objects, forcedViewSpace); 
    576541         
    577542        cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     
    734699        //cout << "pvs entries: " << pvsEntriesIncr << " " << mHierarchyStats.pvsEntries << endl; 
    735700 
    736         const int sizeOfEntry = sizeof(PvsData) + sizeof(Intersectable *); 
    737701        // memory size in byte 
    738         mHierarchyStats.mMemory += float(pvsEntriesIncr * sizeOfEntry); 
     702        mHierarchyStats.mMemory += (float)ObjectPvs::GetEntrySizeByte(); 
    739703        mHierarchyStats.mRenderCostDecrease = sc->GetRenderCostDecrease(); 
    740704 
     
    744708        { 
    745709                memoryCount += 100000; 
    746                 cout << "\nstorage cost: " << mHierarchyStats.mMemory / (1024.0f * 1024.0f) << ", steps: " << mHierarchyStats.Leaves() << endl; 
     710                cout << "\nstorage cost: " << mHierarchyStats.mMemory / float(1024 * 1024) << " MB, steps: " << mHierarchyStats.Leaves() << endl; 
    747711        } 
    748712 
     
    930894int HierarchyManager::RunConstruction(SplitQueue &splitQueue, 
    931895                                                                          SubdivisionCandidateContainer &dirtyCandidates, 
    932                                                                           const float minRenderCostDecr, 
     896                                                                          SubdivisionCandidate *oldCandidate, 
    933897                                                                          const int minSteps) 
    934898{ 
     
    939903        while (!splitQueue.Empty()) 
    940904        { 
     905                const float threshold = oldCandidate ? oldCandidate->GetPriority() : 1e20; 
    941906                SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue);  
    942                  
     907                //cout << "here2 " << sc->GetPriority() << " " << threshold << endl; 
     908 
    943909                // minimum slope reached 
    944                 if ((sc->GetRenderCostDecrease() < minRenderCostDecr) && 
    945                         !(steps < minSteps)) 
    946                 { 
    947                         //cout << "breaking on " << sc->GetRenderCostDecrease() << " smaller than " << minRenderCostDecr << endl; 
     910                if ((sc->GetPriority() < threshold) && !(steps < minSteps)) 
     911                { 
     912                        cout << "**************** breaking on " << sc->GetPriority() << " smaller than " << threshold << endl; 
    948913                        break; 
    949914                } 
     915 
    950916                //////// 
    951917                //-- subdivide leaf node of either type 
     
    993959                        mHierarchyStats.mPvsEntries = mBvHierarchy->CountViewCells(objects); 
    994960 
    995                         mHierarchyStats.mMemory = mHierarchyStats.mPvsEntries * 
    996                                 sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f); 
     961                        mHierarchyStats.mMemory =  
     962                                (float)mHierarchyStats.mPvsEntries * ObjectPvs::GetEntrySizeByte(); 
    997963 
    998964                        mHierarchyStats.mRenderCostDecrease = 0; 
     
    10381004        mHierarchyStats.mRenderCostDecrease = 0; 
    10391005 
    1040         mHierarchyStats.mMemory = mHierarchyStats.mPvsEntries *  
    1041                 sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f); 
     1006        mHierarchyStats.mMemory = (float)mHierarchyStats.mPvsEntries * ObjectPvs::GetEntrySizeByte(); 
    10421007 
    10431008        // evaluate new stats before first subdivsiion 
     
    13091274                const float rcd = sc->GetRenderCostDecrease(); 
    13101275                 
    1311                 splitQueue.Erase(sc); // erase from queue 
    1312                 sc->EvalPriority(recomputeSplitPlaneOnRepair); // reevaluate 
    1313                  
     1276                // erase from queue 
     1277                splitQueue.Erase(sc); 
     1278                // reevaluate candidate 
     1279                sc->EvalCandidate(recomputeSplitPlaneOnRepair); 
     1280                 // reinsert 
     1281                splitQueue.Push(sc); 
     1282 
     1283                cout << "."; 
     1284 
    13141285#ifdef _DEBUG 
    13151286                Debug << "candidate " << sc << " reevaluated\n"  
     
    13171288                          << " old: " << rcd << " new " << sc->GetRenderCostDecrease() << endl; 
    13181289#endif   
    1319                 splitQueue.Push(sc); // reinsert 
    1320                 cout << "."; 
    13211290        } 
    13221291 
     
    13391308                SubdivisionCandidate *candidate = NextSubdivisionCandidate(splitQueue); 
    13401309                 // reevaluate local split plane and priority 
    1341                 candidate->EvalPriority(recomputeSplitPlane); 
     1310                candidate->EvalCandidate(recomputeSplitPlane); 
    13421311                cout << "."; 
    13431312                mCandidateBuffer.push_back(candidate); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1666 r1667  
    4141class BvHierarchy; 
    4242class Exporter; 
     43class ViewCellsParseHandlers; 
     44 
    4345 
    4446#define COUNT_ORIGIN_OBJECTS 1 
     
    130132class HierarchyManager 
    131133{ 
    132         friend VspTree; 
    133         friend OspTree; 
    134         friend BvHierarchy; 
    135         friend ViewCellsParseHandlers; 
    136  
    137134public: 
    138135        /** Constructor with the view space partition tree and 
     
    233230        }  
    234231 
     232        HierarchyStatistics &GetHierarchyStats() { return mHierarchyStats; }; 
     233 
     234        inline bool ConsiderMemory() const { return mConsiderMemory; } 
     235 
    235236protected: 
    236237 
     
    254255        float GetObjectSpaceMemUsage() const; 
    255256 
     257 
    256258        ////////////////////////////// 
    257259        // the main loop 
    258         ////////////////////// 
    259260 
    260261        /** This is for interleaved construction / sequential construction. 
     
    270271        int RunConstruction(SplitQueue &splitQueue, 
    271272                                                SubdivisionCandidateContainer &chosenCandidates, 
    272                                                 const float minRenderCostDecr, 
     273                                                //const float minRenderCostDecr, 
     274                                                SubdivisionCandidate *oldCandidate, 
    273275                                                const int minSteps); 
    274276 
     
    344346        bool StartViewSpaceSubdivision() const; 
    345347 
     348 
    346349        //////////////////////////// 
    347350        // Helper function for preparation of subdivision 
    348         /////// 
    349351 
    350352        /** Prepare bv hierarchy for subdivision 
     
    493495        float mTermMaxMemory; 
    494496 
     497 
    495498        //////////////////// 
    496499 
     500        /// number of minimal steps of the same type 
    497501        int mMinStepsOfSameType; 
    498502 
     
    532536 
    533537        float mMemoryConst; 
     538 
     539 
     540        friend VspTree; 
     541        friend OspTree; 
     542        friend BvHierarchy; 
     543        friend ViewCellsParseHandlers; 
     544 
    534545}; 
    535546 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1633 r1667  
    1313#include "IntersectableWrapper.h" 
    1414#include "KdTree.h" 
     15#include "HierarchyManager.h" 
     16 
    1517 
    1618 
     
    250252                int Type() const { return OBJECT_SPACE; } 
    251253         
    252                 void EvalPriority(bool computeSplitplane = true) 
    253                 { 
    254                         if (computeSplitplane) 
    255                                 sOspTree->EvalSubdivisionCandidate(*this);       
    256                         // else TODO 
     254                void EvalCandidate(bool computeSplitplane = true) 
     255                { 
     256                        //if (computeSplitplane) TODO 
     257                        sOspTree->EvalSubdivisionCandidate(*this);       
    257258                } 
    258259 
     
    274275                { 
    275276                        sOspTree->CollectDirtyCandidates(this, dirtyList, onlyUnmailed); 
     277                } 
     278 
     279                float GetPriority() const 
     280                { 
     281                        HierarchyManager *hm = sOspTree->mHierarchyManager; 
     282                        if (hm->ConsiderMemory()) 
     283                        { 
     284                                const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease; 
     285                                const float mc = hm->GetHierarchyStats().mMemory + 
     286                                                                 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte(); 
     287 
     288                                return - (rc * mc); 
     289                        } 
     290                        else 
     291                        { 
     292                                return mPriority; 
     293                        } 
    276294                } 
    277295 
     
    698716 
    699717        void AddSubdivisionStats(const int viewCells, 
    700                 const float renderCostDecr, 
    701                 const float totalRenderCost); 
     718                                                         const float renderCostDecr, 
     719                                                         const float totalRenderCost); 
    702720 
    703721        void EvalViewCellsForHeuristics(const VssRay &ray,  
    704                 float &volLeft,  
    705                 float &volRight); 
     722                                                                        float &volLeft,  
     723                                                                        float &volRight); 
    706724 
    707725        float EvalViewCellsVolume(KdLeaf *leaf, const RayInfoContainer &rays) const; 
    708726         
    709         int RemoveParentViewCellsPvs(KdLeaf *leaf,  
    710                                                                           const RayInfoContainer &rays 
    711                                                                           ) const; 
     727        int RemoveParentViewCellsPvs(KdLeaf *leaf,  const RayInfoContainer &rays) const; 
    712728 
    713729        int UpdateViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const; 
    714 int CheckViewCellsPvs(KdLeaf *leaf,  
    715                                                            const RayInfoContainer &rays) const; 
    716         bool AddViewCellToObjectPvs( 
    717                 Intersectable *obj, 
    718                 ViewCell *vc,  
    719                 float &contribution, 
    720                 bool onlyUnmailed) const; 
    721  
    722         int ClassifyRays( 
    723                 const RayInfoContainer &rays,  
    724                 KdLeaf *leaf,  
    725                 const AxisAlignedPlane &plane, 
    726                 RayInfoContainer &frontRays, 
    727                 RayInfoContainer &backRays) const; 
    728  
    729         void CollectTouchedViewCells( 
    730                 const RayInfoContainer &rays,  
    731                 ViewCellContainer &touchedViewCells) const; 
    732  
    733         void AddObjectContribution( 
    734                 KdLeaf *leaf, 
    735                 Intersectable * obj, 
    736                 ViewCellContainer &touchedViewCells, 
    737                 float &renderCost); 
    738  
    739         void SubtractObjectContribution( 
    740                 KdLeaf *leaf, 
    741                 Intersectable * obj, 
    742                 ViewCellContainer &touchedViewCells, 
    743                 float &renderCost); 
    744  
    745         SubdivisionCandidate *PrepareConstruction( 
    746                 const VssRayContainer &sampleRays, 
    747                 const ObjectContainer &objects, 
    748                 RayInfoContainer &rays); 
     730         
     731        int CheckViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const; 
     732 
     733        bool AddViewCellToObjectPvs(Intersectable *obj, 
     734                                                                ViewCell *vc,  
     735                                                                float &contribution, 
     736                                                                bool onlyUnmailed) const; 
     737 
     738        int ClassifyRays(const RayInfoContainer &rays,  
     739                                         KdLeaf *leaf,  
     740                                         const AxisAlignedPlane &plane, 
     741                                         RayInfoContainer &frontRays, 
     742                                         RayInfoContainer &backRays) const; 
     743 
     744        void CollectTouchedViewCells(const RayInfoContainer &rays,  
     745                                                                 ViewCellContainer &touchedViewCells) const; 
     746 
     747        void AddObjectContribution(KdLeaf *leaf, 
     748                                                           Intersectable * obj, 
     749                                                           ViewCellContainer &touchedViewCells, 
     750                                                           float &renderCost); 
     751 
     752        void SubtractObjectContribution(KdLeaf *leaf, 
     753                                                                        Intersectable * obj, 
     754                                                                        ViewCellContainer &touchedViewCells, 
     755                                                                        float &renderCost); 
     756 
     757        SubdivisionCandidate *PrepareConstruction(const VssRayContainer &sampleRays, 
     758                                                                                          const ObjectContainer &objects, 
     759                                                                                          RayInfoContainer &rays); 
    749760 
    750761 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h

    r1586 r1667  
    177177  */ 
    178178  void Clear(); 
     179 
     180  static int GetEntrySizeByte();  
     181  static float GetEntrySize(); 
    179182 
    180183  /** Compute continuous PVS difference */ 
     
    189192         
    190193        return pvsReduction + pvsEnlargement; 
    191   } 
    192  
    193                                            
     194  }                
    194195                                           
    195196  /// Map of PVS entries 
     
    493494 
    494495 
     496template <typename T, typename S> 
     497float Pvs<T, S>::GetEntrySize() 
     498{ 
     499        return (float)sizeof(T) + sizeof(S) / float(1024 * 1024); 
     500} 
     501 
     502 
     503template <typename T, typename S> 
     504int Pvs<T, S>::GetEntrySizeByte() 
     505{ 
     506        return sizeof(T) + sizeof(S); 
     507} 
     508 
     509 
     510/////////////////////////////////////// 
     511 
    495512/** Class instantiating the Pvs template for kd tree nodes. 
    496513*/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1633 r1667  
    2525 
    2626        virtual ~SubdivisionCandidate() {}; 
    27         virtual void EvalPriority(bool computeSplitplane = true) = 0; 
     27        /** Evaluate this subdivision candidate. 
     28        */ 
     29        virtual void EvalCandidate(bool computeSplitplane = true) = 0; 
     30        /** Returns type of this subdivision candidate. 
     31        */ 
    2832        virtual int Type() const = 0; 
     33        /** Evaluate this candidate and put results into queue for further traversal. 
     34        */ 
    2935        virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) = 0; 
     36        /** Returns true of the global termination criteria of this split were met, 
     37                false otherwise. 
     38        */ 
    3039        virtual bool GlobalTerminationCriteriaMet() const = 0; 
    31  
     40        /** Collects #of subdivision candidates that were affected by the 
     41                application of this one. 
     42        */ 
    3243        virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList, 
    3344                                                                                const bool onlyUnmailed) = 0; 
     
    5667                mSplitAxis = splitAxis; 
    5768        } 
     69         
    5870        inline void SetMaxCostMisses(const int misses) 
    5971        { 
    6072                mMaxCostMisses = misses; 
    6173        } 
     74 
    6275        inline void SetPvsEntriesIncr(const int pvsEntriesIncr) 
    6376        { 
     
    6982                return mSplitAxis; 
    7083        } 
     84 
    7185        inline int GetMaxCostMisses() const 
    7286        { 
    7387                return mMaxCostMisses; 
    7488        } 
     89 
    7590        inline int GetPvsEntriesIncr() const 
    7691        { 
    7792                return mPvsEntriesIncr; 
    7893        } 
     94 
    7995 
    8096        ////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1666 r1667  
    15481548        stats.open(mergeStats.c_str()); 
    15491549 
    1550         const float entrySize = sizeof(PvsData) + sizeof(Intersectable *); 
    1551         const float memoryCost = (float)entriesInPvs *  entrySize / (1024.0f * 1024.0f); 
     1550        const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
    15521551 
    15531552        ///////////// 
     
    16211620                        avgRenderCost = (float)totalPvs / (float)numViewCells; 
    16221621 
    1623                         const float entrySize = sizeof(PvsData) + sizeof(Intersectable *); 
    1624                         const float memoryCost = (float)entriesInPvs * entrySize / (1024.0f * 1024.0f); 
     1622                        const float memoryCost = (float)entriesInPvs * ObjectPvs::GetEntrySize(); 
    16251623 
    16261624                        UpdateStats(stats, 
     
    20652063float ViewCellsTree::GetMemoryCost(ViewCell *vc) const 
    20662064{ 
    2067         const float entrySize =  
    2068                 sizeof(PvsData) + sizeof(Intersectable *); 
    2069  
    2070         return (float)CountStoredPvsEntries(vc) * entrySize; 
     2065        return (float)CountStoredPvsEntries(vc) * ObjectPvs::GetEntrySize(); 
    20712066} 
    20722067 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1653 r1667  
    3535        /// number of view cells 
    3636        int viewCells; 
    37  
    3837        /// size of the PVS 
    3938        int pvsSize; 
    40  
    4139        /// largest PVS of all view cells 
    4240        int maxPvs; 
    43  
    4441        /// smallest PVS of all view cells 
    4542        int minPvs; 
    46  
    4743        /// view cells with empty PVS 
    4844        int emptyPvs; 
    49  
    5045        /// number of leaves covering the view space 
    5146        int leaves; 
    52  
    5347        /// largest number of leaves covered by one view cell 
    5448        int maxLeaves; 
    55  
     49        /// number of invalid view cells 
    5650        int invalid; 
    5751 
     
    8983 
    9084/** 
    91         View cell with an optional mesh representation 
     85        A view cell. View cells are regions in space. The visibility informations, 
     86        i.e., the primitives seen by the view cell are stored in a PVs. 
     87        A view cell can be represented in many different ways, e.g., 
     88        a mesh representation. 
    9289*/ 
    93  
    94  
    9590class ViewCell: public MeshInstance 
    9691{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1666 r1667  
    2626 
    2727 
    28 // should not count origin object for sampling because it disturbs heuristics 
    29 #define SAMPLE_ORIGIN_OBJECTS 1 
     28// warning: Should not count origin object for sampling because it disturbs heuristics 
     29#define SAMPLE_ORIGIN_OBJECTS 1  // matt temp 
    3030 
    3131// $$JB HACK 
     
    54425442 
    54435443 
    5444 void VspOspViewCellsManager::Finalize(ViewCell *viewCell,  
    5445                                                                           const bool createMesh) 
     5444void VspOspViewCellsManager::Finalize(ViewCell *viewCell, const bool createMesh) 
    54465445{ 
    54475446        float area = 0; 
     
    56515650        totalRenderCost = avgRenderCost = expectedCost = (float)rootPvs; 
    56525651 
    5653         const float entrySize = sizeof(PvsData) + sizeof(Intersectable *); 
    5654         const float memoryCost = (float)entriesInPvs *  entrySize / (1024.0f * 1024.0f); 
     5652        const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize(); 
    56555653 
    56565654        ///////////// 
     
    57285726                                avgRenderCost = (float)totalPvs / (float)numViewCells; 
    57295727 
    5730                                 const float entrySize = sizeof(PvsData) + sizeof(Intersectable *); 
    5731                                 const float memoryCost = (float)entriesInPvs * entrySize / (1024.0f * 1024.0f); 
     5728                                const float memoryCost = (float)entriesInPvs *  
     5729                                        (float)ObjectPvs::GetEntrySize(); 
    57325730 
    57335731                                mViewCellsTree->UpdateStats(stats, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1633 r1667  
    161161        { 
    162162                // for a spatial subdivision, it is not necessary to store 
    163                 // the objects with the leaves, they can be classified 
    164                 // geometrically 
    165                 mHierarchyManager->mOspTree->InsertObjects( 
    166                         mHierarchyManager->mOspTree->mRoot, *mObjects); 
     163                // the objects with the leaves, they can be classified geometrically 
     164                mHierarchyManager->mOspTree-> 
     165                        InsertObjects(mHierarchyManager->mOspTree->mRoot, *mObjects); 
    167166        } 
    168167} 
     
    11731172void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes) 
    11741173{ 
    1175         KdLeaf * leaf =  
    1176                 new KdLeaf(dynamic_cast<KdInterior *>(mCurrentOspNode), NULL); 
    1177  
    1178         if (mCurrentOspNode) // replace front or (if not NULL) back child 
    1179         { 
     1174        KdLeaf * leaf = new KdLeaf(dynamic_cast<KdInterior *>(mCurrentOspNode), NULL); 
     1175 
     1176        if (mCurrentOspNode) 
     1177        { 
     1178                 // replace front or (if not NULL) back child 
    11801179                dynamic_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf); 
    11811180        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r1632 r1667  
    154154        typedef std::priority_queue<VspBspTraversalData> VspBspTraversalQueue; 
    155155         
     156        // note: should be inherited from subdivision candidate 
    156157        class VspBspSubdivisionCandidate 
    157158        {   
     
    172173                        return mPriority; 
    173174#else 
    174                         return (float) (-mDepth); // for kd tree 
     175                        return (float) (-mDepth); // for standard breath-first traversal 
    175176#endif 
    176177                } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1666 r1667  
    786786 
    787787 
    788 void VspTree::EvalSubdivisionCandidate(VspSubdivisionCandidate &splitCandidate) 
    789 { 
    790         float frontProb; 
    791         float backProb; 
     788void VspTree::EvalSubdivisionCandidate(VspSubdivisionCandidate &splitCandidate, bool computeSplitPlane) 
     789{ 
     790        if (computeSplitPlane) 
     791        { 
     792                float frontProb; 
     793                float backProb; 
     794 
     795                // compute locally best split plane 
     796                const float ratio = SelectSplitPlane(splitCandidate.mParentData,  
     797                                                                                         splitCandidate.mSplitPlane,  
     798                                                                                         frontProb,  
     799                                                                                         backProb); 
     800         
     801                const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
     802 
     803                const int maxCostMisses = splitCandidate.mParentData.mMaxCostMisses; 
     804                // max cost threshold violated? 
     805                splitCandidate.SetMaxCostMisses(maxCostRatioViolated  ? maxCostMisses + 1: maxCostMisses); 
     806        } 
    792807         
    793808        VspLeaf *leaf = dynamic_cast<VspLeaf *>(splitCandidate.mParentData.mNode); 
    794809         
    795         // compute locally best split plane 
    796         const float ratio = SelectSplitPlane(splitCandidate.mParentData,  
    797                                                                                  splitCandidate.mSplitPlane,  
    798                                                                                  frontProb,  
    799                                                                                  backProb); 
    800  
    801         const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
    802  
    803         // max cost threshold violated? 
    804         splitCandidate.SetMaxCostMisses(maxCostRatioViolated  ?  
    805                         splitCandidate.mParentData.mMaxCostMisses + 1: 
    806                         splitCandidate.mParentData.mMaxCostMisses); 
    807  
    808810        // compute global decrease in render cost 
    809811        float oldRenderCost; 
     
    821823        // otherwise danger of being stuck in a local minimum!! 
    822824        const float factor = mRenderCostDecreaseWeight; 
    823  
    824825        float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost; 
    825826 
    826         if (mHierarchyManager->mConsiderMemory) 
    827         { 
    828                 //cout << "here4 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl; 
    829                 //const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr(); 
     827        if (1)//0 && mHierarchyManager->mConsiderMemory) 
     828        { 
    830829                priority /= ((float)splitCandidate.GetPvsEntriesIncr() + mHierarchyManager->mMemoryConst); 
    831830        } 
     
    835834 
    836835 
    837 float VspTree::EvalPriority(const VspSubdivisionCandidate &splitCandidate) const 
     836/*float VspTree::EvalPriority(const VspSubdivisionCandidate &splitCandidate) const 
    838837{ 
    839838        // compute global decrease in render cost 
     
    857856 
    858857        return priority; 
    859 } 
     858}*/ 
    860859 
    861860 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1664 r1667  
    1111#include "gzstream.h" 
    1212#include "SubdivisionCandidate.h" 
     13#include "HierarchyManager.h" 
    1314 
    1415 
     
    457458                int Type() const { return VIEW_SPACE; } 
    458459 
    459                 void EvalPriority(bool computeSplitplane = true) 
     460                void EvalCandidate(bool computeSplitplane = true) 
    460461                { 
    461                         if (computeSplitplane) 
    462                                 sVspTree->EvalSubdivisionCandidate(*this);       
    463                         else 
    464                         { 
    465                                 mPvsEntriesIncr = sVspTree->EvalPvsEntriesIncr(*this); 
    466                                 mPriority = sVspTree->EvalPriority(*this); 
    467                         } 
     462                        sVspTree->EvalSubdivisionCandidate(*this, computeSplitplane); 
    468463                } 
    469464 
     
    490485                mSplitPlane(plane), mParentData(tData) 
    491486                {} 
     487 
     488                float GetPriority() const 
     489                { 
     490                        HierarchyManager *hm = sVspTree->mHierarchyManager; 
     491                        if (hm->ConsiderMemory()) 
     492                        { 
     493                                const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease; 
     494                                const float mc = hm->GetHierarchyStats().mMemory + 
     495                                                                 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte(); 
     496 
     497                                return - (rc * mc) / float(1024 * 1024); 
     498                        } 
     499                        else 
     500                        { 
     501                                return mPriority; 
     502                        } 
     503                } 
    492504        }; 
    493505 
     
    702714        /** Evaluates candidate for splitting. 
    703715        */ 
    704         void EvalSubdivisionCandidate(VspSubdivisionCandidate &splitData); 
     716        void EvalSubdivisionCandidate(VspSubdivisionCandidate &splitData,  
     717                                                                  bool computeSplitPlane = true); 
    705718 
    706719        /** Evaluates render cost decrease of next split. 
     
    854867                @returns priority 
    855868        */ 
    856         float EvalPriority(const VspSubdivisionCandidate &splitCandidate) const; 
     869        //float EvalPriority(const VspSubdivisionCandidate &splitCandidate) const; 
    857870 
    858871        ///////////////////////////////////////////////////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.