Index: /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1770)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1772)
@@ -206,5 +206,5 @@
 				Name="VCLinkerTool"
 				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtGlRenderer.lib"
-				OutputFile="../bin/release/Preprocessor.exe"
+				OutputFile="../bin/release/Preprocessor2.exe"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;&quot;$(QTDIR)\lib&quot;;.\QtGlRenderer\Release"
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1767)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1772)
@@ -1496,6 +1496,6 @@
 	//-- compute cost
 
-	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
-	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
+	const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize();
+	const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize();
 
 	const float pOverall = sizeBox;
@@ -2018,10 +2018,10 @@
 
 	// upper and lower bounds
-	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
-	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
-
-	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
-    const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);
-	const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit);
+	const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize();
+	const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize();
+
+	const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit);
+    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
+	const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
 			
 	const float oldRenderCost = pOverall * penaltyOld;
@@ -2125,13 +2125,14 @@
 	}
 	
-
-	// -- pvs rendering heuristics
+	////////
+	//-- pvs rendering heuristics
+
 	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
 	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
 
 	// only render cost heuristics or combined with standard deviation
-	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
-    const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);
-	const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit);
+	const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit);
+    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
+	const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
 			
 	const float oldRenderCost = pOverall * penaltyOld;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1771)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1772)
@@ -945,5 +945,5 @@
 						   SimpleRayContainer &rays)
 {
-  return strategy.GenerateSamples(number, rays);
+	return strategy.GenerateSamples(number, rays);
 }
 
@@ -953,24 +953,22 @@
 						   SimpleRayContainer &rays)
 {
-  const int startSize = (int)rays.size();
-  SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType);
-  int castRays = 0;
-  
-  if (!strategy)
-	{
-	  return 0;
-	}
-  
+	const int startSize = (int)rays.size();
+	SamplingStrategy *strategy = GenerateSamplingStrategy(sampleType);
+	int castRays = 0;
+
+	if (!strategy)
+	{
+		return 0;
+	}
+
 #if 1
-  if (!strategy->GenerateSamples(number, rays))
-	return false;
-  ++ castRays;
+	castRays = strategy->GenerateSamples(number, rays);
 #else
-  GenerateRayBundle(rays, newRay, 16, 0);
-  castRays += 16;
+	GenerateRayBundle(rays, newRay, 16, 0);
+	castRays += 16;
 #endif
-  
-  delete strategy;
-  return castRays;
+
+	delete strategy;
+	return castRays;
 }
 
@@ -994,4 +992,8 @@
 	case SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION:
 		return new ViewCellBorderBasedDistribution(*this);
+	case SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION:
+		return new ViewSpaceBorderBasedDistribution(*this);
+	case SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION:
+		return new ReverseViewSpaceBorderBasedDistribution(*this);
 	//case OBJECTS_INTERIOR_DISTRIBUTION:
 	//	return new ObjectsInteriorDistribution(*this);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1771)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1772)
