Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1190)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTree.h	(revision 1192)
@@ -192,5 +192,6 @@
 		{
 		public:
-			Node(int level, AxisAlignedBox& aabb, Branch * parent):
+			Node(KdTree * owner, int level, AxisAlignedBox& aabb, Branch * parent):
+			mOwner(owner),
 			mLevel(level),
 			mAABB(aabb),
@@ -208,46 +209,32 @@
 			virtual bool hasGeometry() const = 0;
 
+			// Gets this node's parent (NULL if this is the root).
+			Node *getParent(void) const { return mParent; };
+			// Gets the nodes left & right child nodes, or NULL if not present
+			// or node is leaf
+			virtual Node *getLeftChild(void) const = 0;
+			virtual Node *getRightChild(void) const = 0;
+			
+			// returns the level the node is on
+			int getLevel(void) const { return mLevel; };
+
 			virtual void queueVisibleObjects(unsigned long currentFrame, 
 				Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) = 0;
 			
-			// consider using typesafe callback functions
-			//virtual void cbInsert(KdTree * caller, KdRenderable * rend) = 0;
-
-			WireBoundingBox * getWireBoundingBox(bool node = true)
+			WireBoundingBox * getWireBoundingBox()
 			{
 				if (mWBB == 0)
 					mWBB = new WireBoundingBox();
 
-				if (node)
+				if (mOwner->getShowNodes())
 					mWBB->setupBoundingBox(mAABB);
 				else
 					mWBB->setupBoundingBox(mWorldAABB);
+
+				if (mOwner->getHiLiteLevel() == mLevel)
+					mWBB->setMaterial("KdTree/BoxHiLite");
+				else
+					mWBB->setMaterial("BaseWhiteNoLighting");
 				
-#ifdef KDTREE_DEBUG
-				SceneManager * sceneManager = Root::getSingleton()._getCurrentSceneManager();
-				int level = -1;
-				bool boxes = false;
-				if (sceneManager->getOption("HighlightLevel",&level))
-				{
-					if (mLevel == level)
-					{
-						mWBB->setMaterial("KdTree/BoxHiLite");
-						return mWBB;
-					}
-					else
-					{
-						mWBB->setMaterial("BaseWhiteNoLighting");
-						if (sceneManager->getOption("ShowAllBoxes", &boxes))
-						{
-							if (boxes)
-								return mWBB;
-							else
-								return 0;
-						}
-					}
-				}
-#else
-				mWBB->setMaterial("BaseWhiteNoLighting");
-#endif // KDTREE_DEBUG
 				return mWBB;
 
@@ -277,7 +264,4 @@
 			*/
 			void setLastRendered(unsigned int frameid) { mLastRendered = frameid; };
-			/** Gets this node's parent (NULL if this is the root).
-			*/	
-			KdTree::Branch *getParent(void) { return mParent; };
 			/** Returns real extent of the kdtree, i.e., the merged extent of the bounding boxes. 
 			*/
@@ -287,6 +271,4 @@
 			virtual void _updateBounds(bool recurse = true) = 0;
 
-			Branch * mParent;
-			int mLevel;
 			AxisAlignedBox mAABB;
 
@@ -295,4 +277,8 @@
 			AxisAlignedBox mWorldAABB;
 		protected:
+			KdTree * mOwner;
+			Branch * mParent;
+			int mLevel;
+
 			WireBoundingBox * mWBB;
 			
@@ -305,10 +291,11 @@
 		{
 		public:
-			Branch(int level, AxisAlignedBox& aabb, Branch * parent, Plane * splitplane, PlaneEvent::Side side):
-				Node(level, aabb, parent), 
-				mSplitPlane(splitplane), 
-				mLeft(0), 
-				mRight(0),
-				mPlaneSide(side)
+			Branch(KdTree * owner, int level, AxisAlignedBox& aabb, Branch * parent, 
+				Plane * splitplane, PlaneEvent::Side side):
+			Node(owner, level, aabb, parent), 
+			mSplitPlane(splitplane), 
+			mLeft(0), 
+			mRight(0),
+			mPlaneSide(side)
 			{ };
 
@@ -329,13 +316,14 @@
 			virtual bool hasGeometry() const { return false; };
 
+			// a branch should have at least one child
+			virtual Node * getLeftChild() const { return mLeft; };
+			virtual Node * getRightChild() const { return mRight; };
+
 			virtual void queueVisibleObjects(unsigned long currentFrame, 
 				Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes)
 			{
 				if (showBoxes)
-				{
-					WireBoundingBox * wbb = getWireBoundingBox();
-					if (wbb)
-						queue->addRenderable(wbb);
-				}
+					if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes())
+						queue->addRenderable(getWireBoundingBox());
 			}
 
@@ -365,6 +353,6 @@
 		{
 		public:
-			Leaf(int level, AxisAlignedBox& aabb, Branch * parent):
-			  Node(level, aabb, parent) 
+			Leaf(KdTree * owner, int level, AxisAlignedBox& aabb, Branch * parent):
+			Node(owner, level, aabb, parent) 
 			{};
 
@@ -379,4 +367,8 @@
 			// a leaf has geometry when it has renderables
 			virtual bool hasGeometry() const { return !mKdRenderables.empty(); };
+
+			// a leaf never has children 
+			virtual Node * getLeftChild() const { return 0; };
+			virtual Node * getRightChild() const { return 0; };
 
 			virtual void queueVisibleObjects(unsigned long currentFrame, 
@@ -478,6 +470,9 @@
 			KDBM_PRIORITYQUEUE
 		};
+
+		const static int HILITE_OFF  = -1;
 		
-		KdTree(int maxdepth);
+		KdTree(int maxdepth, BuildMethod bm);
+		KdTree(int maxdepth, BuildMethod bm, int hilite, bool allboxes, bool shownodes);
 		virtual ~KdTree();
 
@@ -486,9 +481,16 @@
 		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; };
+		// sets the level to highlight or turns it off (when hilite < 0)
+		inline void setHiLiteLevel(int hilite) { mHiLiteLevel = hilite; };
+		inline int  getHiLiteLevel(void) { return mHiLiteLevel; };
+
+		// toggles displaying the kdtree boxes
+		inline void setShowAllBoxes(bool show) { mShowAllBoxes = show; };
+		inline bool getShowAllBoxes(void) { return mShowAllBoxes; };
+
+		// toggles between displaying the bounding box of the node and
+		// the box of the contained scene nodes
+		inline void setShowNodes(bool show = true) { mShowNodes = show; };
+		inline bool getShowNodes(void) { return mShowNodes; };
 
 		NodePtr getRoot(void) const { return mKdRoot; };
@@ -510,4 +512,6 @@
 		void setBuildMethod(BuildMethod bm) { mBuildMethod = bm; }
 	protected:
+		// init materials, logs and stuff
+		void init();
 		// recursive insert funciton
 		void recInsert(KdTree::Node * node, KdRenderable * rend);
@@ -549,6 +553,11 @@
 		Stats mStats;
 
-		// show node or object aabb
-		bool mShowNodeAABB;
+		/** Visualization flags **/
+		// show/highlight selected level in kdtree
+		int mHiLiteLevel;
+		// show whole kd-tree
+		bool mShowAllBoxes;
+		// show node or object boxes
+		bool mShowNodes;
 
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1187)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1192)
@@ -243,4 +243,10 @@
 	// if bounding boxes of kdtree nodes are shown
 	bool mShowBoxes;
