Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 428)
@@ -62,5 +62,5 @@
 
 Sampling {
-	totalSamples	1000000
+	totalSamples	600000
 	samplesPerPass  3
 }
@@ -219,13 +219,13 @@
 
 	Construction {
-		samples 1000000
+		samples 500000
 	}
 	
 	Termination {
 		maxDepth 	30
-		minPvs		50
-		minRays		10
+		minPvs		60
+		minRays		1
 		minSize		0.1
-		maxCostRatio	0.95
+		maxCostRatio	999.0
 		maxRayContribution 0.2
 	}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 428)
@@ -26,6 +26,9 @@
 #include "RayInfo.h"
 
+
 // Static variables
 int VspKdTreeLeaf::mailID = 0;
+
+#define USE_FIXEDPOINT_T 0
 
 /// Adds object to the pvs of the front and back node
@@ -51,9 +54,10 @@
 	}
 	
-	if (side >= 0) 
+	if (side >= 0)
 	{
 		if (!object->Mailed(1) && !object->Mailed(2)) 
 		{
 			++ pvsFront;
+
 			if (object->Mailed())
 				object->Mail(2);
@@ -245,4 +249,26 @@
 	return mRays;
 }
+
+void VspKdTreeLeaf::ExtractPvs(ObjectContainer &objects) const
+{
+	RayInfoContainer::const_iterator it, it_end = mRays.end();
+
+	for (it = mRays.begin(); it != it_end; ++ it)
+	{
+		if ((*it).mRay->mTerminationObject)
+			objects.push_back((*it).mRay->mTerminationObject);
+		if ((*it).mRay->mOriginObject)
+			objects.push_back((*it).mRay->mOriginObject);
+	}
+}
+
+void VspKdTreeLeaf::GetRays(VssRayContainer &rays)
+{
+	RayInfoContainer::const_iterator it, it_end = mRays.end();
+
+	for (it = mRays.begin(); it != mRays.end(); ++ it)
+		rays.push_back((*it).mRay);
+}
+
 /*********************************************************/
 /*            class VspKdTree implementation             */
@@ -250,7 +276,5 @@
 
 
-// Constructor
-VspKdTree::VspKdTree():
-mOnlyDrivingAxis(true)
+VspKdTree::VspKdTree(): mOnlyDrivingAxis(true)
 {	  
 	environment->GetIntValue("VspKdTree.Termination.maxDepth", mTermMaxDepth);
@@ -546,6 +570,6 @@
 {
 	int minDirDepth = 6;
-	int axis;
-	float costRatio;
+	int axis = 0;
+	float costRatio = 0;
 	
 	if (splitType == ESplitRegular) 
@@ -575,5 +599,5 @@
 	}
 
-	if (0 && costRatio > mTermMaxCostRatio) 
+	if (costRatio > mTermMaxCostRatio) 
 	{
 		Debug << "Too big cost ratio " << costRatio << endl;
@@ -581,11 +605,9 @@
 	}
 
-#if 1	
-	Debug <<
-		"pvs=" << leaf->mPvsSize <<
-		" rays=" << (int)leaf->mRays.size() <<
-		" rc=" << leaf->GetAvgRayContribution() <<
-		" axis=" << axis << endl;
-#endif
+	if (0)
+		Debug << "pvs=" << leaf->mPvsSize 
+			  << " rays=" << (int)leaf->mRays.size() 
+			  << " rc=" << leaf->GetAvgRayContribution() 
+			  << " axis=" << axis << endl;
 	
 	return axis;
@@ -638,12 +660,13 @@
 	float ratio = 0;
 	
-	if (1)
-	{
-		const float sum = pvsBack + pvsFront;
+	if (0)
+	{
+		const float sum = float(pvsBack + pvsFront);
 		const float oldCost = (float)pvsSize * 2;
 
 		return sum / oldCost;
 	}
-	else {
+	else 
+	{
 		AxisAlignedBox3 box = GetBBox(leaf);
 	
@@ -653,5 +676,5 @@
 		
 		// float sum = raysBack*(position - minBox) + raysFront*(maxBox - position);
-		float sum = pvsBack * (position - minBox) + pvsFront * (maxBox - position);
+		const float sum = pvsBack * (position - minBox) + pvsFront * (maxBox - position);
 
 		newCost = mCtDivCi + sum  / sizeBox;
@@ -659,8 +682,7 @@
 		//Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
 		//  float oldCost = leaf->mRays.size();
-		float oldCost = (float)pvsSize;
+		const float oldCost = (float)pvsSize;
 		
 		float ratio = newCost / oldCost;
-	
 	}
 	
@@ -685,6 +707,5 @@
 	AxisAlignedBox3 sBox = GetBBox(leaf);
 
-	// int sAxis = box.Size().DrivingAxis();
-	int sAxis = sBox.Size().DrivingAxis();
+	const int sAxis = sBox.Size().DrivingAxis();
 
 	for (axis = 0; axis < 3; ++ axis) 
@@ -706,8 +727,14 @@
 			else
 				if (nCostRatio[axis] < nCostRatio[bestAxis])
+				{
+					Debug << "pvs front " << nPvsBack[axis]
+						  << " pvs back " << nPvsFront[axis]
+						  << " overall pvs " << leaf->GetPvsSize() << endl;
 					bestAxis = axis;
-		}
-	}
-
+				}
+		}
+	}
+
+	//-- assign best axis
 	axis = bestAxis;
 	position = nPosition[bestAxis];