@@ -14,51 +14,53 @@
 class SamplingStrategy
 {
- public:
-
-	 /** Sample rays of particular type
-	 */
-	 enum 
-	 {
-		 OBJECT_BASED_DISTRIBUTION,
-		 DIRECTION_BASED_DISTRIBUTION,
-		 DIRECTION_BOX_BASED_DISTRIBUTION,
-		 SPATIAL_BOX_BASED_DISTRIBUTION,
-		 RSS_BASED_DISTRIBUTION,
-		 RSS_SILHOUETTE_BASED_DISTRIBUTION,
-		 VSS_BASED_DISTRIBUTION,
-		 OBJECT_DIRECTION_BASED_DISTRIBUTION,
-		 OBJECTS_INTERIOR_DISTRIBUTION,
-		 REVERSE_OBJECT_BASED_DISTRIBUTION,
-		 VIEWCELL_BORDER_BASED_DISTRIBUTION
-	 };
-  
-  /** Default constructor
-   */
-  SamplingStrategy(const Preprocessor &preprocessor);
-  
-  virtual ~SamplingStrategy();
-  
-  /** Each strategy has to implement this function.
-	  @returns true if generated valid sample.
-  */
-
-  virtual int GenerateSamples(const int number, SimpleRayContainer &rays) const;
-
-private:
-
-  virtual bool GenerateSample(SimpleRay &ray) const = 0;
-
 public:
-  /// variables usefull for mixed distribution sampling
-  int mType;
-  int mRays;
-  float mContribution;
-  float mTime;
-  float mRatio;
-  
+
+	/** Sample rays of particular type
+	*/
+	enum 
+	{
+		OBJECT_BASED_DISTRIBUTION,
+		DIRECTION_BASED_DISTRIBUTION,
+		DIRECTION_BOX_BASED_DISTRIBUTION,
+		SPATIAL_BOX_BASED_DISTRIBUTION,
+		RSS_BASED_DISTRIBUTION,
+		RSS_SILHOUETTE_BASED_DISTRIBUTION,
+		VSS_BASED_DISTRIBUTION,
+		OBJECT_DIRECTION_BASED_DISTRIBUTION,
+		OBJECTS_INTERIOR_DISTRIBUTION,
+		REVERSE_OBJECT_BASED_DISTRIBUTION,
+		VIEWCELL_BORDER_BASED_DISTRIBUTION,
+		VIEWSPACE_BORDER_BASED_DISTRIBUTION,
+		REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION
+	};
+
+	/** Default constructor
+	*/
+	SamplingStrategy(const Preprocessor &preprocessor);
+
+	virtual ~SamplingStrategy();
+
+	/** Each strategy has to implement this function.
+	@returns true if generated valid sample.
+	*/
+
+	virtual int GenerateSamples(const int number, SimpleRayContainer &rays) const;
+
+private:
+
+	virtual bool GenerateSample(SimpleRay &ray) const = 0;
+
+public:
+	/// variables usefull for mixed distribution sampling
+	int mType;
+	int mRays;
+	float mContribution;
+	float mTime;
+	float mRatio;
+
 protected:
-  
-  const Preprocessor &mPreprocessor;
-  
+
+	const Preprocessor &mPreprocessor;
+
 };
 
@@ -134,4 +136,17 @@
 	 SpatialBoxBasedDistribution(const Preprocessor &preprocessor):
 	   SamplingStrategy(preprocessor){
+	   mType = DIRECTION_BOX_BASED_DISTRIBUTION;
+	 }
+	   
+private:
+	   virtual bool GenerateSample(SimpleRay &ray) const;
+};
+
+
+class ViewSpaceBorderBasedDistribution: public SamplingStrategy
+{
+ public:
+	 ViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor):
+	   SamplingStrategy(preprocessor){
 	   mType = SPATIAL_BOX_BASED_DISTRIBUTION;
 	 }
@@ -140,4 +155,18 @@
 	 virtual bool GenerateSample(SimpleRay &ray) const;
 };
+
+
+class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
+{
+ public:
+	 ReverseViewSpaceBorderBasedDistribution(const Preprocessor &preprocessor):
+	   SamplingStrategy(preprocessor){
+	   mType = SPATIAL_BOX_BASED_DISTRIBUTION;
+	 }
+	 
+private:
+	 virtual bool GenerateSample(SimpleRay &ray) const;
+};
+
 
 class RssBasedDistribution: public SamplingStrategy
@@ -159,4 +188,5 @@
   
 };
+
 
 class ViewCellBorderBasedDistribution: public SamplingStrategy
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1771)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1772)
@@ -320,13 +320,12 @@
 	
 	const int numRaysPerPass = samplesPerPass / (int)strategies.size();
