source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhConstructor.h @ 3280

Revision 3280, 2.0 KB checked in by mattausch, 15 years ago (diff)
Line 
1#ifndef __BVHCONSTRUCTOR_H
2#define __BVHCONSTRUCTOR_H
3
4#include "Bvh.h"
5
6
7
8namespace CHCDemoEngine
9{
10
11/** This class represents a bvh construction algorithm
12*/
13class BvhConstructor
14{
15public:
16
17        BvhConstructor(SceneEntity **entities, int first, int last);
18
19        /** Constructs a bvh and returns the root and the number of bvh nodes.
20        */
21        BvhNode *Construct(int &nodes);
22
23        /** Types of split heuristics.
24        */     
25        enum {SPATIAL_MEDIAN, OBJECT_MEDIAN, SAH, SAH_OR_SIZE};
26
27protected:
28
29        //////////
30        //-- sorting functions
31
32        /** The method of subdividing objects into halves in some axis using spatial median
33        */
34        int     SortTrianglesSpatialMedian(BvhLeaf *leaf, int axis);
35        /** The method of subdividing objects into halves in some axis
36                using object median.
37        */
38        int SortTrianglesObjectMedian(BvhLeaf *leaf, int axis, float &pos);
39        /** sort triangles along the axis with respect to the splitting plane
40                given by axis/position return index of the first tiangles belong
41                to the front of the splitting plane.
42        */
43        int     SortTriangles(BvhLeaf *leaf, const int axis, const float position);
44        /** sort triangles by their area.
45        */
46        int SortTrianglesSurfaceArea(BvhLeaf *leaf, float sa);
47        /** This function drives the subdivision.
48        */
49        BvhNode *SubdivideLeaf(BvhLeaf *leaf, int parentAxis);
50
51        inline bool TerminationCriteriaMet(BvhLeaf *leaf) const;
52        /** Update the bounding box of this node and the child nodes
53        */
54        void UpdateBoundingBoxes(BvhNode *node);
55        /** Select splitting plane using SAH - returns the position of the splitting plane.
56        */
57        float SelectPlaneSah(BvhLeaf *leaf, int &axis, float &minCost);
58        /** evaluate the SAH cost of a particulkar splitting plane
59        */
60        float EvaluateSahCost(BvhLeaf *leaf, int axis, float position);
61
62        int CountTriangles(BvhNode *node) const;
63
64
65
66        /////////////////
67
68        SceneEntity **mEntities;
69
70        int mFirst;
71        int mLast;
72
73        int mMaxDepth;
74        int mMaxObjects;
75        int mNumNodes;
76        int mSplitType;
77        int mMaxTriangles;
78};
79
80}
81
82#endif // __BVH_H
Note: See TracBrowser for help on using the repository browser.