Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchyInterface.cpp	(revision 1319)
+++ 	(revision )
@@ -1,144 +1,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of the GameTools Project
-http://www.gametools.org
-
-Author: Martin Szydlowski
------------------------------------------------------------------------------
-*/
-
-#include "OgreBvRenderable.h"
-#include "OgreBvHierarchySceneManager.h"
-#include "OgreBvHierarchyInterface.h"
-
-namespace Ogre
-{
-
-KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys):
-PlatformHierarchyInterface(sm, rsys)
-{
-
-}
-
-bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
-{
-	return KDNODEPTR_CAST(node)->isLeaf();
-}
-
-void KdTreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
-{
-	++ mNumTraversedNodes;
-
-	KdTree::Node * kdnode = KDNODEPTR_CAST(node);
-
-	// if the node is a leaf and has geometry => render it
-	if (kdnode->isLeaf())
-	{
-		if (!kdnode->isEmpty())
-		{
-			RenderNode(node);
-		}
-	}
-	else
-	{
-		if (kdnode->getLeftChild())
-			mDistanceQueue->push(kdnode->getLeftChild());
-		if (kdnode->getRightChild())
-			mDistanceQueue->push(kdnode->getRightChild());
-	}
-}
-
-void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
-{
-	KdTree::Node * kdnode = KDNODEPTR_CAST(node);
-	if (kdnode->lastRendered() != mFrameId)
-	{
-		kdnode->setLastRendered(mFrameId);
-		KdTreeSceneManager * ksm = static_cast<KdTreeSceneManager *>(mSceneManager);
-
-		ksm->_renderNode(kdnode, mCamera, mOnlyShadowCasters, mLeavePassesInQueue);
-
-		mVisibleNodes.push_back(node);
-	}
-}
-
-void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
-{
-	KdTree::Node * kdnode = KDNODEPTR_CAST(node);
-
-	while (kdnode && !kdnode->isNodeVisible())
-	{
-		kdnode->setNodeVisible(true);
-		kdnode = kdnode->getParent();
-	}
-}
-
-float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
-{
-	const Vector3 pos = KDNODEPTR_CAST(node)->mAABB.getCenter();
-	return (mCameraPosition - pos).squaredLength();
-}
-
-AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
-{
-	// reuse box if node is the same
-	// only create renderable bounding box for new node
-	if (node != mSavedNode)
-	{
-		mSavedNode = node;
-		mBox = KDNODEPTR_CAST(node)->_getWorldAABB();
-	}
-
-	return &mBox;
-}
-
-bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
-{
-	return KDNODEPTR_CAST(node)->hasGeometry();
-}
-
-void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
-{
-	KDNODEPTR_CAST(node)->setNodeVisible(visible);
-}
-
-bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
-{
-	return KDNODEPTR_CAST(node)->isNodeVisible();
-}
-
-void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
-{
-	KDNODEPTR_CAST(node)->setLastVisited(frameId);
-}
-
-unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
-{
-	return KDNODEPTR_CAST(node)->lastVisited();
-}
-
-void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 
-												   GtpVisibility::CullingType type) const
-{
-	WireBoundingBox *box = KDNODEPTR_CAST(node)->getWireBoundingBox();
-
-	if (type == GtpVisibility::FRUSTUM_CULLED)
-	{
-		box->setMaterial("FrustumCulledNodesMaterial");
-	}
-	else // type == GtpVisibility::QUERY_CULLED
-	{
-		box->setMaterial("QueryCulledNodesMaterial");
-	}
-
-	dynamic_cast<KdTreeSceneManager *>(mSceneManager)->getRenderQueue()->addRenderable(box);
-}
-
-void KdTreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, 
-												   GtpVisibility::GeometryVector *geometryList, 
-												   bool includeChildren) 
-{
-	KDNODEPTR_CAST(node)->getGeometryList(geometryList);
-}
-
-} // namespace Ogre
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchySceneNode.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchySceneNode.cpp	(revision 1319)
+++ 	(revision )
@@ -1,191 +1,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of the GameTools Project
-http://www.gametools.org
-
-Author: Martin Szydlowski
------------------------------------------------------------------------------
-*/
-
-#include "OgreBvHierarchySceneNode.h"
-#include "OgreBvHierarchySceneManager.h"
-
-#include <OgreStringConverter.h>
-#include <OgreLogManager.h>
-
-namespace Ogre
-{
-	// TRIVIA: this function is _not_ called for nodes which did not change since the last frame
-	// only exception: the root node ... it's aabb should be null however, so we don't care
-	void KdTreeSceneNode::_updateBounds(void)
-	{
-		// Reset bounds first
-		mWorldAABB.setNull();
-
-		// Update bounds from own attached objects
-		ObjectMap::iterator i;
-		for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i)
-		{
-			// Merge world bounds of each object
-			mWorldAABB.merge(i->second->getWorldBoundingBox(true));
-		}
-
-		if (!mWorldAABB.isNull())
-		{
-			static_cast<KdTreeSceneManager *>(mCreator)->_updateNode(this);
-		}
-	}
-
-	void KdTreeSceneNode::computeScene(PlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren)
-	{
-		/**************************************************************************************/
-		/* HACK: do not include camera node, FUCKS UP world AABB really BAD, dunno why        */
-		/* TODO: find a generic solution where MOVABLE nodes are NOT INSERTED into the KDTREE */
-		/**************************************************************************************/
-		//if (mName == "PlayerCamNode")
-		//	return;
-
-		// first compute nodes AABB
-		mWorldAABB.setNull();
-		// Update bounds from own attached objects
-		ObjectMap::iterator i;
-		for (i = mObjectsByName.begin(); i != mObjectsByName.end(); ++i)
-		{
-			// ignore objects with no actual geometry like frustums & lights
-			if (getExcludedMovables().find(i->second->getMovableType()) == getExcludedMovables().end())
-			{
-				//LogManager::getSingleton().getLog(KDTREE_LOGNAME)->logMessage("Adding movable type " + i->second->getMovableType() + " to KdTree");
-				// Merge world bounds of each object
-				mWorldAABB.merge(i->second->getWorldBoundingBox(true));
-			}
-		}
-
-		// create information for KdTree/SAH
-		if (!mWorldAABB.isNull())
-		{
-			// merge aabb with global AABB
-			aabb.merge(mWorldAABB);
-
-			// increase object count
-			nObjects++;
-
-			// generate events
-			PlaneEvent::Dimension axes[] = 
-				{PlaneEvent::PED_X, PlaneEvent::PED_Y, PlaneEvent::PED_Z};
-			Vector3 min = mWorldAABB.getMinimum();
-			Vector3 max = mWorldAABB.getMaximum();
-			for (int i = 0; i < 3; i++)
-			{
-				// 1-D and 2-D objects
-				if (min[i] == max[i])
-				{	
-					//e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON);
-					//sceneinfo.events.push_back(*e);
-					events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_ON));
-				}
-				else
-				{
-					//e = new PlaneEvent(this, min, axes[i], PlaneEvent::PET_START);
-					//sceneinfo.events.push_back(*e);
-					//e = new PlaneEvent(this, max, axes[i], PlaneEvent::PET_END);
-					//sceneinfo.events.push_back(*e);
-					events.push_back(PlaneEvent(this, min, axes[i], PlaneEvent::PET_START));
-					events.push_back(PlaneEvent(this, max, axes[i], PlaneEvent::PET_END));
-				}
-			}
-		}
-
-		// Merge with children
-		if (includeChildren)
-		{
-			ChildNodeMap::iterator child;
-			for (child = mChildren.begin(); child != mChildren.end(); ++child)
-			{
-				KdTreeSceneNode* sceneChild = static_cast<KdTreeSceneNode*>(child->second);
-				sceneChild->computeScene(events, aabb, nObjects);
-			}
-		}
-	}
-
-	//void KdTreeSceneNode::_findVisibleObjects(Camera* cam, RenderQueue* queue, 
-	//	bool includeChildren, bool displayNodes, bool onlyShadowCasters)
-	void KdTreeSceneNode::queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters)
-	{
-		//SceneNode::_findVisibleObjects(cam, queue, includeChildren, displayNodes, onlyShadowCasters);
-
-		// Add all entities
-		ObjectMap::iterator iobj;
-		ObjectMap::iterator iobjend = mObjectsByName.end();
-		for (iobj = mObjectsByName.begin(); iobj != iobjend; ++iobj)
-		{
-			// Tell attached objects about camera position (incase any extra processing they want to do)
-			iobj->second->_notifyCurrentCamera(cam);
-			if (iobj->second->isVisible() &&
-				(!onlyShadowCasters || iobj->second->getCastShadows()))
-			{
-				iobj->second->_updateRenderQueue(queue);
-			}
-		}
-
-		// Check if the bounding box should be shown.
-		// See if our flag is set or if the scene manager flag is set.
-		if (mShowBoundingBox || (mCreator && mCreator->getShowBoundingBoxes())) 
-		{ 
-			_addBoundingBoxToQueue(queue);
-		}
-	}
-
-	void KdTreeSceneNode::getGeometryList(GtpVisibility::GeometryVector *geometryList)
-	{
-		SceneNode::ObjectIterator objIt = getAttachedObjectIterator();
-
-		while (objIt.hasMoreElements())
-		{
-			MovableObject *movable = objIt.getNext();
-
-			// we are interested only in the entities, i.e., instances of geometry
-			if (movable->getMovableType() == "Entity")
-			{
-				Entity *ent = static_cast<Entity *>(movable);
-				geometryList->push_back(ent);
-			}
-		}
-	}
-
-	// recalculate the world aabb
-	AxisAlignedBox KdTreeSceneNode::getBoundingBox(void) const
-	{
-		return mWorldAABB;
-	}
-
-	KdTreeSceneNode::StringSet& KdTreeSceneNode::getExcludedMovables(void)
-	{
-		static StringSet sExluded;
-
-		// initialise once
-		if (sExluded.empty())
-		{
-			sExluded.insert("Camera");
-			sExluded.insert("Frustum");
-			sExluded.insert("Light");
-		}
-
-		return sExluded;
-	}
-
-	// DEBUG
-	String KdTreeSceneNode::dumpToString(void)
-	{
-		String objects;
-		// Add all entities
-		ObjectMap::iterator iobj = mObjectsByName.begin();
-		ObjectMap::iterator iobjend = mObjectsByName.end();
-		while (iobj != iobjend)
-		{
-			objects += " " + iobj->second->getName();
-			iobj++;
-		}
-		objects += " Attached to " + StringConverter::toString(mLeaves.size()) + " KdLeaves.";
-		return objects;
-	}
-}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchy.cpp	(revision 1319)
+++ 	(revision )
@@ -1,1734 +1,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of the GameTools Project
-http://www.gametools.org
-
-Author: Martin Szydlowski
------------------------------------------------------------------------------
-*/
-
-#include "OgreBvHierarchy.h"
-#include "OgreBvRenderable.h"
-#include "OgreBvHierarchySceneNode.h"
-#include "OgreBvHierarchySceneManager.h"
-
-#include <OgreStringConverter.h>
-#include <OgreLogManager.h>
-#include <OgreRoot.h>
-#include <OgreTimer.h>
-
-#include <OgreMaterialManager.h>
-
-#define PLT_SIZE 101
-
-namespace Ogre
-{
-
-enum Intersection
-{
-	OUTSIDE=0,
-	INSIDE=1,
-	INTERSECT=2
-};
-
-Intersection intersect( const Ray &one, const AxisAlignedBox &two )
-{
-	// Null box?
-	if (two.isNull()) return OUTSIDE;
-
-	bool inside = true;
-	const Vector3* pCorners = two.getAllCorners();
-	Vector3 origin = one.getOrigin();
-	Vector3 dir = one.getDirection();
-
-	Vector3 maxT(-1, -1, -1);
-
-	int i = 0;
-	for(i=0; i<3; i++ )
-	{
-		if( origin[i] < pCorners[0][i] )
-		{
-			inside = false;
-			if( dir[i] > 0 )
-			{
-				maxT[i] = (pCorners[0][i] - origin[i])/ dir[i];
-			}
-		}
-		else if( origin[i] > pCorners[4][i] )
-		{
-			inside = false;
-			if( dir[i] < 0 )
-			{
-				maxT[i] = (pCorners[4][i] - origin[i]) / dir[i];
-			}
-		}
-	}
-
-	if( inside )
-	{
-		return INTERSECT;
-	}
-	int whichPlane = 0;
-	if( maxT[1] > maxT[whichPlane])
-		whichPlane = 1;
-	if( maxT[2] > maxT[whichPlane])
-		whichPlane = 2;
-
-	if( ((int)maxT[whichPlane]) & 0x80000000 )
-	{
-		return OUTSIDE;
-	}
-	for(i=0; i<3; i++ )
-	{
-		if( i!= whichPlane )
-		{
-			float f = origin[i] + maxT[whichPlane] * dir[i];
-			if ( f < (pCorners[0][i] - 0.00001f) ||
-				f > (pCorners[4][i] +0.00001f ) )
-			{
-				return OUTSIDE;
-			}
-		}
-	}
-
-	return INTERSECT;
-
-}
-
-
-/** Checks how the second box intersects with the first.
-*/
-Intersection intersect( const PlaneBoundedVolume &one, const AxisAlignedBox &two )
-{
-	// Null box?
-	if (two.isNull()) return OUTSIDE;
-
-	// Get corners of the box
-	const Vector3* pCorners = two.getAllCorners();
-
-	// For each plane, see if all points are on the negative side
-	// If so, object is not visible.
-	// If one or more are, it's partial.
-	// If all aren't, full
-	int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
-	bool all_inside = true;
-	PlaneList::const_iterator i, iend;
-	iend = one.planes.end();
-	for (i = one.planes.begin(); i != iend; ++i)
-	{
-		const Plane& plane = *i;
-		bool all_outside = true;
-
-		float distance = 0;
-
-		for ( int corner = 0; corner < 8; ++corner )
-		{
-			distance = plane.getDistance( pCorners[ corners[ corner ] ] );
-			all_outside = all_outside && ( distance < 0 );
-			all_inside = all_inside && ( distance >= 0 );
-
-			if ( !all_outside && !all_inside )
-				break;
-		}
-
-		if ( all_outside )
-			return OUTSIDE;
-	}
-
-	if ( all_inside )
-		return INSIDE;
-	else
-		return INTERSECT;
-
-}
-
-
-/** Checks how the second box intersects with the first.
-*/
-Intersection intersect( const AxisAlignedBox &one, const AxisAlignedBox &two )
-{
-	// Null box?
-	if (one.isNull() || two.isNull()) return OUTSIDE;
-
-	const Vector3 * outside = one.getAllCorners();
-	const Vector3 *inside = two.getAllCorners();
-
-	if ( inside[ 4 ].x < outside[ 0 ].x ||
-		inside[ 4 ].y < outside[ 0 ].y ||
-		inside[ 4 ].z < outside[ 0 ].z ||
-		inside[ 0 ].x > outside[ 4 ].x ||
-		inside[ 0 ].y > outside[ 4 ].y ||
-		inside[ 0 ].z > outside[ 4 ].z )
-	{
-		return OUTSIDE;
-	}
-
-	bool full = ( inside[ 0 ].x > outside[ 0 ].x &&
-		inside[ 0 ].y > outside[ 0 ].y &&
-		inside[ 0 ].z > outside[ 0 ].z &&
-		inside[ 4 ].x < outside[ 4 ].x &&
-		inside[ 4 ].y < outside[ 4 ].y &&
-		inside[ 4 ].z < outside[ 4 ].z );
-
-	if ( full )
-		return INSIDE;
-	else
-		return INTERSECT;
-
-}
-
-/** Checks how the box intersects with the sphere.
-*/
-Intersection intersect( const Sphere &one, const AxisAlignedBox &two )
-{
-	// Null box?
-	if (two.isNull()) return OUTSIDE;
-
-	float sradius = one.getRadius();
-
-	sradius *= sradius;
-
-	Vector3 scenter = one.getCenter();
-
-	const Vector3 *corners = two.getAllCorners();
-
-	float s, d = 0;
-
-	Vector3 mndistance = ( corners[ 0 ] - scenter );
-	Vector3 mxdistance = ( corners[ 4 ] - scenter );
-
-	if ( mndistance.squaredLength() < sradius &&
-		mxdistance.squaredLength() < sradius )
-	{
-		return INSIDE;
-	}
-
-	//find the square of the distance
-	//from the sphere to the box
-	for ( int i = 0 ; i < 3 ; i++ )
-	{
-		if ( scenter[ i ] < corners[ 0 ][ i ] )
-		{
-			s = scenter[ i ] - corners[ 0 ][ i ];
-			d += s * s;
-		}
-
-		else if ( scenter[ i ] > corners[ 4 ][ i ] )
-		{
-			s = scenter[ i ] - corners[ 4 ][ i ];
-			d += s * s;
-		}
-
-	}
-
-	bool partial = ( d <= sradius );
-
-	if ( !partial )
-	{
-		return OUTSIDE;
-	}
-
-	else
-	{
-		return INTERSECT;
-	}
-}
-
-Real PlaneEvent::KT = 2.0;
-Real PlaneEvent::KI = 1.0;
-
-//----------------------------------------------------------------------------
-// determine if this event is left or right of the reference event
-void PlaneEvent::classify(const PlaneEvent& e, PlaneEvent::Side side)
-{
-	// only classify events of the same dimension
-	if (mDimension == e.mDimension)
-	{
-		if (mType == PET_END && mPosition[mDimension] <= e.mPosition[e.mDimension])
-		{
-			mRenderable->setSide(PES_LEFT);
-		}
-		else if (mType == PET_START && mPosition[mDimension] >= e.mPosition[e.mDimension])
-		{
-			mRenderable->setSide(PES_RIGHT);
-		}
-		else if (mType == PET_ON)
-		{
-			if (mPosition[mDimension] < e.mPosition[e.mDimension] ||
-				(mPosition[mDimension] == e.mPosition[e.mDimension] && side == PES_LEFT))
-			{
-				mRenderable->setSide(PES_LEFT);
-			}
-			if (mPosition[mDimension] > e.mPosition[e.mDimension] ||
-				(mPosition[mDimension] == e.mPosition[e.mDimension] && side == PES_RIGHT))
-			{
-				mRenderable->setSide(PES_RIGHT);
-			}
-		}
-	}
-}
-
-//----------------------------------------------------------------------------
-// clip this event to an aabb (move it so that the plane on one of the box planes)
-PlaneEvent PlaneEvent::clip(AxisAlignedBox& box, PlaneEvent::Dimension dim)
-{
-	Vector3 newpos = mPosition, min = box.getMinimum(), max = box.getMaximum();
-	if (newpos[dim] < min[dim])
-		newpos[dim] = min[dim];
-	else if (newpos[dim] > max[dim])
-		newpos[dim] = max[dim];
-
-	return PlaneEvent(mRenderable, newpos, mDimension, mType);
-}
-
-//----------------------------------------------------------------------------
-// the surface area heuristic to determine the cost of splitting the parent aabb
-// along the plane represented by this event
-void PlaneEvent::SAH(const AxisAlignedBox& parent, int nLeft, int nPlane, int nRight, SplitInfo& split)
-{
-	Real mu = splitBox(parent, split.bleft, split.bright);
-	Real sav = surfaceArea(parent);
-	Real pl = surfaceArea(split.bleft) / sav;
-	Real pr = surfaceArea(split.bright) / sav;
-	Real costl = splitCost(pl, pr, nLeft + nPlane, nRight, mu);
-	Real costr = splitCost(pl, pr, nLeft, nPlane + nRight, mu);
-
-	if (costl < costr)
-	{
-		split.cost = costl;
-		split.side = PES_LEFT;
-		split.nleft = nLeft + nPlane;
-		split.nright = nRight;
-	}
-	else
-	{
-		split.cost = costr;
-		split.side = PES_RIGHT;
-		split.nleft = nLeft;
-		split.nright = nPlane + nRight;
-
-	}
-	split.event = *this;
-}
-
-//----------------------------------------------------------------------------
-// split the parent aabb with the plane in this event
-Real PlaneEvent::splitBox(const AxisAlignedBox& parent, AxisAlignedBox& left, AxisAlignedBox& right)
-{
-	Vector3 bmin = parent.getMinimum();
-	Vector3 bmax = parent.getMaximum();
-	// calculate the penalty for spliting the box that way
-	Real mu = lookupPenalty(
-		(mPosition[mDimension] - bmin[mDimension]) / 
-		(bmax[mDimension] - bmin[mDimension]));
-	// set corners which are the same as parent AABB
-	left.setMinimum(bmin);
-	right.setMaximum(bmax);
-	// modify "inner" corners
-	bmin[mDimension] = mPosition[mDimension];
-	bmax[mDimension] = mPosition[mDimension];
-	// set the corners on the split plane
-	left.setMaximum(bmax);
-	right.setMinimum(bmin);
-
-	return mu;
-}
-
-//----------------------------------------------------------------------------
-// compute surface area of a box ... DUH!
-Real PlaneEvent::surfaceArea(const AxisAlignedBox& box)
-{
-	Vector3 sides = box.getMaximum() - box.getMinimum();
-	return	2 * sides.x * sides.y +
-		2 * sides.y * sides.z +
-		2 * sides.z * sides.x;
-}
-
-//----------------------------------------------------------------------------
-// lookup the penalty for placing the splitting plane near to the edge of the AABB
-// 0.0 <= p <= 1.0, p = 0.5 means the plane divides the aabb in half
-Real PlaneEvent::lookupPenalty(Real p)
-{
-	// precomputed table of {x^6 + 1|0 <= x <= 1}
-	static Real mPenaltyLookupTable[PLT_SIZE];
-	static bool init_done = false;
-
-	if (!init_done)
-	{
-		Real step = 1.0  / (PLT_SIZE - 1);
-		Real x = 0.0; 
-		//LogManager::getSingleton().logMessage("### Calculating Lookup Table ###");
-		for (int i = 0; i < PLT_SIZE; i++)
-		{
-			mPenaltyLookupTable[i] = Math::Pow(x, 6) + 1.0;
-			x += step;
-			//LogManager::getSingleton().logMessage("### mPenaltyLookupTable[" + StringConverter::toString(i,3) + "]=" + StringConverter::toString(mPenaltyLookupTable[i]));
-		}
-		init_done = true;
-		//LogManager::getSingleton().logMessage("### Lookup Table Calculated ###");
-	}
-
-	// normalize p to [0,1]
-	Real x = Math::Abs(p * 2 - 1);
-	// compute index
-	int i = Math::IFloor(x * (PLT_SIZE - 1));
-
-	return mPenaltyLookupTable[i];
-}
-
-//----------------------------------------------------------------------------
-// compute cost of the split, reward splitting of empty space (lambda, const),
-// penalize splitting off 'thin' slices (mu, const)
-Real PlaneEvent::splitCost(Real pLeft, Real pRight, int nLeft, int nRight)
-{
-	// reward splitting off chunks of empty space
-	Real lambda = 1.0;
-	if (nLeft == 0 || nRight == 0)
-	{
-		lambda = 0.8;
-	}
-
-	// penalize splitting off small chunks (thin slices)
-	Real mu = 1.0;
-	if (pLeft < 0.1 || pRight < 0.1 || pLeft > 0.9 || pRight > 0.9)
-	{
-		mu = 1.5;
-	}
-	return lambda * mu * (KT + (KI * (pLeft*nLeft + pRight*nRight)));
-}
-
-//----------------------------------------------------------------------------
-// compute cost of the split, reward splitting of empty space (lambda, const),
-// penalize splitting off 'thin' slices (mu, parameter)
-Real PlaneEvent::splitCost(Real pLeft, Real pRight, int nLeft, int nRight, Real mu)
-{
-	// reward splitting off chunks of empty space
-	Real lambda = 1.0;
-	if (nLeft == 0 || nRight == 0)
-	{
-		lambda = 0.8;
-	}
-
-	return lambda * mu * (KT + (KI * (pLeft*nLeft + pRight*nRight)));
-}
-
-//----------------------------------------------------------------------------
-// surface area heuristic modified for the priority queue method of building
-// the probabilities (p, pl, pr) are relative to the global (all enclosing) aabb
-void PlaneEvent::pqSAH(Real globalSA, Real parentSA, int nLeft, int nPlane, int nRight, 
-	AxisAlignedBox& parentBox, SplitInfo& split)
-{
-	Real mu = splitBox(parentBox, split.bleft, split.bright);
-	Real p = parentSA / globalSA;
-	Real pl = surfaceArea(split.bleft) / globalSA;
-	Real pr = surfaceArea(split.bright) / globalSA;
-	Real costl = pqSplitCost(p, pl, pr, nLeft + nPlane, nRight, mu);
-	Real costr = pqSplitCost(p, pl, pr, nLeft, nPlane + nRight, mu);
-
-	if (costl < costr)
-	{
-		split.cost = costl;
-		split.side = PES_LEFT;
-		split.nleft = nLeft + nPlane;
-		split.nright = nRight;
-	}
-	else
-	{
-		split.cost = costr;
-		split.side = PES_RIGHT;
-		split.nleft = nLeft;
-		split.nright = nPlane + nRight;
-
-	}
-	split.event = *this;
-}
-
-//----------------------------------------------------------------------------
-// compute split cost without any penalties
-Real PlaneEvent::pqSplitCost(Real pParent, Real pLeft, Real pRight, int nLeft, int nRight, Real mu)
-{
-	return pParent * KT + (KI * (pLeft * nLeft + pRight * nRight));
-}
-
-//----------------------------------------------------------------------------
-// DEBUG
-String PlaneEvent::print()
-{
-	String dim, type;
-	if (mDimension == PED_X)
-		dim = "X";
-	if (mDimension == PED_Y)
-		dim = "Y";
-	if (mDimension == PED_Z)
-		dim = "Z";
-	if (mType == PET_END)
-		type = "END  ";
-	if (mType == PET_ON)
-		type = "ON   ";
-	if (mType == PET_START)
-		type = "START";
-	//return StringConverter::toString(mPosition[mDimension]) + " " + dim + " " + type;
-	return type + " " + dim + " " + StringConverter::toString(mPosition[mDimension]);
-};
-
-//----------------------------------------------------------------------------
-String SplitInfo::print()
-{
-	String sside;
-	if (side == PlaneEvent::PES_BOTH)
-		sside = "BOTH ";
-	if (side == PlaneEvent::PES_LEFT)
-		sside = "LEFT ";
-	if (side == PlaneEvent::PES_RIGHT)
-		sside = "RIGHT";
-	return "nLeft: " + StringConverter::toString(nleft, 4) + " nRight: " + 
-		StringConverter::toString(nright, 4) + " Cost: " + StringConverter::toString(cost, 8, 9) +
-		" Side: " + sside + " Event: " + event.print() + " Leftbox: " + 
-		StringConverter::toString(bleft.getMinimum()) + ", " + 
-		StringConverter::toString(bleft.getMaximum()) + " Rightbox: " +
-		StringConverter::toString(bright.getMinimum()) + ", " + 
-		StringConverter::toString(bright.getMaximum());
-};
-
-//----------------------------------------------------------------------------
-String KdTree::SplitCandidate::print()
-{		
-	String sside;
-	if (side == PlaneEvent::PES_BOTH)
-		sside = "BOTH ";
-	if (side == PlaneEvent::PES_LEFT)
-		sside = "LEFT ";
-	if (side == PlaneEvent::PES_RIGHT)
-		sside = "RIGHT";
-	return "List: " + StringConverter::toString(events->size(), 4) + " Objects: " +
-		StringConverter::toString(nObjects, 4) + " Cost: " + StringConverter::toString(cost, 8, 9) + 
-		" Decrease: " + StringConverter::toString(decrease, 8, 9) + " Side: " + sside + " Best: " +
-		best->print() +  " Box: " + StringConverter::toString(aabb.getMinimum()) + ", "
-		+ StringConverter::toString(aabb.getMaximum());
-
-};
-
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-//----------------------------------------------------------------------------
-
-KdTree::KdTree(int maxdepth, BuildMethod bm): 
-mMaxDepth(maxdepth), 
-mBuildMethod(bm), 
-mHiLiteLevel(0),
-mShowAllBoxes(false),
-mShowNodes(true),
-mKdRoot(0), 
-mBuildLog(0)
-{
-	init();
-}
-
-KdTree::KdTree(int maxdepth, BuildMethod bm, int hilite, bool allboxes, bool shownodes):
-mMaxDepth(maxdepth), 
-mBuildMethod(bm), 
-mHiLiteLevel(hilite),
-mShowAllBoxes(allboxes),
-mShowNodes(shownodes),
-mKdRoot(0), 
-mBuildLog(0)
-{
-	init();
-}
-
-KdTree::~KdTree()
-{
-	delete mKdRoot;
-}
-
-void KdTree::init()
-{
-	MaterialPtr mat;
-	TextureUnitState *tex;
-
-	// init visualization materials (unlit solid green/yellow)
-	mat = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite");
-	if (mat.isNull())
-	{
-		ColourValue green(0, 1, 0);
-		mat = MaterialManager::getSingleton().create("KdTree/BoxHiLite", "General");
-		//mat->setAmbient(green);
-		//mat->setDiffuse(green);
-		mat->setLightingEnabled(false);
-		tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState();
-		tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, green, green);
-	}
-
-	mat = MaterialManager::getSingleton().getByName("KdTree/BoxViz");
-	if (mat.isNull())
-	{
-		ColourValue yellow(1, 1, 0);
-		mat = MaterialManager::getSingleton().create("KdTree/BoxViz", "General");
-		//mat->setAmbient(yellow);
-		//mat->setDiffuse(yellow);
-		mat->setLightingEnabled(false);
-		tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState();
-		tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, yellow, yellow);
-	}
-
-	// retrieve or create build log
-	try
-	{
-		mBuildLog = LogManager::getSingleton().getLog(KDTREE_LOGNAME);
-	}
-	catch (Exception&)
-	{		
-		mBuildLog = LogManager::getSingleton().createLog(KDTREE_LOGNAME);
-	}
-
-	setEnhancedVis(false);
-}
-
-/************************************************************************/
-/* KdTree insert/delete functions                                       */
-/************************************************************************/
-
-void KdTree::remove(BvRenderable * rend)
-{
-	// DEBUG
-	//LogManager::getSingleton().logMessage("-- Removing SceneNode: " + (static_cast<KdTreeSceneNode *>(rend))->getName());
-	std::queue<LeafPtr> cleanup;
-	LeafPtr leaf;
-	LeafSet ls = rend->getLeaves();
-	LeafSet::iterator it = ls.begin();
-	LeafSet::iterator end = ls.end();
-	while (it != end)
-	{
-		cleanup.push(*it);
-		it++;
-	}
-	while (!cleanup.empty())
-	{
-		leaf = cleanup.front();
-		cleanup.pop();
-		leaf->remove(rend);
-		bool gone = rend->detachFrom(leaf);
-		assert(gone && "Failed to detach leave which is abso-fuckin-lutely impossible!!!");
-		//dump();
-		recDelete(leaf);
-		//dump();
-	}
-}
-
-void KdTree::recDelete(KdTree::Node * node)
-{
-	if (node == 0) // DEBUG
-	{
-		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
-			"SNAFU while inserting BvRenderable into KdTree.",
-			"KdTree::recInsert" );
-		return;
-	}
-
-	if (node->isEmpty())
-	{
-		if (node == mKdRoot)
-		{
-			OGRE_DELETE(mKdRoot);
-		} 
-		else
-		{
-			KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent());
-			if (node == parent->mLeft)
-			{
-				OGRE_DELETE(parent->mLeft);
-			}
-			else if (node == parent->mRight)
-			{
-				OGRE_DELETE(parent->mRight);
-			}
-			recDelete(parent);
-		}
-	}
-}
-
-void KdTree::insert(BvRenderable * rend)
-{
-	// make sure the tree exists
-	if (mKdRoot)
-	{
-		// make sure the renderable is inside the world bounding box
-		AxisAlignedBox aabb = rend->getBoundingBox();
-		AxisAlignedBox isect = mKdRoot->mAABB.intersection(aabb);
-		if (isect.getMinimum() == aabb.getMinimum() && isect.getMaximum() == aabb.getMaximum())
-		{
-			recInsert(mKdRoot, rend);
-		}
-		else
-		{
-			//LogManager::getSingleton().logMessage("Inserted node outside of world AABB.");
-			BvRenderableList nodelist;
-			nodelist.push_back(rend);
-			addRendToList(mKdRoot, nodelist);
-			OGRE_DELETE(mKdRoot);
-			mKdRoot = buildFromList(nodelist, 0, AxisAlignedBox());
-		}
-	}
-	// otherwise build a new one
-	else
-	{
-		build(rend);
-	}
-}
-
-void KdTree::recInsert(KdTree::Node * node, BvRenderable * rend)
-{
-	if (node == 0) // DEBUG
-	{
-		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
-			"SNAFU while inserting BvRenderable into KdTree.",
-			"KdTree::recInsert" );
-		return;
-	}
-
-	// rebuild the leaf/replace with subtree ...
-	if (node->isLeaf())
-	{
-		//LogManager::getSingleton().logMessage("## Replacing leaf.");
-		rebuildSubtree(node, rend);
-	}
-	else
-	{
-		KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
-		AxisAlignedBox aabb = rend->getBoundingBox();
-		Plane::Side smin = branch->mSplitPlane->getSide(aabb.getMinimum());
-		Plane::Side smax = branch->mSplitPlane->getSide(aabb.getMaximum());
-		if (smin == smax)
-		{
-			if (smax == Plane::NEGATIVE_SIDE ||
-				(smax == Plane::NO_SIDE && branch->mPlaneSide == PlaneEvent::PES_LEFT))
-			{
-				if (branch->mLeft)
-					recInsert(branch->mLeft, rend);
-				else
-					recInsertNew(branch, PlaneEvent::PES_LEFT, rend);
-			}
-			else if (smin == Plane::POSITIVE_SIDE || 
-				(smin == Plane::NO_SIDE && branch->mPlaneSide == PlaneEvent::PES_RIGHT))
-			{
-				if (branch->mRight)
-					recInsert(branch->mRight, rend);
-				else
-					recInsertNew(branch, PlaneEvent::PES_RIGHT, rend);
-			}
-		}
-		else
-		{
-			if (smin == Plane::NEGATIVE_SIDE && smax == Plane::NO_SIDE)
-			{
-				if (branch->mLeft)
-					recInsert(branch->mLeft, rend);
-				else
-					recInsertNew(branch, PlaneEvent::PES_LEFT, rend);
-			}
-			else if (smax == Plane::POSITIVE_SIDE && smin == Plane::NO_SIDE)
-			{
-				if (branch->mRight)
-					recInsert(branch->mRight, rend);
-				else
-					recInsertNew(branch, PlaneEvent::PES_RIGHT, rend);
-			}
-			else
-			{
-				// to avoid SNAFUs, rebuild whole subtree
-				//LogManager::getSingleton().logMessage("## Rebuilding subtree for insertion");
-				rebuildSubtree(node, rend);
-			}
-		}
-	}
-}
-
-void KdTree::recInsertNew(KdTree::Branch * parent, PlaneEvent::Side side, BvRenderable * rend)
-{
-	//LogManager::getSingleton().logMessage("## Inserting into new subtree");
-
-	AxisAlignedBox left, rigth, aabb;
-	PlaneEventList events;
-	int nObjects;
-	
-	rend->computeScene(events, aabb, nObjects, false);
-
-	// override aabb
-	splitBox(*parent, left, rigth);
-	if (side == PlaneEvent::PES_LEFT)
-	{
-		aabb = left;
-		if (mBuildMethod == KDBM_RECURSIVE)
-			parent->mLeft = recBuild(events, nObjects, aabb, parent);
-		else if (mBuildMethod == KDBM_PRIORITYQUEUE)
-			parent->mLeft = pqBuild(events, nObjects, aabb, parent);
-		else
-		{
-			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
-				"Invalid build method for the KdTree.",
-				"KdTree::buildFromList");
-			parent->mLeft = 0;
-		}
-		
-	}
-	else if (side == PlaneEvent::PES_RIGHT)
-	{
-		aabb = rigth;
-		if (mBuildMethod == KDBM_RECURSIVE)
-			parent->mRight = recBuild(events, nObjects, aabb, parent);
-		else if (mBuildMethod == KDBM_PRIORITYQUEUE)
-			parent->mRight = pqBuild(events, nObjects, aabb, parent);
-		else
-		{
-			OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
-				"Invalid build method for the KdTree.",
-				"KdTree::buildFromList");
-			parent->mRight = 0;
-		}
-	}
-}
-
-void KdTree::rebuildSubtree(KdTree::Node * node, BvRenderable * rend)
-{
-	//LogManager::getSingleton().logMessage("## Rebuilding subtree");
-
-	AxisAlignedBox aabb = node->mAABB;
-	
-	BvRenderableList nodelist;
-	nodelist.push_back(rend);
-	addRendToList(node, nodelist);
-
-	if (node == mKdRoot)
-	{
-		OGRE_DELETE(mKdRoot);
-		mKdRoot = buildFromList(nodelist, 0, aabb);
-	}
-	else
-	{
-		KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent());
-
-		if (node == parent->mLeft)
-		{
-			OGRE_DELETE(parent->mLeft);
-			parent->mLeft = buildFromList(nodelist, parent, aabb);
-		}
-		else if (node == parent->mRight)
-		{
-			OGRE_DELETE(parent->mRight);
-			parent->mRight = buildFromList(nodelist, parent, aabb);
-		}
-		else
-		{
-			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
-				"SNAFU while inserting BvRenderable into KdTree.",
-				"KdTree::recInsert" );
-		}
-	}
-}
-
-// compute both AABB then return the requested one.
-void KdTree::splitBox(const KdTree::Branch& parent, AxisAlignedBox& left, AxisAlignedBox& right)
-{
-	Vector3 bmin = parent.mAABB.getMinimum();
-	Vector3 bmax = parent.mAABB.getMaximum();
-	Real pos = - parent.mSplitPlane->d;
-	int dim = static_cast<int>(parent.mSplitPlane->normal.dotProduct(Vector3(0,1,2)));
-	// set corners which are the same as parent AABB
-	left.setMinimum(bmin);
-	right.setMaximum(bmax);
-	// modify "inner" corners
-	bmin[dim] = pos;
-	bmax[dim] = pos;
-	// set the corners on the split plane
-	left.setMaximum(bmax);
-	right.setMinimum(bmin);
-}
-
-void KdTree::addRendToList(KdTree::Node * node, BvRenderableList& nodelist)
-{
-	if (node->isLeaf())
-	{
-		KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
-		BvRenderableList::iterator it  = leaf->mBvRenderables.begin();
-		BvRenderableList::iterator end = leaf->mBvRenderables.end();
-		while (it != end)
-		{
-			nodelist.push_back(*it);
-			it++;
-		}
-	}
-	else
-	{
-		KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
-		if (branch->mLeft)
-			addRendToList(branch->mLeft, nodelist);
-		if (branch->mRight)
-			addRendToList(branch->mRight, nodelist);
-	}
-}
-
-/************************************************************************/
-/* KdTree build functions                                               */
-/************************************************************************/
-
-void KdTree::build(BvRenderable * sceneRoot)
-{
-	Timer *timer = Root::getSingleton().getTimer();
-	unsigned long t1, t2, t3, t4;
-
-	mTreeStats.clear();
-	
-	// data we want to collect
-	PlaneEventList events;
-	AxisAlignedBox aabb;
-	int nObjects = 0;
-
-	t1 = timer->getMicroseconds(); // DEBUG
-	sceneRoot->computeScene(events, aabb, nObjects);
-	t2 = timer->getMicroseconds(); // DEBUG
-	events.sort();
-	t3 = timer->getMicroseconds(); // DEBUG
-
-	mTreeStats.mNumSceneNodes = nObjects;
-
-	assert(! aabb.isNull() && "Teh stubid worldAABB iz NULL ... waht now?");
-	// hack to avoid SNAFU with "2-dimensional" scene
-	aabb.merge(aabb.getMaximum()+Vector3(1,1,1));
-	aabb.merge(aabb.getMinimum()+Vector3(-1,-1,-1));
-
-	if (mBuildMethod == KDBM_RECURSIVE)
-		mKdRoot = recBuild(events, nObjects, aabb, 0);
-	else if (mBuildMethod == KDBM_PRIORITYQUEUE)
-		mKdRoot = pqBuild(events, nObjects, aabb, 0);
-	else
-	{
-		OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
-			"Invalid build method for the KdTree.",
-			"KdTree::build");
-		mKdRoot = 0;
-	}
-
-	t4 = timer->getMicroseconds(); // DEBUG
-
-	String method = "Invalid";
-	if (mBuildMethod == KDBM_RECURSIVE)
-		method = "Recursive";
-	else if (mBuildMethod == KDBM_PRIORITYQUEUE)
-		method = "Priority Queue";
-
-	mBuildLog->logMessage("######## SAH Statistics ########");
-	mBuildLog->logMessage("Build Method: " + method);
-	mBuildLog->logMessage("Time for events build: " + StringConverter::toString(t2 - t1) + "µs");
-	mBuildLog->logMessage("Time for events sort: " + StringConverter::toString(t3 - t2) + "µs");
-	mBuildLog->logMessage("Time for tree build: " + StringConverter::toString(t4 - t3) + "µs");
-	mBuildLog->logMessage("Total time: " + StringConverter::toString(t4 - t1) + "µs");
-	mBuildLog->logMessage("Tree Depth: " + StringConverter::toString(mMaxDepth));
-	mBuildLog->logMessage("Number of Objects: " + StringConverter::toString(mTreeStats.mNumSceneNodes));
-	mBuildLog->logMessage("Number of Leaves: " + StringConverter::toString(mTreeStats.mNumLeaves));
-	mBuildLog->logMessage("Number of Nodes: " + StringConverter::toString(mTreeStats.mNumNodes));
-	mBuildLog->logMessage("Total cost: " + StringConverter::toString(calcCost()));
-	mBuildLog->logMessage("################################");
-}
-
-KdTree::Node * KdTree::buildFromList(BvRenderableList& nodelist, KdTree::Branch * parent, AxisAlignedBox& aabb)
-{
-	// data we want to collect
-	PlaneEventList events;
-	AxisAlignedBox nodeaabb;
-	int nObjects = 0;
-
-	BvRenderableList::iterator it = nodelist.begin();
-	BvRenderableList::iterator end = nodelist.end();
-	while (it != end)
-	{
-		(*it)->computeScene(events, nodeaabb, nObjects, false);
-		it++;
-	}
-
-	events.sort();
-	
-	// HACK
-	if (aabb.isNull())
-	{
-		aabb = nodeaabb;
-	}
-
-	if (mBuildMethod == KDBM_RECURSIVE)
-		return recBuild(events, nObjects, aabb, parent);
-	else if (mBuildMethod == KDBM_PRIORITYQUEUE)
-		return pqBuild(events, nObjects, aabb, parent);
-	else
-	{
-		OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, 
-			"Invalid build method for the KdTree.",
-			"KdTree::buildFromList");
-		return 0;
-	}
-}
-
-KdTree::Node * KdTree::recBuild(PlaneEventList& events, int nObjects, AxisAlignedBox& aabb, KdTree::Branch * parent)
-{
-	// determine the depth we are on
-	int level = 0;
-	if (parent)
-	{
-		level = parent->getLevel() + 1;
-	}
-
-	/************************************************/
-	/**************** BEGIN FINDPLANE ***************/
-	/************************************************/
-	// find optimal split plane and split node accordingly
-
-	// initialize
-	const int dim = 3;
-	int pStart, pOn, pEnd;
-	int nLeft[dim], nPlane[dim], nRight[dim];
-	for (int i = 0; i < dim; i++)
-	{
-		nLeft[i] = 0; nPlane[i] = 0; nRight[i] = nObjects;
-	}
-
-	SplitInfo split, best;
-	best.cost = Math::POS_INFINITY;
-
-	PlaneEventList::iterator begin = events.begin();
-	PlaneEventList::iterator end = events.end();
-	PlaneEventList::iterator it = begin;
-	// try all planes to find the best one for the given set of objects
-	while (it != end)
-	{
-		PlaneEventList::iterator p = it;
-		pStart = pOn = pEnd = 0;
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_END))
-		{
-			it++; pEnd++;
-		}
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_ON))
-		{
-			it++; pOn++;
-		}
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_START))
-		{
-			it++; pStart++;
-		}
-		int d = p->getDimension();
-		nPlane[d] = pOn; nRight[d] -= pOn; nRight[d] -= pEnd;
-		p->SAH(aabb, nLeft[d], nPlane[d], nRight[d], split);
-		if (split.cost < best.cost)
-		{
-			best = split;
-		}
-		nLeft[d] += pStart; nLeft[d] += pOn; nPlane[d] = 0;
-	}
-
-	/************************************************/
-	/**************** BEGIN TERMINATE ***************/
-	/************************************************/
-	// check terminating condition
-	if (best.cost > PlaneEvent::KI*nObjects || level >= mMaxDepth)
-	{
-		// Terminating condition reached, create leaf and add renderables to list
-		KdTree::Leaf * leaf = new KdTree::Leaf(this, level, aabb, parent);
-		BvRenderable *rend;
-		it = begin;
-		while (it != end)
-		{
-			rend = it->getRenderable();
-			rend->setClassified(false);
-			if (rend->attachTo(leaf, this))
-			{
-				leaf->insert(rend);
-			}
-			it++;
-		}
-		// update stats
-		++ mTreeStats.mNumNodes;
-		++ mTreeStats.mNumLeaves;
-		// update bounding box
-		leaf->_updateBounds(false);
-		return leaf;
-	}
-
-	/************************************************/
-	/**************** BEGIN CLASSIFY ****************/
-	/************************************************/
-	// split the event list in left and right sub-lists
-	else
-	{
-		PlaneEventList eventsRight, eventsLeft;
-		it = begin;
-		// slightly redundant, since we mark each renderable up to 6 times
-		while (it != end)
-		{
-			it->getRenderable()->setSide(PlaneEvent::PES_BOTH);
-			it->getRenderable()->setClassified(false);
-			it++;
-		}
-		// now classify all renderables. do they belong to the left child, the right child or both?
-		it = begin;
-		while (it != end)
-		{
-			it->classify(best.event, best.side);
-			it++;
-		}
-		// divide the event lists
-		int nLeftS = 0, nRightS = 0, nBothS = 0;
-		it = begin;
-		while (it != end)
-		{
-			// right-only nodes go in right list
-			if (it->getRenderable()->getSide() == PlaneEvent::PES_RIGHT)
-			{
-				if (!it->getRenderable()->isClassified())
-				{
-					it->getRenderable()->setClassified(true);
-					nRightS++;
-				}
-				eventsRight.push_back(*it);
-			}
-			// left-only nodes go in left list
-			else if (it->getRenderable()->getSide() == PlaneEvent::PES_LEFT)
-			{
-				if (!it->getRenderable()->isClassified())
-				{
-					it->getRenderable()->setClassified(true);
-					nLeftS++;
-				}
-				eventsLeft.push_back(*it);
-			}
-			// remaining nodes go in both lists, bust must be clipped to prevent
-			// events from lying outside the new nodes aabb
-			else
-			{
-				if (!it->getRenderable()->isClassified())
-				{
-					it->getRenderable()->setClassified(true);
-					nBothS++;
-				}
-				eventsRight.push_back(it->clip(best.bright, best.event.getDimension()));
-				eventsLeft.push_back(it->clip(best.bleft, best.event.getDimension()));
-			}
-			it++;
-		}
-
-		// create a new branch node and continue recursion
-		KdTree::Branch * branch = new KdTree::Branch(this, level, aabb, parent, 
-			best.event.getSplitPlane(), best.side);
-
-		// now create the child nodes and continue recursion
-		if (eventsLeft.size() > 0)
-		{
-			branch->mLeft = recBuild(eventsLeft, nLeftS + nBothS, best.bleft, branch);
-		}
-		if (eventsRight.size() > 0)
-		{
-			branch->mRight = recBuild(eventsRight, nBothS + nRightS, best.bright, branch);
-		}
-
-		// update stats
-		++ mTreeStats.mNumNodes;
-
-		// update bounding box
-		branch->_updateBounds(false);
-
-		return branch;
-	}
-}
-
-KdTree::Node * KdTree::pqBuild(PlaneEventList& events, int nObjects, AxisAlignedBox& aabb, KdTree::Branch * parent)
-{
-	SplitCandidatePQ pqueue;
-	Real globalTreeCost;
-	Real globalSA;
-
-	KdTree::Node * newNode = 0, * topNode = 0;
-	// init global tree cost
-	globalTreeCost = PlaneEvent::KI * nObjects;
-	globalSA = PlaneEvent::surfaceArea(aabb);
-
-	PlaneEventList * e = new PlaneEventList(events);
-
-	// inital split candidate
-	SplitInfo * best = pqFindPlane(e, nObjects, aabb, globalSA);
-	SplitCandidate splitcandidate(e, nObjects, aabb, parent, globalTreeCost, 
-		globalTreeCost - best->cost, best, PlaneEvent::PES_BOTH);
-	pqueue.push(splitcandidate);
-
-
-	/*** BEGIN ITERATIVE BUILD ***/
-	while (!pqueue.empty())
-	{
-		SplitCandidate sc = pqueue.top();
-		pqueue.pop();
-
-		// determine the depth we are on
-		int level = 0;
-		if (sc.parent)
-		{
-			level = sc.parent->getLevel() + 1;
-		}
-
-		/************************************************/
-		/**************** BEGIN TERMINATE ***************/
-		/************************************************/
-		// check terminating condition
-		if (sc.decrease < 0.0 || level >= mMaxDepth)
-		{
-			// Terminating condition reached, create leaf and add renderables to list
-			KdTree::Leaf * leaf = new KdTree::Leaf(this, level, sc.aabb, sc.parent);
-			BvRenderable *rend;
-			PlaneEventList::iterator begin = sc.events->begin();
-			PlaneEventList::iterator end = sc.events->end();
-			PlaneEventList::iterator it = begin;
-			while (it != end)
-			{
-				rend = it->getRenderable();
-				rend->setClassified(false);
-				if (rend->attachTo(leaf, this))
-				{
-					leaf->insert(rend);
-				}
-				it++;
-			}
-			newNode = leaf;
-			if (!topNode)
-				topNode = leaf;
-			// update stats
-			++ mTreeStats.mNumNodes;
-			++ mTreeStats.mNumLeaves;
-		}
-
-		/************************************************/
-		/**************** BEGIN CLASSIFY ****************/
-		/************************************************/
-		else
-		{
-			PlaneEventList * eventsLeft = new PlaneEventList();
-			PlaneEventList * eventsRight = new PlaneEventList();
-			PlaneEventList::iterator begin = sc.events->begin();
-			PlaneEventList::iterator end = sc.events->end();
-			PlaneEventList::iterator it = begin;
-			// slightly redundant, since we mark each renderable up to 6 times
-			while (it != end)
-			{
-				it->getRenderable()->setSide(PlaneEvent::PES_BOTH);
-				it->getRenderable()->setClassified(false);
-				it++;
-			}
-
-			// now classify all renderables. do they belong to the left child, the right child or both?
-			it = begin;
-			while (it != end)
-			{
-				it->classify(sc.best->event, sc.best->side);
-				it++;
-			}
-
-			// divide the event lists
-			int nLeftS = 0, nRightS = 0, nBothS = 0;
-			it = begin;
-			while (it != end)
-			{
-				// right-only events go in the right list
-				if (it->getRenderable()->getSide() == PlaneEvent::PES_RIGHT)
-				{
-					if (!it->getRenderable()->isClassified())
-					{
-						it->getRenderable()->setClassified(true);
-						nRightS++;
-					}
-
-					eventsRight->push_back(*it);
-				}
-				// left-only events go in the left list
-				else if (it->getRenderable()->getSide() == PlaneEvent::PES_LEFT)
-				{
-					if (!it->getRenderable()->isClassified())
-					{
-						it->getRenderable()->setClassified(true);
-						nLeftS++;
-					}
-					eventsLeft->push_back(*it);
-				}
-				// the rest goes in both lists after being clipped
-				else
-				{
-					if (!it->getRenderable()->isClassified())
-					{
-						it->getRenderable()->setClassified(true);
-						nBothS++;
-					}
-
-					eventsRight->push_back(it->clip(sc.best->bright, sc.best->event.getDimension()));
-					eventsLeft->push_back(it->clip(sc.best->bleft, sc.best->event.getDimension()));
-				}
-				it++;
-			}
-
-			// create a new branch node
-			KdTree::Branch * branch = new KdTree::Branch(this, level, sc.aabb, sc.parent, 
-				sc.best->event.getSplitPlane(), sc.best->side);
-
-			globalTreeCost -= sc.decrease;
-
-
-			// now for each potential child node, compute the split plane and the cost decrease
-			// and place them in the queue
-			if (eventsLeft->size() > 0)
-			{
-				best = pqFindPlane(eventsLeft, nLeftS + nBothS, sc.best->bleft, globalSA);
-				Real old = PlaneEvent::surfaceArea(sc.best->bleft)/globalSA*PlaneEvent::KI*(nLeftS + nBothS);
-				SplitCandidate scleft(eventsLeft, nLeftS + nBothS, sc.best->bleft, 
-					branch, old, old - best->cost, best, PlaneEvent::PES_LEFT);
-				pqueue.push(scleft);
-			}
-			// cleanup
-			else
-			{
-				delete eventsLeft;
-			}
-
-			if (eventsRight->size() > 0)
-			{
-				best = pqFindPlane(eventsRight, nBothS + nRightS, sc.best->bright, globalSA);
-				Real old = PlaneEvent::surfaceArea(sc.best->bright)/globalSA*PlaneEvent::KI*(nBothS + nRightS);
-				SplitCandidate scright(eventsRight, nBothS + nRightS, sc.best->bright, 
-					branch, old, old - best->cost, best, PlaneEvent::PES_RIGHT);
-				pqueue.push(scright);
-			}
-			// cleanup
-			else
-			{
-				delete eventsRight;
-			}
-
-			newNode = branch;
-			if (!topNode)
-				topNode = branch;
-
-
-			// update stats
-			++ mTreeStats.mNumNodes;
-		}
-
-		// attach new node to parent
-		if (sc.parent)
-		{
-			if (sc.side == PlaneEvent::PES_LEFT)
-			{
-				sc.parent->mLeft = newNode;
-			}
-			else if (sc.side == PlaneEvent::PES_RIGHT)
-			{
-				sc.parent->mRight = newNode;
-			}
-			else
-			{
-				OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
-					"PQBUILD SNAFU - CHILD I AM NOT LEFT NOR RIGHT","KdTree::pqBuild");
-			}
-		}
-
-		// update bounding boxes when geometry (leaf) was added
-		if (newNode->isLeaf())
-			newNode->_updateBounds();
-
-		//cleanup
-		OGRE_DELETE(sc.events);
-		OGRE_DELETE(sc.best);
-	}
-	mBuildLog->logMessage("Cost after PQBUILD " + StringConverter::toString(globalTreeCost));
-	return topNode;
-}
-
-//-------------------------------------------------------------------------
-SplitInfo * KdTree::pqFindPlane(PlaneEventList * events, int nObjects, AxisAlignedBox& aabb, Real globalSA)
-{
-	static const int dim = 3;
-	int pStart, pOn, pEnd;
-	int nLeft[dim], nPlane[dim], nRight[dim];
-	for (int i = 0; i < dim; i++)
-	{
-		nLeft[i] = 0; nPlane[i] = 0; nRight[i] = nObjects;
-	}
-
-	SplitInfo split, best;
-	best.cost = Math::POS_INFINITY;
-
-	Real parentSA = PlaneEvent::surfaceArea(aabb);
-
-	PlaneEventList::iterator begin = events->begin();
-	PlaneEventList::iterator end = events->end();
-	PlaneEventList::iterator it = begin;
-	// try all planes to find the best one for the given set of objects
-	while (it != end)
-	{
-		PlaneEventList::iterator p = it;
-		pStart = pOn = pEnd = 0;
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_END))
-		{
-			it++; pEnd++;
-		}
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_ON))
-		{
-			it++; pOn++;
-		}
-		while (it != end && p->equalsType(*it, PlaneEvent::PET_START))
-		{
-			it++; pStart++;
-		}
-		int d = p->getDimension();
-		nPlane[d] = pOn; nRight[d] -= pOn; nRight[d] -= pEnd;
-		p->pqSAH(globalSA, parentSA, nLeft[d], nPlane[d], nRight[d], aabb, split);
-		if (split.cost < best.cost)
-		{
-			best = split;
-		}
-		nLeft[d] += pStart; nLeft[d] += pOn; nPlane[d] = 0;
-	}
-	return new SplitInfo(best);
-}
-
-/************************************************************************/
-/* KdTree rendering functions                                           */
-/************************************************************************/
-
-//-------------------------------------------------------------------------
-void KdTree::queueVisibleObjects(BvHierarchyCamera* cam, RenderQueue* queue, bool onlyShadowCasters, 
-	bool showBoxes, KdTree::NodeList& visibleNodes)
-{
-	mFrameStats.clear();
-	cam->mNumVisQueries = 0;
-
-	if (mKdRoot)
-		recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(),
-			cam, queue, onlyShadowCasters, showBoxes, visibleNodes);
-
-	mFrameStats.mTraversedNodes = cam->mNumVisQueries;
-}
-
-//-------------------------------------------------------------------------
-void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 
-	BvHierarchyCamera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes, 
-	KdTree::NodeList& visibleNodes, bool fullVis)
-{
-	BvHierarchyCamera::NodeVisibility vis = BvHierarchyCamera::KDNV_PART;
-	// test visibility
-	//if (cam->isVisible(node->mAABB))
-	if (fullVis || 
-		((vis = (cam->*getVisibility)(node->mAABB)) != BvHierarchyCamera::KDNV_NONE))
-	{
-		visibleNodes.push_back(node);
-
-		bool v = (fullVis || vis == BvHierarchyCamera::KDNV_FULL);
-
-		node->queueVisibleObjects(currentFrame, cam, queue, onlyShadowCasters, showBoxes, v);
-
-		if (v || node->isLeaf())
-			++ mFrameStats.mRenderedNodes;
-
-		if (!v)
-		{
-
-			if (node->getLeftChild())
-				recQueueVisibleObjects(node->getLeftChild(), currentFrame, 
-				cam, queue, onlyShadowCasters, showBoxes, visibleNodes, v);
-			if (node->getRightChild())
-				recQueueVisibleObjects(node->getRightChild(), currentFrame, 
-				cam, queue, onlyShadowCasters, showBoxes, visibleNodes, v);
-		}
-	}
-	else
-	{
-		++ mFrameStats.mFrustumCulledNodes;
-	}
-}
-
-//-------------------------------------------------------------------------
-void KdTree::setEnhancedVis(bool enh)
-{
-	if (enh)
-		getVisibility = &BvHierarchyCamera::getVisibilityEnhanced;
-	else
-		getVisibility = &BvHierarchyCamera::getVisibilitySimple;
-}
-
-//-------------------------------------------------------------------------
-bool KdTree::getEnhancedVis()
-{
-	return getVisibility == &BvHierarchyCamera::getVisibilityEnhanced;
-}
-
-//-------------------------------------------------------------------------
-//void KdTree::findVisibleNodes(NodeList& visibleNodes, Camera * cam)
-//{
-//	if (mKdRoot)
-//		recFindVisibleNodes(mKdRoot, visibleNodes, cam);
-//}
-
-////-------------------------------------------------------------------------
-//void KdTree::recFindVisibleNodes(KdTree::Node * node, NodeList& visibleNodes, Camera * cam)
-//{
-//	// test visibility
-//	if (cam->isVisible(node->mAABB))
-//	{
-//		visibleNodes.push_back(node);
-
-//		if (node->getLeftChild())
-//			recFindVisibleNodes(node->getLeftChild(), visibleNodes, cam);
-//		if (node->getRightChild())
-//			recFindVisibleNodes(node->getRightChild(), visibleNodes, cam);
-//	}
-//}
-
-void KdTree::findNodesIn(const AxisAlignedBox &box, std::list<SceneNode *> &list, SceneNode *exclude)
-{
-	if (mKdRoot)
-		recFindNodesIn(box, list, exclude, mKdRoot);
-}
-
-void KdTree::findNodesIn(const Sphere &sphere, std::list<SceneNode *> &list, SceneNode *exclude)
-{
-	if (mKdRoot)
-		recFindNodesIn(sphere, list, exclude, mKdRoot);
-}
-
-void KdTree::findNodesIn(const PlaneBoundedVolume &volume, std::list<SceneNode *> &list, SceneNode *exclude)
-{
-	if (mKdRoot)
-		recFindNodesIn(volume, list, exclude, mKdRoot);
-}
-
-void KdTree::findNodesIn(const Ray &ray, std::list<SceneNode *> &list, SceneNode *exclude)
-{
-	if (mKdRoot)
-		recFindNodesIn(ray, list, exclude, mKdRoot);
-}
-
-void KdTree::recFindNodesIn(const AxisAlignedBox &box, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full)
-{
-	// check intersection
-	if ( !full )
-	{
-		Intersection isect = intersect(box, node->_getWorldAABB());
-
-		if ( isect == OUTSIDE )
-			return ;
-
-		full = ( isect == INSIDE );
-	}
-
-	if (node->isLeaf())
-	{
-		LeafPtr leaf = KDLEAFPTR_CAST(node);
-		for (BvRenderableList::iterator it = leaf->mBvRenderables.begin();
-			it != leaf->mBvRenderables.end(); it ++)
-		{
-			SceneNode *sn = dynamic_cast<SceneNode *>(*it);
-
-			if (sn != exclude)
-			{
-				if (full)
-				{
-					list.push_back(sn);
-				}
-				else
-				{
-					Intersection nsect = intersect(box, sn->_getWorldAABB());
-
-					if ( nsect != OUTSIDE )
-					{
-						list.push_back(sn);
-					}
-				}
-			}
-		}
-	}
-	else
-	{
-		if (node->getLeftChild())
-			recFindNodesIn(box, list, exclude, node->getLeftChild(), full);
-		if (node->getRightChild())
-			recFindNodesIn(box, list, exclude, node->getRightChild(), full);
-	}
-}
-
-void KdTree::recFindNodesIn(const Sphere &sphere, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full)
-{
-	// TODO
-}
-
-void KdTree::recFindNodesIn(const PlaneBoundedVolume &volume, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full)
-{
-	// TODO
-}
-
-void KdTree::recFindNodesIn(const Ray &ray, std::list<SceneNode *> &list, SceneNode *exclude, Node * node, bool full)
-{
-	// TODO
-}
-
-/************************************************************************/
-/* KdTree debug & helper functions                                      */
-/************************************************************************/
-
-//-------------------------------------------------------------------------
-void KdTree::dump()
-{
-	//LogManager::getSingleton().logMessage("#@#@#@#@ Dumping KdTree #@#@#@#@");
-	mBuildLog->logMessage("#@#@#@#@ Dumping KdTree #@#@#@#@");
-	if (mKdRoot)
-		dump(mKdRoot);
-}
-
-//-------------------------------------------------------------------------
-void KdTree::dump(KdTree::Node * node)
-{
-	//LogManager * log = LogManager::getSingletonPtr();
-	KdTreeSceneNode * scenenode;
-	String pad;
-	int p;
-	
-	pad = "";
-	for (p = 0; p < node->getLevel(); p++)
-	{
-		pad += " ";
-	}
-
-	if (node->isLeaf())
-	{
-		KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
-		BvRenderableList::iterator it  = leaf->mBvRenderables.begin();
-		BvRenderableList::iterator end = leaf->mBvRenderables.end();
-		while (it != end)
-		{
-			scenenode = dynamic_cast<KdTreeSceneNode *>(*it);
-			mBuildLog->logMessage(pad + "# Leaf   level " + 
-				StringConverter::toString(node->getLevel()) + 
-				" SceneNode " + scenenode->getName());
-			mBuildLog->logMessage(pad + "## Objects: " + scenenode->dumpToString());
-			it++;
-		}
-	}
-	else
-	{
-		KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
-		if (branch->mLeft)
-		{
-			mBuildLog->logMessage(pad + "# Branch level " + 
-				StringConverter::toString(node->getLevel()) + " Left Child");
-			dump(branch->mLeft);
-		}
-		if (branch->mRight)
-		{
-			mBuildLog->logMessage(pad + "# Branch level " + 
-				StringConverter::toString(node->getLevel()) + " Right Child");
-			dump(branch->mRight);
-		}
-	}
-}
-
-//-------------------------------------------------------------------------
-Real KdTree::calcCost()
-{
-	if (mKdRoot)
-		return calcCost(mKdRoot, PlaneEvent::surfaceArea(mKdRoot->mAABB));
-	else
-		return 0;
-}
-
-//-------------------------------------------------------------------------
-Real KdTree::calcCost(KdTree::Node * node, Real vs)
-{
-	if (node == 0)
-		return 0.0;
-
-	if (node->isLeaf())
-	{
-		KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
-		return (PlaneEvent::surfaceArea(node->mAABB)/vs) *
-			PlaneEvent::KI * leaf->mBvRenderables.size();
-	}
-	else
-	{
-		KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
-		return (PlaneEvent::surfaceArea(node->mAABB)/vs) * PlaneEvent::KT + 
-			calcCost(branch->mLeft, vs) + calcCost(branch->mRight, vs);
-	}
-}
-
-/************************************************************************/
-/* KdTree::Node/Branch/Leaf functions                                   */
-/************************************************************************/
-
-//-------------------------------------------------------------------------
-KdTree::Leaf::~Leaf()
-{
-	// detach all scene nodes in the case that we are rebuilding
-	// the tree but not the scene
-	BvRenderableList::iterator it = mBvRenderables.begin();
-	BvRenderableList::iterator end = mBvRenderables.end();
-	while (it != end)
-	{
-		(*it)->detachFrom(this);
-		it++;
-	}
-	mBvRenderables.clear();
-}
-
-//-------------------------------------------------------------------------
-void KdTree::Leaf::queueVisibleObjects(unsigned long currentFrame, 
-	Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes, bool fullVis)
-{
-	BvRenderableList::iterator it  = mBvRenderables.begin();
-	BvRenderableList::iterator end = mBvRenderables.end();
-	while (it != end)
-	{			
-		if (!(*it)->isQueued(currentFrame, cam))
-		{
-			(*it)->queueObjects(cam, queue, onlyShadowCasters);
-		}
-		it++;
-	}
-
-	if (showBoxes)
-		if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes())
-			queue->addRenderable(getWireBoundingBox());
-}
-
-//-------------------------------------------------------------------------
-void KdTree::Leaf::getGeometryList(GtpVisibility::GeometryVector *geometryList)
-{
-	BvRenderableList::iterator it = mBvRenderables.begin();
-	BvRenderableList::iterator end = mBvRenderables.end();
-	while (it != end)
-	{
-		(*it)->getGeometryList(geometryList);
-		it++;
-	}
-}
-
-//-------------------------------------------------------------------------
-// update the world aabb based on the contained geometry
-void KdTree::Leaf::_updateBounds(bool recurse)
-{
-	// reset box
-	mWorldAABB.setNull();
-
-	// merge boxes from attached geometry
-	BvRenderableList::iterator it = mBvRenderables.begin();
-	BvRenderableList::iterator end = mBvRenderables.end();
-	while (it != end)
-	{
-		//(*it)->_updateBounds();
-		mWorldAABB.merge((*it)->getBoundingBox());
-		it++;
-	}
-
-	// update parent recursively
-	if (recurse && mParent)
-		mParent->_updateBounds(recurse);
-}
-
-} // namespace Ogre
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchySceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchySceneManager.cpp	(revision 1319)
+++ 	(revision )
@@ -1,1455 +1,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of the GameTools Project
-http://www.gametools.org
-
-Author: Martin Szydlowski
------------------------------------------------------------------------------
-*/
-
-#include <OgreCamera.h>
-#include <OgreSubEntity.h>
-#include <OgreMaterialManager.h>
-#include <OgreLogManager.h>
-#include <OgreStringConverter.h>
-
-#include "OgreBvHierarchySceneManager.h"
-#include "OgreBvHierarchySceneNode.h"
-#include "OgreBvHierarchy.h"
-
-#include <OgreMeshInstance.h>
-#include <OgreBoundingBoxConverter.h>
-#include <OgreTypeConverter.h>
-#include <VisibilityEnvironment.h>
-#include "OgreVisibilityOptionsManager.h"
-
-namespace Ogre
-{
-
-KdTreeSceneManager::KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm):
-SceneManager(name), 
-mVisibilityManager(vm), 
-mBvHierarchy(0), 
-mMaxDepth(KDTREE_MAX_DEPTH),
-mShowBoxes(false),
-mHiLiteLevel(0),
-mShowAllBoxes(false),
-mEnhancedVisiblity(true),
-mBuildMethod(KdTree::KDBM_RECURSIVE),
-mRenderMethod(KdTree::KDRM_INTERNAL),
-mShowVisualization(false),
-mRenderNodesForViz(false),
-mRenderNodesContentForViz(false),
-mVisualizeCulledNodes(false),
-mLeavePassesInQueue(0),
-mDelayRenderTransparents(true),
-mUseDepthPass(false),
-mIsDepthPassPhase(false),
-mUseItemBuffer(false),
-mIsItemBufferPhase(false),
-mCurrentEntityId(1),
-mEnableDepthWrite(true),
-mSkipTransparents(false),
-mRenderTransparentsForItemBuffer(true),
-mExecuteVertexProgramForAllPasses(false),
-mIsHierarchicalCulling(false),
-mDeleteQueueAfterRendering(true),
-mViewCellsLoaded(false),
-mUseViewCells(false),
-mUseVisibilityFilter(false),
-mViewCellsManager(0),
-mElementaryViewCell(0),
-mCurrentViewCell(0)
-{
-	// Replace root node with my node
-	OGRE_DELETE(mSceneRoot);
-	mSceneRoot = new KdTreeSceneNode(this, "root node");
-	mSceneRoot->_notifyRootNode();
-
-	// init heirarchy interface
-	mHierarchyInterface = new KdTreeHierarchyInterface(this, mDestRenderSystem);
-}
-
-KdTreeSceneManager::~KdTreeSceneManager(void)
-{
-	delete mHierarchyInterface;
-	delete mBvHierarchy;
-}
-
-void KdTreeSceneManager::clearScene()
-{
-	// DEBUG
-	//if (mBvHierarchy)
-	//	mBvHierarchy->dump();
-
-	// must happen before actual scene is cleared
-	OGRE_DELETE(mBvHierarchy);
-
-	SceneManager::clearScene();
-}
-
-
-const String& KdTreeSceneManager::getTypeName(void) const
-{
-	return BvHierarchySceneManagerFactory::FACTORY_TYPE_NAME;
-}
-
-void KdTreeSceneManager::setShowBoxes(bool showboxes)
-{
-	mShowBoxes = showboxes;
-}
-
-bool KdTreeSceneManager::getShowBoxes(void) const
-{
-	return mShowBoxes;
-}
-
-bool KdTreeSceneManager::setOption(const String& strKey, const void* pValue)
-{
-	// change max depth of the kdtree
-	// rebuild the tree if already exists
-	if (strKey == "KdTreeMaxDepth")
-	{
-		int maxdepth = *static_cast<const int *>(pValue);
-
-		// no negative depth, plz!
-		if (maxdepth < 0)
-		{
-			return false;
-		}
-		else
-		{
-			mMaxDepth = maxdepth;
-			if (mHiLiteLevel > mMaxDepth)
-				mHiLiteLevel = mMaxDepth;
-			return true;
-		}
-		return true;
-	}
-	else if (strKey == "KT")
-	{
-		Real kt = *static_cast<const Real *>(pValue);
-		if (kt > 0)
-		{
-			PlaneEvent::KT = kt;
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-	else if (strKey == "KI")
-	{
-		Real ki = *static_cast<const Real *>(pValue);
-		if (ki > 0)
-		{
-			PlaneEvent::KI = ki;
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-	else if (strKey == "RebuildKdTree")
-	{
-		OGRE_DELETE(mBvHierarchy);
-		mBvHierarchy = new KdTree(mMaxDepth, mBuildMethod, mHiLiteLevel, mShowAllBoxes, mShowNodes);
-		mBvHierarchy->build(static_cast<KdTreeSceneNode *>(mSceneRoot));
-		mBvHierarchy->setEnhancedVis(mEnhancedVisiblity);
-		return true;
-	}
-	else if (strKey == "EnhancedVisibility")
-	{
-		bool enh = *static_cast<const bool *>(pValue);
-		mEnhancedVisiblity = enh;
-		if (mBvHierarchy)
-			mBvHierarchy->setEnhancedVis(mEnhancedVisiblity);
-		//setEnhancedVis(enh);
-		return true;
-	}
-	else if (strKey == "BuildMethod")
-	{
-		KdTree::BuildMethod bm = *static_cast<const KdTree::BuildMethod *>(pValue);
-		if (bm == KdTree::KDBM_RECURSIVE || bm == KdTree::KDBM_PRIORITYQUEUE)
-		{
-			mBuildMethod = bm;
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-	else if (strKey == "RenderMethod")
-	{
-		KdTree::RenderMethod rm = *static_cast<const KdTree::RenderMethod *>(pValue);
-		if (rm == KdTree::KDRM_INTERNAL)
-		{
-			mRenderMethod = rm;
-			return true;
-		}
-		else if (rm == KdTree::KDRM_GTP_VFC)
-		{
-			mRenderMethod = rm;
-			int cmt = GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING;
-			return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-				.setOption("Algorithm", &cmt);
-		}
-		else if (rm == KdTree::KDRM_GTP_SWC)
-		{
-			mRenderMethod = rm;
-			int cmt = GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING;
-			return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-				.setOption("Algorithm", &cmt);
-		}
-		else if (rm == KdTree::KDRM_GTP_CHC)
-		{
-			mRenderMethod = rm;
-			int cmt = GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING;
-			return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-				.setOption("Algorithm", &cmt);
-		}
-		else
-		{
-			return false;
-		}
-	}
-	// little hack in case someone uses "Algorithm" option from VisOptMan directly
-	else if (strKey == "Algorithm")
-	{
-		bool success = VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-			.setOption(strKey, pValue);
-		// change setting only if change in VisOptMan was successful
-		if (success)
-		{
-			int val = *static_cast<const int *>(pValue);
-			if (val == GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING)
-				mRenderMethod = KdTree::KDRM_GTP_VFC;
-			else if (val == GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING)
-				mRenderMethod = KdTree::KDRM_GTP_SWC;
-			else if (val == GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
-				mRenderMethod = KdTree::KDRM_GTP_CHC;
-			// default, should never happen
-			else
-				mRenderMethod = KdTree::KDRM_INTERNAL;
-		}
-		else
-		{
-			mRenderMethod = KdTree::KDRM_INTERNAL;
-		}
-		return success;
-	}
-	else if (strKey == "ShowKdTree")
-	{
-		bool sk = *static_cast<const bool *>(pValue);
-		mShowBoxes = sk;
-		return true;
-	}
-	else if (strKey == "HiLiteLevel")
-	{
-		int hl = *static_cast<const int *>(pValue);
-		if (hl >= 0 && hl <= mMaxDepth)
-		{
-			mHiLiteLevel = hl;
-			if (mBvHierarchy)
-				mBvHierarchy->setHiLiteLevel(mHiLiteLevel);
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-	else if (strKey == "ShowAllBoxes")
-	{
-		bool sa = *static_cast<const bool *>(pValue);
-		mShowAllBoxes = sa;
-		if (mBvHierarchy)
-			mBvHierarchy->setShowAllBoxes(mShowAllBoxes);
-		return true;
-	}
-	else if (strKey == "ShowNodes")
-	{
-		bool sn = *static_cast<const bool *>(pValue);
-		mShowNodes = sn;
-		if (mBvHierarchy)
-			mBvHierarchy->setShowNodes(mShowNodes);
-		return true;
-	}
-	// options for CHC
-	else if (strKey == "UseDepthPass")
-	{
-		mUseDepthPass = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "PrepareVisualization")
-	{
-		mShowVisualization = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "RenderNodesForViz")
-	{
-		mRenderNodesForViz = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "RenderNodesContentForViz")
-	{
-		mRenderNodesContentForViz = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "SkyBoxEnabled")
-	{
-		mSkyBoxEnabled = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "SkyPlaneEnabled")
-	{
-		mSkyPlaneEnabled = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "SkyDomeEnabled")
-	{
-		mSkyDomeEnabled = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "VisualizeCulledNodes")
-	{
-		mVisualizeCulledNodes = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "DelayRenderTransparents")
-	{
-		mDelayRenderTransparents = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-
-	else if (strKey == "DepthWrite")
-	{
-		mEnableDepthWrite = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "UseItemBuffer")
-	{
-		mUseItemBuffer = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "ExecuteVertexProgramForAllPasses")
-	{ 
-		mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "RenderTransparentsForItemBuffer")
-	{ 
-		mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	else if (strKey == "DeleteRenderQueue")
-	{
-		mDeleteQueueAfterRendering = (*static_cast<const bool *>(pValue));
-		return true;
-	}
-	// options for viewcells
-	else if (strKey == "LoadViewCells")
-	{ 
-		if (!mViewCellsLoaded)
-		{
-			String filename(static_cast<const char *>(pValue));
-			mViewCellsLoaded = LoadViewCells(filename);	
-		}
-
-		return mViewCellsLoaded;
-	}
-	else if (strKey == "UseViewCells")
-	{ 
-		if (mViewCellsLoaded)
-		{
-			mUseViewCells = *static_cast<const bool *>(pValue);
-
-			// reset view cell
-			OGRE_DELETE(mCurrentViewCell);
-
-			if (mUseViewCells)
-				mCurrentViewCell = mViewCellsManager->GenerateViewCell();
-
-			mElementaryViewCell = NULL;
-
-			// if using view cells, all objects are set to false initially
-			SetObjectsVisible(!mUseViewCells);
-
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-
-	}
-	else if (strKey == "UseVisibilityFilter")
-	{
-		if (mViewCellsLoaded)
-		{
-			mUseVisibilityFilter = *static_cast<const bool *>(pValue);
-			// set null =>recomputation of the pvs
-			mElementaryViewCell = NULL;
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-		.setOption(strKey, pValue) || SceneManager::setOption(strKey, pValue);
-}
-
-bool KdTreeSceneManager::getOption(const String& strKey, void* pDestValue)
-{
-	if (strKey == "KdTreeMaxDepth")
-	{
-		*static_cast<int *>(pDestValue) = mMaxDepth;
-		return true;
-	}
-	else if (strKey == "KT")
-	{
-		*static_cast<Real *>(pDestValue) = PlaneEvent::KT;
-		return true;
-	}
-	else if (strKey == "KI")
-	{
-		*static_cast<Real *>(pDestValue) = PlaneEvent::KI;
-		return true;
-	}
-	else if (strKey == "EnhancedVisibility")
-	{
-		if (mBvHierarchy)
-			*static_cast<bool *>(pDestValue) = mBvHierarchy->getEnhancedVis();
-		else
-			*static_cast<bool *>(pDestValue) = mEnhancedVisiblity;
-		return true;
-	}
-	else if (strKey == "BuildMethod")
-	{
-		*static_cast<KdTree::BuildMethod *>(pDestValue) = mBuildMethod;
-		return true;
-	}
-	else if (strKey == "RenderMethod")
-	{
-		*static_cast<KdTree::RenderMethod *>(pDestValue) = mRenderMethod;
-		return true;
-	}
-	else if (strKey == "ShowKdTree")
-	{
-		*static_cast<bool *>(pDestValue) = mShowBoxes;
-		return true;
-	}	
-	else if (strKey == "HiLiteLevel")
-	{
-		*static_cast<int *>(pDestValue) = mHiLiteLevel;
-		return true;
-	}
-	else if (strKey == "ShowAllBoxes")
-	{
-		*static_cast<bool *>(pDestValue) = mShowAllBoxes;
-		return true;
-	}
-	else if (strKey == "ShowNodes")
-	{
-		*static_cast<bool *>(pDestValue) = mShowNodes;
-		return true;
-	}
-	// vis options
-	else if (strKey == "NumFrustumCulledNodes")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			unsigned int numnodes = 0;
-			if (mBvHierarchy)
-				numnodes = mBvHierarchy->getFramesStats().mFrustumCulledNodes;
-
-			* static_cast<unsigned int *>(pDestValue) = (unsigned int)numnodes;
-			return true;
-		}
-		// otherwise let fall through to VisibilityOptionsManager
-	}
-	else if (strKey == "NumQueryCulledNodes")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			* static_cast<unsigned int *>(pDestValue) = 0;
-			return true;
-		}
-		// otherwise let fall through to VisibilityOptionsManager
-	}
-	else if (strKey == "NumHierarchyNodes")
-	{
-		unsigned int numnodes = 0;
-		if (mBvHierarchy)
-			numnodes = mBvHierarchy->getTreeStats().mNumNodes;
-
-		* static_cast<unsigned int *>(pDestValue) = (unsigned int)numnodes;
-		return true;
-	}
-	else if (strKey == "NumRenderedNodes")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			unsigned int numnodes = 0;
-			if (mBvHierarchy)
-				numnodes = mBvHierarchy->getFramesStats().mRenderedNodes;
-
-			* static_cast<unsigned int *>(pDestValue) = (unsigned int)numnodes;
-			return true;
-		}
-		// otherwise let fall through to VisibilityOptionsManager
-	}
-	else if (strKey == "NumQueriesIssued")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			* static_cast<unsigned int *>(pDestValue) = 0;
-			return true;
-		}
-		// otherwise let fall through to VisibilityOptionsManager
-	}
-	else if (strKey == "NumTraversedNodes")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			unsigned int numnodes = 0;
-			if (mBvHierarchy)
-				numnodes = mBvHierarchy->getFramesStats().mTraversedNodes;
-
-			* static_cast<unsigned int *>(pDestValue) = (unsigned int)numnodes;
-			return true;
-		}
-		// otherwise let fall through to VisibilityOptionsManager
-	}
-	else if (strKey == "VisibilityManager")
-	{
-		* static_cast<GtpVisibility::VisibilityManager **>(pDestValue) = 
-			(GtpVisibility::VisibilityManager *)mVisibilityManager;
-		return true;
-	}
-	else if (strKey == "HierarchInterface")
-	{
-		* static_cast<GtpVisibility::HierarchyInterface **>(pDestValue) = 
-			(GtpVisibility::HierarchyInterface *)mHierarchyInterface;
-		return true;
-	}
-	// view cell options
-
-	else if (strKey == "UseViewCells")
-	{ 
-		*static_cast<bool *>(pDestValue) = mUseViewCells;
-		return mViewCellsLoaded;
-	}
-	else if (strKey == "UseVisibilityFilter")
-	{
-		*static_cast<bool *>(pDestValue) = mUseVisibilityFilter;
-		return mViewCellsLoaded;
-	}
-
-	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-		.getOption(strKey, pDestValue) || SceneManager::getOption(strKey, pDestValue);
-}
-
-bool KdTreeSceneManager::getOptionKeys(StringVector &refKeys)
-{
-	refKeys.push_back("Algorithm");
-	refKeys.push_back("BuildMethod");
-	refKeys.push_back("DelayRenderTransparents");
-	refKeys.push_back("DeleteRenderQueue");
-	refKeys.push_back("DepthWrite");
-	refKeys.push_back("EnhancedVisibility");
-	refKeys.push_back("ExecuteVertexProgramForAllPasses");
-	refKeys.push_back("HiLiteLevel");
-	refKeys.push_back("HierarchInterface");
-	refKeys.push_back("KI");
-	refKeys.push_back("KT");
-	refKeys.push_back("KdTreeMaxDepth");
-	refKeys.push_back("LoadViewCells");
-	refKeys.push_back("NumHierarchyNodes");
-	refKeys.push_back("PrepareVisualization");
-	refKeys.push_back("RebuildKdTree");
-	refKeys.push_back("RenderMethod");
-	refKeys.push_back("RenderNodesContentForViz");
-	refKeys.push_back("RenderNodesForViz");
-	refKeys.push_back("RenderTransparentsForItemBuffer");
-	refKeys.push_back("ShowAllBoxes");
-	refKeys.push_back("ShowKdTree");
-	refKeys.push_back("ShowNodes");
-	refKeys.push_back("SkyBoxEnabled");
-	refKeys.push_back("SkyDomeEnabled");
-	refKeys.push_back("SkyPlaneEnabled");
-	refKeys.push_back("UseDepthPass");
-	refKeys.push_back("UseItemBuffer");
-	refKeys.push_back("UseViewCells");
-	refKeys.push_back("UseVisibilityFilter");
-	refKeys.push_back("VisibilityManager");
-	refKeys.push_back("VisualizeCulledNodes");
-	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
-		.getOptionKeys(refKeys);
-}
-
-bool KdTreeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
-{
-	return SceneManager::getOptionValues(key, refValueList);
-}
-
-void KdTreeSceneManager::setVisibilityManager(GtpVisibility::VisibilityManager *visManager)
-{
-	mVisibilityManager = visManager;
-}
-
-GtpVisibility::VisibilityManager * KdTreeSceneManager::getVisibilityManager()
-{
-	return mVisibilityManager;
-}
-
-GtpVisibility::VisibilityManager * KdTreeSceneManager::GetVisibilityManager()
-{
-	return mVisibilityManager;
-}
-
-KdTreeHierarchyInterface * KdTreeSceneManager::GetHierarchyInterface()
-{
-	return mHierarchyInterface;
-}
-
-Camera* KdTreeSceneManager::createCamera(const String& name)
-{
-	// Check name not used
-	if (mCameras.find(name) != mCameras.end())
-	{
-		OGRE_EXCEPT(
-			Exception::ERR_DUPLICATE_ITEM,
-			"A camera with the name " + name + " already exists",
-			"SceneManager::createCamera" );
-	}
-
-	Camera *c = new BvHierarchyCamera(name, this);
-	mCameras.insert(CameraList::value_type(name, c));
-
-	return c;
-}
-
-SceneNode* KdTreeSceneManager::createSceneNode(void)
-{
-	SceneNode* sn = new KdTreeSceneNode(this);
-	assert(mSceneNodes.find(sn->getName()) == mSceneNodes.end());
-	mSceneNodes[sn->getName()] = sn;
-	return sn;
-}
-
-SceneNode* KdTreeSceneManager::createSceneNode(const String& name)
-{
-	// Check name not used
-	if (mSceneNodes.find(name) != mSceneNodes.end())
-	{
-		OGRE_EXCEPT(
-			Exception::ERR_DUPLICATE_ITEM,
-			"A scene node with the name " + name + " already exists",
-			"KdTreeSceneManager::createSceneNode" );
-	}
-
-	SceneNode* sn = new KdTreeSceneNode(this, name);
-	mSceneNodes[sn->getName()] = sn;
-	return sn;
-}
-
-Entity * KdTreeSceneManager::createEntity(const String& entityName, const String& meshName)
-{
-	Entity *ent = SceneManager::createEntity(entityName, meshName);
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)
-	{
-		ent->getSubEntity(i)->setId(mCurrentEntityId);
-	}
-
-	// increase counter of entity id values
-	++ mCurrentEntityId;
-#endif
-	return ent;
-}
-
-// make sure it's called only for non-empty nodes .. avoids one uneccessary funciton call
-void KdTreeSceneManager::_updateNode(KdTreeSceneNode *node)
-{
-	//LogManager::getSingleton().logMessage("### _updateNode called for " + node->getName());
-
-	/* Rebuild kdtree when it was wiped out
-		* Usually this happens only before the first frame
-		* The initial AABB shall enclose all objects present
-		* in the scene at the time of construction
-		* TODO: find a more appropriate place for it,
-		* e.g., before the first render call
-		* teh stupid thing is I can't find any other place so far ...
-		*/
-	if (!mBvHierarchy)
-	{
-		mBvHierarchy = new KdTree(mMaxDepth, mBuildMethod);
-		mBvHierarchy->build(static_cast<KdTreeSceneNode *>(mSceneRoot));
-		mBvHierarchy->setEnhancedVis(mEnhancedVisiblity);
-	}
-
-	// if the node is in the tree and _updateNode was called, then the node was moved/rotated/resized/wahtever
-	if (node->isAttached())
-	{
-		// TEST: perfomance when adding & removing for every frame
-		//mBvHierarchy->remove(node);
-		//mBvHierarchy->insert(node);
-	}
-	// there's a new node in town ... 
-	else
-	{			
-		// inserting single nodes yields sub-optimal results
-		// rebuilding tree takes too long
-		// "What now?", spoke Zeus ...
-
-		//mBvHierarchy->insert(node);
-		
-		//delete mBvHierarchy;
-		//mBvHierarchy = new KdTree(mMaxDepth);
-		//mBvHierarchy->build(static_cast<KdTreeSceneNode *>(mSceneRoot));
-	}
-
-}
-
-void KdTreeSceneManager::_updateSceneGraph(Camera* cam)
-{
-	mVisibilityManager->GetCullingManager()->SetHierarchyInterface(mHierarchyInterface);
-	mHierarchyInterface->SetRenderSystem(mDestRenderSystem);
-
-	SceneManager::_updateSceneGraph(cam);
-}
-
-void KdTreeSceneManager::_findVisibleObjects(Camera *cam, bool onlyShadowCasters)
-{
-	if (mRenderMethod == KdTree::KDRM_INTERNAL)
-	{
-		getRenderQueue()->clear();
-		if (mShowVisualization)
-		{
-			PrepareVisualization(cam);
-		}
-		else
-		{
-			mVisibleNodes.clear();
-			if (mBvHierarchy)
-			{
-				// determine visibility
-				mBvHierarchy->queueVisibleObjects(KDCAMPTR_CAST(cam), getRenderQueue(), onlyShadowCasters, mShowBoxes, mVisibleNodes);
-				// apply view cell pvs
-				updatePvs(cam);
-			}
-		}
-	}
-	else
-	{
-		//-- show visible scene nodes and octree bounding boxes from last frame
-		if (mShowVisualization)
-		{
-			PrepareVisualization(cam);
-		}
-		else 
-		{	
-			// for hierarchical culling, we interleave identification 
-			// and rendering of objects in _renderVisibibleObjects
-
-			// for the shadow pass we use only standard rendering
-			// because of low occlusion
-			if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
-				mIlluminationStage == IRS_RENDER_TO_TEXTURE)
-			{
-				getRenderQueue()->clear();
-				if (mBvHierarchy)
-					mBvHierarchy->queueVisibleObjects(KDCAMPTR_CAST(cam), getRenderQueue(), onlyShadowCasters, mShowBoxes, mVisibleNodes);
-			}
-
-			// only shadow casters will be rendered in shadow texture pass
-			if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
-
-
-			//-- apply view cell pvs -
-			updatePvs(cam);
-		}
-		mVisibleNodes.clear();	
-	}
-}
-
-void KdTreeSceneManager::_renderVisibleObjects()
-{
-	if (mRenderMethod == KdTree::KDRM_INTERNAL)
-	{
-		SceneManager::_renderVisibleObjects();
-	}
-	else
-	{
-		InitDepthPass(); 	  // create material for depth pass
-		InitItemBufferPass(); // create material for item buffer pass
-
-		// save ambient light to reset later
-		ColourValue savedAmbient = mAmbientLight;
-
-		//-- apply standard rendering for some modes (e.g., visualization, shadow pass)
-
-		if (mShowVisualization ||
-			(mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
-			mIlluminationStage == IRS_RENDER_TO_TEXTURE))
-		{	
-			IlluminationRenderStage savedStage = mIlluminationStage; 
-
-			if (mShowVisualization) 
-			{
-				// disable illumination stage to prevent rendering shadows
-				mIlluminationStage = IRS_NONE;
-			}
-
-			// standard rendering for shadow maps because of performance
-			SceneManager::_renderVisibleObjects();
-
-			mIlluminationStage = savedStage;
-		}
-		else //-- the hierarchical culling algorithm
-		{
-			// this is also called in TerrainSceneManager: really necessary?
-			//mDestRenderSystem -> setLightingEnabled(false);
-
-			// don't render backgrounds for item buffer
-			if (mUseItemBuffer)
-			{
-				clearSpecialCaseRenderQueues();
-				getRenderQueue()->clear();
-			}
-
-			//-- hierarchical culling
-
-			// the objects of different layers (e.g., background, scene, 
-			// overlay) must be identified and rendered one after another
-
-			//-- render all early skies
-			clearSpecialCaseRenderQueues();
-			addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
-			addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
-			setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
-
-			SceneManager::_renderVisibleObjects();
-
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-			// delete previously rendered content
-			_deleteRenderedQueueGroups();
-#endif
-
-			//-- prepare queue for visible objects (i.e., all but overlay and skies late)
-			clearSpecialCaseRenderQueues();
-			addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
-			addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
-
-			// exclude this queues from hierarchical rendering
-			setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
-
-
-			// set all necessary parameters for 
-			// hierarchical visibility culling and rendering
-			InitVisibilityCulling(mCameraInProgress);
-
-
-			/** 
-			* the hierarchical culling algorithm
-			* for depth pass: we just find objects and update depth buffer
-			* for "delayed" rendering: we render some passes afterwards
-			* e.g., transparents, because they need front-to-back sorting
-			**/
-
-			mVisibilityManager->ApplyVisibilityCulling();
-
-			// delete remaining renderables from queue:
-			// all which are not in mLeavePassesInQueue
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-			_deleteRenderedQueueGroups(mLeavePassesInQueue);
-#endif
-
-			//-- reset parameters
-			mIsDepthPassPhase = false;
-			mIsItemBufferPhase = false;
-			mSkipTransparents = false;
-			mIsHierarchicalCulling = false;
-
-			mLeavePassesInQueue = 0;
-
-			// add visible nodes found by the visibility culling algorithm
-			if (mUseDepthPass)
-			{
-				KdTree::NodeList::const_iterator it, end = mVisibleNodes.end();
-				for (it = mVisibleNodes.begin(); it != end; it++)
-				{
-					(*it)->queueVisibleObjects(mHierarchyInterface->GetFrameId(), mCameraInProgress,
-						getRenderQueue(), false, mShowBoxes);
-				}
-			}
-
-			//-- now we can render all remaining queue objects
-			//-- used for depth pass, transparents, overlay
-			clearSpecialCaseRenderQueues();
-
-			SceneManager::_renderVisibleObjects();
-		} // hierarchical culling
-
-
-		// reset ambient light
-		setAmbientLight(savedAmbient);
-
-
-		// almost same effect as below
-		getRenderQueue()->clear(mDeleteQueueAfterRendering);
-
-		//if (!mDeleteQueueAfterRendering)
-		//	getRenderQueue()->clear(true); // finally clear render queue
-		//else
-		//	OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
-
-		if (0) WriteLog(); // write out stats
-	}
-}
-
-
-void KdTreeSceneManager::_renderNode(KdTree::NodePtr node, Camera * cam, 
-									 bool onlyShadowCasters, int leavePassesInQueue)
-{
-	RenderQueueGroup *currentGroup = 
-		getRenderQueue()->getQueueGroup(getRenderQueue()->getDefaultQueueGroup());
-	currentGroup->clear(leavePassesInQueue);
-
-	node->queueVisibleObjects(mHierarchyInterface->GetFrameId(), cam, getRenderQueue(),
-		onlyShadowCasters, mShowBoxes);
-	mVisibleNodes.push_back(node);
-
-	_renderQueueGroupObjects(currentGroup, QueuedRenderableCollection::OM_PASS_GROUP);
-}
-
-//-----------------------------------------------------------------------
-const Pass *KdTreeSceneManager::_setPass(const Pass* pass, bool evenIfSuppressed)
-{
-	if (mRenderMethod == KdTree::KDRM_INTERNAL)
-	{
-		return SceneManager::_setPass(pass);
-	}
-
-	// TODO: setting vertex program is not efficient
-	//Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass); 
-
-	// set depth fill pass if we currently do not make an aabb occlusion query
-	const bool useDepthPass = 
-		(mIsDepthPassPhase && !mHierarchyInterface->IsBoundingBoxQuery());
-
-	const IlluminationRenderStage savedStage = mIlluminationStage; 
-
-	// set illumination stage to NONE so no shadow material is used 
-	// for depth pass or for occlusion query
-	if (mIsDepthPassPhase || mHierarchyInterface->IsBoundingBoxQuery())
-	{
-		mIlluminationStage = IRS_NONE;
-	}
-
-	// --- set vertex program of current pass in order to set correct depth
-	if (mExecuteVertexProgramForAllPasses && 
-		mIsDepthPassPhase && 
-		pass->hasVertexProgram())
-	{
-		// add vertex program of current pass to depth pass
-		mDepthPass->setVertexProgram(pass->getVertexProgramName());
-
-		if (mDepthPass->hasVertexProgram())
-		{
-			const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
-			// Load this program if not done already
-			if (!prg->isLoaded())
-				prg->load();
-			// Copy params
-			mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
-		}
-	}
-	else if (mDepthPass->hasVertexProgram()) // reset vertex program
-	{
-		mDepthPass->setVertexProgram("");
-	}
-
-	const Pass *usedPass = useDepthPass ? mDepthPass : pass;
-
-	// save old depth write: needed for item buffer
-	const bool IsDepthWrite = usedPass->getDepthWriteEnabled();
-
-	// global option which enables / disables depth writes
-	if (!mEnableDepthWrite)
-	{
-		//	usedPass->setDepthWriteEnabled(false);
-	}
-	//else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
-
-
-	//-- set actual pass here
-	const Pass *result = SceneManager::_setPass(usedPass);
-
-
-	// reset depth write
-	if (!mEnableDepthWrite)
-	{
-		//	usedPass->setDepthWriteEnabled(IsDepthWrite);
-	}
-
-	// reset illumination stage
-	mIlluminationStage = savedStage;
-
-	return result;
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
-													  QueuedRenderableCollection::OrganisationMode om)
-{
-	// Basic render loop
-	// Iterate through priorities
-	RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-
-	while (groupIt.hasMoreElements())
-	{
-		RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-		// Sort the queue first
-		pPriorityGrp->sort(mCameraInProgress);
-
-		// Do solids
-		renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
-
-		// for correct rendering, transparents must be rendered after hierarchical culling
-		// => do nothing
-
-		// Do transparents (always descending)
-		if (mRenderMethod == KdTree::KDRM_INTERNAL || !mSkipTransparents)
-		{
-			renderObjects(pPriorityGrp->getTransparents(), 
-				QueuedRenderableCollection::OM_SORT_DESCENDING, true);
-		}
-
-
-	}// for each priority
-}
-//-----------------------------------------------------------------------
-bool KdTreeSceneManager::validatePassForRendering(Pass* pass)
-{
-	if (mRenderMethod == KdTree::KDRM_INTERNAL)
-	{
-		return SceneManager::validatePassForRendering(pass);
-	}
-
-	// skip all but first pass if we are doing the depth pass
-	if ((mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() > 0))
-	{
-		return false;
-	}
-	// all but first pass
-	/*else if ((!mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() != 0))
-	{
-	return false;
-	}*/
-
-	return SceneManager::validatePassForRendering(pass);
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::_renderQueueGroupObjects(RenderQueueGroup* pGroup, 
-												  QueuedRenderableCollection::OrganisationMode om)
-{
-	if (mRenderMethod == KdTree::KDRM_INTERNAL || !mIsItemBufferPhase)
-	{
-		SceneManager::_renderQueueGroupObjects(pGroup, om);
-		return;
-	}
-#ifdef  ITEM_BUFFER
-	//-- item buffer
-	//-- item buffer: render objects using false colors
-
-	// Iterate through priorities
-	RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-
-	while (groupIt.hasMoreElements())
-	{
-		RenderItemBuffer(groupIt.getNext());
-	}
-#endif // ITEM_BUFFER
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
-	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
-{
-	// only render solid passes during hierarchical culling
-	if (mIsHierarchicalCulling)
-	{
-		RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-		LightList lightList;
-
-		while (groupIt.hasMoreElements())
-		{
-			RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-			// Sort the queue first
-			pPriorityGrp->sort(mCameraInProgress);
-
-			// Clear light list
-			lightList.clear();
-
-			// Render all the ambient passes first, no light iteration, no lights
-			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
-			// mIlluminationStage = IRS_AMBIENT;
-
-			SceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
-			// Also render any objects which have receive shadows disabled
-			SceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
-		}
-	}
-	else // render the rest of the passes
-	{
-		SceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
-	}
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
-	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
-{
-	if (mIsHierarchicalCulling)
-	{
-		// Iterate through priorities
-		RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-
-		while (groupIt.hasMoreElements())
-		{
-			RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-			// Sort the queue first
-			pPriorityGrp->sort(mCameraInProgress);
-
-			// Do (shadowable) solids
-			SceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
-		}
-	}
-	else
-	{
-		SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
-	}
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::InitDepthPass()
-{
-	MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
-
-	if (depthMat.isNull())
-	{
-		depthMat = MaterialManager::getSingleton().create(
-			"Visibility/DepthPass",
-			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
-
-		mDepthPass = depthMat->getTechnique(0)->getPass(0);
-		mDepthPass->setColourWriteEnabled(false);
-		mDepthPass->setDepthWriteEnabled(true);
-		mDepthPass->setLightingEnabled(false);
-	}
-	else
-	{
-		mDepthPass = depthMat->getTechnique(0)->getPass(0);
-	}
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::InitItemBufferPass()
-{
-	MaterialPtr itemBufferMat = MaterialManager::getSingleton().
-		getByName("Visibility/ItemBufferPass");
-
-	if (itemBufferMat.isNull())
-	{
-		// Init
-		itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass",
-			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
-
-		mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
-		mItemBufferPass->setColourWriteEnabled(true);
-		mItemBufferPass->setDepthWriteEnabled(true);
-		mItemBufferPass->setLightingEnabled(true);
-		//mItemBufferPass->setLightingEnabled(false);
-	}
-	else
-	{
-		mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0);
-	}
-	//mItemBufferPass->setAmbient(1, 1, 0);
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::PrepareVisualization(Camera *cam)
-{
-	// add player camera for visualization purpose
-	try 
-	{
-		Camera *c;
-		if ((c = getCamera("PlayerCam")) != NULL)
-		{
-			getRenderQueue()->addRenderable(c);
-		}   
-	}
-	catch (...)
-	{
-		// ignore
-	}
-
-	if (mRenderNodesForViz || mRenderNodesContentForViz)
-	{
-		RenderQueue * queue = getRenderQueue();
-		unsigned long frameid = 0;
-
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-			frameid = Root::getSingleton().getCurrentFrameNumber();
-		else
-			frameid = mHierarchyInterface->GetFrameId();
-
-		for (KdTree::NodeList::iterator it = mVisibleNodes.begin(); it != mVisibleNodes.end(); ++it)
-		{
-			if (mRenderNodesForViz && (*it)->isLeaf())
-			{
-				WireBoundingBox * wirebox = (*it)->getWireBoundingBox();
-				wirebox->setMaterial("KdTree/BoxViz");
-				getRenderQueue()->addRenderable(wirebox);
-			}
-			// add renderables itself
-			if (mRenderNodesContentForViz) 
-			{
-				(*it)->queueVisibleObjects(frameid, cam, queue, false, false);
-			}
-		}
-	}	
-}
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::InitVisibilityCulling(Camera *cam)
-{
-	// reset culling manager stats
-	mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
-
-	// set depth pass flag before rendering
-	mIsDepthPassPhase = mUseDepthPass;
-
-	mIsHierarchicalCulling = true; // during hierarchical culling
-
-	// item buffer needs full ambient lighting to use item colors as unique id
-	if (mUseItemBuffer) 
-	{
-		mIsItemBufferPhase = true;
-		setAmbientLight(ColourValue(1,1,1,1));
-	}
-
-
-	// set passes which are stored in render queue 
-	// for rendering AFTER hierarchical culling, i.e., passes which need 
-	// a special rendering order
-
-	mLeavePassesInQueue = 0;
-
-	// if we have the depth pass or use an item buffer, no passes are left in the queue
-	if (1 && !mUseDepthPass && !mUseItemBuffer)
-	{
-		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
-		{
-			// TODO: remove this pass because it should be processed during hierarchical culling
-			//mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
-
-			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
-			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR;
-			mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
-
-			// just render ambient passes
-			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
-			// mIlluminationStage = IRS_AMBIENT; 
-			//getRenderQueue()->setSplitPassesByLightingType(true);
-		}
-
-		if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
-		{
-			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
-			mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
-		}
-
-		// transparents should be rendered after hierarchical culling to 
-		// provide front-to-back ordering
-		if (mDelayRenderTransparents)
-		{
-			mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
-		}
-	}
-
-	// skip rendering transparents during the hierarchical culling
-	// (because they will be rendered afterwards)
-	mSkipTransparents = 
-		(mIsDepthPassPhase || (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES));
-
-	// -- initialise interface for rendering traversal of the hierarchy
-	mHierarchyInterface->SetHierarchyRoot(mBvHierarchy->getRoot());
-
-	// possible two cameras (one for culling, one for rendering)
-	mHierarchyInterface->InitTraversal(mCameraInProgress, 
-		/*mCullCamera ? getCamera("CullCamera") : */NULL,
-		mLeavePassesInQueue);
-
-}
-
-//-------------------------------------------------------------------------
-void KdTreeSceneManager::SetObjectsVisible(const bool visible)
-{
-	GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
-
-	for (it = mObjects.begin(); it != it_end; ++ it)
-	{
-		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*it);
-		Entity *ent = omi->GetMesh();
-
-		ent->setVisible(visible);
-	}
-}
-//-----------------------------------------------------------------------
-bool KdTreeSceneManager::LoadViewCells(const String &filename)
-{
-	// objects are set to invisible initially
-	SetObjectsVisible(false);
-
-	const string bboxesFilename = mVisibilityManager->GetVisibilityEnvironment()->getViewCellsFileName();
-
-	// converter between view cell ids and Ogre entites 
-	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
-	OgreBoundingBoxConverter bconverter(this);
-
-	// load the view cells assigning the found objects to the pvss
-	mViewCellsManager = 
-		GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects, false, &bconverter);
-
-	return (mViewCellsManager != NULL);
-}
-//-------------------------------------------------------------------------
-void KdTreeSceneManager::applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 
-													const bool load)
-{	// NOTE: should not happen, rather apply view cell representing unbounded space then
-	if (!vc) 
-	{	
-		// set everything visible for savety
-		SetObjectsVisible(true);
-
-		return;
-	}
-
-	GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator oit,
-		oit_end = vc->GetPvs().mEntries.end();
-
-	//-- PVS of view cell
-	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
-	{
-		if (!(*oit).first) continue;
-
-		OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>((*oit).first);
-		omi->GetMesh()->setVisible(load);
-		//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
-	}
-}
-//-------------------------------------------------------------------------
-void KdTreeSceneManager::updatePvs(Camera *cam)
-{
-	if (!(mViewCellsLoaded && mUseViewCells))
-		return;
-
-	const GtpVisibilityPreprocessor::Vector3 viewPoint = 
-		OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
-
-	GtpVisibilityPreprocessor::ViewCell *newElementary = 
-		mViewCellsManager->GetViewCell(viewPoint);
-
-	// elementary view cell did not change => apply same pvs
-	if (mElementaryViewCell == newElementary)
-		return;
-
-	mElementaryViewCell = newElementary;
-	//LogManager::getSingleton().logMessage("unloading");
-	//-- unload old pvs
-	applyViewCellPvs(mCurrentViewCell, false);
-
-
-	//-- the new view cell
-
-	GtpVisibilityPreprocessor::ViewCell *viewCell;
-
-
-	if (mUseVisibilityFilter)
-	{
-		//-- compute new filtered cell
-		GtpVisibilityPreprocessor::PrVs prvs;
-		mViewCellsManager->GetPrVS(viewPoint, prvs, 5);
-		viewCell = prvs.mViewCell;
-	}
-	else
-	{
-		viewCell = newElementary;
-	}
-	//LogManager::getSingleton().logMessage("loading");
-	//-- load new pvs
-	applyViewCellPvs(viewCell, true);
-
-	// store pvs
-	mCurrentViewCell->SetPvs(viewCell->GetPvs());
-
-	// delete merge tree of filtered view cell
-	if (mUseVisibilityFilter)
-		mViewCellsManager->DeleteLocalMergeTree(viewCell);
-}
-
-//-----------------------------------------------------------------------
-void KdTreeSceneManager::WriteLog()
-{
-	std::stringstream d;
-
-	d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
-		<< "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
-		<< "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
-		<< "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
-		<< "Hierarchy nodes: " << (mBvHierarchy ? mBvHierarchy->getTreeStats().mNumNodes : 0) << ", " 
-		<< "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
-		<< "Rendered nodes: " << mHierarchyInterface->GetNumRenderedNodes() << ", "
-		<< "Query culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumQueryCulledNodes() << ", "
-		<< "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
-		<< "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << ", "
-		<< "Found objects: " << (int)mVisibleNodes.size() << "\n"
-		;
-
-	LogManager::getSingleton().logMessage(d.str());
-}
-
-/************************************************************************/
-/* Factory for KdTreeSceneManager                                       */
-/************************************************************************/
-//-----------------------------------------------------------------------
-//-----------------------------------------------------------------------
-const String BvHierarchySceneManagerFactory::FACTORY_TYPE_NAME = "KdTreeSceneManager";
-//-----------------------------------------------------------------------
-void BvHierarchySceneManagerFactory::initMetaData(void) const
-{
-	mMetaData.typeName = FACTORY_TYPE_NAME;
-	mMetaData.description = "Scene manager that organises the scene based on a kd-tree";
-	mMetaData.sceneTypeMask = 0xFFFF; // support all types of scenes (hopefully)
-	mMetaData.worldGeometrySupported = false;
-}
-//-----------------------------------------------------------------------
-SceneManager* BvHierarchySceneManagerFactory::createInstance(
-	const String& instanceName)
-{
-	return new KdTreeSceneManager(instanceName, visManager);
-}
-//-----------------------------------------------------------------------
-void BvHierarchySceneManagerFactory::destroyInstance(SceneManager* instance)
-{
-	delete instance;
-}
-
-} // namespace Ogre
-
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchyCamera.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/OgreBvHierarchyCamera.cpp	(revision 1319)
+++ 	(revision )
@@ -1,104 +1,0 @@
-/*
------------------------------------------------------------------------------
-This source file is part of the GameTools Project
-http://www.gametools.org
-
-Author: Martin Szydlowski
------------------------------------------------------------------------------
-*/
-
-#include "OgreBvHierarchyCamera.h"
-
-namespace Ogre
-{
-
-BvHierarchyCamera::BvHierarchyCamera(const String& name, SceneManager *sm):
-Camera(name, sm)
-{
-
-}
-
-BvHierarchyCamera::~BvHierarchyCamera()
-{
-
-}
-
-//-----------------------------------------------------------------------
-// enhanced vis calculation - borrowed from OctreeCamera - indicate when entire box inside the frustum
-BvHierarchyCamera::NodeVisibility BvHierarchyCamera::getVisibilityEnhanced(const AxisAlignedBox& box) const
-{
-	++ mNumVisQueries;
-	
-	// Null boxes always invisible
-	if ( box.isNull() )
-		return KDNV_NONE;
-
-	// Make any pending updates to the calculated frustum planes
-	updateFrustumPlanes();
-
-	// Get corners of the box
-	const Vector3* pCorners = box.getAllCorners();
-
-	// For each plane, see if all points are on the negative side
-	// If so, object is not visible.
-	// If one or more are, it's partial.
-	// If all aren't, full
-
-	int corners[ 8 ] = {0, 4, 3, 5, 2, 6, 1, 7};
-
-	int planes[ 6 ] = {FRUSTUM_PLANE_TOP, FRUSTUM_PLANE_BOTTOM,
-		FRUSTUM_PLANE_LEFT, FRUSTUM_PLANE_RIGHT,
-		FRUSTUM_PLANE_FAR, FRUSTUM_PLANE_NEAR };
-
-	bool all_inside = true;
-
-	for ( int plane = 0; plane < 6; ++plane )
-	{
-
-		// Skip far plane if infinite view frustum
-		if (mFarDist == 0 && planes[ plane ] == FRUSTUM_PLANE_FAR)
-			continue;
-
-		bool all_outside = true;
-
-		float distance = 0;
-
-		for ( int corner = 0; corner < 8; ++corner )
-		{
-			distance = mFrustumPlanes[ planes[ plane ] ].getDistance( pCorners[ corners[ corner ] ] );
-			all_outside = all_outside && ( distance < 0 );
-			all_inside = all_inside && ( distance >= 0 );
-
-			if ( !all_outside && !all_inside )
-				break;
-		}
-
-		if ( all_outside )
-			return KDNV_NONE;
-	}
-
-	if ( all_inside )
-		return KDNV_FULL;
-	else
-		return KDNV_PART;
-}
-
-//-----------------------------------------------------------------------
-// simple vis calculation - does the same as isVisible, only different return type
-BvHierarchyCamera::NodeVisibility BvHierarchyCamera::getVisibilitySimple(const AxisAlignedBox& box) const
-{
-	++ mNumVisQueries;
-
-	// dummy
-	FrustumPlane* culledBy = 0;
-	if (mCullFrustum)
-	{
-		return mCullFrustum->isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
-	}
-	else
-	{
-		return Frustum::isVisible(box, culledBy) ? KDNV_PART : KDNV_NONE;
-	}
-}
-
-} // namespace Ogre
