Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2005)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2017)
@@ -189,12 +189,15 @@
 				GlobalOptimizations="TRUE"
 				InlineFunctionExpansion="2"
-				FavorSizeOrSpeed="1"
+				EnableIntrinsicFunctions="TRUE"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="TRUE"
 				EnableFiberSafeOptimizations="TRUE"
 				OptimizeForProcessor="3"
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\Qt&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include&quot;;QtInterface"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT3"
-				RuntimeLibrary="2"
-				RuntimeTypeInfo="TRUE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT"
+				RuntimeLibrary="2"
+				EnableEnhancedInstructionSet="2"
+				RuntimeTypeInfo="FALSE"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1960)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 2017)
@@ -202,5 +202,5 @@
 		if (!node->IsLeaf()) 
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 								
 			BspNodeGeometry *front = new BspNodeGeometry();
@@ -220,5 +220,5 @@
 			if (maxPvs)
 			{
-				BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+				BspLeaf *leaf = static_cast<BspLeaf *>(node);
 
 				mForcedMaterial.mDiffuseColor.b = 1.0f;
@@ -816,5 +816,5 @@
 		if (node->IsLeaf()) 
 		{
-			ViewCell *vc = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+			ViewCell *vc = static_cast<BspLeaf *>(node)->GetViewCell();
 #if 0     
 			// set the mesh material according to the ray density
@@ -990,5 +990,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode);
+			BspInterior *interior = static_cast<BspInterior *>(tData.mNode);
 
 			// add current side of split plane
@@ -1107,5 +1107,5 @@
 		if (!node->IsLeaf())
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			// bounded plane is added to the polygons
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2017)
@@ -273,5 +273,5 @@
 		case Intersectable::MESH_INSTANCE:
 			{
-				Mesh *mesh = dynamic_cast<MeshInstance *>(object)->GetMesh();
+				Mesh *mesh = static_cast<MeshInstance *>(object)->GetMesh();
 				AddMeshToPolygons(mesh, polys);
 			}
