Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1580)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1581)
@@ -430,23 +430,12 @@
 	bool GetExportPvs() const;
 
-	/////////////////////////////
-	// static members
-	
-	/** Loads view cells from file. The view cells manager is created with 
-		respect to the loaded view cells.
-
-		@param filename the filename of the view cells
-		@param objects the scene objects
-		@param finalizeViewCells if the view cells should be post processed, i.e.
-			a mesh is created representing the geometry
-		@param bconverter a conversion routine working with the similarities of bounding
-		boxes: if there is a certain similarity of overlap between bounding boxes, two tested
-		candidate objects are considered to be the same objects
-		@returns the view cells manager if loading was successful, false otherwise
-	*/
-	static ViewCellsManager *LoadViewCells(const string &filename, 
-										   ObjectContainer *objects, 
-										   const bool finalizeViewCells,
-										   BoundingBoxConverter *bconverter = NULL);
+
+  Preprocessor *GetPreprocessor() {
+	return mPreprocessor;
+  }
+  
+  void SetPreprocessor(Preprocessor *p) {
+	mPreprocessor = p;
+  }
 
 
@@ -731,5 +720,5 @@
 
 	~BspViewCellsManager();
-
+  
 	int ConstructSubdivision(const ObjectContainer &objects, 
 				  const VssRayContainer &rays);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1387)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1581)
@@ -10,4 +10,9 @@
 #include "KdTree.h"
 #include "Environment.h"
