Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 491)
@@ -13,7 +13,7 @@
 #;../data/vienna/vienna-plane.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
-#	filename ../data/atlanta/atlanta2.x3d
+	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
-	filename ../data/soda/soda5.dat
+#	filename ../data/soda/soda5.dat
 }
 
@@ -28,10 +28,10 @@
 VssPreprocessor {
 	samplesPerPass  100000
-	initialSamples 5000000
+	initialSamples 1000000
 	vssSamples 200000
 	vssSamplesPerPass 100000
 	useImportanceSampling true
-	loadInitialSamples  false
-	storeInitialSamples true
+	loadInitialSamples  true
+	storeInitialSamples false
 }
 
@@ -152,5 +152,5 @@
 	loadFromFile false
 	#type kdTree
-	#type vspKdTree
+	type vspKdTree
 	#type bspTree
 	type vspBspTree
@@ -159,6 +159,6 @@
 	
 	height 5.0
-	maxViewCells 100
-	maxPvs 90
+	maxViewCells 500
+	maxPvs 200
 	
 	
@@ -178,5 +178,5 @@
 		#colorCode MergedTreeDiff
 		colorCode Random
-		exportRays true
+		exportRays false
 		exportGeometry true
 	}
@@ -208,5 +208,5 @@
 		minPvs			50
 		minRays			300
-		minSize			0.1
+		minSize			0.001
 		maxCostRatio		0.9
 		missTolerance		4
@@ -266,15 +266,16 @@
 	Termination {
 		# parameters used for autopartition
-		minRays 		1
+		minRays 		20
 		minPolygons 		-1
 		maxDepth		30
 		minPvs 			20
-		minArea 		0.0001
+		#minArea 		0.0001
+		#minArea 		0.000
 		maxRayContribution	0.005
 		maxCostRatio		0.9
-		missTolerance		2
+		missTolerance		4
 		#maxAccRayLength	100
 		
-		maxViewCells		1000
+		maxViewCells		5000
 		
 		# used for pvs criterium
@@ -291,7 +292,7 @@
 	PostProcess {
 		maxCostRatio 0.1
-		minViewCells 200
-		maxPvsSize   500
-		useRaysForMerge false
+		minViewCells 500
+		maxPvsSize   1000
+		useRaysForMerge true
 	}
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 489)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 491)
@@ -421,5 +421,6 @@
 	*/
 	float SelectAxisAlignedPlane(Plane3 &plane, 
-								 const VspBspTraversalData &tData);
+								 const VspBspTraversalData &tData,
+								 int &bestAxis);
 
 	/** Sorts split candidates for surface area heuristics for axis aligned splits.
@@ -438,6 +439,17 @@
 								  float &position);
 
+	/** Evaluates cost ratio for axis aligned splits.
+	*/
+	float EvalCostRatio(const VspBspTraversalData &tData,
+						const AxisAlignedBox3 &box,
+						const int axis,
+						const float position,
+						int &raysBack,
+						int &raysFront,
+						int &pvsBack,
+						int &pvsFront);
+
 	/** Selects an axis aligned split plane.
-		Returns true if split is valied
+		@Returns true if split is valied
 	*/
 	bool SelectAxisAlignedPlane(Plane3 &plane, const PolygonContainer &polys) const;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 491)
@@ -831,4 +831,5 @@
 	return  (mCtDivCi + newCost) / oldCost;
 }
+
 
 float VspKdTree::BestCostRatioRegular(VspKdLeaf *leaf,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 491)
@@ -93,5 +93,6 @@
 	int nodes;
 	// number of splits
-	int splits;
+	int splits[3];
+	
 	// totals number of rays
 	int rays;
@@ -129,4 +130,6 @@
 	/// number of invalid leaves
 	int invalidLeaves;
+	/// polygon splits 
+	int polySplits;
 
 	// Constructor
