Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h	(revision 512)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.h	(revision 516)
@@ -300,4 +300,12 @@
   //
   /////////////////////////////////
+
+
+  // the bbox of the node
+  AxisAlignedBox3 bbox;
+  
+  // the bbox of the node
+  AxisAlignedBox3 dirBBox;
+
   
   inline RssTreeNode(RssTreeInterior *p);
@@ -333,9 +341,4 @@
   RssTreeNode *back, *front;
 
-  // the bbox of the node
-  AxisAlignedBox3 bbox;
-  
-  // the bbox of the node
-  AxisAlignedBox3 dirBBox;
 
   // data for caching
@@ -611,5 +614,7 @@
   /////////////////////////////
   // The core pointer
-  RssTreeNode *root;
+  vector<RssTreeNode *> mRoots;
+  
+  
   
   /////////////////////////////
@@ -618,4 +623,5 @@
   // total number of nodes of the tree
   int nodes;
+
   // axis aligned bounding box of the scene
   AxisAlignedBox3 bbox;
@@ -625,5 +631,5 @@
 
   // forced bounding box for from viewcell visibility
-  AxisAlignedBox3 *mForcedBoundingBox;
+  //  AxisAlignedBox3 *mForcedBoundingBox;
 
   /////////////////////////////
@@ -652,7 +658,9 @@
   float termMaxRayContribution;
 
-	
   // randomized construction
   bool randomize;
+
+  // use a root per object in the tree
+  bool mPerObjectTree;
   
   // type of the splitting to use fo rthe tree construction
@@ -711,6 +719,7 @@
   virtual void
   Construct(
-			VssRayContainer &rays,
-			AxisAlignedBox3 *forcedBoundingBox = NULL
+			ObjectContainer &objects,
+			VssRayContainer &rays
+			//			AxisAlignedBox3 *forcedBoundingBox = NULL
 			);
 	
@@ -849,19 +858,21 @@
   
   AxisAlignedBox3 GetBBox(const RssTreeNode *node) const {
-    if (node->parent == NULL)
-      return bbox;
-
-    if (!node->IsLeaf())
-      return ((RssTreeInterior *)node)->bbox;
-
-    if (node->parent->axis >= 3)
-      return node->parent->bbox;
+	return node->bbox;
+
+//     if (node->parent == NULL)
+//       return bbox;
+
+//     if (!node->IsLeaf())
+//       return ((RssTreeInterior *)node)->bbox;
+
+//     if (node->parent->axis >= 3)
+//       return node->parent->bbox;
       
-    AxisAlignedBox3 box(node->parent->bbox);
-    if (node->parent->front == node)
-      box.SetMin(node->parent->axis, node->parent->position);
-    else
-      box.SetMax(node->parent->axis, node->parent->position);
-    return box;
+//     AxisAlignedBox3 box(node->parent->bbox);
+//     if (node->parent->front == node)
+//       box.SetMin(node->parent->axis, node->parent->position);
+//     else
+//       box.SetMax(node->parent->axis, node->parent->position);
+//     return box;
   }
 
@@ -869,21 +880,21 @@
 
   AxisAlignedBox3 GetDirBBox(const RssTreeNode *node) const {
-
-    if (node->parent == NULL)
-      return dirBBox;
+	return node->dirBBox;
+//     if (node->parent == NULL)
+//       return dirBBox;
     
-    if (!node->IsLeaf() )
-      return ((RssTreeInterior *)node)->dirBBox;
-
-    if (node->parent->axis < 3)
-      return node->parent->dirBBox;
+//     if (!node->IsLeaf() )
+//       return ((RssTreeInterior *)node)->dirBBox;
+
+//     if (node->parent->axis < 3)
+//       return node->parent->dirBBox;
     
-    AxisAlignedBox3 dBBox(node->parent->dirBBox);
-
-    if (node->parent->front == node)
-      dBBox.SetMin(node->parent->axis - 3, node->parent->position);
-    else
-      dBBox.SetMax(node->parent->axis - 3, node->parent->position);
-    return dBBox;
+//     AxisAlignedBox3 dBBox(node->parent->dirBBox);
+
+//     if (node->parent->front == node)
+//       dBBox.SetMin(node->parent->axis - 3, node->parent->position);
+//     else
+//       dBBox.SetMax(node->parent->axis - 3, node->parent->position);
+//     return dBBox;
   }
   