+#include "RssPreprocessor.h"
+#include "RssTree.h"
+#include "Trackball.h"
+
+
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
@@ -17,4 +22,7 @@
 namespace GtpVisibilityPreprocessor {
 
+
+#define CAMERA_VIEW_WIDTH 0.5f
+  
 class ViewCellsManager;
 
@@ -380,7 +388,5 @@
   makeCurrent();
 
-
   SetupProjection(GetWidth(), GetHeight());
-
   
   for (int i=0; i < mPvsStatFrames; i++) {
@@ -797,5 +803,6 @@
 	
 	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, depthMapSize, 
-		depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
+				 depthMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
+
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -906,15 +913,35 @@
 
 void
-QtGlRendererWidget::SetupProjection(const int w, const int h, const float angle)
-{
-  if (!mTopView)
-	GlRenderer::SetupProjection(w, h, angle);
-  else {
-	glViewport(0, 0, w, h);
+QtGlRendererWidget::SetupCameraProjection(const int w, const int h, const float angle)
+{
+  if (!mTopView) {
+	int ww = w*CAMERA_VIEW_WIDTH;
+	int hh = h;
+	glViewport(0, 0, ww, hh);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
+	gluPerspective(angle, ww/(float)hh, 0.1, 2.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
 	glMatrixMode(GL_MODELVIEW);
-  }
+  } else {
+	int ww = w*CAMERA_VIEW_WIDTH;
+	int hh = h;
+	glViewport(0, 0, ww, hh);
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	gluPerspective(50.0, ww/(float)hh, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal()));
+	glMatrixMode(GL_MODELVIEW);
+  }
+}
+
+void
+QtGlRendererWidget::SetupManipulatorProjection(const int w, const int h, const float angle)
+{
+  int ww = w*(1.0f - CAMERA_VIEW_WIDTH);
+  int hh = h;
+  glViewport(w - ww, 0, ww, hh);
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  gluPerspective(angle, ww/(float)hh, 1.0f, 40.0f);
+  glMatrixMode(GL_MODELVIEW);
 }
 
@@ -922,6 +949,5 @@
 QtGlRendererWidget::RenderPvs()
 {
-  SetupCamera();
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  
   
   ViewCell *viewcell = NULL;
@@ -987,5 +1013,4 @@
   mUseFalseColors = true;
 
-  SetupCamera();
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
@@ -1125,14 +1150,36 @@
   int x = e->pos().x();
   int y = e->pos().y();
-  
-  if (e->modifiers() & Qt::ControlModifier) {
-	mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
-	mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
+
+  int diffx = -(mousePoint.x - x);
+  int diffy = -(mousePoint.y - y);
+  
+  if (x < width()*CAMERA_VIEW_WIDTH) {
+	if (e->modifiers() & Qt::ControlModifier) {
+	  mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
+	  mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
+	} else {
+	  mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
+	  float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
+	  float angle = atan2(mViewDirection.x, mViewDirection.z);
+	  mViewDirection.x = sin(angle+adiff);
+	  mViewDirection.z = cos(angle+adiff);
+	}
   } else {
-	mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
-	float adiff = TURN_ANGLE*(x - mousePoint.x)*-TURN_SENSITIVITY;
-	float angle = atan2(mViewDirection.x, mViewDirection.z);
-	mViewDirection.x = sin(angle+adiff);
-	mViewDirection.z = cos(angle+adiff);
+	float W = width()*(1.0f-CAMERA_VIEW_WIDTH);
+	float H = height();
+	int xx = x - width()*CAMERA_VIEW_WIDTH;
+	int mxx = mousePoint.x - width()*CAMERA_VIEW_WIDTH;
+    if (e->modifiers() & Qt::ControlModifier) {
+	  mManipulatorScale = mManipulatorScale * (1.0 + (((float) (-diffy)) / H));
+	} else {
+	  float quat[4];
+	  trackball(quat,
+				(2.0 * mxx - W) / W,
+				(H - 2.0 * mousePoint.y) / H,
+				(2.0 * xx - W) / W,
+				(H - 2.0 * y) / H
+				);
+	  add_quats(quat, mManipulatorLastQuat, mManipulatorLastQuat);
+	}
   }
   
@@ -1153,5 +1200,5 @@
 QtGlRendererWidget::resizeGL(int w, int h)
 {
-  SetupProjection(w, h);
+  SetupCameraProjection(w, h);
   updateGL();
 }
@@ -1162,22 +1209,46 @@
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-  
-  if (!mRenderViewCells) {
-	if (mRenderErrors)
+  if (1) {
+	SetupCameraProjection(width(), height());
+	SetupCamera();
+	
+	if (mRenderErrors) {
 	  RenderErrors();
-	else
+	} else {
 	  RenderPvs();
+	}
+	
 	RenderInfo();
-  } else {
-	RenderViewCells();
-	
-	mWireFrame = true;
-	RenderScene();
-	mWireFrame = false;
-	
-	RenderInfo();
   }
 
   mFrame++;
+
+  if (1) {
+	// render into the right side of the window buffer
+	SetupManipulatorProjection(width(), height());
+	SetupManipulator();
+	
+	
+	if (mRenderViewCells) 
+	  RenderViewCells();
+	
+	RenderPvs();
+	
+	if (0) {
+	  mWireFrame = true;
+	  RenderScene();
+	  mWireFrame = false;
+	}
+	
+	if (mShowRays) {
+	  RssPreprocessor *p = (RssPreprocessor *)mViewCellsManager->GetPreprocessor();
+	  VssRayContainer rays;
+	  p->mRssTree->CollectRays(rays, 10000);
+	  RenderRays(rays);
+	}
+	
+  }
+  mFrame++;
+  
 }
 
@@ -1222,4 +1293,25 @@
 
 void
+QtGlRendererWidget::SetupManipulator()
+{
+  float m[4][4];
+
+  glLoadIdentity();
+  gluLookAt(0.0, 0.0, 30.0,  /* eye is at (0,0,30) */
+			0.0, 0.0, 0.0,      /* center is at (0,0,0) */
+			0.0, 1.0, 0.);      /* up is in positive Y direction */
+  
+  build_rotmatrix(m, mManipulatorLastQuat);
+  glMultMatrixf(&m[0][0]);
+  
+  float scale = mManipulatorScale*20.0f/Magnitude(mSceneGraph->GetBox().Diagonal());
+  glScalef(scale, scale, scale);
+  
+  Vector3 t = -mSceneGraph->GetBox().Center();
+  glTranslatef(t.x, t.y, t.z);
+  
+}
+
+void
 QtGlRendererWidget::keyPressEvent ( QKeyEvent * e )
 {
@@ -1227,5 +1319,5 @@
   case Qt::Key_T:
 	mTopView = !mTopView;
-	SetupProjection(width(), height());
+	SetupCameraProjection(width(), height());
 	updateGL();
 	break;
@@ -1248,5 +1340,6 @@
   
 
-QtGlRendererWidget::QtGlRendererWidget(SceneGraph *sceneGraph,
+QtGlRendererWidget::QtGlRendererWidget(
+									   SceneGraph *sceneGraph,
 									   ViewCellsManager *viewcells,
 									   KdTree *tree,
@@ -1265,5 +1358,6 @@
   mRenderErrors = false;
   mRenderFilter = true;
-
+  mManipulatorScale = 1.0f;
+  trackball(mManipulatorLastQuat, 0.0f, 0.0f, 0.0f, 0.0f);
   bool tmp;
 
@@ -1281,4 +1375,6 @@
   mPvsSize = 0;
   mRenderError = 0.0f;
+  mShowRays = false;
+  
   mControlWidget = new QtRendererControlWidget(NULL);
   
@@ -1302,5 +1398,10 @@
 		  this, SLOT(SetUseSpatialFilter(bool)));
 
-  
+  connect(mControlWidget,
+		  SIGNAL(SetShowRays(bool)),
+		  this,
+		  SLOT(SetShowRays(bool)));
+
+  resize(1000, 500);
   mControlWidget->show();
 }
@@ -1368,4 +1469,6 @@
 	  // init ortographic projection
 	  glMatrixMode(GL_PROJECTION);
+
+
 	  glPushMatrix();
 	  
@@ -1484,5 +1587,6 @@
   mUseFalseColors = true;
 
-  SetupCamera();
+  glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
+  
   glEnable(GL_CULL_FACE);
   //glDisable(GL_CULL_FACE);
@@ -1529,5 +1633,6 @@
   }
 
-  glDisable(GL_CLIP_PLANE0);
+
+  glPopAttrib();
 
 }
@@ -1633,4 +1738,9 @@
   cb->setChecked(false);
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
+
+  cb = new QCheckBox("Show rays", hbox);
+  hlayout->addWidget(cb);
+  cb->setChecked(false);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
 
   vbox->resize(800,100);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1581)
@@ -428,11 +428,11 @@
 	if (mLoadViewCells)
 	{	
-		Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
-		cout << "loading view cells from " << buf << endl;
-		
-		mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true);
-
-		if (!mViewCellsManager)
-			return false;
+	  Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
+	  cout << "loading view cells from " << buf << endl;
+	  
+	  mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true);
+	  
+	  if (!mViewCellsManager)
+		return false;
 	}
 	else
@@ -488,15 +488,16 @@
 
 	mViewCellsManager->SetRenderer(mRenderSimulator);
-
+	
 	if (mUseGlRenderer || mUseGlDebugger)
-	{
+	  {
 		// NOTE: render texture should be power of 2 and square
 		// renderer must be initialised
 		// $$matt
-//		renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree);
+		//		renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree);
 		//		renderer->makeCurrent();
 		
-	}
-	
+	  }
+
+	mViewCellsManager->SetPreprocessor(this);
 	return true;
 }
