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);
 		}
