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