Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1170)
@@ -11,4 +11,11 @@
 #define _OgreKdTree_H__
 
+#define KDNODE_CAST(a) (static_cast<KdTree::Node>(a))
+#define KDBRANCH_CAST(a) (static_cast<KdTree::Branch>(a))
+#define KDLEAF_CAST(a) (static_cast<KdTree::Leaf>(a))
+#define KDNODEPTR_CAST(a) (static_cast<KdTree::Node *>(a))
+#define KDBRANCHPTR_CAST(a) (static_cast<KdTree::Branch *>(a))
+#define KDLEAFPTR_CAST(a) (static_cast<KdTree::Leaf *>(a))
+
 #include <OgreAxisAlignedBox.h>
 #include <OgreWireBoundingBox.h>
@@ -20,5 +27,6 @@
 #include <stack>
 
-#include "OgreKdTreeHierarchyInterface.h"
+//#include "OgreKdTreeHierarchyInterface.h"
+
 
 namespace Ogre
@@ -199,4 +207,5 @@
 			virtual bool isLeaf() const = 0;
 			virtual bool isEmpty() const = 0;
+			virtual bool hasGeometry() const = 0;
 			
 			// consider using typesafe callback functions
@@ -240,4 +249,37 @@
 			}
 
+			// functions for the CHC hierarchy interface
+
+			/** Returns last visited frame id. */
+			unsigned int lastVisited(void) { return mLastVisited; };
+			/** Set to current frame id.
+			@param current frame id.
+			*/
+			void setLastVisited(unsigned int frameid) { mLastVisited = frameid; };
+			/** Makes this octree become visible / invisble.
+			@param visible Whether this node is to be made visible or invisible
+			*/
+			void setNodeVisible(bool visible) { mVisible = visible; };
+			/** Returns true if this node is marked visible, false otherwise. 
+			*/
+			bool isNodeVisible(void) { return mVisible; };
+			/** Gets this node's parent (NULL if this is the root).
+			*/	
+			KdTree::Node *getParent(void) { return mParent; };
+			/** Frame id when this octree was last rendered. 
+			@return last rendered frame id
+			*/	
+			unsigned int lastRendered(void) { return mLastRendered; };
+			/** Sets frame id when this octree was last rendered. 
+			@param last rendered frame id
+			*/
+			void setLastRendered(unsigned int frameid) { mLastRendered = frameid; };
+
+			/* do we need this? */
+			/** Returns real extent of the octree, i.e., the merged extent of the bounding boxes. 
+			*/
+			//AxisAlignedBox _getWorldAABB(void) const = 0;
+
+
 			Branch * mParent;
 			int mLevel;
@@ -245,4 +287,12 @@
 		protected:
 			WireBoundingBox * mWBB;
+
+			// for the CHC hierarchy interface
+			/** the real extent of the node. */
+			//AxisAlignedBox mWorldAABB;
+
+			unsigned int mLastRendered;
+			unsigned int mLastVisited;
+			bool mVisible;
 		};
 
@@ -265,7 +315,12 @@
 			};
 
+			// a branch is not a leaf 
 			virtual bool isLeaf() const { return false; };
 
+			// s branch is empty when it does not have children
 			virtual bool isEmpty() const { return (mLeft == 0 && mRight == 0); }
+
+			// a branch never has geometry
+			virtual bool hasGeometry() const { return false; };
 			
 			Node * mLeft;
@@ -284,7 +339,12 @@
 			virtual ~Leaf();
 
+			// a leaf is a leaf, dammit
 			virtual bool isLeaf() const { return true; };
 
+			// a leaf is empty when it does not posses renderables
 			virtual bool isEmpty() const { return mKdRenderables.empty(); };
+
+			// a leaf has geometry when it has renderables
+			virtual bool hasGeometry() const { return !mKdRenderables.empty(); };
 
 			virtual void remove(KdRenderable * rend)
@@ -337,12 +397,22 @@
 		};
 