-
 	vector<int>::const_iterator iit, iit_end = strategies.end();
 
 	for (iit = strategies.begin(); iit != iit_end; ++ iit)
 	{
-		int stype = *iit;
+		const int stype = *iit;
 		const int newRays = 
 			mPreprocessor->GenerateRays(numRaysPerPass, stype, simpleRays);
-	
+
 		cout << "cast " << newRays << " rays of strategy " << stype << endl;
 		castRays += newRays;
@@ -394,7 +393,16 @@
 	// mix of sampling strategies
 	vector<int> strategies;
-	strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+	
+	if (0)
+	{
+		strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+	}
+	else
+	{
+		strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		//strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+	}
 
 	// cast initial samples
@@ -838,7 +846,6 @@
 	for (; it != it_end; ++it) {
 	  //(*it)->UpdatePvsCost();
-	  (*it)->SetPvsCost((*it)->GetFilteredPvsSize());
-	}
-	
+	  (*it)->SetPvsCost((float)(*it)->GetFilteredPvsSize());
+	}
 
 	float maxPvs, maxVal, minVal;
@@ -989,7 +996,16 @@
 	// mix of sampling strategies
 	vector<int> strategies;
-	strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+	
+	if (0)
+	{
+		strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+	}
+	else
+	{
+		strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+	}
 
 	cout << "finished" << endl;
@@ -5980,8 +5996,17 @@
     // mix of sampling strategies
 	vector<int> strategies;
-	strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
-	strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
-//strategies.push_back(SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION);
+	
+	if (0)
+	{
+		strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+	}
+	else
+	{
+		strategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		strategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+	}
+
 	cout << "reseting pvs ... ";
 		
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1764)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1772)
@@ -262,5 +262,5 @@
 							const float pdf, 
 							float &contribution)
-{ cout << "here15" << endl;
+{ 
 	const bool result = mPvs.AddSample(sample, pdf, contribution);
 	// have to recompute pvs size
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 1768)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 1772)
@@ -182,5 +182,5 @@
 
   Vector3 GetRandomPoint() const;
-
+  Vector3 GetRandomSurfacePoint() const;
 
   Vector3 GetPoint(const Vector3 &p) const {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1765)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1772)
@@ -1411,5 +1411,5 @@
 	}
 	
-//#ifdef GTP_DEBUG
+#ifdef GTP_DEBUG
 	cout << "\n((((( eval local cost )))))" << endl
 		  << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl 
@@ -1417,5 +1417,5 @@
 		  << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl
 		  << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl;
-//#endif
+#endif
 	return ratio;
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h	(revision 863)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Rectangle3.h	(revision 1772)
@@ -15,5 +15,5 @@
   Vector3 mVertices[4];
 
-  Vector3 GetVertex(const int i) const { return mVertices[i]; }
+  inline Vector3 GetVertex(const int i) const { return mVertices[i]; }
   Rectangle3() {}
   
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1768)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1772)
@@ -2286,4 +2286,29 @@
 }
 
-}
-
+
+Vector3 AxisAlignedBox3::GetRandomSurfacePoint() const
+{
+	const int idx = Random(6);
+
+	const Rectangle3 face = GetFace(idx);
+
+	Vector3 point = Vector3(0,0,0);
+	float sum = 0.0f;
+
+	for (int i = 0; i < 4; ++ i) 
+	{
+		const float r = RandomValue(0, 1);
+		sum += r;
+		point += face.mVertices[i] * r;
+	}
+
+	point *= 1.0f / sum;
+
+	//normal = face.GetNormal();
+
+	return point;
+}
+
+
+}
+
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 1769)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 1772)
@@ -422,21 +422,20 @@
 Mesh::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
 {
-  //const int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1));
+	//const int faceIndex = (int)RandomValue(0, (Real)((int)mFaces.size()-1));
 	const int faceIndex = (int)RandomValue(0, (Real)mFaces.size() - 0.5f);
 
-  // assume the face is convex and generate a convex combination
-  //
-  Face *face = mFaces[faceIndex];
- 
-  point = Vector3(0,0,0);
-  float sum = 0.0f;
-  
-  for (int i = 0; i < face->mVertexIndices.size(); i++) {
-    float r = RandomValue(0,1);
-    sum += r;
-    point += mVertices[face->mVertexIndices[i]]*r;
-  }
-  point *= 1.0f/sum;
-	
+	// assume the face is convex and generate a convex combination
+	Face *face = mFaces[faceIndex];
+
+	point = Vector3(0,0,0);
+	float sum = 0.0f;
+
+	for (int i = 0; i < face->mVertexIndices.size(); i++) {
+		float r = RandomValue(0,1);
+		sum += r;
+		point += mVertices[face->mVertexIndices[i]]*r;
+	}
+	point *= 1.0f/sum;
+
 	normal = GetFacePlane(faceIndex).mNormal;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1771)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1772)
