Index: /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 417)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 418)
@@ -231,7 +231,8 @@
 
 		// get results, create a node/entity on the position
-		mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			mouseRay.getOrigin(), Vector3(val, 0, 0), 
-			msObjectCaptions[mCurrentObjectType]);
+		mCurrentObject = 
+			mTerrainContentGenerator->GenerateSceneObject(mouseRay.getOrigin(), 
+														  Vector3(val, 0, 0), 
+														  msObjectCaptions[mCurrentObjectType]);
 		
 		mLMouseDown = true; 
@@ -1523,4 +1524,5 @@
 	top += vert_space;
 	initHelpOverlayElement("SceneObjects", top); top += vert_space;
+	initHelpOverlayElement("PlaceObjects", top); top += vert_space;
 	initHelpOverlayElement("GenerateObjects", top); top += vert_space;
 	initHelpOverlayElement("RemoveObjects", top); top += vert_space;
Index: /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 417)
+++ /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 418)
@@ -378,5 +378,5 @@
 									   (CEGUI::utf8*)"MouseArrow");
 
-	 CEGUI::MouseCursor::getSingleton().show();
+	 CEGUI::MouseCursor::getSingleton().hide();
 }
 //-----------------------------------------------------------------------
Index: /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 417)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 418)
@@ -176,4 +176,9 @@
         mUseBufferedInputMouse = !mUseBufferedInputMouse;
 		mInputDevice->setBufferedInput(true, mUseBufferedInputMouse);
+
+		if (!mUseBufferedInputMouse)
+			CEGUI::MouseCursor::getSingleton().hide();
+		else
+			CEGUI::MouseCursor::getSingleton().show();
 	}
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 416)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 418)
@@ -68,5 +68,5 @@
 ViewCells {
 	#hierarchy kdTree
-	hierarchy vspTree
+	#hierarchy vspTree
 	hierarchy bspTree
 	# hierarchy sceneDependent
@@ -133,5 +133,5 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 12
+	splitPlaneStrategy 1024
 	
 	maxPolyCandidates 50
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 414)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 418)
@@ -25,12 +25,14 @@
 #include "Ray.h"
 
-
-#define DEBUG_DIR_SPLIT 0
-
-
-
 // Static variables
-int
-VspKdTreeLeaf::mailID = 0;
+int VspKdTreeLeaf::mailID = 0;
+int VspKdTree::sTermMaxDepth = 10;
+float VspKdTree::sTermMinSize = 0.1;
+int VspKdTree::sTermMinPvs = 10;
+int VspKdTree::sTermMinRays = 20;
+float VspKdTree::sTermMaxCostRatio = 0.1;
+float VspKdTree::sTermMaxRayContribution = 0.1;
+
+
 
 inline void AddObject2Pvs(Intersectable *object,
@@ -68,20 +70,77 @@
 }
 
