Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1145)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1155)
@@ -101,8 +101,9 @@
 	*/
 	float ComputeSampleContributions(const VssRayContainer &rays,
-								   const bool addContributions,
-								   const bool storeViewCells);
-
-	/** Add sample contributions to the viewcells they intersect */
+									 const bool addContributions,
+									 const bool storeViewCells);
+
+	/** Add sample contributions to the viewcells they intersect 
+	*/
 	void AddSampleContributions(const VssRayContainer &rays);
   
@@ -116,5 +117,5 @@
 	*/
 	virtual float ComputeSampleContributions(VssRay &ray, 
-											 const bool addRays, 
+											 const bool addRays,
 											 const bool storeViewCells);
 
@@ -475,7 +476,18 @@
 
 
-	/** Returns true if this view cell is equivalent to a node of the spatial hierarchy.
+	/** Returns true if the view cell is equivalent to a 
+		node of the spatial hierarchy. This function can be used for merged
+		view cell.
+		e.g. to see if the spatial tree can be reduced on this location
 	*/
 	virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
+
+	/** If true, the kd nodes are stored instead of the object pvs.
+	*/
+	void SetStoreKdPvs(const bool storeKdPvs);
+
+	/** Returns true if the kd nodes are stored instead of the object pvs.
+	**/
+	bool GetStoreKdPVs() const;
 
 protected:
@@ -592,5 +604,7 @@
 	bool mPruneEmptyViewCells;
 
-	/// if the pvss in the view cell leaves and the interiors are up to date
+	/// if the values in the view cell leaves and the interiors are up to date
+	/// this is meant for lazy storing of the pvs, where only a scalar indicating
+	/// pvs size is stored in interiors and not the pvs itself.
 	bool mViewCellPvsIsUpdated;
 
@@ -658,4 +672,6 @@
 	/// if pvs should be exported with view cells
 	bool mExportPvs;
+
+	bool mStoreKdPvs;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1149)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1155)
@@ -508,5 +508,4 @@
 	{
 		mBoundingBox.Initialize();
-
 		VssRayContainer::const_iterator rit, rit_end = rays.end();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1151)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1155)
@@ -54,5 +54,6 @@
 mMaxPvsRatio(1.0),
 mViewCellPvsIsUpdated(false),
-mPreprocessor(NULL)
+mPreprocessor(NULL),
+mStoreKdPvs(false)
 {
 	mViewSpaceBox.Initialize();
@@ -1361,5 +1362,5 @@
 float
 ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays,
-											 const bool addRays,
+											 const bool addRays,									
 											 const bool storeViewCells
 											 )
@@ -1372,9 +1373,8 @@
 
   float sum = 0.0f;
+
   for (it = rays.begin(); it != it_end; ++ it) 
   {
 	  sum += ComputeSampleContributions(*(*it), addRays, storeViewCells);
-	  //ComputeSampleContributions(*(*it), addRays);
-	  //	sum += (*it)->mPvsContribution;
   }
 
@@ -1867,9 +1867,6 @@
 	CastLineSegment(origin, termination, viewcells);
 
-	//const bool storeViewcells = !addRays;
-//return 0;
 	if (storeViewCells)
-	{
-		// copy viewcells memory efficiently
+	{	// copy viewcells memory efficiently
 		ray.mViewCells.reserve(viewcells.size());
 		ray.mViewCells = viewcells;
@@ -1909,5 +1906,5 @@
 	}
 
-	
+	// if addrays is true, sampled entities are stored in the pvs
 	if (addRays)
 	{
@@ -1919,7 +1916,19 @@
 			{
 				// if ray not outside of view space
-				 if (ray.mTerminationObject)
-					 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf);
-
+
+				// add kd cell
+				if (ray.mTerminationObject)
+				{
+					if (!mStoreKdPvs)
+					{
+						viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf);
+					}
+					else
+					{
+						// todo
+						//viewcell->GetPvs().AddSample(ray.mTerminationNode, ray.mPdf);
+					}
+				}
+				
 #if 0
 				 if (ray.mOriginObject)
@@ -2446,4 +2455,15 @@
 
 
+void ViewCellsManager::SetStoreKdPvs(const bool storeKdPvs)
+{
+	mStoreKdPvs = storeKdPvs;
+}
+
+
+bool ViewCellsManager::GetStoreKdPVs() const
+{
+	return mStoreKdPvs;
+}
+
 
 /*******************************************************************/
