source: GTP/trunk/Lib/Vis/Preprocessing/src/PvsBase.h @ 2530

Revision 2530, 2.8 KB checked in by mattausch, 18 years ago (diff)
RevLine 
[2116]1#ifndef __PVSBASE_H
2#define __PVSBASE_H
3
4#include "common.h"
5#include "Containers.h"
6
7
[2530]8
[2116]9namespace GtpVisibilityPreprocessor {
10
11
12/** Information stored with a PVS entry. Consists of the number
13        the object was seen from the view cell.
14*/
15template<typename T, typename S>
16struct PvsEntry
17{
18public:
19
[2117]20        PvsEntry(): mObject(NULL), mData(0) {}
21        PvsEntry(T sample): mObject(sample), mData(0) {}
[2116]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
34template<typename T, typename S>
35int operator< (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
36{
37        return a.mObject < b.mObject;
38}
39
40template<typename T, typename S>
41int operator== (const PvsEntry<T, S> &a, const PvsEntry<T, S> &b)
42{
43        return a.mObject == b.mObject;
44}
45
46
47template<typename T, typename S>
48struct 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
56template<typename T, typename S>
57int 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*/
65struct PvsData
66{
67public:
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!!!
[2529]74        inline float GetVisibility() { return mSumPdf; }
[2116]75
76        /// sum of probability density of visible sample rays
77        float mSumPdf;
78};
79
80
81class MailablePvsData
82{
83public:
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!!!
[2529]94        inline float GetVisibility() { return mSumPdf; }
[2116]95
[2529]96
[2116]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
121protected:
122
123        int mMailbox;
124
125};
126
127}
128
129#endif
Note: See TracBrowser for help on using the repository browser.