1 | #ifndef _GvsPreprocessor_H__
|
---|
2 | #define _GvsPreprocessor_H__
|
---|
3 |
|
---|
4 | #include <fstream>
|
---|
5 | #include <stack>
|
---|
6 |
|
---|
7 | #include "Preprocessor.h"
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | class Exporter;
|
---|
12 | class VssRay;
|
---|
13 |
|
---|
14 | /** View space partition statistics.
|
---|
15 | */
|
---|
16 | class GvsStatistics: public StatisticsBase
|
---|
17 | {
|
---|
18 | public:
|
---|
19 |
|
---|
20 | /// Constructor
|
---|
21 | GvsStatistics()
|
---|
22 | {
|
---|
23 | Reset();
|
---|
24 | }
|
---|
25 |
|
---|
26 | void Reset()
|
---|
27 | {
|
---|
28 | mPass = 0;
|
---|
29 | mTotalSamples = 0;
|
---|
30 | mPassContribution = 0;
|
---|
31 | mTotalContribution = 0;
|
---|
32 | mReverseSamples = 0;
|
---|
33 | mBorderSamples = 0;
|
---|
34 | mGvsPass = 0;
|
---|
35 |
|
---|
36 | mTotalPvs = 0;
|
---|
37 | mViewCells = 0;
|
---|
38 | mPerViewCellSamples = 0;
|
---|
39 | mPerViewCellPvs = 0;
|
---|
40 | mTrianglePvs = 0;
|
---|
41 | mViewCellId = 0;
|
---|
42 | mTotalTime = 0;
|
---|
43 | mTimePerViewCell = 0;
|
---|
44 | mTotalTrianglePvs = 0;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | public:
|
---|
49 |
|
---|
50 | int mPass;
|
---|
51 | int mTotalSamples;
|
---|
52 | int mPassContribution;
|
---|
53 | int mTotalContribution;
|
---|
54 | int mReverseSamples;
|
---|
55 | int mBorderSamples;
|
---|
56 | int mGvsPass;
|
---|
57 |
|
---|
58 | int mTotalPvs;
|
---|
59 | int mViewCells;
|
---|
60 | int mPerViewCellSamples;
|
---|
61 | int mPerViewCellPvs;
|
---|
62 | int mTrianglePvs;
|
---|
63 | int mTotalTrianglePvs;
|
---|
64 | int mViewCellId;
|
---|
65 |
|
---|
66 | float mTimePerViewCell;
|
---|
67 | float mTotalTime;
|
---|
68 |
|
---|
69 | float RaysPerSec() const { if (!mTotalTime) return 0; return (float)mTotalSamples / mTotalTime * 1e-6f; }
|
---|
70 |
|
---|
71 | void Print(ostream &app) const;
|
---|
72 |
|
---|
73 | friend ostream &operator<<(ostream &s, const GvsStatistics &stat)
|
---|
74 | {
|
---|
75 | stat.Print(s);
|
---|
76 | return s;
|
---|
77 | }
|
---|
78 | };
|
---|
79 |
|
---|
80 |
|
---|
81 | /** Sampling based visibility preprocessing. The implementation is
|
---|
82 | based on heuristical sampling of view space.
|
---|
83 | */
|
---|
84 | class GvsPreprocessor : public Preprocessor {
|
---|
85 |
|
---|
86 | public:
|
---|
87 |
|
---|
88 | GvsPreprocessor();
|
---|
89 | ~GvsPreprocessor();
|
---|
90 |
|
---|
91 | virtual bool ComputeVisibility();
|
---|
92 |
|
---|
93 |
|
---|
94 | protected:
|
---|
95 | #if 0
|
---|
96 | struct PendingRay
|
---|
97 | {
|
---|
98 | PendingRay(VssRay *ray, const bool d)
|
---|
99 | : mRay(ray), mFoundDiscontinuity(d)
|
---|
100 | {}
|
---|
101 |
|
---|
102 | VssRay *mRay;
|
---|
103 | bool mFoundDiscontinuity;
|
---|
104 | };
|
---|
105 |
|
---|
106 | typedef stack<PendingRay> PendingQueue;
|
---|
107 | #endif
|
---|
108 | typedef stack<VssRay *> RayQueue;
|
---|
109 |
|
---|
110 | /** Runs the adaptive sampling until the ray queue is empty.
|
---|
111 | The method starts with a number of random rays given
|
---|
112 | by the queue and continues as long it finds new visible geometry
|
---|
113 | (i.e., the queue is not empty).
|
---|
114 |
|
---|
115 | @returns the number of samples cast.
|
---|
116 | */
|
---|
117 | int ProcessQueue();
|
---|
118 |
|
---|
119 | /** Generates the rays starting the adaptive visibility sampling process.
|
---|
120 | */
|
---|
121 | int CastInitialSamples(const int numSamples, const int sampleType);
|
---|
122 |
|
---|
123 | /** Uses the information gained from the ray for doing adaptive border sampling.
|
---|
124 | This function tries to find the border of the triangle found visible by the
|
---|
125 | current ray. New rays are generated which sample this border.
|
---|
126 |
|
---|
127 | We use the following strategies:
|
---|
128 |
|
---|
129 | a) if new triangle was found: adaptive border sampling
|
---|
130 | b) if triangle was found reverse sampling
|
---|
131 | */
|
---|
132 | bool HandleRay(VssRay *ray);
|
---|
133 |
|
---|
134 | /** The adaptive border sampling step. It aims to find neighbouring
|
---|
135 | triangles of the one hit by the current ray.
|
---|
136 | */
|
---|
137 | int AdaptiveBorderSampling(const VssRay ¤tRay);
|
---|
138 |
|
---|
139 | /** The reverse sampling step. It is started once the cast
|
---|
140 | ray finds a discontinuity, i.e., a closer triangle.
|
---|
141 | Then the process tries to find a ray from the old
|
---|
142 | triangle passing through a gap.
|
---|
143 | */
|
---|
144 | VssRay *ReverseSampling(const VssRay ¤tRay,
|
---|
145 | const Triangle3 &hitTriangle,
|
---|
146 | const VssRay &oldRay);
|
---|
147 |
|
---|
148 | /** Returns true if we sampled a closer triangle than with the previous ray.
|
---|
149 | Does reverse sampling if gap found.
|
---|
150 | */
|
---|
151 | int CheckDiscontinuity(const VssRay ¤tRay,
|
---|
152 | const Triangle3 &hitTriangle,
|
---|
153 | const VssRay &oldRay);
|
---|
154 |
|
---|
155 | /** Adds new samples to the ray queue and classifies them
|
---|
156 | with respect to the previous ray.
|
---|
157 | */
|
---|
158 | void EnqueueRays(VssRayContainer &samples, VssRayContainer &invalidSamples);
|
---|
159 |
|
---|
160 | /** Hepler function for adaptive border sampling. It finds
|
---|
161 | new sample points around a triangle in a eps environment
|
---|
162 | */
|
---|
163 | void EnlargeTriangle(VertexContainer &vertices,
|
---|
164 | const Triangle3 &hitTriangle,
|
---|
165 | const VssRay &ray) const;
|
---|
166 |
|
---|
167 | int SubdivideEdge(const Triangle3 &hitTriangle,
|
---|
168 | const Vector3 &p1,
|
---|
169 | const Vector3 &p2,
|
---|
170 | const VssRay &ray1,
|
---|
171 | const VssRay &ray2,
|
---|
172 | const VssRay &oldRay);
|
---|
173 |
|
---|
174 | void Visualize();
|
---|
175 |
|
---|
176 | void CreateDisplacedVertices(VertexContainer &vertices,
|
---|
177 | const Triangle3 &hitTriangle,
|
---|
178 | const VssRay &ray,
|
---|
179 | const int index) const;
|
---|
180 |
|
---|
181 | Vector3 CalcPredictedHitPoint(const VssRay &newRay,
|
---|
182 | const Triangle3 &hitTriangle,
|
---|
183 | const VssRay &oldRay) const;
|
---|
184 |
|
---|
185 | bool GetPassingPoint(const VssRay ¤tRay,
|
---|
186 | const Triangle3 &occluder,
|
---|
187 | const VssRay &oldRay,
|
---|
188 | Vector3 &newPoint) const;
|
---|
189 |
|
---|
190 | bool NextViewCell();
|
---|
191 |
|
---|
192 | void GlobalComputation();
|
---|
193 |
|
---|
194 | void PerViewCellComputation();
|
---|
195 |
|
---|
196 | void VisualizeViewCells();
|
---|
197 |
|
---|
198 | void VisualizeViewCell(ViewCell *vc);
|
---|
199 | void VisualizeViewCell(const ObjectContainer &objects);
|
---|
200 |
|
---|
201 | /** Exchanges view cell triangle pvs with bvh leaf pvs.
|
---|
202 | */
|
---|
203 | void UpdatePvs(ViewCell *currentViewCell);
|
---|
204 |
|
---|
205 | void ProcessViewCell();
|
---|
206 | void ClearRayQueue();
|
---|
207 |
|
---|
208 | void CompileViewCellsList();
|
---|
209 |
|
---|
210 | void GetObjectPvs(ObjectContainer &trianglePvs) const;
|
---|
211 |
|
---|
212 | bool HasContribution(VssRay &ray);
|
---|
213 |
|
---|
214 | void IntersectWithViewCell();
|
---|
215 |
|
---|
216 | void DeterminePvsObjects(VssRayContainer &rays);
|
---|
217 |
|
---|
218 | //virtual void ComputeRenderError();
|
---|
219 |
|
---|
220 | void StorePvs(const ObjectContainer &objectPvs);
|
---|
221 |
|
---|
222 |
|
---|
223 | //////////////////////
|
---|
224 |
|
---|
225 | //int mSamplesPerPass;
|
---|
226 | //int mTotalSamples;
|
---|
227 | int mInitialSamples;
|
---|
228 |
|
---|
229 | RayQueue mRayQueue;
|
---|
230 | int mSamplingType;
|
---|
231 |
|
---|
232 | //AxisAlignedBox3 mViewSpaceBox;
|
---|
233 | float mEps;
|
---|
234 | float mThreshold;
|
---|
235 | VssRayContainer mVssRays;
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | ///////////
|
---|
240 | // stats
|
---|
241 |
|
---|
242 | ofstream mGvsStatsStream;
|
---|
243 | GvsStatistics mGvsStats;
|
---|
244 |
|
---|
245 | bool mPerViewCell;
|
---|
246 | bool mOnlyRandomSampling;
|
---|
247 |
|
---|
248 | ViewCell *mCurrentViewCell;
|
---|
249 |
|
---|
250 | int mProcessedViewCells;
|
---|
251 |
|
---|
252 | int mMinContribution;
|
---|
253 |
|
---|
254 | ViewCellContainer mViewCells;
|
---|
255 |
|
---|
256 | int mMaxViewCells;
|
---|
257 |
|
---|
258 | ObjectContainer mTrianglePvs;
|
---|
259 |
|
---|
260 | // HACK
|
---|
261 | int mGvsSamplesPerPass;
|
---|
262 |
|
---|
263 | bool mComputeRenderError;
|
---|
264 |
|
---|
265 | bool mEvaluatePixelError;
|
---|
266 | };
|
---|
267 |
|
---|
268 | };
|
---|
269 |
|
---|
270 | #endif
|
---|