Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1976)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1977)
@@ -201,4 +201,6 @@
 	bool mPerViewCell;
 	bool mOnlyRandomSampling;
+
+	ViewCell *mCurrentViewCell;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1977)
@@ -156,5 +156,9 @@
 											const bool storeViewCells);
 
-	//virtual void AddSampleContributions(VssRay &ray);
+	/** Compute sample contribution only for current view cell.
+	*/
+	virtual float ComputeSampleContribution(VssRay &ray, 
+											const bool addRays,
+											ViewCell *currentViewCell);
 
 	/** Prints out statistics of the view cells.
@@ -251,9 +255,14 @@
 		by this line segment 
 	*/
-  
-	virtual int CastLineSegment(const Vector3 &origin,
+  	virtual int CastLineSegment(const Vector3 &origin,
 							  const Vector3 &termination,
 							  ViewCellContainer &viewcells
 							  ) = 0;
+
+	/** Tests if this line segment intersects a particular view cell.
+	*/
+	virtual bool LineSegmentIntersects(const Vector3 &origin,
+									   const Vector3 &termination,
+									   ViewCell *viewCell) = 0;
 
 	/** Returns a stats about the global pvs.
@@ -883,4 +892,8 @@
 							   VssRayContainer *visRays = NULL);
 
+	bool LineSegmentIntersects(const Vector3 &origin,
+							   const Vector3 &termination,
+							   ViewCell *viewCell);
+
 protected:
 
@@ -964,4 +977,8 @@
 							   VssRayContainer *visRays = NULL);
 
+	bool LineSegmentIntersects(const Vector3 &origin,
+							   const Vector3 &termination,
+							   ViewCell *viewCell);
+
 protected:
 
@@ -1051,4 +1068,8 @@
 
 	
+	bool LineSegmentIntersects(const Vector3 &origin,
+							   const Vector3 &termination,
+							   ViewCell *viewCell);
+
 protected:
 
@@ -1117,4 +1138,5 @@
 {
 	friend class ViewCellsParseHandlers;
+
 public:
 
@@ -1136,6 +1158,6 @@
 	ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
 
-  virtual Intersectable *
-  GetIntersectable(const VssRay &ray, const bool isTermination) const;
+	virtual Intersectable *GetIntersectable(
+		const VssRay &ray, const bool isTermination) const;
 
 	bool ViewCellsConstructed() const;
@@ -1146,4 +1168,8 @@
 						ViewCellContainer &viewcells);
 
+	bool LineSegmentIntersects(const Vector3 &origin, 
+							   const Vector3 &termination, 
+							   ViewCell *viewCell);
+
 	float GetProbability(ViewCell *viewCell);
 	
@@ -1164,11 +1190,5 @@
 	void Finalize(ViewCell *viewCell, const bool createMesh);
 
-	/** Stores sample contribution for kd cells or objects.
-	*/
-  //	virtual float ComputeSampleContribution(VssRay &ray, 
-  //											const bool addRays,
-  //											const bool storeViewCells);
-
-	ViewCellsManager *LoadViewCells(const string &filename, 
+  	ViewCellsManager *LoadViewCells(const string &filename, 
 									ObjectContainer *objects,
 									const bool finalizeViewCells,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1968)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1977)
@@ -489,5 +489,5 @@
 			</File>
 			<File
-				RelativePath="..\src\Intersectable.h">
+				RelativePath=".\Intersectable.h">
 			</File>
 			<File
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1913)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1977)
@@ -701,4 +701,7 @@
 	VspNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate);
 
+	bool LineSegmentIntersects(const Vector3 &origin, 
+							   const Vector3 &termination, 
+							   ViewCell *viewCell);
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1977)
@@ -2027,8 +2027,7 @@
 		stat.avgPvs += pvsCost;
 
-		const float pvsEntries = mViewCellsTree->GetPvsEntries(viewcell);
+		const float pvsEntries = (float)mViewCellsTree->GetPvsEntries(viewcell);
 		stat.avgPvsEntries += pvsEntries;
 		
