1 | #ifndef _OspTree_H__
|
---|
2 | #define _OspTree_H__
|
---|
3 |
|
---|
4 | #include <stack>
|
---|
5 |
|
---|
6 | #include "Mesh.h"
|
---|
7 | #include "Containers.h"
|
---|
8 | #include "Statistics.h"
|
---|
9 | #include "VssRay.h"
|
---|
10 | #include "RayInfo.h"
|
---|
11 | #include "gzstream.h"
|
---|
12 | #include "SubdivisionCandidate.h"
|
---|
13 | #include "IntersectableWrapper.h"
|
---|
14 | #include "KdTree.h"
|
---|
15 | #include "HierarchyManager.h"
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 | namespace GtpVisibilityPreprocessor {
|
---|
20 |
|
---|
21 | class ViewCellLeaf;
|
---|
22 | class Plane3;
|
---|
23 | class AxisAlignedBox3;
|
---|
24 | class Ray;
|
---|
25 | class ViewCellsStatistics;
|
---|
26 | class ViewCellsManager;
|
---|
27 | class MergeCandidate;
|
---|
28 | class Beam;
|
---|
29 | class ViewCellsTree;
|
---|
30 | class Environment;
|
---|
31 | class VspInterior;
|
---|
32 | class VspLeaf;
|
---|
33 | class VspNode;
|
---|
34 | class KdNode;
|
---|
35 | class KdInterior;
|
---|
36 | class KdLeaf;
|
---|
37 | class OspTree;
|
---|
38 | class KdIntersectable;
|
---|
39 | class KdTree;
|
---|
40 | class VspTree;
|
---|
41 | class KdTreeStatistics;
|
---|
42 | class SubdivisionCandidate;
|
---|
43 | class HierarchyManager;
|
---|
44 | class KdNode;
|
---|
45 |
|
---|
46 |
|
---|
47 | /** View space partition statistics.
|
---|
48 | */
|
---|
49 | class OspTreeStatistics: public StatisticsBase
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | // total number of nodes
|
---|
53 | int nodes;
|
---|
54 | // number of splits
|
---|
55 | int splits[3];
|
---|
56 |
|
---|
57 | // maximal reached depth
|
---|
58 | int maxDepth;
|
---|
59 | // minimal depth
|
---|
60 | int minDepth;
|
---|
61 |
|
---|
62 | // max depth nodes
|
---|
63 | int maxDepthNodes;
|
---|
64 | // minimum depth nodes
|
---|
65 | int minDepthNodes;
|
---|
66 | // max depth nodes
|
---|
67 | int minPvsNodes;
|
---|
68 | // minimum area nodes
|
---|
69 | int minProbabilityNodes;
|
---|
70 | /// nodes termination because of max cost ratio;
|
---|
71 | int maxCostNodes;
|
---|
72 | // max number of objects per node
|
---|
73 | int maxObjectRefs;
|
---|
74 | int objectRefs;
|
---|
75 | /// samples contributing to pvs
|
---|
76 | int contributingSamples;
|
---|
77 | /// sample contributions to pvs
|
---|
78 | int sampleContributions;
|
---|
79 | /// largest pvs
|
---|
80 | int maxPvs;
|
---|
81 | /// number of invalid leaves
|
---|
82 | int invalidLeaves;
|
---|
83 | /// accumulated number of rays refs
|
---|
84 | int accumRays;
|
---|
85 | /// overall potentially visible objects
|
---|
86 | int pvs;
|
---|
87 | // accumulated depth (used to compute average)
|
---|
88 | int accumDepth;
|
---|
89 | // global cost ratio violations
|
---|
90 | int mGlobalCostMisses;
|
---|
91 |
|
---|
92 |
|
---|
93 | // Constructor
|
---|
94 | OspTreeStatistics()
|
---|
95 | {
|
---|
96 | Reset();
|
---|
97 | }
|
---|
98 |
|
---|
99 | int Nodes() const {return nodes;}
|
---|
100 | int Interior() const { return nodes / 2; }
|
---|
101 | int Leaves() const { return (nodes / 2) + 1; }
|
---|
102 |
|
---|
103 | // TODO: computation wrong
|
---|
104 | double AvgDepth() const { return accumDepth / (double)Leaves();};
|
---|
105 |
|
---|
106 |
|
---|
107 | void Reset()
|
---|
108 | {
|
---|
109 | nodes = 0;
|
---|
110 | for (int i = 0; i < 3; ++ i)
|
---|
111 | splits[i] = 0;
|
---|
112 |
|
---|
113 | maxDepth = 0;
|
---|
114 | minDepth = 99999;
|
---|
115 | accumDepth = 0;
|
---|
116 | pvs = 0;
|
---|
117 | maxDepthNodes = 0;
|
---|
118 | minPvsNodes = 0;
|
---|
119 | minProbabilityNodes = 0;
|
---|
120 | maxCostNodes = 0;
|
---|
121 | contributingSamples = 0;
|
---|
122 | sampleContributions = 0;
|
---|
123 | maxPvs = 0;
|
---|
124 | invalidLeaves = 0;
|
---|
125 | objectRefs = 0;
|
---|
126 | maxObjectRefs = 0;
|
---|
127 | mGlobalCostMisses = 0;
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | void Print(std::ostream &app) const;
|
---|
132 |
|
---|
133 | friend std::ostream &operator<<(std::ostream &s, const OspTreeStatistics &stat)
|
---|
134 | {
|
---|
135 | stat.Print(s);
|
---|
136 | return s;
|
---|
137 | }
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 | /** Object Space Partitioning Kd tree.
|
---|
142 | */
|
---|
143 | class OspTree
|
---|
144 | {
|
---|
145 | friend class ViewCellsParseHandlers;
|
---|
146 | friend class HierarchyManager;
|
---|
147 |
|
---|
148 | public:
|
---|
149 |
|
---|
150 | /** Additional data which is passed down the BSP tree during traversal.
|
---|
151 | */
|
---|
152 | class OspTraversalData
|
---|
153 | {
|
---|
154 | public:
|
---|
155 | /// the current node
|
---|
156 | KdLeaf *mNode;
|
---|
157 | /// current depth
|
---|
158 | int mDepth;
|
---|
159 | /// rays piercing this node
|
---|
160 | RayInfoContainer *mRays;
|
---|
161 | /// the probability that this node contains view point
|
---|
162 | float mProbability;
|
---|
163 | /// the bounding box of the node
|
---|
164 | AxisAlignedBox3 mBoundingBox;
|
---|
165 | /// pvs size
|
---|
166 | float mRenderCost;
|
---|
167 | /// how often this branch has missed the max-cost ratio
|
---|
168 | int mMaxCostMisses;
|
---|
169 | // current axis
|
---|
170 | int mAxis;
|
---|
171 | // current priority
|
---|
172 | float mPriority;
|
---|
173 |
|
---|
174 |
|
---|
175 | OspTraversalData():
|
---|
176 | mNode(NULL),
|
---|
177 | mRays(NULL),
|
---|
178 | mDepth(0),
|
---|
179 | mRenderCost(0),
|
---|
180 | mProbability(0.0),
|
---|
181 | mMaxCostMisses(0),
|
---|
182 | mPriority(0),
|
---|
183 | mAxis(0)
|
---|
184 | {}
|
---|
185 |
|
---|
186 | OspTraversalData(KdLeaf *node,
|
---|
187 | const int depth,
|
---|
188 | RayInfoContainer *rays,
|
---|
189 | const float rc,
|
---|
190 | const float p,
|
---|
191 | const AxisAlignedBox3 &box):
|
---|
192 | mNode(node),
|
---|
193 | mDepth(depth),
|
---|
194 | mRays(rays),
|
---|
195 | mRenderCost(rc),
|
---|
196 | mProbability(p),
|
---|
197 | mBoundingBox(box),
|
---|
198 | mMaxCostMisses(0),
|
---|
199 | mPriority(0),
|
---|
200 | mAxis(0)
|
---|
201 | {}
|
---|
202 |
|
---|
203 | OspTraversalData(const int depth,
|
---|
204 | RayInfoContainer *rays,
|
---|
205 | const AxisAlignedBox3 &box):
|
---|
206 | mNode(NULL),
|
---|
207 | mDepth(depth),
|
---|
208 | mRays(rays),
|
---|
209 | mRenderCost(0),
|
---|
210 | mProbability(0),
|
---|
211 | mMaxCostMisses(0),
|
---|
212 | mAxis(0),
|
---|
213 | mBoundingBox(box)
|
---|
214 | {}
|
---|
215 |
|
---|
216 | /** Returns cost of the traversal data.
|
---|
217 | */
|
---|
218 | float GetCost() const
|
---|
219 | {
|
---|
220 | //cout << mPriority << endl;
|
---|
221 | return mPriority;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /// deletes contents and sets them to NULL
|
---|
225 | void Clear()
|
---|
226 | {
|
---|
227 | DEL_PTR(mRays);
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 | friend bool operator<(const OspTraversalData &a, const OspTraversalData &b)
|
---|
232 | {
|
---|
233 | return a.GetCost() < b.GetCost();
|
---|
234 | }
|
---|
235 | };
|
---|
236 |
|
---|
237 | /** Candidate for a view space split.
|
---|
238 | */
|
---|
239 | class OspSubdivisionCandidate: public SubdivisionCandidate
|
---|
240 | {
|
---|
241 | public:
|
---|
242 | static OspTree* sOspTree;
|
---|
243 |
|
---|
244 | /// the current split plane
|
---|
245 | AxisAlignedPlane mSplitPlane;
|
---|
246 | /// parent data
|
---|
247 | OspTraversalData mParentData;
|
---|
248 |
|
---|
249 | OspSubdivisionCandidate(const OspTraversalData &tData): mParentData(tData)
|
---|
250 | {};
|
---|
251 |
|
---|
252 | int Type() const { return OBJECT_SPACE; }
|
---|
253 |
|
---|
254 | void EvalCandidate(bool computeSplitplane = true)
|
---|
255 | {
|
---|
256 | mDirty = false;
|
---|
257 | // todo: avoid computing split plane
|
---|
258 | sOspTree->EvalSubdivisionCandidate(*this);
|
---|
259 | }
|
---|
260 |
|
---|
261 | bool GlobalTerminationCriteriaMet() const
|
---|
262 | {
|
---|
263 | return sOspTree->GlobalTerminationCriteriaMet(mParentData);
|
---|
264 | }
|
---|
265 |
|
---|
266 | bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet, SubdivisionCandidateContainer &dirtyList)
|
---|
267 | {
|
---|
268 | KdNode *n = sOspTree->Subdivide(splitQueue ,this, terminationCriteriaMet);
|
---|
269 |
|
---|
270 | // local or global termination criteria failed
|
---|
271 | return !n->IsLeaf();
|
---|
272 | }
|
---|
273 |
|
---|
274 | void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList,
|
---|
275 | const bool onlyUnmailed)
|
---|
276 | {
|
---|
277 | sOspTree->CollectDirtyCandidates(this, dirtyList, onlyUnmailed);
|
---|
278 | }
|
---|
279 |
|
---|
280 | float GetPriority() const
|
---|
281 | {
|
---|
282 | return mPriority;
|
---|
283 | }
|
---|
284 |
|
---|
285 | OspSubdivisionCandidate(const AxisAlignedPlane &plane, const OspTraversalData &tData):
|
---|
286 | mSplitPlane(plane), mParentData(tData)
|
---|
287 | {}
|
---|
288 | };
|
---|
289 |
|
---|
290 | /** Struct for traversing line segment.
|
---|
291 | */
|
---|
292 | struct LineTraversalData
|
---|
293 | {
|
---|
294 | KdNode *mNode;
|
---|
295 | Vector3 mExitPoint;
|
---|
296 |
|
---|
297 | float mMaxT;
|
---|
298 |
|
---|
299 | LineTraversalData () {}
|
---|
300 | LineTraversalData (KdNode *n, const Vector3 &p, const float maxt):
|
---|
301 | mNode(n), mExitPoint(p), mMaxT(maxt) {}
|
---|
302 | };
|
---|
303 |
|
---|
304 | /** Default constructor creating an empty tree.
|
---|
305 | */
|
---|
306 | OspTree();
|
---|
307 |
|
---|
308 | /** Copies tree from a kd tree.
|
---|
309 | */
|
---|
310 | OspTree(const KdTree &kdTree);
|
---|
311 |
|
---|
312 | /** Default destructor.
|
---|
313 | */
|
---|
314 | ~OspTree();
|
---|
315 |
|
---|
316 | /** Returns tree statistics.
|
---|
317 | */
|
---|
318 | const OspTreeStatistics &GetStatistics() const;
|
---|
319 |
|
---|
320 | /** Returns bounding box of the specified node.
|
---|
321 | */
|
---|
322 | AxisAlignedBox3 GetBoundingBox(KdNode *node) const;
|
---|
323 |
|
---|
324 | /** Returns list of leaves with pvs smaller than
|
---|
325 | a certain threshold.
|
---|
326 | @param onlyUnmailed if only the unmailed leaves should be considered
|
---|
327 | @param maxPvs the maximal pvs of a leaf to be added (-1 means unlimited)
|
---|
328 | */
|
---|
329 |
|
---|
330 | void CollectLeaves(vector<KdLeaf *> &leaves) const;
|
---|
331 |
|
---|
332 | /** Returns bounding box of the whole tree (= bbox of root node)
|
---|
333 | */
|
---|
334 | AxisAlignedBox3 GetBoundingBox()const;
|
---|
335 |
|
---|
336 | /** Returns root of the view space partitioning tree.
|
---|
337 | */
|
---|
338 | KdNode *GetRoot() const;
|
---|
339 |
|
---|
340 | /** Collects the leaf view cells of the tree
|
---|
341 | @param viewCells returns the view cells
|
---|
342 | */
|
---|
343 | void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const;
|
---|
344 |
|
---|
345 | /** A ray is cast possible intersecting the tree.
|
---|
346 | @param the ray that is cast.
|
---|
347 | @returns the number of intersections with objects stored in the tree.
|
---|
348 | */
|
---|
349 | int CastRay(Ray &ray);
|
---|
350 |
|
---|
351 | /** finds neighbouring leaves of this tree node.
|
---|
352 | */
|
---|
353 | int FindNeighbors(KdLeaf *n,
|
---|
354 | vector<VspLeaf *> &neighbors,
|
---|
355 | const bool onlyUnmailed) const;
|
---|
356 |
|
---|
357 | /** Returns random leaf of BSP tree.
|
---|
358 | @param halfspace defines the halfspace from which the leaf is taken.
|
---|
359 | */
|
---|
360 | KdLeaf *GetRandomLeaf(const Plane3 &halfspace);
|
---|
361 |
|
---|
362 | /** Returns random leaf of BSP tree.
|
---|
363 | @param onlyUnmailed if only unmailed leaves should be returned.
|
---|
364 | */
|
---|
365 | KdLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
|
---|
366 |
|
---|
367 | /** Returns epsilon of this tree.
|
---|
368 | */
|
---|
369 | float GetEpsilon() const;
|
---|
370 |
|
---|
371 | /** Casts line segment into the tree.
|
---|
372 | @param origin the origin of the line segment
|
---|
373 | @param termination the end point of the line segment
|
---|
374 | @returns view cells intersecting the line segment.
|
---|
375 | */
|
---|
376 | int CastLineSegment(const Vector3 &origin,
|
---|
377 | const Vector3 &termination,
|
---|
378 | ViewCellContainer &viewcells);
|
---|
379 | /** Sets pointer to view cells manager.
|
---|
380 | */
|
---|
381 | void SetViewCellsManager(ViewCellsManager *vcm);
|
---|
382 | /** Writes tree to output stream
|
---|
383 | */
|
---|
384 | bool Export(OUT_STREAM &stream);
|
---|
385 | /** Returns or creates a new intersectable for use in a kd based pvs.
|
---|
386 | The OspTree is responsible for destruction of the intersectable.
|
---|
387 | */
|
---|
388 | KdIntersectable *GetOrCreateKdIntersectable(KdNode *node);
|
---|
389 | /** Collects rays stored in the leaves.
|
---|
390 | */
|
---|
391 | void CollectRays(VssRayContainer &rays);
|
---|
392 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
393 | @returns number of view cells found
|
---|
394 | */
|
---|
395 | int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
396 | ViewCellContainer &viewCells) const;
|
---|
397 |
|
---|
398 |
|
---|
399 | /** Returns kd leaf the point pt lies in, starting from root.
|
---|
400 | */
|
---|
401 | KdLeaf *GetLeaf(const Vector3 &pt, KdNode *root = NULL) const;
|
---|
402 |
|
---|
403 |
|
---|
404 | ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; }
|
---|
405 |
|
---|
406 | void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; }
|
---|
407 |
|
---|
408 | float EvalRenderCost(const VssRayContainer &myrays);
|
---|
409 | float EvalLeafCost(const OspTraversalData &tData);
|
---|
410 |
|
---|
411 | /** Adds this objects to the kd leaf objects.
|
---|
412 | @warning: Can corrupt the tree
|
---|
413 | */
|
---|
414 | void InsertObjects(KdNode *node, const ObjectContainer &objects);
|
---|
415 |
|
---|
416 | /** Add the leaf to the pvs of the view cell.
|
---|
417 | */
|
---|
418 | bool AddLeafToPvs(
|
---|
419 | KdLeaf *leaf,
|
---|
420 | ViewCell *vc,
|
---|
421 | const float pdf,
|
---|
422 | float &contribution);
|
---|
423 |
|
---|
424 | protected:
|
---|
425 |
|
---|
426 | // --------------------------------------------------------------
|
---|
427 | // For sorting objects
|
---|
428 | // --------------------------------------------------------------
|
---|
429 | struct SortableEntry
|
---|
430 | {
|
---|
431 | /** There is a 3th "event" for rays which intersect a
|
---|
432 | box in the middle. These "events" don't induce a change in
|
---|
433 | pvs size, but may induce a change in view cell volume.
|
---|
434 | */
|
---|
435 | enum EType
|
---|
436 | {
|
---|
437 | BOX_MIN,
|
---|
438 | BOX_MAX,
|
---|
439 | BOX_INTERSECT
|
---|
440 | };
|
---|
441 |
|
---|
442 | int mType;
|
---|
443 | //int mPvs;
|
---|
444 | float mPos;
|
---|
445 | VssRay *mRay;
|
---|
446 |
|
---|
447 | Intersectable *mObject;
|
---|
448 |
|
---|
449 | SortableEntry() {}
|
---|
450 |
|
---|
451 | SortableEntry(const int type,
|
---|
452 | //const float pvs,
|
---|
453 | const float pos,
|
---|
454 | Intersectable *obj,
|
---|
455 | VssRay *ray):
|
---|
456 | mType(type),
|
---|
457 | //mPvs(pvs),
|
---|
458 | mPos(pos),
|
---|
459 | mObject(obj),
|
---|
460 | mRay(ray)
|
---|
461 | {}
|
---|
462 |
|
---|
463 | bool operator<(const SortableEntry &b) const
|
---|
464 | {
|
---|
465 | return mPos < b.mPos;
|
---|
466 | }
|
---|
467 | };
|
---|
468 |
|
---|
469 |
|
---|
470 | /** faster evaluation of split plane cost for kd axis aligned cells.
|
---|
471 | */
|
---|
472 | float EvalLocalSplitCost(const OspTraversalData &data,
|
---|
473 | const AxisAlignedBox3 &box,
|
---|
474 | const int axis,
|
---|
475 | const float &position,
|
---|
476 | float &pFront,
|
---|
477 | float &pBack) const;
|
---|
478 |
|
---|
479 | /** Evaluates candidate for splitting.
|
---|
480 | */
|
---|
481 | void EvalSubdivisionCandidate(OspSubdivisionCandidate &splitData);
|
---|
482 |
|
---|
483 | /** Computes priority of the traversal data and stores it in tData.
|
---|
484 | */
|
---|
485 | void EvalPriority(OspTraversalData &tData) const;
|
---|
486 |
|
---|
487 | /** Evaluates render cost decrease of next split.
|
---|
488 | */
|
---|
489 | float EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane,
|
---|
490 | const OspTraversalData &data,
|
---|
491 | float &normalizedOldRenderCost) const;
|
---|
492 |
|
---|
493 |
|
---|
494 | /** Collects view cells in the subtree under root.
|
---|
495 | */
|
---|
496 | void CollectViewCells(KdNode *root,
|
---|
497 | bool onlyValid,
|
---|
498 | ViewCellContainer &viewCells,
|
---|
499 | bool onlyUnmailed = false) const;
|
---|
500 |
|
---|
501 | /** Evaluates tree stats in the BSP tree leafs.
|
---|
502 | */
|
---|
503 | void EvaluateLeafStats(const OspTraversalData &data);
|
---|
504 |
|
---|
505 | /** Subdivides node using a best split priority queue.
|
---|
506 | @param tQueue the best split priority queue
|
---|
507 | @param splitCandidate the candidate for the next split
|
---|
508 | @param globalCriteriaMet if the global termination criteria were already met
|
---|
509 | @returns new root of the subtree
|
---|
510 | */
|
---|
511 | KdNode *Subdivide(SplitQueue &tQueue,
|
---|
512 | SubdivisionCandidate *splitCandidate,
|
---|
513 | const bool globalCriteriaMet);
|
---|
514 |
|
---|
515 | /** Subdivides leaf.
|
---|
516 | @param leaf the leaf to be subdivided
|
---|
517 |
|
---|
518 | @param polys the polygons to be split
|
---|
519 | @param frontPolys returns the polygons in front of the split plane
|
---|
520 | @param backPolys returns the polygons in the back of the split plane
|
---|
521 |
|
---|
522 | @param rays the polygons to be filtered
|
---|
523 | @param frontRays returns the polygons in front of the split plane
|
---|
524 | @param backRays returns the polygons in the back of the split plane
|
---|
525 |
|
---|
526 | @returns the root of the subdivision
|
---|
527 | */
|
---|
528 | KdInterior *SubdivideNode(
|
---|
529 | const AxisAlignedPlane &splitPlane,
|
---|
530 | const OspTraversalData &tData,
|
---|
531 | OspTraversalData &frontData,
|
---|
532 | OspTraversalData &backData);
|
---|
533 |
|
---|
534 | void SplitObjects(KdLeaf *leaf,
|
---|
535 | const AxisAlignedPlane & splitPlane,
|
---|
536 | const ObjectContainer &objects,
|
---|
537 | ObjectContainer &front,
|
---|
538 | ObjectContainer &back);
|
---|
539 |
|
---|
540 | /** does some post processing on the objects in the new child leaves.
|
---|
541 | */
|
---|
542 | void ProcessMultipleRefs(KdLeaf *leaf) const;
|
---|
543 |
|
---|
544 | /** Sorts split candidates for cost heuristics using axis aligned splits.
|
---|
545 | @param node the current node
|
---|
546 | @param axis the current split axis
|
---|
547 | */
|
---|
548 | void SortSubdivisionCandidates(const OspTraversalData &data,
|
---|
549 | const int axis,
|
---|
550 | float minBand,
|
---|
551 | float maxBand);
|
---|
552 |
|
---|
553 | /** Computes best cost for axis aligned planes.
|
---|
554 | */
|
---|
555 | float EvalLocalCostHeuristics(const OspTraversalData &tData,
|
---|
556 | const AxisAlignedBox3 &box,
|
---|
557 | const int axis,
|
---|
558 | float &position,
|
---|
559 | int &objectsFront,
|
---|
560 | int &objectsBack);
|
---|
561 |
|
---|
562 | /** Subdivides the rays into front and back rays according to the split plane.
|
---|
563 |
|
---|
564 | @param plane the split plane
|
---|
565 | @param rays contains the rays to be split. The rays are
|
---|
566 | distributed into front and back rays.
|
---|
567 | @param frontRays returns rays on the front side of the plane
|
---|
568 | @param backRays returns rays on the back side of the plane
|
---|
569 |
|
---|
570 | @returns the number of splits
|
---|
571 | */
|
---|
572 | int SplitRays(const AxisAlignedPlane &plane,
|
---|
573 | RayInfoContainer &rays,
|
---|
574 | RayInfoContainer &frontRays,
|
---|
575 | RayInfoContainer &backRays) const;
|
---|
576 |
|
---|
577 | int FilterRays(KdLeaf *leaf, const RayInfoContainer &rays, RayInfoContainer &filteredRays);
|
---|
578 |
|
---|
579 | /** Adds the object to the pvs of the front and back leaf with a given classification.
|
---|
580 |
|
---|
581 | @param obj the object to be added
|
---|
582 | @param cf the ray classification regarding the split plane
|
---|
583 | @param frontPvs returns the PVS of the front partition
|
---|
584 | @param backPvs returns the PVS of the back partition
|
---|
585 |
|
---|
586 | */
|
---|
587 | void UpdateObjPvsContri(Intersectable *obj,
|
---|
588 | const int cf,
|
---|
589 | float &frontPvs,
|
---|
590 | float &backPvs,
|
---|
591 | float &totalPvs) const;
|
---|
592 |
|
---|
593 | /** Returns true if tree can be terminated.
|
---|
594 | */
|
---|
595 | bool LocalTerminationCriteriaMet(const OspTraversalData &data) const;
|
---|
596 |
|
---|
597 | /** Returns true if global tree can be terminated.
|
---|
598 | */
|
---|
599 | bool GlobalTerminationCriteriaMet(const OspTraversalData &data) const;
|
---|
600 |
|
---|
601 | /** Selects an axis aligned for the next split.
|
---|
602 | @returns cost for this split
|
---|
603 | */
|
---|
604 | float SelectSplitPlane(
|
---|
605 | const OspTraversalData &tData,
|
---|
606 | AxisAlignedPlane &plane);
|
---|
607 |
|
---|
608 | /** Propagates valid flag up the tree.
|
---|
609 | */
|
---|
610 | void PropagateUpValidity(KdNode *node);
|
---|
611 |
|
---|
612 | /** Writes the node to disk
|
---|
613 | @note: should be implemented as visitor.
|
---|
614 | */
|
---|
615 | void ExportNode(KdNode *node, OUT_STREAM &stream);
|
---|
616 |
|
---|
617 | /** Returns estimated memory usage of tree.
|
---|
618 | */
|
---|
619 | float GetMemUsage() const;
|
---|
620 |
|
---|
621 | /** Evaluate the contributions of view cell volume of the left and the right view cell.
|
---|
622 | */
|
---|
623 | void EvalRayContribution(
|
---|
624 | KdLeaf *leaf,
|
---|
625 | const VssRay &ray,
|
---|
626 | float &renderCost);
|
---|
627 |
|
---|
628 | void EvalViewCellContribution(
|
---|
629 | KdLeaf *leaf,
|
---|
630 | ViewCell *viewCell,
|
---|
631 | float &renderCost);
|
---|
632 |
|
---|
633 | /** Evaluates the influence on the pvs of the event.
|
---|
634 | @param ve the visibility event
|
---|
635 | @param pvsLeft updates the left pvs
|
---|
636 | @param rightPvs updates the right pvs
|
---|
637 | */
|
---|
638 | void EvalHeuristicsContribution(KdLeaf *leaf,
|
---|
639 | const SortableEntry &ci,
|
---|
640 | float &renderCost,
|
---|
641 | ViewCellContainer &touchedViewCells);
|
---|
642 |
|
---|
643 | /** Prepares objects for the cost heuristics.
|
---|
644 | @returns pvs size of the node
|
---|
645 | */
|
---|
646 | float PrepareHeuristics(
|
---|
647 | const OspTraversalData &tData,
|
---|
648 | ViewCellContainer &touchedViewCells);
|
---|
649 |
|
---|
650 | /** Prepares heuristics for a particular ray.
|
---|
651 | */
|
---|
652 | void PrepareHeuristics(
|
---|
653 | const VssRay &ray,
|
---|
654 | ViewCellContainer &touchedViewCells);
|
---|
655 |
|
---|
656 | /** Prepares construction for vsp and osp trees.
|
---|
657 | */
|
---|
658 | void ComputeBoundingBox(const ObjectContainer &objects);
|
---|
659 |
|
---|
660 | void CollectDirtyCandidates(OspSubdivisionCandidate *sc,
|
---|
661 | vector<SubdivisionCandidate *> &dirtyList,
|
---|
662 | const bool onlyUnmailed);
|
---|
663 |
|
---|
664 | /** Collect view cells which see this kd leaf.
|
---|
665 | */
|
---|
666 | void CollectViewCells(KdLeaf *leaf,
|
---|
667 | ViewCellContainer &viewCells);
|
---|
668 |
|
---|
669 | /** Rays will be clipped to the bounding box.
|
---|
670 | */
|
---|
671 | void PreprocessRays(
|
---|
672 | KdLeaf *root,
|
---|
673 | const VssRayContainer &sampleRays,
|
---|
674 | RayInfoContainer &rays);
|
---|
675 |
|
---|
676 | /** Reads parameters from environment singleton.
|
---|
677 | */
|
---|
678 | void ReadEnvironment();
|
---|
679 |
|
---|
680 | /** Returns true if the specified ray end points is inside the kd leaf.
|
---|
681 | @param isTermination if origin or termination point should be checked
|
---|
682 | */
|
---|
683 | bool EndPointInsideNode(KdLeaf *leaf, VssRay &ray, bool isTermination) const;
|
---|
684 |
|
---|
685 | void AddViewCellVolumeContri(
|
---|
686 | ViewCell *vc,
|
---|
687 | float &frontVol,
|
---|
688 | float &backVol,
|
---|
689 | float &frontAndBackVol) const;
|
---|
690 |
|
---|
691 | /** Classifies and mail view cell with respect to the heuristics contribution.
|
---|
692 | Set view cell mail box according to it's influence on
|
---|
693 | front (0), back (1) and front / back node (2).
|
---|
694 | */
|
---|
695 | void MailViewCell(ViewCell *vc, const int cf) const;
|
---|
696 |
|
---|
697 | int ClassifyRay(VssRay *ray, KdLeaf *leaf, const AxisAlignedPlane &plane) const;
|
---|
698 |
|
---|
699 | void EvalSubdivisionStats(const SubdivisionCandidate &tData);
|
---|
700 |
|
---|
701 | void AddSubdivisionStats(const int viewCells,
|
---|
702 | const float renderCostDecr,
|
---|
703 | const float totalRenderCost);
|
---|
704 |
|
---|
705 | void EvalViewCellsForHeuristics(const VssRay &ray,
|
---|
706 | float &volLeft,
|
---|
707 | float &volRight);
|
---|
708 |
|
---|
709 | float EvalViewCellsVolume(KdLeaf *leaf, const RayInfoContainer &rays) const;
|
---|
710 |
|
---|
711 | int RemoveParentViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const;
|
---|
712 |
|
---|
713 | int UpdateViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const;
|
---|
714 |
|
---|
715 | int CheckViewCellsPvs(KdLeaf *leaf, const RayInfoContainer &rays) const;
|
---|
716 |
|
---|
717 | bool AddViewCellToObjectPvs(Intersectable *obj,
|
---|
718 | ViewCell *vc,
|
---|
719 | float &contribution,
|
---|
720 | bool onlyUnmailed) const;
|
---|
721 |
|
---|
722 | int ClassifyRays(const RayInfoContainer &rays,
|
---|
723 | KdLeaf *leaf,
|
---|
724 | const AxisAlignedPlane &plane,
|
---|
725 | RayInfoContainer &frontRays,
|
---|
726 | RayInfoContainer &backRays) const;
|
---|
727 |
|
---|
728 | void CollectTouchedViewCells(const RayInfoContainer &rays,
|
---|
729 | ViewCellContainer &touchedViewCells) const;
|
---|
730 |
|
---|
731 | void AddObjectContribution(KdLeaf *leaf,
|
---|
732 | Intersectable * obj,
|
---|
733 | ViewCellContainer &touchedViewCells,
|
---|
734 | float &renderCost);
|
---|
735 |
|
---|
736 | void SubtractObjectContribution(KdLeaf *leaf,
|
---|
737 | Intersectable *obj,
|
---|
738 | ViewCellContainer &touchedViewCells,
|
---|
739 | float &renderCost);
|
---|
740 |
|
---|
741 | void PrepareConstruction(SplitQueue &tQueue,
|
---|
742 | const VssRayContainer &sampleRays,
|
---|
743 | const ObjectContainer &objects,
|
---|
744 | RayInfoContainer &rays);
|
---|
745 |
|
---|
746 |
|
---|
747 | protected:
|
---|
748 |
|
---|
749 | /// pointer to the hierarchy of view cells
|
---|
750 | ViewCellsTree *mViewCellsTree;
|
---|
751 |
|
---|
752 | /// pointer to the view space partition
|
---|
753 | /// note: should be handled over the hierarchy manager
|
---|
754 | VspTree *mVspTree;
|
---|
755 |
|
---|
756 | /// pointer to the hierarchy manager
|
---|
757 | HierarchyManager *mHierarchyManager;
|
---|
758 |
|
---|
759 | /// The view cells manager
|
---|
760 | ViewCellsManager *mViewCellsManager;
|
---|
761 |
|
---|
762 | /// candidates for placing split planes during cost heuristics
|
---|
763 | vector<SortableEntry> *mSubdivisionCandidates;
|
---|
764 |
|
---|
765 | /// Pointer to the root of the tree
|
---|
766 | KdNode *mRoot;
|
---|
767 |
|
---|
768 | /// Statistics for the object space partition
|
---|
769 | OspTreeStatistics mOspStats;
|
---|
770 |
|
---|
771 | /// box around the whole view domain
|
---|
772 | AxisAlignedBox3 mBoundingBox;
|
---|
773 |
|
---|
774 |
|
---|
775 | //////////////////////////////
|
---|
776 | //-- local termination
|
---|
777 |
|
---|
778 | /// maximal possible depth
|
---|
779 | int mTermMaxDepth;
|
---|
780 | /// mininum probability
|
---|
781 | float mTermMinProbability;
|
---|
782 | /// minimal number of objects
|
---|
783 | int mTermMinObjects;
|
---|
784 | /// maximal contribution per ray
|
---|
785 | float mTermMaxRayContribution;
|
---|
786 | /// maximal acceptable cost ratio
|
---|
787 | float mTermMaxCostRatio;
|
---|
788 | /// tolerance value indicating how often the max cost ratio can be failed
|
---|
789 | int mTermMissTolerance;
|
---|
790 |
|
---|
791 |
|
---|
792 | ////////////////////////
|
---|
793 | //-- global criteria
|
---|
794 |
|
---|
795 | float mTermMinGlobalCostRatio;
|
---|
796 | int mTermGlobalCostMissTolerance;
|
---|
797 | int mGlobalCostMisses;
|
---|
798 |
|
---|
799 | /// maximal number of view cells
|
---|
800 | int mTermMaxLeaves;
|
---|
801 | /// maximal tree memory
|
---|
802 | float mMaxMemory;
|
---|
803 | /// the tree is out of memory
|
---|
804 | bool mOutOfMemory;
|
---|
805 |
|
---|
806 |
|
---|
807 | ///////////////////////////////////////////
|
---|
808 | //-- split heuristics based parameters
|
---|
809 |
|
---|
810 | bool mUseCostHeuristics;
|
---|
811 | /// balancing factor for PVS criterium
|
---|
812 | float mCtDivCi;
|
---|
813 | /// if only driving axis should be used for split
|
---|
814 | bool mOnlyDrivingAxis;
|
---|
815 | /// represents min and max band for sweep
|
---|
816 | float mSplitBorder;
|
---|
817 |
|
---|
818 | ////////////////////////////////////////////////
|
---|
819 |
|
---|
820 | /// current time stamp (used for keeping split history)
|
---|
821 | int mTimeStamp;
|
---|
822 | // if rays should be stored in leaves
|
---|
823 | bool mStoreRays;
|
---|
824 | /// epsilon for geometric comparisons
|
---|
825 | float mEpsilon;
|
---|
826 | /// subdivision stats output file
|
---|
827 | std::ofstream mSubdivisionStats;
|
---|
828 | /// keeps track of cost during subdivision
|
---|
829 | float mTotalCost;
|
---|
830 | /// keeps track of overall pvs size during subdivision
|
---|
831 | int mTotalPvsSize;
|
---|
832 | /// number of currenly generated view cells
|
---|
833 | int mCreatedLeaves;
|
---|
834 |
|
---|
835 | /// weight between render cost decrease and node render cost
|
---|
836 | float mRenderCostDecreaseWeight;
|
---|
837 |
|
---|
838 | /// stores the kd node intersectables used for pvs
|
---|
839 | KdIntersectableMap mKdIntersectables;
|
---|
840 |
|
---|
841 | private:
|
---|
842 |
|
---|
843 | bool mCopyFromKdTree;
|
---|
844 | };
|
---|
845 |
|
---|
846 |
|
---|
847 | }
|
---|
848 |
|
---|
849 | #endif
|
---|