+/**************************************************************/
+ *                VspKdTreeInterior implementation            *
+/**************************************************************/
+
+VspKdTreeInterior::VspKdTreeInterior(VspKdTreeInterior *p):
+VspKdTreeNode(p), mBack(NULL), mFront(NULL), mAccesses(0), mLastAccessTime(-1)
+{
+}
+
+int VspKdTreeInterior::GetAccessTime()
+{
+	return lastAccessTime;
+}
+
+void VspKdTreeInterior::SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f) 
+{
+	mBack = b;
+	mFront = f;
+	b->mParent = f->mParent = this;
+}
+
+void VspKdTreeInterior::ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild)
+{
+	if (mBack == oldChild)
+		mBack = newChild;
+	else
+		mFront = newChild;
+}
+
+int VspKdTreeInterior::Type() const  
+{ 
+	return VspKdInterior; 
+}
+  
+VspKdTreeInterior::~VspKdTreeInterior()
+{
+	DEL_PTR(mBack);
+	DEL_PTR(mFront);
+}
+  
+void VspKdTreeInterior::Print(ostream &s) const 
+{
+	if (axis == 0)
+		s << "x ";
+	else
+		if (axis == 1)
+			s << "y ";
+		else
+			s << "z ";
+	s << position << " ";
+
+	mBack->Print(s);
+	mFront->Print(s);
+}
+	
+int VspKdTreeInterior::ComputeRayIntersection(const RayInfo &rayData, float &t) 
+{
+	return rayData.ComputeRayIntersection(axis, position, t);
+}
+
 
 // Constructor
 VspKdTree::VspKdTree()
 {
-	environment->GetIntValue("VspKdTree.maxDepth", termMaxDepth);
-	environment->GetIntValue("VspKdTree.minPvs", termMinPvs);
-	environment->GetIntValue("VspKdTree.minRays", termMinRays);
-	environment->GetFloatValue("VspKdTree.maxRayContribution", termMaxRayContribution);
-	environment->GetFloatValue("VspKdTree.maxCostRatio", termMaxCostRatio);
-
-	environment->GetFloatValue("VspKdTree.minSize", termMinSize);
+	environment->GetIntValue("VspKdTree.maxDepth", sTermMaxDepth);
+	environment->GetIntValue("VspKdTree.minPvs", sTermMinPvs);
+	environment->GetIntValue("VspKdTree.minRays", sTermMinRays);
+	environment->GetFloatValue("VspKdTree.maxRayContribution", sTermMaxRayContribution);
+	environment->GetFloatValue("VspKdTree.maxCostRatio", sTermMaxCostRatio);
+
+	environment->GetFloatValue("VspKdTree.minSize", sTermMinSize);
 	termMinSize = sqr(termMinSize);
-	
-	environment->GetFloatValue("VspKdTree.refDirBoxMaxSize", refDirBoxMaxSize);
-	refDirBoxMaxSize = sqr(refDirBoxMaxSize);
-  
+	  
 	environment->GetFloatValue("VspKdTree.epsilon", epsilon);
 	environment->GetFloatValue("VspKdTree.ct_div_ci", ct_div_ci);
@@ -92,6 +151,4 @@
   
 	float refDirAngle;
-	environment->GetFloatValue("VspKdTree.refDirAngle", refDirAngle);
-
 	environment->GetIntValue("VspKdTree.accessTimeThreshold", accessTimeThreshold);
 	//= 1000;
@@ -119,5 +176,5 @@
 	environment->GetBoolValue("VspKdTree.randomize", randomize);
 
-	root = NULL;
+	mRoot = NULL;
 
 	splitCandidates = new vector<SortableEntry>;
@@ -127,13 +184,9 @@
 VspKdTree::~VspKdTree()
 {
-	if (root)
-		delete root;
-}
-
-
-
-
-void
-VspKdStatistics::Print(ostream &app) const
+	if (mRoot)
+		delete mRoot;
+}
+
+void VspKdStatistics::Print(ostream &app) const
 {
   app << "===== VspKdTree statistics ===============\n";
@@ -1493,2 +1546,31 @@
 	return sumPvs / (float)leaves;
 }
+
+VspKdTreeNode *VspKdTree::GetRoot() const
+{
+	return mRoot;
+}
+
+AxisAlignedBox3 VspKdTree::GetBBox(const VspKdTreeNode *node) 
+{
+	if (node->parent == NULL)
+		return mBbox;
+
+	if (!node->IsLeaf())
+		return ((VspKdTreeInterior *)node)->mBbox;
+
+	if (node->parent->axis >= 3)
+		return node->parent->mBbox;
+    
+	AxisAlignedBox3 box(node->parent->mBbox);
+	if (node->parent->front == node)
+		box.SetMin(node->parent->axis, node->parent->position);
+	else
+		box.SetMax(node->parent->axis, node->parent->position);
+	return mBbox;
+}
+
+int	VspKdTree::GetRootPvsSize() const 
+{
+	return GetPvsSize(mRoot, mBox);
+}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 396)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 418)
@@ -12,4 +12,5 @@
 class KdTree;
 class BspTree;
+class VspKdTree;
 class SceneGraphNode;
 class Ray;
@@ -46,4 +47,7 @@
   virtual bool
   ExportKdTree(const KdTree &tree) = 0;