@@ -279,5 +279,5 @@
 		case Intersectable::VIEW_CELL:
 			{
-				Mesh *mesh = dynamic_cast<ViewCell *>(object)->GetMesh();
+				Mesh *mesh = static_cast<ViewCell *>(object)->GetMesh();
 				AddMeshToPolygons(mesh, polys);
 				break;
@@ -286,5 +286,5 @@
 			{
 				TransformedMeshInstance *mi = 
-					dynamic_cast<TransformedMeshInstance *>(object);
+					static_cast<TransformedMeshInstance *>(object);
 
 				Mesh mesh;
@@ -296,5 +296,5 @@
 			{
 				TriangleIntersectable *intersect = 
-					dynamic_cast<TriangleIntersectable *>(object);
+					static_cast<TriangleIntersectable *>(object);
 
 				Polygon3 *poly = new Polygon3(intersect->GetItem());
@@ -762,5 +762,5 @@
 		
 		Plane3 splitPlane;
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);
+		BspLeaf *leaf = static_cast<BspLeaf *>(tData.mNode);
 		
 		// choose next split plane
@@ -817,5 +817,5 @@
 	if (newNode->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode);
+		BspLeaf *leaf = static_cast<BspLeaf *>(newNode);
 		
 		BspViewCell *viewCell = new BspViewCell();
@@ -961,5 +961,5 @@
 	if (newNode->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode);
+		BspLeaf *leaf = static_cast<BspLeaf *>(newNode);
 
 		BspViewCell *viewCell = new BspViewCell();
@@ -1037,5 +1037,5 @@
 	VspBspTraversalData backData;
 	
-	BspLeaf *leaf = dynamic_cast<BspLeaf *>(splitCandidate.mParentData.mNode);
+	BspLeaf *leaf = static_cast<BspLeaf *>(splitCandidate.mParentData.mNode);
 	
 	// compute locally best split plane
@@ -1109,5 +1109,5 @@
 									   PolygonContainer &coincident)
 {
-	BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);
+	BspLeaf *leaf = static_cast<BspLeaf *>(tData.mNode);
 	
 	//-- the front and back traversal data is filled with the new values
@@ -2205,5 +2205,5 @@
 			if (node->IsLeaf())
 			{
-				BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+				BspLeaf *leaf = static_cast<BspLeaf *>(node);
 			
 				if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid())
@@ -2215,5 +2215,5 @@
 			else 
 			{
-				BspInterior *interior = dynamic_cast<BspInterior *>(node);
+				BspInterior *interior = static_cast<BspInterior *>(node);
 			
 				BspNode *first = interior->GetFront();
@@ -2398,5 +2398,5 @@
 		{
 			// test if this leaf is in valid view space
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 			if (leaf->TreeValid() && 
 				(!onlyUnmailed || !leaf->Mailed()) &&
@@ -2408,5 +2408,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			nodeStack.push(interior->GetBack());
@@ -2432,5 +2432,5 @@
 {
 	// the node became a leaf -> evaluate stats for leafs
-	BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode);
+	BspLeaf *leaf = static_cast<BspLeaf *>(data.mNode);
 
 
@@ -2508,5 +2508,5 @@
 		if (!node->IsLeaf())
 		{
-			BspInterior *in = dynamic_cast<BspInterior *>(node);
+			BspInterior *in = static_cast<BspInterior *>(node);
 
 			Plane3 splitPlane = in->GetPlane();
@@ -2550,5 +2550,5 @@
 		else // reached leaf => intersection with view cell
 		{
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 
 			if (!leaf->GetViewCell()->Mailed())
@@ -2612,5 +2612,5 @@
 			if (!onlyValid || node->TreeValid())
 			{
-				ViewCellLeaf *leafVc = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+				ViewCellLeaf *leafVc = static_cast<BspLeaf *>(node)->GetViewCell();
 
 				ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leafVc);
@@ -2625,5 +2625,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2652,9 +2652,9 @@
 		if (node->IsLeaf())
         {
-			BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+			BspViewCell *viewCell = static_cast<BspLeaf *>(node)->GetViewCell();
 
 			if (!viewCell->GetValid())
 			{
-				BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+				BspViewCell *viewCell = static_cast<BspLeaf *>(node)->GetViewCell();
 	
 				ViewCellContainer leaves;
@@ -2665,5 +2665,5 @@
 				for (it = leaves.begin(); it != it_end; ++ it)
 				{
-					BspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf;
+					BspLeaf *l = static_cast<BspViewCell *>(*it)->mLeaf;
 					l->SetViewCell(GetOrCreateOutOfBoundsCell());
 					++ mBspStats.invalidLeaves;
@@ -2677,5 +2677,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2723,5 +2723,5 @@
 		if (node->IsLeaf())
 		{
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 
 			if (!leaf->GetViewCell()->GetValid())
@@ -2737,5 +2737,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2880,6 +2880,6 @@
 		if (n)
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(n);
-			Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane();
+			BspInterior *interior = static_cast<BspInterior *>(n);
+			Plane3 halfSpace = static_cast<BspInterior *>(interior)->GetPlane();
 
             if (interior->GetBack() != lastNode)
@@ -3023,5 +3023,5 @@
 			continue;
 		
-		BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it);
+		BspViewCell *bspVc = static_cast<BspViewCell *>(*it);
 		vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end();
 
@@ -3110,5 +3110,5 @@
 				if (isAdjacent)
 				{	
-					neighbors.push_back(dynamic_cast<BspLeaf *>(node));
+					neighbors.push_back(static_cast<BspLeaf *>(node));
 				}
 			}
@@ -3116,5 +3116,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(),
@@ -3204,5 +3204,5 @@
 				if (isAdjacent)
 				{	
-					neighbors.push_back(dynamic_cast<BspLeaf *>(node));
+					neighbors.push_back(static_cast<BspLeaf *>(node));
 				}
 			}
@@ -3210,5 +3210,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(),
@@ -3271,9 +3271,9 @@
 		if (node->IsLeaf())
 		{
-			return dynamic_cast<BspLeaf *>(node);
+			return static_cast<BspLeaf *>(node);
 		}
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 			BspNode *next;
 			BspNodeGeometry geom;
@@ -3324,9 +3324,9 @@
 		{
 			if ( (!onlyUnmailed || !node->Mailed()) )
-				return dynamic_cast<BspLeaf *>(node);
+				return static_cast<BspLeaf *>(node);
 		}
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			// random decision
@@ -3452,5 +3452,5 @@
 		if (!node->IsLeaf())
 		{
-			BspInterior *in = dynamic_cast<BspInterior *>(node);
+			BspInterior *in = static_cast<BspInterior *>(node);
 
 			Plane3 splitPlane = in->GetPlane();
@@ -3499,5 +3499,5 @@
 		{
 			// reached leaf => intersection with view cell
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 			ViewCell *viewCell;
 			
@@ -3577,5 +3577,5 @@
 		return node;
 
-	BspInterior *interior = dynamic_cast<BspInterior *>(node);
+	BspInterior *interior = static_cast<BspInterior *>(node);
 
 	BspNode *front = CollapseTree(interior->GetFront(), collapsed);
@@ -3584,6 +3584,6 @@
 	if (front->IsLeaf() && back->IsLeaf())
 	{
-		BspLeaf *frontLeaf = dynamic_cast<BspLeaf *>(front);
-		BspLeaf *backLeaf = dynamic_cast<BspLeaf *>(back);
+		BspLeaf *frontLeaf = static_cast<BspLeaf *>(front);
+		BspLeaf *backLeaf = static_cast<BspLeaf *>(back);
 
 		//-- collapse tree
@@ -3643,5 +3643,5 @@
 		if (node->IsLeaf())
 		{
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 
 			BspViewCell *viewCell = leaf->GetViewCell();
@@ -3658,5 +3658,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			nodeStack.push(interior->GetFront());
@@ -3699,5 +3699,5 @@
 			if (node->IsLeaf())
 			{
-				BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+				BspLeaf *leaf = static_cast<BspLeaf *>(node);
 			
 				if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid())
@@ -3709,5 +3709,5 @@
 			else 
 			{
-				BspInterior *interior = dynamic_cast<BspInterior *>(node);
+				BspInterior *interior = static_cast<BspInterior *>(node);
 			
 				BspNode *first = interior->GetFront();
@@ -3837,5 +3837,5 @@
 
 		iit = ray->mViewCells.begin();
-		BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++));
+		BspViewCell *bspVc = static_cast<BspViewCell *>(*(iit ++));
 		BspLeaf *leaf = bspVc->mLeaves[0];
 		
@@ -3846,5 +3846,5 @@
 			// next pair
 			BspLeaf *prevLeaf = leaf;
-			bspVc = dynamic_cast<BspViewCell *>(*iit);
+			bspVc = static_cast<BspViewCell *>(*iit);
             leaf = bspVc->mLeaves[0]; // exactly one leaf
 
@@ -3929,10 +3929,10 @@
 		if (node->IsLeaf()) 
 		{
-			viewcell = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+			viewcell = static_cast<BspLeaf *>(node)->GetViewCell();
 			break;
 		} 
 		else 	
 		{	
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
         
 			// random decision
@@ -3964,5 +3964,5 @@
 			return false;
 			
-		BspInterior *in = dynamic_cast<BspInterior *>(node);
+		BspInterior *in = static_cast<BspInterior *>(node);
 					
 		if (in->GetPlane().Side(viewPoint) <= 0) 
@@ -4000,5 +4000,5 @@
 		{
             node = node->GetParent();
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 			
 			// the parent is valid iff both leaves are valid
@@ -4021,5 +4021,5 @@
 	if (node->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+		BspLeaf *leaf = static_cast<BspLeaf *>(node);
 		ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
 
@@ -4032,5 +4032,5 @@
 	else
 	{
-		BspInterior *interior = dynamic_cast<BspInterior *>(node);
+		BspInterior *interior = static_cast<BspInterior *>(node);
 	
 		Plane3 plane = interior->GetPlane();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2017)
@@ -77,4 +77,5 @@
 };
 
+typedef pair<ViewCell *, SimpleRayContainer> ViewCellPoints;
 
 /**	Manages different higher order operations on the view cells.
@@ -513,7 +514,34 @@
 	virtual void CompressViewCells();
 
+	ViewCell *GetViewCellById(const int id);
+
+	/** Returns number of view cells.
+	*/
 	int GetNumViewCells() const;
 
-	/////////////////////////////
+	bool GenerateRandomViewCells(ViewCellContainer &viewCells, 
+								 const int numViewCells);
+
+	bool GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells,
+								 const int nViewCells,
+								 const int nViewPoints);
+
+
+	bool GenerateViewPoints(ViewCell *viewCell, 
+							const int numViewPoints,
+							SimpleRayContainer &viewPoints);
+
+	bool ImportRandomViewCells(const string &filename, 
+							   vector<ViewCellPoints *> &viewCells);
+
+
+	bool ExportRandomViewCells(const string &filename,
+							   const vector<ViewCellPoints *> &viewCells);
+
+	bool GenerateViewPoint(ViewCell *viewCell, SimpleRay &ray);
+
+	bool IsValidViewSpace(ViewCell *vc);
+
+	//////////////
 	// static members
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 1923)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 2017)
@@ -498,5 +498,5 @@
 		if (!tData.mNode->IsLeaf())
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode);
+			BspInterior *interior = static_cast<BspInterior *>(tData.mNode);
 
 			///////////////////
@@ -636,12 +636,12 @@
 		{
 		case Intersectable::MESH_INSTANCE:
-			mesh = dynamic_cast<MeshInstance *>(object)->GetMesh();
+			mesh = static_cast<MeshInstance *>(object)->GetMesh();
 			break;
 		case Intersectable::VIEW_CELL:
-			mesh = dynamic_cast<ViewCell *>(object)->GetMesh();
+			mesh = static_cast<ViewCell *>(object)->GetMesh();
 			break;
 		case Intersectable::TRANSFORMED_MESH_INSTANCE:
 			{
-				TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object);
+				TransformedMeshInstance *mi = static_cast<TransformedMeshInstance *>(object);
 
 				if (!mi->GetMesh())	
@@ -801,5 +801,5 @@
 		if (!ray->intersections.empty())
 		{
-			MeshInstance *obj = dynamic_cast<MeshInstance *>(ray->intersections[0].mObject);
+			MeshInstance *obj = static_cast<MeshInstance *>(ray->intersections[0].mObject);
 
 			Mesh *mesh;
@@ -807,5 +807,5 @@
 			{
 				TransformedMeshInstance *tmobj = 
-					dynamic_cast<TransformedMeshInstance *>(obj);
+					static_cast<TransformedMeshInstance *>(obj);
 			
 				mesh = new Mesh();
@@ -1006,5 +1006,5 @@
 	if (TerminationCriteriaMet(tData))		
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);
+		BspLeaf *leaf = static_cast<BspLeaf *>(tData.mNode);
 	
 		BspViewCell *viewCell;
@@ -1017,5 +1017,5 @@
 		{	
 			// add predefined view cell to leaf
-			viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell);
+			viewCell = static_cast<BspViewCell *>(tData.mViewCell);
 
 			// out of bounds cell can be handled as any other view cell,
@@ -1154,10 +1154,10 @@
 		if (DotProd((*it)->GetNormal(), splitPlane.mNormal) > 0)
 		{
-			backData.mViewCell = dynamic_cast<ViewCellLeaf *>((*it)->mParent);
+			backData.mViewCell = static_cast<ViewCellLeaf *>((*it)->mParent);
 			foundBack = true;
 		}
 		else
 		{
-			frontData.mViewCell = dynamic_cast<ViewCellLeaf *>((*it)->mParent);
+			frontData.mViewCell = static_cast<ViewCellLeaf *>((*it)->mParent);
 			foundFront = true;
 		}
@@ -1173,5 +1173,5 @@
 	mStat.nodes += 2;
 	
-	BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);	
+	BspLeaf *leaf = static_cast<BspLeaf *>(tData.mNode);	
 	
 	// select subdivision plane
@@ -1972,5 +1972,5 @@
 		else 
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			nodeStack.push(interior->GetBack());
@@ -1990,5 +1990,5 @@
 {
 	// the node became a leaf -> evaluate stats for leafs
-	BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode);
+	BspLeaf *leaf = static_cast<BspLeaf *>(data.mNode);
 
 	// store maximal and minimal depth
@@ -2055,5 +2055,5 @@
 		if (!node->IsLeaf()) 
 		{
-			BspInterior *in = dynamic_cast<BspInterior *>(node);
+			BspInterior *in = static_cast<BspInterior *>(node);
 			
 			Plane3 splitPlane = in->GetPlane();
@@ -2097,5 +2097,5 @@
 		} else // reached leaf => intersection with view cell
 		{
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
       
 			if (!leaf->mViewCell->Mailed())
@@ -2154,5 +2154,5 @@
 		if (!node->IsLeaf())  
 		{
-			BspInterior *in = dynamic_cast<BspInterior *>(node);
+			BspInterior *in = static_cast<BspInterior *>(node);
 
 			Plane3 splitPlane = in->GetPlane();
@@ -2202,5 +2202,5 @@
 		{
 			// reached leaf => intersection with view cell
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+			BspLeaf *leaf = static_cast<BspLeaf *>(node);
 		
 			if (!leaf->mViewCell->Mailed()) 
@@ -2246,5 +2246,5 @@
 		if (node->IsLeaf()) 
 		{
-			ViewCellLeaf *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell;
+			ViewCellLeaf *viewCell = static_cast<BspLeaf *>(node)->mViewCell;
 
 			if (!viewCell->Mailed()) 
@@ -2256,5 +2256,5 @@
 		else 
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			nodeStack.push(interior->GetFront());
@@ -2372,6 +2372,6 @@
 		if (n)
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(n);
-			Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane();
+			BspInterior *interior = static_cast<BspInterior *>(n);
+			Plane3 halfSpace = static_cast<BspInterior *>(interior)->GetPlane();
 
             if (interior->GetBack() != lastNode)
@@ -2403,5 +2403,5 @@
 			continue;
 
-		BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*it);
+		BspViewCell *bspVc = static_cast<BspViewCell *>(*it);
 		vector<BspLeaf *>::const_iterator bit, bit_end = bspVc->mLeaves.end();
 
@@ -2592,5 +2592,5 @@
 				if (isAdjacent)
 				{	
-					neighbors.push_back(dynamic_cast<BspLeaf *>(node));
+					neighbors.push_back(static_cast<BspLeaf *>(node));
 				}
 			}
@@ -2598,5 +2598,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(),
@@ -2660,9 +2660,9 @@
 		{
 			if ( (!onlyUnmailed || !node->Mailed()) )
-				return dynamic_cast<BspLeaf *>(node);
+				return static_cast<BspLeaf *>(node);
 		}
 		else 
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			// random decision
@@ -2829,5 +2829,5 @@
 
 		iit = ray->mViewCells.begin();
-		BspViewCell *bspVc = dynamic_cast<BspViewCell *>(*(iit ++));
+		BspViewCell *bspVc = static_cast<BspViewCell *>(*(iit ++));
 		BspLeaf *leaf = bspVc->mLeaves[0];
 		
@@ -2838,5 +2838,5 @@
 			// next pair
 			BspLeaf *prevLeaf = leaf;
-			bspVc = dynamic_cast<BspViewCell *>(*iit);
+			bspVc = static_cast<BspViewCell *>(*iit);
             leaf = bspVc->mLeaves[0];
 
@@ -3340,5 +3340,5 @@
 		if (node->IsLeaf()) 
 		{
-			viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell;
+			viewcell = static_cast<BspLeaf *>(node)->mViewCell;
 			break;
 		} 
@@ -3346,5 +3346,5 @@
 		{
 
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			// random decision
@@ -3375,5 +3375,5 @@
 	if (node->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+		BspLeaf *leaf = static_cast<BspLeaf *>(node);
 		ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
 
@@ -3384,5 +3384,5 @@
 	else
 	{
-		BspInterior *interior = dynamic_cast<BspInterior *>(node);
+		BspInterior *interior = static_cast<BspInterior *>(node);
 	
 		Plane3 plane = interior->GetPlane();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2012)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2017)
@@ -208,11 +208,18 @@
 	cout << "done.\n";
 
+	cout << "deleting render simulator ... \n";
 	DEL_PTR(mRenderSimulator);
+	mRenderSimulator = NULL;
+	cout << "deleting renderer ... \n";
 	DEL_PTR(renderer);
+	renderer = NULL;
+	cout << "deleting ray caster ... \n";
 	DEL_PTR(mRayCaster);
 
 #ifdef USE_CG
+	cout << "deleting global lines renderer ... \n";
 	DEL_PTR(mGlobalLinesRenderer);
 #endif
+	cout << "finished" << endl;
 }
 
@@ -336,5 +343,5 @@
 		if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
 		{
-			Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
+			Triangle3 tri = static_cast<TriangleIntersectable *>(obj)->GetItem();
 
 			samplesOut.write(reinterpret_cast<char *>(tri.mVertices + 0), sizeof(Vector3));
@@ -370,5 +377,5 @@
 		if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
 		{
-			Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
+			Triangle3 tri = static_cast<TriangleIntersectable *>(obj)->GetItem();
 			//if (!(bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2])))continue;
 			
@@ -391,8 +398,8 @@
 		if (obj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
 		{
-			//Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
+			//Triangle3 tri = static_cast<TriangleIntersectable *>(obj)->GetItem();
 			//if (!(bbox.IsInside(tri.mVertices[0]) && bbox.IsInside(tri.mVertices[1]) && bbox.IsInside(tri.mVertices[2]))) continue;
 			
-			Triangle3 tri = dynamic_cast<TriangleIntersectable *>(obj)->GetItem();
+			Triangle3 tri = static_cast<TriangleIntersectable *>(obj)->GetItem();
 			samplesOut << "f " << i << " " << i + 1 << " " << i + 2 << endl;
 			i += 3;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1977)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2017)
@@ -213,6 +213,10 @@
 				Name="VCCLCompilerTool"
 				Optimization="3"
+				GlobalOptimizations="TRUE"
 				InlineFunctionExpansion="0"
-				FavorSizeOrSpeed="0"
+				EnableIntrinsicFunctions="TRUE"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="TRUE"
+				EnableFiberSafeOptimizations="TRUE"
 				OptimizeForProcessor="3"
 				OptimizeForWindowsApplication="TRUE"
@@ -221,7 +225,8 @@
 				ExceptionHandling="TRUE"
 				RuntimeLibrary="2"
+				EnableEnhancedInstructionSet="2"
 				DisableLanguageExtensions="FALSE"
 				ForceConformanceInForLoopScope="FALSE"
-				RuntimeTypeInfo="TRUE"
+				RuntimeTypeInfo="FALSE"
 				UsePrecompiledHeader="0"
 				BrowseInformation="1"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 1984)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 2017)
@@ -12,5 +12,5 @@
 {
 
-  Q_OBJECT
+  //Q_OBJECT
 
 	friend class QtGlRendererWidget;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj	(revision 1969)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj	(revision 2017)
@@ -180,7 +180,5 @@
 				Name="VCMIDLTool"/>
 			<Tool
-				Name="VCPostBuildEventTool"
-				Description="&quot;copy dll to preprocessor dir&quot;"
-				CommandLine="copy Release\*.dll ..\..\bin\"/>
+				Name="VCPostBuildEventTool"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1707)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 2017)
@@ -225,5 +225,5 @@
 		if (!node->IsLeaf()) 
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 								
 			BspNodeGeometry *front = new BspNodeGeometry();
@@ -243,5 +243,5 @@
 			if (maxPvs)
 			{
-				BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
+				BspLeaf *leaf = static_cast<BspLeaf *>(node);
 
 				mForcedMaterial.mDiffuseColor.b = 1.0f;
@@ -584,5 +584,5 @@
 		SetFilled();
 		SetForcedMaterial(RandomMaterial());
-		ExportGeometry(dynamic_cast<KdLeaf *>(node)->mObjects);	
+		ExportGeometry(static_cast<KdLeaf *>(node)->mObjects);	
 		SetWireframe();
 	}
@@ -764,5 +764,5 @@
 		if (node->IsLeaf()) 
 		{
-			ViewCell *vc = dynamic_cast<BspLeaf *>(node)->GetViewCell();
+			ViewCell *vc = static_cast<BspLeaf *>(node)->GetViewCell();
 #if 0     
 			// set the mesh material according to the ray density
@@ -918,5 +918,5 @@
 		else
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode);
+			BspInterior *interior = static_cast<BspInterior *>(tData.mNode);
 
 			// add current side of split plane
@@ -1035,5 +1035,5 @@
 		if (!node->IsLeaf())
 		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
+			BspInterior *interior = static_cast<BspInterior *>(node);
 
 			// bounded plane is added to the polygons
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2012)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2017)
@@ -262,7 +262,8 @@
 	/////////////////////////
 
-  GlobalLinesRenderer *mGlobalLinesRenderer;
-  RayCaster *mRayCaster;
-  /// samples used for construction of the BSP view cells tree.
+	GlobalLinesRenderer *mGlobalLinesRenderer;
+
+	RayCaster *mRayCaster;
+	/// samples used for construction of the BSP view cells tree.
 	int mBspConstructionSamples;
 	/// samples used for construction of the VSP OSP tree.
@@ -281,5 +282,5 @@
 };
 
-  extern Preprocessor *preprocessor;
+extern Preprocessor *preprocessor;
 
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2005)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2017)
@@ -490,5 +490,5 @@
 {
 	BvhSubdivisionCandidate *sc = 
-		dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate);
+		static_cast<BvhSubdivisionCandidate *>(splitCandidate);
 	BvhTraversalData &tData = sc->mParentData;
 
@@ -1994,5 +1994,5 @@
 	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
 	{
-        VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit);
+        VspViewCell *vc = static_cast<VspViewCell *>(*vit);
 		VspLeaf *leaf = vc->mLeaves[0];
 	
@@ -2060,5 +2060,5 @@
 		if (node->IsLeaf()) 
 		{
-			leaf = dynamic_cast<BvhLeaf *>(node);
+			leaf = static_cast<BvhLeaf *>(node);
 
 			if (IsObjectInLeaf(leaf, object))
@@ -2070,5 +2070,5 @@
 		{	
 			// find point
-			BvhInterior *interior = dynamic_cast<BvhInterior *>(node);
+			BvhInterior *interior = static_cast<BvhInterior *>(node);
         
 			if (interior->GetBack()->GetBoundingBox().Includes(object->GetBox()))
@@ -2112,5 +2112,5 @@
 	if (node->IsLeaf())
 	{
-		BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node);
+		BvhLeaf *leaf = static_cast<BvhLeaf *>(node);
 		const AxisAlignedBox3 box = leaf->GetBoundingBox();
 		stream << "<Leaf"
@@ -2127,5 +2127,5 @@
 	else
 	{	
-		BvhInterior *interior = dynamic_cast<BvhInterior *>(node);
+		BvhInterior *interior = static_cast<BvhInterior *>(node);
 		const AxisAlignedBox3 box = interior->GetBoundingBox();
 
@@ -2215,5 +2215,5 @@
 	
 	// root and bounding box was already constructed
-	BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot);
+	BvhLeaf *bvhLeaf = static_cast<BvhLeaf *>(mRoot);
 	
 	// only rays intersecting objects in node are interesting
@@ -2226,6 +2226,5 @@
 	// create bvh traversal data
 	BvhTraversalData oData(bvhLeaf, 0, prop, nRays);
-	cout << "here4" << endl;
-	
+		
 	// create sorted object lists for the first data
 	if (mUseGlobalSorting)
@@ -2234,5 +2233,4 @@
 	}
 	
-	cout << "here6" << endl;
 	///////////////////
 	//-- add first candidate for object space partition	
@@ -2267,5 +2265,5 @@
 		for (cit = candidateContainer.begin(); cit != cit_end; ++ cit)
 		{
-			BvhSubdivisionCandidate *sCandidate = dynamic_cast<BvhSubdivisionCandidate *>(*cit);
+			BvhSubdivisionCandidate *sCandidate = static_cast<BvhSubdivisionCandidate *>(*cit);
 			
 			// reevaluate priority
@@ -2295,5 +2293,4 @@
 	for (int i = 0; i < 3; ++ i)
 	{
-		cout << "here2 " << endl;
 		SortableEntryContainer *sortedObjects = new SortableEntryContainer();
 
@@ -2316,5 +2313,5 @@
 		delete sortedObjects;
 	}
-cout << "here102" << endl;
+
 	// last sorted list: by size
 	tData.mSortedObjects[3] = new ObjectContainer();
@@ -2390,5 +2387,5 @@
 
 	const int nRays = CountRays(objects);
-	BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot);
+	BvhLeaf *bvhLeaf = static_cast<BvhLeaf *>(mRoot);
 
 	// create bvh traversal data
@@ -2517,5 +2514,5 @@
 {
 	BvhSubdivisionCandidate *sc = 
-		dynamic_cast<BvhSubdivisionCandidate *>(splitCandidate);
+		static_cast<BvhSubdivisionCandidate *>(splitCandidate);
 	BvhTraversalData &tData = sc->mParentData;
 
@@ -2531,5 +2528,5 @@
 		BvhTraversalData tBackData;
 			
-		BvhInterior *oldInterior = dynamic_cast<BvhInterior *>(oldNode);
+		BvhInterior *oldInterior = static_cast<BvhInterior *>(oldNode);
 		
 		sc->mFrontObjects.clear();
@@ -2667,5 +2664,5 @@
 
 		BvhSubdivisionCandidate *bsc = 
-			dynamic_cast<BvhSubdivisionCandidate *>(candidate);
+			static_cast<BvhSubdivisionCandidate *>(candidate);
 
 		if (!InitialTerminationCriteriaMet(bsc->mParentData))
@@ -2767,10 +2764,10 @@
 		if (node->IsLeaf())
 		{
-			BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node);
+			BvhLeaf *leaf = static_cast<BvhLeaf *>(node);
 			node->mRenderCost = EvalAbsCost(leaf->mObjects);
 		}
 		else
 		{
-			BvhInterior *interior = dynamic_cast<BvhInterior *>(node);
+			BvhInterior *interior = static_cast<BvhInterior *>(node);
 		
 			node->mRenderCost = GetRenderCostIncrementially(interior->GetFront()) + 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2017)
@@ -238,8 +238,4 @@
 		mEvaluationSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION;
 	}
-	/*else if (strcmp(buf, "interior") == 0)
-	{
-		mEvaluationSamplingType = SamplingStrategy::OBJECTS_INTERIOR_DISTRIBUTION;
-	}*/
 	else
 	{
@@ -311,4 +307,295 @@
 
 
+ViewCell *ViewCellsManager::GetViewCellById(const int id)
+{
+	ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();
+
+	for (vit = mViewCells.begin(); vit != vit_end; ++ vit)
+	{
+		if ((*vit)->GetId() == id)
+			return (*vit);
+	}
+	return NULL;
+}
+
+
+bool ViewCellsManager::ExportRandomViewCells(const string &filename,
+											 const vector<ViewCellPoints *> &viewCells)
+{
+	std::ofstream outStream;
+	outStream.open(filename.c_str());
+
+	vector<ViewCellPoints *>::const_iterator vit, vit_end = viewCells.end();
+    
+	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
+	{
+		ViewCell *vc = (*vit)->first;
+
+		outStream << "v " << vc->GetId() << endl;
+
+		SimpleRayContainer viewPoints;
+	
+		SimpleRayContainer::const_iterator pit, pit_end = (*vit)->second.end();
+
+		for (pit = (*vit)->second.begin(); pit != pit_end; ++ pit)
+		{
+			const Vector3 pt = (*pit).mOrigin;
+			const Vector3 dir = (*pit).mDirection;
+
+			outStream << "p " << pt.x  << " " << pt.y  << " " << pt.z 
+				      << " "  << dir.x << " " << dir.y << " " << dir.z << endl;
+		}
+	}
+
+	return true;
+}
+
+
+bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells,
+											   const int nViewCells,
+											   const int nViewPoints)
+{
+	ViewCellContainer rViewCells;
+
+	cout << "generating " << nViewCells << " random view cells" << endl;
+	GenerateRandomViewCells(rViewCells, nViewCells);
+
+	cout << "finished" << endl;
+
+	//for (int i = 0; i < viewCells.size(); ++ i)
+	//	cout << "vc " << i << ": " << viewCells[i]->GetId() << endl;
+
+	cout << "generating " << nViewPoints << " view points per view cell" << endl;
+	ViewCellContainer::const_iterator vit, vit_end = rViewCells.end();
+    
+	for (vit = rViewCells.begin(); vit != vit_end; ++ vit)
+	{
+		ViewCell *vc = *vit;
+
+		ViewCellPoints *vcPts = new ViewCellPoints();
+		viewCells.push_back(vcPts);
+
+		vcPts->first = vc;
+
+		SimpleRayContainer viewPoints;
+		// generate random view points
+		GenerateViewPoints(vc, nViewPoints, viewPoints);
+		
+		SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end();
+
+		for (pit = viewPoints.begin(); pit != pit_end; ++ pit)
+		{
+			vcPts->second.push_back(*pit);	
+		}
+	}
+
+	return true;
+}
+
+
+bool ViewCellsManager::ImportRandomViewCells(const string &filename, 
+											 vector<ViewCellPoints *> &viewCells)
+{
+	ifstream inStream(filename.c_str());
+	if (!inStream.is_open())
+		return false;
+
+	ViewCellPoints *currentViewCell = NULL;
+
+ 	string buf;
+	while (!(getline(inStream, buf)).eof())
+	{
+		switch (buf[0])
+		{
+		case 'v':
+			{
+				int id;
+				sscanf(buf.c_str(), "v %d", &id);
+			
+				currentViewCell = new ViewCellPoints();
+				currentViewCell->first = GetViewCellById(id);
+						
+				viewCells.push_back(currentViewCell);
+				break;
+			}
+		case 'p':
+			{
+				Vector3 pt, dir;
+				sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z);
+				
+				SimpleRay ray(pt, dir, 0, 1);
+				currentViewCell->second.push_back(ray);
+				break;
+			}
+		default:
+			break;
+		}
+	}
+
+	return true;
+}
+
+
+bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell, 
+										  const int numViewPoints,
+										  SimpleRayContainer &viewPoints)
+{
+	bool success = true;
+	int generatedPts = 0;
+	int i = 0;
+
+	while (generatedPts < numViewPoints)
+	{
+		SimpleRay pt;
+
+		if (GenerateViewPoint(viewCell, pt))
+		{
+			++ generatedPts;
+			viewPoints.push_back(pt);
+		}
+
+		// savety criterium
+		if (++ i > numViewPoints + 100000)
+		{
+			return false;
+		}
+	}
+	
+	return true;
+}
+
+
+bool ViewCellsManager::GenerateViewPoint(ViewCell *viewCell, 
+										 SimpleRay &ray)
+{
+	// do not use this function since it could return different viewpoints for
+	// different executions of the algorithm
+	int tries = 0;
+	Vector3 viewPoint, direction;
+	const int maxTries = 100;
+
+	while (1) 
+	{
+		// hack
+		if (!viewCell->GetMesh())
+			CreateMesh(viewCell);
+
+        Mesh *mesh = viewCell->GetMesh();
+		AxisAlignedBox3 box = mesh->mBox;
+		//cout <<"box: " << box << endl;
+		/*Vector3 pVector = Vector3(halton.GetNumber(1),
+								  halton.GetNumber(2),
+								  halton.GetNumber(3));*/
+
+		Vector3 pVector = Vector3(Random(1.0f),
+								  Random(1.0f),
+								  Random(1.0f));
+
+		viewPoint =  box.GetPoint(pVector);
+	
+		//const Vector3 dVector = Vector3(2 * M_PI * halton.GetNumber(4), M_PI*halton.GetNumber(5),0.0f);
+		const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f);
+		direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x)));
+		//halton.GenerateNext();
+
+		//cout << "vp: " << viewPoint << endl;
+		//cout << "dir: " << direction << endl;
+
+		ViewCell *v = GetViewCell(viewPoint);
+
+		if (v && v->GetValid())
+		{
+			//cout << "validating view point" << endl;
+
+			mPreprocessor->GetRenderer()->mViewPoint = viewPoint;
+			mPreprocessor->GetRenderer()->mViewDirection = direction;
+
+			if (mPreprocessor->GetRenderer()->ValidViewPoint())
+			{
+				cout << "view point valid" << endl;
+				break;
+			}
+		}
+
+		// generate a new vector
+		//halton.GenerateNext();
+
+		//if (!box.IsInside(viewPoint))
+		//	cout << "error!" << endl;
+		if (++ tries > maxTries)
+			return false;
+	}
+
+	ray = SimpleRay(viewPoint, direction, 0, 1);
+	//cout << "view point generated: " << viewPoint << " " << direction << endl;
+
+	return true;
+}
+
+
+bool ViewCellsManager::IsValidViewSpace(ViewCell *vc)
+{
+	SimpleRay simpleRay;
+	//check if view point can be generated
+	return GenerateViewPoint(vc, simpleRay);
+}
+
+
+bool ViewCellsManager::GenerateRandomViewCells(ViewCellContainer &viewCells, 
+											   const int numViewCells)
+{
+	int generatedViewCells = 0;
+	//HaltonSequence halton;
+	//float r[1];
+
+	ViewCell::NewMail();
+
+	while (generatedViewCells < numViewCells)
+	{
+		// savety criterium
+		const int tries = 100000 + generatedViewCells;
+		int i = 0;
+
+		// generate next view cell
+		while (1)
+		{
+			//halton.GetNext(1, r);
+			//const int idx = (int)(r[0] * mViewCells.size() - 1.0f);
+			const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f);
+			
+			ViewCell *viewCell = GetViewCell(idx);
+
+			if (!viewCell->Mailed())
+			{
+				viewCell->Mail();
+
+				// check for valid view space
+				if (IsValidViewSpace(viewCell))
+				{
+					// valid view cell found
+					viewCells.push_back(viewCell);
+
+	                ++ generatedViewCells;
+					//cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;	
+					break;
+				}
+				else
+				{
+					cout << "error: invalid view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl;	
+				}
+			}
+
+			if (++ i == tries) // no new view cell fond
+			{
+				cerr << "big error! no view cell found" << endl;
+				return false;
+			}		
+		}			
+	}
+
+	return true;
+}
+
+
 ViewCellsManager::~ViewCellsManager()
 {
@@ -575,5 +862,5 @@
 		mRenderer->RenderScene();
 		SimulationStatistics ss;
-		dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
+		static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
 
 		Debug << ss << endl;
@@ -1616,5 +1903,5 @@
 			if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
 			{
-				TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit);
+				TransformedMeshInstance *mit = static_cast<TransformedMeshInstance *>(*oit);
 				mesh = MeshManager::GetSingleton()->CreateResource();
 				mit->GetTransformedMesh(*mesh);
@@ -1622,5 +1909,5 @@
 			else if ((*oit)->Type() == Intersectable::MESH_INSTANCE)
 			{
-				MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit);
+				MeshInstance *mit = static_cast<MeshInstance *>(*oit);
 				mesh = mit->GetMesh();
 			}
