Index: trunk/VUT/GtpVisibilityPreprocessor/src/Material.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Material.h	(revision 162)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Material.h	(revision 386)
@@ -32,5 +32,11 @@
   {
   }
-  
+
+	Material(const RgbColor &color):mDiffuseColor(color),
+																	mAmbientColor(color),
+																	mSpecularColor(0,0,0)
+	{
+	}
+
   friend Material RandomMaterial();
   
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h	(revision 312)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h	(revision 386)
@@ -42,4 +42,9 @@
   }
 
+	void SetDirection(const Vector3 &dir) {
+    mDirection = dir;
+    Precompute();
+  }
+
   void LookInBox(const AxisAlignedBox3 &box)
   {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h	(revision 386)
@@ -463,9 +463,34 @@
       VssTreeLeaf *leafa = (VssTreeLeaf *) a.node;
       VssTreeLeaf *leafb = (VssTreeLeaf *) b.node;
-      //      return leafa->rays.size()*a.bbox.GetVolume() < leafb->rays.size()*b.bbox.GetVolume();
-      return 
+#if 0
+			return
 				leafa->rays.size()*a.bbox.GetVolume()
 				<
 				leafb->rays.size()*b.bbox.GetVolume();
+#endif
+#if 0
+			return
+				leafa->mPvsSize*a.bbox.GetVolume()*
+				<
+				leafb->mPvsSize*b.bbox.GetVolume();
+#endif
+#if 0
+			return
+				leafa->mPvsSize
+				<
+				leafb->mPvsSize;
+#endif
+#if 1
+			return
+				leafa->mPvsSize/(leafa->rays.size()+1)
+				>
+				leafb->mPvsSize/(leafb->rays.size()+1);
+#endif
+#if o
+			return
+				leafa->mPvsSize*leafa->rays.size()
+				<
+				leafb->mPvsSize*leafb->rays.size();
+#endif
     }
   };
@@ -527,5 +552,5 @@
 
   // type of the splitting to use fo rthe tree construction
-  enum {ESplitRegular, ESplitVolume };
+  enum {ESplitRegular, ESplitHeuristic };
   int splitType;
 	
@@ -620,11 +645,25 @@
   
 	float
-	BestCostRatio(
-								VssTreeLeaf *node,
-								int &axis,
-								float &position,
-								int &raysBack,
-								int &raysFront
-								);
+	BestCostRatioHeuristic(
+												 VssTreeLeaf *node,
+												 int &axis,
+												 float &position,
+												 int &raysBack,
+												 int &raysFront,
+												 int &pvsBack,
+												 int &pvsFront
+												 );
+
+	float
+	BestCostRatioRegular(
+											 VssTreeLeaf *node,
+											 int &axis,
+											 float &position,
+											 int &raysBack,
+											 int &raysFront,
+											 int &pvsBack,
+											 int &pvsFront
+
+											 );
 	
 	float
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 383)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 386)
@@ -8,4 +8,5 @@
 #include "Material.h"
 #include "Containers.h"
+#include "VssRay.h"
 
 class KdTree;
@@ -49,15 +50,20 @@
   ExportBspTree(const BspTree &tree) = 0;
 
-  virtual bool
-  ExportRays(const vector<Ray> &rays,
-	     const float length=1000,
-	     const RgbColor &color = RgbColor(1,1,1)
-	     ) = 0;
+//    virtual bool
+//    ExportRays(const vector<Ray> &rays,
+//  	     const float length=1000,
+//  	     const RgbColor &color = RgbColor(1,1,1)
+//  	     ) = 0;
   
   virtual bool
   ExportRays(const RayContainer &rays,
-	     const float length=1000,
-	     const RgbColor &color = RgbColor(1,1,1)
-	     ) = 0;
+						 const float length=1000,
+						 const RgbColor &color = RgbColor(1,1,1)
+						 ) = 0;
+
+	virtual bool
+  ExportRays(const VssRayContainer &rays,
+						 const RgbColor &color = RgbColor(1,1,1)
+						 ) = 0;
 
   virtual void 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp	(revision 359)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp	(revision 386)