@@ -146,5 +149,6 @@
 	{
 		nodes = 0;
-		splits = 0;
+		for (int i = 0; i < 3; ++ i)
+			splits[i] = 0;
 		
 		maxDepth = 0;
@@ -165,4 +169,5 @@
 		maxPvs = 0;
 		invalidLeaves = 0;
+		polySplits = 0;
 	}
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 491)
@@ -34,4 +34,42 @@
 
 float BspMergeCandidate::sOverallCost = 0;
+
+
+/// Adds object to the pvs of the front and back node
+inline void AddObject2Pvs(Intersectable *object,
+						  const int side,
+						  int &pvsBack,
+						  int &pvsFront)
+{
+	if (!object)
+		return;
+
+	if (side <= 0)
+	{
+		if (!object->Mailed() && !object->Mailed(2))
+		{
+			++ pvsBack;
+
+			if (object->Mailed(1))
+				object->Mail(2);
+			else
+				object->Mail();
+		}
+	}
+
+	if (side >= 0)
+	{
+		if (!object->Mailed(1) && !object->Mailed(2))
+		{
+			++ pvsFront;
+
+			if (object->Mailed())
+				object->Mail(2);
+			else
+				object->Mail(1);
+		}
+	}
+}
+
 
 /****************************************************************/
@@ -509,9 +547,9 @@
 
 	// subdivide polygons
-	mStat.splits += SplitPolygons(interior->GetPlane(),
-								  *tData.mPolygons,
-		                          *frontData.mPolygons,
-								  *backData.mPolygons,
-								  coincident);
+	SplitPolygons(interior->GetPlane(),
+				  *tData.mPolygons,
+	              *frontData.mPolygons,
+				  *backData.mPolygons,
+				  coincident);
 
 
@@ -755,5 +793,6 @@
 
 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane,
-										 const VspBspTraversalData &tData)
+										 const VspBspTraversalData &tData,
+										 int &bestAxis)
 {
 	AxisAlignedBox3 box;
@@ -771,5 +810,5 @@
 	float nPosition[3];
 	float nCostRatio[3];
-	int bestAxis = -1;
+	bestAxis = -1;
 
 	const int sAxis = box.Size().DrivingAxis();
@@ -815,7 +854,124 @@
 	Vector3 normal(0,0,0); normal[bestAxis] = 1;
 	plane = Plane3(normal, nPosition[bestAxis]);
-
+	
 	return nCostRatio[bestAxis];
 }
+
+
+float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData,
+								const AxisAlignedBox3 &box,
+								const int axis,
+								const float position,
+								int &raysBack,
+								int &raysFront,
+								int &pvsBack,
+								int &pvsFront)
+{
+	raysBack = 0;
+	raysFront = 0;
+	pvsFront = 0;
+	pvsBack = 0;
+
+	Intersectable::NewMail(3);
+
+	// eval pvs size
+	const int pvsSize = tData.mPvs;
+
+	// create unique ids for pvs heuristics
+	GenerateUniqueIdsForPvs();
+
+	// this is the main ray classification loop!
+	for(RayInfoContainer::iterator ri = tData.mRays->begin();
+			ri != tData.mRays->end(); ++ ri)
+	{
+		if (!(*ri).mRay->IsActive())
+			continue;
+
+		// determine the side of this ray with respect to the plane
+		float t;
+		int side = (*ri).ComputeRayIntersection(axis, position, t);
+			
+		if (side <= 0)
+			++ raysBack;
+
+		if (side >= 0)
+			++ raysFront;
+
+		AddObjToPvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront);
+	}
+
+	//-- only one of these options should be one
+
+	if (0) //-- only pvs
+	{
+		const float sum = float(pvsBack + pvsFront);
+		const float oldCost = (float)pvsSize;
+
+		return sum / oldCost;
+	}
+
+	//-- pvs + probability heuristics
+	float pBack, pFront, pOverall;
+
+	if (0)
+	{
+		// box length substitute for probability
+		const float minBox = box.Min(axis);
+		const float maxBox = box.Max(axis);
+
+		pBack = position - minBox;
+		pFront = maxBox - position;
+		pOverall = maxBox - minBox;
+	}
+
+	if (1) //-- area substitute for probability
+	{
+		
+		const bool useMidSplit = true;
+		//const bool useMidSplit = false;
+			
+		pOverall = box.SurfaceArea();
+			
+		if (!useMidSplit)
+		{
+			Vector3 pos = box.Max(); pos[axis] = position;
+			pBack = AxisAlignedBox3(box.Min(), pos).SurfaceArea();
+
+			pos = box.Min(); pos[axis] = position;
+			pFront = AxisAlignedBox3(pos, box.Max()).SurfaceArea();
+		}
+		else
+		{
+			//-- simplified computation for mid split
+			const int axis2 = (axis + 1) % 3;
+			const int axis3 = (axis + 2) % 3;
+
+			const float faceArea = 
+				(box.Max(axis2) - box.Min(axis2)) *
+				(box.Max(axis3) - box.Min(axis3));
+
+			pBack = pFront = pOverall * 0.5f + faceArea;
+		}
+	}
+
+	//-- ray density substitute for probability
+	if (0)
+	{
+		pBack = (float)raysBack;
+		pFront = (float)raysFront;
+		pOverall = (float)tData.mRays->size();
+	}
+
+	//Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl;
+	//Debug << pFront << " " << pBack << " " << pOverall << endl;
+
+	// float sum = raysBack*(position - minBox) + raysFront*(maxBox - position);
+	const float newCost = pvsBack * pBack + pvsFront * pFront;
+	//  float oldCost = leaf->mRays.size();
+	const float oldCost = (float)pvsSize * pOverall;
+
+	return  (mCtDivCi + newCost) / oldCost;
+}
+
 
 
@@ -835,21 +991,4 @@
 			return true;
 		}
