Ignore:
Timestamp:
12/11/06 08:31:01 (18 years ago)
Author:
bittner
Message:

sampling updates

File:
1 edited

Legend:

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

    r1867 r1877  
    184184        int Compress() {return 0;} 
    185185        int GetSize() const {return (int)mEntries.size();} 
    186         bool Empty() const {return mEntries.empty();} 
    187  
     186  bool Empty() const {return mEntries.empty();} 
     187 
     188  void Reserve(const int n) { mEntries.reserve(n); } 
    188189        /** Normalize the visibility of entries in order to get  
    189190                comparable results. 
     
    231232        */ 
    232233        void Sort(); 
     234 
     235  /** Sort pvs entries assume that the pvs contains unique entries 
     236   */ 
     237  void SimpleSort(); 
    233238 
    234239        /** Adds sample to PVS. Assumes that the pvs is sorted 
     
    307312                // way we can achieve logarithmic behaviour for insertion and find 
    308313                const int dirtySize = (int)mEntries.size() - mLastSorted; 
    309                 return dirtySize > (int)(log((double)mEntries.size()) / log(2.0)); 
     314                return dirtySize > 4*(int)(log((double)mEntries.size()) / log(2.0)); 
    310315        } 
    311316 
     
    362367        mEntries = newPvs.mEntries; 
    363368        mLastSorted = (int)mEntries.size(); 
     369} 
     370 
     371template <typename T, typename S> 
     372void Pvs<T, S>::SimpleSort() 
     373{ 
     374  sort(mEntries.begin(), mEntries.end()); 
     375  mLastSorted = (int)mEntries.size(); 
    364376} 
    365377 
     
    587599                                         const bool checkDirty) 
    588600{ 
    589         bool found = false; 
    590  
    591         PvsEntry<T, S> dummy(sample, PvsData()); 
    592  
    593         // only check clean part 
    594         // $$ TMP JB 
    595         // mLastSorted = 0; 
    596         vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
    597  
    598         // binary search 
    599         it = lower_bound(mEntries.begin(), sorted_end, dummy); 
    600  
    601         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    602                 found = true; 
    603  
    604         // sample not found yet => search further in the unsorted part 
    605         if (!found && checkDirty) 
    606         { 
    607                 vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
    608  
    609                 for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 
    610                  
    611                 if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 
    612                         found = true; 
    613         } 
    614          
    615         return found; 
     601  bool found = false; 
     602   
     603  PvsEntry<T, S> dummy(sample, PvsData()); 
     604   
     605  // only check clean part 
     606  vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
     607   
     608  // binary search 
     609  it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     610   
     611  if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     612        found = true; 
     613   
     614  // sample not found yet => search further in the unsorted part 
     615  if (!found && checkDirty) { 
     616        vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
     617         
     618        for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit) ; 
     619         
     620        if (dit != dit_end) 
     621          found = true; 
     622  } 
     623   
     624  return found; 
    616625} 
    617626 
     
    698707        const bool entryFound = Find(sample, it); 
    699708 
    700         if (entryFound) 
    701         { 
    702                 S &data = (*it).mData; 
    703  
    704                 data.mSumPdf += pdf; 
    705                 //contribution = pdf / data.mSumPdf; 
    706  
    707                 return false; 
    708         } 
    709         else  
    710         { 
    711                 AddSampleDirty(sample, pdf); 
    712                 //contribution = 1.0f; 
    713  
    714                 return true; 
     709        if (entryFound) { 
     710          S &data = (*it).mData; 
     711           
     712          data.mSumPdf += pdf; 
     713          //contribution = pdf / data.mSumPdf; 
     714           
     715          return false; 
     716        } 
     717        else { 
     718          AddSampleDirty(sample, pdf); 
     719          //contribution = 1.0f; 
     720          return true; 
    715721        } 
    716722} 
Note: See TracChangeset for help on using the changeset viewer.