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