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

Revision 366, 3.1 KB checked in by mattausch, 19 years ago (diff)

some ideas abou saving bspleaves with the ray and t

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();}
[341]38        bool Empty() {return mEntries.size() == 0;}
[362]39        /** Merges pvs of a and pvs of b into this pvs.
40        */
[350]41        void Merge(const Pvs<T> &a, const Pvs<T> &b);
[362]42    /** Difference of pvs to pvs b.
43                @returns number of different entries.
44        */
45        int Diff(const Pvs<T> &b);
[310]46
47        PvsData<T> *Find(T sample);
48        int AddSample(T sample);
49
[362]50        void GetData(const int index, T &entry, PvsData<T> &data);
[310]51        std::map<T, PvsData<T>, LtSample<T> > mEntries;
52};
53
[341]54template <typename T>
[362]55int Pvs<T>::Diff(const Pvs<T> &b)
56{
57        int dif = 0;
58
59        std::map<T, PvsData<T>, LtSample<T> >::const_iterator it;
60
61        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
62        {
63                PvsData<T> *data = Find((*it).first);           
64                if (!data) ++ dif;
65        }
66
67        return dif;
68}
69
70template <typename T>
[350]71void Pvs<T>::Merge(const Pvs<T> &a, const Pvs<T> &b)
[341]72{
[362]73        std::map<T, PvsData<T>, LtSample<T> >::const_iterator it;
74
75        // todo: copy all elements instead of inserting
76        for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it)
77        {
78                mEntries.insert(*it);
79        }
80
81        for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
82        {
83                PvsData<T> *data = Find((*it).first);
84               
85                if (data)
86                        data->mVisibleSamples += (*it).second.mVisibleSamples;
87                else
88                        mEntries.insert(*it);
89        }
[341]90}
91
[362]92
[310]93template <typename T>
[311]94PvsData<T> *Pvs<T>::Find(T sample)
[310]95{
[311]96  std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.find(sample);
[310]97  if (i != mEntries.end()) {
98    return &(*i).second;
[311]99  } else
[310]100    return NULL;
101}
102
103template <typename T>
[311]104void Pvs<T>::GetData(const int index,
[310]105               T &entry,
106               PvsData<T> &data)
107{
[311]108  std::map<T, PvsData<T>, LtSample<T> >::iterator i = mEntries.begin();
[310]109  for (int k = 0; k != index && i != mEntries.end(); i++, k++);
110
111  entry = (*i).first;
[311]112  data = (*i).second;
[310]113}
114
[311]115template <typename T>
116int Pvs<T>::AddSample(T sample)
[177]117{
[311]118        int result;
119        PvsData<T> *data = Find(sample);
[177]120
[311]121        if (data)
122        {
123                data->mVisibleSamples ++;
124                result = 0;
[240]125       
[311]126        }
127        else
128        {
129                mEntries[sample] = PvsData<T>(1);
130                result = 1;
131        }
[240]132
[311]133        return  result;
134}
[308]135
[311]136/** Class instantiating the Pvs template for kd tree nodes.
137*/
138class KdPvs: public Pvs<KdNode *>
[308]139{
[311]140        int Compress();
[308]141};
142
[311]143typedef std::map<KdNode *, PvsData<KdNode *>, LtSample<KdNode *> > KdPvsMap;
[312]144typedef std::map<Intersectable *, PvsData<Intersectable *>, LtSample<Intersectable *> > ViewCellPvsMap;
145typedef PvsData<Intersectable *> ViewCellPvsData;
[311]146typedef PvsData<KdNode *> KdPvsData;
147//typedef Pvs<KdNode *> KdPvs;
148typedef Pvs<Intersectable *> ViewCellPvs;
[308]149
[366]150
[177]151#endif
152
Note: See TracBrowser for help on using the repository browser.