@@ -505,12 +506,12 @@
 bool Preprocessor::ConstructViewCells()
 {
-	// construct view cells using it's own set of samples
-	mViewCellsManager->Construct(this);
-
-	// visualizations and statistics
-	Debug << "finished view cells:" << endl;
-	mViewCellsManager->PrintStatistics(Debug);
-	    
-	return true;
+  // construct view cells using it's own set of samples
+  mViewCellsManager->Construct(this);
+  
+  // visualizations and statistics
+  Debug << "finished view cells:" << endl;
+  mViewCellsManager->PrintStatistics(Debug);
+  
+  return true;
 }
 
@@ -900,9 +901,9 @@
 	}
 
+	if (i % 10000 == 0)
+		cout<<".";
+
 #if DEBUB_RAYCAST
 	long t2 = GetTime();
-	if (i % 10000 == 0)
-		cout<<".";
-
 	if (castDoubleRays)
 		cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h	(revision 1387)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h	(revision 1581)
@@ -31,4 +31,5 @@
 class TransformedMeshInstance;
 
+
 struct VssRayContainer;
 struct PvsRenderStatistics; 
@@ -149,4 +150,5 @@
   void SetSpatialFilterSize(int);
 
+  void SetShowRays(bool);
   void SetRenderFilter(bool);
   void SetUseFilter(bool);
@@ -180,5 +182,6 @@
   bool mUseSpatialFilter;
   bool mShowRenderCost;
-  
+  bool mShowRays;
+
   bool mShowPvsSizes;
   float mSpatialFilterSize;
