Changeset 1576


Ignore:
Timestamp:
10/05/06 18:51:15 (18 years ago)
Author:
mattausch
Message:

added measurement for pvs entries size decrease during subdivision

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
13 edited

Legend:

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

    r1571 r1576  
    369369 
    370370    // how often was max cost ratio missed in this branch? 
    371         frontData.mMaxCostMisses = sc.mMaxCostMisses; 
    372         backData.mMaxCostMisses = sc.mMaxCostMisses; 
     371        frontData.mMaxCostMisses = sc.GetMaxCostMisses(); 
     372        backData.mMaxCostMisses = sc.GetMaxCostMisses(); 
    373373         
    374374        // assign the objects in sorted order 
     
    475475        const bool maxCostRatioViolated = mTermMaxCostRatio < ratio; 
    476476 
    477         splitCandidate.mMaxCostMisses = maxCostRatioViolated ?  
     477        splitCandidate.SetMaxCostMisses(maxCostRatioViolated ?  
    478478                splitCandidate.mParentData.mMaxCostMisses + 1 : 
    479                 splitCandidate.mParentData.mMaxCostMisses; 
     479                splitCandidate.mParentData.mMaxCostMisses); 
    480480 
    481481        const float oldProp = EvalViewCellsVolume(leaf->mObjects); 
     
    488488 
    489489        const float renderCostDecr = oldRenderCost - newRenderCost; 
     490        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 
    490491 
    491492#ifdef _DEBUG 
     
    494495        Debug << "render cost decrease: " << renderCostDecr << endl; 
    495496#endif 
     497 
    496498        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     499        splitCandidate.SetPvsEntriesIncr(EvalPvsEntriesIncr(splitCandidate)); 
    497500 
    498501#if 1 
     
    510513 
    511514 
     515int BvHierarchy::EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate) const 
     516{ 
     517        const int oldPvsSize = CountViewCells(splitCandidate.mParentData.mNode->mObjects); 
     518         
     519        const int fPvsSize = CountViewCells(splitCandidate.mFrontObjects); 
     520        const int bPvsSize = CountViewCells(splitCandidate.mBackObjects); 
     521 
     522        return fPvsSize + bPvsSize - oldPvsSize; 
     523} 
     524 
     525 
    512526inline bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const 
    513527{ 
     
    515529        return ( 0 
    516530                || ((int)data.mNode->mObjects.size() <= mTermMinObjects) 
    517                 || (data.mProbability <= mTermMinProbability) 
    518                 || (data.mDepth >= mTermMaxDepth) 
    519                 || (data.mNumRays <= mTermMinRays) 
     531                //|| (data.mProbability <= mTermMinProbability) 
     532                //|| (data.mNumRays <= mTermMinRays) 
    520533                 ); 
    521534} 
     
    10631076        return vol; 
    10641077} 
     1078 
    10651079/////////////////////////////////////////////////////////// 
    10661080 
     
    12891303                        return 0.0f; 
    12901304 
    1291                 //////////////////// 
     1305                //////////////// 
    12921306                //-- surface area heuristics 
    12931307 
     
    12981312        } 
    12991313        else 
    1300         {       //////////////////// 
     1314        {       /////////////// 
    13011315                //-- render cost heuristics 
    13021316 
    13031317                const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 
     1318 
    13041319                // probability that view point lies in a view cell which sees this node 
    13051320                const float p = EvalViewCellsVolume(objects) / viewSpaceVol;     
     
    14041419                for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit) 
    14051420                { 
    1406                         VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     1421                        //VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 
     1422                        ViewCell *vc = *vit; 
    14071423 
    14081424                        // store view cells 
     
    14261442                } 
    14271443        } 
     1444} 
     1445 
     1446 
     1447int BvHierarchy::CountViewCells(Intersectable *obj) const 
     1448{ 
     1449        int result = 0; 
     1450         
     1451        VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 
     1452 
     1453        for (rit = obj->mVssRays.begin(); rit < rit_end; ++ rit) 
     1454        { 
     1455                VssRay *ray = (*rit); 
     1456                ViewCellContainer tmpViewCells; 
     1457         
     1458                mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells); 
     1459                 
     1460                ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end(); 
     1461                for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit) 
     1462                { 
     1463                        ViewCell *vc = *vit; 
     1464 
     1465                        // store view cells 
     1466                        if (!vc->Mailed()) 
     1467                        { 
     1468                                vc->Mail(); 
     1469                                ++ result; 
     1470                        } 
     1471                } 
     1472        } 
     1473 
     1474        return result; 
     1475} 
     1476 
     1477 
     1478int BvHierarchy::CountViewCells(const ObjectContainer &objects) const 
     1479{ 
     1480        // no view cells yet 
     1481        if (mHierarchyManager->GetViewSpaceSubdivisionType() ==  
     1482                HierarchyManager::NO_VIEWSPACE_SUBDIV) 
     1483                return 1; 
     1484 
     1485        int nViewCells = 0; 
     1486 
     1487        ViewCell::NewMail(); 
     1488 
     1489        ObjectContainer::const_iterator oit, oit_end = objects.end(); 
     1490 
     1491        // loop through all object and collect view cell pvs of this node 
     1492        for (oit = objects.begin(); oit != oit_end; ++ oit) 
     1493        { 
     1494                nViewCells += CountViewCells(*oit); 
     1495        } 
     1496 
     1497        return nViewCells; 
    14281498} 
    14291499 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1548 r1576  
    724724                const bool setCounter = false) const; 
    725725 
     726        /** Counts the view cells of this object. note: only 
     727                counts unmailed objects. 
     728        */ 
     729        int CountViewCells(Intersectable *obj) const; 
     730 
     731        /** Counts the view cells seen by this bvh leaf 
     732        */ 
     733        int CountViewCells(const ObjectContainer &objects) const; 
     734 
    726735        /** Collects view cells which see an object. 
    727736        */ 
     
    731740                const bool useMailBoxing, 
    732741                const bool setCounter = false) const; 
     742 
     743        /** Evaluates increase in pvs size. 
     744        */ 
     745        int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate) const; 
    733746 
    734747        /** Rays will be clipped to the bounding box. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r1545 r1576  
    21652165         
    21662166        RegisterOption("VspTree.Construction.renderCostDecreaseWeight", 
    2167                         optFloat, 
    2168                         "vsp_construction_render_cost_decrease_weight=", 
    2169                         "0.99"); 
     2167                                optFloat, 
     2168                                "vsp_construction_render_cost_decrease_weight=", 
     2169                                "0.99"); 
    21702170 
    21712171        RegisterOption("VspTree.Termination.maxDepth", 
     
    21882188                                        optFloat, 
    21892189                                        "vsp_term_min_probability=", 
    2190                                         "0.001"); 
     2190                                        "0.0000001"); 
    21912191 
    21922192        RegisterOption("VspTree.Termination.maxRayContribution", 
    2193                         optFloat, 
    2194                         "vsp_term_ray_contribution=", 
    2195                         "0.9"); 
     2193                                optFloat, 
     2194                                "vsp_term_ray_contribution=", 
     2195                                "0.9"); 
    21962196         
    21972197        RegisterOption("VspTree.Termination.maxCostRatio", 
    2198                 optFloat, 
    2199                 "vsp_term_max_cost_ratio=", 
    2200                 "1.5"); 
     2198                                optFloat, 
     2199                                "vsp_term_max_cost_ratio=", 
     2200                                "1.5"); 
    22012201         
    22022202        RegisterOption("VspTree.Termination.maxViewCells", 
    2203                 optInt, 
    2204                 "vsp_term_max_view_cells=", 
    2205                 "10000"); 
     2203                                optInt, 
     2204                                "vsp_term_max_view_cells=", 
     2205                                "10000"); 
    22062206 
    22072207         
    22082208        RegisterOption("VspTree.Termination.missTolerance", 
    2209                 optInt, 
    2210                 "vsp_term_miss_tolerance=", 
    2211                 "4"); 
     2209                                optInt, 
     2210                                "vsp_term_miss_tolerance=", 
     2211                                "4"); 
    22122212 
    22132213        RegisterOption("VspTree.Termination.minGlobalCostRatio", 
     
    22372237 
    22382238        RegisterOption("VspTree.maxStaticMemory",  
    2239                 optFloat,  
    2240                 "vsp_max_static_mem=",  
    2241                 "8.0"); 
     2239                                        optFloat,  
     2240                                        "vsp_max_static_mem=",  
     2241                                        "8.0"); 
    22422242 
    22432243        RegisterOption("VspTree.useCostHeuristics", 
    2244                 optBool, 
    2245                 "vsp_use_cost_heuristics=", 
    2246                 "false"); 
     2244                                        optBool, 
     2245                                        "vsp_use_cost_heuristics=", 
     2246                                        "false"); 
    22472247 
    22482248        RegisterOption("VspTree.simulateOctree",  
    2249                 optBool,  
    2250                 "vsp_simulate_octree=",  
    2251                 "false"); 
     2249                                        optBool,  
     2250                                        "vsp_simulate_octree=",  
     2251                                        "false"); 
    22522252 
    22532253        RegisterOption("VspTree.Construction.randomize",  
    2254                 optBool,  
    2255                 "vsp_construction_randomize=",  
    2256                 "false"); 
     2254                                        optBool,  
     2255                                        "vsp_construction_randomize=",  
     2256                                        "false"); 
    22572257 
    22582258        RegisterOption("VspTree.subdivisionStats", 
     
    23982398                                        optFloat, 
    23992399                                        "bvh_term_min_objects=", 
    2400                                         "0.00001"); 
     2400                                        "0.0000001"); 
    24012401 
    24022402        RegisterOption("BvHierarchy.Termination.minRays", 
     
    25152515                                        "hierarchy_construction_multilevel=", 
    25162516                                        "false"); 
     2517 
     2518        RegisterOption("Hierarchy.Construction.levels", 
     2519                                        optInt, 
     2520                                        "hierarchy_construction_levels=", 
     2521                                        "4"); 
    25172522 
    25182523        ///////////////////////////////////////////////////////////////// 
  • GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp

    r1572 r1576  
    8181bool GvsPreprocessor::HandleRay(VssRay *vssRay) 
    8282{ 
    83         cout << "\nhere12 " << (int)vssRay->mFlags << endl; 
     83        cout << "x " << (int)vssRay->mFlags; 
    8484        const bool storeRaysForViz = true; 
    8585        mViewCellsManager->ComputeSampleContribution(*vssRay, true, storeRaysForViz); 
     
    367367        // add samples to ray queue 
    368368        VssRayContainer::const_iterator vit, vit_end = samples.end(); 
    369                 for (vit = samples.begin(); vit != vit_end; ++ vit) 
     369        for (vit = samples.begin(); vit != vit_end; ++ vit) 
    370370        { 
    371371                HandleRay(*vit); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1564 r1576  
    146146 
    147147        if (mOspTree) 
     148        { 
    148149                mOspTree->SetViewCellsManager(vcm); 
     150        } 
    149151        else if (mBvHierarchy) 
     152        { 
    150153                mBvHierarchy->SetViewCellsManager(vcm); 
     154        } 
    151155} 
    152156 
     
    179183                return mBvHierarchy->mBoundingBox; 
    180184        default: 
    181                 // empty box 
     185                // hack: empty box 
    182186                return AxisAlignedBox3(); 
    183187        } 
     
    198202        const float costDecr = tData.GetRenderCostDecrease(); 
    199203 
    200         switch (mObjectSpaceSubdivisionType) 
    201         { 
    202         case KD_BASED_OBJ_SUBDIV: 
    203                 AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 
    204                                                         costDecr, 
    205                                                         mTotalCost 
    206                                                         ); 
    207                 break; 
    208         case BV_BASED_OBJ_SUBDIV: 
    209                 AddSubdivisionStats(mBvHierarchy->mBvhStats.Leaves() + mVspTree->mVspStats.Leaves(), 
    210                                                         costDecr, 
    211                                                         mTotalCost 
    212                                                         ); 
    213                 break; 
    214         default: 
    215                 AddSubdivisionStats(mVspTree->mVspStats.Leaves(), 
    216                                                         costDecr, 
    217                                                         mTotalCost 
    218                                                         ); 
    219                 break; 
    220         } 
     204        AddSubdivisionStats(mHierarchyStats.Leaves(), 
     205                                                costDecr, 
     206                                                mTotalCost, 
     207                                                mTotalPvsEntries 
     208                                                ); 
    221209} 
    222210 
     
    224212void HierarchyManager::AddSubdivisionStats(const int splits, 
    225213                                                                                   const float renderCostDecr, 
    226                                                                                    const float totalRenderCost) 
     214                                                                                   const float totalRenderCost, 
     215                                                                                   const int pvsEntries) 
    227216{ 
    228217        mSubdivisionStats 
    229218                        << "#Splits\n" << splits << endl 
    230219                        << "#RenderCostDecrease\n" << renderCostDecr << endl  
     220                        << "#TotalPvsEntries\n" << pvsEntries << endl 
    231221                        << "#TotalRenderCost\n" << totalRenderCost << endl; 
    232                         //<< "#AvgRenderCost\n" << avgRenderCost << endl; 
    233222} 
    234223 
     
    525514                { 
    526515                        cout << mCurrentCandidate->Type() << " "; 
    527                         if (0) cout << "subdividing candidate " << ++ i << " of type "  
    528                                                 << mCurrentCandidate->Type() << endl; 
     516                 
     517                        // update stats 
    529518                        mHierarchyStats.nodes += 2; 
    530  
     519                        mHierarchyStats.pvsEntries += mCurrentCandidate->GetPvsEntriesIncr(); 
     520                        mHierarchyStats.memory += 0; // TODO 
    531521                        // subdivision successful 
    532522                        EvalSubdivisionStats(*mCurrentCandidate); 
     
    534524                        // reevaluate candidates affected by the split for view space splits,  
    535525                        // this would be object space splits and other way round 
    536                         if (repairQueue) RepairQueue(); 
     526                        if (repairQueue)  
     527                        {        
     528                                RepairQueue(); 
     529                        } 
    537530                } 
    538531 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1563 r1576  
    4949{ 
    5050public: 
    51  
     51        /// total number of entries in the pvs 
     52        int pvsEntries; 
     53        /// storage cost 
     54        int memory; 
    5255        /// total number of nodes 
    5356        int nodes; 
     
    8184                accumDepth = 0; 
    8285                repairTime = 0; 
     86                memory = 0; 
     87                pvsEntries = 0; 
    8388        } 
    8489 
     
    255260                const int splits, 
    256261                const float renderCostDecr, 
    257                 const float totalRenderCost); 
     262                const float totalRenderCost, 
     263                const int totalPvsEntries); 
    258264 
    259265        void CollectObjectSpaceDirtyList(); 
     
    343349 
    344350        //////// 
    345         //-- global criteria 
     351        //-- global termination criteria 
     352 
    346353        float mTermMinGlobalCostRatio; 
    347354        int mTermGlobalCostMissTolerance; 
    348355         
     356        //////////////////// 
     357 
    349358        /// keeps track of cost during subdivision 
    350359        float mTotalCost; 
    351360 
     361        int mTotalPvsEntries; 
    352362        HierarchyStatistics mHierarchyStats; 
    353363 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1570 r1576  
    433433                                                                tBackData); 
    434434         
    435                 const int maxCostMisses = sc->mMaxCostMisses; 
     435                const int maxCostMisses = sc->GetMaxCostMisses(); 
    436436 
    437437        // how often was max cost ratio missed in this branch? 
     
    505505        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
    506506 
     507        const float pvsSizeIncr = 0; // todo 
    507508#if 0 
    508509        const float priority = (float)-data.mDepth; 
     
    518519        splitCandidate.SetPriority(priority); 
    519520 
    520         splitCandidate.mMaxCostMisses =  
    521                 success ? splitCandidate.mParentData.mMaxCostMisses :  
    522         splitCandidate.mParentData.mMaxCostMisses + 1; 
     521        splitCandidate.SetMaxCostMisses(success ?  
     522                splitCandidate.mParentData.mMaxCostMisses :  
     523                splitCandidate.mParentData.mMaxCostMisses + 1); 
    523524} 
    524525 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1520 r1576  
    6262{        
    6363        Vector3 origin, direction;  
    64  
    6564    const int i = (int)RandomValue(0, (Real)((int)mPreprocessor.mObjects.size() - 1)); 
    66  
    6765        Intersectable *object = mPreprocessor.mObjects[i]; 
    6866         
     
    9593          
    9694        direction = UniformRandomVector(); 
    97  
    9895        const float c = Magnitude(direction); 
    9996 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1473 r1576  
    3838        /** Position in queue. 
    3939        */ 
    40         int GetPosition() const 
     40        inline int GetPosition() const 
    4141        { 
    4242                return mPosition; 
    4343        } 
     44 
     45        inline void SetSplitAxis(const int splitAxis) 
     46        { 
     47                mSplitAxis = splitAxis; 
     48        } 
     49        inline void SetMaxCostMisses(const int misses) 
     50        { 
     51                mMaxCostMisses = misses; 
     52        } 
     53        inline void SetPvsEntriesIncr(const int pvsEntriesIncr) 
     54        { 
     55                mPvsEntriesIncr = pvsEntriesIncr; 
     56        } 
     57 
     58        inline int GetSplitAxis() const 
     59        { 
     60                return mSplitAxis; 
     61        } 
     62        inline int GetMaxCostMisses() const 
     63        { 
     64                return mMaxCostMisses; 
     65        } 
     66        inline int GetPvsEntriesIncr() const 
     67        { 
     68                return mPvsEntriesIncr; 
     69        } 
     70 
     71protected: 
    4472 
    4573        /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned) 
     
    4775        /// the number of misses of max cost ratio until this split 
    4876        int mMaxCostMisses; 
    49  
    50 protected: 
    51  
    5277        /// render cost decrease achieved through this split 
    5378        float mRenderCostDecrease; 
    54          
     79        /// the decrease of the number of pvs entries 
     80        int mPvsEntriesIncr; 
    5581}; 
    5682 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1571 r1576  
    47744774 
    47754775        int sampleContributions = 0; 
    4776  
    47774776        VssRayContainer sampleRays; 
    47784777 
     
    47924791        mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox); 
    47934792 
    4794          
     4793#if TEST_EVALUATION 
     4794        VssRayContainer::const_iterator tit, tit_end = constructionRays.end(); 
     4795        for (tit = constructionRays.begin(); tit != tit_end; ++ tit) 
     4796        { 
     4797                storedRays.push_back(new VssRay(*(*tit))); 
     4798        } 
     4799#endif 
     4800 
    47954801        ///////////////////////// 
    47964802        //-- print satistics for subdivision and view cells 
     
    48004806        ResetViewCells(); 
    48014807        Debug << "\nView cells after construction:\n" << mCurrentViewCellsStats << endl; 
    4802  
    4803         if (0) 
    4804         { 
    4805                 OUT_STREAM stream("osptree.xml.zip"); 
    4806                 mHierarchyManager->ExportObjectSpaceHierarchy(stream); 
    4807         }        
    4808  
    48094808 
    48104809        ////////////// 
     
    55735572} 
    55745573 
    5575 //#define TEST_EVALUATION 
    55765574 
    55775575#if TEST_EVALUATION 
     
    55875585 
    55885586        // should directional sampling be used? 
    5589         const bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION); 
     5587        const bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 
    55905588 
    55915589        cout << "reseting pvs ... "; 
     
    56495647        } 
    56505648 
    5651         Debug << "\nrendercost hack: " << rc / mHierarchyManager->GetViewSpaceBox() << endl; 
     5649        Debug << "\nrendercost hack: " << rc / mViewSpaceBox.GetVolume() << endl; 
    56525650        mViewCellsTree->ExportStats(fileName); 
    56535651        cout << "finished" << endl; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1571 r1576  
    692692        int mMaxFilterSize; 
    693693         
    694          
    695  
     694        // only for debugging 
     695VssRayContainer storedRays; 
    696696        ////////////////// 
    697697        //-- visualization options 
     
    10271027}; 
    10281028 
    1029 #define TEST_EVALUATION 0 
     1029#define TEST_EVALUATION 1 
    10301030 
    10311031/** 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1571 r1576  
    616616void VspTree::CreateViewCell(VspTraversalData &tData, const bool updatePvs) 
    617617{ 
     618        /////////////// 
    618619        //-- create new view cell 
    619         VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode); 
     620        VspLeaf *leaf = tData.mNode; 
    620621         
    621622        VspViewCell *viewCell = new VspViewCell(); 
     
    627628        if (updatePvs) 
    628629        { 
    629                 //-- update pvs of view cell 
     630                // update pvs of view cell 
    630631                AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp); 
    631632 
     
    642643                /////////// 
    643644                //-- store sampling rays 
    644                 RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
     645        RayInfoContainer::const_iterator it, it_end = tData.mRays->end(); 
    645646 
    646647                for (it = tData.mRays->begin(); it != it_end; ++ it) 
    647648                { 
    648649                        (*it).mRay->Ref();                       
     650                        // note: should rather store rays with view cell 
    649651                        leaf->mVssRays.push_back((*it).mRay); 
    650652                } 
     
    689691                // create new interior node and two leaf node 
    690692                const AxisAlignedPlane splitPlane = sc->mSplitPlane; 
    691                 const int maxCostMisses = sc->mMaxCostMisses; 
     693                const int maxCostMisses = sc->GetMaxCostMisses(); 
    692694 
    693695                newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData); 
     
    788790 
    789791        // max cost threshold violated? 
    790         splitCandidate.mMaxCostMisses = maxCostRatioViolated  ?  
     792        splitCandidate.SetMaxCostMisses(maxCostRatioViolated  ?  
    791793                        splitCandidate.mParentData.mMaxCostMisses + 1: 
    792                         splitCandidate.mParentData.mMaxCostMisses; 
     794                        splitCandidate.mParentData.mMaxCostMisses); 
    793795         
    794796        float oldRenderCost; 
     
    800802 
    801803        splitCandidate.SetRenderCostDecrease(renderCostDecr); 
     804 
     805        // the increase in pvs entries num induced by this split 
     806        const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate); 
     807        splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 
    802808 
    803809#if 0 
     
    814820 
    815821 
     822int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate) const 
     823{ 
     824        float oldPvsSize = 0; 
     825        float fPvsSize = 0; 
     826        float bPvsSize = 0; 
     827         
     828        AxisAlignedPlane candidatePlane = splitCandidate.mSplitPlane; 
     829        RayInfoContainer::const_iterator rit,  
     830                rit_end = splitCandidate.mParentData.mRays->end(); 
     831 
     832        // this is the main ray classification loop! 
     833        for(rit = splitCandidate.mParentData.mRays->begin(); rit != rit_end; ++ rit) 
     834        { 
     835                VssRay *ray = (*rit).mRay; 
     836                RayInfo rayInf = *rit; 
     837                 
     838                float t; 
     839                // classify ray 
     840                const int cf =  
     841                        rayInf.ComputeRayIntersection(candidatePlane.mAxis,  
     842                                                                                  candidatePlane.mPosition, t); 
     843 
     844                UpdatePvsEntriesContribution(*ray, true, cf, fPvsSize, bPvsSize, oldPvsSize); 
     845        } 
     846         
     847        return (int)(fPvsSize + bPvsSize - oldPvsSize); 
     848} 
     849 
     850 
    816851VspInterior *VspTree::SubdivideNode(const AxisAlignedPlane &splitPlane, 
    817852                                                                        VspTraversalData &tData, 
     
    836871                          *backData.mRays); 
    837872 
    838         ///////////// 
    839873        //-- compute pvs 
    840874        frontData.mPvs = EvalPvsSize(*frontData.mRays); 
    841875        backData.mPvs = EvalPvsSize(*backData.mRays); 
    842         //Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl; 
    843          
     876                 
    844877        //-- split front and back node geometry and compute area 
    845878        tData.mBoundingBox.Split(splitPlane.mAxis,  
     
    851884        backData.mProbability = tData.mProbability - frontData.mProbability; 
    852885 
    853         // update some stats 
    854         // store maximal depth 
     886 
     887        //////// 
     888        //-- update some stats 
     889         
    855890        if (tData.mDepth > mVspStats.maxDepth) 
    856         { 
    857                 //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 
     891        {       //Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl; 
    858892                mVspStats.maxDepth = tData.mDepth; 
    859893        } 
    860894 
    861         // two more leaves 
     895        // two more leaves per split 
    862896        mVspStats.nodes += 2; 
    863897        /// and a new split 
     
    865899 
    866900 
    867     /////////////////////// 
     901        //////////////// 
    868902        //-- create front and back and subdivide further 
    869903 
     
    902936        CreateViewCell(frontData, false); 
    903937        CreateViewCell(backData, false); 
    904  
    905938 
    906939#if WORK_WITH_VIEWCELL_PVS 
     
    14361469        // mark objects in the front / back / both using mailboxing 
    14371470        // then count pvs sizes 
     1471 
    14381472        Intersectable::NewMail(3); 
    14391473        KdLeaf::NewMail(3); 
     
    14971531                  << "render cost decrease: " << renderCostDecrease << endl; 
    14981532#endif 
     1533 
    14991534        return renderCostDecrease; 
    15001535} 
     
    15191554 
    15201555        const int pvsSize = data.mPvs; 
    1521  
    15221556        RayInfoContainer::const_iterator rit, rit_end = data.mRays->end(); 
    15231557 
     
    15351569        } 
    15361570 
    1537  
     1571        ////////////// 
    15381572        //-- evaluate cost heuristics 
    1539  
    15401573        float pOverall = data.mProbability; 
    15411574 
     
    15551588 
    15561589 
    1557 void VspTree::UpdateContributionsToPvs(Intersectable *obj, 
    1558                                                                            const int cf, 
    1559                                                                            float &frontPvs, 
    1560                                                                            float &backPvs, 
    1561                                                                            float &totalPvs) const 
    1562 { 
    1563         if (!obj) return; 
    1564  
    1565         //const float renderCost = mViewCellsManager->SimpleRay &raynderCost(obj); 
    1566         const int renderCost = 1; 
    1567  
    1568         // object in no pvs => new 
    1569         if (!obj->Mailed() && !obj->Mailed(1) && !obj->Mailed(2)) 
    1570         { 
    1571                 totalPvs += renderCost; 
    1572         } 
    1573  
    1574         // QUESTION matt: is it safe to assume that  
    1575         // the object belongs to no pvs in this case? 
    1576         //if (cf == Ray::COINCIDENT) return; 
    1577  
    1578         if (cf >= 0) // front pvs 
    1579         { 
    1580                 if (!obj->Mailed() && !obj->Mailed(2)) 
    1581                 { 
    1582                         frontPvs += renderCost; 
    1583                  
    1584                         // already in back pvs => in both pvss 
    1585                         if (obj->Mailed(1)) 
    1586                                 obj->Mail(2); 
    1587                         else 
    1588                                 obj->Mail(); 
    1589                 } 
    1590         } 
    1591  
    1592         if (cf <= 0) // back pvs 
    1593         { 
    1594                 if (!obj->Mailed(1) && !obj->Mailed(2)) 
    1595                 { 
    1596                         backPvs += renderCost; 
    1597                  
    1598                         // already in front pvs => in both pvss 
    1599                         if (obj->Mailed()) 
    1600                                 obj->Mail(2); 
    1601                         else 
    1602                                 obj->Mail(1); 
    1603                 } 
    1604         } 
    1605 } 
    1606  
    1607  
    16081590void VspTree::UpdateContributionsToPvs(BvhLeaf *leaf, 
    16091591                                                                           const int cf, 
    16101592                                                                           float &frontPvs, 
    16111593                                                                           float &backPvs, 
    1612                                                                            float &totalPvs) const 
     1594                                                                           float &totalPvs, 
     1595                                                                           const bool countEntries) const 
    16131596{ 
    16141597        if (!leaf) return; 
    1615  
    1616         const int renderCost = (int)leaf->mObjects.size(); 
     1598        const int renderCost = countEntries ? 1 : (int)leaf->mObjects.size(); 
    16171599 
    16181600        // leaf in no pvs => new 
     
    16211603                totalPvs += renderCost; 
    16221604        } 
    1623  
    1624         // QUESTION matt: is it safe to assume that  
    1625         // the leaf belongs to no pvs in this case? 
    1626         //if (cf == Ray::COINCIDENT) return; 
    16271605 
    16281606        if (cf >= 0) // front pvs 
     
    16841662    }    
    16851663         
    1686         // QUESTION matt: is it safe to assume that  
    1687         // the object belongs to no pvs in this case? 
    1688         //if (cf == Ray::COINCIDENT) return; 
    1689  
    16901664        if (cf >= 0) // front pvs 
    16911665        { 
     
    21462120 
    21472121 
     2122int VspTree::EvalPvsEntriesContribution(const VssRay &ray,  
     2123                                                                                const bool isTermination) const 
     2124 
     2125{ 
     2126                Intersectable *obj;  
     2127                Vector3 pt; 
     2128                KdNode *node; 
     2129 
     2130                ray.GetSampleData(isTermination, pt, &obj, &node); 
     2131                if (!obj) return 0; 
     2132 
     2133                switch(mHierarchyManager->GetObjectSpaceSubdivisionType()) 
     2134                { 
     2135                case HierarchyManager::NO_OBJ_SUBDIV: 
     2136                { 
     2137                        if (!obj->Mailed()) 
     2138                        { 
     2139                                obj->Mail(); 
     2140                                return 1; 
     2141                        } 
     2142                         
     2143                        return 0; 
     2144                } 
     2145 
     2146                case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     2147                { 
     2148                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     2149                        if (!leaf->Mailed()) 
     2150                        { 
     2151                                leaf->Mail(); 
     2152                                return 1; 
     2153                        } 
     2154                         
     2155                        return 0; 
     2156                } 
     2157        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     2158                { 
     2159                        BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     2160 
     2161                        if (!bvhleaf->Mailed()) 
     2162                        { 
     2163                                bvhleaf->Mail(); 
     2164                                return 1; 
     2165                        } 
     2166                         
     2167                        return 0; 
     2168                } 
     2169        default: 
     2170                break; 
     2171        } 
     2172 
     2173        return 0; 
     2174} 
     2175 
     2176 
     2177int VspTree::EvalPvsEntriesSize(const RayInfoContainer &rays) const 
     2178{ 
     2179        int pvsSize = 0; 
     2180 
     2181        Intersectable::NewMail(); 
     2182        KdNode::NewMail(); 
     2183        BvhLeaf::NewMail(); 
     2184 
     2185        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     2186 
     2187        for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     2188        { 
     2189                VssRay *ray = (*rit).mRay; 
     2190 
     2191                pvsSize += EvalPvsEntriesContribution(*ray, true); 
     2192                pvsSize += EvalPvsEntriesContribution(*ray, false); 
     2193        } 
     2194 
     2195        return pvsSize; 
     2196} 
     2197 
     2198 
    21482199float VspTree::GetEpsilon() const 
    21492200{ 
     
    29913042 
    29923043 
    2993 int VspTree::EvalContributionToPvs(const VssRay &ray,  
    2994                                                                    const bool isTermination) const 
     3044void VspTree::UpdatePvsEntriesContribution(const VssRay &ray, 
     3045                                                                                   const bool isTermination, 
     3046                                                                                   const int cf, 
     3047                                                                                   float &frontPvs, 
     3048                                                                                   float &backPvs, 
     3049                                                                                   float &totalPvs) const 
     3050{ 
     3051        /*ray.GetSampleData(isTermination, pt, &obj, &node); 
     3052        if (!obj) return 0; 
     3053 
     3054        switch (mHierarchyManager->GetObjectSpaceSubdivisionType()) 
     3055        { 
     3056        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     3057                // TODO 
     3058                break; 
     3059        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     3060                { 
     3061                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     3062                        UpdateContributionsToPvs(leaf, true, cf, pvsFront, pvsBack, totalPvs, true);             
     3063                        break; 
     3064                } 
     3065        default: 
     3066                UpdateContributionsToPvs(obj, true, cf, pvsFront, pvsBack, totalPvs, true);      
     3067                break; 
     3068        }*/ 
     3069} 
     3070 
     3071 
     3072int VspTree::EvalContributionToPvs(const VssRay &ray, const bool isTermination) const 
    29953073{        
    29963074        Intersectable *obj;  
     
    30183096                { 
    30193097                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
    3020  
    30213098                        pvs += EvalContributionToPvs(leaf); 
    30223099                        break; 
     
    30483125        leaf->Mail(); 
    30493126 
     3127        // this is the pvs which is uniquely part of this kd leaf 
    30503128        int pvs = (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
    30513129 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1570 r1576  
    3636class VspTree; 
    3737class KdTreeStatistics; 
    38 //class SubdivisionCandidate; 
    39 //class VspSubdivisionCandidate; 
     38 
    4039 
    4140/** View space partition statistics. 
     
    781780        int EvalPvsSize(const RayInfoContainer &rays) const; 
    782781 
     782        int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate) const; 
     783 
     784        /** Returns number of effective entries in the pvs. 
     785        */ 
     786        int EvalPvsEntriesSize(const RayInfoContainer &rays) const; 
     787        int EvalPvsEntriesContribution(const VssRay &ray, const bool isTermination) const; 
    783788        /** Computes best cost for axis aligned planes. 
    784789        */ 
     
    845850                              RayInfoContainer &frontRays,  
    846851                                  RayInfoContainer &backRays) const; 
     852 
     853        void UpdatePvsEntriesContribution( 
     854                const VssRay &ray, 
     855                const bool isTermination, 
     856                const int cf, 
     857                float &frontPvs, 
     858                float &backPvs, 
     859                float &totalPvs) const; 
    847860 
    848861        /** Classfifies the object with respect to the  
     
    880893                float &frontPvs, 
    881894                float &backPvs, 
    882                 float &totalPvs) const; 
     895                float &totalPvsm, 
     896                const bool countEntries = false) const; 
    883897 
    884898        /** Evaluates the contribution for kd leaves. 
Note: See TracChangeset for help on using the changeset viewer.