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