+	// bounding boxes of kd nodes will be highlighted on this level of the kd tree
+	int mHiLiteLevel;
+	// if all bounding boxes shall be displayed, not only the highlighted level
+	bool mShowAllBoxes;
+	// visualize kdtree nodes or bounding boxes of objects in nodes
+	bool mShowNodes;
 
 	// the method/algorithm used when rendering the scene
@@ -249,10 +255,4 @@
 	// the method of building the tree
 	KdTree::BuildMethod mBuildMethod;
-#ifdef KDTREE_DEBUG
-	// bounding boxes of kd nodes will be highlighted on this level of the kd tree
-	int mHighlighLevel;
-	// if all bounding boxes shall be displayed, not only the highlighted level
-	bool mShowAllBoxes;
-#endif
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1190)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1192)
@@ -29,8 +29,6 @@
 mMaxDepth(KDTREE_MAX_DEPTH),
 mShowBoxes(false),
-#ifdef KDTREE_DEBUG
-mHighlighLevel(0),
+mHiLiteLevel(0),
 mShowAllBoxes(false),
-#endif
 mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
 mRenderMethod(KdTree::KDRM_INTERNAL),
@@ -102,8 +100,6 @@
 		{
 			mMaxDepth = maxdepth;
-#ifdef KDTREE_DEBUG
-			if (mHighlighLevel > mMaxDepth)
-				mHighlighLevel = mMaxDepth;
-#endif
+			if (mHiLiteLevel > mMaxDepth)
+				mHiLiteLevel = mMaxDepth;
 			return true;
 		}