@@ -529,8 +529,8 @@
     mesh->AddRectangle(shaft->mSource);
     mesh->AddRectangle(shaft->mTarget);
-    vector<Ray> rays;
+    vector<Ray *> rays;
     for (int j=0; j < 4; j++) {
-      Ray ray;
-      shaft->GetRaySegment(j, ray);
+      Ray *ray = new Ray;
+      shaft->GetRaySegment(j, *ray);
       rays.push_back(ray);
     }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 386)
@@ -109,6 +109,6 @@
     splitType = ESplitRegular;
   else
-    if (name.compare("heuristics") == 0)
-      splitType = ESplitVolume;
+    if (name.compare("heuristic") == 0)
+      splitType = ESplitHeuristic;
 		else {
 			cerr<<"Invalid VssTree split type "<<name<<endl;
@@ -301,7 +301,15 @@
 
   
+	int lastMem = 0;
   while (!tStack.empty()) {
 
-    if ( GetMemUsage() > maxMemory ) {
+		float mem = GetMemUsage();
+		
+		if ( lastMem/10 != ((int)mem)/10) {
+			cout<<mem<<" MB"<<endl;
+		}
+		lastMem = (int)mem;
+		
+		if (  mem > maxMemory ) {
       // count statistics on unprocessed leafs
       while (!tStack.empty()) {
@@ -411,10 +419,13 @@
 		
 	} else {
-    if (splitType == ESplitVolume)
-      costRatio = BestCostRatio(leaf,
-																axis,
-																position,
-																raysBack,
-																raysFront);
+    if (splitType == ESplitHeuristic)
+      costRatio = BestCostRatioHeuristic(leaf,
+																				 axis,
+																				 position,
+																				 raysBack,
+																				 raysFront,
+																				 pvsBack,
+																				 pvsFront
+																				 );
 		else {
 			cerr<<"VssTree: Unknown split heuristics\n";
@@ -424,5 +435,5 @@
 
 	if (costRatio > termMaxCostRatio) {
-		cout<<"Too big cost ratio "<<costRatio<<endl;
+		//		cout<<"Too big cost ratio "<<costRatio<<endl;
 		return -1;
 	}
@@ -485,5 +496,7 @@
 					raysFront++;
 				
+#if BIDIRECTIONAL_RAY
 				AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront);
+#endif
 				AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront);
 
@@ -524,5 +537,7 @@
 				//				(*ri).mRay->mSide = side;
 
+#if BIDIRECTIONAL_RAY
 				AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront);
+#endif
 				AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront);
 
@@ -550,11 +565,29 @@
 
 float
-VssTree::BestCostRatio(
-											 VssTreeLeaf *node,
-											 int &axis,
-											 float &position,
-											 int &raysBack,
-											 int &raysFront
-											 )
+VssTree::BestCostRatioRegular(
+															VssTreeLeaf *node,
+															int &axis,
+															float &position,
+															int &raysBack,
+															int &raysFront,
+															int &pvsBack,
+															int &pvsFront
+															
+															)
+{
+	
+	return 0;
+}
+
+float
+VssTree::BestCostRatioHeuristic(
+																VssTreeLeaf *node,
+																int &axis,
+																float &position,
+																int &raysBack,
+																int &raysFront,
+																int &pvsBack,
+																int &pvsFront
+																)
 {
 	AxisAlignedBox3 box = GetBBox(node);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 383)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 386)
@@ -10,4 +10,5 @@
 #include "Exporter.h"
 #include "Containers.h"
+#include "VssRay.h"
 
 class SceneGraphNode;
@@ -30,8 +31,8 @@
 
 
-  bool
-  ExportRays(const vector<Ray> &rays,
-	     const float length=1000,
-	     const RgbColor &color = RgbColor(1,1,1));
+//    bool
+//    ExportRays(const vector<Ray> &rays,
+//  	     const float length=1000,
+//  	     const RgbColor &color = RgbColor(1,1,1));
 
   bool
@@ -82,7 +83,11 @@
   bool
   ExportRays(const RayContainer &rays,
-			 const float length=1000,
-			 const RgbColor &color = RgbColor(1,1,1));
+						 const float length=1000,
+						 const RgbColor &color = RgbColor(1,1,1));
 
