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

Revision 1004, 23.7 KB checked in by mattausch, 18 years ago (diff)

environment as a singleton

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