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