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

Revision 1842, 20.1 KB checked in by mattausch, 18 years ago (diff)

fixed compress

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