[177] | 1 | #ifndef __PVS_H
|
---|
| 2 | #define __PVS_H
|
---|
| 3 |
|
---|
| 4 | #include <map>
|
---|
| 5 |
|
---|
| 6 | class KdNode;
|
---|
[240] | 7 | class BspNode;
|
---|
[191] | 8 | class Ray;
|
---|
[308] | 9 | class Intersectable;
|
---|
[177] | 10 |
|
---|
[310] | 11 |
|
---|
| 12 | template<typename T>
|
---|
| 13 | struct LtSample {
|
---|
[311] | 14 | bool operator()(const T a, const T b) const
|
---|
[310] | 15 | {
|
---|
| 16 | return a < b;
|
---|
| 17 | }
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | //typedef std::map<T *, PvsData<T>, LtSample<T>> PvsMap<T>;
|
---|
| 21 |
|
---|
| 22 | template<typename T>
|
---|
| 23 | struct PvsData {
|
---|
| 24 | int mVisibleSamples;
|
---|
| 25 | PvsData<T>() {}
|
---|
[311] | 26 | PvsData<T>(const int samples): mVisibleSamples(samples) {}
|
---|
[310] | 27 | };
|
---|
| 28 |
|
---|
| 29 | template<typename T>
|
---|
[311] | 30 | class Pvs
|
---|
[310] | 31 | {
|
---|
| 32 | public:
|
---|
[311] | 33 | Pvs(): mSamples(0), mEntries() {}
|
---|
[310] | 34 | int mSamples;
|
---|
| 35 |
|
---|
[311] | 36 | int Compress() {return 0;}
|
---|
[310] | 37 | int GetSize() {return (int)mEntries.size();}
|
---|
| 38 |
|
---|
| 39 | PvsData<T> *Find(T sample);
|
---|
| 40 | int AddSample(T sample);
|
---|
| 41 |
|
---|
| 42 | void GetData(const int index,
|
---|
| 43 | T &entry,
|
---|
| 44 | PvsData<T> &data);
|
---|
| 45 | std::map<T, PvsData<T>, LtSample<T> > mEntries;
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | template <typename T>
|
---|
[311] | 50 | PvsData<T> *Pvs<T>::Find(T sample)
|
---|
[310] | 51 | {
|
---|
[311] | 52 | std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.find(sample);
|
---|
[310] | 53 | if (i != mEntries.end()) {
|
---|
| 54 | return &(*i).second;
|
---|
[311] | 55 | } else
|
---|
[310] | 56 | return NULL;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | template <typename T>
|
---|
[311] | 60 | void Pvs<T>::GetData(const int index,
|
---|
[310] | 61 | T &entry,
|
---|
| 62 | PvsData<T> &data)
|
---|
| 63 | {
|
---|
[311] | 64 | std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.begin();
|
---|
[310] | 65 | for (int k = 0; k != index && i != mEntries.end(); i++, k++);
|
---|
| 66 |
|
---|
| 67 | entry = (*i).first;
|
---|
[311] | 68 | data = (*i).second;
|
---|
[310] | 69 | }
|
---|
| 70 |
|
---|
[311] | 71 | template <typename T>
|
---|
| 72 | int Pvs<T>::AddSample(T sample)
|
---|
[177] | 73 | {
|
---|
[311] | 74 | int result;
|
---|
| 75 | PvsData<T> *data = Find(sample);
|
---|
[177] | 76 |
|
---|
[311] | 77 | if (data)
|
---|
| 78 | {
|
---|
| 79 | data->mVisibleSamples ++;
|
---|
| 80 | result = 0;
|
---|
[240] | 81 |
|
---|
[311] | 82 | }
|
---|
| 83 | else
|
---|
| 84 | {
|
---|
| 85 | mEntries[sample] = PvsData<T>(1);
|
---|
| 86 | result = 1;
|
---|
| 87 | }
|
---|
[240] | 88 |
|
---|
[311] | 89 | return result;
|
---|
| 90 | }
|
---|
[308] | 91 |
|
---|
[311] | 92 | /** Class instantiating the Pvs template for kd tree nodes.
|
---|
| 93 | */
|
---|
| 94 | class KdPvs: public Pvs<KdNode *>
|
---|
[308] | 95 | {
|
---|
[311] | 96 | int Compress();
|
---|
[308] | 97 | };
|
---|
| 98 |
|
---|
[311] | 99 | typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap;
|
---|
[312] | 100 | typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap;
|
---|
| 101 | typedef PvsData<Intersectable *> ViewCellPvsData;
|
---|
[311] | 102 | typedef PvsData<KdNode *> KdPvsData;
|
---|
| 103 | //typedef Pvs<KdNode *> KdPvs;
|
---|
| 104 | typedef Pvs<Intersectable *> ViewCellPvs;
|
---|
[308] | 105 |
|
---|
[177] | 106 | #endif
|
---|
| 107 |
|
---|