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