@@ -978,5 +989,5 @@
 		  );
 
-  RssTreeNode *GetRoot() const { return root; }
+  RssTreeNode *GetRoot(Intersectable *object = NULL) const;
 
   bool
@@ -1053,5 +1064,15 @@
 					 vector<RssTreeLeaf::SilhouetteRays> &rays
 					 );
-  
+
+  void
+  PushRoots(priority_queue<TraversalData> &stack) const;
+
+  void
+  PushRoots(stack<RssTreeNode *> &st) const;
+
+  void
+  PushRoots(stack<RayTraversalData> &st, RssTreeNode::RayInfo &info) const;
+
+
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 516)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.0) on: so 7. I 10:49:27 2006
+# Generated by qmake (2.00a) (Qt 4.1.0) on: st 11. I 15:48:57 2006
 # Project:  preprocessor.pro
 # Template: app
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 511)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 516)
@@ -1649,4 +1649,6 @@
 	RegisterOption("RssTree.maxRays", optInt, "rss_max_rays=", "2000000");
 
+	RegisterOption("RssTree.perObjectTree", optBool, "rss_per_object_tree", "false");
+
 	RegisterOption("RssPreprocessor.Export.pvs", optBool, "rss_export_pvs", "false");
 	RegisterOption("RssPreprocessor.Export.rssTree", optBool, "rss_export_rss_tree", "false");
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssTree.cpp	(revision 516)
@@ -163,5 +163,7 @@
   environment->GetIntValue("RssTree.maxRays", mMaxRays);
 
-  root = NULL;
+  environment->GetBoolValue("RssTree.perObjectTree", mPerObjectTree);
+  
+  //  mRoots;
   
   splitCandidates = new vector<SortableEntry>;
@@ -171,6 +173,7 @@
 RssTree::~RssTree()
 {
-  if (root)
-    delete root;
+  for (int i=0; i < mRoots.size(); i++)
+	if (mRoots[i])
+	  delete mRoots[i];
 }
 
@@ -301,70 +304,96 @@
 void
 RssTree::Construct(
-				   VssRayContainer &rays,
+				   ObjectContainer &objects,
+				   VssRayContainer &rays
 				   // forced bounding box is only used when computing from-box
 				   // visibility
-				   AxisAlignedBox3 *forcedBoundingBox
+				   //				   AxisAlignedBox3 *forcedBoundingBox
 				   )
 {
+  cout<<"Constructing rss tree"<<endl<<flush;
   stat.Start();
   
   maxMemory = maxStaticMemory;
 
-  if (root)
-    delete root;
-
-  
-  root = new RssTreeLeaf(NULL, rays.size());
-  // first construct a leaf that will get subdivide
-  RssTreeLeaf *leaf = (RssTreeLeaf *) root;
-
-  stat.nodes = 1;
-  
-  bbox.Initialize();
-  dirBBox.Initialize();
-
-
-  mForcedBoundingBox = forcedBoundingBox;
+  //  if (root)
+  //    delete root;
+
+  if (mPerObjectTree) {
+	// get max id from the rays
+	int i;
+	mRoots.resize(objects.size());
+	for (i = 0; i < objects.size(); i++) {
+	  RssTreeLeaf *leaf = new RssTreeLeaf(NULL, 0);
+	  //	  leaf->bbox.Initialize();
+	  leaf->dirBBox.Initialize();
+	  leaf->dirBBox.SetMin(2, 0.0f);
+	  leaf->dirBBox.SetMax(2, 1.0f);
+	  
+	  mRoots[i] = leaf;
+	}
+	// init spatial bounding boxes
+	for (i = 0; i < objects.size(); i++) {
+	  GetRoot(objects[i])->bbox = objects[i]->GetBox();
+	}
+
+	stat.nodes = i;
+  } else {
+	mRoots.resize(1);
+	RssTreeLeaf *leaf = new RssTreeLeaf(NULL, rays.size());
+	leaf->bbox.Initialize();
+	leaf->dirBBox.Initialize();
+	leaf->dirBBox.SetMin(2, 0.0f);
+	leaf->dirBBox.SetMax(2, 1.0f);
+	mRoots[0] = leaf;
+	stat.nodes = 1;
+  }
+
   for(VssRayContainer::const_iterator ri = rays.begin();
-      ri != rays.end();
-      ri++) {
-		
-	RssTreeNode::RayInfo info(*ri);
-	if (forcedBoundingBox)
-	  if (!ClipRay(info, *forcedBoundingBox))
-		continue;
-
-	leaf->AddRay(info);
-		
-    bbox.Include((*ri)->GetOrigin());
-    bbox.Include((*ri)->GetTermination());
-    
-		
-	dirBBox.Include(Vector3(
-							(*ri)->GetDirParametrization(0),
-							(*ri)->GetDirParametrization(1),
-							0
-							)
-					);
-  }
-  
+	  ri != rays.end();
+	  ri++) {
+	
+	  RssTreeNode::RayInfo info(*ri);
+	  
+	  // first construct a leaf that will get subdivide
+	  RssTreeLeaf *leaf = (RssTreeLeaf *) GetRoot(info.GetObject());
+
+	  leaf->AddRay(info);
+	  
+	  // leaf bbox contains bbox of origins only
+	  leaf->bbox.Include((*ri)->GetOrigin());
+	  
+	  // include both origin and terminatin in the global bbox
+	  bbox.Include((*ri)->GetOrigin());
+	  bbox.Include((*ri)->GetTermination());
+	  
+	  Vector3 dVec = Vector3(
+							 (*ri)->GetDirParametrization(0),
+							 (*ri)->GetDirParametrization(1),
+							 0
+							 );
+
+	  leaf->dirBBox.Include(dVec);
+	  dirBBox.Include(dVec);
+  }
+
   // make the z axis (unused) a unit size
   // important for volume computation