@@ -2608,5 +2895,5 @@
 	for (lit = leaves.begin(); lit != lit_end; ++ lit)
 	{
-		dynamic_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc);
+		static_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc);
 	}
 }
@@ -2648,5 +2935,5 @@
 		for (it = objects.begin(); it != it_end; ++ it)
 		{
-			MeshInstance *mi = dynamic_cast<MeshInstance *>(*it);
+			MeshInstance *mi = static_cast<MeshInstance *>(*it);
 			const AxisAlignedBox3 box = mi->GetBox();
 
@@ -2671,5 +2958,5 @@
 		for (it = objects.begin(); it != it_end; ++ it)
 		{	
-			MeshInstance *mi = dynamic_cast<MeshInstance *>(*it);
+			MeshInstance *mi = static_cast<MeshInstance *>(*it);
 			const AxisAlignedBox3 box = mi->GetBox();
 			Vector3 bmin = box.Min();
@@ -3252,5 +3539,5 @@
 	//-- interior node => propagate pvs up the tree
 
-	ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root);
+	ViewCellInterior *interior = static_cast<ViewCellInterior *>(root);
 
 	// reset interior pvs
@@ -3920,6 +4207,8 @@
 
 	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
-
+	
 	IncludeNodeGeomInMesh(geom, *mesh);
+	mesh->ComputeBoundingBox();
+
 	vc->SetMesh(mesh);
 }
