Index: GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 1883)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 1900)
@@ -2,5 +2,5 @@
 
 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+"
-COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter+"
+COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter-"
 
 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
@@ -35,18 +35,18 @@
 
 
-# $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
-# -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \
-# -preprocessor_histogram_file=$PREFIX-r-reference.hlog
+#$COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+#-view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \
+#-preprocessor_histogram_file=$PREFIX-r-reference.hlog
 
 
+#$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+#-rss_update_subdivision+ -rss_split=hybrid -hybrid_depth=10 \
+#-view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-i-combined-update-ccb12-nn.log \
+#-preprocessor_histogram_file=$PREFIX-i-combined-update-ccb12-nn.hlog
+
 # $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
-# -rss_update_subdivision+ -rss_split=hybrid -hybrid_depth=10 \
-# -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-i-combined-update-ccb12-nn.log \
-# -preprocessor_histogram_file=$PREFIX-i-combined-update-ccb12-nn.hlog
-
-$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--rss_update_subdivision- -rss_split=hybrid -hybrid_depth=10 \
--view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-i-combined-ccb12-nn.log \
--preprocessor_histogram_file=$PREFIX-i-combined-ccb12-nn.hlog
+# -rss_update_subdivision- -rss_split=hybrid -hybrid_depth=10 \
+# -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-i-combined-ccb12-nn.log \
+# -preprocessor_histogram_file=$PREFIX-i-combined-ccb12-nn22.hlog
 
 
@@ -64,8 +64,8 @@
 
 
-#$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
-#-rss_distributions=spatial+object_direction -view_cells_filter_max_size=1 \
-# -preprocessor_stats=$PREFIX-i-mixed-b1-n.log \
-# -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n.hlog
+$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+-rss_distributions=object_direction+spatial+object+direction -view_cells_filter_max_size=1 \
+-preprocessor_stats=$PREFIX-i-mixed-b1-n225678.log \
+-preprocessor_histogram_file=$PREFIX-i-mixed-b1-n225678.hlog
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1895)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1900)
@@ -1840,4 +1840,7 @@
 	  "preprocessor_use_viewspace_box=",
 	  "false");   
+
+   RegisterOption("Preprocessor.Export.rays", optBool, "export_rays=", "false");
+	RegisterOption("Preprocessor.Export.numRays", optInt, "export_num_rays=", "5000");
    
 	/*************************************************************************/
@@ -1962,6 +1965,5 @@
 	RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs=", "false");
 	RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree=", "false");
-	RegisterOption("RssPreprocessor.Export.rays", optBool, "rss_export_rays=", "false");
-	RegisterOption("RssPreprocessor.Export.numRays", optInt, "rss_export_num_rays=", "5000");
+
 	RegisterOption("RssPreprocessor.useViewcells", optBool, "rss_use_viewcells=", "false");
 	RegisterOption("RssPreprocessor.updateSubdivision",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1898)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1900)
@@ -167,4 +167,7 @@
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useViewSpaceBox", mUseViewSpaceBox);
 
+	Environment::GetSingleton()->GetBoolValue("Preprocessor.Export.rays", mExportRays);
+	Environment::GetSingleton()->GetIntValue("Preprocessor.Export.numRays", mExportNumRays);
+
 	Debug << "******* Preprocessor Options **********" << endl;
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
@@ -1220,3 +1223,42 @@
 }
 