-  dirBBox.SetMin(2, 0.0f);
-  dirBBox.SetMax(2, 1.0f);
-  
-  if ( forcedBoundingBox ) 
-	bbox = *forcedBoundingBox;
-	
+
+  
+  //  if ( forcedBoundingBox ) 
+  //	bbox = *forcedBoundingBox;
+  
   cout<<"Bbox = "<<bbox<<endl;
   cout<<"Dirr Bbox = "<<dirBBox<<endl;
-
-  stat.rays = leaf->rays.size();
-  UpdatePvsSize(leaf);
-
-  stat.initialPvsSize = leaf->GetPvsSize();
-  // Subdivide();
-  root = Subdivide(TraversalData(leaf, bbox, 0));
-
+  
+  stat.rays = rays.size();
+  stat.initialPvsSize = 0;
+  for (int i=0; i < mRoots.size(); i++) {
+	RssTreeLeaf *leaf = (RssTreeLeaf *)mRoots[i];
+	stat.initialPvsSize += leaf->GetPvsSize();
+	UpdatePvsSize(leaf);
+	mRoots[i] = Subdivide(TraversalData(leaf, GetBBox(leaf), 0));
+  }
+  
   if (splitCandidates) {
     // force realease of this vector
@@ -386,6 +415,7 @@
   //  stack<TraversalData> tStack;
   
-  tStack.push(TraversalData(root, bbox, 0));
-	
+  //  tStack.push(TraversalData(root, bbox, 0));
+  PushRoots(tStack);
+			
   AxisAlignedBox3 backBox;
   AxisAlignedBox3 frontBox;
@@ -1071,13 +1101,12 @@
   node->axis = axis;
   node->position = info.position;
-  node->bbox = box;
-  node->dirBBox = GetDirBBox(leaf);
-  
-  backBBox = box;
-  frontBBox = box;
+  //  node->bbox = box;
+  //  node->dirBBox = GetDirBBox(leaf);
+  
   
   RssTreeLeaf *back = new RssTreeLeaf(node, info.raysBack);
   RssTreeLeaf *front = new RssTreeLeaf(node, info.raysFront);
 
+  
   // update halton generator
   back->halton.index = leaf->halton.index;
@@ -1089,10 +1118,18 @@
   // and setup child links
   node->SetupChildLinks(back, front);
-	
+
+  back->bbox = leaf->bbox;
+  front->bbox = leaf->bbox;
+  back->dirBBox = leaf->dirBBox;
+  front->dirBBox = leaf->dirBBox;
+  
   if (axis <= RssTreeNode::SPLIT_Z) {
-	backBBox.SetMax(axis, info.position);
-    frontBBox.SetMin(axis, info.position);
-  }
-
+	back->bbox.SetMax(axis, info.position);
+    front->bbox.SetMin(axis, info.position);
+  } else {
+	back->dirBBox.SetMax(axis-3, info.position);
+    front->dirBBox.SetMin(axis-3, info.position);
+  }
+  
   for(RssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();
 	  ri != leaf->rays.end();
@@ -1117,6 +1154,4 @@
   // distribute the total number of rays according to the distribution
   // of rays which remained
-  
-  
   //  front->mTotalRays = front->rays.size()*leaf->mTotalRays/leaf->rays.size();
   //  back->mTotalRays = back->rays.size()*leaf->mTotalRays/leaf->rays.size();
@@ -1157,5 +1192,5 @@
   int released;
 
-  tstack.push(root);
+  PushRoots(tstack);
 
   while (!tstack.empty()) {
@@ -1267,6 +1302,6 @@
       ri++) {
 	RssTreeNode::RayInfo info(*ri);
-	if (mForcedBoundingBox==NULL || ClipRay(info, bbox))
-	  AddRay(info);
+	//	if (mForcedBoundingBox==NULL || ClipRay(info, bbox))
+	AddRay(info);
   }
 
@@ -1294,5 +1329,5 @@
   stack<RayTraversalData> tstack;
 
-  tstack.push(RayTraversalData(root, RssTreeNode::RayInfo(ray)));
+  PushRoots(tstack, RssTreeLeaf::RayInfo(ray));
   
   RayTraversalData data;
@@ -1374,5 +1409,6 @@
 
   stack<RayTraversalData> tstack;
-  
+
+  RssTreeNode *root = GetRoot(info.GetObject());
   tstack.push(RayTraversalData(root, info));
   
@@ -1534,5 +1570,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
 
   Intersectable::NewMail();
@@ -1581,5 +1617,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
   
   Intersectable::NewMail();
@@ -1625,5 +1661,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
 	
   float sumPvsSize = 0.0f;
@@ -1695,5 +1731,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
 	
   while (!tstack.empty()) {
@@ -1730,5 +1766,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
 	
   while (!tstack.empty()) {
@@ -2310,5 +2346,5 @@
 	float contributionThreshold = allRays[desired]->mWeightedPvsContribution;
 	
-	tstack.push(root);
+	PushRoots(tstack);
 	
 	while (!tstack.empty()) {
@@ -2328,5 +2364,5 @@
   } else {
 	// prune random rays from each leaf so that the ratio's remain the same
-	tstack.push(root);
+	PushRoots(tstack);
 	float ratio = desired/(float)stat.rayRefs;
 	
@@ -2413,5 +2449,5 @@
 {
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
 
   int sumPvs = 0;
@@ -2705,5 +2741,5 @@
 
   stack<RssTreeNode *> tstack;
-  tstack.push(root);
+  PushRoots(tstack);
   
   while (!tstack.empty()) {
@@ -2731,2 +2767,35 @@
 }
 
+
+RssTreeNode *
+RssTree::GetRoot(Intersectable *object) const
+{
+  if (mPerObjectTree && object) {
+	int id = object->GetId();
+	if (id >= mRoots.size())
+	  id = mRoots.size()-1; // $$ last tree is used by all unsigned objects
+	return mRoots[id];
+  } else
+	return mRoots[0];
+}
+
+void
+RssTree::PushRoots(priority_queue<TraversalData> &st) const
+{
+  for (int i=0; i < mRoots.size(); i++)
+	st.push(TraversalData(mRoots[i], GetBBox(mRoots[i]), 0));
+}
+
+void
+RssTree::PushRoots(stack<RssTreeNode *> &st)  const
+{
+  for (int i=0; i < mRoots.size(); i++)
+	st.push(mRoots[i]);
+}
+
+void
+RssTree::PushRoots(stack<RayTraversalData> &st, RssTreeNode::RayInfo &info)  const
+{
+  for (int i=0; i < mRoots.size(); i++)
+	st.push(RayTraversalData(mRoots[i], info));
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 508)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 516)
@@ -15,4 +15,7 @@
 static bool useViewSpaceBox = true;
 static bool use2dSampling = false;
+
+
+// not supported anymore!
 static bool fromBoxVisibility = false;
 
@@ -644,8 +647,8 @@
   if (mUseImportanceSampling) {
 	
-	if (fromBoxVisibility)
-	  rssTree->Construct(mVssRays, mViewSpaceBox);
-	else
-	  rssTree->Construct(mVssRays, NULL);
+	//	if (fromBoxVisibility)
+	//	  rssTree->Construct(mObjects, mVssRays, mViewSpaceBox);
+	//	else
+	rssTree->Construct(mObjects, mVssRays);
 
 	rssTree->stat.Print(mStats);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 507)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 516)
@@ -69,5 +69,5 @@
 RssPreprocessor {
 	samplesPerPass  100000
-	initialSamples 1000000
+	initialSamples 500000
 	vssSamples 10000000
 	vssSamplesPerPass 500000
@@ -94,4 +94,5 @@
 
 	epsilon		1e-6
+	perObjectTree true
 
 	maxDepth 	40
@@ -105,7 +106,7 @@
 	maxStaticMemory	100
 
-#	splitType regular
+	splitType regular
 #	splitType heuristic
-	splitType hybrid
+#	splitType hybrid
 	splitUseOnlyDrivingAxis true
 	importanceBasedCost false
@@ -169,6 +170,6 @@
 	#type kdTree
 	#type vspKdTree
-	# type bspTree
-	type vspBspTree
+	type bspTree
+	#type vspBspTree
 	
 	#type sceneDependent
Index: trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 505)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 516)
@@ -4,4 +4,5 @@
 
 #win32:INCLUDEPATH += c:/STLport-4.6.2/stlport
+win32:INCLUDEPATH += "d:/Programs/NVIDIA Corporation/Cg/include"
 
 unix:INCLUDEPATH += ../support/src/xerces-c-src_2_7_0/include
@@ -10,5 +11,5 @@
 
 
-win32:LIBPATH += ../support/xerces/lib ../support/devil/lib
+win32:LIBPATH += ../support/xerces/lib ../support/devil/lib "d:/Programs/NVIDIA Corporation/Cg/lib"
 unix:LIBPATH += ../support/src/xerces-c-src_2_7_0/lib ../support/devil/lib /usr/lib/qt3/lib64
 
@@ -25,5 +26,5 @@
 QT += opengl
 
-win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib
+win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib cg.lib cgGL.lib
 unix:LIBS += -lxerces-c -lIL -lILU -lILUT
 
@@ -43,4 +44,4 @@
 RenderSimulator.cpp VspKdTree.cpp RayInfo.cpp RssTree.cpp RssPreprocessor.cpp \
 ViewCellsManager.cpp VspBspTree.cpp GlRenderer.cpp \
-PreprocessorThread.cpp Renderer.cpp Beam.cpp
+PreprocessorThread.cpp Renderer.cpp Beam.cpp ViewCellsParser.cpp
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 513)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 516)
@@ -406,9 +406,7 @@
 {
   static int glList = -1;
-  if (glList != -1) {
-	glCallList(glList);
-  } else {
+  if (glList == -1) {
 	glList = glGenLists(1);
-	glNewList(glList, GL_COMPILE_AND_EXECUTE);
+	glNewList(glList, GL_COMPILE);
 	ObjectContainer::const_iterator oi = mObjects.begin();
 	for (; oi != mObjects.end(); oi++)
@@ -416,4 +414,5 @@
 	glEndList();
   }
+  glCallList(glList);
   return true;
 }
@@ -571,5 +570,5 @@
 											   Beam &beam,
 											   const int desiredSamples,
-											   BeamSampleStatistics &stat)
+											   GlRendererBuffer::BeamSampleStatistics &stat)
 {
 	// TODO: should not be done every time here
@@ -607,4 +606,5 @@
 		
 		SampleViewpointContributions(sourceObject,
+									 viewPoint,
 									 beam,
 									 directionalSamples,
@@ -624,4 +624,5 @@
 
 void GlRendererBuffer::SampleViewpointContributions(Intersectable *sourceObject,
+													const Vector3 viewPoint,
 													Beam &beam,
 													const int desiredSamples,
