Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 397)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 399)
@@ -56,5 +56,5 @@
 
 Sampling {
-	totalSamples	250000
+	totalSamples	100000
 	samplesPerPass  3
 }
@@ -88,5 +88,5 @@
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 100000
+		samples 50000
 		sideTolerance 0.005
 	}
@@ -126,7 +126,7 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 1024
+	splitPlaneStrategy 8
 	
-	maxPolyCandidates 200
+	maxPolyCandidates 50
 	maxRayCandidates 0
 	
@@ -134,7 +134,7 @@
 		# autopartition
 		maxRays 200
-		maxPolygons 5
+		maxPolygons 20
 		maxDepth 30
-		minPvs 50
+		minPvs -1
 		minArea -0.001
 		
@@ -158,5 +158,5 @@
 		exportSplits true
 		# how much samples should be used in visualization
-		samples 1000
+		samples 100000
 	}
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 397)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 399)
@@ -730,5 +730,5 @@
 	/** Computes the pvs of the front and back leaf with a given classification.
 	*/
-	void AddToPvs(Intersectable &obj, 
+	void IncPvs(Intersectable &obj, 
 				  int &frontPvs,
 				  int &backPvs,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 398)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 399)
@@ -274,5 +274,6 @@
 		}
 
-		contribution += mViewCell->GetPvs().AddSample(ray->sourceObject.mObject);
+		if (ray->sourceObject.mObject)
+			contribution += mViewCell->GetPvs().AddSample(ray->sourceObject.mObject);
 
 		if (contribution > 0)
@@ -281,6 +282,5 @@
 			++ contributingSamples;
 		}
-
-		// warning: not ordered
+		// warning: intersections not ordered
 		ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this));
 	}
@@ -1392,11 +1392,14 @@
 				// assure that we only count a object 
 				// once for the front and once for the back side of the plane
-				AddToPvs(*ray->intersections[0].mObject, frontData.mPvs, backData.mPvs, 
-						 cf, frontId, backId, frontAndBackId);
+				IncPvs(*ray->intersections[0].mObject, frontData.mPvs, backData.mPvs, 
+					   cf, frontId, backId, frontAndBackId);
 			}
 
 			// the source object in the origin of the ray
-			AddToPvs(*ray->sourceObject.mObject, frontData.mPvs, backData.mPvs, 
-					 cf, frontId, backId, frontAndBackId);
+			if (ray->sourceObject.mObject)
+			{
+				IncPvs(*ray->sourceObject.mObject, frontData.mPvs, backData.mPvs, 
+					   cf, frontId, backId, frontAndBackId);
+			}
 
 			// use #rays to approximate volume
@@ -1429,11 +1432,11 @@
 }
 
-void BspTree::AddToPvs(Intersectable &obj,
-					   int &frontPvs,
-					   int &backPvs,
-					   const int cf, 
-					   const int frontId, 
-					   const int backId, 
-					   const int frontAndBackId) const
+void BspTree::IncPvs(Intersectable &obj,
+					 int &frontPvs,
+					 int &backPvs,
+					 const int cf, 
+					 const int frontId, 
+					 const int backId, 
+					 const int frontAndBackId) const
 {
 	if (cf == Ray::COINCIDENT) //TODO: really belongs to no pvs?
@@ -2311,8 +2314,11 @@
 			}
 		}
-		if (!ray->sourceObject.mObject->Mailed())
-		{
-			ray->sourceObject.mObject->Mail();
-			++ pvsSize;
+		if (ray->sourceObject.mObject)
+		{
+			if (!ray->sourceObject.mObject->Mailed())
+			{
+				ray->sourceObject.mObject->Mail();
+				++ pvsSize;
+			}
 		}
 	}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 396)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 399)
@@ -192,8 +192,8 @@
 			
 			if (!ray.intersections.empty()) // second intersection found
-				{
-					sampleContributions += 
-						AddObjectSamples(ray.intersections[0].mObject, ray);
-				}
+			{
+				sampleContributions += 
+					AddObjectSamples(ray.intersections[0].mObject, ray);
+			}
 		}
 	}
@@ -475,5 +475,5 @@
 					{
 						ProcessBspViewCells(ray,
-											object,
+											reverseSample ? NULL : object,
 											faceIndex,
 											passContributingSamples,
@@ -907,5 +907,5 @@
 
 			// export rays piercing this view cell
-			exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0));
+			exporter->ExportRays(vcRays[i], 10000, RgbColor(0, 1, 0));
 
 			m.mDiffuseColor = RgbColor(1, 0, 0);
@@ -981,8 +981,5 @@
 
 			Exporter *exporter = Exporter::GetExporter(s);
-			exporter->SetFilled();
-
-			ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin();
-
+			
 			exporter->SetFilled();//Wireframe();
 
@@ -1002,19 +999,28 @@
 			}
 
-			Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() << endl;
+			
+			Debug << i << ": pvs size=" << (int)vc->GetPvs().GetSize() 
+					<< ", piercing rays=" << (int)vcRays[i].size() << endl;
 
 			
 			// export rays piercing this view cell
-			exporter->ExportRays(vcRays[i], 10000, RgbColor(0, 1, 0));
-
+			exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0));
+	
 			m.mDiffuseColor = RgbColor(1, 0, 0);
 			exporter->SetForcedMaterial(m);
 
+			ViewCellPvsMap::const_iterator it,
+				it_end = vc->GetPvs().mEntries.end();
+
 			// output PVS of view cell
-			for (; it != vc->GetPvs().mEntries.end(); ++ it) 
+			for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it) 
 			{
 				Intersectable *intersect = (*it).first;
 				if (!intersect->Mailed())
 				{
+					Material m = RandomMaterial();
+			
+					exporter->SetForcedMaterial(m);
+
 					exporter->ExportIntersectable(intersect);
 					intersect->Mail();
