Changeset 1133


Ignore:
Timestamp:
07/13/06 09:06:21 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h

    r1077 r1133  
    3131 
    3232  /// kd leaves that this intersectable belongs to 
    33   set<KdLeaf *> mKdLeaves; 
     33  //set<KdLeaf *> mKdLeaves; 
    3434 
    3535  enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE }; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.h

    r860 r1133  
    1212class Vector3; 
    1313 
     14 
    1415typedef vector<RayInfo> RayInfoContainer; 
     16 
     17 
    1518/** Structure holding additional info about 
    1619        the ray during traversal. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1121 r1133  
    252252        const bool result = mPvs.AddSample(sample, pdf, contribution); 
    253253 
    254         // update pvs size 
     254        // update pvs size scalar 
    255255        mPvsSize = mPvs.GetSize(); 
    256256        mPvsSizeValid = true; 
     
    260260 
    261261 
     262bool ViewCell::AddKdPvsSample(KdLeaf *sample, 
     263                                                          const float pdf,  
     264                                                          float &contribution) 
     265{ 
     266        const bool result = mKdPvs.AddSample(sample, pdf, contribution); 
     267 
     268        return result; 
     269} 
    262270 
    263271/************************************************************************/ 
     
    16871695                Intersectable *obj = (*oit).first; 
    16881696 
    1689                 set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
    1690  
    1691                 for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    1692                 { 
    1693                         KdLeaf *leaf = *kit; 
     1697/*              KdLeaf *leaf = ; 
    16941698 
    16951699                        pvsSize += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size()); 
     
    17091713                                } 
    17101714                        }                
    1711                 } 
     1715                }*/ 
    17121716        } 
    17131717 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1121 r1133  
    191191        bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution); 
    192192   
    193  
     193        bool AddKdPvsSample(KdLeaf *sample, const float pdf, float &contribution); 
    194194 
    195195        /// Rays piercing this view cell. 
     
    267267        /// the potentially visible objects 
    268268        ObjectPvs mPvs; 
     269        /// the potentially visible kd leaves 
     270        KdPvs mKdPvs; 
    269271 
    270272        float mVolume; 
     
    685687        */ 
    686688        ViewCell *GetInitialLeftViewCell() const; 
     689        /** Returns leaf view cell initially associated with this merge candidate. 
     690        */ 
    687691        ViewCell *GetInitialRightViewCell() const; 
    688692 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1129 r1133  
    54925492 
    54935493                                // collect kd leaves 
     5494                                //KdLeaf = 
    54945495                                set<KdLeaf *>::const_iterator kdit, kdit_end = obj->mKdLeaves.end(); 
    54955496 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r1084 r1133  
    715715 
    716716        /////////////////////////////////////////////////////////// 
     717 
     718 
    717719protected: 
    718720         
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1129 r1133  
    324324mOutOfBoundsCell(NULL), 
    325325mStoreRays(false), 
    326 mTimeStamp(1) 
     326mTimeStamp(1), 
     327mOspTree(NULL) 
    327328{ 
    328329        bool randomize = false; 
     
    790791 
    791792 
    792 /*void VspTree::RemoveParentViewCellReferences(VspTraversalData &parentData) 
    793 { 
    794         RayInfoContainer::const_iterator it, it_end = parentData.mRays->end(); 
    795  
    796         KdLeaf::NewMail(); 
    797         Intersectable::NewMail(); 
    798  
    799         ViewCell *vc = parentData.mNode->mViewCell; 
    800  
    801         const float highestContri = 1e25; 
    802  
    803         // add contributions from samples to the PVS 
    804         for (it = parentData.mRays->begin(); it != it_end; ++ it) 
    805         { 
    806                 VssRay *ray = (*it).mRay; 
    807  
    808                 Intersectable *obj = ray->mTerminationObject; 
    809  
    810                 if (obj && !obj->Mailed()) 
    811                 { 
    812                         obj->Mail(); 
    813                         // reduce object reference count by one 
    814                         -- obj->mViewCellPvs; 
    815  
    816                         set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
    817  
    818                         for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    819                         { 
    820                                 KdLeaf *leaf = *kit; 
    821   
    822                                 if (!leaf->Mailed()) 
    823                                 { 
    824                                         leaf->Mail(); 
    825                                         leaf->mViewCellPvs.RemoveSample(vc, highestContri); 
    826                                 } 
    827                         } 
    828                 } 
    829  
    830                 Intersectable *obj = ray->mOriginObject; 
    831  
    832                 if (obj && !obj->Mailed()) 
    833                 { 
    834                         obj->Mail(); 
    835                         // reduce object reference count by one 
    836                         -- obj->mViewCellPvs; 
    837  
    838                         set<KdLeaf *>::const_iterator kit, kit_end = obj->mKdLeaves.end(); 
    839  
    840                         for (kit = obj->mKdLeaves.begin(); kit != kit_end; ++ kit) 
    841                         { 
    842                                 KdLeaf *leaf = *kit; 
    843  
    844                                 if (!leaf->Mailed()) 
    845                                 { 
    846                                         leaf->Mail(); 
    847                                         leaf->mViewCellPvs.RemoveSample(vc, highestContri); 
    848                                 } 
    849                         } 
    850                 } 
    851         } 
    852 }*/ 
     793KdNode *VspTree::GetKdNode(VssRay &ray, const bool termination) const 
     794{ 
     795        if (termination) 
     796        { 
     797                if (!ray.mTerminationNode) 
     798                { 
     799                        ray.mTerminationNode = mOspTree->GetRoot(); 
     800                } 
     801 
     802                ray.mTerminationNode =  
     803                        mOspTree->GetLeaf(ray.mTermination, ray.mTerminationNode); 
     804 
     805                return ray.mTerminationNode; 
     806        } 
     807        else 
     808        { 
     809                if (!ray.mOriginNode) 
     810                { 
     811                        ray.mOriginNode = mOspTree->GetRoot(); 
     812                } 
     813 
     814                ray.mOriginNode =  
     815                        mOspTree->GetLeaf(ray.mOrigin, ray.mOriginNode); 
     816 
     817                return ray.mOriginNode; 
     818        } 
     819} 
    853820 
    854821 
     
    920887 
    921888                        sc += contribution; 
     889 
     890                        // potentially visible kd cells 
     891                        const bool termination = true; 
     892                        vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 
    922893                } 
    923894 
     
    932903 
    933904                        sc += contribution; 
     905 
     906                        // potentially visible kd cells 
     907                        const bool termination = false; 
     908                        vc->AddKdPvsSample(GetKdLeaf(ray, termination)); 
    934909                } 
    935910 
     
    28262801 
    28272802        SplitObjects(splitPlane, leaf->mObjects, front->mObjects, back->mObjects); 
    2828  
    2829         ProcessLeafObjects(leaf, front, back); 
     2803        //ProcessLeafObjects(leaf, front, back); 
    28302804     
    28312805        backData.mNode = back; 
     
    29922966         
    29932967        float totalVol = PrepareHeuristics(node->mObjects); 
    2994         int voll = 0, volr = totalVol; 
     2968        float voll = 0; 
     2969        float volr = totalVol; 
    29952970   
    29962971        const int totalPvs = (int)node->mObjects.size(); 
     
    30242999        for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci) 
    30253000        { 
    3026                 EvalPvsIncr(*ci, voll, volr); 
     3001                EvalViewCellVolumeIncr(*ci, voll, volr); 
    30273002 
    30283003                cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id "  
     
    30603035        const float pFront = volFront; 
    30613036 
    3062         const float penaltyOld = totalPvs;//EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 
    3063     const float penaltyFront = totalPvs - pvsBack;//EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 
    3064         const float penaltyBack = pvsBack;//EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 
     3037        const float penaltyOld = (float)totalPvs;//EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 
     3038    const float penaltyFront = (float)totalPvs - pvsBack;//EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 
     3039        const float penaltyBack = (float)pvsBack;//EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 
    30653040         
    30663041        const float oldRenderCost = penaltyOld * pOverall + Limits::Small; 
     
    31633138 
    31643139 
    3165 void OspTree::EvalPvsIncr(const SortableEntry &ci, 
    3166                                                   int &pvsLeft, 
    3167                                                   int &pvsRight) const 
     3140void OspTree::EvalViewCellVolumeIncr(const SortableEntry &ci, 
     3141                                                                         float &volLeft, 
     3142                                                                         float &volRight) const 
    31683143{ 
    31693144        Intersectable *obj = ci.mObject; 
     
    31723147        { 
    31733148                case SortableEntry::BOX_MIN: 
    3174                         AddContriToPvs(obj, pvsLeft); 
     3149                        AddContriToPvs(obj, volLeft); 
    31753150                        break; 
    31763151                         
    31773152                case SortableEntry::BOX_MAX: 
    3178                         RemoveContriFromPvs(obj, pvsRight); 
     3153                        RemoveContriFromPvs(obj, volRight); 
    31793154                        break; 
    31803155        } 
    31813156 
    3182         cout << "pvs left: " << pvsLeft << " pvs right " << pvsRight << endl; 
     3157        //cout << "vol left: " << volLeft << " vol right " << volRight << endl; 
    31833158} 
    31843159 
     
    31963171 
    31973172 
    3198 void OspTree::RemoveContriFromPvs(Intersectable *object, int &pvs) const 
     3173void OspTree::RemoveContriFromPvs(Intersectable *object, float &pvs) const 
    31993174{ 
    32003175        if (mUseEqualWeightForHeuristics) 
     
    32063181 
    32073182 
    3208 void OspTree::AddContriToPvs(Intersectable *object, int &pvs) const 
     3183void OspTree::AddContriToPvs(Intersectable *object, float &pvs) const 
    32093184{ 
    32103185        if (mUseEqualWeightForHeuristics) 
     
    34143389} 
    34153390 
    3416  
     3391#if DEPRECATED 
    34173392void OspTree::ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const 
    34183393{ 
     
    34913466         
    34923467} 
    3493  
     3468#endif 
    34943469 
    34953470void OspTree::CollectLeaves(vector<KdLeaf *> &leaves) const 
     
    36083583 
    36093584 
     3585KdLeaf *OspTree::GetLeaf(const Vector3 &pt, KdNode *node) const 
     3586{ 
     3587        if (node == NULL) 
     3588                node = mRoot; 
     3589 
     3590        stack<KdNode *> nodeStack; 
     3591        nodeStack.push(node); 
     3592   
     3593        KdLeaf *leaf = NULL; 
     3594   
     3595        while (!nodeStack.empty())   
     3596        { 
     3597                KdNode *node = nodeStack.top(); 
     3598                nodeStack.pop(); 
     3599         
     3600                if (node->IsLeaf())  
     3601                { 
     3602                        leaf = dynamic_cast<KdLeaf *>(node); 
     3603                }  
     3604                else     
     3605                {        
     3606                        KdInterior *interior = dynamic_cast<KdInterior *>(node); 
     3607         
     3608                        // random decision 
     3609                        if (interior->mPosition < pt[interior->mAxis]) 
     3610                                nodeStack.push(interior->mBack); 
     3611                        else 
     3612                                nodeStack.push(interior->mFront); 
     3613                } 
     3614        } 
     3615   
     3616        return leaf; 
     3617} 
     3618 
     3619 
     3620KdNode *OspTree::GetRoot() const 
     3621{ 
     3622        return mRoot; 
     3623} 
     3624 
     3625 
    36103626/********************************************************************/ 
    36113627/*               class HierarchyManager implementation              */ 
     
    36173633mVspTree(vspTree), mOspTree(ospTree) 
    36183634{ 
     3635        mVspTree.mOspTree = &ospTree; 
    36193636} 
    36203637 
     
    36343651 
    36353652void HierarchyManager::ProcessRays(const VssRayContainer &sampleRays, 
    3636                                                                    RayInfoContainer &rays, 
    3637                                                                    ObjectContainer &sampledObjects) 
     3653                                                                   RayInfoContainer &rays) 
    36383654{ 
    36393655        VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); 
     
    36643680                        rays.push_back(RayInfo(ray, minT / len, maxT / len)); 
    36653681                } 
    3666  
    3667                 // store objects 
    3668                 if (ray->mTerminationObject && !ray->mTerminationObject->Mailed()) 
    3669                 { 
    3670                         ray->mTerminationObject->Mail(); 
    3671                         sampledObjects.push_back(ray->mTerminationObject); 
    3672                 } 
    3673  
    3674                 if (ray->mOriginObject && !ray->mOriginObject->Mailed()) 
    3675                 { 
    3676                         ray->mOriginObject->Mail(); 
    3677                         sampledObjects.push_back(ray->mOriginObject); 
    3678                 } 
    36793682        } 
    36803683 
     
    36833686 
    36843687 
    3685 void HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 
    3686                                                                   AxisAlignedBox3 *forcedViewSpace, 
    3687                                                                   RayInfoContainer &rays) 
     3688SplitCandidate *HierarchyManager::PrepareVsp(const VssRayContainer &sampleRays, 
     3689                                                                                         AxisAlignedBox3 *forcedViewSpace, 
     3690                                                                                         RayInfoContainer &rays 
     3691                                                                                         ) 
    36883692{ 
    36893693        // prepare bounding box 
     
    36913695 
    36923696        // get clipped rays 
    3693         ObjectContainer sampledObjects; 
    3694         ProcessRays(sampleRays, rays, sampledObjects); 
    3695  
    3696         //const int pvsSize = mVspTree.ComputePvsSize(rays); 
    3697         const int pvsSize = (int)sampledObjects.size(); 
    3698  
     3697        ProcessRays(sampleRays, rays); 
     3698 
     3699        const int pvsSize = mVspTree.ComputePvsSize(rays); 
     3700         
    36993701        cout <<  "here450 pvs size: " << pvsSize << endl; 
    37003702        // -- prepare view space partition 
     
    37033705        VspLeaf *leaf = new VspLeaf(); 
    37043706        mVspTree.mRoot = leaf; 
     3707 
    37053708        const float prop = mVspTree.mBoundingBox.GetVolume(); 
    37063709 
     
    37213724                oit_end = leaf->GetViewCell()->GetPvs().mEntries.end(); 
    37223725 
    3723         cout << "here23 " << leaf->GetViewCell()->GetPvs().mEntries.size(); 
    37243726 
    37253727        for (oit = leaf->GetViewCell()->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 
    37263728        { 
    37273729                Intersectable *obj = (*oit).first; 
    3728                 cout << "obj: " << obj->GetId() << endl; 
    37293730                obj->mViewCellPvs.AddSample(leaf->GetViewCell(), 1); 
    37303731        } 
    37313732 
    37323733        // compute first split candidate 
    3733         VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData); 
     3734        VspTree::VspSplitCandidate *splitCandidate =  
     3735                new VspTree::VspSplitCandidate(vData); 
    37343736    mVspTree.EvalSplitCandidate(*splitCandidate); 
    37353737 
    3736         mTQueue.Push(splitCandidate); 
    3737 } 
    3738  
    3739  
    3740 void HierarchyManager::PrepareOsp(const ObjectContainer &objects,                                                                                  
    3741                                                                   AxisAlignedBox3 *forcedViewSpace) 
     3738        return splitCandidate; 
     3739} 
     3740 
     3741 
     3742SplitCandidate * HierarchyManager::PrepareOsp(const ObjectContainer &objects, 
     3743                                                                                          AxisAlignedBox3 *forcedViewSpace) 
    37423744{ 
    37433745        mOspTree.PrepareConstruction(objects, forcedViewSpace); 
     
    37623764 
    37633765                 
    3764         mOspTree.ProcessLeafObjects(NULL, kdleaf, NULL); 
     3766        //mOspTree.ProcessLeafObjects(NULL, kdleaf, NULL); 
    37653767 
    37663768        // compute first split candidate 
     
    37693771    mOspTree.EvalSplitCandidate(*oSplitCandidate); 
    37703772 
    3771         mTQueue.Push(oSplitCandidate); 
     3773        return oSplitCandidate; 
    37723774} 
    37733775 
     
    37783780                                                                                   RayInfoContainer &rays) 
    37793781{ 
    3780         PrepareVsp(sampleRays, forcedViewSpace, rays); 
    3781         PrepareOsp(objects, forcedViewSpace); 
     3782        mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, rays)); 
     3783        mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 
    37823784} 
    37833785 
     
    37983800        // makes no sense otherwise because only one kd cell available 
    37993801        // during view space partition 
    3800         const int savedCountMethod = 
     3802        const int savedCountMethod = mVspTree.mPvsCountMethod; 
    38013803        mVspTree.mPvsCountMethod = VspTree::PER_OBJECT; 
    38023804 
    3803         PrepareVsp(sampleRays, forcedViewSpace, *rays); 
     3805        mTQueue.Push(PrepareVsp(sampleRays, forcedViewSpace, *rays)); 
    38043806 
    38053807        long startTime = GetTime(); 
     
    38423844 
    38433845        //-- object space partition 
    3844     PrepareOsp(objects, forcedViewSpace); 
     3846    mTQueue.Push(PrepareOsp(objects, forcedViewSpace)); 
    38453847 
    38463848        i = 0; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1129 r1133  
    3232class KdInterior; 
    3333class KdLeaf; 
     34class OspTree; 
     35 
    3436 
    3537class KdTreeStatistics; 
     
    752754        ViewCellsTree *mViewCellsTree; 
    753755 
     756        OspTree *mOspTree; 
     757 
    754758protected: 
    755759 
     
    10041008                vector<SplitCandidate *> &dirtyList); 
    10051009 
     1010        KdNode *GetKdNode(VssRay &ray, const bool termination) const; 
     1011 
     1012 
    10061013protected: 
    10071014 
     
    10101017 
    10111018        ViewCellsManager *mViewCellsManager; 
     1019         
    10121020        vector<SortableEntry> *mSplitCandidates; 
    10131021 
     
    10911099        int mCreatedViewCells; 
    10921100 
    1093         /// weight between  render cost decrease and node render cost 
     1101        /// weight between render cost decrease and node render cost 
    10941102        float mRenderCostDecreaseWeight; 
    10951103}; 
     
    13351343 
    13361344 
     1345        KdLeaf *GetLeaf(const Vector3 &pt, KdNode *node) const; 
     1346 
     1347 
    13371348        /// pointer to the hierarchy of view cells 
    13381349        ViewCellsTree *mViewCellsTree; 
     
    14391450                                          ObjectContainer &back); 
    14401451 
     1452#if DEPRECATED 
    14411453         /** does some post processing on the objects in the new child leaves. 
    14421454         */ 
    14431455        void ProcessLeafObjects(KdLeaf *parent, KdLeaf *front, KdLeaf *back) const; 
    1444  
     1456#endif 
    14451457        /** Selects an axis aligned for the next split. 
    14461458                @returns cost for this split 
     
    15391551                @param rightPvs updates the right pvs 
    15401552        */ 
    1541         void EvalPvsIncr(const SortableEntry &ve, 
    1542                                           int &pvsLeft, 
    1543                                           int &pvsRight) const; 
    1544  
    1545         void RemoveContriFromPvs(Intersectable *object, int &pvs) const; 
    1546         void AddContriToPvs(Intersectable *object, int &pvs) const; 
     1553        void EvalViewCellVolumeIncr(const SortableEntry &ve, 
     1554                float &volLeft, 
     1555                float &volRight) const; 
     1556 
     1557        void RemoveContriFromPvs(Intersectable *object, float &pvs) const; 
     1558        void AddContriToPvs(Intersectable *object, float &pvs) const; 
    15471559 
    15481560        /** Prepares objects for the cost heuristics. 
     
    17211733        void CollectDirtyCandidates(vector<SplitCandidate *> &dirtyList); 
    17221734 
    1723         void PrepareVsp(const VssRayContainer &sampleRays, 
     1735        SplitCandidate * PrepareVsp(const VssRayContainer &sampleRays, 
    17241736                AxisAlignedBox3 *forcedViewSpace, 
    17251737                RayInfoContainer &rays); 
    17261738 
    1727         void PrepareOsp(const ObjectContainer &objects, AxisAlignedBox3 *forcedViewSpace); 
     1739        SplitCandidate * PrepareOsp(const ObjectContainer &objects,  
     1740                AxisAlignedBox3 *forcedViewSpace); 
    17281741 
    17291742        void ProcessRays(const VssRayContainer &sampleRays, 
    1730                 RayInfoContainer &rays, 
    1731                 ObjectContainer &sampledObjects); 
     1743                RayInfoContainer &rays); 
    17321744 
    17331745 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h

    r1112 r1133  
    1212class AxisAlignedBox3; 
    1313class Intersectable; 
     14class KdNode; 
    1415 
    1516class VssRay { 
     
    5051  ViewCellContainer mViewCells; 
    5152   
     53 
    5254  //////////////////////// 
    5355  // members related to importance sampling 
     
    7072   
    7173  ////////////////////////////// 
     74 
     75   
     76  /// the kd node holding the termination point 
     77  KdNode *mTerminationNode; 
     78  /// the kd node holding the origin point 
     79  KdNode *mOriginNode; 
     80 
     81 
    7282  VssRay( 
    7383                 const Vector3 &origin, 
     
    8898        mViewCells(0), 
    8999        mWeightedPvsContribution(0), 
    90         mPdf(pdf) 
    91   { 
    92     Precompute(); 
    93   } 
     100        mPdf(pdf), 
     101        mTerminationNode(NULL), 
     102        mOriginNode(NULL) 
     103        { 
     104                Precompute(); 
     105        } 
    94106         
    95107  VssRay(const Ray &ray): 
     
    100112        mPass(0), 
    101113        mViewCells(0), 
    102         mPdf(1.0f) 
     114        mPdf(1.0f), 
     115        mTerminationNode(NULL), 
     116        mOriginNode(NULL) 
    103117  { 
    104118        if (ray.sourceObject.mObject) 
Note: See TracChangeset for help on using the changeset viewer.