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