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 | #include "ViewCellBsp.h"
|
---|
9 |
|
---|
10 | namespace GtpVisibilityPreprocessor {
|
---|
11 |
|
---|
12 | class ViewCell;
|
---|
13 | class Intersectable;
|
---|
14 | class RenderSimulator;
|
---|
15 | class Renderer;
|
---|
16 | class Mesh;
|
---|
17 | struct Triangle3;
|
---|
18 | class SimulationStatistics;
|
---|
19 | class BspTree;
|
---|
20 | class KdTree;
|
---|
21 | class VspKdTree;
|
---|
22 | class VspBspTree;
|
---|
23 | class KdNode;
|
---|
24 | class KdLeaf;
|
---|
25 | class VspKdTree;
|
---|
26 | class AxisAlignedBox3;
|
---|
27 | class BspLeaf;
|
---|
28 | class ViewCellsStatistics;
|
---|
29 | class Exporter;
|
---|
30 | class Beam;
|
---|
31 | class Preprocessor;
|
---|
32 | class ViewCellsTree;
|
---|
33 | class MergeCandidate;
|
---|
34 | class BoundingBoxConverter;
|
---|
35 |
|
---|
36 |
|
---|
37 | struct BspRay;
|
---|
38 |
|
---|
39 |
|
---|
40 | /** Probably Visible Set */
|
---|
41 | class PrVs
|
---|
42 | {
|
---|
43 | public:
|
---|
44 | /// root of view cells tree
|
---|
45 | ViewCell *mViewCell;
|
---|
46 |
|
---|
47 | // input parameter is the render budget for the PrVs
|
---|
48 | float mRenderBudget;
|
---|
49 |
|
---|
50 | /// some characteristic values could be here
|
---|
51 |
|
---|
52 | };
|
---|
53 |
|
---|
54 |
|
---|
55 | /** Manages different higher order operations on the view cells.
|
---|
56 | */
|
---|
57 | class ViewCellsManager
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | struct PvsStatistics
|
---|
61 | {
|
---|
62 | int minPvs;
|
---|
63 | int maxPvs;
|
---|
64 | float avgPvs;
|
---|
65 | int viewcells;
|
---|
66 | };
|
---|
67 |
|
---|
68 | /// view cell container types
|
---|
69 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
70 |
|
---|
71 | /// render cost evaluation type
|
---|
72 | enum {PER_OBJECT, PER_TRIANGLE};
|
---|
73 |
|
---|
74 | /** Default constructor.
|
---|
75 | */
|
---|
76 | ViewCellsManager();
|
---|
77 |
|
---|
78 | virtual ~ViewCellsManager();
|
---|
79 |
|
---|
80 | /** Constructs view cells container taking a preprocessor
|
---|
81 | @returns the output rays (if not null)
|
---|
82 | */
|
---|
83 | int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
|
---|
84 |
|
---|
85 | /** Constructs view cell container with a given number of samples.
|
---|
86 | */
|
---|
87 | virtual int ConstructSubdivision(const ObjectContainer &objects,
|
---|
88 | const VssRayContainer &rays) = 0;
|
---|
89 |
|
---|
90 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
91 |
|
---|
92 | @param rays bundle of rays used to find intersections with view cells and
|
---|
93 | adding the contribution
|
---|
94 | @param addRays true if rays should be added to the PVSs of the viewcells they
|
---|
95 | intersect
|
---|
96 | @param storeViewCells true if view cells should be stored in the ray
|
---|
97 | */
|
---|
98 | float ComputeSampleContributions(const VssRayContainer &rays,
|
---|
99 | const bool addContributions,
|
---|
100 | const bool storeViewCells);
|
---|
101 |
|
---|
102 | /** Add sample contributions to the viewcells they intersect */
|
---|
103 | void AddSampleContributions(const VssRayContainer &rays);
|
---|
104 |
|
---|
105 |
|
---|
106 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
107 | @param ray finds intersections with view cells and holds the contribution
|
---|
108 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
109 | is already holding the information and need not be recast.
|
---|
110 |
|
---|
111 | @returns number of sample contributions
|
---|
112 | */
|
---|
113 | virtual float ComputeSampleContributions(VssRay &ray,
|
---|
114 | const bool addRays,
|
---|
115 | const bool storeViewCells);
|
---|
116 |
|
---|
117 | virtual void AddSampleContributions(VssRay &ray);
|
---|
118 |
|
---|
119 | /** Prints out statistics of the view cells.
|
---|
120 | */
|
---|
121 | virtual void PrintStatistics(ostream &s) const;
|
---|
122 |
|
---|
123 | /** Post processes view cells givemŽa number of rays.
|
---|
124 | */
|
---|
125 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
126 | const VssRayContainer &rays) = 0;
|
---|
127 |
|
---|
128 | /** Show visualization of the view cells.
|
---|
129 | */
|
---|
130 | virtual void Visualize(const ObjectContainer &objects,
|
---|
131 | const VssRayContainer &sampleRays) = 0;
|
---|
132 |
|
---|
133 | /** type of the view cell container.
|
---|
134 | */
|
---|
135 | virtual int GetType() const = 0;
|
---|
136 |
|
---|
137 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
138 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
139 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
140 |
|
---|
141 | @param filename file to load
|
---|
142 | @return true on success
|
---|
143 | */
|
---|
144 | virtual bool LoadViewCellsGeometry(const string filename);
|
---|
145 |
|
---|
146 |
|
---|
147 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
148 | @param the base triangle
|
---|
149 | @param the height of the newly created view cell
|
---|
150 | */
|
---|
151 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
152 |
|
---|
153 | /** Merges two view cells.
|
---|
154 | @note the piercing rays of the front and back will be ordered
|
---|
155 | @returns new view cell based on the merging.
|
---|
156 | */
|
---|
157 | ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
|
---|
158 |
|
---|
159 | /** Merges a container of view cells.
|
---|
160 | @returns new view cell based on the merging.
|
---|
161 | */
|
---|
162 | ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
|
---|
163 |
|
---|
164 | /** Generates view cell of type specified by this manager
|
---|
165 | */
|
---|
166 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
|
---|
167 |
|
---|
168 | /** Adds a new view cell to the list of predefined view cells.
|
---|
169 | */
|
---|
170 | void AddViewCell(ViewCell *viewCell);
|
---|
171 |
|
---|
172 | /** Derive view cells from scene objects. The view ells are created by taking the object
|
---|
173 | geometry into account.
|
---|
174 | */
|
---|
175 | void DeriveViewCellsFromObjects(const ObjectContainer &objects,
|
---|
176 | ViewCellContainer &viewCells,
|
---|
177 | const int maxViewCells) const;
|
---|
178 |
|
---|
179 | /** Sets maximal number of samples used for the
|
---|
180 | construction of the view cells.
|
---|
181 | */
|
---|
182 | void SetVisualizationSamples(const int visSamples);
|
---|
183 |
|
---|
184 | /** Sets maximal number of samples used for the construction of the view cells.
|
---|
185 | */
|
---|
186 | void SetConstructionSamples(const int constructionSamples);
|
---|
187 |
|
---|
188 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
189 | */
|
---|
190 | void SetInitialSamples(const int initialSamples);
|
---|
191 |
|
---|
192 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
193 | */
|
---|
194 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
195 |
|
---|
196 | /** See set.
|
---|
197 | */
|
---|
198 | int GetVisualizationSamples() const;
|
---|
199 |
|
---|
200 | /** See set.
|
---|
201 | */
|
---|
202 | int GetConstructionSamples() const;
|
---|
203 |
|
---|
204 | /** See set.
|
---|
205 | */
|
---|
206 | int GetPostProcessSamples() const;
|
---|
207 |
|
---|
208 | /** Returns true if view cells are already constructed.
|
---|
209 | */
|
---|
210 | virtual bool ViewCellsConstructed() const = 0;
|
---|
211 |
|
---|
212 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
213 | by this line segment
|
---|
214 | */
|
---|
215 |
|
---|
216 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
217 | const Vector3 &termination,
|
---|
218 | ViewCellContainer &viewcells
|
---|
219 | ) = 0;
|
---|
220 |
|
---|
221 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
222 |
|
---|
223 | virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs, const float filterWidth);
|
---|
224 |
|
---|
225 | /** Get a viewcell containing the specified point
|
---|
226 | @param active if the active or elementary view cell should be returned.
|
---|
227 | */
|
---|
228 | virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0;
|
---|
229 |
|
---|
230 | virtual void PrintPvsStatistics(ostream &s);
|
---|
231 |
|
---|
232 | /** Updates pvs of the view cell hierarchy if necessary.
|
---|
233 | */
|
---|
234 | void UpdatePvs();
|
---|
235 |
|
---|
236 | /** Returns probability that view point lies in one view cell.
|
---|
237 | */
|
---|
238 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
239 |
|
---|
240 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
241 | */
|
---|
242 | float GetRendercost(ViewCell *viewCell) const;
|
---|
243 |
|
---|
244 | /** Returns reference to container of loaded / generated view cells.
|
---|
245 | */
|
---|
246 | ViewCellContainer &GetViewCells();
|
---|
247 |
|
---|
248 | /** Helper function used to split ray sets uniformly
|
---|
249 | into one that is currently used and the other that
|
---|
250 | is saved for later processing.
|
---|
251 | @param sourceRays the input ray set
|
---|
252 | @param maxSize the maximal number of rays that will be used
|
---|
253 | @param usedRays returns the used ray set
|
---|
254 | @param savedRays if not null, returns the saved ray set
|
---|
255 | */
|
---|
256 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
257 | const int maxSize,
|
---|
258 | VssRayContainer &usedRays,
|
---|
259 | VssRayContainer *savedRays = NULL) const;
|
---|
260 |
|
---|
261 | /** Returns accumulated area of all view cells.
|
---|
262 | */
|
---|
263 | float GetAccVcArea();
|
---|
264 |
|
---|
265 | /** Returns area of one view cell.
|
---|
266 | */
|
---|
267 | virtual float GetArea(ViewCell *viewCell) const;
|
---|
268 |
|
---|
269 | /** Returns volume of view cell.
|
---|
270 | */
|
---|
271 | virtual float GetVolume(ViewCell *viewCell) const;
|
---|
272 |
|
---|
273 | /** Sets the current renderer mainly for view cells statistics.
|
---|
274 | */
|
---|
275 | void SetRenderer(Renderer *renderer);
|
---|
276 |
|
---|
277 | /** Computes a (random) view point in the valid view space.
|
---|
278 | @returns true if valid view point was found
|
---|
279 | */
|
---|
280 | virtual bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
281 |
|
---|
282 | /** Returns true if this view point is in the valid view space.
|
---|
283 | */
|
---|
284 | virtual bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
285 |
|
---|
286 | /** Sets a view space boundary.
|
---|
287 | */
|
---|
288 | void SetViewSpaceBox(const AxisAlignedBox3 &box);
|
---|
289 |
|
---|
290 | AxisAlignedBox3 GetViewSpaceBox() const;
|
---|
291 |
|
---|
292 | /** Creates mesh for this view cell.
|
---|
293 | */
|
---|
294 | virtual void CreateMesh(ViewCell *vc) = NULL;
|
---|
295 |
|
---|
296 | /** Writes view cells to disc.
|
---|
297 | */
|
---|
298 | virtual bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
|
---|
299 |
|
---|
300 | /** Casts beam to collect view cells.
|
---|
301 | */
|
---|
302 | virtual int CastBeam(Beam &beam);
|
---|
303 |
|
---|
304 | /** Checks if view cell is considered as valid.
|
---|
305 | */
|
---|
306 | virtual bool CheckValidity(ViewCell *vc,
|
---|
307 | int minPvsSize,
|
---|
308 | int maxPvsSize) const;
|
---|
309 |
|
---|
310 |
|
---|
311 | /** Sets validity of view cell
|
---|
312 | */
|
---|
313 | virtual void SetValidity(ViewCell *vc,
|
---|
314 | int minPvsSize,
|
---|
315 | int maxPvsSize) const;
|
---|
316 |
|
---|
317 | /** sets validy of all viewcells
|
---|
318 | */
|
---|
319 | virtual void SetValidity(int minPvsSize,
|
---|
320 | int maxPvsSize) const;
|
---|
321 |
|
---|
322 |
|
---|
323 | /** set valid viewcells in the range of pvs. sorts the viewcells
|
---|
324 | according to the pvs and then pickups those in the ranges
|
---|
325 | */
|
---|
326 | void SetValidityPercentage(const float minValid, const float maxValid);
|
---|
327 |
|
---|
328 | int CountValidViewcells() const;
|
---|
329 |
|
---|
330 | /** Returns maximal allowed pvs size.
|
---|
331 | */
|
---|
332 | int GetMaxPvsSize() const;
|
---|
333 |
|
---|
334 | /** Returns maximal allowed pvs size.
|
---|
335 | */
|
---|
336 | int GetMinPvsSize() const;
|
---|
337 |
|
---|
338 | /** Returns maximal ratio. i.e., currentPVs / maxPvs,
|
---|
339 | where pvs is still considered valid.
|
---|
340 | */
|
---|
341 | float GetMaxPvsRatio() const;
|
---|
342 |
|
---|
343 | /** Exports view cell geometry.
|
---|
344 | */
|
---|
345 | virtual void ExportViewCellGeometry(Exporter *exporter,
|
---|
346 | ViewCell *vc,
|
---|
347 | const Plane3 *clipPlane = NULL) const = 0;
|
---|
348 |
|
---|
349 | /** Brings the view cells into their final state, computes meshes and volume.
|
---|
350 | */
|
---|
351 | virtual void FinalizeViewCells(const bool createMesh);
|
---|
352 |
|
---|
353 | /** Evaluates statistics values on view cells.
|
---|
354 | */
|
---|
355 | void EvaluateRenderStatistics(float &totalRenderCost,
|
---|
356 | float &expectedRenderCost,
|
---|
357 | float &deviation,
|
---|
358 | float &variance,
|
---|
359 | int &totalPvs,
|
---|
360 | float &avgRenderCost);
|
---|
361 |
|
---|
362 |
|
---|
363 | /** Returns hierarchy of the view cells.
|
---|
364 | */
|
---|
365 | ViewCellsTree *GetViewCellsTree();
|
---|
366 |
|
---|
367 | virtual void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
368 | vector<MergeCandidate> &candidates) = 0;
|
---|
369 |
|
---|
370 | void CollectViewCells(const int n);
|
---|
371 |
|
---|
372 | /** Returns true if this (logical) view cell is equal to a spatial node.
|
---|
373 | */
|
---|
374 | virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
375 |
|
---|
376 | /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
|
---|
377 | */
|
---|
378 | void SetViewCellsActive();
|
---|
379 |
|
---|
380 | /** Evaluates worth of current view cell hierarchy.
|
---|
381 | */
|
---|
382 | void EvalViewCellPartition(Preprocessor *preprocessor);
|
---|
383 |
|
---|
384 | /** Sets maximal size of a view cell filter.
|
---|
385 | */
|
---|
386 | void SetMaxFilterSize(const int size);
|
---|
387 |
|
---|
388 | /** Returns maximal filter size.
|
---|
389 | */
|
---|
390 | int GetMaxFilterSize() const;
|
---|
391 |
|
---|
392 | /** Deletes interior nodes from the tree which have negative merge cost set (local merge).
|
---|
393 | */
|
---|
394 | void DeleteLocalMergeTree(ViewCell *vc) const;
|
---|
395 |
|
---|
396 | /** Evaluautes histogram for a given number of view cells.
|
---|
397 | */
|
---|
398 | void EvalViewCellHistogram(const string filename, const int nViewCells);
|
---|
399 |
|
---|
400 | /** Evaluautes histogram for a given number of view cells.
|
---|
401 | */
|
---|
402 | void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
|
---|
403 |
|
---|
404 | /** Evaluates the render cost of a view cell.
|
---|
405 | */
|
---|
406 | float EvalRenderCost(Intersectable *obj) const;
|
---|
407 |
|
---|
408 | /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves
|
---|
409 | of the hierarchy.
|
---|
410 | */
|
---|
411 | void SetScalarPvsSize(ViewCell *vc, const int pvsSize) const;
|
---|
412 |
|
---|
413 |
|
---|
414 | /** Returns bounding box of a view cell.
|
---|
415 | */
|
---|
416 | AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
|
---|
417 |
|
---|
418 | /** Exports bounding boxes of objects to file.
|
---|
419 | */
|
---|
420 | bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
|
---|
421 |
|
---|
422 | /** Load the bounding boxes into the container.
|
---|
423 | */
|
---|
424 | bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
|
---|
425 |
|
---|
426 | /** Returns true if pvs should be exported together with the view cells.
|
---|
427 | */
|
---|
428 | bool GetExportPvs() const;
|
---|
429 |
|
---|
430 | /** Loads view cells from file. The view cells manager is created with
|
---|
431 | respect to the loaded view cells.
|
---|
432 |
|
---|
433 | @param filename the filename of the view cells
|
---|
434 | @param objects the scene objects
|
---|
435 | @param finalizeViewCells if the view cells should be post processed, i.e.
|
---|
436 | a mesh is created representing the geometry
|
---|
437 | @param bconverter a conversion routine working with the similarities of bounding
|
---|
438 | boxes: if there is a certain similarity of overlap between bounding boxes, two tested
|
---|
439 | candidate objects are considered to be the same objects
|
---|
440 | @returns the view cells manager if loading was successful, false otherwise
|
---|
441 | */
|
---|
442 | static ViewCellsManager *LoadViewCells(const string &filename,
|
---|
443 | ObjectContainer *objects,
|
---|
444 | const bool finalizeViewCells,
|
---|
445 | BoundingBoxConverter *bconverter = NULL);
|
---|
446 |
|
---|
447 |
|
---|
448 | ////////////////////////////////////////////////////////7
|
---|
449 | // visiblity filter options
|
---|
450 | // TODO: write own visibiltiy filter class
|
---|
451 | void ApplyFilter(KdTree *kdTree,
|
---|
452 | const float viewSpaceFilterSize,
|
---|
453 | const float spatialFilterSize);
|
---|
454 |
|
---|
455 | void ApplySpatialFilter(KdTree *kdTree,
|
---|
456 | const float spatialFilterSize,
|
---|
457 | ObjectPvs &pvs);
|
---|
458 |
|
---|
459 | void ApplyFilter(ViewCell *viewCell,
|
---|
460 | KdTree *kdTree,
|
---|
461 | const float viewSpaceFilterSize,
|
---|
462 | const float spatialFilterSize,
|
---|
463 | ObjectPvs &pvs);
|
---|
464 |
|
---|
465 | float GetFilterWidth();
|
---|
466 |
|
---|
467 | float GetAbsFilterWidth();
|
---|
468 |
|
---|
469 |
|
---|
470 | /** Returns the bounding box of filter width.
|
---|
471 | */
|
---|
472 | AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
|
---|
473 |
|
---|
474 |
|
---|
475 | protected:
|
---|
476 | /** Exports bounding boxes as xml stream
|
---|
477 | */
|
---|
478 | //bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;
|
---|
479 |
|
---|
480 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
481 | @returns number of view cells found
|
---|
482 | */
|
---|
483 | virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
484 | ViewCellContainer &viewCells) const;
|
---|
485 |
|
---|
486 | /** Tests the visibility filter functionality.
|
---|
487 | */
|
---|
488 | virtual void TestFilter(const ObjectContainer &objects) {};
|
---|
489 |
|
---|
490 | /** If the view cells tree was already constructed or not.
|
---|
491 | */
|
---|
492 | bool ViewCellsTreeConstructed() const;
|
---|
493 |
|
---|
494 | int CastPassSamples(const int samplesPerPass,
|
---|
495 | const int sampleType,
|
---|
496 | VssRayContainer &vssRays) const;
|
---|
497 |
|
---|
498 | /** Parse the options from the environment file.
|
---|
499 | */
|
---|
500 | void ParseEnvironment();
|
---|
501 |
|
---|
502 | /** Creates unique view cell ids.
|
---|
503 | */
|
---|
504 | void CreateUniqueViewCellIds();
|
---|
505 |
|
---|
506 | /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
|
---|
507 | */
|
---|
508 | virtual void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
509 |
|
---|
510 | /** Recollects view cells and resets statistics.
|
---|
511 | */
|
---|
512 | void ResetViewCells();
|
---|
513 |
|
---|
514 | /** Collects the view cells in the view cell container.
|
---|
515 | */
|
---|
516 | virtual void CollectViewCells() = 0;
|
---|
517 |
|
---|
518 | /** Evaluates view cells statistics and stores it in
|
---|
519 | mViewCellsStatistics.
|
---|
520 | */
|
---|
521 | void EvaluateViewCellsStats();
|
---|
522 |
|
---|
523 | //-- helper functions for view cell visualization
|
---|
524 |
|
---|
525 | /** Exports the view cell partition.
|
---|
526 | */
|
---|
527 | void ExportViewCellsForViz(Exporter *exporter) const;
|
---|
528 |
|
---|
529 | /** Sets exporter color.
|
---|
530 | */
|
---|
531 | virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
|
---|
532 |
|
---|
533 | /** Returns volume of the view space.
|
---|
534 | */
|
---|
535 | virtual float GetViewSpaceVolume();
|
---|
536 |
|
---|
537 | /** Creates meshes from the view cells.
|
---|
538 | */
|
---|
539 | void CreateViewCellMeshes();
|
---|
540 |
|
---|
541 | /** Takes different measures to prepares the view cells after loading them from disc.
|
---|
542 | */
|
---|
543 | virtual void PrepareLoadedViewCells() {};
|
---|
544 |
|
---|
545 | /** Constructs local view cell merge hierarchy.
|
---|
546 | */
|
---|
547 | ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
|
---|
548 | const ViewCellContainer &viewCells);
|
---|
549 |
|
---|
550 | /** Constructs local view cell merge hierarchy based solely on similarity with the
|
---|
551 | current viewcell
|
---|
552 | */
|
---|
553 | ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
|
---|
554 | const ViewCellContainer &viewCells);
|
---|
555 |
|
---|
556 |
|
---|
557 | /** Creates clip plane for visualization.
|
---|
558 | */
|
---|
559 | void CreateClipPlane();
|
---|
560 |
|
---|
561 | /** Updates pvs of all view cells for statistical evaluation after some more sampling
|
---|
562 | */
|
---|
563 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
|
---|
564 |
|
---|
565 |
|
---|
566 | ////////////////////////////////////////////////
|
---|
567 |
|
---|
568 | /// if bounding boxes should also be exported
|
---|
569 | bool mExportBboxesForPvs;
|
---|
570 |
|
---|
571 | //Environment *environment;
|
---|
572 | Plane3 mClipPlane;
|
---|
573 |
|
---|
574 | bool mUseClipPlaneForViz;
|
---|
575 |
|
---|
576 |
|
---|
577 | /// Renders the view cells.
|
---|
578 | Renderer *mRenderer;
|
---|
579 |
|
---|
580 | /// Loaded view cells
|
---|
581 | ViewCellContainer mViewCells;
|
---|
582 | /// the corresponding view cell tree holding the logical description of view cells
|
---|
583 | ViewCellsTree *mViewCellsTree;
|
---|
584 | /// if empty view cells should be pruned (i.e., invalidated) from this point on
|
---|
585 | bool mPruneEmptyViewCells;
|
---|
586 |
|
---|
587 | /// if the pvss in the view cell leaves and the interiors are up to date
|
---|
588 | bool mViewCellPvsIsUpdated;
|
---|
589 |
|
---|
590 | /// maximum number of samples taken for construction of the view cells
|
---|
591 | int mConstructionSamples;
|
---|
592 | int mSamplesPerPass;
|
---|
593 | int mInitialSamples;
|
---|
594 | int mPostProcessSamples;
|
---|
595 | int mVisualizationSamples;
|
---|
596 |
|
---|
597 | float mTotalAreaValid;
|
---|
598 | float mTotalArea;
|
---|
599 |
|
---|
600 | int mMaxPvsSize;
|
---|
601 | int mMinPvsSize;
|
---|
602 | float mMaxPvsRatio;
|
---|
603 |
|
---|
604 | int mSamplingType;
|
---|
605 | int mEvaluationSamplingType;
|
---|
606 | int mNumActiveViewCells;
|
---|
607 | bool mCompressViewCells;
|
---|
608 |
|
---|
609 | /// holds the current view cell statistics
|
---|
610 | ViewCellsStatistics mCurrentViewCellsStats;
|
---|
611 | /// the scene bounding box
|
---|
612 | AxisAlignedBox3 mViewSpaceBox;
|
---|
613 |
|
---|
614 | /// if view cells should be exported
|
---|
615 | bool mExportViewCells;
|
---|
616 |
|
---|
617 | // if only valid view cells should be considered for processing
|
---|
618 | bool mOnlyValidViewCells;
|
---|
619 |
|
---|
620 | /// if rays should be used to collect merge candidates
|
---|
621 | bool mUseRaysForMerge;
|
---|
622 | /// if there should be an additional merge step after the subdivision
|
---|
623 | bool mMergeViewCells;
|
---|
624 |
|
---|
625 | /// the width of the box filter
|
---|
626 | float mFilterWidth;
|
---|
627 | int mMaxFilterSize;
|
---|
628 |
|
---|
629 | //-- visualization options
|
---|
630 |
|
---|
631 | /// color code for view cells visualization
|
---|
632 | int mColorCode;
|
---|
633 | bool mExportGeometry;
|
---|
634 | bool mExportRays;
|
---|
635 |
|
---|
636 | bool mViewCellsFinished;
|
---|
637 |
|
---|
638 | bool mEvaluateViewCells;
|
---|
639 |
|
---|
640 | bool mShowVisualization;
|
---|
641 |
|
---|
642 | // HACK in order to detect empty view cells
|
---|
643 | void CollectEmptyViewCells();
|
---|
644 | void TestEmptyViewCells(const ObjectContainer &obj);
|
---|
645 |
|
---|
646 | ViewCellContainer mEmptyViewCells;
|
---|
647 |
|
---|
648 | int mRenderCostEvaluationType;
|
---|
649 |
|
---|
650 | /// if pvs should be exported with view cells
|
---|
651 | bool mExportPvs;
|
---|
652 | };
|
---|
653 |
|
---|
654 |
|
---|
655 | /**
|
---|
656 | Manages different higher order operations on the view cells.
|
---|
657 | */
|
---|
658 | class BspViewCellsManager: public ViewCellsManager
|
---|
659 | {
|
---|
660 |
|
---|
661 | public:
|
---|
662 | /** Constructor taking the bsp tree and the number of samples
|
---|
663 | used to construct the bsp tree.
|
---|
664 | */
|
---|
665 | BspViewCellsManager(BspTree *tree);
|
---|
666 |
|
---|
667 | ~BspViewCellsManager();
|
---|
668 |
|
---|
669 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
670 | const VssRayContainer &rays);
|
---|
671 |
|
---|
672 | int PostProcess(const ObjectContainer &objects,
|
---|
673 | const VssRayContainer &rays);
|
---|
674 |
|
---|
675 | void Visualize(const ObjectContainer &objects,
|
---|
676 | const VssRayContainer &sampleRays);
|
---|
677 |
|
---|
678 | int GetType() const;
|
---|
679 |
|
---|
680 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
681 |
|
---|
682 | bool ViewCellsConstructed() const;
|
---|
683 |
|
---|
684 | //void PrintStatistics(ostream &s) const;
|
---|
685 |
|
---|
686 | int CastLineSegment(const Vector3 &origin,
|
---|
687 | const Vector3 &termination,
|
---|
688 | ViewCellContainer &viewcells);
|
---|
689 |
|
---|
690 | float GetProbability(ViewCell *viewCell);
|
---|
691 |
|
---|
692 |
|
---|
693 | /** Get a viewcell containing the specified point
|
---|
694 | */
|
---|
695 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
|
---|
696 |
|
---|
697 | void CreateMesh(ViewCell *vc);
|
---|
698 |
|
---|
699 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
700 | ViewCell *vc,
|
---|
701 | const Plane3 *clipPlane = NULL) const;
|
---|
702 |
|
---|
703 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
704 | vector<MergeCandidate> &candidates);
|
---|
705 |
|
---|
706 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
707 |
|
---|
708 | bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
|
---|
709 |
|
---|
710 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
711 | */
|
---|
712 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
713 |
|
---|
714 | /** Updates the pvs in the view cells tree.
|
---|
715 | */
|
---|
716 | void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
|
---|
717 |
|
---|
718 |
|
---|
719 | protected:
|
---|
720 |
|
---|
721 |
|
---|
722 | void CollectViewCells();
|
---|
723 |
|
---|
724 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
725 |
|
---|
726 | /// the BSP tree.
|
---|
727 | BspTree *mBspTree;
|
---|
728 |
|
---|
729 | vector<BspRay *> mBspRays;
|
---|
730 |
|
---|
731 | private:
|
---|
732 |
|
---|
733 | /** Exports visualization of the BSP splits.
|
---|
734 | */
|
---|
735 | void ExportSplits(const ObjectContainer &objects);
|
---|
736 |
|
---|
737 | /** Exports visualization of the BSP PVS.
|
---|
738 | */
|
---|
739 | void ExportBspPvs(const ObjectContainer &objects);
|
---|
740 |
|
---|
741 | /** test if subdivision is valid in terms of volume / area.
|
---|
742 | */
|
---|
743 | void TestSubdivision();
|
---|
744 | };
|
---|
745 |
|
---|
746 | /**
|
---|
747 | Manages different higher order operations on the KD type view cells.
|
---|
748 | */
|
---|
749 | class KdViewCellsManager: public ViewCellsManager
|
---|
750 | {
|
---|
751 |
|
---|
752 | public:
|
---|
753 |
|
---|
754 | KdViewCellsManager(KdTree *tree);
|
---|
755 |
|
---|
756 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
757 | const VssRayContainer &rays);
|
---|
758 |
|
---|
759 | int CastLineSegment(const Vector3 &origin,
|
---|
760 | const Vector3 &termination,
|
---|
761 | ViewCellContainer &viewcells);
|
---|
762 |
|
---|
763 | int PostProcess(const ObjectContainer &objects,
|
---|
764 | const VssRayContainer &rays);
|
---|
765 |
|
---|
766 | void Visualize(const ObjectContainer &objects,
|
---|
767 | const VssRayContainer &sampleRays);
|
---|
768 |
|
---|
769 | int GetType() const;
|
---|
770 |
|
---|
771 | bool ViewCellsConstructed() const;
|
---|
772 |
|
---|
773 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
774 |
|
---|
775 | /** Prints out statistics of this approach.
|
---|
776 | */
|
---|
777 | // virtual void PrintStatistics(ostream &s) const;
|
---|
778 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
|
---|
779 |
|
---|
780 | float GetProbability(ViewCell *viewCell);
|
---|
781 |
|
---|
782 |
|
---|
783 | void CreateMesh(ViewCell *vc);
|
---|
784 |
|
---|
785 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
786 | ViewCell *vc,
|
---|
787 | const Plane3 *clipPlane = NULL) const;
|
---|
788 |
|
---|
789 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
790 | vector<MergeCandidate> &candidates);
|
---|
791 |
|
---|
792 |
|
---|
793 | protected:
|
---|
794 |
|
---|
795 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
|
---|
796 | /** Collects view cells from a hierarchy.
|
---|
797 | */
|
---|
798 | void CollectViewCells();
|
---|
799 |
|
---|
800 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
801 |
|
---|
802 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
803 |
|
---|
804 |
|
---|
805 | /// the BSP tree.
|
---|
806 | KdTree *mKdTree;
|
---|
807 |
|
---|
808 | /// depth of the KD tree nodes with represent the view cells
|
---|
809 | int mKdPvsDepth;
|
---|
810 |
|
---|
811 |
|
---|
812 | };
|
---|
813 |
|
---|
814 | /**
|
---|
815 | Manages different higher order operations on the view cells
|
---|
816 | for vsp kd tree view cells.
|
---|
817 | */
|
---|
818 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
819 | {
|
---|
820 |
|
---|
821 | public:
|
---|
822 |
|
---|
823 | VspKdViewCellsManager(VspKdTree *vspKdTree);
|
---|
824 |
|
---|
825 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
826 | const VssRayContainer &rays);
|
---|
827 |
|
---|
828 |
|
---|
829 | int PostProcess(const ObjectContainer &objects,
|
---|
830 | const VssRayContainer &rays);
|
---|
831 |
|
---|
832 | void Visualize(const ObjectContainer &objects,
|
---|
833 | const VssRayContainer &sampleRays);
|
---|
834 |
|
---|
835 | int GetType() const;
|
---|
836 |
|
---|
837 | bool ViewCellsConstructed() const;
|
---|
838 |
|
---|
839 | //virtual void PrintStatistics(ostream &s) const;
|
---|
840 |
|
---|
841 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
842 |
|
---|
843 |
|
---|
844 | int CastLineSegment(const Vector3 &origin,
|
---|
845 | const Vector3 &termination,
|
---|
846 | ViewCellContainer &viewcells);
|
---|
847 |
|
---|
848 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
|
---|
849 |
|
---|
850 | float GetProbability(ViewCell *viewCell);
|
---|
851 |
|
---|
852 |
|
---|
853 | void CreateMesh(ViewCell *vc);
|
---|
854 |
|
---|
855 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
856 | ViewCell *vc,
|
---|
857 | const Plane3 *clipPlane = NULL) const;
|
---|
858 |
|
---|
859 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
860 |
|
---|
861 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
|
---|
862 |
|
---|
863 |
|
---|
864 | protected:
|
---|
865 |
|
---|
866 | void ExportLeaves(const ObjectContainer &objects,
|
---|
867 | const VssRayContainer &sampleRays);
|
---|
868 |
|
---|
869 | void CollectViewCells();
|
---|
870 |
|
---|
871 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
872 |
|
---|
873 |
|
---|
874 |
|
---|
875 | /// the BSP tree.
|
---|
876 | VspKdTree *mVspKdTree;
|
---|
877 | };
|
---|
878 |
|
---|
879 |
|
---|
880 |
|
---|
881 | /**
|
---|
882 | Manages different higher order operations on the view cells.
|
---|
883 | */
|
---|
884 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
885 | {
|
---|
886 |
|
---|
887 | public:
|
---|
888 |
|
---|
889 | VspBspViewCellsManager(VspBspTree *tree);
|
---|
890 | ~VspBspViewCellsManager();
|
---|
891 |
|
---|
892 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
893 | const VssRayContainer &rays);
|
---|
894 |
|
---|
895 | int PostProcess(const ObjectContainer &objects,
|
---|
896 | const VssRayContainer &rays);
|
---|
897 |
|
---|
898 | void Visualize(const ObjectContainer &objects,
|
---|
899 | const VssRayContainer &sampleRays);
|
---|
900 |
|
---|
901 | int GetType() const;
|
---|
902 |
|
---|
903 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
904 |
|
---|
905 | bool ViewCellsConstructed() const;
|
---|
906 |
|
---|
907 |
|
---|
908 | int CastLineSegment(const Vector3 &origin,
|
---|
909 | const Vector3 &termination,
|
---|
910 | ViewCellContainer &viewcells);
|
---|
911 |
|
---|
912 | float GetProbability(ViewCell *viewCell);
|
---|
913 |
|
---|
914 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
|
---|
915 |
|
---|
916 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
917 |
|
---|
918 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
919 |
|
---|
920 | void CreateMesh(ViewCell *vc);
|
---|
921 |
|
---|
922 | bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
|
---|
923 |
|
---|
924 | int CastBeam(Beam &beam);
|
---|
925 |
|
---|
926 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
927 | ViewCell *vc,
|
---|
928 | const Plane3 *clipPlane = NULL) const;
|
---|
929 |
|
---|
930 | //float GetVolume(ViewCell *viewCell) const;
|
---|
931 |
|
---|
932 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
933 |
|
---|
934 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
935 |
|
---|
936 | /** Returns true if this view cell is equivavalent to a spatial node.
|
---|
937 | */
|
---|
938 | bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
939 |
|
---|
940 |
|
---|
941 | protected:
|
---|
942 |
|
---|
943 | int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
|
---|
944 |
|
---|
945 | /** Returns node of the spatial hierarchy corresponding to the view cell
|
---|
946 | if such a node exists.
|
---|
947 | */
|
---|
948 | BspNode *GetSpatialNode(ViewCell *viewCell) const;
|
---|
949 |
|
---|
950 | /** Merges the view cells.
|
---|
951 | */
|
---|
952 | void MergeViewCells(const VssRayContainer &rays,
|
---|
953 | const ObjectContainer &objects);
|
---|
954 |
|
---|
955 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
956 |
|
---|
957 | void CollectViewCells();
|
---|
958 |
|
---|
959 | /** Returns maximal depth difference of view cell
|
---|
960 | leaves in tree.
|
---|
961 | */
|
---|
962 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
963 |
|
---|
964 |
|
---|
965 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
966 |
|
---|
967 | /** Prepare view cells for use after loading them from disc.
|
---|
968 | */
|
---|
969 | void PrepareLoadedViewCells();
|
---|
970 |
|
---|
971 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
972 | */
|
---|
973 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
974 |
|
---|
975 | void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
|
---|
976 |
|
---|
977 |
|
---|
978 | /// HACK for testing visibility filter functionality
|
---|
979 | void TestFilter(const ObjectContainer &objects);
|
---|
980 |
|
---|
981 |
|
---|
982 | /** Visualization of the pvs difference to exact visubility using
|
---|
983 | from point queries.
|
---|
984 | */
|
---|
985 | void VisualizeWithFromPointQueries();
|
---|
986 |
|
---|
987 | /** Evaluate from point queries for the current scene.
|
---|
988 | */
|
---|
989 | void EvalFromPointQueries();
|
---|
990 |
|
---|
991 |
|
---|
992 | /// the view space partition BSP tree.
|
---|
993 | VspBspTree *mVspBspTree;
|
---|
994 |
|
---|
995 |
|
---|
996 | private:
|
---|
997 |
|
---|
998 | /** Exports visualization of the BSP splits.
|
---|
999 | */
|
---|
1000 | void ExportSplits(const ObjectContainer &objects,
|
---|
1001 | const VssRayContainer &rays);
|
---|
1002 |
|
---|
1003 | /** Exports visualization of the BSP PVS.
|
---|
1004 | */
|
---|
1005 | void ExportBspPvs(const ObjectContainer &objects,
|
---|
1006 | const VssRayContainer &rays);
|
---|
1007 |
|
---|
1008 | /** test if subdivision is valid in terms of volume / area.
|
---|
1009 | */
|
---|
1010 | void TestSubdivision();
|
---|
1011 | };
|
---|
1012 |
|
---|
1013 |
|
---|
1014 | /*class ViewCellsManagerFactory
|
---|
1015 | {
|
---|
1016 | public:
|
---|
1017 | ViewCellsManager *Create(const string mName);
|
---|
1018 | };*/
|
---|
1019 |
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | #endif
|
---|