Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 361)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 370)
@@ -347,4 +347,7 @@
 			</File>
 		</Filter>
+		<File
+			RelativePath=".\VTune\Preprocessor.vpj">
+		</File>
 	</Files>
 	<Globals>
Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 367)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 370)
@@ -56,5 +56,5 @@
 
 Sampling {
-	totalSamples	300000
+	totalSamples	1000000
 	samplesPerPass  3
 }
@@ -82,5 +82,5 @@
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 10000
+		samples 200000
 		sideTolerance 0.005
 	}
@@ -120,5 +120,5 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 1024
+	splitPlaneStrategy 130
 	
 	maxCandidates 80
@@ -128,11 +128,11 @@
 		maxRays 200
 		maxPolygons 5
-		maxDepth 100
+		maxDepth 50
 		
 		# axis aligned splits
 		AxisAligned {
 			maxPolys 5000
-			maxRays 5000
-			maxObjects 2000
+			maxRays 600
+			maxObjects 20
 			maxCostRatio 0.9
 			ct_div_ci 0.5
@@ -145,5 +145,5 @@
 	
 	PostProcessing {
-		samples 100000
+		samples 200000
 	}
 		
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 369)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 370)
@@ -56,4 +56,18 @@
   };
 
+  struct BspIntersection {
+    // the point of intersection
+    float mT;
+
+    BspLeaf *mLeaf;
+
+    BspIntersection(const float t, BspLeaf *l):
+	mT(t), mLeaf(l) {}
+
+    BspIntersection() {}
+
+    bool operator<(const BspIntersection &b) const {
+      return mT	<b.mT; }
+  };
 
   // I should have some abstract cell data type !!! here
@@ -63,5 +77,5 @@
   
   vector<Intersection> intersections;
-  vector<BspLeaf *> bspLeaves;
+  vector<BspIntersection> bspIntersections;
   vector<KdLeaf *> kdLeaves;
   vector<MeshInstance *> meshes;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 367)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 370)
@@ -321,5 +321,6 @@
 		}
 
-		ray->bspLeaves.push_back(this);
+		// warning: not ordered
+		ray->bspIntersections.push_back(Ray::BspIntersection((*it)->mMinT, this));
 	}
 }
@@ -1621,5 +1622,5 @@
 			if (!leaf->mViewCell->Mailed())
 			{
-				ray.bspLeaves.push_back(leaf);
+				ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf));
 				leaf->mViewCell->Mail();
 				++ hits;
@@ -2299,5 +2300,5 @@
 
 	BoundedRayContainer::const_iterator rit, rit_end = rays.end();
-	vector<BspLeaf *>::const_iterator lit;
+	vector<Ray::BspIntersection>::const_iterator iit;
 
 	ViewCell::NewMail();
@@ -2307,9 +2308,11 @@
 		Ray *ray = (*rit)->mRay;
 		
-		for (lit = ray->bspLeaves.begin(); lit != ray->bspLeaves.end(); ++ lit)
-		{
-			if ((*lit)->mViewCell->Mailed())
+		for (iit = ray->bspIntersections.begin(); iit != ray->bspIntersections.end(); ++ iit)
+		{
+			BspViewCell *vc = (*iit).mLeaf->mViewCell;
+
+			if (vc->Mailed())
 			{
-				pvsSize += (*lit)->mViewCell->GetPvs().GetSize();
+				pvsSize += vc->GetPvs().GetSize();
 			}
 		}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 369)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 370)
@@ -61,10 +61,13 @@
 
 ViewCells {
-	hierarchy kdTree
-	#hierarchy bspTree
+	#hierarchy kdTree
+	hierarchy bspTree
 	# hierarchy sceneDependent
 	
 	height 5.0
 	maxViewCells 0
+	
+	minPvsDif 100
+#	maxPvsSize 200
 	
 #	filename ../data/atlanta/atlanta_viewcells_large.x3d
@@ -74,7 +77,4 @@
 }
 