-
 		if (mPerViewCellStat[i].pvsSize > 0.0f)
 		  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize)/mPerViewCellStat[i].pvsSize;
@@ -2280,4 +2279,58 @@
 	  }
 	
+}
+
+
+float ViewCellsManager::ComputeSampleContribution(VssRay &ray,
+												  const bool addRays,
+												  ViewCell *currentViewCell)
+{
+	ray.mPvsContribution = 0;
+	ray.mRelativePvsContribution = 0.0f;
+
+	if (!ray.mTerminationObject)
+		return 0.0f;
+
+	static Ray hray;
+	hray.Init(ray);
+
+	float tmin = 0, tmax = 1.0;
+
+	if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax))
+	{
+		// cerr<<"ray outside view space box\n";
+		return 0;
+	}
+
+	Vector3 origin = hray.Extrap(tmin);
+	Vector3 termination = hray.Extrap(tmax);
+
+	// traverse the view space subdivision
+	if (!LineSegmentIntersects(origin, 
+							   termination, 
+							   currentViewCell))
+	{
+		return 0;
+	}
+	
+	// optain pvs entry (can be different from hit object)
+	Intersectable *terminationObj = GetIntersectable(ray, true);
+
+	ComputeViewCellContribution(currentViewCell, 
+								ray, 
+								terminationObj, 
+								ray.mTermination, 
+								addRays);
+	
+#if USE_RAY_LENGTH_AS_CONTRIBUTION
+	float c = 0.0f;
+	if (terminationObj) 
+	  c = ray.Length();
+	ray.mRelativePvsContribution = ray.mPvsContribution = c;
+	return c;
+#else
+	return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution +
+	  (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution;
+#endif
 }
 
@@ -3330,4 +3383,12 @@
 
 
+bool BspViewCellsManager::LineSegmentIntersects(const Vector3 &origin, 
+												const Vector3 &termination, 
+												ViewCell *viewCell)
+{
+	return false;
+}
+
+
 void ViewCellsManager::ExportMergedViewCells(const ObjectContainer &objects)
 {
@@ -4316,4 +4377,12 @@
 
 
+bool KdViewCellsManager::LineSegmentIntersects(const Vector3 &origin, 
+											   const Vector3 &termination, 
+											   ViewCell *viewCell)
+{
+	return false;
+}
+
+
 void KdViewCellsManager::CreateMesh(ViewCell *vc)
 {
@@ -5089,4 +5158,12 @@
 {
 	return mVspBspTree->CastLineSegment(origin, termination, viewcells);
+}
+
+
+bool VspBspViewCellsManager::LineSegmentIntersects(const Vector3 &origin, 
+												   const Vector3 &termination, 
+												   ViewCell *viewCell)
+{
+	return false;
 }
 
@@ -6105,5 +6182,15 @@
 											ViewCellContainer &viewcells)
 {
-	return mHierarchyManager->GetVspTree()->CastLineSegment(origin, termination, viewcells);
+	return mHierarchyManager->
+		GetVspTree()->CastLineSegment(origin, termination, viewcells);
+}
+
+
+bool VspOspViewCellsManager::LineSegmentIntersects(const Vector3 &origin, 
+												   const Vector3 &termination, 
+												   ViewCell *viewCell)
+{
+	return mHierarchyManager->
+		GetVspTree()->LineSegmentIntersects(origin, termination, viewCell);
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1919)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1977)
@@ -3502,3 +3502,101 @@
 }
 
