Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2572)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2576)
@@ -1,6 +1,6 @@
+#include "glInterface.h"
+#include "QtGlRenderer.h"
 #include "Mesh.h"
-#include "glInterface.h"
 #include "OcclusionQuery.h"
-#include "QtGlRenderer.h"
 #include "ViewCellsManager.h"
 #include "SceneGraph.h"
@@ -1245,6 +1245,58 @@
 #endif
 
-void
-QtGlRendererWidget::RenderViewCells()
+
+
+void QtGlRendererWidget::ComputeMaxValues(const ViewCellContainer &viewCells,
+										  int &maxPvs, 
+										  int &maxPiercingRays, 
+										  float &maxRelativeRays, 
+										  float &maxRcCost)
+{
+	maxPvs = -1;
+	maxPiercingRays = 1; // not zero for savety
+	maxRelativeRays = Limits::Small; // not zero for savety
+	maxRcCost = Limits::Small;
+
+	for (size_t i = 0; i < viewCells.size(); ++ i) 
+	{
+		ViewCell *vc = viewCells[i];
+
+		if (mShowPvsSizes) // pvs size
+		{
+			//const int p = vc->GetPvs().CountObjectsInPvs();
+			const int p = vc->GetPvs().GetSize();
+			if (p > maxPvs)
+				maxPvs = p;
+		}
+		else if (mShowPiercingRays) // relative number of rays
+		{
+			const int piercingRays = vc->GetNumPiercingRays();
+
+			if (piercingRays > maxPiercingRays)
+				maxPiercingRays = piercingRays;
+		} 
+		else if (mShowWeightedRays)
+		{
+			const int piercingRays = vc->GetNumPiercingRays();
+
+			const float relativeArea = 
+				vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
+
+			if ((float)piercingRays / relativeArea > maxRelativeRays)
+				maxRelativeRays = (float)piercingRays / relativeArea;
+		}
+		else if (mShowWeightedCost)
+		{
+			const float rcCost = ComputeRenderCost(vc);
+			mViewCellsManager->UpdateScalarPvsCost(vc, rcCost);
+
+			if (rcCost > maxRcCost)
+				maxRcCost = rcCost;
+		}
+	}
+}
+
+
+void QtGlRendererWidget::RenderViewCells()
 {
 	mUseFalseColors = true;
@@ -1272,46 +1324,9 @@
 	ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
 	
-	int maxPvs = -1;
-	int maxPiercingRays = 1; // not zero for savety
-	float maxRelativeRays = Limits::Small; // not zero for savety
-	float maxRcCost = Limits::Small;
-
-	for (i = 0; i < viewcells.size(); ++ i) 
-	{
-		ViewCell *vc = viewcells[i];
-
-		if (mShowPvsSizes) // pvs size
-		{
-			//const int p = vc->GetPvs().CountObjectsInPvs();
-			const int p = vc->GetPvs().GetSize();
-			if (p > maxPvs)
-				maxPvs = p;
-		}
-		else if (mShowPiercingRays) // relative number of rays
-		{
-			const int piercingRays = vc->GetNumPiercingRays();
-
-			if (piercingRays > maxPiercingRays)
-				maxPiercingRays = piercingRays;
-		} 
-		else if (mShowWeightedRays)
-		{
-			const int piercingRays = vc->GetNumPiercingRays();
-
-			const float relativeArea = 
-				vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
-
-			if ((float)piercingRays / relativeArea > maxRelativeRays)
-				maxRelativeRays = (float)piercingRays / relativeArea;
-		}
-		else if (mShowWeightedCost)
-		{
-			const float rcCost = ComputeRenderCost(vc);
-			mViewCellsManager->UpdateScalarPvsCost(vc, rcCost);
-
-			if (rcCost > maxRcCost)
-				maxRcCost = rcCost;
-		}
-	}
+	int maxPvs, maxPiercingRays;
+	float maxRelativeRays, maxRcCost;
+
+	ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
+
 
 	if (!mShowPvsSizes && !mShowPiercingRays && !mShowWeightedRays && !mShowWeightedCost)
@@ -1338,7 +1353,5 @@
 	else
 	{
-		//glDisable(GL_CULL_FACE);
-		//glCullFace(GL_BACK);
-
+		// transparency	
 		if (!mUseTransparency)
 		{
@@ -1365,46 +1378,11 @@
 		}
 
-		for (i = 0; i < viewcells.size(); ++ i) 
-		{
-			RgbColor c;
-            ViewCell *vc = viewcells[i];
-			
-			float importance;
-
-			if (mShowPiercingRays)
-			{
-				importance = mTransferFunction *
-					((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
-			}
-			else if (mShowWeightedRays) // relative number of rays
-			{
-				float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
-
-				if (relativeArea < Limits::Small)
-					relativeArea = Limits::Small;
-
-				importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
-			}
-			else if (mShowPvsSizes) // pvs size
-			{
-				importance = mTransferFunction *
-					((float)vc->GetPvs().GetSize() / (float)maxPvs);
-			} // weighted render cost
-			else if (mShowWeightedCost)
-			{
-				const float rcCost = mTransferFunction * ComputeRenderCost(vc);
-				importance = rcCost / maxRcCost;
-			}
-
-			// c = RgbColor(importance, 1.0f - importance, 0.0f);
-			c = RainbowColorMapping(importance);
-
-			glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
-
-			if (!mHideByCost || (mHidingCost < importance)) 
-			{
-				RenderViewCell(vc);
-			}
-		}
+		ViewCellInfoContainer *infos1 = mCurrentInfos[mCurrentSamples];
+		ViewCellInfoContainer *infos2 = mCompareInfos[mCurrentSamples];
+
+		if (mAssignImportanceByRelativeValue)
+			AssignImportanceByRelativeValue(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
+		else
+			AssignColorByComparison(viewcells, *infos1, *infos2);
 
 		glEnable(GL_DEPTH_TEST);	
@@ -1423,29 +1401,96 @@
 
 
-
-/*********************************************************************/
-/*                   QtGlDebuggerWidget implementation               */
-/*********************************************************************/
-
-
-QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
-: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
-{
-	// create the pbuffer
-	//pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
-	timerId = startTimer(20);
-	setWindowTitle(("OpenGL pbuffers"));
-}
-
-
-QtGlDebuggerWidget::~QtGlDebuggerWidget()
-{
-	mRenderBuffer->releaseFromDynamicTexture();
-	glDeleteTextures(1, &dynamicTexture);
-
-	DEL_PTR(mRenderBuffer);
-}
-
-
+void QtGlRendererWidget::AssignImportanceByRelativeValue(const ViewCellContainer &viewCells,
+														 int &maxPvs, 
+														 int &maxPiercingRays, 
+														 float &maxRelativeRays, 
+														 float &maxRcCost)
+{
+	for (size_t i = 0; i < viewCells.size(); ++ i) 
+	{
+		RgbColor c;
+		ViewCell *vc = viewCells[i];
+
+		float importance;
+
+		if (mShowPiercingRays)
+		{
+			importance = mTransferFunction *
+				((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
+		}
+		else if (mShowWeightedRays) // relative number of rays
+		{
+			float relativeArea = vc->GetBox().SurfaceArea() / mViewCellsManager->GetViewSpaceBox().SurfaceArea();
+
+			if (relativeArea < Limits::Small)
+				relativeArea = Limits::Small;
+
+			importance = mTransferFunction * ((float)vc->GetNumPiercingRays() / relativeArea) / maxRelativeRays;
+		}
+		else if (mShowPvsSizes) // pvs size
+		{
+			importance = mTransferFunction *
+				((float)vc->GetPvs().GetSize() / (float)maxPvs);
+		} // weighted render cost
+		else if (mShowWeightedCost)
+		{
+			const float rcCost = mTransferFunction * ComputeRenderCost(vc);
+			importance = rcCost / maxRcCost;
+		}
+
+		// c = RgbColor(importance, 1.0f - importance, 0.0f);
+		c = RainbowColorMapping(importance);
+
+		glColor4f(c.r, c.g, c.b, 1.0f - mTransparency);
+
+		if (!mHideByCost || (mHidingCost < importance)) 
+		{
+			RenderViewCell(vc);
+		}
+	}
+}
+
+
+void QtGlRendererWidget::AssignColorByComparison(const ViewCellContainer &viewcells,
+												 const ViewCellInfoContainer &infos1, 
+												 const ViewCellInfoContainer &infos2)
+{
+
+	const float maxRatio = 2;
+	const float minRatio = 0.5;
+
+	const float scale = 1.0f / (maxRatio - minRatio);
+
+	for (size_t i = 0; i < viewcells.size(); ++ i) 
+	{
+		RgbColor c;
+		ViewCell *vc = viewcells[i];
+
+		ViewCellInfo vc1Info = infos1[i];
+		ViewCellInfo vc2Info = infos2[i];
+
+		const float vcRatio = vc1Info.mPiercingRays / vc2Info.mPiercingRays + Limits::Small;
+
+		const float importance = (vcRatio - minRatio) * scale;
+
+		// c = RgbColor(importance, 1.0f - importance, 0.0f);
+		c = RainbowColorMapping(importance);
+
+		glColor4f(c.r, c.g, c.b, 1.0f);
+
+		if (1)//!mHideByCost || (mHidingCost < importance)) 
+		{
+			RenderViewCell(vc);
+		}
+	}
+}
+
+
+
+/**********************************************************************/
+/*              QtRendererControlWidget implementation                */
+/**********************************************************************/
+
+#if 1
 QGroupBox *QtRendererControlWidget::CreateVisualizationPanel(QWidget *parent)
 {
@@ -1527,4 +1572,5 @@
 }
 
+
 QtRendererControlWidget::QtRendererControlWidget(QWidget * parent, Qt::WFlags f):
 QWidget(parent, f)
@@ -1843,8 +1889,5 @@
 void
 QtRendererControlWidget::FocusNextPvsErrorFrame(void)
-{
-
-
-}
+{}
 
 void
@@ -1865,4 +1908,32 @@
 
 
+
+#endif
+
+
+/*********************************************************************/
+/*                   QtGlDebuggerWidget implementation               */
+/*********************************************************************/
+
+
+QtGlDebuggerWidget::QtGlDebuggerWidget(QtGlRendererBuffer *buf, QWidget *parent)
+: QGLWidget(QGLFormat(QGL::SampleBuffers), parent), mRenderBuffer(buf)
+{
+	// create the pbuffer
+	//pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
+	timerId = startTimer(20);
+	setWindowTitle(("OpenGL pbuffers"));
+}
+
+
+QtGlDebuggerWidget::~QtGlDebuggerWidget()
+{
+	mRenderBuffer->releaseFromDynamicTexture();
+	glDeleteTextures(1, &dynamicTexture);
+
+	DEL_PTR(mRenderBuffer);
+}
+
+
 void QtGlDebuggerWidget::initializeGL()
 {
@@ -1945,4 +2016,5 @@
 }
 
+
 void QtGlDebuggerWidget::initCommon()
 {
@@ -1954,4 +2026,3 @@
 
 
-
-}
+}