@@ -4101,10 +4390,10 @@
 	if (root->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(root);
+		BspLeaf *leaf = static_cast<BspLeaf *>(root);
 		leaf->GetViewCell()->SetMergeCost(0.0f);
 		return leaf->GetViewCell();
 	}
 	
-	BspInterior *interior = dynamic_cast<BspInterior *>(root);
+	BspInterior *interior = static_cast<BspInterior *>(root);
 	ViewCellInterior *viewCellInterior = new ViewCellInterior();
 		
@@ -4243,5 +4532,5 @@
 
 		for (int i = 0; i < leafOut; ++ i)
-			kdLeaves.push_back(dynamic_cast<KdLeaf *>(mKdTree->GetRandomLeaf()));
+			kdLeaves.push_back(static_cast<KdLeaf *>(mKdTree->GetRandomLeaf()));
 
 		for (int i = 0; i < kdLeaves.size(); ++ i)
@@ -4406,5 +4695,5 @@
 	for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it);
+		KdViewCell *kdVc = static_cast<KdViewCell *>(*it);
 		exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaves[0]));
 	}
@@ -4746,5 +5035,5 @@
 
 	SimulationStatistics ss;
-	dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
+	static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
     Debug << "render time before refine\n\n" << ss << endl;
 
@@ -4826,7 +5115,7 @@
 
 	cout << "\nview cells partition render time before compress" << endl << endl;;
-	dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();
+	static_cast<RenderSimulator *>(mRenderer)->RenderScene();
 	SimulationStatistics ss;
-	dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
+	static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
  	cout << ss << endl;
 	
