#include "AbstractBVH.h"

using namespace VRUT;

int AbstractBVH::BVHNode::GetNumberOfChildren() const
{
	return IsLeaf() ? 0 : ~offset;
}

AbstractBVH::AbstractBVH() : arity(AbstractBVH::BVH_2), nodes(nullptr), numberOfNodes(0) {}

AbstractBVH::~AbstractBVH()
{
	Clear();
}

void AbstractBVH::Clear()
{
	if (numberOfNodes != 0)
	{
		VrutAlignedFree(nodes);
		nodes = nullptr;
		numberOfNodes = 0;
	}
}

const AbstractBVH::BVHNode * AbstractBVH::GetNodes() const 
{
	return nodes;
}

float AbstractBVH::GetCost() const 
{
	return numberOfNodes > 0 ? GetSubtreeCost(0) : 0;
}