-		else
-		{
-			//-- choose plane on midpoint of a ray
-			const int candidateIdx = (int)RandomValue(0, (Real)((int)data.mRays->size() - 1));
-
-			const Vector3 minPt = (*data.mRays)[candidateIdx].ExtrapOrigin();
-			const Vector3 maxPt = (*data.mRays)[candidateIdx].ExtrapTermination();
-
-			const Vector3 pt = (maxPt + minPt) * 0.5;
-
-			const Vector3 normal = (*data.mRays)[candidateIdx].mRay->GetDir();
-
-			plane = Plane3(normal, pt);
-			return true;
-		}
-
-		return false;
 	}
 
@@ -938,4 +1077,5 @@
 	// intermediate plane
 	Plane3 plane;
+	bool useAxisAlignedPlane = false;
 
 	const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates);
@@ -967,25 +1107,17 @@
 	}
 
-#if 0
-	//-- choose candidate planes extracted from rays
-	//-- different methods are available
-	for (int i = 0; i < mMaxRayCandidates; ++ i)
-	{
-		plane = ChooseCandidatePlane3(*data.mRays);
-		candidateCost = SplitPlaneCost(plane, data);
-
-		if (candidateCost < lowestCost)
-		{
-			bestPlane = plane;
-			lowestCost = candidateCost;
-		}
-	}
-#endif
-
-	// axis aligned splits
-	candidateCost = SelectAxisAlignedPlane(plane, data);
+	//-- axis aligned splits
+	int axis;
+	candidateCost = SelectAxisAlignedPlane(plane, data, axis);
 
 	if (candidateCost < lowestCost)
