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

Revision 1844, 20.0 KB checked in by mattausch, 18 years ago (diff)

implemented object space compression

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>
21class 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*/
70class 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        /** Normalize the visibility of entries in order to get
189                comparable results.
190        */
191        void NormalizeMaximum();
192
193        /** Merges pvs of a into this pvs.
194                Warning: very slow!
195        */
196        void MergeInPlace(const Pvs<T, S> &a);
197
198        /** Difference of pvs to pvs b.
199                @returns number of different entries.
200        */
201        int Diff(const Pvs<T, S> &b);
202
203        /** Finds sample in PVS.
204                @param checkDirty if dirty part of the pvs should be checked for entry
205                        (warning: linear runtime in dirty part)
206                @returns iterator on the sample.
207        */
208        bool Find(T sample,
209                          typename vector<PvsEntry<T, S> >::iterator &it,
210                          const bool checkDirty = true);
211
212        bool GetSampleContribution(T sample, const float pdf, float &contribution);
213
214        /** Adds sample to PVS.
215                @returns contribution of sample (0 or 1)
216        */
217        float AddSample(T sample, const float pdf);
218
219        /** Adds sample to PVS without checking for presence of the sample
220                pvs remains unsorted!
221        */
222        void AddSampleDirty(T sample, const float pdf);
223
224        /** Adds sample dirty (on the end of the vector) but
225                first checks if sample is already in clean part of the pvs.
226        */
227        bool AddSampleDirtyCheck(T sample, const float pdf);//, float &contribution);
228
229        /** Sort pvs entries - this should always be called after a
230                sequence of AddSampleDirty calls
231        */
232        void Sort();
233
234        /** Adds sample to PVS. Assumes that the pvs is sorted
235                @returns contribution of sample (0 or 1)
236        */
237        //float AddSamples(const vector<PvsEntry<T, S> > &samples);
238
239        /** Adds sample to PVS.
240                @returns PvsData
241        */
242        typename std::vector<PvsEntry<T, S> >::iterator AddSample2(T sample, const float pdf);
243
244        /** Subtracts one pvs from another one.
245                WARNING: could contains bugs
246                @returns new pvs size
247        */
248        int SubtractPvs(const Pvs<T, S> &pvs);
249
250        /** Returns PVS data, i.e., how often it was seen from the view cell,
251                and the object itsef.
252        */
253        void GetData(const int index, T &entry, S &data);
254
255        /** Collects the PVS entries and returns them in the vector.
256        */
257        void CollectEntries(std::vector<T> &entries);
258
259        /** Removes sample from PVS if reference count is zero.
260                @param visibleSamples number of references to be removed
261        */
262        bool RemoveSample(T sample, const float pdf);
263
264        /** Compute continuous PVS difference
265        */
266        void ComputeContinuousPvsDifference(Pvs<T, S> &pvs,
267                                                                                float &pvsReduction,
268                                                                                float &pvsEnlargement);
269
270        /** Clears the pvs.
271        */
272        void Clear(const bool trim = true);
273
274        void Trim();
275
276        static int GetEntrySizeByte();
277        static float GetEntrySize();
278
279        /** Compute continuous PVS difference
280        */
281        float GetPvsHomogenity(Pvs<T, S> &pvs);
282
283        static void Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b);
284
285        static void Merge(Pvs<T, S> &mergedPvs,
286                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin,
287                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd,
288                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin,
289                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd,
290                                          const int aSamples,
291                                          const int bSamples);
292
293        int GetSamples() const
294        {
295                return mSamples;
296        }
297
298
299        bool IsDirty() const
300        {
301                return mLastSorted < mEntries.size();
302        }
303
304        bool RequiresResort() const
305        {
306                // the last part should not be more than log of the sorted part. this
307                // way we can achieve logarithmic behaviour for insertion and find
308                const int dirtySize = (int)mEntries.size() - mLastSorted;
309                return dirtySize > (int)(log((double)mEntries.size()) / log(2.0));
310        }
311
312
313        int GetLastSorted() const
314        {
315                return mLastSorted;
316        }
317
318        typename PvsIterator<T, S> GetIterator() const;
319
320protected:
321
322        /// vector of PVS entries
323        vector<PvsEntry<T, S> > mEntries;
324       
325        /// Number of samples used to create the PVS
326        int mSamples;
327 
328        /// Last sorted entry in the pvs (important for find and merge)
329        int mLastSorted; 
330};
331
332
333template <typename T, typename S>
334Pvs<T, S>::Pvs(const vector<PvsEntry<T, S> > &samples)
335{
336        mEntries.reserve(samples.size());
337        mEntries = samples;
338        mLastSorted = 0;
339        mSamples = samples.size();
340}
341
342
343template <typename T, typename S>
344void Pvs<T, S>::Sort()
345{
346        std::vector<PvsEntry<T, S> >::iterator it = mEntries.begin() + mLastSorted;
347        //std::vector<PvsEntry<T, S> >::const_iterator it = mEntries.begin() + mLastSorted;
348        std::vector<PvsEntry<T, S> >::iterator it_end = mEntries.end();
349
350        // throw out double entries
351        std::vector<PvsEntry<T, S> >::iterator newEnd = unique(it, it_end);
352        sort(it, newEnd);
353        //sort(mEntries.begin(), mEntries.end());
354
355        // now merge sorted ranges
356        ObjectPvs newPvs;
357        Merge(newPvs,
358                  mEntries.begin(), it,
359                  it, newEnd,
360                  mSamples, 0);
361       
362        mEntries = newPvs.mEntries;
363        mLastSorted = (int)mEntries.size();
364}
365
366
367/**
368   Compute continuous PVS difference of 'b' with respect to the base PVS (*this).
369   Provides separatelly PVS reduction from PVS enlargement.
370
371*/
372template <typename T, typename S>
373void
374Pvs<T, S>::ComputeContinuousPvsDifference(Pvs<T, S> &b,
375                                                                                  float &pvsReduction,
376                                                                                  float &pvsEnlargement)
377{
378        pvsReduction = 0.0f;
379        pvsEnlargement = 0.0f;
380
381        // Uses sum of log differences, which corresponds to entropy
382        std::vector<PvsEntry<T, S> >::iterator it;
383
384        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
385        {
386                float bSumPdf = (*it).mData.mSumPdf;
387                float aSumPdf = 0.0f;
388
389                vector<PvsEntry<T, S> >::iterator oit;
390                const bool entryFound = Find((*it).mObject, oit);               
391
392                if (entryFound)
393                {
394                        aSumPdf = (*it).mData.mSumPdf;
395
396                        // mark this entry as processed to avoid double counting
397                        (*it).mData.mSumPdf = -aSumPdf;
398                }
399
400#if 0
401                const float diff = bSumPdf - aSumPdf;
402
403                if (diff > 0.0f) {
404                        pvsEnlargement += diff;
405                } else {
406                        pvsReduction += -diff;
407                }
408#else
409                if (!entryFound)
410                        pvsEnlargement += 1.0f;
411#endif
412        }
413
414        for (it = mEntries.begin(); it != mEntries.end(); ++ it)
415        {
416                float aSumPdf = (*it).mData.mSumPdf;
417                float bSumPdf = 0.0f;
418                if (aSumPdf < 0.0f) {
419               
420                        // this entry was already accounted for!
421                        // just revert it back
422                        (*it).mData.mSumPdf = -aSumPdf;
423                } else {
424                        vector<PvsEntry<T, S> >::iterator oit;
425               
426                        const bool entryFound = b.Find((*it).mObject, oit);
427                                               
428                        if (entryFound) {
429                                bSumPdf = (*oit).mData.mSumPdf;
430                        }
431#if 0
432                        const float diff = bSumPdf - aSumPdf;
433
434                        if (diff > 0.0f) {
435                                pvsEnlargement += diff;
436                        } else {
437                                pvsReduction += -diff;
438                        }
439
440#else
441                        if (!entryFound)
442                                pvsReduction += 1.0f;
443#endif
444                }
445        }
446}
447
448
449template <typename T, typename S>
450int Pvs<T, S>::Diff(const Pvs<T, S> &b)
451{
452        int dif = 0;
453
454        std::vector<PvsEntry<T, S> >::const_iterator it;
455
456        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
457        {
458                vector<PvsEntry<T, S> >::iterator bit;
459                const bool entryFound = Find((*it).first, bit);
460
461                if (!entryFound) ++ dif;
462        }
463
464        return dif;
465}
466
467
468template <typename T, typename S>
469void Pvs<T, S>::MergeInPlace(const Pvs<T, S> &a)
470{
471        // early exit
472        if (a.Empty())
473        {
474                return;
475        }
476        else if (Empty())
477        {
478                mEntries.reserve(a.GetSize());
479                mEntries = a.mEntries;
480                mSamples = a.mSamples;
481                return;
482        }
483
484        ObjectPvs interPvs;
485       
486        Merge(interPvs, *this, a);
487       
488        mEntries.reserve(interPvs.GetSize());
489        mEntries = interPvs.mEntries;
490        mSamples = interPvs.mSamples;
491}
492
493
494template <typename T, typename S>
495void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs, const Pvs<T, S> &a, const Pvs<T, S> &b)
496{
497        std::vector<PvsEntry<T, S> >::const_iterator ait = a.mEntries.begin(), ait_end = a.mEntries.end();
498        std::vector<PvsEntry<T, S> >::const_iterator bit = b.mEntries.begin(), bit_end = b.mEntries.end();
499       
500        Merge(mergedPvs,
501                  ait, ait_end,
502                  bit, bit_end,
503                  a.mSamples,
504                  b.mSamples);
505}
506
507
508template <typename T, typename S>
509void Pvs<T, S>::Merge(Pvs<T, S> &mergedPvs,
510                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aBegin,
511                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &aEnd,
512                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bBegin,
513                                          const typename std::vector<PvsEntry<T, S> >::const_iterator &bEnd,
514                                          const int aSamples,
515                                          const int bSamples)
516{
517        std::vector<PvsEntry<T, S> >::const_iterator ait = aBegin;
518        std::vector<PvsEntry<T, S> >::const_iterator bit = bBegin;
519       
520        for (; (ait != aEnd); ++ ait)
521        {
522                Intersectable *aObj = (*ait).mObject;
523                Intersectable *bObj = NULL;
524                //Intersectable *bObjOld = NULL;
525       
526                const PvsEntry<T, S> &aEntry = (*ait);
527
528                for (; (bit != bEnd) && ((*bit).mObject <= (*ait).mObject); ++ bit)
529                {
530                        bObj = (*bit).mObject;
531
532                        // object found => add up probabilities
533                        if (bObj == aEntry.mObject)
534                        {
535                                PvsData newData(aEntry.mData.mSumPdf + (*bit).mData.mSumPdf);
536                                PvsEntry<T, S> entry(bObj, newData);
537                                mergedPvs.mEntries.push_back(entry);
538                        }
539                        else
540                        {
541                                mergedPvs.mEntries.push_back(*bit);
542                        }
543                       
544                        //bObjOld = bObj;
545                }
546
547                // only push back if objects different
548                // (equal case is handled by second loop)
549                if (aObj != bObj)
550                {
551                        mergedPvs.mEntries.push_back(*ait);
552                }
553        }
554
555        // add the rest
556        for (; (bit != bEnd); ++ bit)
557        {
558                mergedPvs.mEntries.push_back(*bit);
559        }
560
561        mergedPvs.mSamples = aSamples + bSamples;
562}
563
564
565template <typename T, typename S> void Pvs<T, S>::Clear(const bool trim = true)
566{
567        mEntries.clear();
568        mSamples = 0;
569        mLastSorted = 0;
570
571        if (trim)
572        {
573                vector<PvsEntry<T,S> >().swap(mEntries);
574        }
575}
576
577
578template <typename T, typename S> void Pvs<T, S>::Trim()
579{
580        vector<PvsEntry<T,S> >(mEntries).swap(mEntries);
581}
582
583
584template <typename T, typename S>
585bool Pvs<T, S>::Find(T sample,
586                                         typename vector<PvsEntry<T, S> >::iterator &it,
587                                         const bool checkDirty)
588{
589        bool found = false;
590
591        PvsEntry<T, S> dummy(sample, PvsData());
592
593        // only check clean part
594        //mLastSorted = 0;
595        vector<PvsEntry<T, S> >::iterator sorted_end = mEntries.begin() + mLastSorted;
596
597        // binary search
598        it = lower_bound(mEntries.begin(), sorted_end, dummy);
599
600        if ((it != mEntries.end()) && ((*it).mObject == sample))
601                found = true;
602
603        // sample not found yet => search further in the unsorted part
604        if (!found && checkDirty)
605        {
606                vector<PvsEntry<T, S> >::const_iterator dit, dit_end = mEntries.end();
607
608                for (dit = sorted_end; (dit != dit_end) && ((*dit).mObject != sample); ++ dit);
609
610                if ((dit != mEntries.end()) && ((*dit).mObject == sample))
611                        found = true;
612        }
613       
614        return found;
615}
616
617
618template <typename T, typename S>
619void Pvs<T, S>::GetData(const int index, T &entry, S &data)
620{
621        std::vector<PvsEntry<T, S> >::iterator i = mEntries.begin();
622        for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k);
623
624        entry = (*i).first;
625        data = (*i).second;
626}
627
628
629template <typename T, typename S>
630float Pvs<T, S>::AddSample(T sample, const float pdf)
631{
632        ++ mSamples;
633       
634        vector<PvsEntry<T, S> >::iterator it;
635        const bool entryFound = Find(sample, it);               
636
637        if (entryFound)
638        {       
639                S &data = (*it).mData;
640                data.mSumPdf += pdf;
641                return data.mSumPdf;
642        }
643        else
644        {
645                PvsEntry<T, S> entry(sample, pdf);
646                mEntries.insert(it, entry);
647                ++ mLastSorted;
648                return pdf;
649        }
650}
651
652
653template <typename T, typename S>
654void Pvs<T, S>::AddSampleDirty(T sample, const float pdf)
655{
656        ++ mSamples;
657        mEntries.push_back(PvsEntry<T, S>(sample, pdf));
658}
659                                         
660
661template <typename T, typename S>
662typename vector< PvsEntry<T, S> >::iterator Pvs<T, S>::AddSample2(T sample,
663                                                                                                                                  const float pdf)
664{
665        ++ mSamples;
666       
667        vector<PvsEntry<T, S> >::iterator it;
668        const bool entryFound == Find(sample, it);
669
670        if (entryFound)
671        {
672                S &data = (*it).second;
673                data->mSumPdf += pdf;
674        }
675        else
676        {
677                PvsEntry<T, S> entry(sample, pdf);
678                mEntries.insert(it, entry);
679                ++ mLastSorted;
680        }
681
682        return it;
683}
684
685
686/** Adds sample dirty (on the end of the vector) but
687        first checks if sample is already in clean part of the pvs.
688*/
689template <typename T, typename S>
690bool Pvs<T, S>::AddSampleDirtyCheck(T sample,
691                                                                        const float pdf)
692                                                                        //,float &contribution)
693{
694        ++ mSamples;
695
696        vector<PvsEntry<T, S> >::iterator it;
697        const bool entryFound = Find(sample, it);
698
699        if (entryFound)
700        {
701                S &data = (*it).mData;
702
703                data.mSumPdf += pdf;
704                //contribution = pdf / data.mSumPdf;
705
706                return false;
707        }
708        else
709        {
710                AddSampleDirty(sample, pdf);
711                //contribution = 1.0f;
712
713                return true;
714        }
715}
716
717
718template <typename T, typename S>
719bool Pvs<T, S>::GetSampleContribution(T sample,
720                                                                          const float pdf,
721                                                                          float &contribution)
722{
723        vector<PvsEntry<T, S> >::iterator it;
724        const bool entryFound = Find(sample, it);
725
726        if (entryFound) 
727        {
728                S &data = (*it).mData;
729                contribution = pdf / (data.mSumPdf + pdf);
730                return false;
731        }
732        else
733        {
734                contribution = 1.0f;
735                return true;
736        }
737}
738
739
740template <typename T, typename S>
741bool Pvs<T, S>::RemoveSample(T sample, const float pdf)
742{
743        -- mSamples;
744       
745        vector<PvsEntry<T, S> >::iterator it;
746        const bool entryFound = Find(sample, it);
747
748        if (!entryFound)
749                return false;
750
751        S &data = (*it).mData;
752
753        data.mSumPdf -= pdf;
754
755        if (data.mSumPdf <= 0.0f)
756        {
757                mEntries.erase(it);
758                -- mLastSorted; // wrong if sample was in tail!!
759        }
760
761        return true;
762}
763
764
765template <typename T, typename S>
766int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs)
767{
768        const int samples = mSamples - pvs.mSamples;
769
770        std::vector<PvsEntry<T, S> >::
771                const_iterator it, it_end = pvs.mEntries.end();
772
773        // output PVS of view cell
774        for (it = pvs.mEntries.begin(); it != it_end; ++ it)
775                RemoveSample((*it).mObject, (*it).mData.mSumPdf);
776
777        mSamples = samples;
778
779        return GetSize();
780}
781
782
783template <typename T, typename S>
784void Pvs<T, S>::CollectEntries(std::vector<T> &entries)
785{
786        std::vector<PvsEntry<T, S> >::
787                const_iterator it, it_end = mEntries.end();
788
789        // output PVS of view cell
790        for (it = mEntries.begin(); it != it_end; ++ it)
791                entries.push_back((*it)->first);
792}
793
794
795template <typename T, typename S>
796void Pvs<T, S>::NormalizeMaximum()
797{
798        std::vector<PvsEntry<T, S> >::
799                const_iterator it, it_end = mEntries.end();
800
801        float maxPdfSum = -1.0f;
802
803        // output PVS of view cell
804        for (it = mEntries.begin(); it != it_end; ++ it) {
805                float sum = (*it)->second.sumPdf;
806                if (sum > maxSum)
807                        maxSum = sum;
808        }
809
810        maxSum = 1.0f / maxSum;
811
812        for (it = mEntries.begin(); it != it_end; ++ it) {
813                (*it)->second.sumPdf *= maxSum;
814        }
815
816}
817
818
819template <typename T, typename S>
820float Pvs<T, S>::GetEntrySize()
821{
822        return (float)(sizeof(T) + sizeof(S)) / float(1024 * 1024);
823}
824
825
826template <typename T, typename S>
827int Pvs<T, S>::GetEntrySizeByte()
828{
829        return sizeof(T) + sizeof(S);
830}
831
832
833template <typename T, typename S>
834float Pvs<T, S>::GetPvsHomogenity(Pvs<T, S> &pvs)
835{
836        float pvsReduction, pvsEnlargement;
837
838        ComputeContinuousPvsDifference(pvs,     pvsReduction, pvsEnlargement);
839
840        return pvsReduction + pvsEnlargement;
841}
842
843
844template <typename T, typename S>
845typename PvsIterator<T, S> Pvs<T, S>::GetIterator() const
846{
847        PvsIterator<T, S> pit(mEntries.begin(), mEntries.end());
848
849        return pit;
850}
851
852
853///////////////////////////////////////
854
855/** Class instantiating the Pvs template for kd tree nodes.
856*/
857class KdPvs: public Pvs<KdNode *, PvsData>
858{
859public:
860        int Compress();
861};
862
863
864////////////
865//-- typedefs
866
867typedef PvsEntry<Intersectable *, PvsData> ObjectPvsEntry;
868typedef std::vector<ObjectPvsEntry> ObjectPvsEntries;
869typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs;
870typedef PvsIterator<Intersectable *, PvsData> ObjectPvsIterator;
871
872
873class ObjectPvs: public Pvs<Intersectable *, PvsData>
874{
875public:
876        /** Counts object int the pvs. Different to method "GetSize", not
877                only the raw container size is returned,
878                but the individual contributions of the entries are summed up.
879        */
880        float EvalPvsCost() const;
881
882        friend ostream &operator<<(ostream &s, const ObjectPvs &p)
883        {
884                ObjectPvsIterator pit = p.GetIterator();
885
886                while (pit.HasMoreEntries())
887                {               
888                        const ObjectPvsEntry &entry = pit.Next();
889                        Intersectable *obj = entry.mObject;
890
891                        cout << (int)obj << " ";
892                }
893               
894                return s;
895        }
896
897};
898
899
900
901}
902
903#endif
904
Note: See TracBrowser for help on using the repository browser.