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