Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 1606)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 1616)
@@ -225,8 +225,10 @@
 	int mCurrentEntityId;
 
-	typedef map<int, MovableObject *> MovableObjectsMap;
+	typedef map<int, MovableObject *> MovableMap;
 
 	/// hash table for view cells geometry
-    MovableObjectsMap mViewCellsGeometry;
+    MovableMap mViewCellsGeometry;
+
+	bool mViewCellsGeometryLoaded;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1595)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1616)
@@ -7,7 +7,11 @@
 #include "BoundingBoxConverter.h"
 #include "Containers.h"
+#include "IntersectableWrapper.h"
+//#include "KdTree.h"
+
 
 namespace Ogre {
 
+#define USE_KD_PVS 1
 class Entity;
 class OctreeSceneManager;
@@ -15,4 +19,24 @@
 class BvHierarchySceneManager;
 
+typedef vector<Entity *> EntityContainer;
+
+class ObjectsIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>
+{
+public:
+	ObjectsIntersectable(EntityContainer *item):
+	GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>(item) {}
+
+	// hack
+	ObjectsIntersectable::~ObjectsIntersectable() 
+	{
+		//CLEAR_CONTAINER(*mItem);
+		delete mItem;
+	}
+
+	int Type() const
+	{
+		return Intersectable::OBJECTS_INTERSECTABLE;
+	}
+};
 
 /**	Class which converts preprocessor types to OGRE types
@@ -42,5 +66,12 @@
 	}
 	
+	/** find object which fits best to this bounding box
+	*/
 	Entity *FindBestFittingObject(const AxisAlignedBox &box) const;
+	
+	/** find objects which are intersected by this box
+	*/
+	void FindIntersectingObjects(const AxisAlignedBox &box,
+								 vector<Entity *> &objects) const;
 
 	T *mSceneMgr;
@@ -74,4 +105,70 @@
 	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
 	// find the bbox which is closest to the current bbox
+	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
+	{
+		SceneNode *sn = *sit;
+		SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator();
+
+        while (oit.hasMoreElements())
+		{
+			MovableObject *mo = oit.getNext();
+
+			// we are only interested in scene entities
+			if (mo->getMovableType() != "Entity")
+			{
+				continue;
+			}
+			 mo->
+			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
+					
+			// compute measure how much aabbs overlap
+			overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox),
+									 OgreTypeConverter::ConvertFromOgre(bbox));
+	
+			 if (overlap > bestFit)
+			 {
+				 bestFit = overlap;
+				 bestFittingObj = static_cast<Entity *>(mo);
+
+				 // perfect fit => object found, early exit
+				 if (overlap >= thresh)
+				 {
+					 return bestFittingObj;	
+				 }
+			 }
+		}
+	}
+
+	if (0)
+	{
+		std::stringstream d; 
+		if (bestFittingObj)
+			d << "best fit: " << bestFit;     
+		else
+			d << "warning, no best fitting object\n" << box;
+	
+		Ogre::LogManager::getSingleton().logMessage(d.str());
+	}
+
+	return bestFittingObj;
+}
+//-----------------------------------------------------------------------
+template<typename T>
+void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box,
+															  EntityContainer &objects) const
+{
+	list<SceneNode *> sceneNodeList;
+			
+	// get intersecting scene nodes (= candidates)
+	//AxisAlignedBox mybox = EnlargeBox(box);
+	//mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
+	mSceneMgr->findNodesIn(box, sceneNodeList, NULL);
+
+	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
+
+	//GtpVisibilityPreprocessor::AxisAlignedBox nodeBox = OgreTypeConverter::ConvertFromOgre(mybox);
+	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box);
+
+	// find really intersecting objects
 	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
 	{
@@ -89,37 +186,75 @@
 			}
 			 
