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