Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1182)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1183)
@@ -211,15 +211,19 @@
 			//virtual void cbInsert(KdTree * caller, KdRenderable * rend) = 0;
 
-			WireBoundingBox * getWireBoundingBox()
+			WireBoundingBox * getWireBoundingBox(bool node = true)
 			{
 				if (mWBB == 0)
 					mWBB = new WireBoundingBox();
 
-				mWBB->setupBoundingBox(mAABB);
+				if (node)
+					mWBB->setupBoundingBox(mAABB);
+				else
+					mWBB->setupBoundingBox(mWorldAABB);
 				
 #ifdef KDTREE_DEBUG
+				SceneManager * sceneManager = Root::getSingleton()._getCurrentSceneManager();
 				int level = -1;
 				bool boxes = false;
-				if (Root::getSingleton()._getCurrentSceneManager()->getOption("HighlightLevel",&level))
+				if (sceneManager->getOption("HighlightLevel",&level))
 				{
 					if (mLevel == level)
@@ -232,5 +236,5 @@
 					{
 						mWBB->setMaterial("BaseWhiteNoLighting");
-						if (Root::getSingleton()._getCurrentSceneManager()->getOption("ShowAllBoxes", &boxes))
+						if (sceneManager->getOption("ShowAllBoxes", &boxes))
 						{
 							if (boxes)
@@ -279,6 +283,5 @@
 			/** Updates bound of the real aabb of kdtree
 			*/
-			virtual void _updateBounds() = 0;
-
+			virtual void _updateBounds(bool recurse = true) = 0;
 
 			Branch * mParent;
@@ -325,5 +328,5 @@
 
 			// branches do not posses geometry => just merge child aabbs
-			virtual void _updateBounds()
+			virtual void _updateBounds(bool recurse = true)
 			{
 				// reset box
@@ -336,6 +339,6 @@
 
 				// update parent recursively
-				if (mParent)
-					mParent->_updateBounds();
+				if (recurse && mParent)
+					mParent->_updateBounds(recurse);
 			}
 			
@@ -365,5 +368,5 @@
 
 			// update the world aabb based on the contained geometry
-			virtual void _updateBounds();
+			virtual void _updateBounds(bool recurse = true);
 
 			virtual void remove(KdRenderable * rend)
@@ -464,4 +467,10 @@
 		void dump(void);
 		Real calcCost(void);
+
+		/** Switches between displaying the bounding box of the node and
+		the box of the contained scene nodes
+		*/
+		inline void setShowNodeAABB(bool show = true) { mShowNodeAABB = show; };
+		inline bool getShowNodeAABB(void) { return mShowNodeAABB; };
 
 		NodePtr getRoot(void) const { return mKdRoot; };
@@ -523,4 +532,8 @@
 		Stats mStats;
 
+		// show node or object aabb
+		bool mShowNodeAABB;
+
+
 		// DEBUG
 		void KdTree::dump(KdTree::Node * node);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1182)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1183)
@@ -59,4 +59,8 @@
 
 mHierarchyInterface = new KdTreeHierarchyInterface(this, mDestRenderSystem);
+
+// test
+//String chc = "CHC";
+//setOption("RenderMethod", &chc);
 }
 
@@ -240,4 +244,79 @@
 		return true;
 	}
+	else if (strKey == "ShowNodeAABB")
+	{
+		bool sn = *static_cast<const bool *>(pValue);
+		if (mKdTree)
+			mKdTree->setShowNodeAABB(sn);
+		return true;
+	}
+	// options for CHC
+	if (strKey == "UseDepthPass")
+	{
+		mUseDepthPass = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "PrepareVisualization")
+	{
+		mShowVisualization = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "RenderNodesForViz")
+	{
+		mRenderNodesForViz = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "RenderNodesContentForViz")
+	{
+		mRenderNodesContentForViz = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "SkyBoxEnabled")
+	{
+		mSkyBoxEnabled = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "SkyPlaneEnabled")
+	{
+		mSkyPlaneEnabled = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "SkyDomeEnabled")
+	{
+		mSkyDomeEnabled = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "VisualizeCulledNodes")
+	{
+		mVisualizeCulledNodes = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "DelayRenderTransparents")
+	{
+		mDelayRenderTransparents = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+
+	if (strKey == "DepthWrite")
+	{
+		mEnableDepthWrite = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "UseItemBuffer")
+	{
+		mUseItemBuffer = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "ExecuteVertexProgramForAllPasses")
+	{ 
+		mExecuteVertexProgramForAllPasses  = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+	if (strKey == "RenderTransparentsForItemBuffer")
+	{ 
+		mRenderTransparentsForItemBuffer  = (*static_cast<const bool *>(pValue));
+		return true;
+	}
+
 
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
@@ -270,5 +349,8 @@
 	else if (strKey == "ShowAllBoxes")
 	{
-		*static_cast<bool *>(pDestValue) = mShowAllBoxes;
+		if (mRenderMethod == KdTree::KDRM_INTERNAL)
+			*static_cast<bool *>(pDestValue) = mShowAllBoxes;
+		else
+			*static_cast<bool *>(pDestValue) = mVisualizeCulledNodes;
 		return true;
 	}
@@ -308,4 +390,17 @@
 			return false;
 		}
+		return true;
+	}
+	else if (strKey == "ShowKdTree")
+	{
+		*static_cast<bool *>(pDestValue) = mShowBoxes;
+		return true;
+	}
+	else if (strKey == "ShowNodeAABB")
+	{
+		if (mKdTree)
+			*static_cast<bool *>(pDestValue) = mKdTree->getShowNodeAABB();
+		else
+			*static_cast<bool *>(pDestValue) = false;
 		return true;
 	}
