source: GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h @ 2227

Revision 2227, 4.4 KB checked in by mattausch, 17 years ago (diff)

added render cost bound for objects, improved undersampling compensation

Line 
1#ifndef SUBDIVISIONCANDIDATE_H
2#define SUBDIVISIONCANDIDATE_H
3
4
5#include "FlexibleHeap.h"
6
7//
8
9namespace GtpVisibilityPreprocessor {
10
11class SubdivisionCandidate;
12
13typedef std::vector<SubdivisionCandidate *> SubdivisionCandidateContainer;
14typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
15
16/** Candidate for a view space / object space split.
17*/
18class SubdivisionCandidate: public Heapable
19
20public:
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,
43                                           bool terminationCriteriaMet,
44                                           SubdivisionCandidateContainer &dirtyList) = 0;
45       
46        /** Returns true of the global termination criteria of this split were met,
47                false otherwise.
48        */
49        virtual bool GlobalTerminationCriteriaMet() const = 0;
50       
51        /** Collects subdivision candidates that were affected by the
52                application of this one.
53        */
54        virtual void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList,
55                                                                                const bool onlyUnmailed) = 0;
56
57        /** Set render cost decrease achieved through this split.
58        */
59        inline void SetRenderCostDecrease(const float renderCostDecr)
60        {
61                mRenderCostDecrease = renderCostDecr;
62        }
63       
64        inline float GetRenderCostDecrease() const
65        {
66                return mRenderCostDecrease;
67        }
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 SetAvgRayContribution(const float rayContri)
74        {
75                mAvgRayContribution = rayContri;
76        }
77       
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        }
87        inline float GetAvgRayContribution() const
88        {
89                return mAvgRayContribution;
90        }
91
92        /** Returns average rays per object.
93        */
94        float GetAvgRaysPerObject() const
95        {
96                return (float)mAvgRaysPerObject;
97        }
98
99        /** Position in queue.
100        */
101        inline int GetPosition() const
102        {
103                return mPosition;
104        }
105
106        inline void SetSplitAxis(const int splitAxis)
107        {
108                mSplitAxis = splitAxis;
109        }
110       
111        inline void SetMaxCostMisses(const int misses)
112        {
113                mMaxCostMisses = misses;
114        }
115
116        inline void SetPvsEntriesIncr(const int pvsEntriesIncr)
117        {
118                mPvsEntriesIncr = pvsEntriesIncr;
119        }
120
121        inline int GetSplitAxis() const
122        {
123                return mSplitAxis;
124        }
125
126        inline int GetMaxCostMisses() const
127        {
128                return mMaxCostMisses;
129        }
130
131        inline int GetPvsEntriesIncr() const
132        {
133                return mPvsEntriesIncr;
134        }
135
136        inline bool IsDirty() const
137        {
138                return mDirty;
139        }
140
141        inline void SetDirty(const bool dirty)
142        {
143                mDirty = dirty;
144        }
145
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
169        void *mEvaluationHack;
170
171protected:
172
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;
177        /// render cost decrease achieved through this split
178        float mRenderCostDecrease;
179        /// the decrease of the number of pvs entries
180        int mPvsEntriesIncr;
181
182        /// the average ray contribution of this candidate
183        float mAvgRayContribution;
184
185        /// the average ray contribution of this candidate
186        float mAvgRaysPerObject;
187
188        int mMailbox;
189
190        bool mDirty;
191};
192
193
194}
195
196// SUBDIVISIONCANDIDATE_H
197#endif
Note: See TracBrowser for help on using the repository browser.