1 | #ifndef SUBDIVISIONCANDIDATE_H
|
---|
2 | #define SUBDIVISIONCANDIDATE_H
|
---|
3 |
|
---|
4 |
|
---|
5 | #include "FlexibleHeap.h"
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | class SubdivisionCandidate;
|
---|
12 |
|
---|
13 | typedef vector<SubdivisionCandidate *> SubdivisionCandidateContainer;
|
---|
14 | typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
|
---|
15 |
|
---|
16 | /** Candidate for a view space / object space split.
|
---|
17 | */
|
---|
18 | class SubdivisionCandidate: public Heapable
|
---|
19 | {
|
---|
20 | public:
|
---|
21 |
|
---|
22 | enum {OBJECT_SPACE, VIEW_SPACE};
|
---|
23 |
|
---|
24 | SubdivisionCandidate():
|
---|
25 | mRenderCostDecrease(0),
|
---|
26 | mAvgRayContribution(0),
|
---|
27 | mDirty(true)
|
---|
28 | {}
|
---|
29 |
|
---|
30 | virtual ~SubdivisionCandidate() {};
|
---|
31 |
|
---|
32 | /** Evaluate this subdivision candidate.
|
---|
33 | */
|
---|
34 | virtual void EvalCandidate(bool computeSplitplane = true) = 0;
|
---|
35 |
|
---|
36 | /** Returns type of this subdivision candidate.
|
---|
37 | */
|
---|
38 | virtual int Type() const = 0;
|
---|
39 |
|
---|
40 | /** Evaluate this candidate and put results into queue for further traversal.
|
---|
41 | */
|
---|
42 | virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) = 0;
|
---|
43 |
|
---|
44 | /** Returns true of the global termination criteria of this split were met,
|
---|
45 | false otherwise.
|
---|
46 | */
|
---|
47 | virtual bool GlobalTerminationCriteriaMet() const = 0;
|
---|
48 |
|
---|
49 | /** Collects subdivision candidates that were affected by the
|
---|
50 | application of this one.
|
---|
51 | */
|
---|
52 | virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList,
|
---|
53 | const bool onlyUnmailed) = 0;
|
---|
54 |
|
---|
55 | /** Set render cost decrease achieved through this split.
|
---|
56 | */
|
---|
57 | inline void SetRenderCostDecrease(const float renderCostDecr)
|
---|
58 | {
|
---|
59 | mRenderCostDecrease = renderCostDecr;
|
---|
60 | }
|
---|
61 |
|
---|
62 | inline float GetRenderCostDecrease() const
|
---|
63 | {
|
---|
64 | return mRenderCostDecrease;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /** The average ray contribution of this candidate .
|
---|
68 | This is somewhat of a confidence value into the computed values. If
|
---|
69 | it is high, there is likely to be a lot of undersampling.
|
---|
70 | */
|
---|
71 | inline void SetAvgRayContribution(const float rayContri)
|
---|
72 | {
|
---|
73 | mAvgRayContribution = rayContri;
|
---|
74 | }
|
---|
75 |
|
---|
76 | inline float GetAvgRayContribution() const
|
---|
77 | {
|
---|
78 | return mAvgRayContribution;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /** Position in queue.
|
---|
82 | */
|
---|
83 | inline int GetPosition() const
|
---|
84 | {
|
---|
85 | return mPosition;
|
---|
86 | }
|
---|
87 |
|
---|
88 | inline void SetSplitAxis(const int splitAxis)
|
---|
89 | {
|
---|
90 | mSplitAxis = splitAxis;
|
---|
91 | }
|
---|
92 |
|
---|
93 | inline void SetMaxCostMisses(const int misses)
|
---|
94 | {
|
---|
95 | mMaxCostMisses = misses;
|
---|
96 | }
|
---|
97 |
|
---|
98 | inline void SetPvsEntriesIncr(const int pvsEntriesIncr)
|
---|
99 | {
|
---|
100 | mPvsEntriesIncr = pvsEntriesIncr;
|
---|
101 | }
|
---|
102 |
|
---|
103 | inline int GetSplitAxis() const
|
---|
104 | {
|
---|
105 | return mSplitAxis;
|
---|
106 | }
|
---|
107 |
|
---|
108 | inline int GetMaxCostMisses() const
|
---|
109 | {
|
---|
110 | return mMaxCostMisses;
|
---|
111 | }
|
---|
112 |
|
---|
113 | inline int GetPvsEntriesIncr() const
|
---|
114 | {
|
---|
115 | return mPvsEntriesIncr;
|
---|
116 | }
|
---|
117 |
|
---|
118 | inline bool IsDirty() const
|
---|
119 | {
|
---|
120 | return mDirty;
|
---|
121 | }
|
---|
122 |
|
---|
123 | inline void SetDirty(const bool dirty)
|
---|
124 | {
|
---|
125 | mDirty = dirty;
|
---|
126 | }
|
---|
127 |
|
---|
128 | //////////
|
---|
129 | //-- mailing stuff
|
---|
130 |
|
---|
131 | static void NewMail(const int reserve = 1)
|
---|
132 | {
|
---|
133 | sMailId += sReservedMailboxes;
|
---|
134 | sReservedMailboxes = reserve;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void Mail() { mMailbox = sMailId; }
|
---|
138 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
139 |
|
---|
140 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
141 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
142 |
|
---|
143 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
144 |
|
---|
145 |
|
---|
146 | // last mail id -> warning not thread safe!
|
---|
147 | // both mailId and mailbox should be unique for each thread!!!
|
---|
148 | static int sMailId;
|
---|
149 | static int sReservedMailboxes;
|
---|
150 |
|
---|
151 | void *mEvaluationHack;
|
---|
152 |
|
---|
153 | protected:
|
---|
154 |
|
---|
155 | /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned)
|
---|
156 | int mSplitAxis;
|
---|
157 | /// the number of misses of max cost ratio until this split
|
---|
158 | int mMaxCostMisses;
|
---|
159 | /// render cost decrease achieved through this split
|
---|
160 | float mRenderCostDecrease;
|
---|
161 | /// the decrease of the number of pvs entries
|
---|
162 | int mPvsEntriesIncr;
|
---|
163 |
|
---|
164 | /// the average ray contribution of this candidate
|
---|
165 | float mAvgRayContribution;
|
---|
166 |
|
---|
167 | int mMailbox;
|
---|
168 |
|
---|
169 | bool mDirty;
|
---|
170 | };
|
---|
171 |
|
---|
172 |
|
---|
173 | }
|
---|
174 |
|
---|
175 | // SUBDIVISIONCANDIDATE_H
|
---|
176 | #endif
|
---|