-		//typedef std::stack<SplitCandidate> SplitCandidatePQ;
+		// typedef std::stack<SplitCandidate> SplitCandidatePQ;
 		typedef std::priority_queue<SplitCandidate> SplitCandidatePQ;
 
+		// nodestack for the stack-based rendering function
+		typedef std::stack<KdTree::Node *> NodeStack;
 	public:
-		friend class Ogre::KdTreeHierarchyInterface;
+		friend class KdTreeHierarchyInterface;
 
 		typedef KdTree::Leaf * LeafPtr;
 		typedef std::set<LeafPtr> LeafSet;
+
+		enum RenderMethod
+		{
+			KDRM_RECURSE,
+			KDRM_STACK,
+			KDRM_SAW,
+			KDRM_CHC
+		};
 
 		enum BuildMethod
@@ -356,6 +426,6 @@
 
 		// DEBUG
-		void KdTree::dump();
-		void KdTree::calcCost();
+		void dump();
+		void calcCost();
 
 		// insert a new scene node into an existing kd-tree
@@ -367,5 +437,6 @@
 
 		// test visibility of objects and add to render	queue
-		void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes = false);
+		void queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 
+			RenderMethod renderMethod, bool showBoxes = false);
 
 		// self-explanatory ...
@@ -396,5 +467,9 @@
 
 		// recursive rendering function
-		void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes);
+		void recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 
+			Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes);
+		// stack based rendering function
+		void stackQueueVisibleObjects(KdTree::Node * root, unsigned long currentFrame, 
+			Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes);
 
 		// the root node of the kdtree
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1170)
@@ -70,4 +70,6 @@
 		bool mShowBoxes;
 
+		KdTree::RenderMethod mRenderMethod;
+
 		KdTree::BuildMethod mBuildMethod;
 #ifdef KDTREE_DEBUG
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 1170)
@@ -11,5 +11,5 @@
 #define _OgreKdTreeHierarchyInterface_H_
 
-#include "OgreSceneNodeHierarchyInterface.h"
+#include "OgrePlatformHierarchyInterface.h"
 
 namespace Ogre
@@ -18,11 +18,79 @@
 class KdTreeSceneManager;
 
-class KdTreeHierarchyInterface : public SceneNodeHierarchyInterface
+class KdTreeHierarchyInterface : public PlatformHierarchyInterface
 {
 public:
 	KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys);
+
 	virtual ~KdTreeHierarchyInterface() {};
 
-	bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
+	/** Returns true if current node is leaf of the hierarchy. 
+	@param node hierarchy node
+	@returns true if node is leaf
+	*/
+	virtual bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
+	/** Traverses and renders the hierarchy from the given node. 
+	@param node the hierarchy node
+	*/
+	virtual void TraverseNode(GtpVisibility::HierarchyNode *node);
+	/** Renders the given hierarchy node.
+	@param node current hierarchy node to be rendered
+	*/
+	virtual void RenderNode(GtpVisibility::HierarchyNode *node);
+	/** Pulls up the visibility from the current node recursively to the parent nodes. 
+	@param node the current node 
+	*/
+	virtual void PullUpVisibility(GtpVisibility::HierarchyNode *node) const;
+
+	/** Returns distance of the node to the view plane.
+	@param node the hierarchy node
+	*/			
+	virtual float GetSquaredDistance(GtpVisibility::HierarchyNode *node) const;
+	/** Returns pointer to bounding box of node.
+	@param node current hierarchy node
+	@returns bounding box of current node
+	*/
+	virtual AxisAlignedBox *GetBoundingBox(GtpVisibility::HierarchyNode *node);
+	/** Returns true if there is renderable geometry attached to this node
+	@param node the current node
+	@returns if the node has renderable geometry
+	*/
+	virtual bool HasGeometry(GtpVisibility::HierarchyNode *node) const;
+	/** Sets the visible flag for this node.
+	@param node the current node
+	@param visible the visible flag
+	*/
+	virtual void SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const;
+	/** Returns true if node has the visible flag set. See set
+	*/
+	virtual bool IsNodeVisible(GtpVisibility::HierarchyNode *node) const;
+	/** Sets the last visited frame id for this node.
+	@param node the current node
+	@param frameId the current frame id
+	*/
+	virtual void SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const;
+	/** Returns frame id when this node was last visited by the traverser. See set
+	*/
+	virtual unsigned int LastVisited(GtpVisibility::HierarchyNode *node) const;
+
+
+	/** Visualization of a culled node, dependent on the culling type. 
+	@param node the hierarchy node to be visualized
+	@param type can be one of FRUSTUM_CULLED, QUERY_CULLED
+	*/
+	virtual void VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 
+		GtpVisibility::CullingType type) const;
+
+
+	/** Returns the geometry of a given hierarchy node. 
+	@param node the hierarchy node containing the geometry
+	@param geometryList geometry is returned in this list
+	@param includeChildren if the geometry of the children should be taken into account
+	*/
+	virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,	
+		GtpVisibility::GeometryVector *geometryList, 
+		bool includeChildren);
+
+
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1170)
@@ -32,4 +32,6 @@
 		// kill the old kd-tree if exists 
 		OGRE_DELETE(mKdTree);
