#ifndef __ABSTRACT_BVH_H__
#define __ABSTRACT_BVH_H__

#include "common.h"
#include "geometry.h"

#define CT 3.0f
#define CI 2.0f

namespace VRUT
{

	class AbstractBVH
	{

		public:

		/// Point in 3d stored aligned for use SSE intrinsics.
		union Point
		{
			/// Array of coordinates.
			float v[4]; 
			/// Coordinate in format for SSE intrinsics.
			__m128 _p;
		};

		/// Structure of node in BVH.
		struct BVHNode
		{
			/// Bounding box
			AABB box;
			/// An offset to triangle array.
			int offset; 
			/// Count of triangles or index to node array.
			unsigned int t;
			/// is leaf?
			bool IsLeaf(void) const
			{
				return offset >= 0;
			}
			/// number of children
			int GetNumberOfChildren(void) const;
		};

		enum Arity {
			BVH_2 = 2,
			BVH_4 = 4,
			BVH_8 = 8
		} arity;

	protected:
		
		/// Array of BVH nodes.
		BVHNode * nodes;

		/// Number of nodes.
		int numberOfNodes;

		/// Returns cost of subtree with a given root index.
		virtual float GetSubtreeCost(int index) const = 0;

	public:

		AbstractBVH(void);
		virtual ~AbstractBVH(void);

		/// Clears.
		void Clear(void);

		/// Return nodes.
		const BVHNode * GetNodes(void) const;

		/// Returns cost of the BVH.
		float GetCost(void) const ;

	};

}

#endif /* __ABSTRACT_BVH_H__ */