@@ -139,30 +135,8 @@
 	{
 		OGRE_DELETE(mKdTree);
-		mKdTree = new KdTree(mMaxDepth);
-		mKdTree->setBuildMethod(mBuildMethod);
+		mKdTree = new KdTree(mMaxDepth, mBuildMethod, mHiLiteLevel, mShowAllBoxes, mShowNodes);
 		mKdTree->build(static_cast<KdTreeSceneNode *>(mSceneRoot));
 		return true;
 	}
-#ifdef KDTREE_DEBUG
-	else if (strKey == "HighlightLevel")
-	{
-		int hl = *static_cast<const int *>(pValue);
-		if (hl >= 0 && hl <= mMaxDepth)
-		{
-			mHighlighLevel = hl;
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-	else if (strKey == "ShowAllBoxes")
-	{
-		bool sa = *static_cast<const bool *>(pValue);
-		mShowAllBoxes = sa;
-		return true;
-	}
-#endif
 	else if (strKey == "BuildMethod")
 	{
@@ -236,4 +210,8 @@
 				mRenderMethod = KdTree::KDRM_INTERNAL;
 		}
+		else
+		{
+			mRenderMethod = KdTree::KDRM_INTERNAL;
+		}
 		return success;
 	}
@@ -244,9 +222,33 @@
 		return true;
 	}