-			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
-					
-			// compute measure how much aabbs overlap
-			overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox),
-									 OgreTypeConverter::ConvertFromOgre(bbox));
-	
-			 if (overlap > bestFit)
+			//const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
+			const AxisAlignedBox bbox = mo->getWorldBoundingBox();
+
+			const bool overlaps = Overlap(nodeBox,
+										  OgreTypeConverter::ConvertFromOgre(bbox)
+										  );
+										  //,0.00001);
+	
+			 if (overlaps)
 			 {
-				 bestFit = overlap;
-				 bestFittingObj = static_cast<Entity *>(mo);
-
-				 // perfect fit => object found, early exit
-				 if (overlap >= thresh)
-				 {
-					 return bestFittingObj;	
-				 }
+				 objects.push_back(static_cast<Entity *>(mo));
 			 }
 		}
 	}
-
-	if (0)
-	{
-		std::stringstream d; 
-		if (bestFittingObj)
-			d << "best fit: " << bestFit;     
-		else
-			d << "warning, no best fitting object\n" << box;
-	
-		Ogre::LogManager::getSingleton().logMessage(d.str());
-	}
-
-	return bestFittingObj;
-}
+}
+
+#if USE_KD_PVS
+//-------------------------------------------------------------------------
+template<typename T>
+bool PlatFormBoundingBoxConverter<T>::IdentifyObjects(
+	const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes,
+	GtpVisibilityPreprocessor::ObjectContainer &objects) const
+{
+	Ogre::LogManager().logMessage("pvs: intersecting objects");
+	const long startTime = GtpVisibilityPreprocessor::GetTime();
+
+	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
+		const_iterator iit, iit_end = iboxes.end();
+  
+	int i = 0;
+
+	for (iit = iboxes.begin(); iit != iit_end; ++ iit, ++ i)
+	{
+		if ((i % 1000) == 0)
+		{
+			std::stringstream d; d << "found " << i << " objects";
+			Ogre::LogManager().getSingleton().logMessage(d.str());
+		}
+
+		const AxisAlignedBox box = OgreTypeConverter::ConvertToOgre((*iit).second);
+		
+		//GtpVisibilityPreprocessor::ObjectContainer *entryObjects = new EntityContainer();
+		EntityContainer *entryObjects = new EntityContainer();
+
+		// find all objects that intersect the bounding box
+		FindIntersectingObjects(box, *entryObjects);
+
+		/*vector<Entity *>::const_iterator mit, mit_end = sceneObjects.end();
+		
+		for (mit = sceneObjects.begin(); mit != mit_end; ++ mit)
+		{
+			Entity *ent = *mit;
+			// create new mesh instance
+			OgreMeshInstance *omi = new OgreGetOrCreateOgreMeshInstance(ent);
+			//omi->SetId((*iit).first);
+			entryObjects->push_back(omi);
+		}*/
+
+		ObjectsIntersectable *entry = 
+			new ObjectsIntersectable(entryObjects);
+		entry->SetId((*iit).first);
+		//kdObj->mBbox = (*iit).second;
+		objects.push_back(entry);
+	}
+
+	std::stringstream d; d << "finished object intersection in " << GtpVisibilityPreprocessor::TimeDiff(startTime, GtpVisibilityPreprocessor::GetTime()) * 1e-3 << "secs";
+	Ogre::LogManager().logMessage(d.str());
+
+	return true;
+}
+#else
 //-------------------------------------------------------------------------
 template<typename T>
@@ -138,7 +273,7 @@
 		Entity *ent = FindBestFittingObject(currentBox);
 
-		// create new mesh instance
 		if (ent)
 		{
+			// create new mesh instance
 			OgreMeshInstance *omi = new OgreMeshInstance(ent);
 			omi->SetId((*iit).first);
@@ -149,5 +284,5 @@
 	return true;
 }
-
+#endif
 
 typedef PlatFormBoundingBoxConverter<OctreeSceneManager> OctreeBoundingBoxConverter;
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreTypeConverter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreTypeConverter.cpp	(revision 1602)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreTypeConverter.cpp	(revision 1616)
@@ -40,6 +40,9 @@
 ManualObject *OgreTypeConverter::ConvertToOgre(GtpVisibilityPreprocessor::Mesh *mesh, SceneManager *sceneMgr)
 {
+	if (!mesh)
+		return NULL;
+
 	char name[100];
-	sprintf(name, "mesh%04d", mesh->GetId());
+	sprintf(name, "mesh%06d", mesh->GetId());
 
 	ManualObject* manual = sceneMgr->createManualObject(name);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1610)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1616)