@@ -191,4 +194,8 @@
   float mRenderError;
 
+
+  float mManipulatorLastQuat[4];
+  float mManipulatorScale;
+  
   QtRendererControlWidget *mControlWidget;
   
@@ -202,4 +209,7 @@
 
   virtual void SetupCamera();
+  // setup a transformation for manipulator
+  void
+  SetupManipulator();
 
   void initializeGL() {
@@ -229,6 +239,12 @@
   virtual int GetHeight() const { return height(); }
 
- virtual void
-  SetupProjection(const int w, const int h, const float angle = 70.0f);
+  // virtual void
+  //  SetupProjection(const int w, const int h, const float angle = 70.0f);
+
+  virtual void
+  SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
+
+  virtual void
+  SetupManipulatorProjection(const int w, const int h, const float angle = 70.0f);
 
   void
@@ -280,4 +296,9 @@
   void SetShowViewCells(bool b) {
 	mRenderViewCells = b;
+	updateGL();
+  }
+
+  void SetShowRays(bool b) {
+	mShowRays = b;
 	updateGL();
   }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.h	(revision 1581)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.h	(revision 1581)
@@ -0,0 +1,78 @@
+/*
+ * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
+ * ALL RIGHTS RESERVED
+ * Permission to use, copy, modify, and distribute this software for
+ * any purpose and without fee is hereby granted, provided that the above
+ * copyright notice appear in all copies and that both the copyright notice
+ * and this permission notice appear in supporting documentation, and that
+ * the name of Silicon Graphics, Inc. not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.
+ *
+ * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
+ * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
+ * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
+ * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
+ * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
+ * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
+ * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
+ * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
+ * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
+ * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * US Government Users Restricted Rights
+ * Use, duplication, or disclosure by the Government is subject to
+ * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
+ * (c)(1)(ii) of the Rights in Technical Data and Computer Software
+ * clause at DFARS 252.227-7013 and/or in similar or successor
+ * clauses in the FAR or the DOD or NASA FAR Supplement.
+ * Unpublished-- rights reserved under the copyright laws of the
+ * United States.  Contractor/manufacturer is Silicon Graphics,
+ * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
+ *
+ * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
+ */
+/*
+ * trackball.h
+ * A virtual trackball implementation
+ * Written by Gavin Bell for Silicon Graphics, November 1988.
+ */
+
+/*
+ * Pass the x and y coordinates of the last and current positions of
+ * the mouse, scaled so they are from (-1.0 ... 1.0).
+ *
+ * The resulting rotation is returned as a quaternion rotation in the
+ * first paramater.
+ */
+void
+trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
+
+/*
+ * Given two quaternions, add them together to get a third quaternion.
+ * Adding quaternions to get a compound rotation is analagous to adding
+ * translations to get a compound translation.  When incrementally
+ * adding rotations, the first argument here should be the new
+ * rotation, the second and third the total rotation (which will be
+ * over-written with the resulting new total rotation).
+ */
+void
+add_quats(float *q1, float *q2, float *dest);
+
+/*
+ * A useful function, builds a rotation matrix in Matrix based on
+ * given quaternion.
+ */
+void
+build_rotmatrix(float m[4][4], float q[4]);
+
+/*
+ * This function computes a quaternion based on an axis (defined by
+ * the given vector) and an angle about which to rotate.  The angle is
+ * expressed in radians.  The result is put into the third argument.
+ */
+void
+axis_to_quat(float a[3], float phi, float q[4]);
+
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1563)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1581)
@@ -918,8 +918,11 @@
   }
 	  
+
+  // do not delete rss tree now - can be used for visualization..
+#if 0
   Debug<<"Deleting RSS tree...\n";
   delete mRssTree;
   Debug<<"Done.\n";
-
+#endif
 
   //mViewCellsManager->ExportViewCells("visibility.xml",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1579)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1581)
@@ -14,5 +14,5 @@
 # filename ../data/vienna/vienna-buildings.x3d
 # filename ../data/vienna/city1500_flat_1.x3d
-#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d
+#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
 #;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
@@ -44,5 +44,5 @@
 	type rss
 #	type render
-	detectEmptyViewSpace true
+	detectEmptyViewSpace false
 #	pvsRenderErrorSamples 0
 	pvsRenderErrorSamples 5000