-	{
+	{	
+		if (!useAxisAlignedPlane)
+		{
+			useAxisAlignedPlane = true;
+			//! error also computed if cost ratio is missed
+			++ mStat.splits[axis];
+		}
+
 		bestPlane = plane;
 		lowestCost = candidateCost;
@@ -1031,6 +1163,8 @@
 	if (mSplitPlaneStrategy & PVS)
 	{
+// matt: change back!!
+Intersectable::NewMail(3);
 		// create unique ids for pvs heuristics
-		GenerateUniqueIdsForPvs();
+		//GenerateUniqueIdsForPvs();
 
 		if (mPvsUseArea) // use front and back cell areas to approximate volume
@@ -1056,5 +1190,5 @@
 	bool useRand;
 
-	// choose test polyongs randomly if over threshold
+	// choose test rays randomly if too much
 	if ((int)data.mRays->size() > mMaxTests)
 	{
@@ -1095,48 +1229,18 @@
 
 			// add the termination object
-			AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs);
+			//AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs);
+			AddObject2Pvs(ray->mTerminationObject, cf, frontPvs, backPvs);
 			// add the source object
-			AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs);
-
-			// use number or length of rays to approximate volume
+			//AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs);
+
+			// use number of rays to approximate volume
 			if (!mPvsUseArea)
 			{
-				float len = 1;
-
-				if (pvsUseLen) // use length of rays
-					len = rayInf.SqrSegmentLength();
-
-				pOverall += len;
-
-				if (cf == 1)
-					pFront += len;
-				else if (cf == -1)
-					pBack += len;
-				else if (cf == 0)
-				{
-					// use length of rays to approximate volume
-					if (pvsUseLen)
-					{
-						float newLen = len *
-							(rayInf.GetMaxT() - t) /
-							(rayInf.GetMaxT() - rayInf.GetMinT());
-
-						if (candidatePlane.Side(rayInf.ExtrapOrigin()) <= 0)
-						{
-							pBack += newLen;
-							pFront += len - newLen;
-						}
-						else
-						{
-							pFront += newLen;
-							pBack += len - newLen;
-						}
-					}
-					else
-					{
-						++ pFront;
-						++ pBack;
-					}
-				}
+				++ pOverall;
+
+				if (cf >= 0)
+					++ pFront;
+				if (cf <= 0)
+					++ pBack;
 			}
 		}
@@ -1215,4 +1319,5 @@
 	}
 }
+
 
 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 491)
@@ -314,7 +314,5 @@
 		polys.pop_back();
 
-		//Debug << "New polygon with plane: " << poly->GetSupportingPlane() << "\n";
-
-		// classify polygon
+		//-- classify polygon
 		const int cf = poly->ClassifyPlane(plane, mEpsilon);
 
@@ -387,5 +385,13 @@
 	app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n";
 
-	app << "#N_SPLITS ( Number of splits )\n" << splits << "\n";
+	app << "#N_POLYSPLITS ( Number of polygon splits )\n" << polySplits << "\n";
+
+	app << "#AXIS_ALIGNED_SPLITS (number of axis aligned splits)\n" << splits[0] + splits[1] + splits[2] << endl;
+
+	app << "#N_SPLITS ( Number of splits in axes x y z\n";
+
+	for (int i = 0; i < 3; ++ i)
+		app << splits[i] << " ";
+	app << endl;
 
 	app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n" 
@@ -420,5 +426,5 @@
 
 	app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" <<
-		 (polys + splits) / (double)polys << endl;
+		 (polys + polySplits) / (double)polys << endl;
 	
 	app << "===== END OF BspTree statistics ==========\n";
@@ -529,5 +535,5 @@
 				CLEAR_CONTAINER(coincident);
 
-				mStat.splits += splits;
+				mStat.polySplits += splits;
 
 				// push the children on the stack
@@ -962,9 +968,9 @@
 	startTime = GetTime();
 	// subdivide polygons with plane
-	mStat.splits += SplitPolygons(interior->GetPlane(),
-								  *tData.mPolygons, 
-		                          *frontData.mPolygons, 
-								  *backData.mPolygons, 
-								  coincident);
+	mStat.polySplits += SplitPolygons(interior->GetPlane(),
+									  *tData.mPolygons, 
+									  *frontData.mPolygons, 
+									  *backData.mPolygons, 
+									  coincident);
 
 	Debug << "time used for polygon splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 491)
