source: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h @ 2015

Revision 2015, 20.5 KB checked in by bittner, 17 years ago (diff)

pvs efficiency tuning

Line 
1#ifndef __PVS_H
2#define __PVS_H
3
4#include <map>
5#include <vector>
6#include "common.h"
7
8namespace GtpVisibilityPreprocessor {
9
10class KdNode;
11class BspNode;
12class Ray;
13class Intersectable;
14class ViewCell;
15
16
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>
21struct PvsEntry
22{
23public:
24
25        PvsEntry() {}
26
27        PvsEntry(T sample, const S &data): mObject(sample), mData(data) {}
28
29        T mObject;
30        S mData;
31
32        template<typename T, typename S>
33        friend int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b);
34        template<typename T, typename S>
35        friend int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b);
36};
37
38
39template<typename T, typename S>
40int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
41{
42        return a.mObject < b.mObject;
43}
44
45template<typename T, typename S>
46int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
47{
48        return a.mObject == b.mObject;
49}
50
51
52template<typename T, typename S>
53struct LtSample
54{
55    bool operator()(const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) const
56    {
57                return a.mObject < b.mObject;
58        }
59};
60
61template<typename T, typename S>
62int equalSample (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
63{
64        return a.mObject == b.mObject;
65}
66
67/** Information stored with a PVS entry. Consists of the number
68        the object was seen from the view cell.
69*/
70struct PvsData {
71public:
72        PvsData() {}
73        PvsData(const float sumPdf):
74        mSumPdf(sumPdf) {}
75       
76        // $$JB in order to return meaningfull values
77        // it assumes that the sum pdf has been normalized somehow!!!
78        inline float GetVisibility()
79        {
80                return mSumPdf;
81        }
82
83        /// sum of probability density of visible sample rays
84        float mSumPdf;
85};
86
87
88class MailablePvsData
89{
90public:
91        // sum of probability density of visible sample rays
92        float mSumPdf;
93        int mCounter;
94
95        MailablePvsData() {}
96        MailablePvsData(const float sumPdf):
97        mSumPdf(sumPdf) {}
98
99        // $$JB in order to return meaningfull values
100        // it assumes that the sum pdf has been normalized somehow!!!
101        float GetVisibility()
102        {
103                return mSumPdf;
104        }
105
106        ////////////////////////////
107        //  Mailing stuff
108
109        // last mail id -> warning not thread safe!
110        // both mailId and mailbox should be unique for each thread!!!
111        static int sMailId;
112        static int sReservedMailboxes;
113
114        static void NewMail(const int reserve = 1) {
115                sMailId += sReservedMailboxes;
116                sReservedMailboxes = reserve;
117        }
118
119        void Mail() { mMailbox = sMailId; }
120        bool Mailed() const { return mMailbox == sMailId; }
121
122        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
123        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
124
125        int IncMail() { return ++ mMailbox - sMailId; }
126       
127        //////////////////////////////////////////
128
129protected:
130
131        int mMailbox;
132
133};
134
135
136template<typename T, typename S>
137class PvsIterator
138{
139public:
140PvsIterator<T, S>(){}
141        PvsIterator<T, S>(const typename vector<PvsEntry<T, S> >::const_iterator &itCurrent,
142                                          const typename vector<PvsEntry<T, S> >::const_iterator &itEnd):
143        mItCurrent(itCurrent), mItEnd(itEnd)
144        {
145        }
146
147        bool HasMoreEntries() const
148        {
149                return (mItCurrent != mItEnd);
150        }
151
152        const PvsEntry<T, S> &Next()
153        {
154                return *(mItCurrent ++);
155        }
156       
157private:
158        typename vector<PvsEntry<T, S> >::const_iterator mItCurrent;
159        typename vector<PvsEntry<T, S> >::const_iterator mItEnd;
160};
161
162
163/** Template class representing the Potentially Visible Set (PVS)
164        mainly from a view cell, but also e.g., from objects.
165*/
166template<typename T, typename S>
167class Pvs
168{
169        template<typename T, typename S>
170        friend class PvsIterator;
171
172public:
173
174        Pvs(): mSamples(0), mEntries(), mLastSorted(0) {}
175
176        /** creates pvs and initializes it with the given entries.
177                Assumes that entries are sorted-
178        */
179        Pvs(const vector<PvsEntry<T, S> > &samples);
180        virtual ~Pvs() {};
181
182        /** Compresses PVS lossless or lossy.
183        */
184        int Compress() {return 0;}
185        int GetSize() const {return (int)mEntries.size();}
186        bool Empty() const {return mEntries.empty();}
187
188        void Reserve(const int n) { mEntries.reserve(n); }
189
190        /** Normalize the visibility of entries in order to get
191                comparable results.
192        */
193        void NormalizeMaximum();
194
195        /** Merges pvs of a into this pvs.
196                Warning: very slow!
197        */
198        void MergeInPlace(const Pvs<T, S> &a);
199
200        /** Difference of pvs to pvs b.
201                @returns number of different entries.
202        */
203        int Diff(const Pvs<T, S> &b);
204
205        /** Finds sample in PVS.
206                @param checkDirty if dirty part of the pvs should be checked for entry
207                        (warning: linear runtime in dirty part)
208                @returns iterator on the sample.
209        */
210        bool Find(T sample,
211                          typename vector<PvsEntry<T, S> >::iterator &it,
212                          const bool checkDirty = true);
213
214        bool GetSampleContribution(T sample, const float pdf, float &contribution);
215
216        /** Adds sample to PVS.
217                @returns contribution of sample (0 or 1)
218        */
219        float AddSample(T sample, const float pdf);
220
221        /** Adds sample to PVS without checking for presence of the sample
222                pvs remains unsorted!
223        */
224        void AddSampleDirty(T sample, const float pdf);
225
226        /** Adds sample dirty (on the end of the vector) but
227                first checks if sample is already in clean part of the pvs.
228        */
229        bool AddSampleDirtyCheck(T sample, const float pdf);//, float &contribution);
230
231        /** Sort pvs entries - this should always be called after a
232                sequence of AddSampleDirty calls
233        */
234        void Sort();
235
236  /** Sort pvs entries assume that the pvs contains unique entries
237   */
238  void SimpleSort();
239
240        /** Adds sample to PVS. Assumes that the pvs is sorted
241                @returns contribution of sample (0 or 1)
242        */
243        //float AddSamples(const vector<PvsEntry<T, S> > &samples);
244
245        /** Adds sample to PVS.
246                @returns PvsData
247        */
248        typename std::vector<PvsEntry<T, S> >::iterator AddSample2(T sample, const float pdf);
249
250        /** Subtracts one pvs from another one.
251                WARNING: could contains bugs
252                @returns new pvs size
253        */
254        int SubtractPvs(const Pvs<T, S> &pvs);
255
256        /** Returns PVS data, i.e., how often it was seen from the view cell,
257                and the object itsef.
258        */
259        void GetData(const int index, T &entry, S &data);
260
261        /** Collects the PVS entries and returns them in the vector.
262        */
263        void CollectEntries(std::vector<T> &entries);
264
265        /** Removes sample from PVS if reference count is zero.
266                @param visibleSamples number of references to be removed
267        */
268        bool RemoveSample(T sample, const float pdf);
269
270        /** Compute continuous PVS difference
271        */
272        void ComputeContinuousPvsDifference(Pvs<T, S> &pvs,
273                                                                                float &pvsReduction,
274                                                                                float &pvsEnlargement);
275
276        /** Clears the pvs.
277        */
278        void Clear(const bool trim = true);
279
280        void Trim();
281
282        static int GetEntrySizeByte();
283        static float GetEntrySize();
284
285        /** Compute continuous PVS difference
286        */
287        float GetPvsHomogenity(Pvs<T, S> &pvs);
288
289        static void Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b);
290
291        static void Merge(Pvs<T, S> &mergedPvs,
292                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin,
293                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd,
294                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin,
295                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd,
296                                          const int aSamples,
297                                          const int bSamples);
298
299        int GetSamples() const
300        {
301                return mSamples;
302        }
303
304
305        bool IsDirty() const
306        {
307                return mLastSorted < mEntries.size();
308        }
309
310        bool RequiresResort() const
311        {
312          // the last part should not be more than log of the sorted part. this
313          // way we can achieve logarithmic behaviour for insertion and find
314          const int dirtySize = (int)mEntries.size() - mLastSorted;
315          return dirtySize > 500;
316          //              4*(int)(log((double)mEntries.size()) / log(2.0));
317        }
318
319  bool RequiresResortLog() const
320  {
321        // the last part should not be more than log of the sorted part. this
322        // way we can achieve logarithmic behaviour for insertion and find
323        const int dirtySize = (int)mEntries.size() - mLastSorted;
324        return dirtySize > 4*(int)(log((double)mEntries.size()) / log(2.0));
325  }
326 
327 
328        int GetLastSorted() const
329        {
330                return mLastSorted;
331        }
332
333        typename PvsIterator<T, S> GetIterator() const;
334
335protected:
336
337        /// vector of PVS entries
338        vector<PvsEntry<T, S> > mEntries;
339       
340        /// Number of samples used to create the PVS
341        int mSamples;
342 
343        /// Last sorted entry in the pvs (important for find and merge)
344        int mLastSorted; 
345};
346
347
348template <typename T, typename S>
349Pvs<T, S>::Pvs(const vector<PvsEntry<T, S> > &samples)
350{
351        mEntries.reserve(samples.size());
352        mEntries = samples;
353        mLastSorted = 0;
354        mSamples = samples.size();
355}
356
357
358template <typename T, typename S>
359void Pvs<T, S>::Sort()
360{
361        std::vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted;
362        //std::vector<PvsEntry<T, S> >::const_iterator it = mEntries.begin() + mLastSorted;
363        std::vector<PvsEntry<T, S> >::iterator it_end = mEntries.end();
364
365        // throw out double entries
366        std::vector<PvsEntry<T, S> >::iterator newEnd = unique(it, it_end);
367        sort(it, newEnd);
368        //sort(mEntries.begin(), mEntries.end());
369
370        // now merge sorted ranges
371        ObjectPvs newPvs;
372        Merge(newPvs,
373                  mEntries.begin(), it,
374                  it, newEnd,
375                  mSamples, 0);
376       
377        mEntries = newPvs.mEntries;
378        mLastSorted = (int)mEntries.size();
379}
380
381template <typename T, typename S>
382void Pvs<T, S>::SimpleSort()
383{
384  sort(mEntries.begin(), mEntries.end());
385  mLastSorted = (int)mEntries.size();
386}
387
388
389/**
390   Compute continuous PVS difference of 'b' with respect to the base PVS (*this).
391   Provides separatelly PVS reduction from PVS enlargement.
392
393*/
394template <typename T, typename S>
395void
396Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b,
397                                                                                  float &pvsReduction,
398                                                                                  float &pvsEnlargement)
399{
400        pvsReduction = 0.0f;
401        pvsEnlargement = 0.0f;
402
403        // Uses sum of log differences, which corresponds to entropy
404        std::vector<PvsEntry<T, S> >::iterator it;
405
406        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
407        {
408                float bSumPdf = (*it).mData.mSumPdf;
409                float aSumPdf = 0.0f;
410
411                vector<PvsEntry<T, S> >::iterator oit;
412                const bool entryFound = Find((*it).mObject, oit);               
413
414                if (entryFound)
415                {
416                        aSumPdf = (*it).mData.mSumPdf;
417
418                        // mark this entry as processed to avoid double counting
419                        (*it).mData.mSumPdf = -aSumPdf;
420                }
421
422#if 0
423                const float diff = bSumPdf - aSumPdf;
424
425                if (diff > 0.0f) {
426                        pvsEnlargement += diff;
427                } else {
428                        pvsReduction += -diff;
429                }
430#else
431                if (!entryFound)
432                        pvsEnlargement += 1.0f;
433#endif
434        }
435
436        for (it = mEntries.begin(); it != mEntries.end(); ++ it)
437        {
438                float aSumPdf = (*it).mData.mSumPdf;
439                float bSumPdf = 0.0f;
440                if (aSumPdf < 0.0f) {
441               
442                        // this entry was already accounted for!
443                        // just revert it back
444                        (*it).mData.mSumPdf = -aSumPdf;
445                } else {
446                        vector<PvsEntry<T, S> >::iterator oit;
447               
448                        const bool entryFound = b.Find((*it).mObject, oit);
449                                               
450                        if (entryFound) {
451                                bSumPdf = (*oit).mData.mSumPdf;
452                        }
453#if 0
454                        const float diff = bSumPdf - aSumPdf;
455
456                        if (diff > 0.0f) {
457                                pvsEnlargement += diff;
458                        } else {
459                                pvsReduction += -diff;
460                        }
461
462#else
463                        if (!entryFound)
464                                pvsReduction += 1.0f;
465#endif
466                }
467        }
468}
469
470
471template <typename T, typename S>
472int Pvs<T, S>::Diff(const Pvs<T, S> &b)
473{
474        int dif = 0;
475
476        std::vector<PvsEntry<T, S> >::const_iterator it;
477
478        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
479        {
480                vector<PvsEntry<T, S> >::iterator bit;
481                const bool entryFound = Find((*it).first, bit);
482
483                if (!entryFound) ++ dif;
484        }
485
486        return dif;
487}
488
489
490template <typename T, typename S>
491void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a)
492{
493        // early exit
494        if (a.Empty())
495        {
496                return;
497        }
498        else if (Empty())
499        {
500                mEntries.reserve(a.GetSize());
501                mEntries = a.mEntries;
502                mSamples = a.mSamples;
503                return;
504        }
505
506        ObjectPvs interPvs;
507       
508        Merge(interPvs, *this, a);
509       
510        mEntries.reserve(interPvs.GetSize());
511        mEntries = interPvs.mEntries;
512        mSamples = interPvs.mSamples;
513}
514
515
516template <typename T, typename S>
517void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b)
518{
519        std::vector<PvsEntry<T, S> >::const_iterator ait = a.mEntries.begin(), ait_end = a.mEntries.end();
520        std::vector<PvsEntry<T, S> >::const_iterator bit = b.mEntries.begin(), bit_end = b.mEntries.end();
521       
522        Merge(mergedPvs,
523                  ait, ait_end,
524                  bit, bit_end,
525                  a.mSamples,
526                  b.mSamples);
527}
528
529
530template <typename T, typename S>
531void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs,
532                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin,
533                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd,
534                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin,
535                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd,
536                                          const int aSamples,
537                                          const int bSamples)
538{
539        std::vector<PvsEntry<T, S> >::const_iterator ait = aBegin;
540        std::vector<PvsEntry<T, S> >::const_iterator bit = bBegin;
541       
542        for (; (ait != aEnd); ++ ait)
543        {
544                Intersectable *aObj = (*ait).mObject;
545                Intersectable *bObj = NULL;
546                //Intersectable *bObjOld = NULL;
547       
548                const PvsEntry<T, S> &aEntry = (*ait);
549
550                for (; (bit != bEnd) && ((*bit).mObject <= (*ait).mObject); ++ bit)
551                {
552                        bObj = (*bit).mObject;
553
554                        // object found => add up probabilities
555                        if (bObj == aEntry.mObject)
556                        {
557                                PvsData newData(aEntry.mData.mSumPdf + (*bit).mData.mSumPdf);
558                                PvsEntry<T, S> entry(bObj, newData);
559                                mergedPvs.mEntries.push_back(entry);
560                        }
561                        else
562                        {
563                                mergedPvs.mEntries.push_back(*bit);
564                        }
565                       
566                        //bObjOld = bObj;
567                }
568
569                // only push back if objects different
570                // (equal case is handled by second loop)
571                if (aObj != bObj)
572                {
573                        mergedPvs.mEntries.push_back(*ait);
574                }
575        }
576
577        // add the rest
578        for (; (bit != bEnd); ++ bit)
579        {
580                mergedPvs.mEntries.push_back(*bit);
581        }
582
583        mergedPvs.mSamples = aSamples + bSamples;
584}
585
586
587template <typename T, typename S> void Pvs<T, S>::Clear(const bool trim = true)
588{
589        mEntries.clear();
590        mSamples = 0;
591        mLastSorted = 0;
592
593        if (trim)
594        {
595                vector<PvsEntry<T,S> >().swap(mEntries);
596        }
597}
598
599
600template <typename T, typename S> void Pvs<T, S>::Trim()
601{
602        vector<PvsEntry<T,S> >(mEntries).swap(mEntries);
603}
604
605
606template <typename T, typename S>
607bool Pvs<T, S>::Find(T sample,
608                                         typename vector<PvsEntry<T, S> >::iterator &it,
609                                         const bool checkDirty)
610{
611  PvsEntry<T, S> dummy(sample, PvsData());
612 
613  // only check clean part
614  vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted;
615 
616  // binary search
617  it = lower_bound(mEntries.begin(), sorted_end, dummy);
618 
619  if ((it != mEntries.end()) && ((*it).mObject == sample))
620        //  if (it != sorted_end)
621        return true;
622 
623  // sample not found yet => search further in the unsorted part
624  if (checkDirty) {
625       
626        for (it = sorted_end; (it != mEntries.end()) && ((*it).mObject != sample); ++ it) ;
627       
628        if (it != mEntries.end())
629          return true;
630  }
631 
632  return false;
633}
634
635
636template <typename T, typename S>
637void Pvs<T, S>::GetData(const int index, T &entry, S &data)
638{
639        std::vector<PvsEntry<T, S> >::iterator i = mEntries.begin();
640        for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k);
641
642        entry = (*i).first;
643        data = (*i).second;
644}
645
646
647template <typename T, typename S>
648float Pvs<T, S>::AddSample(T sample, const float pdf)
649{
650        ++ mSamples;
651       
652        vector<PvsEntry<T, S> >::iterator it;
653        const bool entryFound = Find(sample, it);               
654
655        if (entryFound)
656        {       
657                S &data = (*it).mData;
658                data.mSumPdf += pdf;
659                return data.mSumPdf;
660        }
661        else
662          {
663                PvsEntry<T, S> entry(sample, pdf);
664                mEntries.insert(it, entry);
665                ++ mLastSorted;
666                return pdf;
667          }
668}
669
670
671template <typename T, typename S>
672void Pvs<T, S>::AddSampleDirty(T sample, const float pdf)
673{
674        ++ mSamples;
675        mEntries.push_back(PvsEntry<T, S>(sample, pdf));
676}
677                                         
678
679template <typename T, typename S>
680typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample,
681                                                                                                                                  const float pdf)
682{
683        ++ mSamples;
684       
685        vector<PvsEntry<T, S> >::iterator it;
686        const bool entryFound == Find(sample, it);
687
688        if (entryFound)
689        {
690                S &data = (*it).second;
691                data->mSumPdf += pdf;
692        }
693        else
694        {
695                PvsEntry<T, S> entry(sample, pdf);
696                mEntries.insert(it, entry);
697                ++ mLastSorted;
698        }
699
700        return it;
701}
702
703
704/** Adds sample dirty (on the end of the vector) but
705        first checks if sample is already in clean part of the pvs.
706*/
707template <typename T, typename S>
708bool Pvs<T, S>::AddSampleDirtyCheck(T sample,
709                                                                        const float pdf)
710                                                                        //,float &contribution)
711{
712        ++ mSamples;
713
714        vector<PvsEntry<T, S> >::iterator it;
715        bool entryFound = Find(sample, it);
716
717        if (entryFound) {
718          S &data = (*it).mData;
719         
720          data.mSumPdf += pdf;
721          //contribution = pdf / data.mSumPdf;
722         
723          return false;
724        }
725        else {
726          AddSampleDirty(sample, pdf);
727          //contribution = 1.0f;
728          return true;
729        }
730}
731
732
733template <typename T, typename S>
734bool Pvs<T, S>::GetSampleContribution(T sample,
735                                                                          const float pdf,
736                                                                          float &contribution)
737{
738        vector<PvsEntry<T, S> >::iterator it;
739        const bool entryFound = Find(sample, it);
740
741        if (entryFound) 
742        {
743                S &data = (*it).mData;
744                contribution = pdf / (data.mSumPdf + pdf);
745                return false;
746        }
747        else
748        {
749                contribution = 1.0f;
750                return true;
751        }
752}
753
754
755template <typename T, typename S>
756bool Pvs<T, S>::RemoveSample(T sample, const float pdf)
757{
758        -- mSamples;
759       
760        vector<PvsEntry<T, S> >::iterator it;
761        const bool entryFound = Find(sample, it);
762
763        if (!entryFound)
764                return false;
765
766        S &data = (*it).mData;
767
768        data.mSumPdf -= pdf;
769
770        if (data.mSumPdf <= 0.0f)
771        {
772                mEntries.erase(it);
773                -- mLastSorted; // wrong if sample was in tail!!
774        }
775
776        return true;
777}
778
779
780template <typename T, typename S>
781int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs)
782{
783        const int samples = mSamples - pvs.mSamples;
784
785        std::vector<PvsEntry<T, S> >::
786                const_iterator it, it_end = pvs.mEntries.end();
787
788        // output PVS of view cell
789        for (it = pvs.mEntries.begin(); it != it_end; ++ it)
790                RemoveSample((*it).mObject, (*it).mData.mSumPdf);
791
792        mSamples = samples;
793
794        return GetSize();
795}
796
797
798template <typename T, typename S>
799void Pvs<T, S>::CollectEntries(std::vector<T> &entries)
800{
801        std::vector<PvsEntry<T, S> >::
802                const_iterator it, it_end = mEntries.end();
803
804        // output PVS of view cell
805        for (it = mEntries.begin(); it != it_end; ++ it)
806                entries.push_back((*it)->first);
807}
808
809
810template <typename T, typename S>
811void Pvs<T, S>::NormalizeMaximum()
812{
813        std::vector<PvsEntry<T, S> >::
814                const_iterator it, it_end = mEntries.end();
815
816        float maxPdfSum = -1.0f;
817
818        // output PVS of view cell
819        for (it = mEntries.begin(); it != it_end; ++ it) {
820                float sum = (*it)->second.sumPdf;
821                if (sum > maxSum)
822                        maxSum = sum;
823        }
824
825        maxSum = 1.0f / maxSum;
826
827        for (it = mEntries.begin(); it != it_end; ++ it) {
828                (*it)->second.sumPdf *= maxSum;
829        }
830
831}
832
833
834template <typename T, typename S>
835float Pvs<T, S>::GetEntrySize()
836{
837        return (float)(sizeof(T) + sizeof(S)) / float(1024 * 1024);
838}
839
840
841template <typename T, typename S>
842int Pvs<T, S>::GetEntrySizeByte()
843{
844        return sizeof(T) + sizeof(S);
845}
846
847
848template <typename T, typename S>
849float Pvs<T, S>::GetPvsHomogenity(Pvs<T, S> &pvs)
850{
851        float pvsReduction, pvsEnlargement;
852
853        ComputeContinuousPvsDifference(pvs,     pvsReduction, pvsEnlargement);
854
855        return pvsReduction + pvsEnlargement;
856}
857
858
859template <typename T, typename S>
860typename PvsIterator<T, S> Pvs<T, S>::GetIterator() const
861{
862        PvsIterator<T, S> pit(mEntries.begin(), mEntries.end());
863
864        return pit;
865}
866
867
868///////////////////////////////////////
869
870/** Class instantiating the Pvs template for kd tree nodes.
871*/
872class KdPvs: public Pvs<KdNode *, PvsData>
873{
874public:
875        int Compress();
876};
877
878
879////////////
880//-- typedefs
881
882typedef PvsEntry<Intersectable *, PvsData> ObjectPvsEntry;
883typedef std::vector<ObjectPvsEntry> ObjectPvsEntries;
884typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs;
885typedef PvsIterator<Intersectable *, PvsData> ObjectPvsIterator;
886
887
888class ObjectPvs: public Pvs<Intersectable *, PvsData>
889{
890public:
891        /** Counts object int the pvs. Different to method "GetSize", not
892                only the raw container size is returned,
893                but the individual contributions of the entries are summed up.
894        */
895        float EvalPvsCost() const;
896
897        friend ostream &operator<<(ostream &s, const ObjectPvs &p)
898        {
899                ObjectPvsIterator pit = p.GetIterator();
900
901                while (pit.HasMoreEntries())
902                {               
903                        const ObjectPvsEntry &entry = pit.Next();
904                        Intersectable *obj = entry.mObject;
905
906                        cout << obj << " ";
907                }
908               
909                return s;
910        }
911};
912
913
914
915}
916
917#endif
918
Note: See TracBrowser for help on using the repository browser.