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