+
+  virtual bool
+  ExportVspKdTree(const VspKdTree &tree) = 0;
 
   virtual bool
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 414)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 418)
@@ -1487,14 +1487,14 @@
 
 		// give penalty to unbalanced split
+		if (0)
 		if (((pFront * 0.2 + Limits::Small) > pBack) || (pFront < (pBack * 0.2 + Limits::Small)))
 			val += 0.5;
 	}
 
-	if (0)
+#ifdef _DEBUG
 	Debug << "totalpvs: " << pvs << " ptotal: " << pOverall
 		  << " frontpvs: " << frontPvs << " pFront: " << pFront 
-		  << " backpvs: " << backPvs << " pBack: " << pBack 
-		  << " val " << val << " new size: " << ComputePvsSize(rays)<< endl << endl;
-
+		  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl;
+#endif
 	return val;
 }
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 416)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 418)
@@ -54,6 +54,7 @@
 	// probability that view point lies in a view cell
 	float pInVcTotal = 0;
+
 	// total probability that a view cell border is crossed
-	float pCrossVcTotal = 0;
+	const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
 
 	// collect all view cells
@@ -78,5 +79,5 @@
 		// compute render time of PVS times probability that view point is in view cell
 		float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
-		Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
+		//Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
 		renderTime += vcCost;
 
@@ -87,11 +88,10 @@
 
 		// probability that a view cell border is crossed
-		float pCrossVc = area;
+		float pCrossVc = area * mMoveSpeed;
 
 		// crossing the border of a view cell is also depending on the move speed
-		loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
+		loadPvsOverhead += pCrossVc * mVcOverhead;
 
 		pInVcTotal += pInVc;
-		pCrossVcTotal += pCrossVc;
 	}
 
@@ -99,7 +99,4 @@
 	renderTime /= pInVcTotal;
 	loadPvsOverhead /= pCrossVcTotal;
-
-	Debug << "bsp RT: " << renderTime << endl;
-	Debug << "bsp pvsOverhead: " << loadPvsOverhead << endl;
 
 	mStat.avgRtWithoutOverhead = renderTime;
@@ -144,5 +141,5 @@
 
 	// total probability that a view cell border is crossed
-	float pCrossVcTotal = 0;
+	const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
 
 	vector<KdLeaf *> leaves;
@@ -165,7 +162,4 @@
 			pInVc = box.SurfaceArea();
 		
-		// probability that a view cell border is crossed
-		const float pCrossVc = box.SurfaceArea();
-
 		float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
 		renderTime += vcCost;
@@ -176,13 +170,11 @@
 			mStat.minCost = vcCost;
 
-		loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
+		// probability that a view cell border is crossed
+		const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
+
+		loadPvsOverhead += pCrossVc * mVcOverhead;
 
 		pInVcTotal += pInVc;
-		pCrossVcTotal += pCrossVc;
 	}
-
-	Debug << "RT: " << renderTime << endl;
-	Debug << "pvsOverhead: " << loadPvsOverhead << endl;
-
 
 	renderTime /= pInVcTotal;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 396)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 418)
@@ -39,4 +39,7 @@
   ExportKdTree(const KdTree &tree);
   
+  bool 
+  ExportVspKdTree(const VspKdTree &tree);
+
   bool ExportBspTree(const BspTree &tree);
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 396)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 418)
@@ -9,4 +9,5 @@
 #include "Polygon3.h"
 #include "VssRay.h"
+#include "VspKdTree.h"
 
 X3dExporter::X3dExporter(const string filename):Exporter(filename)
@@ -580,4 +581,58 @@
 
 	return true;