+	bool
+	ExportRays(const VssRayContainer &rays,
+						 const RgbColor &color = RgbColor(1,1,1));
+		
   virtual void
   ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 386)
@@ -39,4 +39,6 @@
   Vector3 mTermination;
 	
+	/// Termination object for the ray
+	/// only the termination object is actually used
 	Intersectable *mOriginObject;
 	Intersectable *mTerminationObject;
@@ -62,4 +64,6 @@
 		Vector3 dir = GetDir();
 
+#define BIDIRECTIONAL_RAY 0
+#if BIDIRECTIONAL_RAY
 		if (dir.y < 0) {
 			// swap objects and poits	
@@ -68,5 +72,5 @@
 			dir = -dir;
 		}
-		
+#endif
 		if (dir.x > 0.0f) mFlags |= FPosDirX;
     if (dir.y > 0.0f) mFlags |= FPosDirY;
@@ -85,4 +89,5 @@
 
 	int HitCount() const {
+#if BIDIRECTIONAL_RAY
 		if (mOriginObject && mTerminationObject)
 			return 2;
@@ -90,4 +95,7 @@
 			return 1;
 		return 0;
+#else
+		return (mTerminationObject) ? 1 : 0;
+#endif
 	}
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 383)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 386)
@@ -36,5 +36,5 @@
 }
 
-VssRay * 
+int
 VssPreprocessor::CastRay(
 												 Vector3 &viewPoint,
@@ -42,4 +42,5 @@
 												 )
 {
+	int hits = 0;
 	static Ray ray;
 	AxisAlignedBox3 box = mKdTree->GetBox();
@@ -65,6 +66,12 @@
 		
 	}
-	
-	SetupRay(ray, viewPoint, -direction);
+
+	bool detectEmptyViewSpace = true;
+	
+	if (detectEmptyViewSpace) {
+		SetupRay(ray, pointA, -direction);
+	} else
+		SetupRay(ray, viewPoint, -direction);
+	
 	
 	if (mKdTree->CastRay(ray)) {
@@ -84,13 +91,25 @@
 
 	VssRay *vssRay  = NULL;
-	
-	if (objectA || objectB) {
+
+	if (objectA) {
+		vssRay = new VssRay(pointB,
+												pointA,
+												objectB,
+												objectA);
+		mVssRays.push_back(vssRay);
+		hits ++;
+	}
+	
+	if (objectB) {
 		vssRay = new VssRay(pointA,
 												pointB,
 												objectA,
 												objectB);
-	}
-	
-	return vssRay;
+		mVssRays.push_back(vssRay);
+		hits ++;
+
+	}
+	
+	return hits;
 }
 
@@ -156,10 +175,6 @@
 			Vector3 direction = GetDirection(viewpoint);
 			
-			VssRay *vssRay = CastRay(viewpoint, direction);
-			
-			if (vssRay) {
-				sampleContributions = vssRay->HitCount();
-				mVssRays.push_back(vssRay);
-			}
+			sampleContributions = CastRay(viewpoint, direction);
+			
 			
 			//-- CORR matt: put block inside loop
@@ -198,8 +213,37 @@
 	cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush;
 
