1 | #ifndef _ViewCellsManager_H__
|
---|
2 | #define _ViewCellsManager_H__
|
---|
3 |
|
---|
4 | #include "Ray.h"
|
---|
5 | #include "VssRay.h"
|
---|
6 | #include "Containers.h"
|
---|
7 |
|
---|
8 | class ViewCell;
|
---|
9 | class Intersectable;
|
---|
10 | class RenderSimulator;
|
---|
11 | class Mesh;
|
---|
12 | struct Triangle3;
|
---|
13 | class SimulationStatistics;
|
---|
14 | class BspTree;
|
---|
15 | class KdTree;
|
---|
16 | class VspKdTree;
|
---|
17 | class VspBspTree;
|
---|
18 | class KdNode;
|
---|
19 | class KdLeaf;
|
---|
20 | class VspKdTree;
|
---|
21 | class AxisAlignedBox3;
|
---|
22 | class BspLeaf;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | Manages different higher order operations on the view cells.
|
---|
26 | */
|
---|
27 | class ViewCellsManager
|
---|
28 | {
|
---|
29 |
|
---|
30 | public:
|
---|
31 | struct PvsStatistics {
|
---|
32 | int minPvs;
|
---|
33 | int maxPvs;
|
---|
34 | float avgPvs;
|
---|
35 | int viewcells;
|
---|
36 | };
|
---|
37 |
|
---|
38 | /// view cell container types
|
---|
39 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
40 |
|
---|
41 | /** Constructor taking the maximal number of samples used for construction
|
---|
42 | */
|
---|
43 | ViewCellsManager(const int constructionSamples);
|
---|
44 |
|
---|
45 | ViewCellsManager();
|
---|
46 |
|
---|
47 | virtual ~ViewCellsManager();
|
---|
48 |
|
---|
49 | /** Constructs view cell container with a given number of samples.
|
---|
50 | */
|
---|
51 | virtual int Construct(const ObjectContainer &objects,
|
---|
52 | const VssRayContainer &rays,
|
---|
53 | AxisAlignedBox3 *sceneBbox = NULL) = 0;
|
---|
54 |
|
---|
55 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
56 |
|
---|
57 | @param rays bundle of rays used to find intersections with view cells and
|
---|
58 | adding the contribution
|
---|
59 | @param castRays true if ray should be cast to gain the information, false if rays
|
---|
60 | already hold the view cells intersection information and need not be recast.
|
---|
61 | @param sampleContributions returns the number of sample contributions
|
---|
62 | @param contributingSamples returns the number of contributingSamples
|
---|
63 | */
|
---|
64 | void ComputeSampleContributions(const VssRayContainer &rays);
|
---|
65 |
|
---|
66 |
|
---|
67 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
68 | @param ray finds intersections with view cells and holds the contribution
|
---|
69 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
70 | is already holding the information and need not be recast.
|
---|
71 |
|
---|
72 | @returns number of sample contributions
|
---|
73 | */
|
---|
74 | virtual void ComputeSampleContributions(VssRay &ray
|
---|
75 | );
|
---|
76 |
|
---|
77 | /** Prints out statistics of the view cells.
|
---|
78 | */
|
---|
79 | virtual void PrintStatistics(ostream &s) const = 0;
|
---|
80 |
|
---|
81 | /** Post processes view cells givemŽa number of rays.
|
---|
82 | */
|
---|
83 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
84 | const VssRayContainer &rays) = 0;
|
---|
85 |
|
---|
86 | /** Show visualization of the view cells.
|
---|
87 | */
|
---|
88 | virtual void Visualize(const ObjectContainer &objects,
|
---|
89 | const VssRayContainer &sampleRays) = 0;
|
---|
90 |
|
---|
91 | /** type of the view cell container.
|
---|
92 | */
|
---|
93 | virtual int GetType() const = 0;
|
---|
94 |
|
---|
95 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
96 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
97 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
98 |
|
---|
99 | @param filename file to load
|
---|
100 | @return true on success
|
---|
101 | */
|
---|
102 | bool LoadViewCells(const string filename);
|
---|
103 |
|
---|
104 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
105 | @param the base triangle
|
---|
106 | @param the height of the newly created view cell
|
---|
107 | */
|
---|
108 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
109 |
|
---|
110 | /** Merges two view cells.
|
---|
111 | @note the piercing rays of the front and back will be ordered
|
---|
112 | @returns new view cell based on the merging.
|
---|
113 | */
|
---|
114 | ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
|
---|
115 |
|
---|
116 | /** Generates view cell of type specified by this manager
|
---|
117 | */
|
---|
118 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
119 |
|
---|
120 | /** Adds a new view cell to the list of predefined view cells.
|
---|
121 | */
|
---|
122 | void AddViewCell(ViewCell *viewCell);
|
---|
123 |
|
---|
124 | /** Derive view cells from objects.
|
---|
125 | */
|
---|
126 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
127 | ViewCellContainer &viewCells,
|
---|
128 | const int maxViewCells) const;
|
---|
129 |
|
---|
130 | /** Sets maximal number of samples used for the
|
---|
131 | construction of the view cells.
|
---|
132 | */
|
---|
133 | void SetVisualizationSamples(const int visSamples);
|
---|
134 |
|
---|
135 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
136 | */
|
---|
137 | void SetConstructionSamples(const int constructionSamples);
|
---|
138 |
|
---|
139 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
140 | */
|
---|
141 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
142 |
|
---|
143 | /** See set.
|
---|
144 | */
|
---|
145 | int GetVisualizationSamples() const;
|
---|
146 |
|
---|
147 | /** See set.
|
---|
148 | */
|
---|
149 | int GetConstructionSamples() const;
|
---|
150 |
|
---|
151 | /** See set.
|
---|
152 | */
|
---|
153 | int GetPostProcessSamples() const;
|
---|
154 |
|
---|
155 | /** Returns true if view cells wer already constructed.
|
---|
156 | */
|
---|
157 | virtual bool ViewCellsConstructed() const = 0;
|
---|
158 |
|
---|
159 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
160 | by this line segment */
|
---|
161 |
|
---|
162 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
163 | const Vector3 &termination,
|
---|
164 | ViewCellContainer &viewcells
|
---|
165 | ) = 0;
|
---|
166 |
|
---|
167 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
168 |
|
---|
169 | virtual void
|
---|
170 | PrintPvsStatistics(ostream &s);
|
---|
171 |
|
---|
172 | /** Returns probability that view point lies in one view cell.
|
---|
173 | */
|
---|
174 | virtual float GetProbability(ViewCell *viewCell) const = 0;
|
---|
175 |
|
---|
176 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
177 | */
|
---|
178 | virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0;
|
---|
179 |
|
---|
180 | /** Returns vector of loaded / generated view cells.
|
---|
181 | */
|
---|
182 | ViewCellContainer &GetViewCells();
|
---|
183 |
|
---|
184 | /** Helper function used to split ray set into one used for view cell
|
---|
185 | construction and one cast after construction.
|
---|
186 | */
|
---|
187 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
188 | VssRayContainer &constructionRays,
|
---|
189 | VssRayContainer &savedRays) const;
|
---|
190 |
|
---|
191 | /** Returns total area of view cells.
|
---|
192 | */
|
---|
193 | float GetTotalArea();
|
---|
194 |
|
---|
195 | /** Returns area of one view cell.
|
---|
196 | */
|
---|
197 | float GetArea(ViewCell *viewCell) const;
|
---|
198 |
|
---|
199 | /** Returns volume of view cells.
|
---|
200 | */
|
---|
201 | float GetVolume(ViewCell *viewCell) const;
|
---|
202 |
|
---|
203 | protected:
|
---|
204 |
|
---|
205 | /// the view cell corresponding to unbounded space
|
---|
206 | ViewCell *mUnbounded;
|
---|
207 |
|
---|
208 | /// Simulates rendering
|
---|
209 | RenderSimulator *mRenderSimulator;
|
---|
210 |
|
---|
211 | /// Loaded view cells
|
---|
212 | ViewCellContainer mViewCells;
|
---|
213 |
|
---|
214 | /// maximum number of samples taken for construction of the view cells
|
---|
215 | int mConstructionSamples;
|
---|
216 | int mPostProcessSamples;
|
---|
217 | int mVisualizationSamples;
|
---|
218 |
|
---|
219 | //-- thresholds used for view cells merge
|
---|
220 | int mMinPvsDif;
|
---|
221 | int mMinPvs;
|
---|
222 | int mMaxPvs;
|
---|
223 |
|
---|
224 | float mTotalAreaValid;
|
---|
225 | float mTotalArea;
|
---|
226 | };
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 | /**
|
---|
231 | Manages different higher order operations on the view cells.
|
---|
232 | */
|
---|
233 | class BspViewCellsManager: public ViewCellsManager
|
---|
234 | {
|
---|
235 |
|
---|
236 | public:
|
---|
237 |
|
---|
238 | BspViewCellsManager(BspTree *tree, int constructionSamples);
|
---|
239 |
|
---|
240 | int Construct(const ObjectContainer &objects,
|
---|
241 | const VssRayContainer &rays,
|
---|
242 | AxisAlignedBox3 *sceneBbox);
|
---|
243 |
|
---|
244 |
|
---|
245 | int PostProcess(const ObjectContainer &objects,
|
---|
246 | const VssRayContainer &rays);
|
---|
247 |
|
---|
248 | void Visualize(const ObjectContainer &objects,
|
---|
249 | const VssRayContainer &sampleRays);
|
---|
250 |
|
---|
251 | int GetType() const;
|
---|
252 |
|
---|
253 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
254 |
|
---|
255 | bool ViewCellsConstructed() const;
|
---|
256 |
|
---|
257 | void PrintStatistics(ostream &s) const;
|
---|
258 |
|
---|
259 | int CastLineSegment(const Vector3 &origin,
|
---|
260 | const Vector3 &termination,
|
---|
261 | ViewCellContainer &viewcells);
|
---|
262 |
|
---|
263 | float GetProbability(ViewCell *viewCell) const;
|
---|
264 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
265 |
|
---|
266 | float GetArea(ViewCell *viewCell) const;
|
---|
267 |
|
---|
268 | protected:
|
---|
269 |
|
---|
270 | /** Merges view cells front and back leaf view cell.
|
---|
271 | */
|
---|
272 | bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
|
---|
273 |
|
---|
274 | /** Returns true if front and back leaf should be merged.
|
---|
275 | */
|
---|
276 | bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
|
---|
277 |
|
---|
278 | /// the BSP tree.
|
---|
279 | BspTree *mBspTree;
|
---|
280 |
|
---|
281 |
|
---|
282 | private:
|
---|
283 |
|
---|
284 |
|
---|
285 | /** Exports visualization of the BSP splits.
|
---|
286 | */
|
---|
287 | void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
288 |
|
---|
289 | /** Exports visualization of the BSP PVS.
|
---|
290 | */
|
---|
291 | void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
292 |
|
---|
293 | };
|
---|
294 |
|
---|
295 | /**
|
---|
296 | Manages different higher order operations on the KD type view cells.
|
---|
297 | */
|
---|
298 | class KdViewCellsManager: public ViewCellsManager
|
---|
299 | {
|
---|
300 |
|
---|
301 | public:
|
---|
302 |
|
---|
303 | KdViewCellsManager(KdTree *tree);
|
---|
304 |
|
---|
305 | int Construct(const ObjectContainer &objects,
|
---|
306 | const VssRayContainer &rays,
|
---|
307 | AxisAlignedBox3 *sceneBbox);
|
---|
308 |
|
---|
309 | int CastLineSegment(const Vector3 &origin,
|
---|
310 | const Vector3 &termination,
|
---|
311 | ViewCellContainer &viewcells
|
---|
312 | ) ;
|
---|
313 |
|
---|
314 | int PostProcess(const ObjectContainer &objects,
|
---|
315 | const VssRayContainer &rays);
|
---|
316 |
|
---|
317 | void Visualize(const ObjectContainer &objects,
|
---|
318 | const VssRayContainer &sampleRays);
|
---|
319 |
|
---|
320 | int GetType() const;
|
---|
321 |
|
---|
322 | bool ViewCellsConstructed() const;
|
---|
323 |
|
---|
324 |
|
---|
325 | /** Prints out statistics of this approach.
|
---|
326 | */
|
---|
327 | virtual void PrintStatistics(ostream &s) const;
|
---|
328 |
|
---|
329 | float GetProbability(ViewCell *viewCell) const;
|
---|
330 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
331 |
|
---|
332 | protected:
|
---|
333 |
|
---|
334 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
335 |
|
---|
336 |
|
---|
337 | /// the BSP tree.
|
---|
338 | KdTree *mKdTree;
|
---|
339 |
|
---|
340 | /// depth of the KD tree nodes with represent the view cells
|
---|
341 | int mKdPvsDepth;
|
---|
342 | };
|
---|
343 |
|
---|
344 | /**
|
---|
345 | Manages different higher order operations on the view cells
|
---|
346 | for vsp kd tree view cells.
|
---|
347 | */
|
---|
348 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
349 | {
|
---|
350 |
|
---|
351 | public:
|
---|
352 |
|
---|
353 | VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
|
---|
354 |
|
---|
355 | int Construct(const ObjectContainer &objects,
|
---|
356 | const VssRayContainer &rays,
|
---|
357 | AxisAlignedBox3 *sceneBbox);
|
---|
358 |
|
---|
359 |
|
---|
360 | int PostProcess(const ObjectContainer &objects,
|
---|
361 | const VssRayContainer &rays);
|
---|
362 |
|
---|
363 | void Visualize(const ObjectContainer &objects,
|
---|
364 | const VssRayContainer &sampleRays);
|
---|
365 |
|
---|
366 | int GetType() const;
|
---|
367 |
|
---|
368 | bool ViewCellsConstructed() const;
|
---|
369 |
|
---|
370 | virtual void PrintStatistics(ostream &s) const;
|
---|
371 |
|
---|
372 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
373 |
|
---|
374 |
|
---|
375 | int CastLineSegment(const Vector3 &origin,
|
---|
376 | const Vector3 &termination,
|
---|
377 | ViewCellContainer &viewcells);
|
---|
378 |
|
---|
379 | float GetProbability(ViewCell *viewCell) const;
|
---|
380 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
381 |
|
---|
382 | protected:
|
---|
383 |
|
---|
384 | /// the BSP tree.
|
---|
385 | VspKdTree *mVspKdTree;
|
---|
386 | };
|
---|
387 |
|
---|
388 |
|
---|
389 |
|
---|
390 | /**
|
---|
391 | Manages different higher order operations on the view cells.
|
---|
392 | */
|
---|
393 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
394 | {
|
---|
395 |
|
---|
396 | public:
|
---|
397 |
|
---|
398 | VspBspViewCellsManager(VspBspTree *tree, int constructionSamples);
|
---|
399 |
|
---|
400 | int Construct(const ObjectContainer &objects,
|
---|
401 | const VssRayContainer &rays,
|
---|
402 | AxisAlignedBox3 *sceneBbox);
|
---|
403 |
|
---|
404 |
|
---|
405 | int PostProcess(const ObjectContainer &objects,
|
---|
406 | const VssRayContainer &rays);
|
---|
407 |
|
---|
408 | void Visualize(const ObjectContainer &objects,
|
---|
409 | const VssRayContainer &sampleRays);
|
---|
410 |
|
---|
411 | int GetType() const;
|
---|
412 |
|
---|
413 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
414 |
|
---|
415 | bool ViewCellsConstructed() const;
|
---|
416 |
|
---|
417 | void PrintStatistics(ostream &s) const;
|
---|
418 |
|
---|
419 | int CastLineSegment(const Vector3 &origin,
|
---|
420 | const Vector3 &termination,
|
---|
421 | ViewCellContainer &viewcells);
|
---|
422 |
|
---|
423 | float GetProbability(ViewCell *viewCell) const;
|
---|
424 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
425 |
|
---|
426 |
|
---|
427 | protected:
|
---|
428 |
|
---|
429 | /** Merges view cells front and back leaf view cell.
|
---|
430 | */
|
---|
431 | bool MergeVspBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
|
---|
432 |
|
---|
433 | /** Returns true if front and back leaf should be merged.
|
---|
434 | */
|
---|
435 | bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
|
---|
436 |
|
---|
437 | /// the view space partition BSP tree.
|
---|
438 | VspBspTree *mVspBspTree;
|
---|
439 |
|
---|
440 |
|
---|
441 | private:
|
---|
442 |
|
---|
443 |
|
---|
444 | /** Exports visualization of the BSP splits.
|
---|
445 | */
|
---|
446 | void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
447 |
|
---|
448 | /** Exports visualization of the BSP PVS.
|
---|
449 | */
|
---|
450 | void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
451 |
|
---|
452 | };
|
---|
453 |
|
---|
454 | #endif
|
---|