Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp	(revision 364)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp	(revision 374)
@@ -458,5 +458,5 @@
 void
 X3dViewCellsParseHandlers::StartCoordinate(
-				  AttributeList&  attributes)
+																					 AttributeList&  attributes)
 {
 	int len = attributes.getLength();
@@ -518,8 +518,8 @@
 #ifdef _DEBUG
 		Debug << "Viewcell: " 
-			  << mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " " 
-			  << mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n";
+					<< mesh->mVertices[0] << " " << mesh->mVertices[1] << " " << mesh->mVertices[2] << " " 
+					<< mesh->mVertices[3] << " " << mesh->mVertices[4] << " " << mesh->mVertices[5] << "\n";
 #endif
-	}
+		}
 }
 
@@ -527,5 +527,5 @@
 void
 X3dViewCellsParseHandlers::startElement(const XMLCh* const name,
-			       AttributeList&  attributes)
+																				AttributeList&  attributes)
 {
   StrX lname(name);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 370)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 374)
@@ -29,5 +29,5 @@
   /// front (back) to the back (front)
   enum {FRONT, BACK, BACK_FRONT, FRONT_BACK, COINCIDENT};
-
+	
   struct Intersection {
     // the point of intersection
@@ -63,8 +63,8 @@
 
     BspIntersection(const float t, BspLeaf *l):
-	mT(t), mLeaf(l) {}
-
+			mT(t), mLeaf(l) {}
+		
     BspIntersection() {}
-
+		
     bool operator<(const BspIntersection &b) const {
       return mT	<b.mT; }
@@ -79,10 +79,15 @@
   vector<BspIntersection> bspIntersections;
   vector<KdLeaf *> kdLeaves;
-  vector<MeshInstance *> meshes;
-  
+  vector<Intersectable *> testedObjects;
+
+	// various flags
+	enum {STORE_KDLEAVES=1, STORE_BSP_INTERSECTIONS=2, STORE_TESTED_OBJECTS=4};
+	int mFlags;
+
+	
   // constructors
   Ray(const Vector3 &wherefrom,
       const Vector3 &whichdir,
-      const int _type) {
+      const int _type):mFlags(0) {
     loc = wherefrom;
     if (_type == LINE_SEGMENT)
@@ -92,9 +97,9 @@
     mType = _type;
     depth = 0;
-    Init();
+		Init();
   }
   // dummy constructor
   Ray() {}
-
+	
   Intersectable *GetIntersectionObject(const int i) const {
     return intersections[i].mObject;
@@ -236,7 +241,8 @@
   // to the number of bounces of the ray, also called the depth of the
   // ray (primary ray has its depth zero)
-  int      depth;
-  
-  
+  int depth;
+
+	
+	
   void Init();
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 374)
@@ -1241,7 +1241,7 @@
 
   RegisterOption("BspTree.splitPlaneStrategy",
-		optString,
-		"-bsp_split_method=",
-		"leastSplits");
+								 optString,
+								 "-bsp_split_method=",
+								 "leastSplits");
 
   RegisterOption("BspTree.maxCandidates",
@@ -1259,4 +1259,10 @@
 	  "-bsp_exportSplits",
 	  "false");
+
+  RegisterOption("Preprocessor.type",
+								 optString,
+								 "-preprocessor=",
+								 "sampling");
+	
 }
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 374)
@@ -476,7 +476,7 @@
       float sum;
       if (mSahUseFaces)
-	sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea();
+				sum = intersectionsLeft*lbox.SurfaceArea() + intersectionsRight*rbox.SurfaceArea();
       else
-	sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea();
+				sum = objectsLeft*lbox.SurfaceArea() + objectsRight*rbox.SurfaceArea();
       
       //      cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl;
@@ -484,9 +484,9 @@
       
       if (sum < minSum) {
-	minSum = sum;
-	position = (*ci).value;
-	
-	objectsBack = objectsLeft;
-	objectsFront = objectsRight;
+				minSum = sum;
+				position = (*ci).value;
+				
+				objectsBack = objectsLeft;
+				objectsFront = objectsRight;
       }
     }