@@ -24,13 +24,39 @@
 								  SimpleRayContainer &rays) const
 {
-  SimpleRay ray;
-  int i = 0;
-  for (; i < number; i++) {
-	if (!GenerateSample(ray))
-	  return i;
-	rays.push_back(ray);
-  }
-
-  return i;
+	SimpleRay ray;
+	int samples = 0;
+	int i = 0;
+	const int maxTries = 20;
+	// tmp changed matt. Q: should one rejected sample 
+	// terminate the whole method?
+	if (0)
+	{
+		for (; i < number; i++) {
+			if (!GenerateSample(ray))
+				return i;
+			rays.push_back(ray);
+		}
+	}
+	else
+	{
+		for (; i < number; i++) 
+		{
+			int j = 0;
+			bool sampleGenerated = false;
+
+			for (j = 0; !sampleGenerated && (j < maxTries); ++ j)
+			{
+				sampleGenerated = GenerateSample(ray);
+
+				if (sampleGenerated)
+				{		
+					++ samples;
+					rays.push_back(ray);
+				}
+			}
+		}
+	}
+	
+	return samples;
 }
 
@@ -196,5 +222,5 @@
 	direction *= 1.0f / c;
 	// a little offset
-	point += direction * 0.01f;
+	point += direction * 0.001f;
 
 	ray = SimpleRay(point, direction, pdf);
@@ -279,4 +305,79 @@
 #endif
 
+
+bool ReverseViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const
+{
+	Vector3 origin, direction; 
+
+	origin = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint();
+
+	Vector3 point;
+	Vector3 normal;
+	//cout << "y";
+	const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f);
+
+	Intersectable *object = mPreprocessor.mObjects[i];
+
+	object->GetRandomSurfacePoint(point, normal);
+	
+	direction = origin - point;
+	
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float c = Magnitude(direction);
+	
+	if ((c <= Limits::Small) || (DotProd(direction, normal) < 0))
+	{
+		return false;
+	}
+
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float pdf = 1.0f;
+	//cout << "p: " << point << " ";
+	direction *= 1.0f / c;
+	// a little offset
+	point += direction * 0.001f;
+
+	ray = SimpleRay(point, direction, pdf);
+	
+	return true;
+}
+
+
+bool ViewSpaceBorderBasedDistribution::GenerateSample(SimpleRay &ray) const
+{
+	Vector3 origin, direction; 
+
+	origin = mPreprocessor.mViewCellsManager->GetViewSpaceBox().GetRandomSurfacePoint();
+
+	Vector3 point;
+	Vector3 normal;
+	//cout << "w";
+	const int i = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f);
+
+	Intersectable *object = mPreprocessor.mObjects[i];
+
+	object->GetRandomSurfacePoint(point, normal);
+	direction = point - origin;
+
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float c = Magnitude(direction);
+
+	if (c <= Limits::Small) 
+		return false;
+
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float pdf = 1.0f;
+	
+	direction *= 1.0f / c;
+
+	// a little offset
+	origin += direction * 0.001f;
+
+	ray = SimpleRay(origin, direction, pdf);
+
+	return true;
+}
+
+
 bool
 RssBasedDistribution::GenerateSample(SimpleRay &ray) const
