Ignore:
Timestamp:
11/25/06 04:07:13 (18 years ago)
Author:
mattausch
Message:

implemented dirty pvs and lazy update

File:
1 edited

Legend:

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

    r1789 r1790  
    206206                @returns iterator on the sample. 
    207207        */ 
    208         typename vector<PvsEntry<T, S> >::iterator Find(T sample, const bool checkDirty = true); 
     208        bool Find(T sample, 
     209                          typename vector<PvsEntry<T, S> >::iterator &it, 
     210                          const bool checkDirty = true); 
    209211 
    210212        bool GetSampleContribution(T sample, const float pdf, float &contribution); 
     
    391393                float aSumPdf = 0.0f; 
    392394 
    393                 vector<PvsEntry<T, S> >::iterator oit = Find((*it).mObject);             
    394  
    395                 const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     395                vector<PvsEntry<T, S> >::iterator oit; 
     396                const bool entryFound = Find((*it).mObject, oit);                
    396397 
    397398                if (entryFound) 
     
    427428                        (*it).mData.mSumPdf = -aSumPdf; 
    428429                } else { 
    429                         vector<PvsEntry<T, S> >::iterator oit = b.Find((*it).mObject); 
    430  
    431                         const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
    432                          
     430                        vector<PvsEntry<T, S> >::iterator oit; 
     431                 
     432                        const bool entryFound = b.Find((*it).mObject, oit); 
     433                                                 
    433434                        if (entryFound) { 
    434435                                bSumPdf = (*oit).mData.mSumPdf; 
     
    461462        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
    462463        { 
    463                 std::vector<PvsEntry<T, S> >::const_iterator bit = Find((*it).first);            
    464                 if (bit == mEntries.end()) ++ dif; 
     464                vector<PvsEntry<T, S> >::iterator bit; 
     465                const bool entryFound = Find((*it).first, bit); 
     466 
     467                if (!entryFound) ++ dif; 
    465468        } 
    466469 
     
    586589 
    587590template <typename T, typename S>  
    588 typename std::vector<PvsEntry<T, S> >::iterator Pvs<T, S>::Find(T sample, const bool checkDirty) 
    589 { 
     591bool Pvs<T, S>::Find(T sample, 
     592                                         typename vector<PvsEntry<T, S> >::iterator &it, 
     593                                         const bool checkDirty) 
     594{ 
     595        bool found = false; 
     596 
    590597        PvsEntry<T, S> dummy(sample, PvsData()); 
    591598 
     
    593600        //mLastSorted = 0; 
    594601        vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted; 
    595 if (sorted_end != mEntries.end()) 
    596 cout << "not entries end!! " << endl; 
     602 
    597603        // binary search 
    598         vector<PvsEntry<T, S> >::iterator it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     604        it = lower_bound(mEntries.begin(), sorted_end, dummy); 
     605 
     606        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     607                found = true; 
    599608 
    600609        // sample not found yet => search further in the unsorted part 
    601         if (checkDirty && 
    602                 ((it == mEntries.end()) || ((*it).mObject != sample))) 
    603         { 
    604                 vector<PvsEntry<T, S> >::const_iterator it_end = mEntries.end(); 
    605                 for (it = sorted_end; (it != it_end) && ((*it).mObject != sample); ++ it); 
    606         } 
    607         else cout << "f "; 
    608         return it; 
     610        if (!found && checkDirty) 
     611        { 
     612                vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end(); 
     613 
     614                for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit); 
     615 
     616                if ((dit != mEntries.end()) && ((*dit).mObject == sample)) 
     617                        found = true; 
     618        } 
     619         
     620        return found; 
    609621} 
    610622 
     
    625637{ 
    626638        ++ mSamples; 
    627         cout << "! "; 
    628         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    629  
    630         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    631         {       cout << "g"; 
     639         
     640        vector<PvsEntry<T, S> >::iterator it; 
     641        const bool entryFound = Find(sample, it);                
     642 
     643        if (entryFound) 
     644        {        
    632645                S &data = (*it).mData; 
    633646                data.mSumPdf += pdf; 
     
    635648        } 
    636649        else  
    637         {cout << "t"; 
     650        { 
    638651                PvsEntry<T, S> entry(sample, pdf); 
    639652                mEntries.insert(it, entry); 
     
    641654                return pdf; 
    642655        } 
    643         cout << " $"; 
    644656} 
    645657 
     
    654666 
    655667template <typename T, typename S> 
    656 typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, const float pdf) 
     668typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample,  
     669                                                                                                                                  const float pdf) 
    657670{ 
    658671        ++ mSamples; 
    659672         
    660         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    661  
    662         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     673        vector<PvsEntry<T, S> >::iterator it; 
     674        const bool entryFound == Find(sample, it); 
     675 
     676        if (entryFound) 
    663677        { 
    664678                S &data = (*it).second; 
     
    674688        return it; 
    675689} 
    676  
    677  
    678 /*template <typename T, typename S>  
    679 bool Pvs<T, S>::AddSample(T sample, 
    680                                                   const float pdf, 
    681                                                   float &contribution) 
    682 { 
    683         ++ mSamples; 
    684  
    685         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    686  
    687         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
    688         { 
    689                 S &data = (*it).mData; 
    690  
    691                 data.mSumPdf += pdf; 
    692                 contribution = pdf / data.mSumPdf; 
    693  
    694                 return false; 
    695         } 
    696         else  
    697         { 
    698                 PvsEntry<T, S> entry(sample, pdf); 
    699  
    700                 mEntries.insert(it, entry); 
    701                 contribution = 1.0f; 
    702                 ++ mLastSorted; 
    703  
    704                 return true; 
    705         } 
    706 }*/ 
    707690 
    708691 
     
    717700        ++ mSamples; 
    718701 
    719         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    720  
    721         if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     702        vector<PvsEntry<T, S> >::iterator it; 
     703        const bool entryFound = Find(sample, it); 
     704 
     705        if (entryFound) 
    722706        { 
    723707                S &data = (*it).mData; 
     
    743727                                                                          float &contribution)  
    744728{ 
    745         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    746  
    747         if (it != mEntries.end() && ((*it).mObject == sample))   
     729        vector<PvsEntry<T, S> >::iterator it; 
     730        const bool entryFound = Find(sample, it); 
     731 
     732        if (entryFound)   
    748733        { 
    749734                S &data = (*it).mData; 
     
    764749        -- mSamples; 
    765750         
    766         std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
    767  
    768         if (it == mEntries.end()) 
     751        vector<PvsEntry<T, S> >::iterator it; 
     752        const bool entryFound = Find(sample, it); 
     753 
     754        if (!entryFound) 
    769755                return false; 
    770756 
Note: See TracChangeset for help on using the changeset viewer.