-}
+
+bool VspTree::LineSegmentIntersects(const Vector3 &origin, 
+									const Vector3 &termination, 
+									ViewCell *viewCell)
+{
+	/*float mint = 0.0f, maxt = 1.0f;
+	const Vector3 dir = termination - origin;
+
+	stack<LineTraversalData> tStack;
+
+	Vector3 entp = origin;
+	Vector3 extp = termination;
+
+	VspNode *node = mRoot;
+	VspNode *farChild;
+
+	float position;
+	int axis;
+
+	while (1)
+	{
+		if (!node->IsLeaf())
+		{
+			VspInterior *in = dynamic_cast<VspInterior *>(node);
+			position = in->GetPosition();
+			axis = in->GetAxis();
+
+			if (entp[axis] <= position)
+			{
+				if (extp[axis] <= position)
+				{
+					node = in->GetBack();
+					// cases N1,N2,N3,P5,Z2,Z3
+					continue;
+				} else
+				{
+					// case N4
+					node = in->GetBack();
+					farChild = in->GetFront();
+				}
+			}
+			else
+			{
+				if (position <= extp[axis])
+				{
+					node = in->GetFront();
+					// cases P1,P2,P3,N5,Z1
+					continue;
+				}
+				else
+				{
+					node = in->GetFront();
+					farChild = in->GetBack();
+					// case P4
+				}
+			}
+
+ 			// $$ modification 3.5.2004 - hints from Kamil Ghais
+			// case N4 or P4
+			const float tdist = (position - origin[axis]) / dir[axis];
+			tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO
+
+			extp = origin + dir * tdist;
+			maxt = tdist;
+		}
+		else
+		{
+			// compute intersection with all objects in this leaf
+			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			ViewCell *viewCell;
+			if (0)
+				viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
+			else
+				viewCell = leaf->GetViewCell();
+
+			if (viewCell == currentViewCell)
+				return true;
+		
+			// get the next node from the stack
+			if (tStack.empty())
+				break;
+
+			entp = extp;
+			mint = maxt;
+			
+			LineTraversalData &s  = tStack.top();
+			node = s.mNode;
+			extp = s.mExitPoint;
+			maxt = s.mMaxT;
+
+			tStack.pop();
+		}
+	}
+*/
+	return false;
+}
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1976)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1977)
@@ -87,5 +87,5 @@
 		newRay->mFlags |= VssRay::ReverseSample;
 		
-		// if ray is not further processed => can delete ray
+		// if ray is not further processed => delete ray
 		if (!HandleRay(newRay))
 		{
@@ -111,33 +111,40 @@
 	const bool storeRaysForViz = GVS_DEBUG;
 
-	mViewCellsManager->ComputeSampleContribution(*vssRay, 
-												 true, 
-												 storeRaysForViz);
+	if (!mPerViewCell)
+	{
+		mViewCellsManager->ComputeSampleContribution(*vssRay, 
+													 true, 
+													 storeRaysForViz);
+	}
+	else
+	{
+		mViewCellsManager->ComputeSampleContribution(*vssRay, 
+													 true, 
+													 mCurrentViewCell);
+	}
 
 	// some pvs contribution for this ray?
-	if (vssRay->mPvsContribution > 0)
-	{
-		// add new ray to ray queue
-		mRayQueue.push(vssRay);
-
-		if (storeRaysForViz)
-		{
-			VssRay *nray = new VssRay(*vssRay);
-			nray->mFlags = vssRay->mFlags;
-
-			// store ray in contributing view cell
-			ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end();
-			for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit)
-			{			
-				(*vit)->GetOrCreateRays()->push_back(nray);				
-			}
+	if (!vssRay->mPvsContribution)
+		return false;
+
+	// add new ray to ray queue
+	mRayQueue.push(vssRay);
+
+	if (storeRaysForViz)
+	{
+		VssRay *nray = new VssRay(*vssRay);
+		nray->mFlags = vssRay->mFlags;
+
+		// store ray in contributing view cell
+		ViewCellContainer::const_iterator vit, vit_end = vssRay->mViewCells.end();
+		for (vit = vssRay->mViewCells.begin(); vit != vit_end; ++ vit)
+		{			
+			(*vit)->GetOrCreateRays()->push_back(nray);				
 		}
-
-        ++ mGvsStats.mPassContribution;
-
-		return true;
-	}
-
-	return false;
+	}
+
+	++ mGvsStats.mPassContribution;
+
+	return true;
 }
 