@@ -54,4 +54,7 @@
 	visibilityFile visibility.xml
 	loadMeshes true
+	loadKdTree	false
+	exportKdTree false
+
 }
 
@@ -73,5 +76,5 @@
 	samplesPerPass 1000
 	initialSamples 1000000
-	vssSamples 10000000
+	vssSamples 50000000
 	vssSamplesPerPass 1000000
 	useImportanceSampling true
@@ -189,9 +192,10 @@
 	exportToFile true
 	loadFromFile true
-
+	
 	#type kdTree
 	#type vspKdTree
 	#type bspTree
 	type vspBspTree
+	#type vspOspTree
 	#type sceneDependent
 	
@@ -256,12 +260,14 @@
 #	filename ../data/soda/soda5-viewcells.xml
 #	filename ../scripts/viewcells_atlanta.xml
-#	filename ../data/soda/soda-viewcells-5000.xml
+	filename ../data/soda/soda-viewcells-5000.xml
 #	filename ../data/test1/test-viewcells.xml
 
 #	filename ../data/soda/soda5-viewcell-single.xm
-	filename ../data/soda/soda-viewcells-1000.xml.zip
+#	filename ../data/soda/soda-viewcells-1000.xml.zip
 #	filename ../data/CityModel/CityModel-viewcells-5000.xml
 #	filename ../data/City4M/City4M-viewcells-5000.xml
 
+
+#	filename ../data/vienna/vsposp-seq-viewCells.xml.gz
 
 #	filename ../data/atlanta/viewcells_atlanta3.xml
@@ -338,5 +344,5 @@
 #		minGlobalCostRatio      0.0001
 # $$MAXVIEWCELLS