-}
+
+bool
+Preprocessor::ExportRays(const char *filename,
+						 const VssRayContainer &vssRays,
+						 const int number
+						 )
+{
+  cout<<"Exporting vss rays..."<<endl<<flush;
+  
+  Exporter *exporter = NULL;
+  exporter = Exporter::GetExporter(filename);
+
+  if (0) {
+	exporter->SetWireframe();
+	exporter->ExportKdTree(*mKdTree);
+  }
+  
+  exporter->SetFilled();
+  // $$JB temporarily do not export the scene
+  if (0)
+	exporter->ExportScene(mSceneGraph->GetRoot());
+
+  exporter->SetWireframe();
+
+  if (1) {
+	exporter->SetForcedMaterial(RgbColor(1,0,1));
+	exporter->ExportBox(mViewCellsManager->GetViewSpaceBox());
+	exporter->ResetForcedMaterial();
+  }
+  
+  VssRayContainer rays;
+  vssRays.SelectRays(number, rays);
+  exporter->ExportRays(rays, RgbColor(1, 0, 0));
+  delete exporter;
+  cout<<"done."<<endl<<flush;
+
+  return true;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1891)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1900)
@@ -164,42 +164,4 @@
 
 
-bool
-RssPreprocessor::ExportRays(const char *filename,
-							const VssRayContainer &vssRays,
-							const int number
-							)
-{
-  cout<<"Exporting vss rays..."<<endl<<flush;
-	
-  Exporter *exporter = NULL;
-  exporter = Exporter::GetExporter(filename);
-  if (0) {
-	exporter->SetWireframe();
-	exporter->ExportKdTree(*mKdTree);
-  }
-  exporter->SetFilled();
-  // $$JB temporarily do not export the scene
-  if (0)
-	exporter->ExportScene(mSceneGraph->GetRoot());
-  exporter->SetWireframe();
-
-  if (1) {
-	exporter->SetForcedMaterial(RgbColor(1,0,1));
-	exporter->ExportBox(mViewCellsManager->GetViewSpaceBox());
-	exporter->ResetForcedMaterial();
-  }
-  
-  VssRayContainer rays;
-  
-  vssRays.SelectRays(number, rays);
-
-  exporter->ExportRays(rays, RgbColor(1, 0, 0));
-	
-  delete exporter;
-
-  cout<<"done."<<endl<<flush;
-
-  return true;
-}
 
 bool
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1891)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1900)
@@ -73,4 +73,9 @@
 	    file	histogram.log
 	}
+	Export {
+		rays true
+		numRays 5000
+	}
+
 }
 
@@ -96,18 +101,14 @@
 #	distributions object_direction
 
-	samplesPerPass 200000
+	samplesPerPass 1000000
 	initialSamples 2000000
-	vssSamples 50000000
-	vssSamplesPerPass 500000
+	vssSamples 20000000
+	vssSamplesPerPass 5000000
 	useImportanceSampling true
 
-	directionalSampling false
-	objectBasedSampling false
 
 	Export {
 		pvs false
 		rssTree false
-		rays true
-		numRays 5000
 	}
 
@@ -131,9 +132,9 @@
 #	splitType heuristic
 
-	minRays		100
+	minRays		50
 	minSize		0.001
  	maxCostRatio 1.0
 	maxRayContribution 1.0
-	maxRays		10000000
+	maxRays		2000000
 	maxTotalMemory	400
 	maxStaticMemory	200
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1884)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1900)
@@ -121,4 +121,10 @@
 	bool ExportKdTree(const string filename);
 
+  virtual bool
+  ExportRays(const char *filename,
+			 const VssRayContainer &vssRays,
+			 const int number
+			 );
+	
 	virtual int
 	GenerateRays(const int number,
@@ -203,4 +209,7 @@
   
 	bool mExportObj;
+
+  bool mExportRays;
+  int mExportNumRays;
 
 	ofstream mStats;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1899)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1900)
@@ -57,5 +57,9 @@
 
 	virtual bool GenerateSample(SimpleRay &ray) = 0;
-  
+
+  // true if the strategy keeps pointers to rays and thus they should get deleted
+  // outside, in that case the strategy has to use reference counting and deleting the rays
+  // by itself if the number of references drops to zero
+  virtual bool RequiresRays() { return false; }
 
 
@@ -70,14 +74,14 @@
 public:
 
-	/// variables usefull for mixed distribution sampling
-	int mType;
-	int mRays;
- 	float mContribution;
-
-	int mTotalRays;
-	float mTotalContribution;
-
-	float mTime;
-	float mRatio;
+  /// variables usefull for mixed distribution sampling
+  int mType;
+  int mRays;
+  float mContribution;
+  
+  int mTotalRays;
+  float mTotalContribution;
+  
+  float mTime;
+  float mRatio;
 
 protected:
@@ -273,4 +277,11 @@
   Construct(char *str);
 
+  virtual bool RequiresRays() {
+	for (int i=0; i < mDistributions.size(); i++)
+	  if (mDistributions[i]->RequiresRays())
+		return true;
+	return false;
+  }
+
 private:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1883)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1900)
