source: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h @ 1664

Revision 1664, 23.5 KB checked in by mattausch, 18 years ago (diff)

changed priority computation:
taking ratio render cost decrease / pvs size increase rather
then render cost decrease alone
this should rather emphasise object space splits, as they
seem to cost less memory.

Line 
1#ifndef _BvHierarchy_H__
2#define _BvHierarchy_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 "AxisAlignedBox3.h"
14#include "IntersectableWrapper.h"
15
16
17
18namespace GtpVisibilityPreprocessor {
19
20
21class ViewCellLeaf;
22class Plane3;
23class AxisAlignedBox3;
24class Ray;
25class ViewCellsStatistics;
26class ViewCellsManager;
27class MergeCandidate;
28class Beam;
29class ViewCellsTree;
30class Environment;
31class BvhInterior;
32class BvhLeaf;
33class BvhNode;
34class BvhIntersectable;
35class BvhTree;
36class VspTree;
37class ViewCellsContainer;
38class HierarchyManager;
39
40
41/** View space partition statistics.
42*/
43class BvhStatistics: public StatisticsBase
44{
45public:
46       
47        /// Constructor
48        BvhStatistics()
49        {
50                Reset();
51        }
52
53        int Nodes() const {return nodes;}
54        int Interior() const { return nodes / 2; }
55        int Leaves() const { return (nodes / 2) + 1; }
56       
57        double AvgDepth() const
58        { return accumDepth / (double)Leaves(); }
59
60        double AvgObjectRefs() const
61        { return objectRefs / (double)Leaves(); }
62
63        double AvgRayRefs() const
64        { return rayRefs / (double)Leaves(); }
65
66
67        void Reset()
68        {
69                nodes = 0;
70                splits = 0;
71                maxDepth = 0;
72                minDepth = 99999;
73                accumDepth = 0;
74        maxDepthNodes = 0;
75                minProbabilityNodes = 0;
76                maxCostNodes = 0;
77                       
78                ///////////////////
79                minObjectsNodes = 0;
80                maxObjectRefs = 0;
81                minObjectRefs = 999999999;
82                objectRefs = 0;
83                emptyNodes = 0;
84
85                ///////////////////
86                minRaysNodes = 0;
87                maxRayRefs = 0;
88                minRayRefs = 999999999;
89                rayRefs = 0;
90                maxRayContriNodes = 0;
91                mGlobalCostMisses = 0;
92        }
93
94
95public:
96
97        // total number of nodes
98        int nodes;
99        // number of splits
100        int splits;
101        // maximal reached depth
102        int maxDepth;
103        // minimal depth
104        int minDepth;
105        // max depth nodes
106        int maxDepthNodes;
107        // accumulated depth (used to compute average)
108        int accumDepth;
109        // minimum area nodes
110        int minProbabilityNodes;
111        /// nodes termination because of max cost ratio;
112        int maxCostNodes;
113        // global cost ratio violations
114        int mGlobalCostMisses;
115
116        //////////////////
117        // nodes with minimum objects
118        int minObjectsNodes;
119        // max number of rays per node
120        int maxObjectRefs;
121        // min number of rays per node
122        int minObjectRefs;
123        /// object references
124        int objectRefs;
125        // leaves with no objects
126        int emptyNodes;
127
128        //////////////////////////
129        // nodes with minimum rays
130        int minRaysNodes;
131        // max number of rays per node
132        int maxRayRefs;
133        // min number of rays per node
134        int minRayRefs;
135        /// object references
136        int rayRefs;
137        /// nodes with max ray contribution
138        int maxRayContriNodes;
139
140        void Print(ostream &app) const;
141
142        friend ostream &operator<<(ostream &s, const BvhStatistics &stat)
143        {
144                stat.Print(s);
145                return s;
146        }
147};
148
149
150/**
151    VspNode abstract class serving for interior and leaf node implementation
152*/
153class BvhNode
154{
155public:
156       
157        // types of vsp nodes
158        enum {Interior, Leaf};
159
160        BvhNode();
161        BvhNode(const AxisAlignedBox3 &bbox);
162        BvhNode(const AxisAlignedBox3 &bbox, BvhInterior *parent);
163
164        virtual ~BvhNode(){};
165
166        /** Determines whether this node is a leaf or not
167                @return true if leaf
168        */
169        virtual bool IsLeaf() const = 0;
170
171        /** Determines whether this node is a root
172                @return true if root
173        */
174        virtual bool IsRoot() const;
175
176        /** Returns parent node.
177        */
178        BvhInterior *GetParent();
179
180        /** Sets parent node.
181        */
182        void SetParent(BvhInterior *parent);
183
184        // collects all objects under this node
185        virtual void CollectObjects(ObjectContainer &objects) = 0;
186        /** The bounding box specifies the node extent.
187        */
188        inline
189        AxisAlignedBox3 GetBoundingBox() const
190        { return mBoundingBox; }
191
192
193        inline
194        void SetBoundingBox(const AxisAlignedBox3 &boundingBox)
195        { mBoundingBox = boundingBox; }
196
197
198        /////////////////////////////////////
199        //-- mailing options
200       
201        static void NewMail(const int reserve = 1) {
202                sMailId += sReservedMailboxes;
203                sReservedMailboxes = reserve;
204        }
205       
206        void Mail() { mMailbox = sMailId; }
207        bool Mailed() const { return mMailbox == sMailId; }
208
209        void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
210        bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
211
212        int IncMail() { return ++ mMailbox - sMailId; }
213
214        static int sMailId;
215        int mMailbox;
216        static int sReservedMailboxes;
217
218        ///////////////////////////////////
219
220protected:
221       
222        /// the bounding box of the node
223        AxisAlignedBox3 mBoundingBox;
224        /// parent of this node
225        BvhInterior *mParent;
226};
227
228
229/** BSP interior node implementation
230*/
231class BvhInterior: public BvhNode
232{
233public:
234        /** Standard contructor taking a bounding box as argument.
235        */
236        BvhInterior(const AxisAlignedBox3 &bbox);
237        BvhInterior(const AxisAlignedBox3 &bbox, BvhInterior *parent);
238
239        ~BvhInterior();
240        /** @return false since it is an interior node
241        */
242        bool IsLeaf() const;
243       
244        BvhNode *GetBack() { return mBack; }
245        BvhNode *GetFront() { return mFront; }
246
247        /** Replace front or back child with new child.
248        */
249        void ReplaceChildLink(BvhNode *oldChild, BvhNode *newChild);
250
251        /** Replace front and back child.
252        */
253        void SetupChildLinks(BvhNode *front, BvhNode *back);
254
255        friend ostream &operator<<(ostream &s, const BvhInterior &A)
256        {
257                return s << A.mBoundingBox;
258        }
259virtual void CollectObjects(ObjectContainer &objects);
260protected:
261
262        /// back node
263        BvhNode *mBack;
264        /// front node
265        BvhNode *mFront;
266};
267
268
269/** BSP leaf node implementation.
270*/
271class BvhLeaf: public BvhNode
272{
273public:
274        /** Standard contructor taking a bounding box as argument.
275        */
276        BvhLeaf(const AxisAlignedBox3 &bbox);
277        BvhLeaf(const AxisAlignedBox3 &bbox, BvhInterior *parent);
278        BvhLeaf(const AxisAlignedBox3 &bbox, BvhInterior *parent, const int numObjects);
279
280        ~BvhLeaf();
281
282        /** @return true since it is an interior node
283        */
284        bool IsLeaf() const;
285       
286        SubdivisionCandidate *GetSubdivisionCandidate()// const
287        {
288                return mSubdivisionCandidate;
289        }
290
291        void SetSubdivisionCandidate(SubdivisionCandidate *candidate)
292        {
293                mSubdivisionCandidate = candidate;
294        }
295virtual void CollectObjects(ObjectContainer &objects);
296public:
297
298        /// Rays piercing this leaf.
299        VssRayContainer mVssRays;
300        /// objects
301        ObjectContainer mObjects;
302        /// universal counter
303        int mCounter;
304
305protected:
306
307        /// pointer to a split plane candidate splitting this leaf
308        SubdivisionCandidate *mSubdivisionCandidate;
309};
310
311
312typedef map<BvhNode *, BvhIntersectable *> BvhIntersectableMap;
313
314
315/** View Space Partitioning tree.
316*/
317class BvHierarchy
318{
319        friend class ViewCellsParseHandlers;
320        friend class HierarchyManager;
321
322protected:
323        struct SortableEntry;
324        typedef vector<SortableEntry> SortableEntryContainer;
325
326public:
327       
328        /** Additional data which is passed down the BSP tree during traversal.
329        */
330        class BvhTraversalData
331        { 
332        public:
333               
334                BvhTraversalData():
335                mNode(NULL),
336                mDepth(0),
337                mProbability(0.0),
338                mMaxCostMisses(0),
339                mAxis(0),
340                mNumRays(0)
341                {
342                        mSortedObjects[0] = mSortedObjects[1] = mSortedObjects[2] = NULL;
343                }
344               
345                BvhTraversalData(BvhLeaf *node,
346                                                 const int depth,
347                                                 const float v,
348                                                 const int numRays):
349                mNode(node),
350                mDepth(depth),
351                //mBoundingBox(box),
352                mProbability(v),
353                mMaxCostMisses(0),
354                mAxis(0),
355                mNumRays(numRays)
356                {
357                        mSortedObjects[0] = mSortedObjects[1] = mSortedObjects[2] = NULL;
358                }
359
360                /** Deletes contents and sets them to NULL.
361                */
362                void Clear()
363                {
364                        DEL_PTR(mNode);
365                        DEL_PTR(mSortedObjects[0]);
366                        DEL_PTR(mSortedObjects[1]);
367                        DEL_PTR(mSortedObjects[2]);
368                }
369
370                /// the current node
371                BvhLeaf *mNode;
372                /// current depth
373                int mDepth;
374                /// the probability that this node is seen
375                float mProbability;
376                /// the bounding box of the node
377                //AxisAlignedBox3 mBoundingBox;
378                /// how often this branch has missed the max-cost ratio
379                int mMaxCostMisses;
380                /// current axis
381                int mAxis;
382                /// number of rays
383                int mNumRays;
384                /// the sorted objects for the three dimensions
385                ObjectContainer *mSortedObjects[3];             
386    };
387
388
389        /** Candidate for a object space split.
390        */
391        class BvhSubdivisionCandidate: public SubdivisionCandidate
392        { 
393        public:
394
395        BvhSubdivisionCandidate(const BvhTraversalData &tData): mParentData(tData)
396                {};
397
398                ~BvhSubdivisionCandidate()
399                {
400                        mParentData.Clear();
401                }
402
403                int Type() const { return OBJECT_SPACE; }
404       
405                void EvalPriority(bool computeSplitplane = true)
406                {
407                        if (computeSplitplane)
408                        {
409                                sBvHierarchy->EvalSubdivisionCandidate(*this); 
410                        }
411                        else
412                        {
413                                mPvsEntriesIncr = sBvHierarchy->EvalPvsEntriesIncr(*this);
414                                mPriority = sBvHierarchy->EvalPriority(*this);
415                        }
416                }
417
418                bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet)
419                {
420                        BvhNode *n =
421                                sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet);
422                        // local or global termination criteria failed
423                        return !n->IsLeaf();           
424                }
425
426                void CollectDirtyCandidates(SubdivisionCandidateContainer &dirtyList,
427                                                                        const bool onlyUnmailed)
428                {
429                        sBvHierarchy->CollectDirtyCandidates(this, dirtyList, onlyUnmailed);
430                }
431
432                bool GlobalTerminationCriteriaMet() const
433                {
434                        return sBvHierarchy->GlobalTerminationCriteriaMet(mParentData);
435                }
436
437                BvhSubdivisionCandidate(
438                        const ObjectContainer &frontObjects,
439                        const ObjectContainer &backObjects,
440                        const BvhTraversalData &tData):
441                mFrontObjects(frontObjects), mBackObjects(backObjects), mParentData(tData)
442                {}
443
444                /// pointer to parent tree.
445                static BvHierarchy *sBvHierarchy;
446                /// parent data
447                BvhTraversalData mParentData;
448                /// the objects on the front of the potential split
449                ObjectContainer mFrontObjects;
450                /// the objects on the back of the potential split
451                ObjectContainer mBackObjects;
452        };
453
454        /** Struct for traversing line segment.
455        */
456        struct LineTraversalData
457        {
458                BvhNode *mNode;
459                Vector3 mExitPoint;
460               
461                float mMaxT;
462   
463                LineTraversalData () {}
464                LineTraversalData (BvhNode *n, const Vector3 &p, const float maxt):
465                mNode(n), mExitPoint(p), mMaxT(maxt) {}
466        };
467
468
469        /** Default constructor creating an empty tree.
470        */
471        BvHierarchy();
472
473        /** Default destructor.
474        */
475        ~BvHierarchy();
476
477        /** Returns tree statistics.
478        */
479        const BvhStatistics &GetStatistics() const;
480 
481        /** Returns bounding box of the specified node.
482        */
483        AxisAlignedBox3 GetBoundingBox(BvhNode *node) const;
484
485        /** Reads parameters from environment singleton.
486        */
487        void ReadEnvironment();
488
489        /** Evaluates candidate for splitting.
490        */
491        void EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitData);
492
493        /** Returns list of leaves with pvs smaller than
494                a certain threshold.
495                @param onlyUnmailed if only the unmailed leaves should be considered
496                @param maxPvs the maximal pvs of a leaf to be added (-1 means unlimited)
497        */
498        void CollectLeaves(vector<BvhLeaf *> &leaves) const;
499
500        /** Returns bounding box of the whole tree (= bbox of root node)
501        */
502        AxisAlignedBox3 GetBoundingBox()const;
503
504        /** Returns root of the view space partitioning tree.
505        */
506        BvhNode *GetRoot() const;
507
508        /** A ray is cast possible intersecting the tree.
509                @param the ray that is cast.
510                @returns the number of intersections with objects stored in the tree.
511        */
512        //int CastRay(Ray &ray);
513
514        /** finds neighbouring leaves of this tree node.
515        */
516        int FindNeighbors(BvhLeaf *n,
517                                          vector<BvhLeaf *> &neighbors,
518                                          const bool onlyUnmailed) const;
519
520        /** Returns random leaf of BSP tree.
521                @param halfspace defines the halfspace from which the leaf is taken.
522        */
523        BvhLeaf *GetRandomLeaf(const Plane3 &halfspace);
524
525        /** Returns random leaf of BSP tree.
526                @param onlyUnmailed if only unmailed leaves should be returned.
527        */
528        BvhLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
529
530        /** Casts line segment into the tree.
531                @param origin the origin of the line segment
532                @param termination the end point of the line segment
533                @returns view cells intersecting the line segment.
534        */
535    int CastLineSegment(const Vector3 &origin,
536                                                const Vector3 &termination,
537                                                ViewCellContainer &viewcells);
538               
539        /** Sets pointer to view cells manager.
540        */
541        void SetViewCellsManager(ViewCellsManager *vcm);
542
543        /** Writes tree to output stream
544        */
545        bool Export(OUT_STREAM &stream);
546
547        /** Returns or creates a new intersectable for use in a kd based pvs.
548                The OspTree is responsible for destruction of the intersectable.
549        */
550        BvhIntersectable *GetOrCreateBvhIntersectable(BvhNode *node);
551
552        /** Collects rays associated with the objects.
553        */
554        void CollectRays(const ObjectContainer &objects, VssRayContainer &rays) const;
555
556        /** Intersects box with the tree and returns the number of intersected boxes.
557                @returns number of view cells found
558        */
559        int ComputeBoxIntersections(const AxisAlignedBox3 &box,
560                                                                ViewCellContainer &viewCells) const;
561
562        /** Returns leaf the point pt lies in, starting from root.
563        */
564        BvhLeaf *GetLeaf(Intersectable *obj, BvhNode *root = NULL) const;
565
566        /** Sets a pointer to the view cells tree.
567        */
568        ViewCellsTree *GetViewCellsTree() const { return mViewCellsTree; }
569        /** See Get
570        */
571        void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; }
572
573        /** Returns estimated memory usage of tree.
574        */
575        float GetMemUsage() const;
576
577protected:
578
579        /** Returns true if tree can be terminated.
580        */
581        bool LocalTerminationCriteriaMet(const BvhTraversalData &data) const;
582
583        /** Returns true if global tree can be terminated.
584        */
585        bool GlobalTerminationCriteriaMet(const BvhTraversalData &data) const;
586
587        /** For sorting the objects during the heuristics
588        */
589        struct SortableEntry
590        {
591                Intersectable *mObject;
592                float mPos;
593
594                SortableEntry() {}
595
596                SortableEntry(Intersectable *obj, const float pos):
597                mObject(obj), mPos(pos)
598                {}
599
600                bool operator<(const SortableEntry &b) const
601                {
602                        return mPos < b.mPos;
603                }
604        };
605
606        /** Evaluate balanced object partition.
607        */
608        float EvalLocalObjectPartition(const BvhTraversalData &tData,
609                                                                   const int axis,
610                                                                   ObjectContainer &objectsFront,
611                                                                   ObjectContainer &objectsBack);
612
613        /** Evaluate surface area heuristic for the node.
614        */
615        float EvalSah(const BvhTraversalData &tData,
616                                  const int axis,
617                                  ObjectContainer &objectsFront,
618                                  ObjectContainer &objectsBack);
619
620        /** Computes priority of the traversal data and stores it in tData.
621        */
622        void EvalPriority(BvhTraversalData &tData) const;
623
624        /** Evaluates render cost of the bv induced by these objects
625        */
626        float EvalRenderCost(const ObjectContainer &objects) const;
627
628        /** Evaluates tree stats in the BSP tree leafs.
629        */
630        void EvaluateLeafStats(const BvhTraversalData &data);
631
632        /** Subdivides node using a best split priority queue.
633            @param tQueue the best split priority queue
634                @param splitCandidate the candidate for the next split
635                @param globalCriteriaMet if the global termination criteria were already met
636                @returns new root of the subtree
637        */
638        BvhNode *Subdivide(SplitQueue &tQueue,
639                                           SubdivisionCandidate *splitCandidate,
640                                           const bool globalCriteriaMet);
641       
642        /** Subdivides leaf.
643                @param sc the subdivisionCandidate holding all necessary data for subdivision           
644               
645                @param frontData returns the traversal data for the front node
646                @param backData returns the traversal data for the back node
647
648                @returns the new interior node = the of the subdivision
649        */
650        BvhInterior *SubdivideNode(const BvhSubdivisionCandidate &sc,
651                                                           BvhTraversalData &frontData,
652                                                           BvhTraversalData &backData);
653
654        /** Splits the objects for the next subdivision.
655                @returns cost for this split
656        */
657        float SelectObjectPartition(const BvhTraversalData &tData,
658                                                                ObjectContainer &frontObjects,
659                                                                ObjectContainer &backObjects);
660       
661        /** Writes the node to disk
662                @note: should be implemented as visitor.
663        */
664        void ExportNode(BvhNode *node, OUT_STREAM &stream);
665
666        /** Exports objects associated with this leaf.
667        */
668        void ExportObjects(BvhLeaf *leaf, OUT_STREAM &stream);
669
670        /** Associates the objects with their bvh leaves.
671        */
672        static void AssociateObjectsWithLeaf(BvhLeaf *leaf);
673
674
675        /////////////////////////////
676        // Helper functions for local cost heuristics
677       
678        /** Prepare split candidates for cost heuristics using axis aligned splits.
679                @param node the current node
680                @param axis the current split axis
681        */
682        void PrepareLocalSubdivisionCandidates(const BvhTraversalData &tData,
683                                                                                   const int axis);
684
685        static void CreateLocalSubdivisionCandidates(const ObjectContainer &objects,
686                                                                                                 SortableEntryContainer **subdivisionCandidates,
687                                                                                                 const bool sort,
688                                                                                                 const int axis);
689
690        /** Computes object partition with the best cost according to the heurisics.
691                @param tData the traversal data
692                @param axis the split axis
693                @param objectsFront the objects in the front child bv
694                @param objectsBack the objects in the back child bv
695                @param backObjectsStart the iterator marking the position where the back objects begin
696
697                @returns relative cost (relative to parent cost)
698        */
699        float EvalLocalCostHeuristics(const BvhTraversalData &tData,
700                                                                  const int axis,
701                                                                  ObjectContainer &objectsFront,
702                                                                  ObjectContainer &objectsBack);
703
704        /** Evaluates the contribution to the front and back volume
705                when this object is changing sides in the bvs.
706
707                @param object the object
708                @param volLeft updates the left pvs
709                @param volPvs updates the right pvs
710        */
711        void EvalHeuristicsContribution(Intersectable *obj,
712                                                                        float &volLeft,
713                                                                        float &volRight);
714
715        /** Prepares objects for the cost heuristics.
716                @returns sum of volume of associated view cells
717        */
718        float PrepareHeuristics(const BvhTraversalData &tData, const int axis);
719       
720        /** Reevaluates the priority of this split candidate
721                @returns priority
722        */
723        float EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const;
724
725        ////////////////////////////////////////////////
726
727
728        /** Prepares construction for vsp and osp trees.
729        */
730        AxisAlignedBox3 EvalBoundingBox(const ObjectContainer &objects,
731                                                                        const AxisAlignedBox3 *parentBox = NULL) const;
732
733        /** Collects list of invalid candidates. Candidates
734                are invalidated by a view space subdivision step
735                that affects this candidate.
736        */
737        void CollectDirtyCandidates(BvhSubdivisionCandidate *sc,
738                                                                vector<SubdivisionCandidate *> &dirtyList,
739                                                                const bool onlyUnmailed);
740
741        /** Collect view cells which see this bvh leaf.
742        */
743        void CollectViewCells(const ObjectContainer &objects,
744                                                  ViewCellContainer &viewCells,
745                                                  const bool setCounter = false) const;
746
747        /** Counts the view cells of this object. note: only
748                counts unmailed objects.
749        */
750        int CountViewCells(Intersectable *obj) const;
751
752        /** Counts the view cells seen by this bvh leaf
753        */
754        int CountViewCells(const ObjectContainer &objects) const;
755
756        /** Collects view cells which see an object.
757        */
758        void CollectViewCells(Intersectable *object,
759                                                  ViewCellContainer &viewCells,
760                                                  const bool useMailBoxing,
761                                                  const bool setCounter = false) const;
762
763        /** Evaluates increase in pvs size.
764        */
765        int EvalPvsEntriesIncr(BvhSubdivisionCandidate &splitCandidate) const;
766
767        /** Rays will be clipped to the bounding box.
768        */
769        void PreprocessRays(BvhLeaf *root,
770                                                const VssRayContainer &sampleRays,
771                                                RayInfoContainer &rays);
772
773        /** Print the subdivision stats in the subdivison log.
774        */
775        void PrintSubdivisionStats(const SubdivisionCandidate &tData);
776
777        /** Prints out the stats for this subdivision.
778        */
779        void AddSubdivisionStats(const int viewCells,
780                                                         const float renderCostDecr,
781                                                         const float totalRenderCost);
782
783        /** Stores rays with objects that see the rays.
784        */
785        int AssociateObjectsWithRays(const VssRayContainer &rays) const;
786
787        /** Tests if object is in this leaf.
788                @note: assumes that objects are sorted by their id.
789        */
790        bool IsObjectInLeaf(BvhLeaf *, Intersectable *object) const;
791
792        /** Prepares the construction of the bv hierarchy and returns
793                the first subdivision candidate.
794        */
795        SubdivisionCandidate *PrepareConstruction(const VssRayContainer &sampleRays,
796                                                                                          const ObjectContainer &objects);
797
798        /** Resets bv hierarchy. E.g. deletes root and resets stats.
799        */
800        SubdivisionCandidate *Reset(const VssRayContainer &rays,
801                                                                const ObjectContainer &objects);
802
803        /** Evaluates volume of view cells that see the objects.
804        */
805        float EvalViewCellsVolume(const ObjectContainer &objects) const;
806
807        /** Assigns or newly creates initial list of sorted objects.
808        */
809        void AssignInitialSortedObjectList(BvhTraversalData &tData);
810
811        /** Assigns sorted objects to front and back data.
812        */
813        void AssignSortedObjects(const BvhSubdivisionCandidate &sc,
814                                                         BvhTraversalData &frontData,
815                                                         BvhTraversalData &backData);
816       
817        /** Creates new root of hierarchy and computes bounding box.
818                Has to be called before the preparation of the subdivision.
819        */
820        void Initialise(const ObjectContainer &objects);
821
822
823protected:
824       
825        /// pre-sorted subdivision candidtes for all three directions.
826        vector<SortableEntry> *mGlobalSubdivisionCandidates[3];
827        /// pointer to the hierarchy of view cells
828        ViewCellsTree *mViewCellsTree;
829        /// The view cells manager
830        ViewCellsManager *mViewCellsManager;
831        /// candidates for placing split planes during cost heuristics
832        vector<SortableEntry> *mSubdivisionCandidates;
833        /// Pointer to the root of the tree
834        BvhNode *mRoot;
835        /// Statistics for the object space partition
836        BvhStatistics mBvhStats;       
837        /// box around the whole view domain
838        AxisAlignedBox3 mBoundingBox;
839        /// the hierarchy manager
840        HierarchyManager *mHierarchyManager;
841
842
843        ////////////////////
844        //-- local termination criteria
845
846        /// maximal possible depth
847        int mTermMaxDepth;
848        /// mininum probability
849        float mTermMinProbability;
850        /// minimal number of objects
851        int mTermMinObjects;
852        /// maximal acceptable cost ratio
853        float mTermMaxCostRatio;
854        /// tolerance value indicating how often the max cost ratio can be failed
855        int mTermMissTolerance;
856        /// minimum number of rays
857        int mTermMinRays;
858
859
860        ////////////////////
861        //-- global termination criteria
862
863        /// the minimal accepted global cost ratio
864        float mTermMinGlobalCostRatio;
865        //// number of accepted misses of the global cost ratio
866        int mTermGlobalCostMissTolerance;
867        /// maximal number of view cells
868        int mTermMaxLeaves;
869        /// maximal tree memory
870        float mMaxMemory;
871        /// the tree is out of memory
872        bool mOutOfMemory;
873
874
875        ////////////////////////////////////////
876        //-- split heuristics based parameters
877       
878        /// if a heuristics should be used for finding a split plane
879    bool mUseCostHeuristics;
880        /// if sah heuristcs should be used for finding a split plane
881        bool mUseSah;
882    /// balancing factor for PVS criterium
883        float mCtDivCi;
884        /// if only driving axis should be used for split
885        bool mOnlyDrivingAxis;
886        /// current time stamp (used for keeping split history)
887        int mTimeStamp;
888        // if rays should be stored in leaves
889        bool mStoreRays;
890        // subdivision stats output file
891        ofstream  mSubdivisionStats;
892        /// keeps track of cost during subdivision
893        float mTotalCost;
894        int mPvsEntries;
895        /// keeps track of overall pvs size during subdivision
896        int mTotalPvsSize;
897        /// number of currenly generated view cells
898        int mCreatedLeaves;
899        /// represents min and max band for sweep
900        float mSplitBorder;
901        /// weight between render cost decrease and node render cost
902        float mRenderCostDecreaseWeight;
903        /// stores the kd node intersectables used for pvs
904        BvhIntersectableMap mBvhIntersectables;
905        /// if the objects should be sorted in one global step
906        bool mUseGlobalSorting;
907
908        bool mUseBboxAreaForSah;
909
910        SortableEntryContainer *mSortedObjects[3];
911};
912
913}
914
915#endif
Note: See TracBrowser for help on using the repository browser.