@@ -21,5 +21,5 @@
 #include "OgreBoundingBoxConverter.h"
 #include <OgreManualObject.h>
-
+#include "IntersectableWrapper.h"
 
 namespace Ogre {
@@ -53,5 +53,6 @@
 mDeleteQueueAfterRendering(true),
 mNormalExecution(false),
-mShowViewCells(false)
+mShowViewCells(false),
+mViewCellsGeometryLoaded(false)
 {
 	Ogre::LogManager::getSingleton().logMessage("creating occlusion culling scene manager");
@@ -179,24 +180,31 @@
 		getRenderQueue()->addRenderable(*it);
 	}
-
+/*
 	// set old view cell geometry to invisible
-    if (mCurrentViewCell && mCurrentViewCell->GetMesh())
+    if (mCurrentViewCell //&& mCurrentViewCell->GetMesh())
 	{
 		//const bool showSingleViewCell = true;
-		if (!mShowViewCells)
-		{
-			const int id = mCurrentViewCell->GetId();
-			mViewCellsGeometry[id]->_updateRenderQueue(getRenderQueue());
-		}
-		else
-		{
-			MovableObjectsMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
-			
-			for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
+		if (mViewCellsGeometryLoaded)
+		{
+			if (!mShowViewCells)
 			{
-				(*mit).second->_updateRenderQueue(getRenderQueue());
-			}	
-		}
-
+				const int id = mCurrentViewCell->GetId();
+
+				MovableMap::iterator fit = mViewCellsGeometry.find(id);
+				if ((fit != mViewCellsGeometry.end()) && (*fit).second)
+					(*fit).second->_updateRenderQueue(getRenderQueue());
+			}
+			else
+			{
+				MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
+
+				for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
+				{
+					if ((*mit).second)
+						(*mit).second->_updateRenderQueue(getRenderQueue());
+				}	
+			}
+		}
+		
 		GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator 
 			oit, oit_end = mCurrentViewCell->GetPvs().mEntries.end();
@@ -204,9 +212,66 @@
 		for (oit = mCurrentViewCell->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
 		{
-			OgreMeshInstance *obj = static_cast<OgreMeshInstance *>((*oit).first);
-			obj->GetEntity()->_updateRenderQueue(getRenderQueue());
+			GtpVisibilityPreprocessor::Intersectable *entry = (*oit).first;
+
+			if (entry->Type() == GtpVisibilityPreprocessor::Intersectable::OBJECTS_INTERSECTABLE)
+			{
+				ObjectsIntersectable *oi = dynamic_cast<ObjectsIntersectable *>(entry);
+				
+				EntityContainer *entries = oi->GetItem();
+				
+				EntityContainer::const_iterator eit, eit_end = entries->end();
+						
+				for (eit = entries->begin(); eit != eit_end; ++ eit)
+				{
+					(*eit)->setUserAny(Any((int)0));
+				}
+			}
+		}
+
+		for (oit = mCurrentViewCell->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
+		{
+			GtpVisibilityPreprocessor::Intersectable *entry = (*oit).first;
+		
+			switch (entry->Type())
+			{	
+				case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
+					{
+						OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(entry);
+						omi->GetEntity()->_updateRenderQueue(getRenderQueue());
+					}
+					break;
+				case GtpVisibilityPreprocessor::Intersectable::OBJECTS_INTERSECTABLE:
+					{
+						ObjectsIntersectable *oi = dynamic_cast<ObjectsIntersectable *>(entry);
+					
+						EntityContainer *entries = oi->GetItem();
+						EntityContainer::const_iterator eit, eit_end = entries->end();
+						
+						for (eit = entries->begin(); eit != eit_end; ++ eit)
+						{
+							//OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(*eit);
+							Entity *ent = *eit;
+							Any newAny = ent->getUserAny();
+
+							int flt = any_cast<int>(newAny);
+							//std::stringstream d; d << "any: " << flt << " ";
+							//Ogre::LogManager::getSingleton().logMessage(d.str());
+							if (any_cast<int>(newAny) == 0)
+							{
+								ent->setUserAny(Any((int)1));
+								ent->_updateRenderQueue(getRenderQueue());
+							}
+
+							//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+						}
+					}
+					break;
+				default:
+					break;
+			}
 		}	
 	}
-/*
+*/
+
     if (mRenderNodesForViz || mRenderNodesContentForViz)
 	{
@@ -242,5 +307,5 @@
 			}
 		}
