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

Revision 437, 23.3 KB checked in by mattausch, 19 years ago (diff)

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