1 | #ifndef __PVSBASE_H
|
---|
2 | #define __PVSBASE_H
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "Containers.h"
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 |
|
---|
12 | /** Information stored with a PVS entry. Consists of the number
|
---|
13 | the object was seen from the view cell.
|
---|
14 | */
|
---|
15 | template<typename T, typename S>
|
---|
16 | struct PvsEntry
|
---|
17 | {
|
---|
18 | public:
|
---|
19 |
|
---|
20 | PvsEntry(): mObject(NULL), mData(0) {}
|
---|
21 | PvsEntry(T sample): mObject(sample), mData(0) {}
|
---|
22 | PvsEntry(T sample, const S &data): mObject(sample), mData(data) {}
|
---|
23 |
|
---|
24 | T mObject;
|
---|
25 | S mData;
|
---|
26 |
|
---|
27 | template<typename T, typename S>
|
---|
28 | friend int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b);
|
---|
29 | template<typename T, typename S>
|
---|
30 | friend int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b);
|
---|
31 | };
|
---|
32 |
|
---|
33 |
|
---|
34 | template<typename T, typename S>
|
---|
35 | int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
|
---|
36 | {
|
---|
37 | return a.mObject < b.mObject;
|
---|
38 | }
|
---|
39 |
|
---|
40 | template<typename T, typename S>
|
---|
41 | int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
|
---|
42 | {
|
---|
43 | return a.mObject == b.mObject;
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | template<typename T, typename S>
|
---|
48 | struct LtSample
|
---|
49 | {
|
---|
50 | bool operator()(const PvsEntry<T, S> &a, const PvsEntry<T, S> &b) const
|
---|
51 | {
|
---|
52 | return a.mObject < b.mObject;
|
---|
53 | }
|
---|
54 | };
|
---|
55 |
|
---|
56 | template<typename T, typename S>
|
---|
57 | int equalSample (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
|
---|
58 | {
|
---|
59 | return a.mObject == b.mObject;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /** Information stored with a PVS entry. Consists of the number
|
---|
63 | the object was seen from the view cell.
|
---|
64 | */
|
---|
65 | struct PvsData
|
---|
66 | {
|
---|
67 | public:
|
---|
68 | PvsData() {}
|
---|
69 | PvsData(const float sumPdf):
|
---|
70 | mSumPdf(sumPdf) {}
|
---|
71 |
|
---|
72 | // $$JB in order to return meaningfull values
|
---|
73 | // it assumes that the sum pdf has been normalized somehow!!!
|
---|
74 | inline float GetVisibility() { return mSumPdf; }
|
---|
75 |
|
---|
76 | /// sum of probability density of visible sample rays
|
---|
77 | float mSumPdf;
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 | class MailablePvsData
|
---|
82 | {
|
---|
83 | public:
|
---|
84 | // sum of probability density of visible sample rays
|
---|
85 | float mSumPdf;
|
---|
86 | int mCounter;
|
---|
87 |
|
---|
88 | MailablePvsData() {}
|
---|
89 | MailablePvsData(const float sumPdf):
|
---|
90 | mSumPdf(sumPdf) {}
|
---|
91 |
|
---|
92 | // $$JB in order to return meaningfull values
|
---|
93 | // it assumes that the sum pdf has been normalized somehow!!!
|
---|
94 | inline float GetVisibility() { return mSumPdf; }
|
---|
95 |
|
---|
96 |
|
---|
97 | ///////////////
|
---|
98 | // Mailing stuff
|
---|
99 |
|
---|
100 | // last mail id -> warning not thread safe!
|
---|
101 | // both mailId and mailbox should be unique for each thread!!!
|
---|
102 | static int sMailId;
|
---|
103 | static int sReservedMailboxes;
|
---|
104 |
|
---|
105 | static void NewMail(const int reserve = 1)
|
---|
106 | {
|
---|
107 | sMailId += sReservedMailboxes;
|
---|
108 | sReservedMailboxes = reserve;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void Mail() { mMailbox = sMailId; }
|
---|
112 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
113 |
|
---|
114 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
115 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
116 |
|
---|
117 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
118 |
|
---|
119 | //////////////////////////////////////////
|
---|
120 |
|
---|
121 | protected:
|
---|
122 |
|
---|
123 | int mMailbox;
|
---|
124 |
|
---|
125 | };
|
---|
126 |
|
---|
127 | }
|
---|
128 |
|
---|
129 | #endif |
---|