-	}*/
+	}
 }
 //-----------------------------------------------------------------------
@@ -635,4 +700,11 @@
 			// all objects are set to invisible per default
 			SetObjectsVisible(!mUseViewCells);
+
+			/*MovableObjectIterator movit = getMovableObjectIterator("Entity");
+			while (movit.hasMoreElements())
+			{
+				Entity *ent = static_cast<Entity *>(movit.getNext());
+				ent->setVisible(!mUseViewCells);
+			}*/
 		}
 
@@ -1090,8 +1162,37 @@
 	for (it = mObjects.begin(); it != it_end; ++ it)
 	{
-		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*it);
-		Entity *ent = omi->GetEntity();
-		
-		ent->setVisible(visible);
+		GtpVisibilityPreprocessor::Intersectable *entry = *it;
+
+		switch (entry->Type())
+		{
+			case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
+				{
+					OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(entry);
+					omi->GetEntity()->setVisible(visible);
+					//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+				}
+				break;
+			case GtpVisibilityPreprocessor::Intersectable::OBJECTS_INTERSECTABLE:
+				{
+					//GtpVisibilityPreprocessor::ObjectsIntersectable *oi = 
+					//	dynamic_cast<GtpVisibilityPreprocessor::ObjectsIntersectable *>(entry);
+					ObjectsIntersectable *oi = dynamic_cast<ObjectsIntersectable *>(entry);
+
+					//GtpVisibilityPreprocessor::ObjectContainer *entries = oi->GetItem();
+					EntityContainer *entries = oi->GetItem();
+					EntityContainer::const_iterator eit,
+						eit_end = entries->end();
+					for (eit = entries->begin(); eit != eit_end; ++ eit)
+					{
+						//OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(*eit);
+						Entity *ent = *eit;
+						ent->setVisible(visible);
+						//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+					}
+				}
+				break;
+			default:
+				break;
+		}
 	}
 }
@@ -1099,7 +1200,4 @@
 bool OcclusionCullingSceneManager::LoadViewCells(const String &filename)
 {
-	// objects are set to invisible initially
-	SetObjectsVisible(false);
-	
 	// converter between view cell ids and Ogre entites 
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
@@ -1110,4 +1208,9 @@
 	mViewCellsManager = 
 		GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects, true, &bconverter);
+
+	Ogre::LogManager().getSingleton().logMessage("view cells loaded");
+	//Ogre::LogManager().getSingleton().flush();
+	// objects are set to invisible initially
+	SetObjectsVisible(false);
 
 	if (finalizeViewCells)
@@ -1126,6 +1229,6 @@
 	{	
 		// if no there is no view cell, set everything visible
-		SetObjectsVisible(true);
-
+		//SetObjectsVisible(true);
+SetObjectsVisible(false);
 		return;
 	}
@@ -1139,10 +1242,41 @@
 	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
 	{
+		GtpVisibilityPreprocessor::Intersectable *entry = (*oit).first;
 		// no associated geometry found
-		if (!(*oit).first) continue;
-
-		OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>((*oit).first);
-		omi->GetEntity()->setVisible(load);
-		//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+		if (!entry) continue;
+	
+		switch (entry->Type())
+		{
+			case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
+				{
+					OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(entry);
+					omi->GetEntity()->setVisible(load);
+					//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+				}
+				break;
+			case GtpVisibilityPreprocessor::Intersectable::OBJECTS_INTERSECTABLE:
+				{
+					//GtpVisibilityPreprocessor::ObjectsIntersectable *oi = 
+					//	dynamic_cast<GtpVisibilityPreprocessor::ObjectsIntersectable *>(entry);
+					ObjectsIntersectable *oi = dynamic_cast<ObjectsIntersectable *>(entry);
+
+					//GtpVisibilityPreprocessor::ObjectContainer *entries = oi->GetItem();
+					EntityContainer *entries = oi->GetItem();
+
+					EntityContainer::const_iterator eit,
+						eit_end = entries->end();
+					for (eit = entries->begin(); eit != eit_end; ++ eit)
+					{
+						//OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(*eit);
+						//omi->GetEntity()->setVisible(load);
+						Entity *ent = *eit;
+						ent->setVisible(load);					
+						//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
+					}
+				}
+				break;
+			default:
+				break;
+		}
 	}
 }