@@ -331,4 +426,5 @@
 	refKeys.push_back("RenderMethod");
 	refKeys.push_back("ShowKdTree");
+	refKeys.push_back("ShowNodeAABB");
 	refKeys.push_back("TreeBox");
 #ifdef KDTREE_DEBUG
@@ -639,5 +735,8 @@
 	while (it != end)
 	{
-		(*it)->queueObjects(cam, getRenderQueue(), onlyShadowCasters);
+		if (!(*it)->isQueued(mHierarchyInterface->GetFrameId(), cam))
+		{
+			(*it)->queueObjects(cam, getRenderQueue(), onlyShadowCasters);
+		}
 		it++;
 	}
@@ -841,5 +940,5 @@
 	}
 	// add bounding boxes of rendered objects
-	if (0)
+	//if (0)
 		//for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
 		//{
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneNode.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneNode.cpp	(revision 1182)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneNode.cpp	(revision 1183)
@@ -12,4 +12,5 @@
 
 #include <OgreStringConverter.h>
+#include <OgreLogManager.h>
 
 namespace Ogre
@@ -140,7 +141,36 @@
 	}
 
+	// recalculate the world aabb
 	AxisAlignedBox KdTreeSceneNode::getBoundingBox() const
 	{
+#if 0
+		AxisAlignedBox box;
+
+		// Update bounds from own attached objects
+		ObjectMap::const_iterator it = mObjectsByName.begin();
+		ObjectMap::const_iterator end = mObjectsByName.end();
+		for ( ; it != end ; ++it)
+		{
+			// Merge world bounds of each object
+			box.merge(it->second->getWorldBoundingBox(true));
+		}
+
+		if (box.getMinimum() != mWorldAABB.getMinimum() ||box.getMaximum() != mWorldAABB.getMaximum())
+		{
+			try
+			{
+				Log * log = LogManager::getSingleton().getLog("KdTreeBuild.log");
+				log->logMessage("mWorldAABB was not up to date");
+			}
+			catch (Exception)
+			{
+				// F.U.
+			}
+		}
+
+		return box;
+#else
 		return mWorldAABB;
+#endif
 	}
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1182)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1183)
@@ -329,5 +329,10 @@
 	//----------------------------------------------------------------------------
 
-	KdTree::KdTree(int maxdepth): mMaxDepth(maxdepth), mKdRoot(0), mBuildMethod(KDBM_RECURSIVE), mBuildLog(0)
+	KdTree::KdTree(int maxdepth): 
+	mMaxDepth(maxdepth), 
+	mKdRoot(0), 
+	mBuildMethod(KDBM_RECURSIVE), 
+	mBuildLog(0), 
+	mShowNodeAABB(true)
 	{
 #ifdef KDTREE_DEBUG
@@ -340,15 +345,4 @@
 			mp->setDiffuse(cv);
 		}
-		//try
-		//{
-		//	ColourValue cv(0.0, 1.0, 0.0);
-		//	MaterialPtr mp = MaterialManager::getSingleton().create("aabbHiLite","General");
-		//	mp->setSelfIllumination(cv);
-		//	mp->setDiffuse(cv);
-		//}
-		//catch (Ogre::Exception&)
-		//{
-		//	// SO FUCKING DON'T CARE !!!
-		//}
 #endif
 		try
@@ -871,4 +865,6 @@
 			++ mStats.mNumNodes;
 			++ mStats.mNumLeaves;
+			// update bounding box
+			leaf->_updateBounds(false);
 			return leaf;
 		}
@@ -957,4 +953,8 @@
 			// update stats
 			++ mStats.mNumNodes;
+
+			// update bounding box
+			branch->_updateBounds(false);
+
 
 			//assert(branch->mRight || branch->mLeft);
@@ -1261,4 +1261,8 @@
 			}
 
+			// update bounding boxes when geometry (leaf) was added
+			if (newNode->isLeaf())
+				newNode->_updateBounds();
+
 			//cleanup
 			OGRE_DELETE(sc.events);
@@ -1336,5 +1340,5 @@
 			WireBoundingBox * wbb = 0;
 			if (showBoxes)
-				wbb = node->getWireBoundingBox();
+				wbb = node->getWireBoundingBox(mShowNodeAABB);
 #endif
 
@@ -1357,5 +1361,5 @@
 #else
 				if (showBoxes)
-					queue->addRenderable(leaf->getWireBoundingBox());
+					queue->addRenderable(leaf->getWireBoundingBox(mShowNodeAABB));
 #endif
 			}
@@ -1368,5 +1372,5 @@
 #else
 				if (showBoxes)
-					queue->addRenderable(branch->getWireBoundingBox());
+					queue->addRenderable(branch->getWireBoundingBox(mShowNodeAABB));
 #endif
 
@@ -1469,5 +1473,5 @@
 
 	// update the world aabb based on the contained geometry
-	void KdTree::Leaf::_updateBounds()
+	void KdTree::Leaf::_updateBounds(bool recurse)
 	{
 		// reset box
@@ -1479,4 +1483,5 @@
 		while (it != end)
 		{
+			//(*it)->_updateBounds();
 			mWorldAABB.merge((*it)->getBoundingBox());
 			it++;
@@ -1484,6 +1489,6 @@
 
 		// update parent recursively
-		if (mParent)
-			mParent->_updateBounds();
+		if (recurse && mParent)
+			mParent->_updateBounds(recurse);
 	}
 } // namespace Ogre