+	cout<<"Exporting vss rays..."<<endl<<flush;
+	
+	int exportRays = 10000;
+
+	if (exportRays) {
+		float prob = exportRays/(float)mVssRays.size();
+		
+		Exporter *exporter = NULL;
+		exporter = Exporter::GetExporter("vss-rays.x3d");
+		exporter->SetWireframe();
+		exporter->ExportKdTree(*mKdTree);
+		if (viewSpaceBox) {
+			exporter->SetForcedMaterial(RgbColor(1,0,0));
+			exporter->ExportBox(*viewSpaceBox);
+			exporter->ResetForcedMaterial();
+		}
+		VssRayContainer rays;
+		for (int i=0; i < mVssRays.size(); i++)
+			if (RandomValue(0,1) < prob)
+				rays.push_back(mVssRays[i]);
+		exporter->ExportRays(rays, RgbColor(1, 0, 0));
+
+		delete exporter;
+	}
+	cout<<"done."<<endl<<flush;
+
 	VssTree *vssTree = new VssTree;
 
 	vssTree->Construct(mVssRays, viewSpaceBox);
-	
+
+	
+
+
   return true;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 374)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 386)
@@ -121,15 +121,21 @@
   }
 
+	Camera camera;
   if (0) {
-    Camera camera;
     //camera.LookAtBox(p->mKdTree->GetBox());
 		camera.LookInBox(p->mKdTree->GetBox());
 		camera.SetPosition(camera.mPosition + Vector3(0,300,0));
     camera.SnapImage("camera.jpg", p->mKdTree);
-		
-    
+	}
+	if (0) {
     camera.LookInBox(p->mKdTree->GetBox());
     camera.SetPosition(camera.mPosition - Vector3(0,100,0));
     camera.SnapImage("camera2.jpg", p->mKdTree);
+  }
+
+	if (0) {
+    camera.SetPosition( p->mKdTree->GetBox().Center() - Vector3(0,-100,0) );
+		camera.SetDirection(Vector3(1, 0, 0));
+		camera.SnapImage("camera3.jpg", p->mKdTree);
   }
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 383)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 386)
@@ -8,4 +8,5 @@
 #include "ViewCell.h"
 #include "Polygon3.h"
+#include "VssRay.h"
 
 X3dExporter::X3dExporter(const string filename):Exporter(filename)
