source: trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h @ 312

Revision 312, 2.1 KB checked in by mattausch, 19 years ago (diff)

bsp split exporter added

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