+}
+
+bool X3dExporter::ExportVspKdTree(const VspKdTree &tree)
+{
+	 if (mExportRayDensity) 
+	 {
+		 return ExportKdTreeRayDensity(tree);
+	 }
+     
+	 stack<VspKdTreeNode *> tStack;
+
+	 tStack.push(tree.GetRoot());
+
+	 Mesh *mesh = new Mesh;
+  
+	 while (!tStack.empty()) 
+	 {
+		 VspKdTreeNode *node = tStack.top();
+    
+		 tStack.pop();
+		 AxisAlignedBox3 box = tree.GetBBox(node);
+
+		 // add 6 vertices of the box
+
+		 int index = (int)mesh->mVertices.size();
+   
+		 for (int i=0; i < 8; ++ i) 
+		 {
+			 Vector3 v;
+			 box.GetVertex(i, v);
+			 mesh->mVertices.push_back(v);
+		 }
+
+		 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) );
+		 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) );
+		 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) );
+
+   
+		 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) );
+		 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) );
+		 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) );
+
+		 if (!node->IsLeaf()) 
+		 {
+			 VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node);
+			 tStack.push(interior->mFront);
+			 tStack.push(interior->mBack);
+		 }
+	 }
+  
+	 ExportMesh(mesh);
+	 DEL_PTR(mesh);
+
+	 return true;
 }
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 414)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 418)
@@ -272,71 +272,36 @@
 {
 public:
-  // plane in local modelling coordinates
-  float position;
-
-  // pointers to children
-  VspKdTreeNode *back, *front;
-
-  // the bbox of the node
-  AxisAlignedBox3 bbox;
-
-  // the bbox of the node
-  AxisAlignedBox3 dirBBox;
-  
-  // data for caching
-  long accesses;
-  long lastAccessTime;
-  
-  VspKdTreeInterior(VspKdTreeInterior *p):VspKdTreeNode(p),
-					back(NULL),
-					front(NULL),
-					accesses(0),
-					lastAccessTime(-1)
-  { }
-
-  virtual int GetAccessTime() {
-    return lastAccessTime;
-  }
-
-  void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f) {
-    back = b;
-    front = f;
-    b->parent = f->parent = this;
-  }
-
-  void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild) {
-    if (back == oldChild)
-      back = newChild;
-    else
-      front = newChild;
-  }
-
-  virtual int Type() const  { return EInterior; }
-  
-  virtual ~VspKdTreeInterior()
-  {
-	  DEL_PTR(back);
-	  DEL_PTR(front);
-  }
-  
-  virtual void Print(ostream &s) const 
-  {
-	  if (axis == 0)
-		  s << "x ";
-	  else
-		  if (axis == 1)
-			  s << "y ";
-		  else
-			  s << "z ";
-	  s << position << " ";
-	  back->Print(s);
-	  front->Print(s);
-  }
-	
-  int ComputeRayIntersection(const RayInfo &rayData, float &t) 
-  {
-	  return rayData.ComputeRayIntersection(axis, position, t);
-  }
-
+	
+	VspKdTreeInterior(VspKdTreeInterior *p);
+			
+	virtual int GetAccessTime();
+	
+	virtual int Type();
+  
+	virtual ~VspKdTreeInterior();
+    
+	virtual void Print(ostream &s) const;
+
+protected:
+
+	void SetupChildLinks(VspKdTreeNode *b, VspKdTreeNode *f);
+ 
+	void ReplaceChildLink(VspKdTreeNode *oldChild, VspKdTreeNode *newChild);
+ 
+	int ComputeRayIntersection(const RayInfo &rayData, float &t);
+
+	// plane in local modelling coordinates
+	float mPosition;
+
+	// pointers to children
+	VspKdTreeNode *mBack;
+	VspKdTreeNode *mFront;
+
+	// the bbox of the node
+	AxisAlignedBox3 mBbox;
+
+	// data for caching
+	long mAccesses;
+	long mLastAccessTime;
 };
 
@@ -543,83 +508,5 @@
 	
 public:
-	
-	/////////////////////////////
-	// The core pointer
-	VspKdTreeNode *root;
-  
-	/////////////////////////////
-	// Basic properties
-
-	// total number of nodes of the tree
-	int nodes;
-	
-	// axis aligned bounding box of the scene
-	AxisAlignedBox3 bbox;
-
-	// axis aligned bounding box of directions
-	AxisAlignedBox3 dirBBox;
-
-	const VspKdStatistics &GetStatistics() const {
-		return mStat;
-	}
-	/////////////////////////////
-	// Construction parameters
-
-	// epsilon used for the construction
-	float epsilon;
-
-	// ratio between traversal and intersection costs
-	float ct_div_ci;
-	
-	// max depth of the tree
-	int termMaxDepth;
-	// minimal ratio of the volume of the cell and the query volume
-	float termMinSize;
-
-	// minimal pvs per node to still get subdivided
-	int termMinPvs;
-
-	// minimal ray number per node to still get subdivided
-	int termMinRays;
-	
-	// maximal cost ration to subdivide a node
-	float termMaxCostRatio;
-	
-	// maximal contribution per ray to subdivide the node
-	float termMaxRayContribution;
-
-	// randomized construction
-	bool randomize;
-
-	// type of the splitting to use for the tree construction
-	enum {ESplitRegular, ESplitHeuristic };
-	int splitType;
-	
-	// maximal size of the box on which the refdir splitting can be performed
-	// (relative to the scene bbox
-	float refDirBoxMaxSize;
-  
-	// maximum alovable memory in MB
-	float maxTotalMemory;
-
-	// maximum alovable memory for static kd tree in MB
-	float maxStaticMemory;
-
-	// this is used during the construction depending
-	// on the type of the tree and queries...
-	float maxMemory;
-
-	// minimal acess time for collapse
-	int accessTimeThreshold;
-
-	// minimal depth at which to perform collapse
-	int minCollapseDepth;
-	
-	// reusable array of split candidates
-	vector<SortableEntry> *splitCandidates;
-	
-	/////////////////////////////
-	VspKdStatistics mStat;
-	
+
 	VspKdTree();
 	virtual ~VspKdTree();
@@ -697,50 +584,5 @@
 						int &pvsFront);
 
-	AxisAlignedBox3 GetBBox(const VspKdTreeNode *node) 
-	{
-		if (node->parent == NULL)
-			return bbox;
-
-		if (!node->IsLeaf())
-			return ((VspKdTreeInterior *)node)->bbox;
-
-		if (node->parent->axis >= 3)
-			return node->parent->bbox;
-      
-		AxisAlignedBox3 box(node->parent->bbox);
-		if (node->parent->front == node)
-			box.SetMin(node->parent->axis, node->parent->position);
-		else
-			box.SetMax(node->parent->axis, node->parent->position);
-		return box;
-	}
-
-	AxisAlignedBox3 GetDirBBox(const VspKdTreeNode *node) 
-	{
-		if (node->parent == NULL)
-			return dirBBox;
-		if (!node->IsLeaf())
-			return ((VspKdTreeInterior *)node)->dirBBox;
-		if (node->parent->axis < 3)
-			return node->parent->dirBBox;
-    
-		AxisAlignedBox3 dBBox(node->parent->dirBBox);
-
-		if (node->parent->front == node)
-			dBBox.SetMin(node->parent->axis - 3, node->parent->position);
-		else
-			dBBox.SetMax(node->parent->axis - 3, node->parent->position);
-		return dBBox;
-	}
-  
-	int	ReleaseMemory(const int time);
-
-	int	CollapseSubtree(VspKdTreeNode *node, const int time);
-	
-	void CountAccess(VspKdTreeInterior *node, const long time) 
-	{
-		++ node->accesses;
-		node->lastAccessTime = time;
-	}
+	AxisAlignedBox3 GetBBox(const VspKdTreeNode *node); 	
 
 	VspKdTreeNode * SubdivideLeaf(VspKdTreeLeaf *leaf,
@@ -759,8 +601,5 @@
 
 
-	int	GetRootPvsSize() const 
-	{
-		return GetPvsSize(root, bbox);
-	}
+	int	GetRootPvsSize() const;
 	
 	int	GetPvsSize(VspKdTreeNode *node, const AxisAlignedBox3 &box) const;
@@ -774,4 +613,82 @@
 
 	float GetAvgPvsSize();
+
+	/** Get the root of the tree.
+	*/
+	VspKdTreeNode *GetRoot() const;
+
+	int CollapseSubtree(VspKdTreeNode *sroot, const int time);
+
+	const VspKdStatistics &GetStatistics() const {
+		return mStat;
+	}
+	
+	
+	/////////////////////////////
+	// Construction parameters
+
+	// max depth of the tree
+	int sTermMaxDepth;
+
+	// minimal ratio of the volume of the cell and the query volume
+	float sTermMinSize;
+
+	// minimal pvs per node to still get subdivided
+	int sTermMinPvs;
+
+	// minimal ray number per node to still get subdivided
+	int sTermMinRays;
+	
+	// maximal cost ration to subdivide a node
+	float sTermMaxCostRatio;
+	
+	// maximal contribution per ray to subdivide the node
+	float sTermMaxRayContribution;
+
+protected:
+	/////////////////////////////
+	// The core pointer
+	VspKdTreeNode *mRoot;
+  
+	/////////////////////////////
+	// Basic properties
+
+	// total number of nodes of the tree
+	int nodes;
+	
+	// axis aligned bounding box of the scene
+	AxisAlignedBox3 mBox;
+
+	// epsilon used for the construction
+	float epsilon;
+
+	// ratio between traversal and intersection costs
+	float ct_div_ci;
+	
+	// type of the splitting to use for the tree construction
+	enum {ESplitRegular, ESplitHeuristic };
+	int splitType;
+	
+	// maximum alovable memory in MB
+	float maxTotalMemory;
+
+	// maximum alovable memory for static kd tree in MB
+	float maxStaticMemory;
+
+	// this is used during the construction depending
+	// on the type of the tree and queries...
+	float maxMemory;
+
+	// minimal acess time for collapse
+	int accessTimeThreshold;
+
+	// minimal depth at which to perform collapse
+	int minCollapseDepth;
+	
+	// reusable array of split candidates
+	vector<SortableEntry> *splitCandidates;
+	
+	/////////////////////////////
+	VspKdStatistics mStat;	
 };
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 416)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 418)
@@ -167,7 +167,5 @@
 
 int