@@ -4857,5 +5146,5 @@
 	if (root->IsLeaf())
 	{
-		BspLeaf *leaf = dynamic_cast<BspLeaf *>(root);
+		BspLeaf *leaf = static_cast<BspLeaf *>(root);
 		leaf->GetViewCell()->SetMergeCost(0.0f);
 		return leaf->GetViewCell();
@@ -4863,5 +5152,5 @@
 	
 	
-	BspInterior *interior = dynamic_cast<BspInterior *>(root);
+	BspInterior *interior = static_cast<BspInterior *>(root);
 	ViewCellInterior *viewCellInterior = new ViewCellInterior();
 		
@@ -5095,5 +5384,5 @@
        		for (vit = leaves.begin(); vit != vit_end; ++ vit)
 			{	
-				BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0];
+				BspLeaf *vcLeaf = static_cast<BspViewCell *>(*vit)->mLeaves[0];
 				VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end();
 
@@ -5387,9 +5676,9 @@
 		for (int j = 0; j < (int)leaves.size(); ++ j)
 		{
-			BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaves[0];
+			BspLeaf *leaf = static_cast<BspViewCell *>(leaves[i])->mLeaves[0];
 
 			if (i != j)
 			{
-				BspLeaf *leaf2 =dynamic_cast<BspViewCell *>(leaves[j])->mLeaves[0];
+				BspLeaf *leaf2 =static_cast<BspViewCell *>(leaves[j])->mLeaves[0];
 				const int dist = mVspBspTree->TreeDistance(leaf, leaf2);
 				
@@ -5422,5 +5711,7 @@
 	
 	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
+	
 	IncludeNodeGeomInMesh(geom, *mesh);
+	mesh->ComputeBoundingBox();
 
 	vc->SetMesh(mesh);
@@ -5500,6 +5791,5 @@
 {
 	// TODO: do I still need this here?
-	if (0)
-		mVspBspTree->RepairViewCellsLeafLists();
+	if (0) mVspBspTree->RepairViewCellsLeafLists();
 }
 
@@ -5748,7 +6038,7 @@
 
 	cout << "\nview cells partition render time before compress" << endl << endl;
-	dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();
+	static_cast<RenderSimulator *>(mRenderer)->RenderScene();
 	SimulationStatistics ss;
-	dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
+	static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
 	cout << ss << endl;
 	
@@ -5782,10 +6072,10 @@
 	if (root->IsLeaf())
 	{
-		VspLeaf *leaf = dynamic_cast<VspLeaf *>(root);
+		VspLeaf *leaf = static_cast<VspLeaf *>(root);
 		leaf->GetViewCell()->SetMergeCost(0.0f);
 		return leaf->GetViewCell();
 	}
 	
-	VspInterior *interior = dynamic_cast<VspInterior *>(root);
+	VspInterior *interior = static_cast<VspInterior *>(root);
 	ViewCellInterior *viewCellInterior = new ViewCellInterior();
 		
@@ -5861,5 +6151,5 @@
 	for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it);
+		VspViewCell *vspVc = static_cast<VspViewCell *>(*it);
 		VspLeaf *l = vspVc->mLeaves[0];
 
@@ -5927,5 +6217,5 @@
 			ObjectPvsEntry entry = pit.Next();
 				
-			BvhNode *node = dynamic_cast<BvhNode *>(entry.mObject);
+			BvhNode *node = static_cast<BvhNode *>(entry.mObject);
 			
 			// hack!!
@@ -6165,5 +6455,5 @@
 			for (vit = leaves.begin(); vit != vit_end; ++ vit)
 			{
-				VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0];
+				VspLeaf *vcLeaf = static_cast<VspViewCell *>(*vit)->mLeaves[0];
 				VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end();
 
@@ -6311,7 +6601,6 @@
 void VspOspViewCellsManager::CreateMesh(ViewCell *vc)
 {
-	// matt: TODO
 	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
-
+	
 	ViewCellContainer leaves;
 	mViewCellsTree->CollectLeaves(vc, leaves);
@@ -6321,9 +6610,11 @@
     for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0];
+		VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0];
 		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf);
         IncludeBoxInMesh(box, *mesh);
 	}
 
+	mesh->ComputeBoundingBox();
+
 	vc->SetMesh(mesh);
 }
@@ -6349,5 +6640,5 @@
     for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0];
+		VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0];
 		
 		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2006)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2017)
@@ -139,15 +139,15 @@
 	break;
   case Intersectable::VIEW_CELL:
-	RenderViewCell(dynamic_cast<ViewCell *>(object));
+	RenderViewCell(static_cast<ViewCell *>(object));
 	break;
   case Intersectable::TRANSFORMED_MESH_INSTANCE:
-	RenderTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
+	RenderTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object));
 	break;
   case Intersectable::TRIANGLE_INTERSECTABLE:
-	RenderTriangle(dynamic_cast<TriangleIntersectable *>(object));
+	RenderTriangle(static_cast<TriangleIntersectable *>(object));
 	break;
   case Intersectable::BVH_INTERSECTABLE: {
 
-	BvhNode *node = dynamic_cast<BvhNode *>(object);
+	BvhNode *node = static_cast<BvhNode *>(object);
 	
 	if (mRenderBoxes)
@@ -158,5 +158,5 @@
   }
   case Intersectable::KD_INTERSECTABLE: {
-	KdNode *node = (dynamic_cast<KdIntersectable *>(object))->GetItem();
+	KdNode *node = (static_cast<KdIntersectable *>(object))->GetItem();
 	
 	if (mRenderBoxes)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 2003)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 2017)