@@ -1208,5 +1342,5 @@
 void OcclusionCullingSceneManager::CreateViewCellsGeometry()
 {
-	LogManager::getSingleton().logMessage("creating view cells geometry");
+	//LogManager::getSingleton().logMessage("creating view cells geometry");
 
 	GtpVisibilityPreprocessor::ViewCellContainer viewCells = mViewCellsManager->GetViewCells();
@@ -1217,26 +1351,33 @@
 		GtpVisibilityPreprocessor::ViewCell *viewCell = *it;
 
-		std::stringstream str;
-		str << "processing view cell with id : " << viewCell->GetId();
-		LogManager::getSingleton().logMessage(str.str());
+		//std::stringstream str;
+		//str << "processing view cell with id : " << viewCell->GetId();
+		//LogManager::getSingleton().logMessage(str.str());
 		ManualObject *manual = OgreTypeConverter::ConvertToOgre(viewCell->GetMesh(), this);
-		mViewCellsGeometry[viewCell->GetId()] = manual;
-
-		// attach to scene node
-		getRootSceneNode()->createChildSceneNode()->attachObject(manual);
-		manual->setQueryFlags(0); // returned by no query
-	
-		// initialy set to invisible
-		manual->setVisible(false);
-	}
+		
+		if (manual)
+		{
+			mViewCellsGeometry[viewCell->GetId()] = manual;
+
+			// attach to scene node
+			getRootSceneNode()->createChildSceneNode()->attachObject(manual);
+			manual->setQueryFlags(0); // returned by no query
+	
+			// initialy set to invisible
+			manual->setVisible(false);
+		}
+	}
+	
+	mViewCellsGeometryLoaded = true;
 }
 //-------------------------------------------------------------------------
 void OcclusionCullingSceneManager::VisualizeViewCells(const bool visualize)
 {
-	MovableObjectsMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
+	MovableMap::const_iterator mit, mit_end = mViewCellsGeometry.end();
 			
 	for (mit = mViewCellsGeometry.begin(); mit != mit_end; ++ mit)
 	{
-		(*mit).second->setVisible(visualize);
+		if ((*mit).second)
+			(*mit).second->setVisible(visualize);
 	}	
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1614)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1616)
@@ -608,8 +608,9 @@
 	ViewCellsManager *vm = NULL;
 
-	if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter))
-	{
-		const long startTime = GetTime();
-
+	const long startTime = GetTime();
+	bool success = parser.ParseViewCellsFile(filename, &vm, objects, bconverter);
+
+	if (success)
+	{
 		vm->ResetViewCells();
 
@@ -621,5 +622,5 @@
 			// create the meshes and compute volumes
 			vm->FinalizeViewCells(true);
-			//			vm->mViewCellsTree->AssignRandomColors();
+			// vm->mViewCellsTree->AssignRandomColors();
 		}
 
@@ -3909,5 +3910,5 @@
 	Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl;
 	
-	if (1) // export merged view cells
+	if (mShowVisualization) // export merged view cells
 	{
 		mColorCode = 0;
@@ -3940,5 +3941,5 @@
 	}
 
-	if (1) 
+	if (mShowVisualization) 
 	{
 		// use pvs size for color coding
@@ -3977,4 +3978,5 @@
 {
 	mRenderer->RenderScene();
+
 	SimulationStatistics ss;
 	dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
@@ -4703,5 +4705,6 @@
 		volume += lVol;
 
-        CreateMesh(*it);
+		if (createMesh)
+			CreateMesh(*it);
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1595)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1616)
@@ -271,5 +271,5 @@
 	// all bounding boxes gathered in this step => 
 	// associate object ids with bounding boxes
-	long startTime = GetTime();
+	const long startTime = GetTime();
 	
 	if (mBoundingBoxConverter)