@@ -87,4 +87,5 @@
   int intersectables, faces;
   mSceneGraph->GetStatistics(intersectables, faces);
+  HaltonSequence halton;
   
   int samples = 0;
@@ -99,8 +100,10 @@
 		  cout<<"+";
 
+		float r[5];
+		halton.GetNext(5, r);
 		Vector3 origin, direction;
-		mViewCellsManager->GetViewPoint( origin );
+		mViewCellsManager->GetViewPoint(origin, Vector3(r[0], r[1], r[2]));
 		
-		direction = UniformRandomVector();
+		direction = UniformRandomVector(r[3],r[4]);
 		ViewCell *viewcell = mViewCellsManager->GetViewCell(origin);
 		
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1884)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1900)
@@ -33,6 +33,4 @@
   bool mExportPvs;
   bool mExportRssTree;
-  bool mExportRays;
-  int mExportNumRays;
 
   bool mUseViewcells;
@@ -72,9 +70,4 @@
   
 
-  bool
-  ExportRays(const char *filename,
-			 const VssRayContainer &vssRays,
-			 const int number
-			 );
 
   bool
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1895)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1900)
@@ -27,7 +27,10 @@
 
 // $$JB HACK
-#define USE_KD_PVS 0
+#define USE_KD_PVS 1
 
 #define KD_PVS_AREA (1e-5f)
+
+#define USE_RAY_LENGTH_AS_CONTRIBUTION 0
+#define DIST_WEIGHTED_CONTRIBUTION 1
 
 namespace GtpVisibilityPreprocessor {
@@ -1536,14 +1539,18 @@
    											 const bool storeViewCells)
 {
-  // view cells not yet constructed
-  if (!ViewCellsConstructed())
-	return 0.0f;
-  
   float sum = 0.0f;
+
   VssRayContainer::const_iterator it, it_end = rays.end();
   
   for (it = rays.begin(); it != it_end; ++ it) 
 	{
-	  sum += ComputeSampleContribution(*(*it), addRays, storeViewCells);
+	  if (!ViewCellsConstructed()) {
+		// view cells not yet constructed
+		// just take the lenghts of the rays as contributions
+		if ((*it)->mTerminationObject)
+		  sum += (*it)->Length();
+	  } else {
+		sum += ComputeSampleContribution(*(*it), addRays, storeViewCells);
+	  }
 	}
   
@@ -2009,6 +2016,6 @@
 float
 ViewCellsManager::ComputeSampleContribution(VssRay &ray,
-												  const bool addRays,
-												  const bool storeViewCells)
+											const bool addRays,
+											const bool storeViewCells)
 {
   ray.mPvsContribution = 0;
@@ -2059,6 +2066,13 @@
 			{
 			  // todo: maybe not correct for kd node pvs
-			  if (viewcell->GetPvs().GetSampleContribution(
-														   terminationObj, ray.mPdf, contribution))
+			  bool absContribution = viewcell->GetPvs().GetSampleContribution(
+																			  terminationObj,
+																			  ray.mPdf,
+																			  contribution);
+#if DIST_WEIGHTED_CONTRIBUTION
+			  // clear the relative contribution
+			  contribution = 0.0f;
+#endif
+			  if (absContribution)
 				{
 				  ++ ray.mPvsContribution;
@@ -2073,4 +2087,10 @@
 #endif
 				  }
+#if DIST_WEIGHTED_CONTRIBUTION 
+				  // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the
+				  // object-> a new contribution in the proximity of the viewcell has a larger weight!
+				  contribution = 1.0f/SqrDistance(GetViewCellBox(viewcell).Center(),
+												  ray.mTermination);
+#endif
 				}
 			  
@@ -2079,7 +2099,15 @@
 		}
 	}
-  
+
+#if USE_RAY_LENGTH_AS_CONTRIBUTION
+  float c = 0.0f;
+  if (terminationObj) 
+	c = ray.Length();
+  ray.mRelativePvsContribution = ray.mPvsContribution = c;
+  return c;
+#else
   return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution +
 	(1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution;
+#endif
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1891)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1900)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: st 13. XII 23:09:08 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: ?t 14. XII 10:54:14 2006
 # Project:  preprocessor.pro
 # Template: app
