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