-
-
-
 BspTree {
 	Construction {
@@ -82,5 +82,5 @@
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 100000
+		samples 10000
 		sideTolerance 0.005
 	}
@@ -97,4 +97,5 @@
 	# least ray splits     = 256
 	# balanced rays        = 512
+	# pvs                  = 1024
 
 	# least splits + balanced polygons
@@ -119,19 +120,19 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 130
+	splitPlaneStrategy 1024
 	
 	maxCandidates 80
 	
 	Termination {
-	# autopartition
-		maxRays 80
-		maxPolygons 0
+		# autopartition
+		maxRays 200
+		maxPolygons 5
 		maxDepth 100
 		
 		# axis aligned splits
 		AxisAligned {
-			maxPolys 500
-			maxRays 300
-			maxObjects 20
+			maxPolys 5000
+			maxRays 5000
+			maxObjects 2000
 			maxCostRatio 0.9
 			ct_div_ci 0.5
@@ -142,4 +143,8 @@
 		splitBorder 0.01
 	}
+	
+	PostProcessing {
+		samples 100000
+	}
 		
 	# if split polys are stored for visualization
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 369)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 370)
@@ -34,5 +34,5 @@
   ray.kdLeaves.clear();
   ray.meshes.clear();
-  ray.bspLeaves.clear();
+  ray.bspIntersections.clear();
 
   //  cout<<point<<" "<<direction<<endl;
@@ -124,16 +124,18 @@
  
 	// object can be seen from the view cell => add to view cell pvs
-	for (j=0; j < ray.bspLeaves.size(); ++ j) 
-	{ 	// if ray not in unbounded space
-		if (ray.bspLeaves[j]->GetViewCell() != &mUnbounded)
+	for (j=0; j < ray.bspIntersections.size(); ++ j)
+	{ 	
+		BspLeaf *leaf = ray.bspIntersections[j].mLeaf;
+		// if ray not in unbounded space
+		if (leaf->GetViewCell() != &mUnbounded)
 			contributingSamples += 
-				ray.bspLeaves[j]->GetViewCell()->GetPvs().AddSample(obj);
+				leaf->GetViewCell()->GetPvs().AddSample(obj);
 	}
  
 	// rays passing through this viewcell
 	if (mPass > 1)
-		for (j=1; j < ((int)ray.bspLeaves.size() - 1); ++ j) 
-		{
-			BspLeaf *leaf = ray.bspLeaves[j];
+		for (j=1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 
+		{
+			BspLeaf *leaf = ray.bspIntersections[j].mLeaf;
 
 			if (leaf->GetViewCell() != &mUnbounded)
@@ -679,5 +681,5 @@
 	int merged = 0;
 	RayContainer::const_iterator rit, rit_end = rays.end();
-	vector<BspLeaf *>::const_iterator lit;
+	vector<Ray::BspIntersection>::const_iterator iit;
 
 	for (rit = rays.begin(); rit != rays.end(); ++ rit)
@@ -685,15 +687,15 @@
 		// traverse leaves stored in the rays and compare and merge consecutive
 		// leaves (i.e., the neighbors in the tree)
-		if ((*rit)->bspLeaves.empty())
+		if ((*rit)->bspIntersections.empty())
 			continue;
 
-		lit = (*rit)->bspLeaves.begin();
-
-		BspLeaf *previousLeaf = *lit;
-		++ lit;
-		
-		for (; lit != (*rit)->bspLeaves.end(); ++ lit)
-		{
-			BspLeaf *leaf = *lit;
+		iit = (*rit)->bspIntersections.begin();
+
+		BspLeaf *previousLeaf = (*iit).mLeaf;
+		++ iit;
+		
+		for (; iit != (*rit)->bspIntersections.end(); ++ iit)
+		{
+			BspLeaf *leaf = (*iit).mLeaf;
 
 			if (mBspTree->ShouldMerge(leaf, previousLeaf))
@@ -784,9 +786,11 @@
 		Ray *ray = mSampleRays[k];
 
-		for (int j = 0; j < (int)ray->bspLeaves.size(); ++ j)
-		{
+		for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j)
+		{
+			BspLeaf *leaf = ray->bspIntersections[j].mLeaf;
+
 			for (int i = 0; i < (int)bspLeaves.size(); ++ i)
 			{
-				if (bspLeaves[i]->GetViewCell() == ray->bspLeaves[j]->GetViewCell()) 
+				if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 
 				{
 					vcRays[i].push_back(*ray);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 362)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 370)
@@ -132,5 +132,5 @@
   ray.kdLeaves.clear();
   ray.meshes.clear();
-  ray.bspLeaves.clear();
+  ray.bspIntersections.clear();
 
   ray.Init(mPosition, target, Ray::LOCAL_RAY);