@@ -63,5 +63,5 @@
 	$(MAKE) -f $(MAKEFILE).Debug uninstall
 
-Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \
+Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \
 		C:\Qt\4.1.2\mkspecs\features\qt_config.prf \
 		C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1884)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1900)
@@ -307,5 +307,5 @@
   //
   /////////////////////////////////
-
+  
 
   // the bbox of the node
@@ -317,4 +317,7 @@
   // evaluated importance of this node
   float mImportance;
+
+  // importance requires update
+  //bool mRequiresUpdate;
 
   inline RssTreeNode(RssTreeInterior *p);
@@ -1133,4 +1136,5 @@
   
   virtual void Update(VssRayContainer &vssRays);
+  virtual bool RequiresRays() { return true; }
   
 private:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1891)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1900)
@@ -365,7 +365,9 @@
 	
 	  RssTreeNode::RayInfo info(*ri);
-	  
+	  if (!EpsilonEqualV3(info.GetOrigin(), info.GetTermination(), Limits::Small)) {
+
 	  // first construct a leaf that will get subdivide
 	  RssTreeLeaf *leaf = (RssTreeLeaf *) GetRoot(info.GetSourceObject());
+	  
 
 	  leaf->AddRay(info);
@@ -389,4 +391,5 @@
 	  leaf->dirBBox.Include(dVec);
 	  dirBBox.Include(dVec);
+	  }
   }
 
@@ -1456,9 +1459,8 @@
   if (stat.rayRefs > mMaxRays) {
 	Debug<<"Prunning rays..."<<endl<<flush;
-	PruneRays(mMaxRays);
+	PruneRays(0.8f*mMaxRays);
 	Debug<<"done."<<endl<<flush;
 	//	UpdateTreeStatistics();
   }
-
 }
 
@@ -1553,4 +1555,6 @@
 RssTree::AddRay(RssTreeNode::RayInfo &info)
 {
+  if (EpsilonEqualV3(info.GetOrigin(), info.GetTermination(), Limits::Small))
+	return;
 
   stack<RayTraversalData> tstack;
@@ -1561,4 +1565,5 @@
   RayTraversalData data;
   
+
   while (!tstack.empty()) {
     data = tstack.top();
@@ -1807,4 +1812,8 @@
 RssTree::UpdateTreeStatistics()
 {
+  for (int i=0; i < mRoots.size(); i++)
+	UpdateImportance(mRoots[i]);
+  
+#if 0  
   stack<RssTreeNode *> tstack;
 	
@@ -1819,9 +1828,7 @@
   int leaves = 0;
 
-  for (int i=0; i < mRoots.size(); i++)
-	UpdateImportance(mRoots[i]);
 
   PushRoots(tstack);
-
+  
   while (!tstack.empty()) {
     RssTreeNode *node = tstack.top();
@@ -1871,4 +1878,5 @@
   stat.avgWeightedRayContribution = sumWeightedRayContribution/(float)sumRays;
   stat.rayRefs = (int)sumRays;
+#endif
   
 }
@@ -2822,4 +2830,5 @@
 	  float c1 = weight*ray->mPvsContribution;
 	  float c2 = weight*ray->mRelativePvsContribution;
+
 	  sumContributions += c1;
 	  if (c1 > maxContribution)
@@ -2832,6 +2841,6 @@
 	  sumRelContributions += c2;
 	  if (c2 > maxRelContribution)
-			maxRelContribution = c2;
-
+		maxRelContribution = c2;
+	  
 	  //sumWeights += weight;
 	  sumWeights += 1.0f;
@@ -2864,6 +2873,6 @@
 	  leaf->mImportance =
 		pow(((weightAbsContributions*sumContributions +
-			  (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights), 3);
-#else 
+			  (1.0f - weightAbsContributions)*sumRelContributions)/sumWeights), 1.0f);
+#else 1
 	  leaf->mImportance =
 		(weightAbsContributions*maxContribution +
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1883)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1900)
@@ -14,5 +14,5 @@
 class KdNode;
 
-#define ABS_CONTRIBUTION_WEIGHT 1.0f
+#define ABS_CONTRIBUTION_WEIGHT 0.0f
 
 class VssRay {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1883)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1900)
@@ -95,6 +95,6 @@
 
 	// regardless of the pruneInvalidRays setting reject rays whic degenerate to a point
