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