+
+		mRenderMethod = KdTree::KDRM_RECURSE;
 
 		//mBuildMethod = KdTree::KDBM_RECURSIVE;
@@ -160,4 +162,32 @@
 			}
 		}
+		else if (strKey == "RenderMethod")
+		{
+			String rm = *static_cast<const String *>(pValue);
+			if (rm == "Recursive")
+			{
+				mRenderMethod = KdTree::KDRM_RECURSE;
+				return true;
+			}
+			else if (rm == "Stack")
+			{
+				mRenderMethod = KdTree::KDRM_STACK;
+				return true;
+			}
+			else if (rm == "StopAndWait")
+			{
+				mRenderMethod = KdTree::KDRM_SAW;
+				return true;
+			}
+			else if (rm == "CHC")
+			{
+				mRenderMethod = KdTree::KDRM_CHC;
+				return true;
+			}
+			else
+			{
+				return false;
+			}
+		}
 		else if (strKey == "ShowKdTree")
 		{
@@ -208,4 +238,24 @@
 			{
 				*static_cast<String *>(pDestValue) = "Recursive";
+			}
+			return true;
+		}
+		else if (strKey == "RenderMethod")
+		{
+			if (mRenderMethod == KdTree::KDRM_RECURSE)
+			{
+				*static_cast<String *>(pDestValue) = "Recursive";
+			}
+			else if (mRenderMethod == KdTree::KDRM_STACK)
+			{
+				*static_cast<String *>(pDestValue) = "Stack";
+			}
+			else if (mRenderMethod == KdTree::KDRM_SAW)
+			{
+				*static_cast<String *>(pDestValue) = "StopAndWait";
+			}
+			else if (mRenderMethod == KdTree::KDRM_CHC)
+			{
+				*static_cast<String *>(pDestValue) = "CHC";
 			}
 			return true;
@@ -278,5 +328,5 @@
 			// inserting single nodes yields sub-optimal results
 			// rebuilding tree takes too long
-			// "What now", spoke Zeus ...
+			// "What now?", spoke Zeus ...
 
 			//mKdTree->insert(node);
@@ -293,5 +343,5 @@
 		getRenderQueue()->clear();
 		if (mKdTree)
-			mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mShowBoxes);
+			mKdTree->queueVisibleObjects(cam, getRenderQueue(), onlyShadowCasters, mRenderMethod, mShowBoxes);
 		//SceneManager::_findVisibleObjects(cam, onlyShadowCasters);
 	}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeHierarchyInterface.cpp	(revision 1170)
@@ -15,5 +15,5 @@
 
 KdTreeHierarchyInterface::KdTreeHierarchyInterface(KdTreeSceneManager *sm, RenderSystem *rsys):
