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