source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h @ 472

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

added priority queue to vspbsptree

Line 
1#ifndef _ViewCellBsp_H__
2#define _ViewCellBsp_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 "ViewCell.h"
11
12class ViewCell;
13//class BspViewCell;
14class Plane3;
15class BspTree; 
16class BspInterior;
17//class Polygon3;
18class AxisAlignedBox3;
19class Ray;
20class ViewCellsStatistics;
21
22class BspNodeGeometry
23{
24public:
25        BspNodeGeometry()
26        {}; 
27
28        ~BspNodeGeometry();
29
30        float GetArea() const;
31       
32        /** Computes new front and back geometry based on the old cell
33                geometry and a new split plane
34        */
35        void SplitGeometry(BspNodeGeometry &front,
36                                           BspNodeGeometry &back,
37                                           const Plane3 &splitPlane,
38                       const AxisAlignedBox3 &box,
39                                           const float epsilon) const;
40
41        Polygon3 *SplitPolygon(Polygon3 *poly, const float epsilon) const;
42
43        PolygonContainer mPolys;
44};
45
46/** Data structure used for optimized ray casting.
47*/
48struct BspRayTraversalData
49{
50    BspNode *mNode;
51    Vector3 mExitPoint;
52    float mMaxT;
53   
54    BspRayTraversalData() {}
55
56    BspRayTraversalData(BspNode *n, const Vector3 &extp, const float maxt):
57    mNode(n), mExitPoint(extp), mMaxT(maxt)
58        {}
59};
60
61/** Data used for passing ray data down the tree.
62*/
63struct BoundedRay
64{
65        Ray *mRay;
66        float mMinT;
67        float mMaxT;
68               
69        BoundedRay(): mMinT(0), mMaxT(1e6), mRay(NULL)
70        {}
71        BoundedRay(Ray *r, float minT, float maxT):
72        mRay(r), mMinT(minT), mMaxT(maxT)
73        {}
74};
75
76typedef vector<BoundedRay *> BoundedRayContainer;
77
78class BspTreeStatistics: public StatisticsBase
79{
80public:
81        // total number of nodes
82        int nodes;
83        // number of splits
84        int splits;
85        // totals number of rays
86        int rays;
87        // maximal reached depth
88        int maxDepth;
89        // minimal depth
90        int minDepth;
91       
92        // max depth nodes
93        int maxDepthNodes;
94        // minimum depth nodes
95        int minDepthNodes;
96        // max depth nodes
97        int minPvsNodes;
98        // nodes with minimum PVS
99        int minRaysNodes;
100        // max ray contribution nodes
101        int maxRayContribNodes;
102        // minimum area nodes
103        int minAreaNodes;
104
105        // max number of rays per node
106        int maxObjectRefs;
107        // accumulated depth (used to compute average)
108        int accumDepth;
109        // number of initial polygons
110        int polys;
111        /// samples contributing to pvs
112        int contributingSamples;
113        /// sample contributions to pvs
114        int sampleContributions;
115        /// largest pvs
116        int largestPvs;
117
118        // Constructor
119        BspTreeStatistics()
120        {
121                Reset();
122        }
123
124        int Nodes() const {return nodes;}
125        int Interior() const { return nodes / 2; }
126        int Leaves() const { return (nodes / 2) + 1; }
127       
128        // TODO: computation wrong
129        double AvgDepth() const { return accumDepth / (double)Leaves();};
130 
131        void Reset()
132        {
133                nodes = 0;
134                splits = 0;
135               
136                maxDepth = 0;
137                minDepth = 99999;
138                polys = 0;
139                accumDepth = 0;
140       
141                maxDepthNodes = 0;
142                minPvsNodes = 0;
143                minRaysNodes = 0;
144                maxRayContribNodes = 0;
145                minAreaNodes = 0;
146
147                contributingSamples = 0;
148                sampleContributions = 0;
149        }
150
151        void Print(ostream &app) const;
152
153        friend ostream &operator<<(ostream &s, const BspTreeStatistics &stat)
154        {
155                stat.Print(s);
156                return s;
157        }
158};
159
160
161/**
162    BspNode abstract class serving for interior and leaf node implementation
163*/
164class BspNode
165{
166        friend class BspTree;
167
168public:
169        BspNode();
170        virtual ~BspNode(){};
171        BspNode(BspInterior *parent);
172
173        /** Determines whether this node is a leaf or not
174        @return true if leaf
175        */
176        virtual bool IsLeaf() const = 0;
177
178        /** Determines whether this node is a root
179        @return true if root
180        */
181        virtual bool IsRoot() const;
182
183        /** Returns parent node.
184        */
185        BspInterior *GetParent();
186
187        /** Sets parent node.
188        */
189        void SetParent(BspInterior *parent);
190
191       
192        static int sMailId;
193        int mMailbox;
194 
195        void Mail() { mMailbox = sMailId; }
196        static void NewMail() { ++ sMailId; }
197        bool Mailed() const { return mMailbox == sMailId; }
198
199protected:
200
201        /// parent of this node
202        BspInterior *mParent;
203};
204
205/** BSP interior node implementation
206*/
207class BspInterior : public BspNode
208{
209        friend class BspTree;
210public:
211        /** Standard contructor taking split plane as argument.
212        */
213        BspInterior(const Plane3 &plane);
214        ~BspInterior();
215        /** @return false since it is an interior node
216        */
217        bool IsLeaf() const;
218
219        BspNode *GetBack();
220        BspNode *GetFront();
221
222        /** Returns split plane.
223        */
224        Plane3 GetPlane() const;
225
226        /** Replace front or back child with new child.
227        */
228        void ReplaceChildLink(BspNode *oldChild, BspNode *newChild);
229        /** Replace front and back child.
230        */
231        void SetupChildLinks(BspNode *b, BspNode *f);
232
233        friend ostream &operator<<(ostream &s, const BspInterior &A)
234        {
235                return s << A.mPlane;
236        }
237
238protected:
239
240        /// Splitting plane corresponding to this node
241        Plane3 mPlane;
242
243        /// back node
244        BspNode *mBack;
245        /// front node
246        BspNode *mFront;
247};
248
249/** BSP leaf node implementation.
250*/
251class BspLeaf : public BspNode
252{
253        friend class BspTree;
254
255public:
256        BspLeaf();
257        BspLeaf(BspViewCell *viewCell);
258        BspLeaf(BspInterior *parent);
259        BspLeaf(BspInterior *parent, BspViewCell *viewCell);
260
261        /** @return true since it is an interior node
262        */
263        bool IsLeaf() const;
264       
265        /** Returns pointer of view cell.
266        */
267        BspViewCell *GetViewCell() const;
268
269        /** Sets pointer to view cell.
270        */
271        void SetViewCell(BspViewCell *viewCell);
272
273        VssRayContainer mVssRays;
274
275protected:
276
277        /// if NULL this does not correspond to feasible viewcell
278        BspViewCell *mViewCell;
279};
280
281/** Implementation of the view cell BSP tree.
282*/
283class BspTree
284{
285public:
286       
287        /** Additional data which is passed down the BSP tree during traversal.
288        */
289        struct BspTraversalData
290        { 
291                /// the current node
292                BspNode *mNode;
293                /// polygonal data for splitting
294                PolygonContainer *mPolygons;
295                /// current depth
296                int mDepth;
297                /// the view cell associated with this subdivsion
298                ViewCell *mViewCell;
299                /// rays piercing this node
300                BoundedRayContainer *mRays;
301                /// area of current node
302                float mArea;
303                /// geometry of node as induced by planes
304                BspNodeGeometry *mGeometry;
305               
306                /// pvs size
307                int mPvs;
308               
309                /** Returns average ray contribution.
310                */
311                float GetAvgRayContribution() const
312                {
313                        return (float)mPvs / ((float)mRays->size() + Limits::Small);
314                }
315
316
317                BspTraversalData():
318                mNode(NULL),
319                mPolygons(NULL),
320                mDepth(0),
321                mViewCell(NULL),
322                mRays(NULL),
323                mPvs(0),
324                mArea(0.0),
325                mGeometry(NULL)
326                {}
327               
328                BspTraversalData(BspNode *node,
329                                                 PolygonContainer *polys,
330                                                 const int depth,
331                                                 ViewCell *viewCell,
332                                                 BoundedRayContainer *rays,
333                                                 int pvs,
334                                                 float area,
335                                                 BspNodeGeometry *cell):
336                mNode(node),
337                mPolygons(polys),
338                mDepth(depth),
339                mViewCell(viewCell),
340                mRays(rays),
341                mPvs(pvs),
342                mArea(area),
343                mGeometry(cell)
344                {}
345    };
346       
347        typedef std::stack<BspTraversalData> BspTraversalStack;
348        //typedef std::priority_queue<BspTraversalData> BspTraversalStack;
349
350        /** Default constructor creating an empty tree.
351        */
352        BspTree();
353       
354        ~BspTree();
355
356        /** Returns detailed statistics of the BSP tree.
357        */
358        const BspTreeStatistics &GetStatistics() const;
359 
360        /** Constructs tree using the given list of view cells.
361            For this type of construction we filter all view cells down the
362                tree. If there is no polygon left, the last split plane
363            decides inside or outside of the viewcell. A pointer to the
364                appropriate view cell is stored within each leaf.
365                Many leafs can point to the same viewcell.
366        */
367        void Construct(const ViewCellContainer &viewCells);
368
369        /** Constructs tree using the given list of objects.
370            @note the objects are not taken as view cells, but the view cells are
371                constructed from the subdivision: Each leaf is taken as one viewcell.
372                @param objects list of objects
373        */
374        void Construct(const ObjectContainer &objects);
375
376        void Construct(const ObjectContainer &objects,
377                                   const RayContainer &sampleRays);
378
379        /** Constructs the tree from a given set of rays.
380                @param sampleRays the set of sample rays the construction is based on
381                @param viewCells if not NULL, new view cells are
382                created in the leafs and stored in the conatainer
383        */
384        void Construct(const RayContainer &sampleRays);
385
386        /** Returns list of BSP leaves.
387        */
388        void CollectLeaves(vector<BspLeaf *> &leaves) const;
389
390        /** Returns box which bounds the whole tree.
391        */
392        AxisAlignedBox3 GetBoundingBox()const;
393
394        /** Returns root of BSP tree.
395        */
396        BspNode *GetRoot() const;
397
398        /** Exports Bsp tree to file.
399        */
400        bool Export(const string filename);
401
402        /** Collects the leaf view cells of the tree
403                @param viewCells returns the view cells
404        */
405        void CollectViewCells(ViewCellContainer &viewCells) const;
406
407        /** A ray is cast possible intersecting the tree.
408                @param the ray that is cast.
409                @returns the number of intersections with objects stored in the tree.
410        */
411  int
412  _CastRay(Ray &ray);
413
414
415  int
416  CastLineSegment(const Vector3 &origin,
417                                  const Vector3 &termination,
418                                  ViewCellContainer &viewcells
419                                  );
420
421        /// bsp tree construction types
422        enum {FROM_INPUT_VIEW_CELLS, FROM_SCENE_GEOMETRY, FROM_SAMPLES};
423
424        /** Returns statistics.
425        */
426        BspTreeStatistics &GetStat();
427
428        /** finds neighbouring leaves of this tree node.
429        */
430        int FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors,
431                                          const bool onlyUnmailed) const;
432
433        /** Constructs geometry associated with the half space intersections
434                leading to this node.
435        */
436        void ConstructGeometry(BspNode *n, PolygonContainer &cell) const;
437       
438        /** Construct geometry of view cell.
439        */
440        void ConstructGeometry(BspViewCell *vc, PolygonContainer &cell) const;
441
442        /** Constructs geometry of view cell returning a BSP node geometry type.
443        */
444        void ConstructGeometry(BspNode *n, BspNodeGeometry &cell) const;
445
446        /** Returns random leaf of BSP tree.
447                @param halfspace defines the halfspace from which the leaf is taken.
448        */
449        BspLeaf *GetRandomLeaf(const Plane3 &halfspace);
450
451        /** Returns random leaf of BSP tree.
452                @param onlyUnmailed if only unmailed leaves should be returned.
453        */
454        BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
455
456        /** Traverses tree and counts all view cells as well as their PVS size.
457        */
458        void EvaluateViewCellsStats(ViewCellsStatistics &stat) const;
459
460        /** Returns view cell corresponding to unbounded space.
461        */
462        BspViewCell *GetRootCell() const;
463
464        /** Returns epsilon of this tree.
465        */
466        float GetEpsilon() const;
467
468protected:
469
470        // --------------------------------------------------------------
471        // For sorting objects
472        // --------------------------------------------------------------
473        struct SortableEntry
474        {
475                enum {POLY_MIN, POLY_MAX};
476   
477                int type;
478                float value;
479                Polygon3 *poly;
480                SortableEntry() {}
481                SortableEntry(const int t, const float v, Polygon3 *poly):
482                type(t), value(v), poly(poly) {}
483               
484                bool operator<(const SortableEntry &b) const
485                {
486                        return value < b.value;
487                } 
488        };
489
490        /** Evaluates tree stats in the BSP tree leafs.
491        */
492        void EvaluateLeafStats(const BspTraversalData &data);
493
494        /** Subdivides node with respect to the traversal data.
495            @param tStack current traversal stack
496                @param tData traversal data also holding node to be subdivided
497                @returns new root of the subtree
498        */
499        BspNode *Subdivide(BspTraversalStack &tStack, BspTraversalData &tData);
500
501        /** Constructs the tree from the given list of polygons and rays.
502                @param polys stores set of polygons on which subdivision may be based
503                @param rays storesset of rays on which subdivision may be based
504        */
505        void Construct(PolygonContainer *polys, BoundedRayContainer *rays);
506
507        /** Selects the best possible splitting plane.
508                @param leaf the leaf to be split
509                @param polys the polygon list on which the split decition is based
510                @param rays ray container on which selection may be based
511                @note the polygons can be reordered in the process
512                @returns the split plane
513        */
514        Plane3 SelectPlane(BspLeaf *leaf,
515                                           BspTraversalData &data);
516
517        /** Evaluates the contribution of the candidate split plane.
518               
519                @param candidatePlane the candidate split plane
520                @param polys the polygons the split can be based on
521                @param rays the rays the split can be based on
522
523                @returns the cost of the candidate split plane
524        */
525        float SplitPlaneCost(const Plane3 &candidatePlane,
526                                                 BspTraversalData &data) const;
527
528        /** Strategies where the effect of the split plane is tested
529            on all input rays.
530                @returns the cost of the candidate split plane
531        */
532        float SplitPlaneCost(const Plane3 &candidatePlane,
533                                                 const PolygonContainer &polys) const;
534
535        /** Strategies where the effect of the split plane is tested
536            on all input rays.
537
538                @returns the cost of the candidate split plane
539        */
540        float SplitPlaneCost(const Plane3 &candidatePlane,
541                                                 const BoundedRayContainer &rays,
542                                                 const int pvs,
543                                                 const float area,
544                                                 const BspNodeGeometry &cell) const;
545
546        /** Filters next view cell down the tree and inserts it into the appropriate leaves
547                (i.e., possibly more than one leaf).
548        */
549        void InsertViewCell(ViewCell *viewCell);
550        /** Inserts polygons down the tree. The polygons are filtered until a leaf is reached,
551                then further subdivided.
552        */
553        void InsertPolygons(PolygonContainer *polys);
554
555        /** Subdivide leaf.
556                @param leaf the leaf to be subdivided
557               
558                @param polys the polygons to be split
559                @param frontPolys returns the polygons in front of the split plane
560                @param backPolys returns the polygons in the back of the split plane
561               
562                @param rays the polygons to be filtered
563                @param frontRays returns the polygons in front of the split plane
564                @param backRays returns the polygons in the back of the split plane
565
566                @returns the root of the subdivision
567        */
568
569        BspInterior *SubdivideNode(BspTraversalData &tData,
570                                                           BspTraversalData &frontData,
571                                                           BspTraversalData &backData,
572                                                           PolygonContainer &coincident);
573
574        /** Filters polygons down the tree.
575                @param node the current BSP node
576                @param polys the polygons to be filtered
577                @param frontPolys returns the polygons in front of the split plane
578                @param backPolys returns the polygons in the back of the split plane
579        */
580        void FilterPolygons(BspInterior *node,
581                                                PolygonContainer *polys,
582                                                PolygonContainer *frontPolys,
583                                                PolygonContainer *backPolys);
584
585        /** Selects the split plane in order to construct a tree with
586                certain characteristics (e.g., balanced tree, least splits,
587                2.5d aligned)
588                @param polygons container of polygons
589                @param rays bundle of rays on which the split can be based
590        */
591        Plane3 SelectPlaneHeuristics(BspLeaf *leaf,
592                                                                 BspTraversalData &data);
593
594        /** Extracts the meshes of the objects and adds them to polygons.
595                Adds object aabb to the aabb of the tree.
596                @param maxPolys the maximal number of objects to be stored as polygons
597                @returns the number of polygons
598        */
599        int AddToPolygonSoup(const ObjectContainer &objects,
600                                                 PolygonContainer &polys,
601                                                 int maxObjects = 0);
602
603        /** Extracts the meshes of the view cells and and adds them to polygons.
604                Adds view cell aabb to the aabb of the tree.
605                @param maxPolys the maximal number of objects to be stored as polygons
606                @returns the number of polygons
607        */
608        int AddToPolygonSoup(const ViewCellContainer &viewCells,
609                                                 PolygonContainer &polys,
610                                                 int maxObjects = 0);
611
612        /** Extract polygons of this mesh and add to polygon container.
613                @param mesh the mesh that drives the polygon construction
614                @param parent the parent intersectable this polygon is constructed from
615                @returns number of polygons
616        */
617        int AddMeshToPolygons(Mesh *mesh, PolygonContainer &polys, MeshInstance *parent);
618
619        /** returns next candidate index and reorders polygons so no candidate is chosen two times
620                @param the current candidate index
621                @param max the range of candidates
622        */
623        int GetNextCandidateIdx(int currentIdx, PolygonContainer &polys);
624
625        /** Helper function which extracts a view cell on the front and the back
626                of the split plane.
627                @param backViewCell returns view cell on the back of the split plane
628                @param frontViewCell returns a view cell on the front of the split plane
629                @param coincident container of polygons coincident to the split plane
630                @param splitPlane the split plane which decides about back and front
631                @param extractBack if a back view cell is extracted
632                @param extractFront if a front view cell is extracted
633        */
634        void ExtractViewCells(BspTraversalData &frontData,
635                                                  BspTraversalData &backData,
636                                                  const PolygonContainer &coincident,
637                                                  const Plane3 &splitPlane) const;
638       
639        /** Computes best cost ratio for the suface area heuristics for axis aligned
640                splits. This heuristics minimizes the cost for ray traversal.
641                @param polys the polygons guiding the ratio computation
642                @param box the bounding box of the leaf
643                @param axis the current split axis
644                @param position returns the split position
645                @param objectsBack the number of objects in the back of the split plane
646                @param objectsFront the number of objects in the front of the split plane
647        */
648        float BestCostRatio(const PolygonContainer &polys,
649                                                const AxisAlignedBox3 &box,
650                                                const int axis,
651                                                float &position,
652                                                int &objectsBack,
653                                                int &objectsFront) const;
654       
655        /** Sorts split candidates for surface area heuristics for axis aligned splits.
656                @param polys the input for choosing split candidates
657                @param axis the current split axis
658                @param splitCandidates returns sorted list of split candidates
659        */
660        void SortSplitCandidates(const PolygonContainer &polys,
661                                                         const int axis,
662                                                         vector<SortableEntry> &splitCandidates) const;
663
664        /** Selects an axis aligned split plane.
665                Returns true if split is valied
666        */
667        bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const;
668
669        /** Subdivides the rays into front and back rays according to the split plane.
670               
671                @param plane the split plane
672                @param rays contains the rays to be split. The rays are
673                           distributed into front and back rays.
674                @param frontRays returns rays on the front side of the plane
675                @param backRays returns rays on the back side of the plane
676               
677                @returns the number of splits
678        */
679        int SplitRays(const Plane3 &plane,
680                                  BoundedRayContainer &rays,
681                              BoundedRayContainer &frontRays,
682                                  BoundedRayContainer &backRays);
683
684
685        /** Extracts the split planes representing the space bounded by node n.
686        */
687        void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const;
688
689        /** Adds the object to the pvs of the front and back leaf with a given classification.
690
691                @param obj the object to be added
692                @param cf the ray classification regarding the split plane
693                @param frontPvs returns the PVS of the front partition
694                @param backPvs returns the PVS of the back partition
695       
696        */
697        void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const;
698
699        /** Computes PVS size induced by the rays.
700        */
701        int ComputePvsSize(const BoundedRayContainer &rays) const;
702
703        /** Returns true if tree can be terminated.
704        */
705        inline bool TerminationCriteriaMet(const BspTraversalData &data) const;
706
707        /** Computes accumulated ray lenght of this rays.
708        */
709        float AccumulatedRayLength(BoundedRayContainer &rays) const;
710
711        /** Splits polygons with respect to the split plane.
712                @param polys the polygons to be split. the polygons are consumed and
713                           distributed to the containers frontPolys, backPolys, coincident.
714                @param frontPolys returns the polygons in the front of the split plane
715                @param backPolys returns the polygons in the back of the split plane
716                @param coincident returns the polygons coincident to the split plane
717
718                @returns the number of splits   
719        */
720        int SplitPolygons(const Plane3 &plane,
721                                          PolygonContainer &polys,
722                                          PolygonContainer &frontPolys,
723                                          PolygonContainer &backPolys,
724                                          PolygonContainer &coincident) const;
725
726        /** Adds ray sample contributions to the PVS.
727                @param sampleContributions the number contributions of the samples
728                @param contributingSampels the number of contributing rays
729               
730        */
731        void AddToPvs(BspLeaf *leaf,
732                                  const BoundedRayContainer &rays,
733                                  int &sampleContributions,
734                                  int &contributingSamples);
735
736        /// Pointer to the root of the tree.
737        BspNode *mRoot;
738
739        /// Stores statistics during traversal.
740        BspTreeStatistics mStat;
741
742        /// Strategies for choosing next split plane.
743        enum {NO_STRATEGY = 0,
744                  RANDOM_POLYGON = 1,
745                  AXIS_ALIGNED = 2,
746                  LEAST_SPLITS = 4,
747                  BALANCED_POLYS = 8,
748                  BALANCED_VIEW_CELLS = 16,
749                  LARGEST_POLY_AREA = 32,
750                  VERTICAL_AXIS = 64,
751                  BLOCKED_RAYS = 128,
752                  LEAST_RAY_SPLITS = 256,
753                  BALANCED_RAYS = 512,
754                  PVS = 1024
755                };
756
757        /// box around the whole view domain
758        AxisAlignedBox3 mBox;
759
760        /// view cell corresponding to unbounded space
761        BspViewCell *mRootCell;
762
763        /// if view cells should be generated or the given view cells should be used.
764        bool mGenerateViewCells;
765
766        /// maximal number of polygons before subdivision termination
767        int mTermMinPolys;
768        /// maximal number of rays before subdivision termination
769        int mTermMinRays;
770        /// maximal possible depth
771        int mTermMaxDepth;
772        /// mininum area
773        float mTermMinArea;
774        /// mininum PVS
775        int mTermMinPvs;
776
777        /// minimal number of polygons for axis aligned split
778        int mTermMinPolysForAxisAligned;
779        /// minimal number of rays for axis aligned split
780        int mTermMinRaysForAxisAligned;
781        /// minimal number of objects for axis aligned split
782        int mTermMinObjectsForAxisAligned;
783        /// maximal contribution per ray
784        float mTermMaxRayContribution;
785        /// minimal accumulated ray length
786        float mTermMinAccRayLength;
787
788
789        /// strategy to get the best split plane
790        int mSplitPlaneStrategy;
791        /// number of candidates evaluated for the next split plane
792        int mMaxPolyCandidates;
793        /// number of candidates for split planes evaluated using the rays
794        int mMaxRayCandidates;
795        /// maximum tests for split plane evaluation with a single candidate
796        int mMaxTests;
797
798        float mCtDivCi;
799
800        /// axis aligned split criteria
801        float mAxisAlignedCtDivCi;
802        float mSplitBorder;
803        float mMaxCostRatio;
804
805        // factors guiding the split plane heuristics
806        float mVerticalSplitsFactor;
807        float mLargestPolyAreaFactor;
808        float mBlockedRaysFactor;
809        float mLeastRaySplitsFactor;
810        float mBalancedRaysFactor;
811        float mPvsFactor;
812        float mLeastSplitsFactor;
813        float mBalancedPolysFactor;
814        float mBalancedViewCellsFactor;
815
816        /// if area or accumulated ray lenght should be used for PVS heuristics
817        bool mPvsUseArea;
818
819        /// epsilon where two points are still considered equal
820        float mEpsilon;
821
822private:
823       
824        /** Evaluates split plane classification with respect to the plane's
825                contribution for a balanced tree.
826        */
827        static const float sLeastPolySplitsTable[4];
828        /** Evaluates split plane classification with respect to the plane's
829                contribution for a minimum number splits in the tree.
830        */
831        static const float sBalancedPolysTable[4];
832        /** Evaluates split plane classification with respect to the plane's
833                contribution for a minimum number of ray splits.
834        */
835        static const float sLeastRaySplitsTable[5];
836        /** Evaluates split plane classification with respect to the plane's
837                contribution for balanced rays.
838        */
839        static const float sBalancedRaysTable[5];
840
841        /// Generates unique ids for PVS criterium
842        static void GenerateUniqueIdsForPvs();
843
844        //-- unique ids for PVS criterium
845        static int sFrontId;
846        static int sBackId;
847        static int sFrontAndBackId;
848};
849
850struct BspIntersection {
851  // the point of intersection
852  float mT;
853 
854  BspLeaf *mLeaf;
855 
856  BspIntersection(const float t, BspLeaf *l):
857        mT(t), mLeaf(l) {}
858 
859  BspIntersection() {}
860 
861  bool operator<(const BspIntersection &b) const {
862        return mT       <b.mT; }
863};
864
865#endif
Note: See TracBrowser for help on using the repository browser.