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