@@ -507,6 +507,6 @@
 int
 KdTree::CastRay(
-		Ray &ray
-		)
+								Ray &ray
+								)
 {
   int hits = 0;
@@ -570,39 +570,41 @@
       maxt = tdist;
 	} else {
-      // compute intersection with all objects in this leaf
-      KdLeaf *leaf = (KdLeaf *) node;
-      ray.kdLeaves.push_back(leaf);
-      
-      ObjectContainer::const_iterator mi;
-      for ( mi = leaf->mObjects.begin();
-	    mi != leaf->mObjects.end();
-	    mi++) {
-	Intersectable *object = *mi;
-	if (!object->Mailed() ) {
-	  object->Mail();
-	  //ray.meshes.push_back(mesh);
-	  hits += object->CastRay(ray);
+		// compute intersection with all objects in this leaf
+		KdLeaf *leaf = (KdLeaf *) node;
+		if (ray.mFlags & Ray::STORE_KDLEAVES)
+			ray.kdLeaves.push_back(leaf);
+		
+		ObjectContainer::const_iterator mi;
+		for ( mi = leaf->mObjects.begin();
+					mi != leaf->mObjects.end();
+					mi++) {
+			Intersectable *object = *mi;
+			if (!object->Mailed() ) {
+				object->Mail();
+				if (ray.mFlags & Ray::STORE_TESTED_OBJECTS)
+					ray.testedObjects.push_back(object);
+				hits += object->CastRay(ray);
+			}
+		}
+		
+		if (hits && ray.GetType() == Ray::LOCAL_RAY)
+			if (ray.intersections[0].mT <= maxt)
+				break;
+		
+		// get the next node from the stack
+		if (tStack.empty())
+			break;
+		
+		entp = extp;
+		mint = maxt;
+		if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f)
+			break;
+		
+		RayTraversalData &s  = tStack.top();
+		node = s.mNode;
+		extp = s.mExitPoint;
+		maxt = s.mMaxT;
+		tStack.pop();
 	}
-      }
-
-      if (hits && ray.GetType() == Ray::LOCAL_RAY)
-	if (ray.intersections[0].mT <= maxt)
-	  break;
-      
-      // get the next node from the stack
-      if (tStack.empty())
-	break;
-      
-      entp = extp;
-      mint = maxt;
-      if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f)
-	break;
-      
-      RayTraversalData &s  = tStack.top();
-      node = s.mNode;
-      extp = s.mExitPoint;
-      maxt = s.mMaxT;
-      tStack.pop();
-    }
   }
   
@@ -624,9 +626,9 @@
       KdLeaf *leaf = (KdLeaf *)node;
       for (int j=0; j < leaf->mObjects.size(); j++) {
-	Intersectable *object = leaf->mObjects[j];
-	if (!object->Mailed()) {
-	  object->Mail();
-	  objects.push_back(object);
-	}
+				Intersectable *object = leaf->mObjects[j];
+				if (!object->Mailed()) {
+					object->Mail();
+					objects.push_back(object);
+				}
       }
     } else {
@@ -699,13 +701,13 @@
       KdInterior *interior = (KdInterior *)node;
       if (interior->mPosition > box.Max(interior->mAxis))
-	nodeStack.push(interior->mBack);
+				nodeStack.push(interior->mBack);
       else
-	if (interior->mPosition < box.Min(interior->mAxis))
-	  nodeStack.push(interior->mFront);
-	else {
-	  // random decision
-	    nodeStack.push(interior->mBack);
-	    nodeStack.push(interior->mFront);
-	}
+				if (interior->mPosition < box.Min(interior->mAxis))
+					nodeStack.push(interior->mFront);
+				else {
+					// random decision
+					nodeStack.push(interior->mBack);
+					nodeStack.push(interior->mFront);
+				}
     }
   }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 373)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 374)
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ExactPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ExactPreprocessor.h	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ExactPreprocessor.h	(revision 374)
@@ -9,4 +9,7 @@
   public:
     virtual bool ComputeVisibility();
+
+		virtual bool BuildBspTree() { return false; }
+
   };
   
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Statistics.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Statistics.h	(revision 374)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Statistics.h	(revision 374)
@@ -0,0 +1,41 @@
+#ifndef __STATISTICS_H
+#define __STATISTICS_H
+
+
+#include "common.h"
+
+// --------------------------------------------------------------
+// Statistics for search - base class
+// --------------------------------------------------------------
+class StatisticsBase
+{
+public:
+	
+  // return time diff. in s
+  static inline double TimeDiff(long time1, long time2) // in s
+  {
+    const double clk=1.0E-6; // ticks per second
+    long t=time2-time1;
+		
+    return ((t<0)?-t:t)*clk;
+  }
+	
+public:
+  long startTime;
+  long stopTime;
+  
+  void Start() {
+    startTime = GetTime();
+  }
+
+  void Stop() {
+    stopTime = GetTime();
+  }
+
+  float Time() const {
+    return TimeDiff(startTime, stopTime);
+  }
+};
+
+
+#endif
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 374)
@@ -28,13 +28,14 @@
 VssPreprocessor::SetupRay(Ray &ray, 
 													const Vector3 &point, 
-													const Vector3 &direction,
-													const int type)
+													const Vector3 &direction
+													)
 {
   ray.intersections.clear();
-  ray.kdLeaves.clear();
-  ray.meshes.clear();
-
+	// do not store anything else then intersections at the ray
+	ray.kdLeaves.clear();
+	ray.mFlags = Ray::STORE_KDLEAVES;
+	
   //  cout<<point<<" "<<direction<<endl;
-  ray.Init(point, direction, type);
+  ray.Init(point, direction, Ray::LOCAL_RAY);
 }
 