-		maxViewCells		1
+		maxViewCells		1000
 	
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp	(revision 1581)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp	(revision 1581)
@@ -0,0 +1,324 @@
+/*
+ * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
+ * ALL RIGHTS RESERVED
+ * Permission to use, copy, modify, and distribute this software for
+ * any purpose and without fee is hereby granted, provided that the above
+ * copyright notice appear in all copies and that both the copyright notice
+ * and this permission notice appear in supporting documentation, and that
+ * the name of Silicon Graphics, Inc. not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission.
+ *
+ * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
+ * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
+ * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
+ * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
+ * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
+ * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
+ * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
+ * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
+ * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
+ * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * US Government Users Restricted Rights
+ * Use, duplication, or disclosure by the Government is subject to
+ * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
+ * (c)(1)(ii) of the Rights in Technical Data and Computer Software
+ * clause at DFARS 252.227-7013 and/or in similar or successor
+ * clauses in the FAR or the DOD or NASA FAR Supplement.
+ * Unpublished-- rights reserved under the copyright laws of the
+ * United States.  Contractor/manufacturer is Silicon Graphics,
+ * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
+ *
+ * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
+ */
+/*
+ * Trackball code:
+ *
+ * Implementation of a virtual trackball.
+ * Implemented by Gavin Bell, lots of ideas from Thant Tessman and
+ *   the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129.
+ *
+ * Vector manip code:
+ *
+ * Original code from:
+ * David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli
+ *
+ * Much mucking with by:
+ * Gavin Bell
+ */
+#include <math.h>
+#include "trackball.h"
+
+/*
+ * This size should really be based on the distance from the center of
+ * rotation to the point on the object underneath the mouse.  That
+ * point would then track the mouse as closely as possible.  This is a
+ * simple example, though, so that is left as an Exercise for the
+ * Programmer.
+ */
+#define TRACKBALLSIZE  (0.8)
+
+/*
+ * Local function prototypes (not defined in trackball.h)
+ */
+static float tb_project_to_sphere(float, float, float);
+static void normalize_quat(float [4]);
+
+void
+vzero(float *v)
+{
+    v[0] = 0.0;
+    v[1] = 0.0;
+    v[2] = 0.0;
+}
+
+void
+vset(float *v, float x, float y, float z)
+{
+    v[0] = x;
+    v[1] = y;
+    v[2] = z;
+}
+
+void
+vsub(const float *src1, const float *src2, float *dst)
+{
+    dst[0] = src1[0] - src2[0];
+    dst[1] = src1[1] - src2[1];
+    dst[2] = src1[2] - src2[2];
+}
+
+void
+vcopy(const float *v1, float *v2)
+{
+    register int i;
+    for (i = 0 ; i < 3 ; i++)
+        v2[i] = v1[i];
+}
+
+void
+vcross(const float *v1, const float *v2, float *cross)
+{
+    float temp[3];
+
+    temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
+    temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
+    temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
+    vcopy(temp, cross);
+}
+
+float
+vlength(const float *v)
+{
+    return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
+}
+
+void
+vscale(float *v, float div)
+{
+    v[0] *= div;
+    v[1] *= div;
+    v[2] *= div;
+}
+
+void
+vnormal(float *v)
+{
+    vscale(v,1.0/vlength(v));
+}
+
+float
+vdot(const float *v1, const float *v2)
+{
+    return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
+}
+
+void
+vadd(const float *src1, const float *src2, float *dst)
+{
+    dst[0] = src1[0] + src2[0];
+    dst[1] = src1[1] + src2[1];
+    dst[2] = src1[2] + src2[2];
+}
+
+/*
+ * Ok, simulate a track-ball.  Project the points onto the virtual
+ * trackball, then figure out the axis of rotation, which is the cross
+ * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0)
+ * Note:  This is a deformed trackball-- is a trackball in the center,
+ * but is deformed into a hyperbolic sheet of rotation away from the
+ * center.  This particular function was chosen after trying out
+ * several variations.
+ *
+ * It is assumed that the arguments to this routine are in the range
+ * (-1.0 ... 1.0)
+ */
+void
+trackball(float q[4], float p1x, float p1y, float p2x, float p2y)
+{
+    float a[3]; /* Axis of rotation */
+    float phi;  /* how much to rotate about axis */
+    float p1[3], p2[3], d[3];
+    float t;
+
+    if (p1x == p2x && p1y == p2y) {
+        /* Zero rotation */
+        vzero(q);
+        q[3] = 1.0;
+        return;
+    }
+
+    /*
+     * First, figure out z-coordinates for projection of P1 and P2 to
+     * deformed sphere
+     */
+    vset(p1,p1x,p1y,tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y));
+    vset(p2,p2x,p2y,tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y));
+
+    /*
+     *  Now, we want the cross product of P1 and P2
+     */
+    vcross(p2,p1,a);
+
+    /*
+     *  Figure out how much to rotate around that axis.
+     */
+    vsub(p1,p2,d);
+    t = vlength(d) / (2.0*TRACKBALLSIZE);
+
+    /*
+     * Avoid problems with out-of-control values...
+     */
+    if (t > 1.0) t = 1.0;
+    if (t < -1.0) t = -1.0;
+    phi = 2.0 * asin(t);
+
+    axis_to_quat(a,phi,q);
+}
+
+/*
+ *  Given an axis and angle, compute quaternion.
+ */
+void
+axis_to_quat(float a[3], float phi, float q[4])
+{
+    vnormal(a);
+    vcopy(a,q);
+    vscale(q,sin(phi/2.0));
+    q[3] = cos(phi/2.0);
+}
+
+/*
+ * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
+ * if we are away from the center of the sphere.
+ */
+static float
+tb_project_to_sphere(float r, float x, float y)
+{
+    float d, t, z;
+
+    d = sqrt(x*x + y*y);
+    if (d < r * 0.70710678118654752440) {    /* Inside sphere */
+        z = sqrt(r*r - d*d);
+    } else {           /* On hyperbola */
+        t = r / 1.41421356237309504880;
+        z = t*t / d;
+    }
+    return z;
+}
+
+/*
+ * Given two rotations, e1 and e2, expressed as quaternion rotations,
+ * figure out the equivalent single rotation and stuff it into dest.
+ *
+ * This routine also normalizes the result every RENORMCOUNT times it is
+ * called, to keep error from creeping in.
+ *
+ * NOTE: This routine is written so that q1 or q2 may be the same
+ * as dest (or each other).
+ */
+
+#define RENORMCOUNT 97
+
+void
+add_quats(float q1[4], float q2[4], float dest[4])
+{
+    static int count=0;
+    float t1[4], t2[4], t3[4];
+    float tf[4];
+
+    vcopy(q1,t1);
+    vscale(t1,q2[3]);
+
+    vcopy(q2,t2);
+    vscale(t2,q1[3]);
+
+    vcross(q2,q1,t3);
+    vadd(t1,t2,tf);
+    vadd(t3,tf,tf);
+    tf[3] = q1[3] * q2[3] - vdot(q1,q2);
+
+    dest[0] = tf[0];
+    dest[1] = tf[1];
+    dest[2] = tf[2];
+    dest[3] = tf[3];
+
+    if (++count > RENORMCOUNT) {
+        count = 0;
+        normalize_quat(dest);
+    }
+}
+
+/*
+ * Quaternions always obey:  a^2 + b^2 + c^2 + d^2 = 1.0
+ * If they don't add up to 1.0, dividing by their magnitued will
+ * renormalize them.
+ *
+ * Note: See the following for more information on quaternions:
+ *
+ * - Shoemake, K., Animating rotation with quaternion curves, Computer
+ *   Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985.
+ * - Pletinckx, D., Quaternion calculus as a basic tool in computer
+ *   graphics, The Visual Computer 5, 2-13, 1989.
+ */
+static void
+normalize_quat(float q[4])
+{
+    int i;
+    float mag;
+
+    mag = (q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]);
+    for (i = 0; i < 4; i++) q[i] /= mag;
+}
+
+/*
+ * Build a rotation matrix, given a quaternion rotation.
+ *
+ */
+void
+build_rotmatrix(float m[4][4], float q[4])
+{
+    m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
+    m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
+    m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
+    m[0][3] = 0.0;
+
+    m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
+    m[1][1]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
+    m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
+    m[1][3] = 0.0;
+
+    m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
+    m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
+    m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);
+    m[2][3] = 0.0;
+
+    m[3][0] = 0.0;
+    m[3][1] = 0.0;
+    m[3][2] = 0.0;
+    m[3][3] = 1.0;
+}
+
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 1457)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 1581)
@@ -24,5 +24,5 @@
   Camera camera;
   