@@ -26,56 +27,57 @@
 
 
-bool
-X3dExporter::ExportRays(const vector<Ray> &rays,
-			const float length,
-			const RgbColor &color)
-{
-  vector<Ray>::const_iterator ri = rays.begin();
-  stream<<"<Shape>"<<endl;
-  stream<<"<Appearance>"<<endl;
-  stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<
-    "\" />"<<endl;
-  stream<<"</Appearance>"<<endl;
-  
-  stream<<"<IndexedLineSet coordIndex=\""<<endl;
-
-  int index = 0;
-  for (; ri != rays.end(); ri++) {
-    stream<<index<<" "<<index+1<<" -1\n";
-    index+=2;
-  }
-  
-  stream<<"\" >"<<endl;
-  
-  stream<<"<Coordinate  point=\""<<endl;
-  
-  ri = rays.begin();
-  for (; ri != rays.end(); ri++) {
-    Vector3 a = (*ri).GetLoc();
+//  bool
+//  X3dExporter::ExportRays(const vector<Ray> &rays,
+//  												const float length,
+//  												const RgbColor &color)
+//  {
+//    vector<Ray>::const_iterator ri = rays.begin();
+//    stream<<"<Shape>"<<endl;
+//    stream<<"<Appearance>"<<endl;
+//    stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<
+//      "\" />"<<endl;
+//    stream<<"</Appearance>"<<endl;
+  
+//    stream<<"<IndexedLineSet coordIndex=\""<<endl;
+
+//    int index = 0;
+//    for (; ri != rays.end(); ri++) {
+//      stream<<index<<" "<<index+1<<" -1\n";
+//      index+=2;
+//    }
+  
+//    stream<<"\" >"<<endl;
+  
+//    stream<<"<Coordinate  point=\""<<endl;
+  
+//    ri = rays.begin();
+//    for (; ri != rays.end(); ri++) {
+//      Vector3 a = (*ri).GetLoc();
     
-    Vector3 b;
-    if (length < 0)
-      b = (*ri).GetLoc() - length*(*ri).GetDir();
-    else
-      if ((*ri).intersections.size()==0)
-	b = (*ri).GetLoc() + length*(*ri).GetDir();
-      else
-	b = (*ri).Extrap((*ri).intersections[0].mT);
+//      Vector3 b;
+//      if (length < 0)
+//        b = (*ri).GetLoc() - length*(*ri).GetDir();
+//      else
+//        if ((*ri).intersections.size()==0)
+//  	b = (*ri).GetLoc() + length*(*ri).GetDir();
+//        else
+//  	b = (*ri).Extrap((*ri).intersections[0].mT);
     
-    stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,";
-    stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n";
-  }
-  
-  stream<<"\" >"<<endl;
-  stream<<"</Coordinate>"<<endl;
-  stream<<"</IndexedLineSet>"<<endl;
-  stream<<"</Shape>"<<endl;
-  return true;
-}
+//      stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,";
+//      stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n";
+//    }
+  
+//    stream<<"\" >"<<endl;
+//    stream<<"</Coordinate>"<<endl;
+//    stream<<"</IndexedLineSet>"<<endl;
+//    stream<<"</Shape>"<<endl;
+//    return true;
+//  }
+
 
 bool
 X3dExporter::ExportRays(const RayContainer &rays,
-						const float length,
-						const RgbColor &color)
+												const float length,
+												const RgbColor &color)
 {
   RayContainer::const_iterator ri = rays.begin();
@@ -121,4 +123,45 @@
   stream<<"</Shape>"<<endl;
 
+  return true;
+}
+
+bool
+X3dExporter::ExportRays(const VssRayContainer &rays,
+												const RgbColor &color)
+{
+  VssRayContainer::const_iterator ri = rays.begin();
+
+  stream<<"<Shape>"<<endl;
+  stream<<"<Appearance>"<<endl;
+  stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<
+    "\" />"<<endl;
+  stream<<"</Appearance>"<<endl;
+  
+  stream<<"<IndexedLineSet coordIndex=\""<<endl;
+
+  int index = 0;
+  for (; ri != rays.end(); ri++) {
+    stream<<index<<" "<<index+1<<" -1\n";
+    index+=2;
+  }
+  
+  stream<<"\" >"<<endl;
+  
+  stream<<"<Coordinate  point=\""<<endl;
+  
+  ri = rays.begin();
+  for (; ri != rays.end(); ri++) {
+    Vector3 a = (*ri)->GetOrigin();
+    
+    Vector3 b = (*ri)->GetTermination();
+    stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,";
+    stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n";
+  }
+  
+  stream<<"\" >"<<endl;
+  stream<<"</Coordinate>"<<endl;
+  stream<<"</IndexedLineSet>"<<endl;
+  stream<<"</Shape>"<<endl;
+	
   return true;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 386)
@@ -11,7 +11,7 @@
 # filename ../data/vienna/vienna-buildings.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
-# filename ../data/atlanta/atlanta2.x3d
-#	filename ../data/soda/soda.dat
-filename ../data/soda/soda5.dat
+filename ../data/atlanta/atlanta2.x3d
+# filename ../data/soda/soda.dat
+# filename ../data/soda/soda5.dat
 }
 
@@ -22,5 +22,5 @@
 
 VssPreprocessor {
-	totalSamples 200000
+	totalSamples 1000000
 	samplesPerPass  50000
 }
@@ -32,9 +32,9 @@
 	minPvs		10
 	minSize		0.00001
-	maxCostRatio	1.0
-	maxRayContribution 0.5
+	maxCostRatio	0.95
+	maxRayContribution 0.2
 	