-	else if (strKey == "ShowNodeAABB")
+	else if (strKey == "HiLiteLevel")
+	{
+		int hl = *static_cast<const int *>(pValue);
+		if (hl >= 0 && hl <= mMaxDepth)
+		{
+			mHiLiteLevel = hl;
+			if (mKdTree)
+				mKdTree->setHiLiteLevel(mHiLiteLevel);
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+	else if (strKey == "ShowAllBoxes")
+	{
+		bool sa = *static_cast<const bool *>(pValue);
+		mShowAllBoxes = sa;
+		if (mKdTree)
+			mKdTree->setShowAllBoxes(mShowAllBoxes);
+		return true;
+	}
+	else if (strKey == "ShowNodes")
 	{
 		bool sn = *static_cast<const bool *>(pValue);
+		mShowNodes = sn;
 		if (mKdTree)
-			mKdTree->setShowNodeAABB(sn);
+			mKdTree->setShowNodes(mShowNodes);
 		return true;
 	}
@@ -341,74 +343,59 @@
 		return true;
 	}
-#ifdef KDTREE_DEBUG
-	else if (strKey == "HighlightLevel")
-	{
-		*static_cast<int *>(pDestValue) = mHighlighLevel;
+	else if (strKey == "BuildMethod")
+	{
+		if (mBuildMethod == KdTree::KDBM_PRIORITYQUEUE)
+		{
+			*static_cast<String *>(pDestValue) = "PriorityQueue";
+		}
+		else if (mBuildMethod == KdTree::KDBM_RECURSIVE)
+		{
+			*static_cast<String *>(pDestValue) = "Recursive";
+		}
+		return true;
+	}
+	else if (strKey == "RenderMethod")
+	{
+		if (mRenderMethod == KdTree::KDRM_INTERNAL)
+		{
+			*static_cast<String *>(pDestValue) = "INT";
+		}
+		else if (mRenderMethod == KdTree::KDRM_GTP_VFC)
+		{
+				*static_cast<String *>(pDestValue) = "VFC";
+		}
+		else if (mRenderMethod == KdTree::KDRM_GTP_SWC)
+		{
+				*static_cast<String *>(pDestValue) = "SWC";
+		}
+		else if (mRenderMethod == KdTree::KDRM_GTP_CHC)
+		{
+				*static_cast<String *>(pDestValue) = "CHC";
+		}
+		else
+		{
+			return false;
+		}
+		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")
 	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-			*static_cast<bool *>(pDestValue) = mShowAllBoxes;
-		else
-			*static_cast<bool *>(pDestValue) = mVisualizeCulledNodes;
-		return true;
-	}
-#endif
-	else if (strKey == "BuildMethod")
-	{
-		if (mBuildMethod == KdTree::KDBM_PRIORITYQUEUE)
-		{
-			*static_cast<String *>(pDestValue) = "PriorityQueue";
-		}
-		else if (mBuildMethod == KdTree::KDBM_RECURSIVE)
-		{
-			*static_cast<String *>(pDestValue) = "Recursive";
-		}
-		return true;
-	}
-	else if (strKey == "RenderMethod")
-	{
-		if (mRenderMethod == KdTree::KDRM_INTERNAL)
-		{
-			*static_cast<String *>(pDestValue) = "INT";
-		}
-		else if (mRenderMethod == KdTree::KDRM_GTP_VFC)
-		{
-				*static_cast<String *>(pDestValue) = "VFC";
-		}
-		else if (mRenderMethod == KdTree::KDRM_GTP_SWC)
-		{
-				*static_cast<String *>(pDestValue) = "SWC";
-		}
-		else if (mRenderMethod == KdTree::KDRM_GTP_CHC)
-		{
-				*static_cast<String *>(pDestValue) = "CHC";
-		}
-		else
-		{
-			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;
-	}
-	else if (strKey == "TreeBox")
-	{
-		if (mKdTree)
-			*static_cast<AxisAlignedBox *>(pDestValue) = mKdTree->getBox();
-		else
-			*static_cast<AxisAlignedBox *>(pDestValue) = AxisAlignedBox();
+		*static_cast<bool *>(pDestValue) = mShowAllBoxes;
+		return true;
+	}
+	else if (strKey == "ShowNodes")
+	{
+		*static_cast<bool *>(pDestValue) = mShowNodes;
+		return true;
 	}
 
@@ -426,10 +413,7 @@
 	refKeys.push_back("RenderMethod");
 	refKeys.push_back("ShowKdTree");
-	refKeys.push_back("ShowNodeAABB");
-	refKeys.push_back("TreeBox");
-#ifdef KDTREE_DEBUG
-	refKeys.push_back("HighlightLevel");
+	refKeys.push_back("ShowNodes");
+	refKeys.push_back("HiLiteLevel");
 	refKeys.push_back("ShowAllBoxes");
-#endif
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface)
 		.getOptionKeys(refKeys);
@@ -515,6 +499,5 @@
 	if (!mKdTree)
 	{
-		mKdTree = new KdTree(mMaxDepth);
-		mKdTree->setBuildMethod(mBuildMethod);
+		mKdTree = new KdTree(mMaxDepth, mBuildMethod);
 		mKdTree->build(static_cast<KdTreeSceneNode *>(mSceneRoot));
 	}
@@ -724,5 +707,5 @@
 
 		getRenderQueue()->clear(); // finally clear render queue
-		if (0) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
+		if (1) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
 
 		if (0) WriteLog(); // write out stats
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1190)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp	(revision 1192)
@@ -304,11 +304,36 @@
 	//----------------------------------------------------------------------------
 
-	KdTree::KdTree(int maxdepth): 
+	KdTree::KdTree(int maxdepth, BuildMethod bm): 
 	mMaxDepth(maxdepth), 
+	mBuildMethod(bm), 
+	mHiLiteLevel(HILITE_OFF),
+	mShowAllBoxes(false),
+	mShowNodes(true),
 	mKdRoot(0), 
-	mBuildMethod(KDBM_RECURSIVE), 
-	mBuildLog(0), 
-	mShowNodeAABB(true)
-	{
+	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()
+	{
+		// init visualization materials
 		MaterialPtr mphi = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite");
 		if (mphi.isNull())
@@ -318,5 +343,4 @@
 			mphi->setAmbient(green);
 			mphi->setDiffuse(green);
-			mphi->setSelfIllumination(ColourValue::Black);
 			mphi->setLightingEnabled(true);
 			mphi->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
@@ -330,9 +354,9 @@
 			mpviz->setAmbient(yellow);
 			mpviz->setDiffuse(yellow);
-			mpviz->setSelfIllumination(ColourValue::Black);
 			mpviz->setLightingEnabled(true);
 			mpviz->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
 		}
 
+		// retrieve or create build log
 		try
 		{
@@ -343,9 +367,4 @@
 			mBuildLog = LogManager::getSingleton().createLog(KDTREE_LOGNAME);
 		}
-	}
-
-	KdTree::~KdTree()
-	{
-		delete mKdRoot;
 	}
 
@@ -399,5 +418,5 @@
 			else
 			{
-				KdTree::Branch * parent = node->mParent;
+				KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent());
 				if (node == parent->mLeft)
 				{
@@ -571,5 +590,5 @@
 		else
 		{
-			KdTree::Branch * parent = KDBRANCHPTR_CAST(node->mParent);
+			KdTree::Branch * parent = KDBRANCHPTR_CAST(node->getParent());
 
 			if (node == parent->mLeft)
@@ -738,5 +757,5 @@
 		if (parent)
 		{
-			level = parent->mLevel + 1;
+			level = parent->getLevel() + 1;
 		}
 
@@ -795,5 +814,5 @@
 		{
 			// Terminating condition reached, create leaf and add renderables to list
-			KdTree::Leaf * leaf = new KdTree::Leaf(level, aabb, parent);
+			KdTree::Leaf * leaf = new KdTree::Leaf(this, level, aabb, parent);
 			KdRenderable *rend;
 			it = begin;
@@ -879,5 +898,6 @@
 
 			// create a new branch node and continue recursion
-			KdTree::Branch * branch = new KdTree::Branch(level, aabb, parent, best.event.getSplitPlane(), best.side);
+			KdTree::Branch * branch = new KdTree::Branch(this, level, aabb, parent, 
+				best.event.getSplitPlane(), best.side);
 
 			// now create the child nodes and continue recursion
@@ -931,5 +951,5 @@
 			if (sc.parent)
 			{
-				level = sc.parent->mLevel + 1;
+				level = sc.parent->getLevel() + 1;
 			}
 
@@ -941,5 +961,5 @@
 			{
 				// Terminating condition reached, create leaf and add renderables to list
-				KdTree::Leaf * leaf = new KdTree::Leaf(level, sc.aabb, sc.parent);
+				KdTree::Leaf * leaf = new KdTree::Leaf(this, level, sc.aabb, sc.parent);
 				KdRenderable *rend;
 				PlaneEventList::iterator begin = sc.events->begin();
@@ -1032,6 +1052,6 @@
 
 				// create a new branch node
-				KdTree::Branch * branch = 
-					new KdTree::Branch(level, sc.aabb, sc.parent, sc.best->event.getSplitPlane(), sc.best->side);
+				KdTree::Branch * branch = new KdTree::Branch(this, level, sc.aabb, sc.parent, 
+					sc.best->event.getSplitPlane(), sc.best->side);
 
 				globalTreeCost -= sc.decrease;
@@ -1174,8 +1194,16 @@
 		if (cam->isVisible(node->mAABB))
 		{
+#if 0
+			node->queueVisibleObjects(currentFrame, cam, queue, onlyShadowCasters, showBoxes);
+
+			if (node->getLeftChild())
+				recQueueVisibleObjects(node->getLeftChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes);
+			if (node->getRightChild())
+				recQueueVisibleObjects(node->getRightChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes);
+#else
 #ifdef KDTREE_DEBUG
 			WireBoundingBox * wbb = 0;
 			if (showBoxes)
-				wbb = node->getWireBoundingBox(mShowNodeAABB);
+				wbb = node->getWireBoundingBox();
 #endif
 
@@ -1198,5 +1226,5 @@
 #else
 				if (showBoxes)
-					queue->addRenderable(leaf->getWireBoundingBox(mShowNodeAABB));
+					queue->addRenderable(leaf->getWireBoundingBox());
 #endif
 			}
@@ -1209,5 +1237,5 @@
 #else
 				if (showBoxes)
-					queue->addRenderable(branch->getWireBoundingBox(mShowNodeAABB));
+					queue->addRenderable(branch->getWireBoundingBox());
 #endif
 
@@ -1217,4 +1245,5 @@
 					recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes);
 			}
+#endif
 		}
 	}
@@ -1241,5 +1270,5 @@
 		
 		pad = "";
-		for (p = 0; p < node->mLevel; p++)
+		for (p = 0; p < node->getLevel(); p++)
 		{
 			pad += " ";
@@ -1255,5 +1284,5 @@
 				scenenode = dynamic_cast<KdTreeSceneNode *>(*it);
 				log->logMessage(pad + "# Leaf   level " + 
-					StringConverter::toString(node->mLevel) + 
+					StringConverter::toString(node->getLevel()) + 
 					" SceneNode " + scenenode->getName());
 				log->logMessage(pad + "## Objects: " + scenenode->dumpToString());
@@ -1267,5 +1296,5 @@
 			{
 				log->logMessage(pad + "# Branch level " + 
-					StringConverter::toString(node->mLevel) + " Left Child");
+					StringConverter::toString(node->getLevel()) + " Left Child");
 				dump(branch->mLeft);
 			}
@@ -1273,5 +1302,5 @@
 			{
 				log->logMessage(pad + "# Branch level " + 
-					StringConverter::toString(node->mLevel) + " Right Child");
+					StringConverter::toString(node->getLevel()) + " Right Child");
 				dump(branch->mRight);
 			}
@@ -1342,9 +1371,6 @@
 
 		if (showBoxes)
-		{
-			WireBoundingBox * wbb = getWireBoundingBox();
-			if (wbb)
-				queue->addRenderable(wbb);
-		}
+			if (mLevel == mOwner->getHiLiteLevel() || mOwner->getShowAllBoxes())
+				queue->addRenderable(getWireBoundingBox());
 	}
 