@@ -86,5 +86,5 @@
 	{
 		// eyport leaf pvs
-		KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
+		KdLeaf *leaf = static_cast<KdLeaf *>(node);
 
 		ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
@@ -171,16 +171,16 @@
 		break;
 	case Intersectable::TRANSFORMED_MESH_INSTANCE:
-		ExportTransformedMeshInstance(dynamic_cast<TransformedMeshInstance *>(object));
+		ExportTransformedMeshInstance(static_cast<TransformedMeshInstance *>(object));
 		break;
 	case Intersectable::VIEW_CELL:
-		ExportViewCell(dynamic_cast<ViewCell *>(object));
+		ExportViewCell(static_cast<ViewCell *>(object));
 		break;
 	case Intersectable::KD_INTERSECTABLE:
-		ExportKdIntersectable(*(dynamic_cast<KdIntersectable *>(object)));
+		ExportKdIntersectable(*(static_cast<KdIntersectable *>(object)));
 		break;
 	case Intersectable::TRIANGLE_INTERSECTABLE:
 		{
 			// if (mClampToBox && !Overlap(mBoundingBox, object->GetBox()))	 return;
-			const Triangle3 triangle = dynamic_cast<TriangleIntersectable *>(object)->GetItem();
+			const Triangle3 triangle = static_cast<TriangleIntersectable *>(object)->GetItem();
 
             Polygon3 poly(triangle);
@@ -190,9 +190,9 @@
 	case Intersectable::BVH_INTERSECTABLE:
 		{
-			BvhNode *node = dynamic_cast<BvhNode *>(object);
+			BvhNode *node = static_cast<BvhNode *>(object);
 			
 			if (node->IsLeaf())
 			{
-				ExportGeometry(dynamic_cast<BvhLeaf *>(node)->mObjects, true);
+				ExportGeometry(static_cast<BvhLeaf *>(node)->mObjects, true);
 			}
 
@@ -275,5 +275,5 @@
 		case Intersectable::TRIANGLE_INTERSECTABLE:
 			{
-				TriangleIntersectable *ti = dynamic_cast<TriangleIntersectable *>(obj);
+				TriangleIntersectable *ti = static_cast<TriangleIntersectable *>(obj);
 				polys.push_back(new Polygon3(ti->GetItem()));
                 break;
@@ -281,5 +281,5 @@
 		case Intersectable::MESH_INSTANCE:
 			{
-				MeshInstance *mi = dynamic_cast<MeshInstance *>(obj);
+				MeshInstance *mi = static_cast<MeshInstance *>(obj);
 				ExportMesh(mi->GetMesh());
 				break;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2017)
@@ -471,5 +471,5 @@
 		else
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -504,5 +504,5 @@
 		else
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -1274,5 +1274,5 @@
 
 	
-	ViewCellInterior *p = dynamic_cast<ViewCellInterior *>(leaf->GetParent());
+	ViewCellInterior *p = static_cast<ViewCellInterior *>(leaf->GetParent());
 
 	p->RemoveChildLink(leaf);
@@ -1285,6 +1285,6 @@
 	float cost1, cost2;
 
-	ViewCellInterior *vc1 = dynamic_cast<ViewCellInterior *>(mc.GetLeftViewCell());
-	ViewCellInterior *vc2 = dynamic_cast<ViewCellInterior *>(mc.GetRightViewCell());
+	ViewCellInterior *vc1 = static_cast<ViewCellInterior *>(mc.GetLeftViewCell());
+	ViewCellInterior *vc2 = static_cast<ViewCellInterior *>(mc.GetRightViewCell());
 
 	ViewCell *leaf1 = mc.GetInitialLeftViewCell();
@@ -1480,5 +1480,5 @@
 	if (!root->IsLeaf())
 	{
-		ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root);
+		ViewCellInterior *interior = static_cast<ViewCellInterior *>(root);
 
         ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -1577,5 +1577,5 @@
 		if (!vc->IsLeaf()) 
 		{	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			const float parentCost = GetPvsCost(interior);
@@ -1651,5 +1651,5 @@
 		else 
 		{	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -1789,5 +1789,5 @@
 		if (!vc->IsLeaf()) // interior cells: go down to leaf level
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -1925,5 +1925,5 @@
 		if (!vc->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -1976,5 +1976,5 @@
 		if (!vc->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -2068,5 +2068,5 @@
 	if (!root->IsLeaf())
 	{
-		ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root);
+		ViewCellInterior *interior = static_cast<ViewCellInterior *>(root);
 
 		ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -2126,5 +2126,5 @@
 		if (!viewCell->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(viewCell);
 
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -2156,5 +2156,5 @@
 		if (!vc->IsLeaf()) 
 		{	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 		  
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -2219,5 +2219,5 @@
 		if (!vc->IsLeaf()) 
 		{	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			const float parentCost = GetPvsCost(interior);
@@ -2284,5 +2284,5 @@
 		if (!vc->IsLeaf()) 
 		{	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
 			const float parentPvsCost = GetPvsCost(interior);
@@ -2372,5 +2372,5 @@
 		if (!vc->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -2397,5 +2397,5 @@
 		{
 			ObjectContainer objects; 
-			BvhNode *node = dynamic_cast<BvhNode *>(obj);
+			BvhNode *node = static_cast<BvhNode *>(obj);
 			node->CollectObjects(objects);
 		
@@ -2422,5 +2422,5 @@
 		stream << "<Leaf ";
 		stream << "id=\"" << viewCell->GetId() << "\" ";
-		stream << "active=\"" << dynamic_cast<ViewCellLeaf *>(viewCell)->GetActiveViewCell()->GetId() << "\" ";
+		stream << "active=\"" << static_cast<ViewCellLeaf *>(viewCell)->GetActiveViewCell()->GetId() << "\" ";
 		stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" ";
 		stream << "pvs=\"";
@@ -2435,5 +2435,5 @@
 	else
 	{
-		ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell);
+		ViewCellInterior *interior = static_cast<ViewCellInterior *>(viewCell);
 	
 		stream << "<Interior ";
@@ -2481,5 +2481,5 @@
 		if (!vc->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2004)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2017)
@@ -75,5 +75,4 @@
 	if (castDoubleRay)
 	{
-		//cerr<<"HERE"<<endl;
 		Vector3 dir = -simpleRay.mDirection;
 		hittriangle = mlrtaIntersectAS(
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2017)
@@ -744,4 +744,5 @@
 {
 	int hits = 0;
+
 	float mint = 0.0f, maxt = 1.0f;
 	const Vector3 dir = termination - origin;
@@ -764,76 +765,78 @@
 	while (1)
 	{
-	  if (!node->IsLeaf()) {
-		KdInterior *in = (KdInterior *)node;
-		position = in->mPosition;
-		axis = in->mAxis;
-		
-		if (entp[axis] <= position)
-		  {
-			if (extp[axis] <= position)
-			  {
-				node = in->mBack;
-				// cases N1,N2,N3,P5,Z2,Z3
-				continue;
-			  } 
+		if (!node->IsLeaf())
+		{
+			KdInterior *in = static_cast<KdInterior *>(node);
+			position = in->mPosition;
+			axis = in->mAxis;
+
+			if (entp[axis] <= position)
+			{
+				if (extp[axis] <= position)
+				{
+					node = in->mBack;
+					// cases N1,N2,N3,P5,Z2,Z3
+					continue;
+				} 
+				else
+				{
+					// case N4
+					node = in->mBack;
+					farChild = in->mFront;
+				}
+			}
 			else
-			  {
-				// case N4
-				node = in->mBack;
-				farChild = in->mFront;
-			  }
-		  }
+			{
+				if (position <= extp[axis])
+				{
+					node = in->mFront;
+					// cases P1,P2,P3,N5,Z1
+					continue;
+				}
+				else
+				{
+					node = in->mFront;
+					farChild = in->mBack;
+					// case P4
+				}
+			}
+
+ 			// $$ modification 3.5.2004 - hints from Kamil Ghais
+			// case N4 or P4
+			float tdist = (position - origin[axis]) / dir[axis];
+			//tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO
+			extp = origin + dir * tdist;
+			maxt = tdist;
+		}
 		else
-		  {
-			if (position <= extp[axis])
-			  {
-				node = in->mFront;
-				// cases P1,P2,P3,N5,Z1
-				continue;
-			  }
-			else
-			  {
-				node = in->mFront;
-				farChild = in->mBack;
-				// case P4
-			  }
-		  }
-		
-		// $$ modification 3.5.2004 - hints from Kamil Ghais
-		// case N4 or P4
-		float tdist = (position - origin[axis]) / dir[axis];
-		//tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO
-		extp = origin + dir * tdist;
-		maxt = tdist;
-	  }
-	  else
 		{
-		  // compute intersection with all objects in this leaf
-		  KdLeaf *leaf = (KdLeaf *)node;
-		  
-		  // add view cell to intersections
-		  ViewCell *vc = leaf->mViewCell;
-		  
-		  if (!vc->Mailed()) {
-			vc->Mail();
-			viewcells.push_back(vc);
-			++ hits;
-		  }
-		  
-		  // get the next node from the stack
-		  if (tStack.empty())
-			break;
-		  
-		  entp = extp;
-		  mint = maxt;
-		  
-		  RayTraversalData &s  = tStack.top();
-		  node = s.mNode;
-		  extp = s.mExitPoint;
-		  maxt = s.mMaxT;
-		  tStack.pop();
+			// compute intersection with all objects in this leaf
+			KdLeaf *leaf = static_cast<KdLeaf *>(node);
+
+			// add view cell to intersections
+			ViewCell *vc = leaf->mViewCell;
+
+			if (!vc->Mailed())
+			{
+				vc->Mail();
+				viewcells.push_back(vc);
+				++ hits;
+			}
+
+			// get the next node from the stack
+			if (tStack.empty())
+				break;
+
+			entp = extp;
+			mint = maxt;
+			
+			RayTraversalData &s  = tStack.top();
+			node = s.mNode;
+			extp = s.mExitPoint;
+			maxt = s.mMaxT;
+			tStack.pop();
 		}
 	}
-	
+
 	return hits;
 }
@@ -1323,10 +1326,10 @@
 		{
 			//Debug << "l";
-			ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node));
+			ExportBinLeaf(stream, static_cast<KdLeaf *>(node));
 		}
 		else
 		{
 			//Debug << "i";
-			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+			KdInterior *interior = static_cast<KdInterior *>(node);
 
 			ExportBinInterior(stream, interior);
@@ -1350,10 +1353,10 @@
 	if (nodeType == TYPE_LEAF)
 	{
-		return ImportBinLeaf(stream, dynamic_cast<KdInterior *>(parent), objects);
+		return ImportBinLeaf(stream, static_cast<KdInterior *>(parent), objects);
 	}
 
 	if (nodeType == TYPE_INTERIOR)
 	{
-		return ImportBinInterior(stream, dynamic_cast<KdInterior *>(parent));
+		return ImportBinInterior(stream, static_cast<KdInterior *>(parent));
 	}
 
@@ -1409,5 +1412,5 @@
 
 			//Debug << "i" ;
-			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+			KdInterior *interior = static_cast<KdInterior *>(node);
 			interior->mBox = tData.mBox;
 
@@ -1554,9 +1557,9 @@
 		if (node->IsLeaf())
 		{
-			leaves.push_back(dynamic_cast<KdLeaf *>(node));
+			leaves.push_back(static_cast<KdLeaf *>(node));
 		}
 		else // interior
 		{
-			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+			KdInterior *interior = static_cast<KdInterior *>(node);
 
 			if (box.Max(interior->mAxis) >= interior->mPosition)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2015)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2017)
@@ -268,6 +268,38 @@
 
 
-
-
+bool VspInterior::IsLeaf() const
+{ 
+	return false; 
+}
+
+
+VspNode *VspInterior::GetBack() 
+{
+	return mBack;
+}
+
+
+VspNode *VspInterior::GetFront() 
+{
+	return mFront;
+}
+
+
+AxisAlignedPlane VspInterior::GetPlane() const
+{
+	return mPlane;
+}
+
+
+float VspInterior::GetPosition() const
+{
+	return mPlane.mPosition;
+}
+
+
+int VspInterior::GetAxis() const
+{
+	return mPlane.mAxis;
+}
 
 
@@ -356,4 +388,8 @@
 
 
+ViewCellLeaf *VspLeaf::GetViewCell() const
+{
+	return mViewCell;
+}
 
 
@@ -364,4 +400,8 @@
 
 
+bool VspLeaf::IsLeaf() const 
+{ 
+	return true; 
+}
 
 
@@ -665,5 +705,5 @@
 	// todo remove dynamic cast
 	VspSubdivisionCandidate *sc = 
-		dynamic_cast<VspSubdivisionCandidate *>(splitCandidate);
+		static_cast<VspSubdivisionCandidate *>(splitCandidate);
 
 	VspTraversalData &tData = sc->mParentData;
@@ -718,5 +758,5 @@
 	if (newNode->IsLeaf()) // subdivision terminated
 	{
-		VspLeaf *leaf = dynamic_cast<VspLeaf *>(newNode);
+		VspLeaf *leaf = static_cast<VspLeaf *>(newNode);
 		
 #if 0
@@ -787,5 +827,5 @@
 	}
 	
-	VspLeaf *leaf = dynamic_cast<VspLeaf *>(splitCandidate.mParentData.mNode);
+	VspLeaf *leaf = static_cast<VspLeaf *>(splitCandidate.mParentData.mNode);
 
 	/////////////
@@ -882,5 +922,5 @@
 									VspTraversalData &backData)
 {
-	VspLeaf *leaf = dynamic_cast<VspLeaf *>(sc.mParentData.mNode);
+	VspLeaf *leaf = static_cast<VspLeaf *>(sc.mParentData.mNode);
 
 	const VspTraversalData &tData = sc.mParentData;
@@ -1441,5 +1481,5 @@
 		if (parent)
 		{
-			parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis();
+			parentAxis = static_cast<VspInterior *>(parent)->GetAxis();
 		}
 
@@ -1816,5 +1856,5 @@
 		{
 			// test if this leaf is in valid view space
-			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 
 			if (leaf->TreeValid() && 
@@ -1827,5 +1867,5 @@
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 
 			nodeStack.push(interior->GetBack());
@@ -1851,5 +1891,5 @@
 {
 	// the node became a leaf -> evaluate stats for leafs
-	VspLeaf *leaf = dynamic_cast<VspLeaf *>(data.mNode);
+	VspLeaf *leaf = static_cast<VspLeaf *>(data.mNode);
 
 	if (data.mPvs > mVspStats.maxPvs)
@@ -1926,9 +1966,9 @@
 		if (node->IsLeaf())
         {
-			BspViewCell *viewCell = dynamic_cast<VspLeaf *>(node)->GetViewCell();
+			BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell();
 
 			if (!viewCell->GetValid())
 			{
-				BspViewCell *viewCell = dynamic_cast<VspLeaf *>(node)->GetViewCell();
+				BspViewCell *viewCell = static_cast<VspLeaf *>(node)->GetViewCell();
 	
 				ViewCellContainer leaves;
@@ -1939,5 +1979,5 @@
 				for (it = leaves.begin(); it != it_end; ++ it)
 				{
-					VspLeaf *l = dynamic_cast<BspViewCell *>(*it)->mLeaf;
+					VspLeaf *l = static_cast<BspViewCell *>(*it)->mLeaf;
 					l->SetViewCell(GetOrCreateOutOfBoundsCell());
 					++ mVspStats.invalidLeaves;
@@ -1952,5 +1992,5 @@
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2005,5 +2045,5 @@
 		if (node->IsLeaf())
 		{
-			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 
 			if (!leaf->GetViewCell()->GetValid())
@@ -2019,5 +2059,5 @@
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2051,5 +2091,5 @@
 			if (!onlyValid || node->TreeValid())
 			{
-				ViewCellLeaf *leafVc = dynamic_cast<VspLeaf *>(node)->GetViewCell();
+				ViewCellLeaf *leafVc = static_cast<VspLeaf *>(node)->GetViewCell();
 
 				ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leafVc);
@@ -2064,5 +2104,5 @@
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 		
 			nodeStack.push(interior->GetFront());
@@ -2089,5 +2129,5 @@
 		if (node->IsLeaf())
 		{
-			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 
 			if (leaf != n && (!onlyUnmailed || !leaf->Mailed()))
@@ -2096,5 +2136,5 @@
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 			
 			if (interior->GetPosition() > box.Max(interior->GetAxis()))
@@ -2134,9 +2174,9 @@
 		if (node->IsLeaf()) 
 		{
-			return dynamic_cast<VspLeaf *>(node);
+			return static_cast<VspLeaf *>(node);
 		} 
 		else 
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 			VspNode *next;
 			
@@ -2186,9 +2226,9 @@
 		{
 			if ( (!onlyUnmailed || !node->Mailed()) )
-				return dynamic_cast<VspLeaf *>(node);
+				return static_cast<VspLeaf *>(node);
 		}
 		else
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 
 			// random decision
@@ -2336,11 +2376,9 @@
 	int axis;
 
-	ViewCell::NewMail();
-	
 	while (1)
 	{
 		if (!node->IsLeaf())
 		{
-			VspInterior *in = (VspInterior *)node;
+			VspInterior *in = static_cast<VspInterior *>(node);
 			position = in->GetPosition();
 			axis = in->GetAxis();
@@ -2387,25 +2425,25 @@
 		{
 			// compute intersection with all objects in this leaf
-			VspLeaf *leaf = (VspLeaf *)node;
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 			ViewCell *viewCell;
-			//			if (0)
-			//				viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
-			//			else
-
-			viewCell = leaf->GetViewCell();
-			
+			if (0)
+				viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
+			else
+				viewCell = leaf->GetViewCell();
+
 			// don't have to mail if each view cell belongs to exactly one leaf
-			// $$ JB -> always mailbox so that we have less conditions
-			if (!viewCell->Mailed()) {
-			  viewCell->Mail();
-			  
-			  viewcells.push_back(viewCell);
-			  ++ hits;
-			}
-			
+			if (!useMailboxing || !viewCell->Mailed())
+			{
+				if (useMailboxing)
+					viewCell->Mail();
+
+				viewcells.push_back(viewCell);
+				++ hits;
+			}
+
 			// get the next node from the stack
 			if (tStack.empty())
-			  break;
-			
+				break;
+
 			entp = extp;
 			mint = maxt;
@@ -2454,5 +2492,5 @@
 		if (!node->IsLeaf())
 		{
-			VspInterior *in = dynamic_cast<VspInterior *>(node);
+			VspInterior *in = static_cast<VspInterior *>(node);
 			position = in->GetPosition();
 			axis = in->GetAxis();
@@ -2499,5 +2537,5 @@
 		{
 			// compute intersection with all objects in this leaf
-			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 			ViewCell *vc = leaf->GetViewCell();
 
@@ -2545,14 +2583,14 @@
 		if (node->IsLeaf()) 
 		{
-			/*const AxisAlignedBox3 box = GetBoundingBox(dynamic_cast<VspLeaf *>(node));
+			/*const AxisAlignedBox3 box = GetBoundingBox(static_cast<VspLeaf *>(node));
 			if (!box.IsInside(point))
 				cerr << "error, point " << point << " should be in view cell " << box << endl;
 			*/	
-			viewcell = dynamic_cast<VspLeaf *>(node)->GetViewCell();
+			viewcell = static_cast<VspLeaf *>(node)->GetViewCell();
 			break;
 		} 
 		else 	
 		{	
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
      
 			// random decision
@@ -2592,5 +2630,5 @@
 			return false;
 			
-		VspInterior *in = dynamic_cast<VspInterior *>(node);
+		VspInterior *in = static_cast<VspInterior *>(node);
 					
 		if (in->GetPosition() - viewPoint[in->GetAxis()] <= 0) 
@@ -2628,5 +2666,5 @@
 		{
             node = node->GetParent();
-			VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			VspInterior *interior = static_cast<VspInterior *>(node);
 			
 			// the parent is valid iff both leaves are valid
@@ -2650,5 +2688,5 @@
 	if (node->IsLeaf())
 	{
-		VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+		VspLeaf *leaf = static_cast<VspLeaf *>(node);
 		ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
 
@@ -2661,5 +2699,5 @@
 	else
 	{	
-		VspInterior *interior = dynamic_cast<VspInterior *>(node);
+		VspInterior *interior = static_cast<VspInterior *>(node);
 	
 		AxisAlignedPlane plane = interior->GetPlane();
@@ -2731,8 +2769,8 @@
 	if (!node->IsLeaf())
 	{
-		return (dynamic_cast<VspInterior *>(node))->GetBoundingBox();		
-	}
-
-	VspInterior *parent = dynamic_cast<VspInterior *>(node->GetParent());
+		return (static_cast<VspInterior *>(node))->GetBoundingBox();		
+	}
+
+	VspInterior *parent = static_cast<VspInterior *>(node->GetParent());
 
 	AxisAlignedBox3 box(parent->GetBoundingBox());
@@ -2766,5 +2804,5 @@
 		  if (node->IsLeaf())
 			{
-			  VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			  VspLeaf *leaf = static_cast<VspLeaf *>(node);
 			  
 			  if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid())
@@ -2776,5 +2814,5 @@
 		  else 
 			{
-			  VspInterior *interior = dynamic_cast<VspInterior *>(node);
+			  VspInterior *interior = static_cast<VspInterior *>(node);
 			  
 			  VspNode *first = interior->GetFront();
@@ -2887,5 +2925,5 @@
 	
 	// root and bounding box were already constructed
-	VspLeaf *leaf = dynamic_cast<VspLeaf *>(mRoot);
+	VspLeaf *leaf = static_cast<VspLeaf *>(mRoot);
 
 	//////////
@@ -3304,5 +3342,5 @@
 {
 	// todo remove dynamic cast
-	VspSubdivisionCandidate *sc = dynamic_cast<VspSubdivisionCandidate *>(splitCandidate);
+	VspSubdivisionCandidate *sc = static_cast<VspSubdivisionCandidate *>(splitCandidate);
 
 	VspTraversalData &tData = sc->mParentData;
@@ -3318,5 +3356,5 @@
 		VspTraversalData tBackData;
 		
-		VspInterior *oldInterior = dynamic_cast<VspInterior *>(oldNode);
+		VspInterior *oldInterior = static_cast<VspInterior *>(oldNode);
 
 		// create new interior node and two leaf node
@@ -3387,5 +3425,5 @@
 		{
 			const ObjectPvsEntry &entry = oit.Next();
-			BvhNode *obj = dynamic_cast<BvhNode *>(entry.mObject);
+			BvhNode *obj = static_cast<BvhNode *>(entry.mObject);
 
 			if (!obj->IsRoot())
@@ -3416,5 +3454,5 @@
 		{
 			const ObjectPvsEntry &entry = oit.Next();
-			BvhNode *obj = dynamic_cast<BvhNode *>(entry.mObject);
+			BvhNode *obj = static_cast<BvhNode *>(entry.mObject);
 
 			if (!obj->IsRoot())
@@ -3486,5 +3524,5 @@
 		if (!node->IsLeaf())
 		{
-			VspInterior *in = dynamic_cast<VspInterior *>(node);
+			VspInterior *in = static_cast<VspInterior *>(node);
 			position = in->GetPosition();
 			axis = in->GetAxis();
@@ -3531,5 +3569,5 @@
 		{
 			// compute intersection with all objects in this leaf
-			VspLeaf *leaf = dynamic_cast<VspLeaf *>(node);
+			VspLeaf *leaf = static_cast<VspLeaf *>(node);
 			ViewCell *viewCell;
 			if (0)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2008)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2017)
@@ -220,5 +220,4 @@
 	}
 	
-
 	////////////
 	//-- initialize external ray caster
@@ -269,5 +268,8 @@
 		exit(1);
 	}
-	
+
+	const string viewCellsFile = ReplaceSuffix(filename, ".obj", ".vc");
+	const int numViewCells = 2;
+	const int numViewPoints = 2;
 
 	bool useHwGlobalLines;
@@ -357,4 +359,13 @@
 		}
 
+	/*	vector<ViewCellPoints *> myViewCells;
+
+		preprocessor->mViewCellsManager->GenerateRandomViewCells(myViewCells, numViewCells, numViewPoints);
+		cout << "exporting random view cells" << endl;
+		preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellsFile, myViewCells);
+
+		//preprocessor->mViewCellsManager->ImportRandomViewCells(viewCellsFile, myViewCells);
+		CLEAR_CONTAINER(myViewCells);
+*/
 		qApp->exec();
 #endif
@@ -381,4 +392,5 @@
 	// release memory
 	Cleanup();
+	
 	delete pt;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2008)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2017)
@@ -195,4 +195,6 @@
   };
 friend class GlobalLinesRenderer;
+friend class ViewCellsManager;
+
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2005)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2017)
@@ -25,5 +25,5 @@
 };
 
-static const float MIN_DIST = 0.01f;
+static const float MIN_DIST = 0.001f;
 
 static vector<VizStruct> vizContainer;
@@ -286,5 +286,5 @@
 								   const VssRay &ray2,
 								   const VssRay &oldRay)
-{
+{//cout <<"x"<<Magnitude(p1 - p2) << " ";
 	int castRays = 0;
 
@@ -293,5 +293,5 @@
 	castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
 
-	if (EqualVisibility(ray1, ray2) || (Magnitude(p1 - p2) <= MIN_DIST))
+	if (EqualVisibility(ray1, ray2) || (SqrMagnitude(p1 - p2) <= MIN_DIST))
 	{
 		return castRays;
@@ -300,5 +300,5 @@
 	// the new subdivision point
 	const Vector3 p = (p1 + p2) * 0.5f;
-
+	//cout << "p: " << p << " " << p1 << " " << p2 << endl;
 	// cast ray into the new point
 	SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin, SamplingStrategy::GVS, 1.0f);
@@ -335,5 +335,5 @@
 	if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
 	{
-		hitTriangle = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem();
+		hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
 	}
 	else
@@ -427,5 +427,5 @@
 
 	CLEAR_CONTAINER(invalidSamples);
-
+//cout << "***********"<< endl;
 	return castRays;
 }
@@ -495,5 +495,5 @@
 	// other types not implemented yet
 	if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
-		occluder = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem();
+		occluder = static_cast<TriangleIntersectable *>(tObj)->GetItem();
 	else
 		cout << "not yet implemented" << endl;
@@ -828,6 +828,9 @@
 				break;
 			}
-
+//if (viewCell->GetId() == 36658)
+//{
 			mViewCells.push_back(viewCell);
+//			return;
+//}
 		}
 
@@ -859,5 +862,5 @@
 		for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
 		{
-			TriangleIntersectable *triObj = dynamic_cast<TriangleIntersectable *>(*oit);
+			TriangleIntersectable *triObj = static_cast<TriangleIntersectable *>(*oit);
 
 			if (box.Intersects(triObj->GetItem()))
@@ -1065,6 +1068,4 @@
 	}
 
-	cout << "here4 " << mKdTree->GetBox() << endl;
-	cout << "here5 " << mViewCellsManager->GetViewSpaceBox() << endl;
 	mGvsStats.Stop();
 	mGvsStats.Print(mGvsStatsStream);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1785)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 2017)
@@ -42,5 +42,5 @@
 			if (node->IsLeaf())
 			{
-				KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
+				KdLeaf *leaf = static_cast<KdLeaf *>(node);
                        
 				// add #objects exclusivly in this node
@@ -64,5 +64,5 @@
 			else // traverse tree
 			{
-				KdInterior *interior = dynamic_cast<KdInterior *>(node);
+				KdInterior *interior = static_cast<KdInterior *>(node);
 
 				tStack.push(interior->mFront);
@@ -85,5 +85,5 @@
 	// hack for choosing which node to account for
 	if (bvhObj->IsLeaf())
-		node = dynamic_cast<BvhLeaf *>(bvhObj)->GetActiveNode();
+		node = static_cast<BvhLeaf *>(bvhObj)->GetActiveNode();
 	else
 		node = bvhObj;
@@ -92,5 +92,5 @@
 	if (node->IsLeaf())	
 	{	
-		BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node);
+		BvhLeaf *leaf = static_cast<BvhLeaf *>(node);
 		// objects already accounted for
 		if (leaf->Mailed())
@@ -118,5 +118,5 @@
 			if (node->IsLeaf())
 			{
-				BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node);
+				BvhLeaf *leaf = static_cast<BvhLeaf *>(node);
 
 				// add #objects exclusivly in this node
@@ -125,5 +125,5 @@
 			else // traverse tree
 			{
-				BvhInterior *interior = dynamic_cast<BvhInterior *>(node);
+				BvhInterior *interior = static_cast<BvhInterior *>(node);
 
 				tStack.push(interior->GetFront());
@@ -156,5 +156,5 @@
 				{
 					// found kd node
-					KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);
+					KdIntersectable *kdObj = static_cast<KdIntersectable *>(obj);
 					pvs += EvalKdNodeContribution(kdObj);	
 					break;
@@ -162,5 +162,5 @@
 			case Intersectable::BVH_INTERSECTABLE:
 				{
-					BvhNode *bvhObj = dynamic_cast<BvhNode *>(obj);
+					BvhNode *bvhObj = static_cast<BvhNode *>(obj);
 					pvs += EvalBvhNodeContribution(bvhObj);
 					break;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1933)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2017)
@@ -1724,5 +1724,5 @@
 		if (!mNode->IsLeaf())
 		{
-			VspInterior *interior = dynamic_cast<VspInterior *>(mNode);
+			VspInterior *interior = static_cast<VspInterior *>(mNode);
 
 			tQueue.push(new VspNodeWrapper(interior->GetFront()));
@@ -1750,5 +1750,5 @@
 		if (!mNode->IsLeaf())
 		{
-			BvhInterior *interior = dynamic_cast<BvhInterior *>(mNode);
+			BvhInterior *interior = static_cast<BvhInterior *>(mNode);
 
 			tQueue.push(new BvhNodeWrapper(interior->GetFront()));
@@ -1777,5 +1777,5 @@
 		if (!mViewCell->IsLeaf())
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mViewCell);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(mViewCell);
 
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
@@ -1819,5 +1819,5 @@
 			{
 				//cout << "1";
-				ViewCellWrapper *viewCellWrapper = dynamic_cast<ViewCellWrapper *>(nodeWrapper);
+				ViewCellWrapper *viewCellWrapper = static_cast<ViewCellWrapper *>(nodeWrapper);
 				viewCells.push_back(viewCellWrapper->mViewCell);
 			}
@@ -1825,5 +1825,5 @@
 			{
 				//cout << "0";
-				BvhNodeWrapper *bvhNodeWrapper = dynamic_cast<BvhNodeWrapper *>(nodeWrapper);
+				BvhNodeWrapper *bvhNodeWrapper = static_cast<BvhNodeWrapper *>(nodeWrapper);
 				bvhNodes.push_back(bvhNodeWrapper->mNode);
 			}
@@ -1854,5 +1854,5 @@
 			cout << "error " << entry.mObject->Type() << endl;
 
-		BvhNode *intersect = dynamic_cast<BvhNode *>(entry.mObject);
+		BvhNode *intersect = static_cast<BvhNode *>(entry.mObject);
 		BvhNode *activeNode;
 
@@ -1861,5 +1861,5 @@
 		{
 			activeNode = 
-				dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode();
+				static_cast<BvhLeaf *>(intersect)->GetActiveNode();
 		}
 		else
@@ -1921,5 +1921,5 @@
 		else if (!vc->IsLeaf()) // interior cells: go down to leaf level
 		{
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -1958,5 +1958,5 @@
 		{
 			//cout <<" t";
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -2000,5 +2000,5 @@
 		{
 			//cout <<" t";
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
 
@@ -2024,5 +2024,5 @@
 	else
 	{
-		ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+		ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 #if 0
 		ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2005)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2017)
@@ -660,5 +660,5 @@
 	if (mCurrentBspNode) // replace front or (if not NULL) back child
 	{
-		BspInterior *interior = dynamic_cast<BspInterior *>(mCurrentBspNode);
+		BspInterior *interior = static_cast<BspInterior *>(mCurrentBspNode);
 
 		leaf = new BspLeaf(interior);
@@ -701,6 +701,6 @@
 		
 		//ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
-//		BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second);
-		BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit);
+//		BspViewCell *viewCell = static_cast<BspViewCell *>((*vit).second);
+		BspViewCell *viewCell = static_cast<BspViewCell *>(*vit);
 		if (viewCell->GetId() == viewCellId)
 		{
@@ -746,5 +746,5 @@
 	if (mCurrentBspNode) // replace NULL child of parent with current node
 	{
-		BspInterior *parent = dynamic_cast<BspInterior *>(mCurrentBspNode);
+		BspInterior *parent = static_cast<BspInterior *>(mCurrentBspNode);
 
 		parent->ReplaceChildLink(NULL, interior);
@@ -825,5 +825,5 @@
 			{	
 				ViewCellInterior *interior = 
-					dynamic_cast<ViewCellInterior *>(mCurrentViewCell);
+					static_cast<ViewCellInterior *>(mCurrentViewCell);
 				interior->SetupChildLink(viewCell);
 			}
@@ -1022,5 +1022,5 @@
 	if (mCurrentVspNode) // replace front or (if not NULL) back child
 	{
-		VspInterior *interior = dynamic_cast<VspInterior *>(mCurrentVspNode);
+		VspInterior *interior = static_cast<VspInterior *>(mCurrentVspNode);
 		leaf = new VspLeaf(interior);
 		interior->ReplaceChildLink(NULL, leaf);
@@ -1065,6 +1065,6 @@
 			Debug << "error: view cell " << viewCellId << " not found" << endl;
 	
-		//VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second);
-		VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit);
+		//VspViewCell *viewCell = static_cast<VspViewCell *>((*vit).second);
+		VspViewCell *viewCell = static_cast<VspViewCell *>(*vit);
 		
 		if (viewCell->GetId() == viewCellId)
@@ -1109,5 +1109,5 @@
 	if (mCurrentVspNode) // replace NULL child of parent with current node
 	{
-		VspInterior *parent = dynamic_cast<VspInterior *>(mCurrentVspNode);
+		VspInterior *parent = static_cast<VspInterior *>(mCurrentVspNode);
 
 		parent->ReplaceChildLink(NULL, interior);
@@ -1161,5 +1161,5 @@
 	if (mCurrentOspNode) // replace NULL child of parent with current node
 	{
-		KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentOspNode);
+		KdInterior *parent = static_cast<KdInterior *>(mCurrentOspNode);
 		parent->ReplaceChildLink(NULL, interior);
 		interior->mParent = parent;
@@ -1186,10 +1186,10 @@
 void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes)
 {
-	KdLeaf * leaf = new KdLeaf(dynamic_cast<KdInterior *>(mCurrentOspNode), NULL);
+	KdLeaf * leaf = new KdLeaf(static_cast<KdInterior *>(mCurrentOspNode), NULL);
 
 	if (mCurrentOspNode)
 	{
 		 // replace front or (if not NULL) back child
-		dynamic_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf);
+		static_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf);
 	}
 	else
@@ -1233,5 +1233,5 @@
 	if (mCurrentBvhNode) // replace front or (if not NULL) back child
 	{
-		BvhInterior *interior = dynamic_cast<BvhInterior *>(mCurrentBvhNode);
+		BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode);
 		leaf = new BvhLeaf(box, interior, (int)objects.size());
 		interior->ReplaceChildLink(NULL, leaf);
@@ -1317,5 +1317,5 @@
 	if (mCurrentBvhNode) // replace NULL child of parent with current node
 	{
-		BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode);
+		BvhInterior *parent = static_cast<BvhInterior *>(mCurrentBvhNode);
 		parent->ReplaceChildLink(NULL, interior);
 		interior->SetParent(parent);
@@ -1380,5 +1380,5 @@
     }
 
-  cout<<"parsing started"<<endl<<flush;
+  //cout<<"parsing started"<<endl<<flush;
 
   //
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 1779)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 2017)
@@ -418,5 +418,5 @@
 						   const bool globalCriteriaMet)
 {
-	OspSubdivisionCandidate *sc = dynamic_cast<OspSubdivisionCandidate *>(splitCandidate);
+	OspSubdivisionCandidate *sc = static_cast<OspSubdivisionCandidate *>(splitCandidate);
 	OspTraversalData &tData = sc->mParentData;
 
@@ -475,5 +475,5 @@
 		if (mStoreRays)
 		{
-			KdLeaf *leaf = dynamic_cast<KdLeaf *>(newNode);
+			KdLeaf *leaf = static_cast<KdLeaf *>(newNode);
 
 			RayInfoContainer::const_iterator it, it_end = tData.mRays->end();
@@ -1509,8 +1509,8 @@
 	if (!node->IsLeaf())
 	{
-		return (dynamic_cast<KdInterior *>(node))->mBox;		
-	}
-
-	KdInterior *parent = dynamic_cast<KdInterior *>(node->mParent);
+		return (static_cast<KdInterior *>(node))->mBox;		
+	}
+
+	KdInterior *parent = static_cast<KdInterior *>(node->mParent);
 
 	AxisAlignedBox3 box(parent->mBox);
@@ -1575,5 +1575,5 @@
 		for (vit = tmpViewCells.begin(); vit != vit_end; ++ vit)
 		{
-			VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit);
+			VspViewCell *vc = static_cast<VspViewCell *>(*vit);
 
 			if (!vc->Mailed())
@@ -1590,5 +1590,5 @@
 	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
 	{
-		VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit);
+		VspViewCell *vc = static_cast<VspViewCell *>(*vit);
 
 		VspLeaf *leaf = vc->mLeaves[0];
@@ -1630,10 +1630,10 @@
 		if (node->IsLeaf()) 
 		{
-			leaf = dynamic_cast<KdLeaf *>(node);
+			leaf = static_cast<KdLeaf *>(node);
 		} 
 		else 	
 		{	
 			// find point
-			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+			KdInterior *interior = static_cast<KdInterior *>(node);
         
 			if (interior->mPosition > pt[interior->mAxis])
@@ -2283,5 +2283,5 @@
 	if (node->IsLeaf())
 	{
-		KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
+		KdLeaf *leaf = static_cast<KdLeaf *>(node);
 
 		stream << "<Leaf ";
@@ -2295,5 +2295,5 @@
 	else
 	{	
-		KdInterior *interior = dynamic_cast<KdInterior *>(node);
+		KdInterior *interior = static_cast<KdInterior *>(node);
 	
 		stream << "<Interior plane=\"" << interior->mPosition << " " 
@@ -2328,5 +2328,5 @@
 		if (node->IsLeaf())
 		{
-			KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
+			KdLeaf *leaf = static_cast<KdLeaf *>(node);
 
 			ObjectContainer::const_iterator oit, oit_end = tData.objects->end();
@@ -2340,5 +2340,5 @@
 		{
 			KdObjectsTraversalData frontData, backData;
-			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+			KdInterior *interior = static_cast<KdInterior *>(node);
 
 			frontData.objects = new ObjectContainer();