-	SceneNodeHierarchyInterface(sm, rsys)
+PlatformHierarchyInterface(sm, rsys)
 {
 
@@ -22,8 +22,92 @@
 bool KdTreeHierarchyInterface::IsLeaf(GtpVisibility::HierarchyNode *node) const
 {
-	KdTree::Node * kdnode = static_cast<KdTree::Node *>(node);
-	return kdnode->isLeaf();
+	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
+	{
+		KdTree::Branch * kdbranch = KDBRANCHPTR_CAST(node);
+		if (kdbranch->mLeft)
+			mDistanceQueue->push(kdbranch->mLeft);
+		if (kdbranch->mRight)
+			mDistanceQueue->push(kdbranch->mRight);
+	}
 }
+
+void KdTreeHierarchyInterface::RenderNode(GtpVisibility::HierarchyNode *node)
+{
+	/*** TODO ***/
+}
+
+void KdTreeHierarchyInterface::PullUpVisibility(GtpVisibility::HierarchyNode *node) const
+{
+	/*** TODO ***/
+}
+
+float KdTreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const
+{
+	/*** TODO ***/
+	return 0.0;
+}
+
+AxisAlignedBox * KdTreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
+{
+	/*** TODO ***/
+	return new AxisAlignedBox();
+}
+
+bool KdTreeHierarchyInterface::HasGeometry(GtpVisibility::HierarchyNode *node) const
+{
+	return KDNODEPTR_CAST(node)->hasGeometry();
+}
+
+void KdTreeHierarchyInterface::SetNodeVisible(GtpVisibility::HierarchyNode *node, const bool visible) const
+{
+	/*** TODO ***/
+}
+
+bool KdTreeHierarchyInterface::IsNodeVisible(GtpVisibility::HierarchyNode *node) const
+{
+	/*** TODO ***/
+	return true;
+}
+
+void KdTreeHierarchyInterface::SetLastVisited(GtpVisibility::HierarchyNode *node, const unsigned int frameId) const
+{
+	/*** TODO ***/
+}
+
+unsigned int KdTreeHierarchyInterface::LastVisited(GtpVisibility::HierarchyNode *node) const
+{
+	/*** TODO ***/
+	return 0;
+}
+
+void KdTreeHierarchyInterface::VisualizeCulledNode(GtpVisibility::HierarchyNode *node, 
+												   GtpVisibility::CullingType type) const
+{
+	/*** TODO ***/
+}
+
+void KdTreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node, 
+												   GtpVisibility::GeometryVector *geometryList, 
+												   bool includeChildren) 
+{
+	/*** TODO ***/
+}
+
+} // namespace Ogre
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1163)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1170)
@@ -465,5 +465,5 @@
 		else
 		{
-			KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);
+			KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
 			AxisAlignedBox aabb = rend->getBoundingBox();
 			Plane::Side smin = branch->mSplitPlane->getSide(aabb.getMinimum());
@@ -576,5 +576,5 @@
 		else
 		{
-			KdTree::Branch * parent = static_cast<KdTree::Branch *>(node->mParent);
+			KdTree::Branch * parent = KDBRANCHPTR_CAST(node->mParent);
 
 			if (node == parent->mLeft)
@@ -619,5 +619,5 @@
 		if (node->isLeaf())
 		{
-			KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);
+			KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
 			KdRenderableList::iterator it  = leaf->mKdRenderables.begin();
 			KdRenderableList::iterator end = leaf->mKdRenderables.end();
@@ -630,5 +630,5 @@
 		else
 		{
-			KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);
+			KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
 			if (branch->mLeft)
 				addRendToList(branch->mLeft, nodelist);
@@ -1272,11 +1272,25 @@
 	}
 