@@ -924,13 +951,11 @@
 	if (TerminationCriteriaMet(leaf, box))
 	{
-		if (1)
-		{
-			if (leaf->mDepth >= mTermMaxDepth) 
-			{
-				Debug << "Warning: max depth reached depth=" << (int)leaf->mDepth<<" rays=" << (int)leaf->mRays.size() << endl;
-				Debug << "Bbox: " << GetBBox(leaf) << endl;
-			}
-			//Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl;
-		}
+		if (1 && leaf->mDepth >= mTermMaxDepth) 
+		{
+			Debug << "Warning: max depth reached depth=" << (int)leaf->mDepth<<" rays=" << (int)leaf->mRays.size() << endl;
+			Debug << "Bbox: " << GetBBox(leaf) << endl;
+		}
+		//Debug << "depth: " << (int)leaf->mDepth << " pvs: " << leaf->GetPvsSize() << " rays: " << leaf->mRays.size() << endl;
+		
 		return leaf;
 	}
@@ -1351,5 +1376,5 @@
 #if DEBUG_COLLAPSE
 	cout << "Collapsing subtree" << endl;
-	cout << "acessTime=" << sroot->GetAccessTime() << endl;
+	cout << "accessTime=" << sroot->GetAccessTime() << endl;
 	cout << "depth=" << (int)sroot->depth << endl;
 #endif
@@ -1717,2 +1742,28 @@
 	return pvsSize;
 }
+
+void VspKdTree::CollectLeaves(vector<VspKdTreeLeaf *> &leaves) const
+{
+	stack<VspKdTreeNode *> nodeStack;
+	nodeStack.push(mRoot);
+
+	while (!nodeStack.empty()) 
+	{
+		VspKdTreeNode *node = nodeStack.top();
+		
+		nodeStack.pop();
+		
+		if (node->IsLeaf()) 
+		{
+			VspKdTreeLeaf *leaf = dynamic_cast<VspKdTreeLeaf *>(node);
+			leaves.push_back(leaf);
+		} 
+		else 
+		{
+			VspKdTreeInterior *interior = dynamic_cast<VspKdTreeInterior *>(node);
+
+			nodeStack.push(interior->mBack);
+			nodeStack.push(interior->mFront);
+		}
+	}
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 428)
@@ -328,6 +328,6 @@
 	void SetViewCell(BspViewCell *viewCell);
 
-	/** Adds rays to the PVS.
-		@param sampleContributions the number contributions of the sampels
+	/** Adds ray sample contributions to the PVS.
+		@param sampleContributions the number contributions of the samples
 		@param contributingSampels the number of contributing rays
 		
@@ -755,13 +755,13 @@
 	void ExtractHalfSpaces(BspNode *n, vector<Plane3> &halfSpaces) const;
 
-	/** Computes the pvs of the front and back leaf with a given classification.
-	*/
-	void IncPvs(Intersectable &obj, 
-				  int &frontPvs,
-				  int &backPvs,
-				  const int cf, 
-				  const int frontId, 
-				  const int backId, 
-				  const int frontAndBackId) const;
+	/** Adds the object to the pvs of the front and back leaf with a given classification.
+
+		@param obj the object to be added
+		@param cf the ray classification regarding the split plane
+		@param frontPvs returns the PVS of the front partition
+		@param backPvs returns the PVS of the back partition
+	
+	*/
+	void AddObjToPvs(Intersectable *obj, const int cf, int &frontPvs, int &backPvs) const;
 	
 	int ComputePvsSize(const BoundedRayContainer &rays) const;
