Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1563)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1566)
@@ -4227,9 +4227,10 @@
 	}
 
-	int limit = min(leafOut, (int)mViewCells.size());
-
-	int raysOut = 0;
-
+	//////////
 	//-- some rays for output
+
+	const int limit = min(leafOut, (int)mViewCells.size());
+	const int raysOut = min((int)rays.size(), 100);
+
 	for (int i = 0; i < limit; ++ i)
 	{
@@ -4246,5 +4247,4 @@
 		mViewCellsTree->GetPvs(vc, pvs);
 
-		//bspLeaves[j]->Mail();
 		char s[64]; sprintf(s, "bsp-pvs%04d.wrl", i);
 		Exporter *exporter = Exporter::GetExporter(s);
@@ -4252,23 +4252,21 @@
 		Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;
 
-		//-- export the sample rays
 		if (mExportRays)
 		{
-			// output rays stored with the view cells during subdivision
+			////////////
+			//-- export rays piercing this view cell
+
+			// take rays stored with the view cells during subdivision
 			VssRayContainer vcRays;
             VssRayContainer collectRays;
 
-			raysOut = min((int)rays.size(), 100);
-
-			// collect intial view cells
+			// collect initial view cells
 			ViewCellContainer leaves;
 			mViewCellsTree->CollectLeaves(vc, leaves);
 
 			ViewCellContainer::const_iterator vit, vit_end = leaves.end();
-       
-			for (vit = leaves.begin(); vit != vit_end; ++ vit)
+       		for (vit = leaves.begin(); vit != vit_end; ++ vit)
 			{
 				BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0];
-				
 				VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end();
 
@@ -4279,16 +4277,16 @@
 			}
 
+			// prepare some rays for output
 			VssRayContainer::const_iterator rit, rit_end = collectRays.end();
-
 			for (rit = collectRays.begin(); rit != rit_end; ++ rit)
 			{
-				float p = RandomValue(0.0f, (float)collectRays.size());
+				const float p = RandomValue(0.0f, (float)collectRays.size());
 			
 				if (p < raysOut)
+				{
 					vcRays.push_back(*rit);
+				}
 			}
 
-			//////////
-			//-- export rays piercing this view cell
 			exporter->ExportRays(vcRays, RgbColor(1, 1, 1));
 		}
@@ -4310,13 +4308,11 @@
 			////////
 			//-- export pvs
+			Intersectable::NewMail();
 			ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
-
-			Intersectable::NewMail();
-
+			
 			// output PVS of view cell
 			for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit)
 			{		
 				Intersectable *intersect = (*oit).first;
-
 				if (!intersect->Mailed())
 				{
@@ -5433,8 +5429,7 @@
 	{
 		ViewCell *viewcell = *it;
-
+		
 		if (viewcell->GetValid())
-		{
-			// if ray not outside of view space
+		{	// if ray not outside of view space
 			float contribution;
 
@@ -5470,5 +5465,7 @@
 
 	if (!addRays)
+	{
 		return ray.mRelativePvsContribution;
+	}
 
 	// sampled objects are stored in the pvs
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1528)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1566)
@@ -20,7 +20,9 @@
  // various flags
   enum {
-    FPosDirX = 1,  // the direction of ray in X-axis is positive
-    FPosDirY = 2,  // the direction of ray in Y-axis is positive
-    FPosDirZ = 4   // the direction of ray in Z-axis is positive
+    FPosDirX = 1,    // the direction of ray in X-axis is positive
+    FPosDirY = 2,    // the direction of ray in Y-axis is positive
+    FPosDirZ = 4,    // the direction of ray in Z-axis is positive
+	BorderSample = 8,// if this ray is an adaptive border ray
+	ReverserRay = 16 // if this ray is a reverse sample
   };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1563)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1566)
@@ -85,5 +85,5 @@
 		//cout << " h " << mSampleContriPerPass << " " << mSamplesPerPass << " " << mTotalSamples << endl;
 		mRayQueue.push(vssRay);
-		//mVssRays.push_back(new VssRay(*vssRay));
+		mVssRays.push_back(new VssRay(*vssRay));
         ++ mSampleContriPerPass;
 
@@ -184,4 +184,5 @@
 		SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin);
 	
+		// cast ray into the new subdivision point
 		VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), false);
 		//cout << "\np1: " << p1 << "\np : " <<  p << "\np2: " << p2 << endl;
@@ -190,4 +191,5 @@
 		const bool enqueued = HandleRay(newRay);
 		
+		// subdivide further
 		const int s1 = SubdivideEdge(hitTriangle, p1, p, x, *newRay, oldRay);
 		const int s2 = SubdivideEdge(hitTriangle, p, p2, *newRay, y, oldRay);
@@ -234,11 +236,13 @@
 		simpleRays.AddRay(sr);
 	}
-#if 0
-	VizStruct dummy;
-	dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
-	dummy.originalTriangle = hitTriangle;
-	//dummy.ray = new VssRay(currentRay);
-	vizContainer.push_back(dummy);
-#endif
+
+	if (0)
+	{
+		VizStruct dummy;
+		dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
+		dummy.originalTriangle = hitTriangle;
+		//dummy.ray = new VssRay(currentRay);
+		vizContainer.push_back(dummy);
+	}
 
 	// cast rays to triangle vertices and determine visibility
@@ -363,5 +367,4 @@
 
 	mTotalSampleContri += mSampleContriPerPass;
-
 	return castSamples;
 }
@@ -439,4 +442,8 @@
 
 		mViewCellsManager->PrintPvsStatistics(mStats);
+
+		// visualization
+//		mViewCellsManager->Visualize(mVssRays);
+		CLEAR_CONTAINER(mVssRays);
 		// ComputeRenderError();
 		++ mPass;