-  if (0)
+  if (1)
 	{
 		// camera.LookAtBox(mPreprocessor->mKdTree->GetBox());
@@ -36,5 +36,5 @@
 	} 
   
-  if (0) {
+  if (2) {
 	camera.LookInBox(mPreprocessor->mKdTree->GetBox());
 	camera.SetPosition(camera.mPosition + Vector3(-250,0,-550));
@@ -42,5 +42,5 @@
   }
 
-  if (0) {
+  if (3) {
 	camera.SetPosition( mPreprocessor->mKdTree->GetBox().Center() - Vector3(0,-100,0) );
 	camera.SetDirection(Vector3(1, 0, 0));
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1580)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1581)
@@ -1856,27 +1856,28 @@
 			{			
 				if (viewcell->GetPvs().GetSampleContribution(
-							ray.mTerminationObject,
-							ray.mPdf,
-							contribution))
-				{
+															 ray.mTerminationObject,
+															 ray.mPdf,
+															 contribution))
+				  {
 					++ ray.mPvsContribution;
-					ray.mRelativePvsContribution += contribution;
-				}
+				  }
+				ray.mRelativePvsContribution += contribution;
+				
 			}
 			
 #if SAMPLE_ORIGIN_OBJECTS
-
+			
 			// for directional sampling it is important to count only contributions
 			// made in one direction!!!
 			// the other contributions of this sample will be counted for the oposite ray!
-
+			
 			if (ray.mOriginObject && 
 				viewcell->GetPvs().GetSampleContribution(ray.mOriginObject,
 														 ray.mPdf,
 														 contribution))
-			{
+			  {
 				++ ray.mPvsContribution;
-				ray.mRelativePvsContribution += contribution;
-			}
+			  }
+			ray.mRelativePvsContribution += contribution;
 #endif
 		}
@@ -5516,6 +5517,6 @@
 			{
 				++ ray.mPvsContribution;
-				ray.mRelativePvsContribution += contribution;
 			}
+			ray.mRelativePvsContribution += contribution;
 #endif
 		}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1146)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1581)
@@ -10,4 +10,6 @@
 #include "KdTree.h"
 #include "Environment.h"
+#include "Triangle3.h"
+#include "IntersectableWrapper.h"
 
 //#include <Cg/cg.h>
@@ -92,4 +94,15 @@
 
 void