@@ -859,4 +859,5 @@
 
 private:
+	
 	/** Evaluates split plane classification with respect to the plane's 
 		contribution for a balanced tree.
@@ -876,4 +877,11 @@
 	static const float sBalancedRaysTable[5];
 
+	/// Generates unique ids for PVS criterium
+	static void GenerateUniqueIdsForPvs();
+
+	//-- unique ids for PVS criterium
+	static int sFrontId; 
+	static int sBackId;
+	static int sFrontAndBackId;
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 428)
@@ -45,5 +45,5 @@
 				 const int face):mT(t), mObject(object), mFace(face) {}
 		
-    Intersection() {}
+				 Intersection(): mT(0), mObject(NULL), mFace(0) {}
 		
     bool operator<(
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 425)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 428)
@@ -110,5 +110,4 @@
   GetExporter(const string filename);
 
-  
 };
  
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 428)
@@ -38,4 +38,7 @@
 int BspTree::sConstructionMethod = FROM_INPUT_VIEW_CELLS;
 
+int BspTree::sFrontId = 0; 
+int BspTree::sBackId = 0;
+int BspTree::sFrontAndBackId = 0;
 
 /****************************************************************/
@@ -1420,4 +1423,11 @@
 }
 
+inline void BspTree::GenerateUniqueIdsForPvs()
+{
+	Intersectable::NewMail(); sBackId = ViewCell::sMailId;
+	Intersectable::NewMail(); sFrontId = ViewCell::sMailId;
+	Intersectable::NewMail(); sFrontAndBackId = ViewCell::sMailId;
+}
+
 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, 
 							  const BoundedRayContainer &rays,