-	void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes)
-	{
+	void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 
+		KdTree::RenderMethod renderMethod, bool showBoxes)
+	{
+		// for now only recurse or stack render methods
 		if (mKdRoot)
-			recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), cam, queue, onlyShadowCasters, showBoxes);
-	}
-
-	void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes)
+		{
+			//if (renderMethod == KdTree::KDRM_STACK)
+			//{
+			//	stackQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), 
+			//		cam, queue, onlyShadowCasters, showBoxes);
+			//}
+			//else
+			//{
+				recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(),
+					cam, queue, onlyShadowCasters, showBoxes);
+			//}
+		}
+	}
+
+	void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 
+		Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes)
 	{
 		// test visibility
@@ -1291,5 +1305,5 @@
 			if (node->isLeaf())
 			{
-				KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);
+				KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
 				KdRenderableList::iterator it  = leaf->mKdRenderables.begin();
 				KdRenderableList::iterator end = leaf->mKdRenderables.end();
@@ -1312,5 +1326,5 @@
 			else
 			{
-				KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);
+				KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
 #ifdef KDTREE_DEBUG
 				if (wbb)
@@ -1325,4 +1339,67 @@
 				if (branch->mRight)
 					recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes);
+			}
+		}
+	}
+
+	void KdTree::stackQueueVisibleObjects(KdTree::Node * root, unsigned long currentFrame, Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes)
+	{
+		static NodeStack nodestack;
+		if (!nodestack.empty()) OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
+			"Stuff left in stack from previos frame", "KdTree::stackQueueVisibleObjects");
+
+		nodestack.push(root);
+
+		while (!nodestack.empty())
+		{
+			KdTree::Node * node = nodestack.top();
+			nodestack.pop();
+
+			// test visibility
+			if (cam->isVisible(node->mAABB))
+			{
+	#ifdef KDTREE_DEBUG
+				WireBoundingBox * wbb = 0;
+				if (showBoxes)
+					wbb = node->getWireBoundingBox();
+	#endif
+
+				if (node->isLeaf())
+				{
+					KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
+					KdRenderableList::iterator it  = leaf->mKdRenderables.begin();
+					KdRenderableList::iterator end = leaf->mKdRenderables.end();
+					while (it != end)
+					{			
+						if (!(*it)->isQueued(currentFrame, cam))
+						{
+							(*it)->queueObjects(cam, queue, onlyShadowCasters);
+						}
+						it++;
+					}
+	#ifdef KDTREE_DEBUG
+					if (wbb)
+						queue->addRenderable(wbb);
+	#else
+					if (showBoxes)
+						queue->addRenderable(leaf->getWireBoundingBox());
+	#endif
+				}
+				else
+				{
+					KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
+	#ifdef KDTREE_DEBUG
+					if (wbb)
+						queue->addRenderable(wbb);
+	#else
+					if (showBoxes)
+						queue->addRenderable(branch->getWireBoundingBox());
+	#endif
+
+					if (branch->mLeft)
+						nodestack.push(branch->mLeft);
+					if (branch->mRight)
+						nodestack.push(branch->mRight);
+				}
 			}
 		}
@@ -1351,5 +1428,5 @@
 		if (node->isLeaf())
 		{
-			KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);
+			KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
 			KdRenderableList::iterator it  = leaf->mKdRenderables.begin();
 			KdRenderableList::iterator end = leaf->mKdRenderables.end();
@@ -1365,5 +1442,5 @@
 		else
 		{
-			KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);
+			KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
 			if (branch->mLeft)
 			{
@@ -1396,10 +1473,10 @@
 		if (node->isLeaf())
 		{
-			KdTree::Leaf * leaf = static_cast<KdTree::Leaf *>(node);
+			KdTree::Leaf * leaf = KDLEAFPTR_CAST(node);
 			return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KI*leaf->mKdRenderables.size();
 		}
 		else
 		{
-			KdTree::Branch * branch = static_cast<KdTree::Branch *>(node);
+			KdTree::Branch * branch = KDBRANCHPTR_CAST(node);
 			return (PlaneEvent::surfaceArea(node->mAABB)/vs)*PlaneEvent::KT + calcCost(branch->mLeft, vs) + calcCost(branch->mRight, vs);
 		}
