Ignore:
Timestamp:
11/10/06 22:15:56 (18 years ago)
Author:
mattausch
Message:

exchanged pvs implementation: using vectors instead of maps

File:
1 edited

Legend:

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

    r1739 r1740  
    1515 
    1616 
    17 template<typename T> 
    18 struct LtSample  
    19 { 
    20     bool operator()(const T a, const T b) const 
     17/** Information stored with a PVS entry. Consists of the number 
     18        the object was seen from the view cell. 
     19*/ 
     20template<typename T, typename S> 
     21class PvsEntry  
     22{ 
     23public: 
     24 
     25        PvsEntry(T sample, const S &data): mObject(sample), mData(data) {} 
     26 
     27        T mObject; 
     28        S mData; 
     29 
     30        template<typename T, typename S> 
     31        friend int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b); 
     32}; 
     33 
     34 
     35template<typename T, typename S> 
     36int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) 
     37{ 
     38        return a.mObject < b.mObject; 
     39}  
     40 
     41 
     42template<typename T, typename S> 
     43struct LtSample 
     44{ 
     45    bool operator()(const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) const 
    2146    { 
    22                 return a < b; 
     47                return a.mObject < b.mObject; 
    2348        }  
    2449}; 
     50 
    2551 
    2652/** Information stored with a PVS entry. Consists of the number 
     
    2955class PvsData { 
    3056public: 
     57        PvsData() {} 
     58        PvsData(const float sumPdf): 
     59        mSumPdf(sumPdf) {} 
     60         
     61        // $$JB in order to return meaningfull values 
     62        // it assumes that the sum pdf has been normalized somehow!!! 
     63        inline float GetVisibility()  
     64        {  
     65                return mSumPdf;  
     66        } 
     67 
    3168        /// sum of probability density of visible sample rays 
    3269        float mSumPdf; 
    33  
    34         PvsData() {} 
    35         PvsData(const float sumPdf): 
     70}; 
     71 
     72 
     73class MailablePvsData  
     74{ 
     75public: 
     76        // sum of probability density of visible sample rays 
     77        float mSumPdf; 
     78        int mCounter; 
     79 
     80        MailablePvsData() {} 
     81        MailablePvsData(const float sumPdf): 
    3682        mSumPdf(sumPdf) {} 
    3783 
     
    4288                return mSumPdf;  
    4389        } 
    44 }; 
    45  
    46  
    47 class MailablePvsData  
    48 { 
     90 
    4991        //////////////////////////// 
    5092        //  Mailing stuff 
    51 protected: 
    52         int mMailbox; 
    53  
    54 public: 
     93 
    5594        // last mail id -> warning not thread safe! 
    5695        // both mailId and mailbox should be unique for each thread!!! 
     
    5897        static int sReservedMailboxes; 
    5998 
    60  
    6199        static void NewMail(const int reserve = 1) { 
    62100                sMailId += sReservedMailboxes; 
     
    71109 
    72110        int IncMail() { return ++ mMailbox - sMailId; } 
     111         
    73112        ////////////////////////////////////////// 
    74113 
    75         // sum of probability density of visible sample rays 
    76         float mSumPdf; 
    77         int mCounter; 
    78  
    79         MailablePvsData() {} 
    80         MailablePvsData(const float sumPdf): 
    81         mSumPdf(sumPdf) {} 
    82  
    83         // $$JB in order to return meaningfull values 
    84         // it assumes that the sum pdf has been normalized somehow!!! 
    85         float GetVisibility()  
    86         {  
    87                 return mSumPdf;  
    88         } 
    89 }; 
     114protected: 
     115 
     116        int mMailbox; 
     117 
     118}; 
     119 
     120 
    90121template<typename T, typename S> 
    91         class Iterator 
    92         { 
    93                 //template<typename T, typename S> friend Pvs<T, S>; 
    94         private: 
    95                 std::vector<std::pair<T, S> >::iterator mIt; 
    96                 //vector<pair<T, S> >::iterator mItEnd; 
    97         }; 
     122class PvsIterator 
     123{ 
     124private: 
     125        typename vector<PvsEntry<T, S> >::iterator mItCurrent; 
     126        typename vector<PvsEntry<T, S> >::iterator mItEnd; 
     127}; 
     128 
     129 
    98130/** Template class representing the Potentially Visible Set (PVS)  
    99131        mainly from a view cell, but also e.g., from objects. 
     
    102134class Pvs 
    103135{ 
     136        template<typename T, typename S> 
     137        friend class PvsIterator; 
     138 
    104139public: 
    105 //vector<pair<T, S> >::iterator mItEnd; 
    106          
    107  
    108         template<typename T, typename S> 
    109         class ConstIterator 
    110         { 
    111         //      template<typename T, typename S> friend Pvs<T, S>; 
    112         private: 
    113                 //vector<pair<T, S> >::const_iterator mIt; 
    114                 //vector<pair<T, S> >::const_iteator mItEnd; 
    115         }; 
    116  
    117   Pvs(): mSamples(0), mEntries() {} 
    118    
    119  
     140 
     141        Pvs(): mSamples(0), mEntries() {} 
     142 
     143        Pvs(const vector<PvsEntry<T, S> > &samples); 
    120144        //virtual ~Pvs(); 
    121145 
     
    126150        bool Empty() const {return mEntries.empty();} 
    127151 
    128         /** Normalize the visibility of entries in order to get comparable 
    129                 results  
     152        /** Normalize the visibility of entries in order to get  
     153                comparable results. 
    130154        */ 
    131155        void NormalizeMaximum(); 
    132156 
    133157        /** Merges pvs of a into this pvs. 
    134         */ 
    135         void Merge(const Pvs<T, S> &a); 
     158                Warning: very slow! 
     159        */ 
     160        void MergeInPlace(const Pvs<T, S> &a); 
    136161 
    137162        /** Difference of pvs to pvs b. 
     
    141166 
    142167        /** Finds sample in PVS. 
    143                 @returns sample if found, NULL otherwise. 
    144         */ 
    145         S *Find(T sample); 
     168                @returns iterator on the sample. 
     169        */ 
     170        typename vector<PvsEntry<T, S> >::iterator Find(T sample); 
    146171 
    147172        bool GetSampleContribution(T sample, const float pdf, float &contribution); 
     
    157182        */ 
    158183        float AddSample(T sample, const float pdf); 
     184         
     185        /** Adds sample to PVS. 
     186                @returns contribution of sample (0 or 1) 
     187        */ 
     188        float AddSamples(const vector<PvsEntry<T, S> > &samples); 
    159189 
    160190        /** Adds sample to PVS. 
    161191                @returns PvsData 
    162192        */ 
    163         S *AddSample2(T sample, const float pdf); 
    164  
    165         /** Adds one pvs to another one. 
    166                 @returns new pvs size 
    167         */ 
    168         int AddPvs(const Pvs<T, S> &pvs); 
     193        typename std::vector<PvsEntry<T, S> >::iterator AddSample2(T sample, const float pdf); 
    169194 
    170195        /** Subtracts one pvs from another one. 
     
    173198        */ 
    174199        int SubtractPvs(const Pvs<T, S> &pvs); 
     200 
    175201        /** Returns PVS data, i.e., how often it was seen from the view cell,  
    176202                and the object itsef. 
     
    189215        /** Compute continuous PVS difference  
    190216        */ 
    191         void ComputeContinuousPvsDifference(Pvs<T, S> &pvs, 
    192                 float &pvsReduction, 
    193                 float &pvsEnlargement); 
    194  
     217        void ComputeContinuousPvsDifference(Pvs<T, S> &pvs,  
     218                                                                                float &pvsReduction, 
     219                                                                                float &pvsEnlargement); 
    195220 
    196221        /** Clears the pvs. 
     
    201226        static float GetEntrySize(); 
    202227 
    203         /** Compute continuous PVS difference */ 
    204         float GetPvsHomogenity(Pvs<T, S> &pvs) { 
    205                 float pvsReduction, pvsEnlargement; 
    206  
    207                 ComputeContinuousPvsDifference(pvs, 
    208                         pvsReduction, 
    209                         pvsEnlargement); 
    210  
    211                 return pvsReduction + pvsEnlargement; 
    212         } 
    213  
    214         int Size() { return mEntries.size(); } 
    215  
    216         //vector<pair<T, S> >::const_iterator &GetConstIterator() const { return mEntries.begin(); } 
    217         //vector<pair<T, S> >::iterator &GetIterator() { return mEntries.begin(); } 
     228        /** Compute continuous PVS difference  
     229        */ 
     230        float GetPvsHomogenity(Pvs<T, S> &pvs); 
     231 
     232        static void Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b); 
    218233 
    219234//protected: 
    220235 
    221236        /// vector of PVS entries 
    222         vector<pair<T, S> > mEntries;  
     237        vector<PvsEntry<T, S> > mEntries;  
    223238         
    224239        /// Number of samples used to create the PVS 
     
    227242 
    228243 
     244template <typename T, typename S> 
     245Pvs<T, S>::Pvs(const vector<PvsEntry<T, S> > &samples) 
     246{ 
     247        mEntries.reserve(samples.size()); 
     248        mEntries = samples; 
     249} 
     250 
    229251 
    230252/** 
     
    236258void 
    237259Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b, 
    238                                                                            float &pvsReduction, 
    239                                                                            float &pvsEnlargement) 
     260                                                                                  float &pvsReduction, 
     261                                                                                  float &pvsEnlargement) 
    240262{ 
    241263        pvsReduction = 0.0f; 
    242264        pvsEnlargement = 0.0f; 
     265 
    243266        // Uses sum of log differences, which corresponds to entropy 
    244         std::vector<pair<T, S> >::iterator it; 
     267        std::vector<PvsEntry<T, S> >::iterator it; 
    245268 
    246269        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)  
    247270        { 
    248                 float bSumPdf = (*it).second.mSumPdf; 
     271                float bSumPdf = (*it).mData.mSumPdf; 
    249272                float aSumPdf = 0.0f; 
    250                 S *data = Find((*it).first);             
    251  
    252                 if (data)  
     273 
     274                vector<PvsEntry<T, S> >::iterator oit = Find((*it).mObject);             
     275 
     276                const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     277 
     278                if (entryFound) 
    253279                { 
    254                         aSumPdf = data->mSumPdf; 
     280                        aSumPdf = (*it).mData.mSumPdf; 
     281 
    255282                        // mark this entry as processed to avoid double counting 
    256                         data->mSumPdf = -aSumPdf; 
     283                        (*it).mData.mSumPdf = -aSumPdf; 
    257284                } 
    258285 
    259286#if 0 
    260                 float diff = bSumPdf - aSumPdf; 
     287                const float diff = bSumPdf - aSumPdf; 
    261288 
    262289                if (diff > 0.0f) { 
     
    266293                } 
    267294#else 
    268                 if (!data) 
     295                if (!entryFound) 
    269296                        pvsEnlargement += 1.0f; 
    270297#endif 
    271298        } 
    272299 
    273         for (it = mEntries.begin(); it != mEntries.end(); ++ it) { 
    274                 float aSumPdf = (*it).second.mSumPdf; 
     300        for (it = mEntries.begin(); it != mEntries.end(); ++ it)  
     301        { 
     302                float aSumPdf = (*it).mData.mSumPdf; 
    275303                float bSumPdf = 0.0f; 
    276304                if (aSumPdf < 0.0f) { 
     305                 
    277306                        // this entry was already accounted for! 
    278307                        // just revert it back 
    279                         (*it).second.mSumPdf = -aSumPdf; 
     308                        (*it).mData.mSumPdf = -aSumPdf; 
    280309                } else { 
    281                         S *data = b.Find((*it).first); 
    282                         if (data) { 
    283                                 bSumPdf = data->mSumPdf; 
     310                        vector<PvsEntry<T, S> >::iterator oit = b.Find((*it).mObject); 
     311 
     312                        const bool entryFound = (it != mEntries.end()) && ((*it).mObject == (*oit).mObject); 
     313                         
     314                        if (entryFound) { 
     315                                bSumPdf = (*oit).mData.mSumPdf; 
    284316                        } 
    285317#if 0 
    286                         float diff = bSumPdf - aSumPdf; 
     318                        const float diff = bSumPdf - aSumPdf; 
    287319 
    288320                        if (diff > 0.0f) { 
     
    293325 
    294326#else 
    295                         if (!data)  
     327                        if (!entryFound)  
    296328                                pvsReduction += 1.0f; 
    297329#endif 
     
    306338        int dif = 0; 
    307339 
    308         std::vector<pair<T, S> >::const_iterator it; 
     340        std::vector<PvsEntry<T, S> >::const_iterator it; 
    309341 
    310342        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
    311343        { 
    312                 S data = Find((*it).first);              
    313                 if (!data) ++ dif; 
     344                std::vector<PvsEntry<T, S> >::const_iterator bit = Find((*it).first);            
     345                if (bit == mEntries.end()) ++ dif; 
    314346        } 
    315347 
     
    317349} 
    318350 
    319 template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a) 
    320 { 
    321 #if TODO 
     351 
     352template <typename T, typename S>  
     353void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a) 
     354{ 
     355    const int samples = mSamples + a.mSamples; 
     356 
     357        ObjectPvs interPvs; 
     358         
     359        Merge(interPvs, *this, a); 
     360         
     361        mEntries.reserve(interPvs.GetSize()); 
     362        mEntries = interPvs.mEntries; 
     363 
     364        mSamples = samples; 
     365} 
     366 
     367 
     368template <typename T, typename S> 
     369void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b) 
     370{ 
     371        std::vector<PvsEntry<T, S> >::const_iterator ait = a.mEntries.begin(), ait_end = a.mEntries.end(); 
     372        std::vector<PvsEntry<T, S> >::const_iterator bit = b.mEntries.begin(), bit_end = b.mEntries.end(); 
     373 
     374        while (1) 
     375        { 
     376                for (; (ait != ait_end) && ((*ait).mObject < (*bit).mObject); ++ ait) 
     377                { 
     378                        if ((*ait).mObject != (*bit).mObject) 
     379                                mergedPvs.mEntries.push_back(*ait); 
     380                } 
     381 
     382                for (; (bit != bit_end) && ((ait == ait_end) || ((*bit).mObject <= (*bit).mObject)); ++ bit) 
     383                { 
     384                        if ((*ait).mObject == (*bit).mObject) 
     385                        { 
     386                                PvsData newData((*ait).mData.mSumPdf + (*bit).mData.mSumPdf); 
     387                                PvsEntry<T, S> entry((*ait).mObject, newData); 
     388                                mergedPvs.mEntries.push_back(entry); 
     389                        } 
     390                        else 
     391                        { 
     392                                mergedPvs.mEntries.push_back(*bit); 
     393                        } 
     394                } 
     395        } 
     396} 
     397 
     398 
     399/*template <typename T, typename S> void Pvs<T, S>::QuickMerge(const Pvs<T, S> &a) 
     400{ 
    322401        const int samples = mSamples + a.mSamples; 
    323402 
    324         std::vector<pair<T, S>> >::const_iterator it; 
    325  
    326         for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
    327         { 
    328                 AddSample((*it).first, (*it).second.mSumPdf); 
     403        std::vector<PvsEntry<T, S>> >::const_iterator it; 
     404 
     405        for (it = mEntries.begin(); it != mEntries.end(); ++ it) 
     406        { 
     407                it->first->Mail(); 
     408        } 
     409 
     410    for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it) 
     411        { 
     412                if (!it->first->Mailed()) 
     413                { 
     414                        mEntries.push_back(*it); 
     415                } 
    329416        } 
    330417 
    331418        mSamples = samples; 
    332 #endif 
    333 } 
     419}*/ 
    334420 
    335421 
     
    341427 
    342428template <typename T, typename S>  
    343 S *Pvs<T, S>::Find(T sample) 
    344 { 
    345 #if TODO 
    346   std::vector<pair<T, S>, LtSample<T> >::iterator i = mEntries.find(sample); 
    347  
    348   if (i != mEntries.end())  
    349   { 
    350           return &(*i).second; 
    351   }  
    352   else 
    353   { 
    354           return NULL; 
    355   } 
    356 #else 
    357 return NULL; 
    358 #endif 
    359 } 
    360  
    361 template <typename T, typename S> 
    362 void Pvs<T, S>::GetData(const int index, 
    363                                          T &entry, 
    364                                          S &data) 
    365 { 
    366         std::vector<pair<T, S> >::iterator i = mEntries.begin(); 
     429typename std::vector<PvsEntry<T, S> >::iterator Pvs<T, S>::Find(T sample) 
     430{ 
     431        PvsEntry<T, S> dummy(sample, PvsData()); 
     432        vector<PvsEntry<T, S> >::iterator it = lower_bound(mEntries.begin(), mEntries.end(), dummy); 
     433                                 
     434        return it; 
     435} 
     436 
     437 
     438template <typename T, typename S> 
     439void Pvs<T, S>::GetData(const int index, T &entry, S &data) 
     440{ 
     441        std::vector<PvsEntry<T, S> >::iterator i = mEntries.begin(); 
    367442        for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k); 
    368443 
     
    373448 
    374449template <typename T, typename S> 
    375 float 
    376 Pvs<T, S>::AddSample(T sample, const float pdf) 
    377 { 
    378 #if TODO 
     450float Pvs<T, S>::AddSample(T sample, const float pdf) 
     451{ 
    379452        ++ mSamples; 
    380         S *data = Find(sample); 
    381  
    382         if (data)   
    383         { 
     453        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     454 
     455        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     456        { 
     457                S &data = (*it).mData; 
     458                data.mSumPdf += pdf; 
     459 
     460                return data.mSumPdf; 
     461        } 
     462        else  
     463        { 
     464                PvsEntry<T, S> entry(sample, pdf); 
     465                 
     466                mEntries.insert(it, entry); 
     467                return pdf; 
     468        } 
     469} 
     470 
     471 
     472template <typename T, typename S> 
     473typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample, const float pdf) 
     474{ 
     475        ++ mSamples; 
     476        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     477 
     478        if ((it != mEntries.end()) && ((*it).first == T)) 
     479        { 
     480                S &data = (*it).second; 
    384481                data->mSumPdf += pdf; 
    385                 return data->mSumPdf; 
    386482        } 
    387483        else  
    388484        { 
    389                 mEntries[sample] = S(pdf); 
    390                 return pdf; 
    391         } 
    392 #else 
    393 return 0; 
    394 #endif 
    395 } 
    396  
    397  
    398 template <typename T, typename S> 
    399 S * Pvs<T, S>::AddSample2(T sample, const float pdf) 
    400 { 
    401   mSamples++; 
    402   S *data = Find(sample); 
    403    
    404   if (data)   
    405         { 
    406           data->mSumPdf += pdf; 
    407         } 
    408   else  
    409         { 
    410           mEntries[sample] = S(pdf); 
    411           data = Find(sample); 
    412         } 
    413    
    414   return data; 
    415 } 
     485                PvsEntry<T, S> entry(sample, pdf); 
     486                mEntries.insert(it, entry); 
     487        } 
     488 
     489        return it; 
     490} 
     491 
    416492 
    417493template <typename T, typename S>  
    418494bool Pvs<T, S>::AddSample(T sample, 
    419                                   const float pdf, 
    420                                   float &contribution) 
     495                                                  const float pdf, 
     496                                                  float &contribution) 
    421497{ 
    422498        ++ mSamples; 
    423     S *data = Find(sample); 
    424 #if TODO 
    425         if (data)   
    426         { 
    427                 data->mSumPdf += pdf; 
    428                 contribution = pdf / data->mSumPdf; 
     499 
     500        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     501 
     502        if ((it != mEntries.end()) && ((*it).mObject == sample)) 
     503        { 
     504                S &data = (*it).mData; 
     505 
     506                data.mSumPdf += pdf; 
     507                contribution = pdf / data.mSumPdf; 
     508 
    429509                return false; 
    430510        } 
    431         else { 
    432                 mEntries[sample] = S(pdf); 
     511        else  
     512        { 
     513                PvsEntry<T, S> entry(sample, pdf); 
     514 
     515                mEntries.insert(it, entry); 
     516                contribution = 1.0f; 
     517 
     518                return true; 
     519        } 
     520} 
     521 
     522 
     523template <typename T, typename S> 
     524bool Pvs<T, S>::GetSampleContribution(T sample, 
     525                                                                          const float pdf, 
     526                                                                          float &contribution)  
     527{ 
     528        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     529 
     530        if (it != mEntries.end() && ((*it).mObject == sample))   
     531        { 
     532                S &data = (*it).mData; 
     533                contribution = pdf / (data.mSumPdf + pdf); 
     534                return false; 
     535        } 
     536        else  
     537        { 
    433538                contribution = 1.0f; 
    434539                return true; 
    435540        } 
    436 #else 
     541} 
     542 
     543 
     544template <typename T, typename S> 
     545bool Pvs<T, S>::RemoveSample(T sample, const float pdf) 
     546{ 
     547        -- mSamples; 
     548 
     549        std::vector<PvsEntry<T, S> >::iterator it = Find(sample); 
     550 
     551        if (it == mEntries.end()) 
     552                return false; 
     553 
     554        S &data = (*it).mData; 
     555 
     556        data.mSumPdf -= pdf; 
     557 
     558        if (data.mSumPdf <= 0.0f) 
     559        { 
     560                mEntries.erase(it); 
     561        } 
     562 
    437563        return true; 
    438 #endif 
    439 } 
    440  
    441 template <typename T, typename S> 
    442 bool 
    443 Pvs<T, S>::GetSampleContribution(T sample, 
    444                                                                  const float pdf, 
    445                                                                  float &contribution)  
    446 { 
    447   S *data = Find(sample); 
    448    
    449   if (data)  { 
    450         contribution = pdf / (data->mSumPdf + pdf); 
    451         return false; 
    452   } 
    453   else { 
    454         contribution = 1.0f; 
    455         return true; 
    456   } 
    457 } 
    458  
    459 template <typename T, typename S> 
    460 bool Pvs<T, S>::RemoveSample(T sample, 
    461                                                          const float pdf) 
    462 { 
    463   -- mSamples; 
    464 #if TODO 
    465   std::vector<pair<T, S> >::iterator it = mEntries.find(sample); 
    466    
    467   if (it == mEntries.end()) 
    468         return false; 
    469    
    470   S *data = &(*it).second; 
    471    
    472   data->mSumPdf -= pdf; 
    473  
    474   if (data->mSumPdf <= 0.0f) 
    475   { 
    476           mEntries.erase(it); 
    477   } 
    478 #endif 
    479   return true; 
    480 } 
    481  
    482 template <typename T, typename S> 
    483 int Pvs<T, S>::AddPvs(const Pvs<T, S> &pvs) 
    484 { 
    485   int samples = mSamples + pvs.mSamples; 
    486   std::vector<pair<T, S> >:: 
    487         const_iterator it, it_end = pvs.mEntries.end(); 
    488    
    489   float contri; 
    490   // output PVS of view cell 
    491   for (it = pvs.mEntries.begin(); it != it_end; ++ it) 
    492   {      
    493           AddSample((*it).first, (*it).second.mSumPdf, contri); 
    494   } 
    495  
    496   mSamples = samples; 
    497  
    498   return GetSize(); 
    499 } 
    500   
     564} 
     565 
     566 
    501567template <typename T, typename S> 
    502568int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs) 
    503569{ 
    504570        const int samples = mSamples - pvs.mSamples; 
    505 #if TODO 
    506         std::vector<pair<T, S> >:: 
     571 
     572        std::vector<PvsEntry<T, S> >:: 
    507573                const_iterator it, it_end = pvs.mEntries.end(); 
    508574 
    509575        // output PVS of view cell 
    510576        for (it = pvs.mEntries.begin(); it != it_end; ++ it)  
    511                 RemoveSample((*it).first, (*it).second.mSumPdf); 
     577                RemoveSample((*it).mObject, (*it).mData.mSumPdf); 
    512578 
    513579        mSamples = samples; 
    514 #endif 
     580 
    515581        return GetSize(); 
    516582} 
    517583 
     584 
    518585template <typename T, typename S> 
    519586void Pvs<T, S>::CollectEntries(std::vector<T> &entries) 
    520587{ 
    521         std::vector<pair<T, S> >:: 
     588        std::vector<PvsEntry<T, S> >:: 
    522589                const_iterator it, it_end = mEntries.end(); 
    523590 
     
    527594} 
    528595 
     596 
    529597template <typename T, typename S> 
    530598void Pvs<T, S>::NormalizeMaximum() 
    531599{ 
    532   std::vector<pair<T, S> >:: 
    533         const_iterator it, it_end = mEntries.end(); 
    534  
    535   float maxPdfSum = -1.0f; 
    536  
    537   // output PVS of view cell 
    538   for (it = mEntries.begin(); it != it_end; ++ it) { 
    539         float sum = (*it)->second.sumPdf; 
    540         if (sum > maxSum) 
    541           maxSum = sum; 
    542   } 
    543  
    544   maxSum = 1.0f / maxSum; 
    545  
    546   for (it = mEntries.begin(); it != it_end; ++ it) { 
    547         (*it)->second.sumPdf *= maxSum; 
    548   } 
    549    
     600        std::vector<PvsEntry<T, S> >:: 
     601                const_iterator it, it_end = mEntries.end(); 
     602 
     603        float maxPdfSum = -1.0f; 
     604 
     605        // output PVS of view cell 
     606        for (it = mEntries.begin(); it != it_end; ++ it) { 
     607                float sum = (*it)->second.sumPdf; 
     608                if (sum > maxSum) 
     609                        maxSum = sum; 
     610        } 
     611 
     612        maxSum = 1.0f / maxSum; 
     613 
     614        for (it = mEntries.begin(); it != it_end; ++ it) { 
     615                (*it)->second.sumPdf *= maxSum; 
     616        } 
     617 
    550618} 
    551619 
     
    562630{ 
    563631        return sizeof(T) + sizeof(S); 
     632} 
     633 
     634 
     635template <typename T, typename S> 
     636float Pvs<T, S>::GetPvsHomogenity(Pvs<T, S> &pvs)  
     637{ 
     638        float pvsReduction, pvsEnlargement; 
     639 
     640        ComputeContinuousPvsDifference(pvs,     pvsReduction, pvsEnlargement); 
     641 
     642        return pvsReduction + pvsEnlargement; 
    564643} 
    565644 
     
    590669//-- typedefs 
    591670 
    592 //typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap; 
    593 //typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsEntries; 
    594 //typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsEntries; 
    595  
    596  
    597 typedef std::vector<pair<Intersectable *, PvsData> > ObjectPvsEntries; 
    598  
     671typedef std::vector<PvsEntry<Intersectable *, PvsData> > ObjectPvsEntries; 
    599672typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs; 
    600673 
Note: See TracChangeset for help on using the changeset viewer.