#ifndef __BVHCONSTRUCTOR_H #define __BVHCONSTRUCTOR_H #include "Bvh.h" namespace CHCDemoEngine { /** This class represents a bvh construction algorithm */ class BvhConstructor { public: BvhConstructor(SceneEntity **entities, int first, int last); /** Constructs a bvh and returns the root and the number of bvh nodes. */ BvhNode *Construct(int &nodes); /** Types of split heuristics. */ enum {SPATIAL_MEDIAN, OBJECT_MEDIAN, SAH}; protected: ////////// //-- sorting functions /** The method of subdividing objects into halves in some axis using spatial median */ int SortTrianglesSpatialMedian(BvhLeaf *leaf, int axis); /** The method of subdividing objects into halves in some axis using object median. */ int SortTrianglesObjectMedian(BvhLeaf *leaf, int axis, float &pos); /** sort triangles along the axis with respect to the splitting plane given by axis/position return index of the first tiangles belong to the front of the splitting plane. */ int SortTriangles(BvhLeaf *leaf, const int axis, const float position); /** sort triangles by their area. */ int SortTrianglesSurfaceArea(BvhLeaf *leaf, float sa); /** This function drives the subdivision. */ BvhNode *SubdivideLeaf(BvhLeaf *leaf, int parentAxis); inline bool TerminationCriteriaMet(BvhLeaf *leaf) const; /** Update the bounding box of this node and the child nodes */ void UpdateBoundingBoxes(BvhNode *node); /** Select splitting plane using SAH - returns the position of the splitting plane. */ float SelectPlaneSah(BvhLeaf *leaf, int &axis, float &minCost); /** evaluate the SAH cost of a particulkar splitting plane */ float EvaluateSahCost(BvhLeaf *leaf, int axis, float position); int CountTriangles(BvhNode *node) const; ///////////////// SceneEntity **mEntities; int mFirst; int mLast; int mMaxDepth; int mMaxObjects; int mNumNodes; int mSplitType; int mMaxTriangles; }; } #endif // __BVH_H