+GlRenderer::RenderTriangle(TriangleIntersectable *object)
+{
+  Triangle3 &t = object->GetItem();
+  glBegin(GL_TRIANGLES);
+  glVertex3f(t.mVertices[0].x, t.mVertices[0].y, t.mVertices[0].z);
+  glVertex3f(t.mVertices[1].x, t.mVertices[1].y, t.mVertices[1].z);
+  glVertex3f(t.mVertices[2].x, t.mVertices[2].y, t.mVertices[2].z);
+  glEnd();
+}
+
+void
 GlRenderer::RenderIntersectable(Intersectable *object)
 {
@@ -105,9 +118,12 @@
 	break;
   case Intersectable::VIEW_CELL:
-	  RenderViewCell(dynamic_cast<ViewCell *>(object));
-	  break;
+	RenderViewCell(dynamic_cast<ViewCell *>(object));
+	break;
   case Intersectable::TRANSFORMED_MESH_INSTANCE:
-	  RenderTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
-	  break;
+	RenderTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
+	break;
+  case Intersectable::TRIANGLE_INTERSECTABLE:
+	RenderTriangle(dynamic_cast<TriangleIntersectable *>(object));
+	break;
   default:
 	cerr<<"Rendering this object not yet implemented\n";
@@ -118,4 +134,20 @@
 }
 
+void
+GlRenderer::RenderRays(const VssRayContainer &rays)
+{
+  VssRayContainer::const_iterator it = rays.begin(), it_end = rays.end();
+
+  glBegin(GL_LINES);
+  for (; it != it_end; ++it) {
+	VssRay *ray = *it;
+	float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f;
+	//	cout<<"w="<<ray->mWeightedPvsContribution<<" r="<<ray->mWeightedPvsContribution;
+	glColor3f(importance, importance, importance);
+	glVertex3fv(&ray->mOrigin.x);
+	glVertex3fv(&ray->mTermination.x);
+  }
+  glEnd();
+}
 
 void
@@ -310,4 +342,6 @@
   glMatrixMode(GL_MODELVIEW);
 }
+
+
 
 void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1579)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1581)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: pá 6. X 16:24:14 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: so 7. X 21:56:30 2006
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1233)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1581)
@@ -1013,5 +1013,5 @@
 			   );
 
-    int
+  int
   CollectRays(VssRayContainer &rays,
 			  const int number);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1563)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1581)
@@ -2881,4 +2881,5 @@
   int desired = min(number, (int)allRays.size());
   float prob = desired/(float)allRays.size();
+  //int skip = allRays.size()/desired;
   while (rays.size() < desired) {
 	VssRayContainer::const_iterator it = allRays.begin();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1580)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1581)
@@ -217,5 +217,5 @@
 												  preprocessor->mViewCellsManager,
 												  preprocessor->mKdTree);
-
+		  
 		  rendererWidget->Show();
 		  guiSupported = true; 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1387)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1581)
@@ -24,4 +24,5 @@
 class OcclusionQuery;
 class TransformedMeshInstance;
+class TriangleIntersectable;
 
 struct VssRayContainer;
@@ -99,5 +100,11 @@
   void SetupMaterial(Material *m);
   virtual void SetupCamera();
-  
+
+  void
+  RenderRays(const VssRayContainer &rays);
+
+  void
+  RenderTriangle(TriangleIntersectable *object);
+
   bool
   RenderScene();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro	(revision 1579)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro	(revision 1581)
@@ -117,5 +117,5 @@
 BvHierarchy.cpp  \
 BoostPreprocessorThread.cpp InternalRayCaster.cpp IntelRayCaster.cpp \
-RayCaster.cpp PreprocessorFactory.cpp GvsPreprocessor.cpp
+RayCaster.cpp PreprocessorFactory.cpp GvsPreprocessor.cpp Trackball.cpp
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1563)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1581)
@@ -439,5 +439,5 @@
 	if (element == "BoundingBox")
 	{
-		cout << "b";
+	  //		cout << "b";
 		StartBoundingBox(attributes);
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1581)
@@ -302,5 +302,4 @@
   const float dirEps = 1e-8f;
   register float minx, maxx;
-  ray.ComputeInvertedDir();
   
   if (fabs(ray.dir.x) < dirEps) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 1581)
@@ -31,5 +31,4 @@
 	*/
 	T GetItem() const;
-
 	/** See get.
 	*/