@@ -255,4 +255,8 @@
 
 
+// use ascii format to store rays
+#define USE_ASCII 0
+
+
 inline bool ilt(Intersectable *obj1, Intersectable *obj2)
 {
@@ -268,33 +272,78 @@
 	environment->GetStringValue("Preprocessor.samplesFilename", fileName);
 	
-	Vector3 origin, termination;
-	// HACK: needed only for lower_bound algorithm
-	MeshInstance object(NULL);
-	ifstream samplesIn(fileName);
-
+    Vector3 origin, termination;
+	// HACK: needed only for lower_bound algorithm to find the 
+	// intersected objects
+	MeshInstance sObj(NULL);
+	MeshInstance tObj(NULL);
+
+#if USE_ASCII
+	ifstream samplesIn(fileName, ios::binary);
 	if (!samplesIn.is_open())
 		return false;
 
 	string buf;
-	
 	while (!(getline(samplesIn, buf)).eof())
 	{
-		sscanf(buf.c_str(), "%f %f %f %f %f %f %d", 
+		sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d", 
 			   &origin.x, &origin.y, &origin.z,
-			   &termination.x, &termination.y, &termination.z, &(object.mId));
-		
-		if (1)
+			   &termination.x, &termination.y, &termination.z, 
+			   &(sObj.mId), &(tObj.mId));
+		
+		Intersectable *sourceObj = NULL;
+		Intersectable *termObj = NULL;
+		
+		if (sObj.mId >= 0)
 		{
 			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &object, ilt);
-
-			samples.push_back(new VssRay(origin, termination, NULL, *oit));
-		}
-		else
+				lower_bound(objects.begin(), objects.end(), &sObj, ilt);
+			sourceObj = *oit;
+		}
+		
+		if (tObj.mId >= 0)
 		{
-			samples.push_back(new VssRay(origin, termination, NULL, objects[object.mId]));
-		}
-	}
-	
+			ObjectContainer::iterator oit =
+				lower_bound(objects.begin(), objects.end(), &tObj, ilt);
+			termObj = *oit;
+		}
+
+		samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
+	}
+#else
+	ifstream samplesIn(fileName, ios::binary);
+	if (!samplesIn.is_open())
+		return false;
+
+	while (1)
+	{
+		 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3));
+		 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3));
+		 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int));
+		 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int));
+		
+		 if (samplesIn.eof())
+			break;
+
+		Intersectable *sourceObj = NULL;
+		Intersectable *termObj = NULL;
+		
+		if (sObj.mId >= 0)
+		{
+			ObjectContainer::iterator oit =
+				lower_bound(objects.begin(), objects.end(), &sObj, ilt);
+			sourceObj = *oit;
+		}
+		
+		if (tObj.mId >= 0)
+		{
+			ObjectContainer::iterator oit =
+				lower_bound(objects.begin(), objects.end(), &tObj, ilt);
+			termObj = *oit;
+		}
+
+		samples.push_back(new VssRay(origin, termination, sourceObj, termObj));
+	}
+
+#endif
 	samplesIn.close();
 
@@ -304,10 +353,12 @@
 bool Preprocessor::WriteSamples(const VssRayContainer &samples) const
 {
-	char buf[100];
-	environment->GetStringValue("Preprocessor.samplesFilename", buf);
-	ofstream samplesOut(buf);
+	char fileName[100];
+	environment->GetStringValue("Preprocessor.samplesFilename", fileName);
+	
 
 	VssRayContainer::const_iterator it, it_end = samples.end();
 	
+#if USE_ASCII
+	ofstream samplesOut(fileName);
 	if (!samplesOut.is_open())
 		return false;
@@ -316,11 +367,32 @@
 	{
 		VssRay *ray = *it;
-	
+		int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;		
+		int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;	
+
 		samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " " 
 				   << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " " 
-				   << ray->mTerminationObject->mId << "\n";
-	}
+				   << sourceid << " " << termid << "\n";
+	}
+#else
+	ofstream samplesOut(fileName, ios::binary);
+	if (!samplesOut.is_open())
+		return false;
+
+	for (it = samples.begin(); it != it_end; ++ it)
+	{	
+		VssRay *ray = *it;
+		Vector3 origin(ray->GetOrigin());
+		Vector3 termination(ray->GetTermination());
+		
+		int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;		
+		int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;		
+
+		samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3));
+		samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3));
+		samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int));
+		samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int));
+    }
+#endif
 	samplesOut.close();
