Changeset 1259


Ignore:
Timestamp:
08/22/06 22:48:02 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
14 edited

Legend:

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

    r1251 r1259  
    15901590 
    15911591 
    1592  
    1593 } 
     1592bool BvHierarchy::AddLeafToPvs(BvhLeaf *leaf,  
     1593                                                           ViewCell *vc,  
     1594                                                           const float pdf,  
     1595                                                           float &contribution) 
     1596{ 
     1597        // add kd intersecable to pvs 
     1598        BvhIntersectable *bvhObj = GetOrCreateBvhIntersectable(leaf); 
     1599         
     1600        return vc->AddPvsSample(bvhObj, pdf, contribution); 
     1601} 
     1602 
     1603 
     1604} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h

    r1251 r1259  
    259259        ObjectContainer mObjects; 
    260260 
     261        /// universal counter 
     262        int mCounter; 
    261263protected: 
    262264 
     
    498500                @returns number of view cells found 
    499501        */ 
    500         int ComputeBoxIntersections(const AxisAlignedBox3 &box,  
    501                                                                 ViewCellContainer &viewCells) const; 
     502        int ComputeBoxIntersections( 
     503                const AxisAlignedBox3 &box,  
     504                ViewCellContainer &viewCells) const; 
    502505 
    503506 
     
    510513        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 
    511514 
     515        /** Add the bvh leaf to the pvs of the view cell. 
     516        */ 
     517        bool AddLeafToPvs( 
     518                BvhLeaf *leaf,  
     519                ViewCell *vc,  
     520                const float pdf,  
     521                float &contribution); 
    512522 
    513523protected: 
     
    560570                } 
    561571        }; 
    562  
    563572  
    564573        /** faster evaluation of split plane cost for kd axis aligned cells. 
     
    748757 
    749758        float EvalViewCellsVolume(BvhLeaf *leaf) const; 
     759 
    750760 
    751761protected: 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp

    r1237 r1259  
    2020#include "VspTree.h" 
    2121#include "OspTree.h" 
     22#include "BvHierarchy.h" 
    2223 
    2324 
     
    3334 
    3435 
    35 HierarchyManager::HierarchyManager(VspTree &vspTree, OspTree &ospTree): 
    36 mVspTree(vspTree), mOspTree(ospTree) 
    37 { 
    38         // cross references 
    39         mVspTree.mOspTree = &ospTree; 
    40         mOspTree.mVspTree = &vspTree; 
    41  
     36HierarchyManager::HierarchyManager(VspTree &vspTree, OspTree &ospTree) 
     37//:mVspTree(vspTree), mOspTree(ospTree) 
     38{ 
    4239        char subdivisionStatsLog[100]; 
    4340        Environment::GetSingleton()->GetStringValue("Hierarchy.subdivisionStats",  
     
    6360{ 
    6461        SubdivisionCandidate *vsc =  
    65                 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays); 
     62                mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, viewSpaceRays); 
    6663        mTQueue.Push(vsc); 
    6764 
    6865        SubdivisionCandidate *osc =  
    69                 mOspTree.PrepareConstruction(sampleRays, objects, forcedViewSpace, objectSpaceRays); 
     66                mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, objectSpaceRays); 
    7067 
    7168        mTQueue.Push(osc); 
     
    7875 
    7976        //mTotalCost -= costDecr; 
    80         // mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
    81  
    82         AddSubdivisionStats(mOspTree.mOspStats.Leaves() + mVspTree.mVspStats.Leaves(), 
     77        //mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 
     78 
     79        AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 
    8380                                                costDecr, 
    8481                                                mTotalCost 
     
    116113        PrepareConstruction(sampleRays, objects, forcedViewSpace, *viewSpaceRays, *objectSpaceRays); 
    117114 
    118         mVspTree.mVspStats.Reset(); 
    119         mVspTree.mVspStats.Start(); 
     115        mVspTree->mVspStats.Reset(); 
     116        mVspTree->mVspStats.Start(); 
    120117 
    121118        cout << "Constructing view space / object space tree ... \n"; 
     
    126123        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    127124 
    128         mVspTree.mVspStats.Stop(); 
     125        mVspTree->mVspStats.Stop(); 
    129126} 
    130127 
     
    139136        if (vspSplit) 
    140137        { 
    141                 VspNode *n = mVspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     138                VspNode *n = mVspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    142139        } 
    143140        else 
    144141        { 
    145                 KdNode *n = mOspTree.Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
     142                KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 
    146143        } 
    147144         
     
    209206        // during view space partition 
    210207        const bool savedCountMethod = mVspTree.mUseKdPvsForHeuristics; 
    211         const bool savedStoreMethod = mVspTree.mStoreKdPvs; 
     208        const bool savedStoreMethod = mVspTree.mStoreObjectPvs; 
    212209         
    213210        mVspTree.mUseKdPvsForHeuristics = false; 
    214         mVspTree.mStoreKdPvs = false; 
     211        mVspTree.mStoreObjectPvs = false; 
    215212#endif 
    216213 
    217214        SubdivisionCandidate *vsc =  
    218                 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
     215                mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
    219216 
    220217        // add to queue 
     
    224221        cout << "starting vsp contruction ... " << endl; 
    225222 
    226         mVspTree.mVspStats.Reset(); 
    227         mVspTree.mVspStats.Start(); 
     223        mVspTree->mVspStats.Reset(); 
     224        mVspTree->mVspStats.Start(); 
    228225 
    229226        int i = 0; 
     
    238235 
    239236        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    240         mVspTree.mVspStats.Stop(); 
    241          
     237        mVspTree->mVspStats.Stop(); 
    242238 
    243239 
     
    255251        // compute first candidate 
    256252        SubdivisionCandidate *osc = 
    257                 mOspTree.PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
     253                mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 
    258254 
    259255        Debug << "reseting cost, new total cost: " << mTotalCost << endl; 
    260         mTotalCost = mOspTree.mTotalCost; 
     256        mTotalCost = mOspTree->mTotalCost; 
    261257 
    262258    mTQueue.Push(osc); 
    263259 
    264         mOspTree.mOspStats.Reset(); 
    265         mOspTree.mOspStats.Start(); 
     260        mOspTree->mOspStats.Reset(); 
     261        mOspTree->mOspStats.Start(); 
    266262 
    267263        startTime = GetTime(); 
     
    272268        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
    273269 
    274         mOspTree.mOspStats.Stop(); 
    275  
    276         float rc = mOspTree.EvalRenderCost(sampleRays); 
     270        mOspTree->mOspStats.Stop(); 
     271 
     272        float rc = mOspTree->EvalRenderCost(sampleRays); 
    277273 
    278274        Debug << "here47 My render cost evalulation: " << rc << endl; 
     
    280276#if 0 
    281277        // reset parameters 
    282         mVspTree.mUseKdPvsForHeuristics = savedCountMethod; 
    283         mVspTree.mStoreKdPvs = savedStoreMethod; 
     278        mVspTree->mUseKdPvsForHeuristics = savedCountMethod; 
     279        mVspTree->mStoreObjectPvs = savedStoreMethod; 
    284280#endif 
    285281} 
     
    290286                                                                  AxisAlignedBox3 *forcedViewSpace) 
    291287{ 
    292         // only view space partition 
     288        // construct only view space partition 
    293289        // object kd tree is taken for osp 
    294290 
    295         mVspTree.mVspStats.Reset(); 
    296         mVspTree.mVspStats.Start(); 
     291        mVspTree->mVspStats.Reset(); 
     292        mVspTree->mVspStats.Start(); 
    297293 
    298294        RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 
    299295         
    300296        SubdivisionCandidate *sc =  
    301                 mVspTree.PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
     297                mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays); 
    302298 
    303299        mTQueue.Push(sc); 
     
    310306 
    311307        cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl; 
    312         mVspTree.mVspStats.Stop(); 
     308        mVspTree->mVspStats.Stop(); 
    313309} 
    314310 
     
    320316 
    321317 
    322 void HierarchyManager::CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList) 
     318void HierarchyManager::CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList) 
     319{ 
     320        switch (mObjectSpaceSubdivisonType) 
     321        { 
     322        case KD_BASED_OBJ_SUBDIV: 
     323                { 
     324                        OspTree::OspSubdivisionCandidate *sc =  
     325                                dynamic_cast<OspTree::OspSubdivisionCandidate *>(mCurrentCandidate); 
     326 
     327                        mOspTree->CollectDirtyCandidates(sc, dirtyList); 
     328                        break; 
     329                } 
     330        case BV_BASED_OBJ_SUBDIV: 
     331                { 
     332                        BvHierarchy::BvhSubdivisionCandidate *sc =  
     333                                dynamic_cast<BvHierarchy::BvhSubdivisionCandidate *>(mCurrentCandidate); 
     334 
     335                        mBvHierarchy->CollectDirtyCandidates(sc, dirtyList); 
     336                        break; 
     337                } 
     338        default: 
     339                break; 
     340        } 
     341} 
     342 
     343 
     344void HierarchyManager::CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList) 
     345{ 
     346        VspTree::VspSubdivisionCandidate *sc =  
     347                dynamic_cast<VspTree::VspSubdivisionCandidate *>(mCurrentCandidate); 
     348 
     349        mVspTree->CollectDirtyCandidates(sc, dirtyList); 
     350} 
     351 
     352 
     353void HierarchyManager::CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList) 
    323354{        
    324355        // we have either a object space or view space split 
    325356        if (mCurrentCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 
    326357        { 
    327                 VspTree::VspSubdivisionCandidate *sc =  
    328                         dynamic_cast<VspTree::VspSubdivisionCandidate *>(mCurrentCandidate); 
    329  
    330                 mVspTree.CollectDirtyCandidates(sc, dirtyList); 
     358                CollectViewSpaceDirtyList(dirtyList); 
    331359        } 
    332360        else // object space split 
    333         {                        
    334                 OspTree::OspSubdivisionCandidate *sc =  
    335                         dynamic_cast<OspTree::OspSubdivisionCandidate *>(mCurrentCandidate); 
    336  
    337                 mOspTree.CollectDirtyCandidates(sc, dirtyList); 
     361        {        
     362                CollectObjectSpaceDirtyList(dirtyList); 
    338363        } 
    339364} 
     
    380405} 
    381406 
    382 } 
     407 
     408} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h

    r1239 r1259  
    3939class VspTree; 
    4040class KdTreeStatistics; 
    41  
     41class BvHierarchy; 
    4242 
    4343 
     
    8686class HierarchyManager 
    8787{ 
     88        friend VspTree; 
     89        friend OspTree; 
     90        friend BvHierarchy; 
     91 
    8892public: 
    8993        /** Constructor taking an object space partition and a view space partition tree. 
     
    112116                                        AxisAlignedBox3 *forcedViewSpace); 
    113117 
    114 public: 
    115         VspTree &mVspTree; 
    116         OspTree &mOspTree; 
    117  
     118        enum  
     119        { 
     120                NO_OBJ_SUBDIV, 
     121                KD_BASED_OBJ_SUBDIV, 
     122                BV_BASED_OBJ_SUBDIV 
     123        }; 
     124 
     125        /** The type of object space subdivison 
     126        */ 
     127        inline int GetObjectSpaceSubdivisonType() const 
     128        { 
     129                return mObjectSpaceSubdivisonType; 
     130        } 
     131         
    118132protected: 
    119133 
     
    143157        void EvalSubdivisionStats(const SubdivisionCandidate &tData); 
    144158 
    145         void AddSubdivisionStats(const int splits, 
     159        void AddSubdivisionStats( 
     160                const int splits, 
    146161                const float renderCostDecr, 
    147162                const float totalRenderCost); 
    148163 
     164        void CollectObjectSpaceDirtyList(); 
     165        void CollectViewSpaceDirtyList(); 
     166 
     167        bool AddSampleToPvs(Intersectable *obj,  
     168                                                const float pdf, 
     169                                                float &contribution) const; 
     170 
     171        void CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList); 
     172        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList); 
     173                 
    149174 
    150175protected: 
     176 
     177        int mObjectSpaceSubdivisonType; 
     178 
     179        VspTree *mVspTree; 
     180        OspTree *mOspTree; 
     181        BvHierarchy *mBvHierarchy; 
    151182 
    152183        AxisAlignedBox3 mBoundingBox; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp

    r1251 r1259  
    27122712 
    27132713 
    2714 } 
     2714bool OspTree::AddLeafToPvs(KdLeaf *leaf,  
     2715                                                   ViewCell *vc,  
     2716                                                   const float pdf,  
     2717                                                   float &contribution) 
     2718{ 
     2719        // add kd intersecable to pvs 
     2720        KdIntersectable *kdObj = GetOrCreateKdIntersectable(leaf); 
     2721         
     2722        return vc->AddPvsSample(kdObj, pdf, contribution); 
     2723} 
     2724 
     2725 
     2726} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h

    r1251 r1259  
    397397        void InsertObjects(KdNode *node, const ObjectContainer &objects); 
    398398 
     399        /** Add the leaf to the pvs of the view cell. 
     400        */ 
     401        bool AddLeafToPvs( 
     402                KdLeaf *leaf,  
     403                ViewCell *vc,  
     404                const float pdf,  
     405                float &contribution); 
     406 
    399407protected: 
    400408 
     
    596604        /** Evaluate the contributions of view cell volume of the left and the right view cell. 
    597605        */ 
    598         void EvalRayContribution(KdLeaf *leaf, 
    599                                                                          const VssRay &ray,  
    600                                                                          float &renderCost); 
    601 void EvalViewCellContribution(KdLeaf *leaf,  
    602                                                                            ViewCell *viewCell, 
    603                                                                            float &renderCost); 
     606        void EvalRayContribution( 
     607                KdLeaf *leaf, 
     608                const VssRay &ray,  
     609                float &renderCost); 
     610         
     611        void EvalViewCellContribution( 
     612                KdLeaf *leaf,  
     613                ViewCell *viewCell, 
     614                float &renderCost); 
     615 
    604616        /** Evaluates the influence on the pvs of the event. 
    605617                @param ve the visibility event 
     
    718730                RayInfoContainer &rays); 
    719731 
     732 
    720733protected: 
    721  
    722734         
    723735        /// pointer to the hierarchy of view cells 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h

    r1239 r1259  
    5656typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue; 
    5757 
    58  
     58typedef vector<SubdivisionCandidate *> SubdivisionCandidateContainer; 
    5959} 
    6060 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1233 r1259  
    2121#include "VspTree.h" 
    2222#include "OspTree.h" 
    23  
     23#include "BvHierarchy.h" 
    2424 
    2525// should not count origin object for sampling because it disturbs heuristics 
     
    5858mMaxPvsRatio(1.0), 
    5959mViewCellPvsIsUpdated(false), 
    60 mPreprocessor(NULL), 
    61 mStoreKdPvs(false) 
     60mPreprocessor(NULL) 
    6261{ 
    6362        mViewSpaceBox.Initialize(); 
     
    107106        Environment::GetSingleton()->GetBoolValue("ViewCells.exportPvs", mExportPvs); 
    108107         
    109         Environment::GetSingleton()->GetBoolValue("ViewCells.storeKdPvs", mStoreKdPvs); 
    110  
    111  
    112108        char buf[100]; 
    113109        Environment::GetSingleton()->GetStringValue("ViewCells.samplingType", buf); 
     
    223219        Debug << "export pvs for view cells: " << mExportPvs << endl; 
    224220         
    225         Debug << "store kd pvs: " << mStoreKdPvs << endl; 
    226  
    227221        Debug << endl; 
    228222} 
     
    877871{ 
    878872        return mExportPvs; 
     873} 
     874 
     875 
     876bool ViewCellsManager::AddSampleToPvs(Intersectable *obj,  
     877                                                                          const Vector3 &hitPoint, 
     878                                                                          ViewCell *vc, 
     879                                                                          const float pdf,  
     880                                                                          float &contribution) const 
     881{ 
     882        if (!obj) return false; 
     883 
     884        // potentially visible objects 
     885        return vc->AddPvsSample(obj, pdf, contribution); 
    879886} 
    880887 
     
    24562463 
    24572464 
    2458 void ViewCellsManager::SetStoreKdPvs(const bool storeKdPvs) 
    2459 { 
    2460         mStoreKdPvs = storeKdPvs; 
    2461 } 
    2462  
    2463  
    2464 bool ViewCellsManager::GetStoreKdPVs() const 
    2465 { 
    2466         return mStoreKdPvs; 
    2467 } 
    2468  
    2469  
    24702465void ViewCellsManager::UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) 
    24712466{ 
     
    56815676        } 
    56825677 
    5683         // if addrays is true, sampled entities are stored in the pvs 
    5684         if (addRays) 
    5685         { 
    5686                 for (it = viewcells.begin(); it != viewcells.end(); ++ it)  
     5678        if (!addRays) 
     5679                return ray.mRelativePvsContribution; 
     5680 
     5681        // sampled objects are stored in the pvs 
     5682        for (it = viewcells.begin(); it != viewcells.end(); ++ it)  
     5683        { 
     5684                ViewCell *viewCell = *it; 
     5685 
     5686                if (!viewCell->GetValid()) 
     5687                        break; 
     5688 
     5689                AddSampleToPvs( 
     5690                        ray.mTerminationObject,  
     5691                        ray.mTermination,  
     5692                        viewCell,  
     5693                        ray.mPdf,  
     5694                        ray.mRelativePvsContribution); 
     5695 
     5696#if SAMPLE_ORIGIN_OBJECTS 
     5697 
     5698                AddSampleToPvs( 
     5699                        ray.mOriginObject,  
     5700                        ray.mOrigin,  
     5701                        viewCell,  
     5702                        ray.mPdf,  
     5703                        ray.mRelativePvsContribution); 
     5704#endif                   
     5705        } 
     5706 
     5707        return ray.mRelativePvsContribution; 
     5708} 
     5709 
     5710 
     5711bool VspOspViewCellsManager::AddSampleToPvs(Intersectable *obj,  
     5712                                                                                        const Vector3 &hitPoint, 
     5713                                                                                        ViewCell *vc, 
     5714                                                                                        const float pdf,  
     5715                                                                                        float &contribution) const 
     5716{ 
     5717        if (!obj) return false; 
     5718 
     5719        switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 
     5720    { 
     5721        case HierarchyManager::NO_OBJ_SUBDIV: 
     5722                        // potentially visible objects 
     5723                        return vc->AddPvsSample(obj, pdf, contribution); 
     5724 
     5725        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
    56875726                { 
    5688                         ViewCell *viewcell = *it; 
    5689              
    5690                         if (viewcell->GetValid()) 
    5691                         { 
    5692                                 // if ray not outside of view space 
    5693  
    5694                                 // add kd cell 
    5695                                 if (ray.mTerminationObject) 
    5696                                 { 
    5697                                         if (!mStoreKdPvs) 
    5698                                         { 
    5699                                                 viewcell->AddPvsSample(ray.mTerminationObject,  
    5700                                                         ray.mPdf, ray.mRelativePvsContribution); 
    5701                                         } 
    5702                                         else 
    5703                                         { 
    5704                                                 // get current leaf the point is located in 
    5705                                                 KdLeaf *leaf = mOspTree->GetLeaf(ray.mTermination); 
    5706                                                 KdIntersectable *entry = mOspTree->GetOrCreateKdIntersectable(leaf); 
    5707  
    5708                                                 viewcell->AddPvsSample(entry, ray.mPdf, ray.mRelativePvsContribution); 
    5709                                         } 
    5710                                 } 
    5711                                  
    5712 #if SAMPLE_ORIGIN_OBJECTS 
    5713                                  if (ray.mOriginObject) 
    5714                                  { 
    5715                                          if (!mStoreKdPvs) 
    5716                                          { 
    5717                                                  viewcell->AddPvsSample(ray.mOriginObject, ray.mPdf, ray.mPvsContribution); 
    5718                                          } 
    5719                                          else 
    5720                                          { 
    5721                                                  /// get current leaf the point 
    5722                                                 KdLeaf *leaf = mOspTree->GetLeaf(ray.mOrigin); 
    5723                                                 KdIntersectable *entry = mOspTree->GetOrCreateKdIntersectable(leaf); 
    5724  
    5725                                                 viewcell->AddPvsSample(entry, ray.mPdf, ray.mRelativePvsContribution); 
    5726                                          } 
    5727                                  } 
    5728 #endif 
    5729                         } 
    5730                 } 
    5731         } 
    5732  
    5733         return ray.mRelativePvsContribution; 
     5727                        // potentially visible kd cells 
     5728                        KdLeaf *leaf = mOspTree->GetLeaf(hitPoint/*ray->mOriginNode*/); 
     5729                        return mOspTree->AddLeafToPvs(leaf, vc, pdf, contribution); 
     5730                } 
     5731        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     5732                { 
     5733                        BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj); 
     5734                        return mBvHierarchy->AddLeafToPvs(leaf, vc, pdf, contribution); 
     5735                } 
     5736        default: 
     5737                return false; 
     5738        } 
    57345739} 
    57355740 
     
    58115816        UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs); 
    58125817 
    5813  
    5814 //-- test render cost 
    5815  
    5816 sprintf(s, "-%09d-eval.log", castSamples); 
    5817 string fileName = string(statsPrefix) + string(s); 
    5818  
    5819 ViewCellContainer leaves; 
    5820  
    5821 mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 
    5822 float rc = 0; 
    5823 ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
    5824 for (vit = leaves.begin(); vit != vit_end; ++ vit) 
    5825 { 
    5826         ViewCell *vc = *vit; 
     5818        /////////////////////////////////////// 
     5819        //-- temporary matt: test render cost 
     5820 
     5821        sprintf(s, "-%09d-eval.log", castSamples); 
     5822        string fileName = string(statsPrefix) + string(s); 
     5823 
     5824        ViewCellContainer leaves; 
     5825 
     5826        mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves); 
     5827        float rc = 0; 
     5828        ViewCellContainer::const_iterator vit, vit_end = leaves.end(); 
     5829        for (vit = leaves.begin(); vit != vit_end; ++ vit) 
     5830        { 
     5831                ViewCell *vc = *vit; 
    58275832                int pvs = vc->GetPvs().CountObjectsInPvs(); 
    5828         float vol = vc->GetVolume(); 
    5829         rc += pvs * vol; 
    5830  
    5831         } 
    5832          
     5833                float vol = vc->GetVolume(); 
     5834                rc += pvs * vol; 
     5835 
     5836        } 
     5837 
    58335838        Debug << "\nhere295 " << rc / mVspTree->GetBoundingBox().GetVolume() << endl; 
    5834  
    58355839        mViewCellsTree->ExportStats(fileName); 
    5836          
    58375840        cout << "finished" << endl; 
    58385841 
     
    58405843} 
    58415844#endif 
    5842 ////////////////////////////////// 
    5843 /*ViewCellsManager *ViewCellsManagerFactory::Create(const string mName) 
    5844 { 
    5845         //TODO 
    5846         return NULL;// new VspBspViewCellsManager(); 
    5847 }*/ 
    5848  
    5849  
    5850 } 
     5845 
     5846 
     5847} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1201 r1259  
    3636class VspNode; 
    3737class HierarchyManager; 
     38class BvHierarchy; 
     39 
    3840struct AxisAlignedPlane; 
    39  
    4041struct BspRay; 
    4142 
     
    490491        bool GetStoreKdPVs() const; 
    491492 
     493        virtual bool AddSampleToPvs( 
     494                Intersectable *obj,  
     495                const Vector3 &hitPoint, 
     496                ViewCell *vc, 
     497                const float pdf,  
     498                float &contribution) const; 
     499 
    492500protected: 
    493501 
     
    672680        bool mExportPvs; 
    673681 
    674         bool mStoreKdPvs; 
     682        bool mStoreObjectPvs; 
    675683 
    676684        VssRayContainer storedRays; 
     
    10161024                BoundingBoxConverter *bconverter); 
    10171025 
     1026        bool AddSampleToPvs( 
     1027                Intersectable *obj,  
     1028                const Vector3 &hitPoint, 
     1029                ViewCell *vc, 
     1030                const float pdf,  
     1031        float &contribution) const; 
    10181032 
    10191033protected: 
     
    10501064 
    10511065        ///////////////////////////////////////// 
    1052         /// the view space partition tree. 
     1066 
     1067        /// the view space / object partition hierarchies 
    10531068        VspTree *mVspTree; 
    10541069        OspTree *mOspTree; 
     1070        BvHierarchy *mBvHierarchy; 
    10551071 
    10561072        HierarchyManager *mHierarchyManager; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp

    r1251 r1259  
    1818#include "KdTree.h" 
    1919#include "KdIntersectable.h" 
     20#include "HierarchyManager.h" 
     21#include "BvHierarchy.h" 
    2022#include "OspTree.h" 
     23 
    2124 
    2225namespace GtpVisibilityPreprocessor { 
     
    358361mStoreRays(false), 
    359362mTimeStamp(1), 
    360 mOspTree(NULL) 
     363mHierarchyManager(NULL) 
    361364{ 
    362365        bool randomize = false; 
     
    397400        Environment::GetSingleton()->GetBoolValue("VspTree.simulateOctree", mCirculatingAxis); 
    398401         
    399         Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvsForHeuristics", mUseKdPvsForHeuristics); 
     402        //Environment::GetSingleton()->GetBoolValue("VspTree.useKdPvsForHeuristics", mUseKdPvsForHeuristics); 
    400403 
    401404        char subdivisionStatsLog[100]; 
     
    433436        Debug << "maxband: " << mMaxBand << endl; 
    434437 
    435         if (!mUseKdPvsForHeuristics) 
    436                 Debug << "pvs heuristics: per object" << endl; 
    437         else 
    438                 Debug << "pvs heuristics: per kd node" << endl; 
    439  
    440438        mLocalSubdivisionCandidates = new vector<SortableEntry>; 
    441439 
     
    911909 
    912910 
    913 bool VspTree::AddKdLeafToPvs(KdLeaf *leaf,  
    914                                                          ViewCell *vc,  
    915                                                          const float pdf,  
    916                                                          float &contribution) 
    917 { 
    918         bool contri = false; 
    919  
    920 #if 1 // add kd intersecable to pvs 
    921         KdIntersectable *kdObj = mOspTree->GetOrCreateKdIntersectable(leaf); 
    922          
    923         if (vc->AddPvsSample(kdObj, pdf, contribution)) 
    924         { 
    925                 return true; 
    926         } 
    927  
    928 #else // add all objects of kd node 
    929  
    930         contribution = 0; 
    931  
    932         ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 
    933  
    934         for (it = leaf->mObjects.begin(); it != it_end; ++ it) 
    935         { 
    936                 Intersectable *object = *it;                                             
    937  
    938                 float newcontri; 
    939                                                  
    940                 if (vc->AddPvsSample(object, pdf, newcontri)) 
    941                 { 
    942                         contri = true; 
    943                 } 
    944  
    945                 //pdf += newPdf; 
    946                 newContri += contribution; 
    947         } 
    948 #endif 
    949  
    950         return contri; 
    951 } 
    952911 
    953912 
     
    977936                if (obj)  
    978937                { 
    979                         if (!mStoreKdPvs) 
    980                         { 
    981                                 // potentially visible objects 
    982                                 madeContrib = vc->AddPvsSample(obj, ray->mPdf, contribution); 
    983                         } 
    984                         else 
    985                         { 
    986                                 // potentially visible kd cells 
    987                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode);        
    988                                 madeContrib = AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
    989                         }        
     938                        madeContrib =  
     939                                mViewCellsManager->AddSampleToPvs( 
     940                                        obj,  
     941                                        ray->mTermination,  
     942                                        vc,  
     943                                        ray->mPdf,  
     944                                        contribution); 
    990945 
    991946                        sc += contribution; 
     
    996951                if (obj)  
    997952                { 
    998                         if (!mStoreKdPvs) 
    999                         { 
    1000                                 // potentially visible objects 
    1001                                 madeContrib = vc->AddPvsSample(obj, ray->mPdf, contribution); 
    1002                         } 
    1003                         else 
    1004                         { 
    1005                                 // potentially visible kd cells 
    1006                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode);        
    1007                                 madeContrib = AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution); 
    1008                         }        
     953                        madeContrib =  
     954                                mViewCellsManager->AddSampleToPvs( 
     955                                        obj, 
     956                                        ray->mOrigin,  
     957                                        vc,  
     958                                        ray->mPdf,  
     959                                        contribution); 
    1009960 
    1010961                        sc += contribution; 
     
    10921043 
    10931044 
     1045int VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination) 
     1046{ 
     1047        int pvsSize = 0; 
     1048         
     1049        Intersectable *obj; 
     1050        Vector3 pt; 
     1051        KdNode *node; 
     1052 
     1053        ray.GetSampleData(isTermination, pt, &obj, &node); 
     1054 
     1055        if (!obj) 
     1056                return 0; 
     1057 
     1058        switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 
     1059        { 
     1060        case HierarchyManager::NO_OBJ_SUBDIV: 
     1061                { 
     1062                        if (!obj->Mailed()) 
     1063                        { 
     1064                                obj->Mail(); 
     1065                                obj->mCounter = 1; 
     1066 
     1067                                ++ pvsSize; 
     1068                        } 
     1069                        else 
     1070                        { 
     1071                                ++ obj->mCounter; 
     1072                        } 
     1073                        break; 
     1074                } 
     1075        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     1076                { 
     1077                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     1078                        pvsSize += PrepareHeuristics(leaf);      
     1079                        break; 
     1080                } 
     1081        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     1082                { 
     1083                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj, NULL); 
     1084 
     1085                        if (!leaf->Mailed()) 
     1086                        { 
     1087                                leaf->Mail(); 
     1088                                leaf->mCounter = 1; 
     1089 
     1090                                ++ pvsSize; 
     1091                        } 
     1092                        else 
     1093                        { 
     1094                                ++ leaf->mCounter; 
     1095                        } 
     1096                        break; 
     1097                } 
     1098        default: 
     1099                break; 
     1100        } 
     1101 
     1102        return pvsSize; 
     1103} 
     1104 
     1105 
    10941106int VspTree::PrepareHeuristics(KdLeaf *leaf) 
    10951107{        
     
    11441156        RayInfoContainer::const_iterator ri, ri_end = rays.end(); 
    11451157 
    1146         //-- set all kd nodes / objects as belonging to the front pvs 
    1147  
     1158    // set all kd nodes / objects as belonging to the front pvs 
    11481159        for (ri = rays.begin(); ri != ri_end; ++ ri) 
    11491160        { 
    11501161                VssRay *ray = (*ri).mRay; 
    1151                 Intersectable *oObject = ray->mOriginObject; 
    1152  
    1153                 if (oObject) 
    1154                 { 
    1155                         if (!mUseKdPvsForHeuristics) 
    1156                         { 
    1157                                 if (!oObject->Mailed()) 
    1158                                 { 
    1159                                         oObject->Mail(); 
    1160                                         oObject->mCounter = 1; 
    1161  
    1162                                         ++ pvsSize; 
    1163                                 } 
    1164                                 else 
    1165                                 { 
    1166                                         ++ oObject->mCounter; 
    1167                                 } 
    1168                         } 
    1169                         else 
    1170                         { 
    1171                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    1172                                 pvsSize += PrepareHeuristics(leaf);      
    1173                         }        
    1174                 } 
    1175  
    1176                 Intersectable *tObject = (*ri).mRay->mTerminationObject; 
    1177  
    1178                 if (tObject) 
    1179                 { 
    1180                         if (!mUseKdPvsForHeuristics) 
    1181                         { 
    1182                                 if (!tObject->Mailed()) 
    1183                                 { 
    1184                                         tObject->Mail(); 
    1185                                         tObject->mCounter = 1; 
    1186                                         ++ pvsSize; 
    1187                                 } 
    1188                                 else 
    1189                                 { 
    1190                                         ++ tObject->mCounter; 
    1191                                 } 
    1192                         } 
    1193                         else 
    1194                         { 
    1195                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    1196                                 pvsSize += PrepareHeuristics(leaf);      
    1197                         }        
    1198                 } 
     1162                 
     1163                pvsSize += PrepareHeuristics(*ray, true); 
     1164                pvsSize += PrepareHeuristics(*ray, false); 
    11991165        } 
    12001166 
     
    12031169 
    12041170 
    1205 void VspTree::RemoveContriFromPvs(KdLeaf *leaf, int &pvs) const 
    1206 { 
     1171int VspTree::EvalMaxEventContribution(KdLeaf *leaf) const 
     1172{ 
     1173        int pvs = 0; 
     1174 
    12071175        // leaf falls out of right pvs 
    12081176        if (-- leaf->mCounter == 0) 
     
    12111179        } 
    12121180 
    1213         //-- handle objects which are in several kd leaves separately  
     1181        //-- separately handle objects which are in several kd leaves 
     1182 
    12141183        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    12151184 
     
    12201189                if (-- object->mCounter == 0) 
    12211190                { 
    1222                         -- pvs; 
    1223                 } 
    1224         } 
    1225 } 
    1226  
    1227  
    1228 void VspTree::AddContriToPvs(KdLeaf *leaf, int &pvs) const 
     1191                        ++ pvs; 
     1192                } 
     1193        } 
     1194 
     1195        return pvs; 
     1196} 
     1197 
     1198 
     1199int VspTree::EvalMinEventContribution(KdLeaf *leaf) const 
    12291200{ 
    12301201        if (leaf->Mailed()) 
    1231                 return; 
     1202                return 0; 
    12321203         
    12331204        leaf->Mail(); 
    12341205 
    12351206        // add objects without those which are part of several kd leaves 
    1236         pvs += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
    1237  
    1238         //-- handle objects of several kd leaves separately 
     1207        int pvs = ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
     1208 
     1209        // separately handle objects which are part of several kd leaves  
    12391210        ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    12401211 
     
    12491220                        ++ pvs; 
    12501221                } 
    1251         }                                        
    1252 } 
    1253  
    1254  
    1255 void VspTree::EvalPvsIncr(const SortableEntry &ci, 
    1256                                                   int &pvsLeft, 
    1257                                                   int &pvsRight) const 
     1222        }        
     1223 
     1224        return pvs; 
     1225} 
     1226 
     1227 
     1228int VspTree::EvalMinEventContribution(const VssRay &ray,  
     1229                                                                          const bool isTermination) const 
     1230{ 
     1231        Intersectable *obj; 
     1232        Vector3 pt; 
     1233        KdNode *node; 
     1234 
     1235        ray.GetSampleData(isTermination, pt, &obj, &node); 
     1236 
     1237        if (!obj) return 0; 
     1238 
     1239        int pvs = 0; 
     1240 
     1241        switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 
     1242        { 
     1243        case HierarchyManager::NO_OBJ_SUBDIV: 
     1244                { 
     1245                        if (!obj->Mailed()) 
     1246                        { 
     1247                                obj->Mail(); 
     1248                                ++ pvs; 
     1249                        } 
     1250 
     1251                        break; 
     1252                } 
     1253        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     1254                { 
     1255                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     1256                        // add contributions of the kd nodes 
     1257                        pvs += EvalMinEventContribution(leaf); 
     1258                                         
     1259                        break; 
     1260                } 
     1261        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     1262                { 
     1263                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     1264 
     1265                        if (!leaf->Mailed()) 
     1266                        { 
     1267                                leaf->Mail(); 
     1268                                ++ pvs; 
     1269                        } 
     1270                        break; 
     1271                } 
     1272        default: 
     1273                break; 
     1274        } 
     1275        return pvs; 
     1276} 
     1277 
     1278 
     1279int VspTree::EvalMaxEventContribution(const VssRay &ray,  
     1280                                                                          const bool isTermination) const 
     1281{ 
     1282        Intersectable *obj; 
     1283        Vector3 pt; 
     1284        KdNode *node; 
     1285 
     1286        ray.GetSampleData(isTermination, pt, &obj, &node); 
     1287 
     1288        if (!obj) return 0; 
     1289 
     1290        int pvs = 0; 
     1291 
     1292        switch (mHierarchyManager->GetObjectSpaceSubdivisonType()) 
     1293        { 
     1294        case HierarchyManager::NO_OBJ_SUBDIV: 
     1295                { 
     1296                        if (-- obj->mCounter == 0) 
     1297                                ++ pvs; 
     1298                        break; 
     1299                } 
     1300        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     1301                { 
     1302                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     1303 
     1304                        // add contributions of the kd nodes 
     1305                        pvs += EvalMaxEventContribution(leaf); 
     1306                        break; 
     1307                } 
     1308        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     1309                { 
     1310                        BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     1311 
     1312                        if (-- leaf->mCounter == 0) 
     1313                                ++ pvs; 
     1314                        break; 
     1315                } 
     1316        default: 
     1317                break; 
     1318        } 
     1319 
     1320        return pvs; 
     1321} 
     1322 
     1323 
     1324void VspTree::EvalHeuristicsContribution(const SortableEntry &ci, 
     1325                                                                                 int &pvsLeft, 
     1326                                                                                 int &pvsRight) const 
    12581327{ 
    12591328        VssRay *ray = ci.ray; 
    12601329 
    1261         Intersectable *oObject = ray->mOriginObject; 
    1262         Intersectable *tObject = ray->mTerminationObject; 
    1263  
    1264         if (oObject) 
    1265         {        
    1266                 if (!mUseKdPvsForHeuristics) 
    1267                 { 
    1268                         if (ci.type == SortableEntry::ERayMin) 
    1269                         { 
    1270                                 if (!oObject->Mailed()) 
    1271                                 { 
    1272                                         oObject->Mail(); 
    1273                                         ++ pvsLeft; 
    1274                                 } 
    1275                         } 
    1276                         else if (ci.type == SortableEntry::ERayMax) 
    1277                         { 
    1278                                 if (-- oObject->mCounter == 0) 
    1279                                         -- pvsRight; 
    1280                         } 
    1281                 } 
    1282                 else // per kd node 
    1283                 { 
    1284                         KdLeaf *node = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    1285  
    1286                         // add contributions of the kd nodes 
    1287                         if (ci.type == SortableEntry::ERayMin) 
    1288                         { 
    1289                                 AddContriToPvs(node, pvsLeft); 
    1290                         } 
    1291                         else if (ci.type == SortableEntry::ERayMax) 
    1292                         { 
    1293                                 RemoveContriFromPvs(node, pvsRight); 
    1294                         } 
    1295                 } 
    1296         } 
    1297          
    1298         if (tObject) 
    1299         {        
    1300                 if (!mUseKdPvsForHeuristics) 
    1301                 { 
    1302                         if (ci.type == SortableEntry::ERayMin) 
    1303                         { 
    1304                                 if (!tObject->Mailed()) 
    1305                                 { 
    1306                                         tObject->Mail(); 
    1307                                         ++ pvsLeft; 
    1308                                 } 
    1309                         } 
    1310                         else if (ci.type == SortableEntry::ERayMax) 
    1311                         { 
    1312                                 if (-- tObject->mCounter == 0) 
    1313                                         -- pvsRight; 
    1314                         } 
    1315                 } 
    1316                 else // per kd node 
    1317                 { 
    1318                         KdLeaf *node = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    1319  
    1320                         if (ci.type == SortableEntry::ERayMin) 
    1321                         { 
    1322                                 AddContriToPvs(node, pvsLeft); 
    1323                         } 
    1324                         else if (ci.type == SortableEntry::ERayMax) 
    1325                         { 
    1326                                 RemoveContriFromPvs(node, pvsRight); 
    1327                         } 
    1328                 } 
     1330        if (ci.type == SortableEntry::ERayMin) 
     1331        { 
     1332                pvsLeft += EvalMinEventContribution(*ray, true); 
     1333                pvsLeft += EvalMinEventContribution(*ray, false); 
     1334        } 
     1335        else 
     1336        { 
     1337                pvsRight -= EvalMaxEventContribution(*ray, true); 
     1338                pvsRight -= EvalMaxEventContribution(*ray, false); 
    13291339        } 
    13301340} 
     
    13361346                                                                           float &position) 
    13371347{ 
     1348        // get subset of rays 
    13381349        RayInfoContainer usedRays; 
    13391350 
     
    13951406        for (ci = mLocalSubdivisionCandidates->begin(); ci != ci_end; ++ ci) 
    13961407        { 
    1397                 EvalPvsIncr(*ci, pvsl, pvsr); 
     1408                EvalHeuristicsContribution(*ci, pvsl, pvsr); 
    13981409 
    13991410                // Note: sufficient to compare size of bounding boxes of front and back side? 
     
    15801591                        rayInf.ComputeRayIntersection(candidatePlane.mAxis,  
    15811592                                                                                  candidatePlane.mPosition, t); 
    1582  
     1593/* 
    15831594                if (!mUseKdPvsForHeuristics) 
    15841595                { 
     
    15911602                        if (ray->mTerminationObject) 
    15921603                        { 
    1593                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     1604                                KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    15941605                                UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 
    15951606                        } 
     
    15971608                        if (ray->mOriginObject) 
    15981609                        { 
    1599                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     1610                                KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    16001611                                UpdateKdLeafPvsContri(leaf, cf, pvsFront, pvsBack, totalPvs); 
    16011612                        } 
    16021613                } 
     1614*/ 
    16031615        } 
    16041616 
     
    22432255 
    22442256 
    2245 int VspTree::EvalPvsSize(const RayInfoContainer &rays) const 
    2246 { 
    2247         int pvsSize = 0; 
    2248         Intersectable::NewMail(); 
    2249  
    2250         RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
    2251  
    2252         if (!mUseKdPvsForHeuristics) 
    2253         { 
    2254                 for (rit = rays.begin(); rit != rays.end(); ++ rit) 
    2255                 { 
    2256                         VssRay *ray = (*rit).mRay; 
    2257  
    2258                         if (ray->mOriginObject) 
    2259                         { 
    2260                                 if (!ray->mOriginObject->Mailed()) 
     2257int VspTree::EvalPvsContribution(const VssRay &ray, const bool isTermination) const 
     2258{        
     2259        Intersectable *obj;  
     2260        Vector3 pt; 
     2261        KdNode *node; 
     2262 
     2263        ray.GetSampleData(isTermination, pt, &obj, &node); 
     2264 
     2265        if (!obj) return 0; 
     2266 
     2267        int pvs = 0; 
     2268 
     2269        switch(mHierarchyManager->GetObjectSpaceSubdivisonType()) 
     2270        { 
     2271        case HierarchyManager::NO_OBJ_SUBDIV: 
     2272                { 
     2273                        if (!obj->Mailed()) 
     2274                        { 
     2275                                obj->Mail(); 
     2276                                ++ pvs; 
     2277                        } 
     2278 
     2279                        break; 
     2280                } 
     2281        case HierarchyManager::KD_BASED_OBJ_SUBDIV: 
     2282                { 
     2283                        KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(pt, node); 
     2284 
     2285                        if (!leaf->Mailed()) 
     2286                        { 
     2287                                leaf->Mail(); 
     2288                                pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
     2289                                 
     2290                                ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
     2291                                for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    22612292                                { 
    2262                                         ray->mOriginObject->Mail(); 
    2263                                         ++ pvsSize; 
    2264                                 } 
    2265                         } 
    2266                         if (ray->mTerminationObject) 
    2267                         { 
    2268                                 if (!ray->mTerminationObject->Mailed()) 
    2269                                 { 
    2270                                         ray->mTerminationObject->Mail(); 
    2271                                         ++ pvsSize; 
    2272                                 } 
    2273                         } 
    2274                 } 
    2275         } 
    2276         else // compute pvs from kd nodes 
    2277         { 
    2278                 KdNode::NewMail(); 
    2279  
    2280                 for (rit = rays.begin(); rit != rays.end(); ++ rit) 
    2281                 { 
    2282                         VssRay *ray = (*rit).mRay; 
    2283  
    2284                         if (ray->mTerminationObject) 
    2285                         { 
    2286                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    2287  
    2288                                 if (!leaf->Mailed()) 
    2289                                 { 
    2290                                         leaf->Mail(); 
    2291                                         pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
    2292                                  
    2293                                         ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    2294                                         for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
     2293                                        Intersectable *obj = *oit; 
     2294 
     2295                                        if (!obj->Mailed()) 
    22952296                                        { 
    2296                                                 Intersectable *obj = *oit; 
    2297  
    2298                                                 if (!obj->Mailed()) 
    2299                                                 { 
    2300                                                         obj->Mail(); 
    2301                                                         ++ pvsSize; 
    2302                                                 } 
     2297                                                obj->Mail(); 
     2298                                                ++ pvs; 
    23032299                                        } 
    23042300                                } 
    23052301                        } 
    23062302 
    2307                         if (ray->mOriginObject) 
    2308                         { 
    2309                                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    2310  
    2311                                 if (!leaf->Mailed()) 
    2312                                 { 
    2313                                         leaf->Mail(); 
    2314                                         pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size()); 
    2315                                  
    2316                                         ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end(); 
    2317                                         for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit) 
    2318                                         { 
    2319                                                 Intersectable *obj = *oit; 
    2320  
    2321                                                 if (!obj->Mailed()) 
    2322                                                 { 
    2323                                                         obj->Mail(); 
    2324                                                         ++ pvsSize; 
    2325                                                 } 
    2326                                         } 
    2327                                 } 
    2328                         } 
    2329                 } 
    2330         } 
    2331  
     2303                        break; 
     2304                } 
     2305        case HierarchyManager::BV_BASED_OBJ_SUBDIV: 
     2306                { 
     2307                        BvhLeaf *bvhleaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj); 
     2308 
     2309                        if (!bvhleaf->Mailed()) 
     2310                        { 
     2311                                bvhleaf->Mail(); 
     2312                                pvs += (int)bvhleaf->mObjects.size(); 
     2313                        } 
     2314 
     2315                        break; 
     2316                } 
     2317        default: 
     2318                break; 
     2319        } 
     2320 
     2321        return pvs; 
     2322} 
     2323 
     2324 
     2325int VspTree::EvalPvsSize(const RayInfoContainer &rays) const 
     2326{ 
     2327        int pvsSize = 0; 
     2328         
     2329        Intersectable::NewMail(); 
     2330        KdNode::NewMail(); 
     2331        BvhNode::NewMail(); 
     2332 
     2333        RayInfoContainer::const_iterator rit, rit_end = rays.end(); 
     2334 
     2335        for (rit = rays.begin(); rit != rays.end(); ++ rit) 
     2336        { 
     2337                VssRay *ray = (*rit).mRay; 
     2338                pvsSize += EvalPvsContribution(*ray, true); 
     2339                pvsSize += EvalPvsContribution(*ray, false); 
     2340        } 
     2341         
    23322342        return pvsSize; 
    23332343} 
     
    28062816 
    28072817 
    2808 void VspTree::CollectDirtyCandidates(VspSubdivisionCandidate *sc,  
    2809                                                                          vector<SubdivisionCandidate *> &dirtyList) 
    2810 { 
    2811         VspTraversalData &tData = sc->mParentData; 
    2812         VspLeaf *node = tData.mNode; 
    2813          
    2814         KdLeaf::NewMail(); 
    2815  
    2816         RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
    2817  
    2818         // add all kd nodes seen by the rays 
    2819         for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
    2820         { 
    2821                 VssRay *ray = (*rit).mRay; 
    2822          
    2823                 KdLeaf *leaf = mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
    2824          
    2825                 if (!leaf->Mailed()) 
    2826                 { 
    2827                         leaf->Mail(); 
    2828                         dirtyList.push_back(leaf->mSubdivisionCandidate); 
    2829                 } 
    2830                  
    2831                 leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
    2832          
    2833                 if (!leaf->Mailed()) 
    2834                 { 
    2835                         leaf->Mail(); 
    2836                         dirtyList.push_back(leaf->mSubdivisionCandidate); 
    2837                 } 
    2838         } 
    2839 } 
    2840  
    2841  
    28422818void VspTree::PreprocessRays(const VssRayContainer &sampleRays, 
    28432819                                                         RayInfoContainer &rays) 
     
    29652941 
    29662942 
    2967  
    2968 } 
     2943void VspTree::CollectDirtyCandidates(VspSubdivisionCandidate *sc,  
     2944                                                                         vector<SubdivisionCandidate *> &dirtyList) 
     2945{ 
     2946        VspTraversalData &tData = sc->mParentData; 
     2947        VspLeaf *node = tData.mNode; 
     2948         
     2949        KdLeaf::NewMail(); 
     2950 
     2951        RayInfoContainer::const_iterator rit, rit_end = tData.mRays->end(); 
     2952 
     2953        // add all kd nodes seen by the rays 
     2954        for (rit = tData.mRays->begin(); rit != rit_end; ++ rit) 
     2955        { 
     2956                VssRay *ray = (*rit).mRay; 
     2957         
     2958                KdLeaf *leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mOrigin, ray->mOriginNode); 
     2959         
     2960                if (!leaf->Mailed()) 
     2961                { 
     2962                        leaf->Mail(); 
     2963                        dirtyList.push_back(leaf->mSubdivisionCandidate); 
     2964                } 
     2965                 
     2966                leaf = mHierarchyManager->mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode); 
     2967         
     2968                if (!leaf->Mailed()) 
     2969                { 
     2970                        leaf->Mail(); 
     2971                        dirtyList.push_back(leaf->mSubdivisionCandidate); 
     2972                } 
     2973        } 
     2974} 
     2975 
     2976} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h

    r1251 r1259  
    3131class KdInterior; 
    3232class KdLeaf; 
    33 class OspTree; 
     33class HierarchyManager; 
    3434class KdIntersectable; 
    3535class KdTree; 
     
    759759                                                         float maxBand); 
    760760 
    761         /** Evaluate pvs size associated with the rays. 
     761        /** Evaluate pvs size as induced by the samples. 
    762762        */ 
    763763        int EvalPvsSize(const RayInfoContainer &rays) const; 
     
    778778                                                                  float &position); 
    779779 
    780         /** Evaluates the influence on the pvs of the visibility event ve. 
     780        /** Evaluates the contribution to left and right pvs at a visibility event ve. 
    781781                @param ve the visibility event 
    782782                @param pvsLeft updates the left pvs 
    783783                @param rightPvs updates the right pvs 
    784784        */ 
    785         void EvalPvsIncr(const SortableEntry &ve, 
    786                                           int &pvsLeft, 
    787                                           int &pvsRight) const; 
    788  
    789         void RemoveContriFromPvs(KdLeaf *leaf, int &pvs) const; 
    790         void AddContriToPvs(KdLeaf *leaf, int &pvs) const; 
     785        void EvalHeuristicsContribution( 
     786                const SortableEntry &ve,  
     787                int &pvsLeft,  
     788                int &pvsRight) const; 
     789 
     790        /** Evaluates contribution of the ray to the left and right pvs. 
     791        */ 
     792        int EvalMinEventContribution( 
     793                const VssRay &ray, const bool isTermination) const; 
     794 
     795        int EvalMaxEventContribution( 
     796                const VssRay &ray, const bool isTermination) const; 
     797 
     798        int EvalMinEventContribution(KdLeaf *leaf) const; 
     799        int EvalMaxEventContribution(KdLeaf *leaf) const; 
    791800 
    792801        /** Prepares objects for the heuristics. 
     
    794803        */ 
    795804        int PrepareHeuristics(const RayInfoContainer &rays); 
    796  
     805        int PrepareHeuristics(const VssRay &ray, const bool isTermination); 
    797806        int PrepareHeuristics(KdLeaf *leaf); 
    798807 
     
    859868                                                 int &contributingSamples); 
    860869 
    861         bool AddKdLeafToPvs(KdLeaf *leaf,  
    862                                                 ViewCell *vc,  
    863                                                 const float pvs,  
    864                                                 float &contribution); 
    865  
    866870        /** Propagates valid flag up the tree. 
    867871        */ 
     
    898902        void EvalSubdivisionStats(const SubdivisionCandidate &tData); 
    899903 
    900         SubdivisionCandidate *PrepareConstruction(const VssRayContainer &sampleRays, 
    901                                                            AxisAlignedBox3 *forcedViewSpace, 
    902                                                            RayInfoContainer &rays); 
     904        SubdivisionCandidate *PrepareConstruction( 
     905                const VssRayContainer &sampleRays, 
     906                AxisAlignedBox3 *forcedViewSpace, 
     907                RayInfoContainer &rays); 
     908 
     909        /** Add pvs contribution of this ray. 
     910        */ 
     911        int EvalPvsContribution(const VssRay &ray, const bool isTermination) const; 
    903912 
    904913protected: 
    905  
    906914 
    907915        /// pointer to the hierarchy of view cells 
    908916        ViewCellsTree *mViewCellsTree; 
    909917 
    910         OspTree *mOspTree; 
    911  
    912         bool mUseKdPvsForHeuristics; 
    913         bool mStoreKdPvs; 
    914  
     918        HierarchyManager *mHierarchyManager; 
     919        //OspTree *mOspTree; 
     920        //bool mUseKdPvsForHeuristics; 
     921         
    915922        ViewCellsManager *mViewCellsManager; 
    916923         
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp

    r1112 r1259  
    264264} 
    265265 
    266 } 
     266 
     267void VssRay::GetSampleData(const bool isTermination,  
     268                                                   Vector3 &pt,  
     269                                                   Intersectable **obj, 
     270                                                   KdNode **node) const 
     271{ 
     272        if (isTermination) 
     273        { 
     274                pt = mTermination; 
     275                *obj = mTerminationObject; 
     276                *node = mTerminationNode; 
     277        } 
     278        else 
     279        { 
     280                pt = mOrigin; 
     281                *obj = mOriginObject; 
     282                *node = mOriginNode; 
     283        } 
     284} 
     285 
     286 
     287} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h

    r1221 r1259  
    282282    return SqrMagnitude(diff); 
    283283  } 
     284 
     285  void GetSampleData( 
     286          const bool isTerminaton,  
     287          Vector3 &pt,  
     288          Intersectable **obj, 
     289          KdNode **node) const; 
     290 
    284291  friend ostream& operator<< (ostream &s, const VssRay &vssRay); 
    285292     
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h

    r1233 r1259  
    266266  }; 
    267267 
     268  void GetSampleData(const bool isTerminaton,  
     269                                  Vector3 &pt,  
     270                                  Intersectable **obj, 
     271                                  KdNode **node) const; 
    268272 
    269273  typedef vector<RayInfo> RayInfoContainer; 
Note: See TracChangeset for help on using the changeset viewer.