-SamplingPreprocessor::CastRay(Intersectable *object,
-															Ray &ray
-															)
+SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray)
 {
 	int sampleContributions = 0;
@@ -520,8 +518,6 @@
 		}
 		else
-		{
-			Debug << "contr: " << passSampleContributions << " pvs: " << pvsSize << " objects: " << objects.size() << endl;
 			pvsSize += passSampleContributions;
-		}
+		
 		float avgRayContrib = (passContributingSamples > 0) ? 
 			passSampleContributions/(float)passContributingSamples : 0;
@@ -641,6 +637,6 @@
 		exporter->ExportKdTree(*mKdTree);
 
-		if (mBspTree && (ViewCell::sHierarchy == ViewCell::BSP))
-			exporter->ExportBspTree(*mBspTree);
+		if (mBspTree && (ViewCell::sHierarchy == ViewCell::VSP))
+			exporter->ExportVspKdTree(*mVspKdTree);
 
 		delete exporter;
Index: /trunk/VUT/Ogre/resources/overlays/VisibilityDemo.overlay
===================================================================
--- /trunk/VUT/Ogre/resources/overlays/VisibilityDemo.overlay	(revision 343)
+++ /trunk/VUT/Ogre/resources/overlays/VisibilityDemo.overlay	(revision 418)
@@ -469,4 +469,5 @@
 			caption [C] Mesh / Patch visibility (only item buffer)
 		}
+		
 		element TextArea(Example/Visibility/Help/SceneObjects): Example/Visibility/Templates/BasicText
 		{
@@ -476,4 +477,11 @@
 			caption ******* Generation / Destruction of scene objects ******
 		}
+		element TextArea(Example/Visibility/Help/PlaceObjects): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			width 180
+			height 30
+			caption [O] Start / Stop object placing mode
+		}
 		element TextArea(Example/Visibility/Help/GenerateObjects): Example/Visibility/Templates/BasicText
 		{
@@ -495,5 +503,5 @@
 			width 180
 			height 30
-			caption [MOUSE LEFT] Drop object on terrain
+			caption [MOUSE LEFT] Drop object on terrain if in object placing mode
 		}
 	}
