source: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h @ 870

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

added pvs

Line 
1#ifndef _VspBspTree_H__
2#define _VspBspTree_H__
3
4#include "Mesh.h"
5#include "Containers.h"
6#include "Polygon3.h"
7#include <stack>
8#include "Statistics.h"
9#include "VssRay.h"
10#include "RayInfo.h"
11#include "ViewCellBsp.h"
12
13namespace GtpVisibilityPreprocessor {
14
15class ViewCell;
16//class BspViewCell;
17class Plane3;
18class VspBspTree; 
19class BspInterior;
20class BspNode;
21class AxisAlignedBox3;
22class Ray;
23class ViewCellsStatistics;
24class ViewCellsManager;
25class MergeCandidate;
26class Beam;
27class ViewCellsTree;
28class Environment;
29
30/**
31        This is a view space partitioning specialised BSPtree. 
32        There are no polygon splits, but we split the sample rays.
33        The candidates for the next split plane are evaluated only
34        by checking the sampled visibility information.
35        The polygons are employed merely as candidates for the next split planes.
36*/
37class VspBspTree
38{
39        friend class ViewCellsParseHandlers;
40        friend class VspBspViewCellsManager;
41public:
42       
43        /** Additional data which is passed down the BSP tree during traversal.
44        */
45        class VspBspTraversalData
46        { 
47        public:
48                /// the current node
49                BspNode *mNode;
50                /// polygonal data for splitting
51                PolygonContainer *mPolygons;
52                /// current depth
53                int mDepth;
54                /// rays piercing this node
55                RayInfoContainer *mRays;
56                /// the probability that this node contains view point
57                float mProbability;
58                /// geometry of node as induced by planes
59                BspNodeGeometry *mGeometry;
60                /// pvs size
61                int mPvs;
62                /// how often this branch has missed the max-cost ratio
63                int mMaxCostMisses;
64                /// if this node is a kd-node (i.e., boundaries are axis aligned
65                bool mIsKdNode;
66                // current axis
67                int mAxis;
68                // current priority
69                float mPriority;
70
71               
72                /** Returns average ray contribution.
73                */
74                float GetAvgRayContribution() const
75                {
76                        return (float)mPvs / ((float)mRays->size() + Limits::Small);
77                }
78
79
80                VspBspTraversalData():
81                mNode(NULL),
82                mPolygons(NULL),
83                mDepth(0),
84                mRays(NULL),
85                mPvs(0),
86                mProbability(0.0),
87                mGeometry(NULL),
88                mMaxCostMisses(0),
89                mIsKdNode(false),
90                mPriority(0),
91                mAxis(0)
92                {}
93               
94                VspBspTraversalData(BspNode *node,
95                                                        PolygonContainer *polys,
96                                                        const int depth,
97                                                        RayInfoContainer *rays,
98                                                        const int pvs,
99                                                        const float p,
100                                                        BspNodeGeometry *geom):
101                mNode(node),
102                mPolygons(polys),
103                mDepth(depth),
104                mRays(rays),
105                mPvs(pvs),
106                mProbability(p),
107                mGeometry(geom),
108                mMaxCostMisses(0),
109                mIsKdNode(false),
110                mPriority(0),
111                mAxis(0)
112                {}
113
114                VspBspTraversalData(PolygonContainer *polys,
115                                                        const int depth,
116                                                        RayInfoContainer *rays,
117                                                        BspNodeGeometry *geom):
118                mNode(NULL),
119                mPolygons(polys),
120                mDepth(depth),
121                mRays(rays),
122                mPvs(0),
123                mProbability(0),
124                mGeometry(geom),
125                mMaxCostMisses(0),
126                mIsKdNode(false),
127                mAxis(0)
128                {}
129
130                /** Returns cost of the traversal data.
131                */
132                float GetCost() const
133                {
134                        //cout << mPriority << endl;
135                        return mPriority;
136                }
137
138                // deletes contents and sets them to NULL
139                void Clear()
140                {
141                        DEL_PTR(mPolygons);
142                        DEL_PTR(mRays);
143                        DEL_PTR(mGeometry);
144                }
145
146                friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b)
147                {
148                        return a.GetCost() < b.GetCost();
149                }
150    };
151       
152
153        typedef std::priority_queue<VspBspTraversalData> VspBspTraversalQueue;
154       
155       
156        struct VspBspSplitCandidate
157        { 
158                /// the current node
159                Plane3 mSplitPlane;
160                /// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned)
161                int mSplitAxis;
162                /// the number of misses of max cost ratio until this split
163                int mMaxCostMisses;
164
165                // parent data
166                VspBspTraversalData mParentData;
167                // cost of applying this split
168                float mRenderCost;
169
170                VspBspSplitCandidate(): mRenderCost(0)
171                {};
172
173                VspBspSplitCandidate(const Plane3 &plane, const VspBspTraversalData &tData):
174                mSplitPlane(plane), mParentData(tData), mRenderCost(0)
175                {}
176
177                /** Returns cost of the traversal data.
178                */
179                float GetCost() const
180                {
181#if 1
182                        return mRenderCost;
183#endif
184#if 0
185                        return (float) (-mDepth); // for kd tree
186#endif
187                }
188
189                friend bool operator<(const VspBspSplitCandidate &a, const VspBspSplitCandidate &b)
190                {
191                        return a.GetCost() < b.GetCost();
192                }
193    };
194
195        typedef std::priority_queue<VspBspSplitCandidate> VspBspSplitQueue;
196
197        /** Default constructor creating an empty tree.
198        */
199        VspBspTree();
200
201       
202        /** Constructor creating an empty tree. Loads parameters
203                from an environment file.
204        */
205        VspBspTree(Environment *env);
206
207        /** Default destructor.
208        */
209        ~VspBspTree();
210
211        /** Returns BSP Tree statistics.
212        */
213        const BspTreeStatistics &GetStatistics() const;
214 
215
216        /** Constructs the tree from a given set of rays.
217                @param sampleRays the set of sample rays the construction is based on
218                @param viewCells if not NULL, new view cells are
219                created in the leafs and stored in the container
220        */
221        void Construct(const VssRayContainer &sampleRays,
222                                   AxisAlignedBox3 *forcedBoundingBox);
223
224        /** Returns list of BSP leaves with pvs smaller than
225                a certain threshold.
226                @param onlyUnmailed if only the unmailed leaves should be considered
227                @param maxPvs the maximal pvs (-1 means unlimited)
228        */
229        void CollectLeaves(vector<BspLeaf *> &leaves,
230                                           const bool onlyUnmailed = false,
231                                           const int maxPvs = -1) const;
232
233        /** Returns box which bounds the whole tree.
234        */
235        AxisAlignedBox3 GetBoundingBox()const;
236
237        /** Returns root of BSP tree.
238        */
239        BspNode *GetRoot() const;
240
241        /** Collects the leaf view cells of the tree
242                @param viewCells returns the view cells
243        */
244        void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const;
245
246        /** A ray is cast possible intersecting the tree.
247                @param the ray that is cast.
248                @returns the number of intersections with objects stored in the tree.
249        */
250        int CastRay(Ray &ray);
251
252        /// bsp tree construction types
253        enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES};
254
255        /** finds neighbouring leaves of this tree node.
256        */
257        int FindNeighbors(BspNode *n,
258                                          vector<BspLeaf *> &neighbors,
259                                          const bool onlyUnmailed) const;
260
261        /** Constructs geometry associated with the half space intersections
262                leading to this node.
263        */
264        void ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const;
265       
266        /** Construct geometry of view cell.
267        */
268        void ConstructGeometry(ViewCell *vc, BspNodeGeometry &geom) const;
269
270        /** Returns random leaf of BSP tree.
271                @param halfspace defines the halfspace from which the leaf is taken.
272        */
273        BspLeaf *GetRandomLeaf(const Plane3 &halfspace);
274
275        /** Returns random leaf of BSP tree.
276                @param onlyUnmailed if only unmailed leaves should be returned.
277        */
278        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
279
280        /** Returns epsilon of this tree.
281        */
282        float GetEpsilon() const;
283
284        /** Casts line segment into the tree.
285                @param origin the origin of the line segment
286                @param termination the end point of the line segment
287                @returns view cells intersecting the line segment.
288        */
289    int CastLineSegment(const Vector3 &origin,
290                                                const Vector3 &termination,
291                                                ViewCellContainer &viewcells);
292
293               
294        /** Sets pointer to view cells manager.
295        */
296        void SetViewCellsManager(ViewCellsManager *vcm);
297
298        /** Returns distance from node 1 to node 2.
299        */
300        int TreeDistance(BspNode *n1, BspNode *n2) const;
301
302        /** Collapses the tree with respect to the view cell partition.
303                @returns number of collapsed nodes
304        */
305        int CollapseTree();
306
307        /** Returns view cell the current point is located in.
308        */
309        ViewCell *GetViewCell(const Vector3 &point);
310
311
312        /** Returns true if this view point is in a valid view space,
313                false otherwise.
314        */
315        bool ViewPointValid(const Vector3 &viewPoint) const;
316
317        /** Returns view cell corresponding to
318                the invalid view space.
319        */
320        BspViewCell *GetOutOfBoundsCell();
321
322        /** Writes tree to output stream
323        */
324        bool Export(ofstream &stream);
325
326        /** Casts beam, i.e. a 5D frustum of rays, into tree.
327                Tests conservative using the bounding box of the nodes.
328                @returns number of view cells it intersected
329        */
330        int CastBeam(Beam &beam);
331
332        /** Finds approximate neighbours, i.e., finds correct neighbors
333                in most cases but sometimes more.
334        */
335        int FindApproximateNeighbors(BspNode *n,
336                                                             vector<BspLeaf *> &neighbors,
337                                                                 const bool onlyUnmailed) const;
338
339        /** Checks if tree validity-flags are right
340                with respect to view cell valitiy.
341                If not, marks subtree as invalid.
342        */
343        void ValidateTree();
344
345        /** Invalid view cells are added to the unbounded space
346        */
347        void CollapseViewCells();
348
349        /** Collects rays stored in the leaves.
350        */
351        void CollectRays(VssRayContainer &rays);
352
353        /** Intersects box with the tree and returns the number of intersected boxes.
354                @returns number of view cells found
355        */
356        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
357
358        // pointer to the hierarchy of view cells
359        ViewCellsTree *mViewCellsTree;
360
361
362protected:
363
364        // --------------------------------------------------------------
365        // For sorting objects
366        // --------------------------------------------------------------
367        struct SortableEntry
368        {
369                enum EType
370                {
371                        ERayMin,
372                        ERayMax
373                };
374
375                int type;
376                float value;
377                VssRay *ray;
378 
379                SortableEntry() {}
380                SortableEntry(const int t, const float v, VssRay *r):type(t),
381                                          value(v), ray(r)
382                {
383                }
384               
385                friend bool operator<(const SortableEntry &a, const SortableEntry &b)
386                {
387                        return a.value < b.value;
388                }
389        };
390
391        /** faster evaluation of split plane cost for kd axis aligned cells.
392        */
393        float EvalAxisAlignedSplitCost(const VspBspTraversalData &data,
394                                                                   const AxisAlignedBox3 &box,
395                                                                   const int axis,
396                                                                   const float &position,
397                                                                   float &pFront,
398                                                                   float &pBack) const;
399
400        /** Evaluates candidate for splitting.
401        */
402        void EvalSplitCandidate(VspBspTraversalData &tData, VspBspSplitCandidate &splitData);
403
404        /** Computes priority of the traversal data and stores it in tData.
405        */
406        void EvalPriority(VspBspTraversalData &tData) const;
407
408        /** Evaluates render cost decrease of next split.
409        */
410        float EvalRenderCostDecrease(const Plane3 &candidatePlane,
411                                                                 const VspBspTraversalData &data) const;
412
413        /** Constructs tree using the split priority queue.
414        */
415        void ConstructWithSplitQueue(const PolygonContainer &polys, RayInfoContainer *rays);
416
417        /** Collects view cells in the subtree under root.
418        */
419        void CollectViewCells(BspNode *root,
420                                                  bool onlyValid,
421                                                  ViewCellContainer &viewCells,
422                                                  bool onlyUnmailed = false) const;
423
424        /** Returns view cell corresponding to
425                the invalid view space. If it does not exist, it is created.
426        */
427        BspViewCell *GetOrCreateOutOfBoundsCell();
428
429        /** Collapses the tree with respect to the view cell partition,
430                i.e. leaves having the same view cell are collapsed.
431                @param node the root of the subtree to be collapsed
432                @param collapsed returns the number of collapsed nodes
433                @returns node of type leaf if the node could be collapsed,
434                this node otherwise
435        */
436        BspNode *CollapseTree(BspNode *node, int &collapsed);
437
438        /** Helper function revalidating the view cell leaf list after merge.
439        */
440        void RepairViewCellsLeafLists();
441
442        /** Evaluates tree stats in the BSP tree leafs.
443        */
444        void EvaluateLeafStats(const VspBspTraversalData &data);
445
446        /** Subdivides node with respect to the traversal data.
447            @param tStack current traversal stack
448                @param tData traversal data also holding node to be subdivided
449                @returns new root of the subtree
450        */
451        BspNode *Subdivide(VspBspTraversalQueue &tStack,
452                                           VspBspTraversalData &tData);
453
454        BspNode *Subdivide(VspBspSplitQueue &tQueue,
455                                           VspBspSplitCandidate &splitCandidate);
456
457        /** Constructs the tree from the given traversal data.
458                @param polys stores set of polygons on which subdivision may be based
459                @param rays storesset of rays on which subdivision may be based
460        */
461        void Construct(const PolygonContainer &polys, RayInfoContainer *rays);
462
463        /** Selects the best possible splitting plane.
464                @param plane returns the split plane
465                @param leaf the leaf to be split
466                @param polys the polygon list on which the split decition is based
467                @param rays ray container on which selection may be based
468                @note the polygons can be reordered in the process
469                @returns true if the cost of the split is under maxCostRatio
470
471        */
472        bool SelectPlane(Plane3 &plane,
473                                         BspLeaf *leaf,
474                                         VspBspTraversalData &data,
475                                         VspBspTraversalData &frontData,
476                                         VspBspTraversalData &backData,
477                                         int &splitAxis);
478       
479        /** Strategies where the effect of the split plane is tested
480            on all input rays.
481
482                @returns the cost of the candidate split plane
483        */
484        float EvalSplitPlaneCost(const Plane3 &candidatePlane,
485                                                         const VspBspTraversalData &data,
486                                                         BspNodeGeometry &geomFront,
487                                                         BspNodeGeometry &geomBack,
488                                                         float &pFront,
489                                                         float &pBack) const;
490
491        /** Subdivides leaf.
492                @param leaf the leaf to be subdivided
493               
494                @param polys the polygons to be split
495                @param frontPolys returns the polygons in front of the split plane
496                @param backPolys returns the polygons in the back of the split plane
497               
498                @param rays the polygons to be filtered
499                @param frontRays returns the polygons in front of the split plane
500                @param backRays returns the polygons in the back of the split plane
501
502                @returns the root of the subdivision
503        */
504
505        BspInterior *SubdivideNode(const Plane3 &splitPlane,
506                                                           VspBspTraversalData &tData,
507                                                           VspBspTraversalData &frontData,
508                               VspBspTraversalData &backData,
509                                                           PolygonContainer &coincident);
510
511        /** Extracts the meshes of the objects and adds them to polygons.
512                Adds object aabb to the aabb of the tree.
513                @param maxPolys the maximal number of objects to be stored as polygons
514                @returns the number of polygons
515        */
516        int AddToPolygonSoup(const ObjectContainer &objects,
517                                                 PolygonContainer &polys,
518                                                 int maxObjects = 0);
519
520        /** Extracts the meshes of the view cells and and adds them to polygons.
521                Adds view cell aabb to the aabb of the tree.
522                @param maxPolys the maximal number of objects to be stored as polygons
523                @returns the number of polygons
524        */
525        int AddToPolygonSoup(const ViewCellContainer &viewCells,
526                                                 PolygonContainer &polys,
527                                                 int maxObjects = 0);
528
529        /** Extract polygons of this mesh and add to polygon container.
530                @param mesh the mesh that drives the polygon construction
531                @param parent the parent intersectable this polygon is constructed from
532                @returns number of polygons
533        */
534        int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent);
535
536        /** Selects an axis aligned for the next split.
537                @returns cost for this split
538        */
539        float SelectAxisAlignedPlane(Plane3 &plane,
540                                                                 const VspBspTraversalData &tData,
541                                                                 int &axis,
542                                                                 BspNodeGeometry **frontGeom,
543                                                                 BspNodeGeometry **backGeom,
544                                                                 float &pFront,
545                                                                 float &pBack,
546                                                                 const bool useKdSplit);
547
548        /** Sorts split candidates for surface area heuristics for axis aligned splits.
549                @param polys the input for choosing split candidates
550                @param axis the current split axis
551                @param splitCandidates returns sorted list of split candidates
552        */
553        void SortSplitCandidates(const RayInfoContainer &rays,
554                                                         const int axis,
555                                                         float minBand,
556                                                         float maxBand);
557
558        /** Computes best cost for axis aligned planes.
559        */
560        float BestCostRatioHeuristics(const RayInfoContainer &rays,
561                                                                  const AxisAlignedBox3 &box,
562                                                                  const int pvsSize,
563                                                                  const int axis,
564                                                                  float &position);
565
566        /** Selects an axis aligned split plane.
567                @Returns true if split is valied
568        */
569        bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const;
570
571        /** Subdivides the rays into front and back rays according to the split plane.
572               
573                @param plane the split plane
574                @param rays contains the rays to be split. The rays are
575                           distributed into front and back rays.
576                @param frontRays returns rays on the front side of the plane
577                @param backRays returns rays on the back side of the plane
578               
579                @returns the number of splits
580        */
581        int SplitRays(const Plane3 &plane,
582                                  RayInfoContainer &rays,
583                              RayInfoContainer &frontRays,
584                                  RayInfoContainer &backRays) const;
585
586
587        /** Extracts the split planes representing the space bounded by node n.
588        */
589        void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const;
590
591        /** Adds the object to the pvs of the front and back leaf with a given classification.
592
593                @param obj the object to be added
594                @param cf the ray classification regarding the split plane
595                @param frontPvs returns the PVS of the front partition
596                @param backPvs returns the PVS of the back partition
597       
598        */
599        void AddObjToPvs(Intersectable *obj,
600                                         const int cf,
601                                         float &frontPvs,
602                                         float &backPvs,
603                                         float &totalPvs) const;
604       
605        /** Computes PVS size induced by the rays.
606        */
607        int ComputePvsSize(const RayInfoContainer &rays) const;
608
609        /** Returns true if tree can be terminated.
610        */
611        inline bool LocalTerminationCriteriaMet(const VspBspTraversalData &data) const;
612
613        /** Returns true if global tree can be terminated.
614        */
615        inline bool GlobalTerminationCriteriaMet(const VspBspTraversalData &data) const;
616
617        /** Computes accumulated ray lenght of this rays.
618        */
619        float AccumulatedRayLength(const RayInfoContainer &rays) const;
620
621        /** Splits polygons with respect to the split plane.
622
623                @param plane the split plane
624                @param polys the polygons to be split. the polygons are consumed and
625                           distributed to the containers frontPolys, backPolys, coincident.
626                @param frontPolys returns the polygons in the front of the split plane
627                @param backPolys returns the polygons in the back of the split plane
628                @param coincident returns the polygons coincident to the split plane
629
630                @returns the number of splits   
631        */
632        int SplitPolygons(const Plane3 &plane,
633                                          PolygonContainer &polys,
634                                          PolygonContainer &frontPolys,
635                                          PolygonContainer &backPolys,
636                                          PolygonContainer &coincident) const;
637
638        /** Adds ray sample contributions to the PVS.
639                @param sampleContributions the number contributions of the samples
640                @param contributingSampels the number of contributing rays
641               
642        */
643        void AddToPvs(BspLeaf *leaf,
644                                  const RayInfoContainer &rays,
645                                  float &sampleContributions,
646                                  int &contributingSamples);
647
648
649
650
651
652       
653        /** Take 3 ray endpoints, where two are minimum and one a maximum
654                point or the other way round.
655        */
656        Plane3 ChooseCandidatePlane(const RayInfoContainer &rays) const;
657
658        /** Take plane normal as plane normal and the midpoint of the ray.
659                PROBLEM: does not resemble any point where visibility is
660                likely to change
661        */
662        Plane3 ChooseCandidatePlane2(const RayInfoContainer &rays) const;
663
664        /** Fit the plane between the two lines so that the plane
665                has equal shortest distance to both lines.
666        */
667        Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const;
668 
669        /** Collects candidates for merging.
670                @param leaves the leaves to be merged
671                @returns number of leaves in queue
672        */
673        int CollectMergeCandidates(const vector<BspLeaf *> leaves, vector<MergeCandidate> &candidates);
674
675        /** Collects candidates for the merge in the merge queue.
676                @returns number of leaves in queue
677        */
678        int CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
679       
680        /** Preprocesses polygons and throws out all polygons which are coincident to
681                the view space box faces (they can be problematic).
682        */
683        void PreprocessPolygons(PolygonContainer &polys);
684       
685        /** Propagates valid flag up the tree.
686        */
687        void PropagateUpValidity(BspNode *node);
688
689        /** Writes the node to disk
690                @note: should be implemented as visitor
691        */
692        void ExportNode(BspNode *node, ofstream &stream);
693
694        /** Returns estimated memory usage of tree.
695        */
696        //float GetMemUsage(const VspBspTraversalQueue &tstack) const;
697        float GetMemUsage() const;
698
699
700
701        /// Pointer to the root of the tree
702        BspNode *mRoot;
703               
704        BspTreeStatistics mBspStats;
705
706        /// Strategies for choosing next split plane.
707        enum {NO_STRATEGY = 0,
708                  RANDOM_POLYGON = 1,
709                  AXIS_ALIGNED = 2,
710                  LEAST_RAY_SPLITS = 256,
711                  BALANCED_RAYS = 512,
712                  PVS = 1024
713                };
714
715        /// box around the whole view domain
716        AxisAlignedBox3 mBox;
717
718        bool mUseCostHeuristics;
719
720        /// minimal number of rays before subdivision termination
721        int mTermMinRays;
722        /// maximal possible depth
723        int mTermMaxDepth;
724        /// mininum probability
725        float mTermMinProbability;
726        /// mininum PVS
727        int mTermMinPvs;
728        /// maximal contribution per ray
729        float mTermMaxRayContribution;
730        /// minimal accumulated ray length
731        float mTermMinAccRayLength;
732
733        //HACK
734        int mTermMinPolygons;
735
736        float mTermMinGlobalCostRatio;
737        int mTermGlobalCostMissTolerance;
738
739        int mGlobalCostMisses;
740
741        bool mUseSplitCostQueue;
742        //-- termination criteria for axis aligned split
743
744        /// minimal number of rays for axis aligned split
745        int mTermMinRaysForAxisAligned;
746        // max ray contribution
747        float mTermMaxRayContriForAxisAligned;
748
749        /// strategy to get the best split plane
750        int mSplitPlaneStrategy;
751        /// number of candidates evaluated for the next split plane
752        int mMaxPolyCandidates;
753        /// number of candidates for split planes evaluated using the rays
754        int mMaxRayCandidates;
755        /// balancing factor for PVS criterium
756        float mCtDivCi;
757
758        bool mUseDrivingAxisForMaxCost;
759        //-- axis aligned split criteria
760        float mAxisAlignedCtDivCi;
761        /// spezifies the split border of the axis aligned split
762        float mAxisAlignedSplitBorder;
763
764        /// maximal acceptable cost ratio
765        float mTermMaxCostRatio;
766        /// tolerance value indicating how often the max cost ratio can be failed
767        int mTermMissTolerance;
768
769        //-- factors guiding the split plane heuristics
770        float mLeastRaySplitsFactor;
771        float mBalancedRaysFactor;
772        float mPvsFactor;
773
774        /// if area or volume should be used for PVS heuristics
775        bool mUseAreaForPvs;
776        /// tolerance for polygon split
777        float mEpsilon;
778        /// maximal number of test rays used to evaluate candidate split plane
779        int mMaxTests;
780        /// normalizes different bsp split plane criteria
781        float mCostNormalizer;
782        /// maximal number of view cells
783        int mMaxViewCells;
784       
785        ofstream  mSubdivisionStats;
786
787        // if rays should be stored in leaves
788        bool mStoreRays;
789       
790        /// if only driving axis should be used for split
791        bool mOnlyDrivingAxis;
792
793        ViewCellsManager *mViewCellsManager;
794
795        vector<SortableEntry> *mSplitCandidates;
796
797       
798        float mRenderCostWeight;
799        /// View cell corresponding to the space outside the valid view space
800        BspViewCell *mOutOfBoundsCell;
801
802        /// maximal tree memory
803        float mMaxMemory;
804        /// the tree is out of memory
805        bool mOutOfMemory;
806       
807        float mTotalCost;
808        int mTotalPvsSize;
809
810        float mMinBand;
811        float mMaxBand;
812
813        //int mSplits;
814        /// subdivision stats output file
815        ofstream mSubdivsionStats;
816        /// if random split axis should be used
817        bool mUseRandomAxis;
818        /// use polygon split whenever there are polys left
819        bool mUsePolygonSplitIfAvailable;
820        /// current time stamp (used for keeping split history)
821        int mTimeStamp;
822        /// number of currenly generated view cells
823        int mCreatedViewCells;
824        /// if vsp bsp tree should simulate octree
825        bool mCirculatingAxis;
826
827        /// if we should use breath first priority for the splits
828        int mNodePriorityQueueType;
829
830        bool mEmptyViewCellsMergeAllowed;
831
832        // priority queue strategy
833        enum {BREATH_FIRST, DEPTH_FIRST, COST_BASED};
834private:
835
836        /// Generates unique ids for PVS criterium
837        static void GenerateUniqueIdsForPvs();
838
839        //-- unique ids for PVS criterium
840        static int sFrontId;
841        static int sBackId;
842        static int sFrontAndBackId;
843};
844
845}
846
847
848#endif
Note: See TracBrowser for help on using the repository browser.