@@ -51,7 +52,7 @@
 int
 VssPreprocessor::AddNodeSamples(const Ray &ray,
-																		 Intersectable *sObject,
-																		 Intersectable *tObject
-																		 )
+																Intersectable *sObject,
+																Intersectable *tObject
+																)
 {
   int contributingSamples = 0;
@@ -62,5 +63,5 @@
 	if (tObject)
 		objects++;
-
+	
 	if (objects) {
 		for (j=0; j < ray.kdLeaves.size(); j++) {
@@ -123,32 +124,6 @@
 	KdNode *nodeToSample = NULL;
 	
-	bool samplePvsBoundary = false;
-	if (pvsSize && samplePvsBoundary) {
-		// this samples the nodes from the boundary of the current PVS
-		// mail all nodes from the pvs
-		Intersectable::NewMail();
-		KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();
-		
-		for (; i != object->mKdPvs.mEntries.end(); i++) {
-			KdNode *node = (*i).first;
-			node->Mail();
-		}
-		
-		int maxTries = 2*pvsSize;
-		Debug << "Finding random neighbour" << endl;	
-		for (int tries = 0; tries < 10; tries++) {
-			int index = RandomValue(0, pvsSize - 1);
-			KdPvsData data;
-			KdNode *node;
-			object->mKdPvs.GetData(index, node, data);
-			nodeToSample = mKdTree->FindRandomNeighbor(node, true);
-			if (nodeToSample)
-				break;
-		}
-	} else {
-		// just pickup a random node
-		//		nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point));
-		nodeToSample = mKdTree->GetRandomLeaf();
-	}
+	// just pickup a random node
+	nodeToSample = mKdTree->GetRandomLeaf();
 	return nodeToSample;
 }
@@ -229,5 +204,5 @@
 					
 					// construct a ray
-					SetupRay(ray, point, direction, Ray::LOCAL_RAY);
+					SetupRay(ray, point, direction);
 					
 					sampleContributions = CastRay(reverseSample ? NULL : object, ray);
@@ -298,9 +273,7 @@
 	}
 	
-	if (ViewCell::sHierarchy == ViewCell::KD)	
-		cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
-  
-	
-  //  HoleSamplingPass();
+	cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
+  
+	
 	if (0) {
 		Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 374)
@@ -1,3 +1,4 @@
 #include "SamplingPreprocessor.h"
+#include "VssPreprocessor.h"
 #include "ExactPreprocessor.h"
 #include "Parser.h"
@@ -24,8 +25,27 @@
   BspTree::ParseEnvironment();
 
-  Preprocessor *p =
-    new SamplingPreprocessor();
+	char buff[128];
 
-  char buff[128];
+	environment->GetStringValue("Preprocessor.type", buff);
+
+	string preprocessorType(buff);
+	
+  Preprocessor *p;
+
+	if (preprocessorType == "vss")
+		p = new VssPreprocessor();
+	else
+		if (preprocessorType == "exact")
+			p = new ExactPreprocessor();
+		else
+			if (preprocessorType == "sampling")
+				p = new SamplingPreprocessor();
+			else {
+				cerr<<"Unknown preprocessor type"<<endl;
+				Debug<<"Unknown preprocessor type"<<endl;
+				exit(1);
+			}
+	
+
   environment->GetStringValue("Scene.filename", buff);
   string filename(buff);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 370)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 374)
@@ -12,6 +12,11 @@
 # filename ../data/vienna/viewcells-25-sel.x3d
 # filename ../data/atlanta/atlanta2.x3d
-#	filename ../data/soda/soda.dat
-filename ../data/soda/soda5.dat
+	filename ../data/soda/soda.dat
+# filename ../data/soda/soda5.dat
+}
+
+Preprocessor {
+#	type sampling
+	type vss
 }
 
@@ -61,6 +66,6 @@
 
 ViewCells {
-	#hierarchy kdTree
-	hierarchy bspTree
+	hierarchy kdTree
+	#hierarchy bspTree
 	# hierarchy sceneDependent
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 373)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 374)
@@ -33,7 +33,7 @@
   ray.intersections.clear();
   ray.kdLeaves.clear();
-  ray.meshes.clear();
+  ray.testedObjects.clear();
   ray.bspIntersections.clear();
-
+	ray.mFlags |= Ray::STORE_KDLEAVES | Ray::STORE_BSP_INTERSECTIONS;
   //  cout<<point<<" "<<direction<<endl;
   ray.Init(point, direction, type);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 374)
@@ -29,7 +29,7 @@
   void
   SetupRay(Ray &ray, 
-		   const Vector3 &point, 
-		   const Vector3 &direction,
-		   const int type);
+					 const Vector3 &point, 
+					 const Vector3 &direction
+					 );
 
   KdNode *
@@ -49,4 +49,6 @@
 	GetNodeToSample(Intersectable *object);
 
+	virtual bool BuildBspTree() { return false; }
+
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 370)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 374)
@@ -109,6 +109,6 @@
 	  exporter->ExportBox(tree->GetBox(ray->kdLeaves[i]));
 	if (0)
-	for (i= 0; i < ray->meshes.size(); i++)
-	  exporter->ExportIntersectable(ray->meshes[i]);
+		for (i= 0; i < ray->testedObjects.size(); i++)
+			exporter->ExportIntersectable(ray->testedObjects[i]);
 
       }
@@ -131,5 +131,5 @@
   ray.intersections.clear();
   ray.kdLeaves.clear();
-  ray.meshes.clear();
+  ray.testedObjects.clear();
   ray.bspIntersections.clear();
 
