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

RevLine 
[177]1#ifndef __PVS_H
2#define __PVS_H
3
4#include <map>
5
6class KdNode;
[240]7class BspNode;
[191]8class Ray;
[308]9class Intersectable;
[177]10
[310]11
12template<typename T>
13struct 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
22template<typename T>
23struct PvsData {
24  int mVisibleSamples;
25  PvsData<T>() {}
[311]26  PvsData<T>(const int samples): mVisibleSamples(samples) {}
[310]27};
28
29template<typename T>
[311]30class Pvs
[310]31{
32public:
[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
49template <typename T>
[311]50PvsData<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
59template <typename T>
[311]60void 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]71template <typename T>
72int 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*/
94class KdPvs: public Pvs<KdNode *>
[308]95{
[311]96        int Compress();
[308]97};
98
[311]99typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap;
[312]100typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap;
101typedef PvsData<Intersectable *> ViewCellPvsData;
[311]102typedef PvsData<KdNode *> KdPvsData;
103//typedef Pvs<KdNode *> KdPvs;
104typedef Pvs<Intersectable *> ViewCellPvs;
[308]105
[177]106#endif
107
Note: See TracBrowser for help on using the repository browser.