-	maxTotalMemory	500
-	maxStaticMemory	200
+	maxTotalMemory	400
+	maxStaticMemory	20
 
 	splitType regular
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 385)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 386)
@@ -386,5 +386,5 @@
   int pvsOut = Min((int)objects.size(), 10);
 
-  vector<Ray> rays[10];
+  RayContainer rays[10];
 
   while (totalSamples < mTotalSamples) {
@@ -455,6 +455,8 @@
 					}
 
-					if ( i < pvsOut )
-						rays[i].push_back(ray);
+					if ( i < pvsOut ) {
+						Ray *nray = new Ray(ray);
+						rays[i].push_back(nray);
+					}
 		
 					if (!ray.intersections.empty()) {
@@ -462,5 +464,6 @@
 						for (int j = 0; j < pvsOut; j++) {
 							if (objects[j] == ray.intersections[0].mObject) {
-								rays[j].push_back(ray);
+								Ray *nray = new Ray(ray);
+								rays[j].push_back(nray);
 							}
 						}
@@ -635,7 +638,7 @@
 
 		for (i=0; i < pvsOut; i++) 
-		exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0));
+			exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0));
 		exporter->SetFilled();
-		  
+		
 		delete exporter;
 	}
@@ -833,5 +836,5 @@
 		//-- some random view cells and rays for output
 		const int raysOut = min((int)mSampleRays.size(), 20000);
-		vector<Ray> vcRays[leafOut];
+		vector<Ray *> vcRays[leafOut];
 		vector<BspLeaf *> bspLeaves;
 		for (int i = 0; i < leafOut; ++ i)
@@ -852,5 +855,5 @@
 					if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 
 					{
-						vcRays[i].push_back(*ray);
+						vcRays[i].push_back(ray);
 					}
 				}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 386)
@@ -41,5 +41,5 @@
 
 	
-	VssRay * 
+	int
 	CastRay(
 					Vector3 &viewPoint,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 374)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp	(revision 386)
@@ -48,5 +48,5 @@
   //  - components*mWidth;
   
-  vector<Ray> rays;
+  vector<Ray *> rays;
 
   long t1 = GetTime();
@@ -74,6 +74,8 @@
       pbuffer+=components;
       
-      if (exportRays && (x==222) && (y==97))
-	rays.push_back(ray);
+      if (exportRays && (x==222) && (y==97)) {
+				Ray *nray = new Ray(ray);
+				rays.push_back(nray);
+			}
     }
     //    pbuffer-=2*components*mWidth;
@@ -97,21 +99,21 @@
     exporter->SetWireframe();
     exporter->ExportKdTree(*tree);
-	//exporter->ExportBspTree(*bsptree);
+		//exporter->ExportBspTree(*bsptree);
     exporter->ExportRays(rays, 10000);
     exporter->SetFilled();
     int k =0;
     for (int j=0; j < rays.size(); j++)
-      if (rays[j].kdLeaves.size()) {
-	Ray *ray = &(rays[j]);
-	int i;
-	if (1)
-	for (i= 0; i < ray->kdLeaves.size(); i++)
-	  exporter->ExportBox(tree->GetBox(ray->kdLeaves[i]));
-	if (0)
-		for (i= 0; i < ray->testedObjects.size(); i++)
-			exporter->ExportIntersectable(ray->testedObjects[i]);
-
+      if (rays[j]->kdLeaves.size()) {
+				Ray *ray = rays[j];
+				int i;
+				if (1)
+					for (i= 0; i < ray->kdLeaves.size(); i++)
+						exporter->ExportBox(tree->GetBox(ray->kdLeaves[i]));
+				if (0)
+					for (i= 0; i < ray->testedObjects.size(); i++)
+						exporter->ExportIntersectable(ray->testedObjects[i]);
+				
       }
-
+		
     delete exporter;
   }