@@ -1445,8 +1455,6 @@
 	if (mSplitPlaneStrategy & PVS)
 	{
-		// create three unique ids for pvs heuristics
-		Intersectable::NewMail(); backId = ViewCell::sMailId;
-		Intersectable::NewMail(); frontId = ViewCell::sMailId;
-		Intersectable::NewMail(); frontAndBackId = ViewCell::sMailId;
+		// create unique ids for pvs heuristics
+		GenerateUniqueIdsForPvs();
 
 		if (mPvsUseArea) // use front and back cell areas to approximate volume
@@ -1490,20 +1498,14 @@
 		if (mSplitPlaneStrategy & PVS)
 		{
-			if (!ray->intersections.empty())
-			{
-				// in case the ray intersects an objcrs
-				// assure that we only count a object 
-				// once for the front and once for the back side of the plane
-				IncPvs(*ray->intersections[0].mObject, frontPvs, backPvs, 
-					   cf, frontId, backId, frontAndBackId);
-			}
-
-			// the source object in the origin of the ray
-			if (ray->sourceObject.mObject)
-			{
-				IncPvs(*ray->sourceObject.mObject, frontPvs, backPvs, 
-					   cf, frontId, backId, frontAndBackId);
-			}
-
+			// in case the ray intersects an object
+			// assure that we only count the object 
+			// once for the front and once for the back side of the plane
+			
+			// add the termination object
+			AddObjToPvs(ray->intersections[0].mObject, cf, frontPvs, backPvs);
+			
+			// add the source object
+			AddObjToPvs(ray->sourceObject.mObject, cf, frontPvs, backPvs);
+			
 			if (!mPvsUseArea) // use front and back cell areas to approximate volume
 			{	
@@ -1584,52 +1586,44 @@
 }
 
-void BspTree::IncPvs(Intersectable &obj,
-					 int &frontPvs,
-					 int &backPvs,
-					 const int cf, 
-					 const int frontId, 
-					 const int backId, 
-					 const int frontAndBackId) const
-{
+void BspTree::AddObjToPvs(Intersectable *obj,
+						  const int cf,
+						  int &frontPvs,
+						  int &backPvs) const
+{
+	if (!obj)
+		return;
 	// TODO: does this really belong to no pvs?
 	//if (cf == Ray::COINCIDENT) return;
 
-	if (cf == Ray::FRONT)
-	{
-		if ((obj.mMailbox != frontId) && 
-			(obj.mMailbox != frontAndBackId))
+	// object belongs to both PVS
+	const bool bothSides = (cf == Ray::FRONT_BACK) || 
+						   (cf == Ray::BACK_FRONT) ||
+						   (cf == Ray::COINCIDENT);
+
+	if ((cf == Ray::FRONT) || bothSides)
+	{
+		if ((obj->mMailbox != sFrontId) && 
+			(obj->mMailbox != sFrontAndBackId))
 		{
 			++ frontPvs;
 
-			if (obj.mMailbox != backId)
-				obj.mMailbox = frontId;
+			if (obj->mMailbox == sBackId)
+				obj->mMailbox = sFrontAndBackId;	
 			else
-				obj.mMailbox = frontAndBackId;					
-		}
-	}
-	else if (cf == Ray::BACK)
-	{
-		if ((obj.mMailbox != backId) &&
-			(obj.mMailbox != frontAndBackId))
+				obj->mMailbox = sFrontId;								
+		}
+	}
+	
+	if ((cf == Ray::BACK) || bothSides)
+	{
+		if ((obj->mMailbox != sBackId) &&
+			(obj->mMailbox != sFrontAndBackId))
 		{
 			++ backPvs;
 
-			if (obj.mMailbox != frontId)
-				obj.mMailbox = backId;
+			if (obj->mMailbox == sFrontId)
+				obj->mMailbox = sFrontAndBackId; 
 			else
-				obj.mMailbox = frontAndBackId; 
-		}
-	}
-	// object belongs to both PVS
-	else if ((cf == Ray::FRONT_BACK) || (cf == Ray::BACK_FRONT) ||(cf == Ray::COINCIDENT))
-	{
-		if (obj.mMailbox !=  frontAndBackId)
-		{
-			if (obj.mMailbox != frontId)
-				++ frontPvs;
-			if (obj.mMailbox != backId)
-				++ backPvs;
-		
-			obj.mMailbox = frontAndBackId;
+				obj->mMailbox = sBackId;				
 		}
 	}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 428)
@@ -171,10 +171,9 @@
 }
 
-int
-Ray::ClassifyPlane(const Plane3 &plane, 
-				   const float minT, 
-				   const float maxT,
-				   Vector3 &entP,
-				   Vector3 &extP) const
+int Ray::ClassifyPlane(const Plane3 &plane, 
+					   const float minT, 
+					   const float maxT,
+					   Vector3 &entP,
+					   Vector3 &extP) const
 {
 	entP = Extrap(minT);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 427)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 428)
@@ -72,4 +72,6 @@
 			mOrigin = ray.GetLoc(); 
 
+		Debug << "origin: " << mOrigin << endl;
+
 		if (!ray.intersections.empty())
 		{
@@ -79,5 +81,6 @@
 		else
 		{
-			mTermination = 1e6;
+			//mTermination = 1e6;
+			mTermination = mOrigin + ray.GetDir() * 1e6;
 			mTerminationObject = NULL;
 		}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h	(revision 428)
@@ -71,5 +71,5 @@
 							 int &sampleContributions);
 
-	void ProcessVspViewCells(const Ray &ray,
+	void ProcessVspViewCells(Ray &ray,
 							 Intersectable *object,
 							 const int faceIndex,
@@ -100,4 +100,6 @@
 
 protected:
+
+
 	int mPass;
 	int mSamplesPerPass;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 428)
@@ -32,5 +32,5 @@
 
 #include "RayInfo.h"
-
+#include "Containers.h"
 
 /**
@@ -123,5 +123,4 @@
 
 	friend class VspKdTree;
-#define USE_FIXEDPOINT_T 1
 
 	enum {EInterior, ELeaf};
@@ -266,6 +265,11 @@
 	void UpdatePvsSize();
 
+	/** Returns stored rays.
+	*/
 	RayInfoContainer &GetRays();
 
+	/** Returns rays into this ray container.
+	*/
+	void GetRays(VssRayContainer &rays);
 	/** Returns average contribution of a ray to the PVS
 	*/
@@ -275,6 +279,9 @@
 	inline float GetSqrRayContribution() const;
 
+	/** Extracts PVS from ray set.
+	*/
+	void ExtractPvs(ObjectContainer &objects) const;
+
 	//-- mailing options
-
 	void Mail();
 
@@ -286,4 +293,5 @@
 
 	static int mailID;
+
 
 protected:
@@ -441,5 +449,10 @@
 	float GetRayMemUsage() const;
 
+	/** Collects leaves of this tree.
+	*/
+	void CollectLeaves(vector<VspKdTreeLeaf *> &leaves) const;
+
 protected:
+
 	// incremental construction
 	virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 426)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 428)