-	if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small))
-	  return 0;
+	//	if (EpsilonEqualV3(hitA.mPoint, hitB.mPoint, Limits::Small))
+	//	  return 0;
 	
 	if (pruneInvalidRays) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp	(revision 1894)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp	(revision 1900)
@@ -29,6 +29,4 @@
 	
 	
-	//  Environment::GetSingleton()->GetBoolValue("RssPreprocessor.Export.rays", mExportRays);
-	//  Environment::GetSingleton()->GetIntValue("RssPreprocessor.Export.numRays", mExportNumRays);
   }
   
@@ -71,14 +69,4 @@
   for (int i=0; i < mTotalSamples; i += mSamplesPerPass, mPass++) {
 
-	if (i - lastEvaluation >= mSamplesPerEvaluation) {
-	  mStats <<
-		"#Pass\n" <<mPass<<endl<<
-		"#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
-		"#TotalSamples\n" <<i<<endl<<
-		"#RssSamples\n" <<totalVssRays<<endl;
-	  vssRays.PrintStatistics(mStats);
-	  mViewCellsManager->PrintPvsStatistics(mStats);
-	  lastEvaluation = i;
-	}
 	
 	cout<<"Progress : "<<(100.0f*i)/mTotalSamples<<"%"<<endl;
@@ -90,10 +78,37 @@
 	CastRays(rays, vssRays, true, pruneInvalidRays);
 	totalVssRays += (int)vssRays.size();
-	
+
+	if (mExportRays) {
+	  Debug<<"Exporting rays..."<<endl<<flush;
+	  char filename[256];
+	  sprintf(filename, "rss-rays-i%04d.x3d", mPass);
+	  ExportRays(filename, vssRays, mExportNumRays);
+	  
+	  //	  VssRayContainer contributingRays;
+	  //	  vssRays.GetContributingRays(contributingRays, 0);
+	  //	  sprintf(filename, "rss-crays-%04d.x3d", mPass);
+	  //	  ExportRays(filename, contributingRays, mExportNumRays);
+	  Debug<<"done."<<endl<<flush;
+	}
+
 	mMixtureDistribution->ComputeContributions(vssRays);
 
+	if (i - lastEvaluation >= mSamplesPerEvaluation) {
+	  mViewCellsManager->PrintPvsStatistics(mStats);
+	  mStats <<
+		"#Pass\n" <<mPass<<endl<<
+		"#Time\n" << TimeDiff(startTime, GetTime())<<endl<<
+		"#TotalSamples\n" <<i<<endl<<
+		"#RssSamples\n" <<totalVssRays<<endl;
+	  lastEvaluation = i;
+	}
+
+	
+	
+	if (!mMixtureDistribution->RequiresRays())
+	  CLEAR_CONTAINER(vssRays);
   }
+  
   return true;
-  
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1899)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1900)
@@ -495,7 +495,7 @@
   float r;
   sHalton.GetNext(1, &r);
-
+  int i;
   // pickup a distribution
-  for (int i=0; i < mDistributions.size()-1; i++)
+  for (i=0; i < mDistributions.size()-1; i++)
 	if (r < mDistributions[i]->mRatio)
 	  break;
@@ -528,5 +528,5 @@
 	mDistributions[i]->mContribution += contribution;
 	mDistributions[i]->mRays ++;
-
+	
 	mDistributions[i]->mTotalContribution += contribution;
 	mDistributions[i]->mTotalRays ++;
@@ -553,13 +553,12 @@
 	float importance = 0.0f;
 	if (mDistributions[i]->mRays != 0) {
-	  importance = pow(mDistributions[i]->mContribution/mDistributions[i]->mRays, 3);
-	}
-	if (importance < Limits::Small)
-	  importance = Limits::Small;
+	  //	  importance = pow(mDistributions[i]->mContribution/mDistributions[i]->mRays, 3);
+	  importance = mDistributions[i]->mContribution/mDistributions[i]->mRays;
+	}
 	mDistributions[i]->mRatio = importance;
 	sum += importance;
   }
 
-  const float minratio = 0.05f;
+  const float minratio = 0.02f;
   float threshold = minratio*sum;
   for (i=0; i < mDistributions.size(); i++) {