-
 	return true;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 491)
@@ -12,7 +12,7 @@
 #include "RenderSimulator.h"
 
-bool useViewSpaceBox = true;
+bool useViewSpaceBox = false;
 bool use2dSampling = false;
-bool useViewspacePlane = true;
+bool useViewspacePlane = false;
 
 VssPreprocessor::VssPreprocessor():
@@ -464,9 +464,15 @@
 	  WriteSamples(mVssRays);
 	  cout << "finished\n" << endl;
-  }
-
-  //VssRayContainer dummyRays;
-  //LoadSamples(dummyRays, mObjects);
-  //Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl;
+
+	  /*VssRayContainer dummyRays;
+	  LoadSamples(dummyRays, mObjects);
+	  Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl;
+
+	  for (int i = 0; i < (int)mVssRays.size(); ++ i)
+	  {
+		  Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl;
+		  Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl;
+	  }*/
+  }
 
   //int numExportRays = 10000;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 490)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 491)
@@ -1643,7 +1643,7 @@
 
 
-/**********************************************************************/
-/*                 VspBspViewCellsManager implementation              */
-/**********************************************************************/
+/************************************************************************/
+/*                 VspBspViewCellsManager implementation                */
+/************************************************************************/
 
 
@@ -1722,14 +1722,43 @@
 	
 	Debug << mVspBspTree->GetStatistics() << endl;
+
 	// collapse invalid regions
+	cout << "collapsing invalid tree regions ... ";
 	mVspBspTree->CollapseTree(mVspBspTree->GetRoot()); 
+	cout << "finished" << endl;
+	cout << "reseting view cell stats ... ";
 	ResetViewCells();
+	cout << "finished" << endl;
 	
 	Debug << "\nView cells after construction:\n" << mViewCellsStats << endl;
-	
+
+	if (1) // export initial view cells
+	{
+		cout << "exporting initial view cells (=leaves) ... ";
+		Exporter *exporter = Exporter::GetExporter("view_cells.x3d");
+	
+		if (exporter)
+		{
+			//exporter->SetWireframe();
+			exporter->SetFilled();
+			ExportViewCells(exporter);
+
+			//if (mExportRays)
+			//	exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0));
+			
+			if (mExportGeometry)
+				exporter->ExportGeometry(objects);
+			
+			delete exporter;
+		}
+		cout << "finished" << endl;
+	}
+
 	long startTime = GetTime();
+	cout << "Computing remaining ray contributions ... ";
 	// recast rest of rays
 	ComputeSampleContributions(savedRays);
-	
+	cout << "finished" << endl;
+
 	Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3 
 		  << " secs" << endl;
@@ -1806,35 +1835,4 @@
     Debug << ss << endl;
 
-	if (1) // export view cells
-	{
-		cout << "exporting initial view cells (=leaves) ... ";
-		Exporter *exporter = Exporter::GetExporter("view_cells.x3d");
-	
-		if (exporter)
-		{
-			//exporter->SetWireframe();
-			exporter->SetFilled();
-			ExportViewCells(exporter);
-
-			if (mExportRays)
-			{
-				exporter->ExportRays(postProcessRays, RgbColor(1, 1, 0));
-			}
-
-			if (mExportGeometry)
-			{
-				Material m;
-				m.mDiffuseColor = RgbColor(0, 1, 0);
-				exporter->SetForcedMaterial(m);
-				exporter->SetFilled();
-
-				exporter->ExportGeometry(objects);
-			}
-
-			delete exporter;
-		}
-		cout << "finished" << endl;
-	}
-
 	//-- merge or subdivide view cells
 	int merged = 0;
@@ -1853,5 +1851,8 @@
 		  << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl;
 	
+	cout << "reseting view cell stats ... ";
 	ResetViewCells();
+	cout << "finished" << endl;
+
 	//BspLeaf::NewMail();
 	if (1) // export merged view cells