@@ -450,4 +450,5 @@
 							direction = point - pointToSample;
 							point = pointToSample;
+							Debug << "point: " << pointToSample << endl;
 						}
 					}
@@ -667,32 +668,81 @@
 	if (mVspKdTree)
 	{
-		Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 
-		//exporter->SetWireframe();
-		exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize);
-
-		Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl;
-
-		if (1) ExportSceneGeometry(exporter, objects);
-
-		bool exportRays = false;
-
-		if (exportRays) 
-		{
-			int raysSize = 500;
-			float prob = raysSize / (float)mVspSampleRays.size();
-		
-			exporter->SetWireframe();
-			
-			VssRayContainer rays;
-			for (int i = 0; i < mVspSampleRays.size(); ++ i)
-			{
-				if (RandomValue(0,1) < prob)
-					rays.push_back(mVspSampleRays[i]);
-			}
-
-			exporter->ExportRays(rays, RgbColor(1, 0, 0));
-		}
-
-		delete exporter;
+		if (1)
+		{
+			Exporter *exporter = Exporter::GetExporter("vspkdtree.x3d"); 
+			//exporter->SetWireframe();
+			exporter->ExportVspKdTree(*mVspKdTree, mVspKdTree->GetStatistics().maxPvsSize);
+
+			Debug << "average PVS size: " << mVspKdTree->GetAvgPvsSize() << endl;
+
+			if (0) ExportSceneGeometry(exporter, objects);
+
+			bool exportRays = true;
+
+			if (exportRays) 
+			{
+				int raysSize = 2000;
+				float prob = raysSize / (float)mVspSampleRays.size();
+		
+				exporter->SetWireframe();
+			
+				VssRayContainer rays;
+				for (int i = 0; i < mVspSampleRays.size(); ++ i)
+				{
+					if (RandomValue(0,1) < prob)
+						rays.push_back(mVspSampleRays[i]);
+				}
+
+				exporter->ExportRays(rays, RgbColor(1, 0, 0));
+			}
+
+			delete exporter;
+		}
+
+		if (1)
+		{
+			vector<VspKdTreeLeaf *> leafContainer;
+
+			mVspKdTree->CollectLeaves(leafContainer);
+
+			for (int i = 0; i < 10; ++ i)
+			{
+				char s[64];
+				sprintf(s, "vsp_leaves%04d.x3d", i);
+				Exporter *exporter = Exporter::GetExporter(s);
+
+				// export geometry
+				VspKdTreeLeaf *leaf = leafContainer[Random((int)leafContainer.size())]; 
+				AxisAlignedBox3 box = mVspKdTree->GetBBox(leaf);
+
+				Material m;
+				m.mDiffuseColor = RgbColor(0, 1, 1);
+				exporter->SetForcedMaterial(m);
+				exporter->SetWireframe();
+				exporter->ExportBox(box);
+
+				//-- export stored rays
+				VssRayContainer vssRays;
+				leaf->GetRays(vssRays);
+
+				VssRayContainer rays;
+
+				VssRayContainer::const_iterator it, it_end = vssRays.end();
+
+				for (it = vssRays.begin(); it != it_end; ++ it)
+					if (!(*it)->mOriginObject)
+						rays.push_back(*it);
+
+				exporter->ExportRays(rays, RgbColor(1, 0, 0));
+
+				//-- export stored PVS
+				ObjectContainer pvsObj;
+				leaf->ExtractPvs(pvsObj);
+				
+				ExportSceneGeometry(exporter, pvsObj);
+
+				delete exporter;
+			}			
+		}
 	}
   
@@ -757,5 +807,5 @@
 
 
-void SamplingPreprocessor::ProcessVspViewCells(const Ray &ray,
+void SamplingPreprocessor::ProcessVspViewCells(Ray &ray,
                                                Intersectable *object,
 											   const int faceIndex,
@@ -768,11 +818,7 @@
 		if ((int)mVspSampleRays.size() < mVspConstructionSamples)
 		{
+			ray.sourceObject = Ray::Intersection(0.0, object, faceIndex);
 			VssRay *sRay = new VssRay(ray);
-		
-            mVspSampleRays.push_back(sRay);
-		
-			// also add origin to sample
-			sRay->mOriginObject = object;
-			sRay->mOrigin = ray.GetLoc();
+			mVspSampleRays.push_back(sRay);
 		}
 		else
