Index: /GTP/trunk/Lib/Vis/README_ONLINE.txt
===================================================================
--- /GTP/trunk/Lib/Vis/README_ONLINE.txt	(revision 673)
+++ /GTP/trunk/Lib/Vis/README_ONLINE.txt	(revision 897)
@@ -1,4 +1,6 @@
 How to install the Visibility Work Package
 
+
+ONLINE VISIBILITY (CHC + VIEW CELLS)
 
 1) Requirements: 
@@ -7,12 +9,45 @@
 
 2) check out gametools repository
-   in the following it is assumed that your repository is located in e:\svn\gametools (not required, just replace your path)
+   in the following it is assumed that your repository is located in d:\svn\gametools (not required, just replace your path)
 
 3) add following environment variables:
-   OGRE_PATH: points to directory where ogre.sln is located (i.e., the directory OGRE)
 
-4) Set preprocessor flag GTP_VISIBILITY_MODIFIED_OGRE to the example projects you want to use
+   OGRE_PATH: points to directory where ogre.sln is located (i.e., the
+directory OGRE), e.g. D:\svn\gametools\OGRE\trunk\ogrenew
+
+4) copy the ogre_dependencies and ogre_changes_12 into the ogrenew directory
+
+5) Set preprocessor flag GTP_VISIBILITY_MODIFIED_OGRE to the example projects you want to use
 
 5) open scripts GTP\trunk\Lib\Vis\shared\GtpVisibility.sln and build all
 
+
 6) start TerrainExampleApplication for testing
+
+
+
+
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+FOR USING THE PREPROCESSED VIEW CELLS:
+
+the same as above, before step 6) change in the code: 
+
+in 
+
+D:\svn\gametools\GTP\trunk\App\Demos\Vis\HillyTerrain\OGRE\TestCullingTerrainApplication.cpp
+
+replace 
+
+bool TestCullingTerrainApplication::msShowHillyTerrain = true;
+
+with 
+
+bool TestCullingTerrainApplication::msShowHillyTerrain = false;
+
+
+Then the vienna model is loaded together with the view cells. The
+usage of the view cells is toggled using key "V".
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h	(revision 726)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h	(revision 897)
@@ -19,5 +19,6 @@
 
 
-/**	Class which implements a hierarchy interface for a scene hierarchy.
+/**	Class which implements a hierarchy interface for a scene hierarchy. It has to be implemented
+	for any rendering engine to use the CHC algorithm.
 */
 class HierarchyInterface
@@ -33,9 +34,9 @@
 	*/
     virtual bool IsLeaf(HierarchyNode *node) const = 0;
-	/** Traverses and renders the given node. 
+	/** Traverses and renders the hierarchy from the given node. 
 		@param node the hierarchy node
 	*/
 	virtual void TraverseNode(HierarchyNode *node) = 0;
-	/** Renders current hierarchy node.
+	/** Renders the given hierarchy node.
 		@param node current hierarchy node to be rendered
 	*/
@@ -47,8 +48,10 @@
 	/** Issue a occlusion query for this node. 
 		@param node the current hierarchy node
+		@param wasVisible if the node was visible in the last frame: based
+		on this the method can decide on the way of querying
 		@returns occlusion query for this node
 	*/
 	virtual OcclusionQuery *IssueNodeOcclusionQuery(HierarchyNode *node, 
-		const bool wasVisible = false) = 0;
+													const bool wasVisible = false) = 0;
 	/** Sets the root of the scene hierarchy.
 		@param root the hierarchy root
@@ -122,8 +125,9 @@
 
 	/** Visualization of a culled node, dependent on the culling type. 
+		@param node the hierarchy node to be visualized
 		@param type can be one of FRUSTUM_CULLED, QUERY_CULLED
 	*/
 	virtual void VisualizeCulledNode(HierarchyNode *node, 
-		CullingType type) const = 0;
+									 CullingType type) const = 0;
 
 	/** Returns vector of visible hierarchy nodes from previous render.
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/QueryManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/QueryManager.h	(revision 316)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/QueryManager.h	(revision 897)
@@ -41,5 +41,8 @@
 	If NULL no visible meshes are not evaluated.
 
-	@param projectedPixels If true the visibility member for
+	@param visiblePatches Pointer to the container where visible patches should be added.
+	If NULL no visible meshes are not evaluated.
+
+	@param relativeVisibility If true the visibility member for
 	NodeInfo and MeshInfo represent relative visibility; i.e. the number of visible
 	pixels divided by the the number of projected pixels.
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/VisibilityManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/VisibilityManager.h	(revision 155)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/VisibilityManager.h	(revision 897)
@@ -45,5 +45,5 @@
 
 	/** Sets the threshold for the visibiliy culling algorithm.
-		@param visibilityThreshold number of visible pixels where an object 
+		@param threshold number of visible pixels where an object 
 		is still considered invisible.
 		@remark automatically sets the threshold of the current and of 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CullingManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CullingManager.h	(revision 114)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CullingManager.h	(revision 897)
@@ -47,6 +47,6 @@
 
 	/** Some visualization of culled nodes are shown, depending 
-	on the type of hierarchy.
-	@param showVisualization if true, culled nodes are visualized
+		on the type of hierarchy.
+		@param visualizeCulledNodes if true, culled nodes are visualized
 	*/
 	void SetVisualizeCulledNodes(bool visualizeCulledNodes);
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/GtpVisibility.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/GtpVisibility.vcproj	(revision 870)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/GtpVisibility.vcproj	(revision 897)
@@ -128,4 +128,7 @@
 			</File>
 			<File
+				RelativePath="..\include\QueryManager.h">
+			</File>
+			<File
 				RelativePath="..\src\StopAndWaitCullingManager.cpp">
 			</File>
@@ -171,7 +174,4 @@
 				</File>
 				<File
-					RelativePath="..\include\QueryManager.h">
-				</File>
-				<File
 					RelativePath="..\include\StopAndWaitCullingManager.h">
 				</File>
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h	(revision 868)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityTerrainSceneManager.h	(revision 897)
@@ -22,5 +22,5 @@
 {
 public:
-	VisibilityTerrainSceneManager(GtpVisibility::VisibilityManager *visManager);
+	VisibilityTerrainSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
 	~VisibilityTerrainSceneManager();
 
@@ -54,5 +54,6 @@
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 
+	virtual void renderObjects(const QueuedRenderableCollection& objs, 
+			QueuedRenderableCollection::OrganisationMode om, 
             bool doLightIteration, const LightList* manualLightList = 0);
 
@@ -61,8 +62,7 @@
 	void WriteLog();
 
-	/** Override pass so we can do the z-fail pass. 
-	*/
-	Pass* setPass(Pass* pass);
-
+	/** We override this because we want to include the z-fail pass. 
+	*/
+	const Pass* _setPass(Pass* pass);
 	/** Override from SceneManager so we can skip all but first pass for depth pass. 
 	*/
@@ -70,4 +70,5 @@
 	/** This function renders renderables using false color ids.
 	*/
+#ifdef ITEM_BUFFER
 	void RenderItemBuffer(RenderPriorityGroup* pGroup);
 	/** Renders a single object using false color id.
@@ -77,5 +78,6 @@
 		scene objects.
 	*/
-	void renderQueueGroupObjects(RenderQueueGroup* pGroup);
+#endif // ITEM_BUFFER
+	void _renderQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om);
 
 	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
@@ -97,14 +99,15 @@
 	/** Override this because we must handle shadows differently.
 	*/
-	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
+	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
 	/** Override this because we must handle shadows differently.
 	*/
-	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
-
-	/** Override standard function so octree boxes are always of equal side length.
-		This has advantages for CHC, because terrain tiles are in different octree nodes
-		and can be culled.
-	*/
-	void setWorldGeometry(const String& filename);
+	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 
+		QueuedRenderableCollection::OrganisationMode om);
+/// @copydoc SceneManager::getTypeName
+	const String& getTypeName(void) const;
+	static const String FACTORY_TYPE_NAME;
+
+	void setWorldGeometry( DataStreamPtr& stream, const String& typeName );
 
 protected:
@@ -178,4 +181,21 @@
 };
 
+/// Factory for VisibilityTerrainSceneManager
+class VisibilityTerrainSceneManagerFactory : public SceneManagerFactory
+{
+protected:
+	typedef std::vector<TerrainPageSource*> TerrainPageSources;
+	TerrainPageSources mTerrainPageSources;
+	void initMetaData(void) const;
+	GtpVisibility::VisibilityManager *visManager;
+public:
+	VisibilityTerrainSceneManagerFactory(GtpVisibility::VisibilityManager *vm);
+	~VisibilityTerrainSceneManagerFactory();
+	/// Factory type name
+	static const String FACTORY_TYPE_NAME;
+	SceneManager* createInstance(const String& instanceName);
+	void destroyInstance(SceneManager* instance);
+};
+
 } // namespace Ogre
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 868)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 897)
@@ -7,12 +7,10 @@
 #include <OgreOctreeCamera.h>
 #include <OgrePrerequisites.h>
-
+#include <OgreMovableObject.h>
 #include "OgreOctreeHierarchyInterface.h"
 #include "OgrePlatformQueryManager.h"
 #include "VisibilityManager.h"
+#include "Containers.h"
 #include "ViewCellsManager.h"
-
-//class GtpVisibilityPreprocessor::ViewCellsManager;
-
 
 namespace Ogre {
@@ -25,5 +23,5 @@
 {
 public:
-	OcclusionCullingSceneManager(GtpVisibility::VisibilityManager *visManager);
+	OcclusionCullingSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
 	~OcclusionCullingSceneManager();
 
@@ -57,5 +55,6 @@
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 
+	virtual void renderObjects(const QueuedRenderableCollection& objs, 
+			QueuedRenderableCollection::OrganisationMode om, 
             bool doLightIteration, const LightList* manualLightList = 0);
 
@@ -66,19 +65,15 @@
 	/** Override pass so we can do the z-fail pass. 
 	*/
-	Pass* setPass(Pass* pass);
+	const Pass* _setPass(Pass* pass);
 
 	/** Override from SceneManager so we can skip all but first pass for depth pass. 
 	*/
 	bool validatePassForRendering(Pass* pass);
-	/** This function renders renderables using false color ids.
-	*/
+#ifdef ITEM_BUFFER
 	void RenderItemBuffer(RenderPriorityGroup* pGroup);
-	/** Renders a single object using false color id.
-	*/
 	void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
-	/** Overritten from scene manager to include the false color id rendering of the
-		scene objects.
-	*/
-	void renderQueueGroupObjects(RenderQueueGroup* pGroup);
+#endif // ITEM_BUFFER
+	void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
 
 	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
@@ -94,17 +89,21 @@
 	OctreeHierarchyInterface *GetHierarchyInterface();
 
-	/** Override this because we must handle shadows differently.
+	/** Inherited from scene manager. Neccesary to draw terrain properly.
 	*/
 	void endFrame();
 
-	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
-	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
+	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
+	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
 
 	/** Override standard function so octree boxes are always of equal side length.
 		This has advantages for CHC, because terrain tiles are in different octree nodes
 		and can be culled.
+		msz: Modified to reflect changes in Ogre::TerrainSceneManager
 	*/
-	void setWorldGeometry( const String& filename );
+	virtual void setWorldGeometry( DataStreamPtr& stream, const String& typeName );
 
+	
 	/** Loads view cells for this particular scene.
 	*/
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilitySceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilitySceneManager.h	(revision 115)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilitySceneManager.h	(revision 897)
@@ -18,5 +18,5 @@
 {
 public:
-	VisibilitySceneManager(GtpVisibility::VisibilityManager *visManager);
+	VisibilitySceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
 	~VisibilitySceneManager();
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 880)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h	(revision 897)
@@ -7,5 +7,5 @@
 #include <OgreOctreeCamera.h>
 #include <OgrePrerequisites.h>
-
+#include <OgreMovableObject.h>
 #include "OgreOctreeHierarchyInterface.h"
 #include "OgrePlatformQueryManager.h"
@@ -25,5 +25,5 @@
 {
 public:
-	VisibilityOctreeSceneManager(GtpVisibility::VisibilityManager *visManager);
+	VisibilityOctreeSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
 	~VisibilityOctreeSceneManager();
 
@@ -57,5 +57,6 @@
 		Override so we can handle delayed rendering of transparent objects
 	*/
-	virtual void renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 
+	virtual void renderObjects(const QueuedRenderableCollection& objs, 
+			QueuedRenderableCollection::OrganisationMode om, 
             bool doLightIteration, const LightList* manualLightList = 0);
 
@@ -66,19 +67,14 @@
 	/** Override pass so we can do the z-fail pass. 
 	*/
-	Pass* setPass(Pass* pass);
+	const Pass* _setPass(Pass* pass);
 
 	/** Override from SceneManager so we can skip all but first pass for depth pass. 
 	*/
 	bool validatePassForRendering(Pass* pass);
-	/** This function renders renderables using false color ids.
-	*/
+#ifdef ITEM_BUFFER
 	void RenderItemBuffer(RenderPriorityGroup* pGroup);
-	/** Renders a single object using false color id.
-	*/
 	void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
-	/** Overritten from scene manager to include the false color id rendering of the
-		scene objects.
-	*/
-	void renderQueueGroupObjects(RenderQueueGroup* pGroup);
+#endif // ITEM_BUFFER
+	void _renderQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om);
 
 	/** Override from SceneManager so that sub entities can be assigned an id for item buffer.
@@ -94,8 +90,8 @@
 	OctreeHierarchyInterface *GetHierarchyInterface();
 
-	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
-	/** Override this because we must handle shadows differently.
-	*/
-	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
+	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, 
+		QueuedRenderableCollection::OrganisationMode om);
+	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
+		QueuedRenderableCollection::OrganisationMode om);
 
 	void loadVisibilityConfig(const String& filename);
@@ -158,10 +154,10 @@
 	bool mRenderNodesContentForViz;
 
-	/// if we render transparents after the hierarchical traversal
+	/// render transparents after the hierarchical traversal
 	bool mDelayRenderTransparents;
 
-	/// if we use a depth pass (i.e., fill only the depth buffer in the first pass)
+	/// use a depth pass (i.e., fill only the depth buffer in the first pass)
 	bool mUseDepthPass;
-	/// if we currently rendering the depth pass
+	/// flag indicating if we currently render the depth pass
 	bool mIsDepthPassPhase;
 
@@ -209,4 +205,22 @@
 };
 
+/// Factory for VisibilityOctreeSceneManager
+class VisibilityOctreeSceneManagerFactory : public SceneManagerFactory
+{
+protected:
+	void initMetaData(void) const;
+	GtpVisibility::VisibilityManager *visManager;
+public:
+	VisibilityOctreeSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
+	{
+		visManager = vm;
+	}
+	~VisibilityOctreeSceneManagerFactory() {}
+	/// Factory type name
+	static const String FACTORY_TYPE_NAME;
+	SceneManager* createInstance(const String& instanceName);
+	void destroyInstance(SceneManager* instance);
+};
+
 } // namespace Ogre
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformHierarchyInterface.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformHierarchyInterface.h	(revision 726)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformHierarchyInterface.h	(revision 897)
@@ -110,5 +110,5 @@
 	/** Deletes all occlusion queries.
 	*/
-	void DeleteQueries();
+	void ResetQueries();
 
 protected:
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h	(revision 316)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgrePlatformQueryManager.h	(revision 897)
@@ -43,5 +43,5 @@
 
 protected:
-
+#ifdef ITEM_BUFFER
 	void CollectItemBufferResults(
 				GtpVisibility::MeshInfoContainer *visibleGeometry,
@@ -50,4 +50,5 @@
 	void InitItemBuffer(GtpVisibility::MeshInfoContainer *visibleGeometry,
 						GtpVisibility::PatchInfoContainer *visiblePatches);
+#endif // ITEM_BUFFER
 
 	Viewport *mViewport;
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 863)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 897)
@@ -104,10 +104,10 @@
 				Name="VCLinkerTool"
 				IgnoreImportLibrary="TRUE"
-				AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib GtpVisibility.lib Preprocessor.lib xerces-c_2.lib zdll.lib zziplibd.lib devil.lib qtmain.lib QtOpenGL4.lib QtCored4.lib QtGuid4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib"
+				AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib GtpVisibility.lib zdll.lib zziplibd.lib Preprocessor.lib xerces-c_2.lib devil.lib qtmain.lib QtOpenGL4.lib QtCored4.lib QtGuid4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib"
 				OutputFile="$(OutDir)/Plugin_VisibilitySceneManager.dll"
 				Version="0.99"
 				LinkIncremental="1"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\support\xercesc\lib\;..\..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\..\NonGTP\zlib\lib;..\..\..\..\..\..\..\NonGTP\Devil\lib;&quot;$(QTDIR)\lib&quot;;&quot;$(CG_LIB_PATH)&quot;;..\..\..\Preprocessing\src\GL"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\lib;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;&quot;$(QTDIR)\lib&quot;;..\..\..\Preprocessing\src\GL;&quot;$(CG_LIB_PATH)&quot;"
 				ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def"
 				GenerateDebugInformation="TRUE"
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 868)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityTerrainSceneManager.cpp	(revision 897)
@@ -10,14 +10,16 @@
 #include <OgreSubEntity.h>
 #include <OgreConfigFile.h>
+#include <OgreMaterialManager.h>
+#include <OgreHeightmapTerrainPageSource.h>
 
 // normal terrain rendering
-const static NORMAL_RENDER_HACK = false;
+const static int NORMAL_RENDER_HACK = false;
 
 namespace Ogre {
 
 //-----------------------------------------------------------------------
-VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(
+VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(const String& name, 
 	GtpVisibility::VisibilityManager *visManager):
-TerrainSceneManager(),
+TerrainSceneManager(name),
 mVisibilityManager(visManager), 
 mShowVisualization(false),
@@ -62,7 +64,9 @@
 
         mDepthPass = depthMat->getTechnique(0)->getPass(0);
+
 		mDepthPass->setColourWriteEnabled(false);
 		mDepthPass->setDepthWriteEnabled(true);
 		mDepthPass->setLightingEnabled(false);
+		//mDepthPass->setDepthCheckEnabled(false);
 	}
 	else
@@ -152,9 +156,9 @@
 }
 //-----------------------------------------------------------------------
-Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
+const Pass *VisibilityTerrainSceneManager::_setPass(Pass* pass)
 {
 	if (NORMAL_RENDER_HACK)
 	{
-		return SceneManager::setPass(pass);
+		return SceneManager::_setPass(pass);
 	}
 
@@ -212,5 +216,5 @@
 
 	//-- set actual pass here
-	Pass *result = SceneManager::setPass(usedPass);
+	const Pass *result = SceneManager::_setPass(usedPass);
 
 
@@ -391,5 +395,5 @@
 
 	getRenderQueue()->clear(); // finally clear render queue
-	if (1) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
+	if (0) OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
 
 	if (0) WriteLog(); // write out stats
@@ -491,10 +495,10 @@
 		if (useArbQueries)
 		{
-			mHierarchyInterface->DeleteQueries();
+			mHierarchyInterface->ResetQueries();
 			mDestRenderSystem->setConfigOption("ArbQueries", "Yes");
 		}
 		else
 		{
-			mHierarchyInterface->DeleteQueries();
+			mHierarchyInterface->ResetQueries();
 			mDestRenderSystem->setConfigOption("ArbQueries", "No");
 		}
@@ -559,7 +563,7 @@
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::renderObjects(
-						const RenderPriorityGroup::TransparentRenderablePassList& objs, 
-                        bool doLightIteration, 
-						const LightList* manualLightList)
+	const QueuedRenderableCollection& objs,
+	QueuedRenderableCollection::OrganisationMode om,
+	bool doLightIteration, const LightList* manualLightList)
 {
 	// for correct rendering, transparents must be rendered after hierarchical culling
@@ -567,5 +571,5 @@
 	if (NORMAL_RENDER_HACK || !mSkipTransparents)
 	{
-		SceneManager::renderObjects(objs, doLightIteration, manualLightList);
+		SceneManager::renderObjects(objs, om, doLightIteration, manualLightList);
 	}
 }
@@ -592,12 +596,13 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityTerrainSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
+void VisibilityTerrainSceneManager::_renderQueueGroupObjects(
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
 	if (NORMAL_RENDER_HACK || !mIsItemBufferPhase)
 	{
-		OctreeSceneManager::renderQueueGroupObjects(pGroup);
+		SceneManager::_renderQueueGroupObjects(pGroup, om);
 		return;
 	}
-
+#ifdef ITEM_BUFFER
 	//-- item buffer: render objects using false colors
 
@@ -609,5 +614,7 @@
 		RenderItemBuffer(groupIt.getNext());
 	}
-}
+#endif // ITEM_BUFFER
+}
+#ifdef ITEM_BUFFER
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
@@ -715,4 +722,5 @@
 	renderSingleObject(rend, usedPass, false, &nullLightList);
 }
+#endif // ITEM_BUFFER
 //-----------------------------------------------------------------------
 GtpVisibility::VisibilityManager *VisibilityTerrainSceneManager::GetVisibilityManager()
@@ -757,6 +765,6 @@
 
 			// just render ambient stuff
-			mIlluminationStage = IRS_AMBIENT;
-			getRenderQueue()->setSplitPassesByLightingType(true);
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT;
 		}
 	
@@ -818,5 +826,5 @@
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
-	RenderQueueGroup* pGroup)
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
 	// only render solid passes during hierarchical culling
@@ -837,19 +845,20 @@
 
 			// Render all the ambient passes first, no light iteration, no lights
-			mIlluminationStage = IRS_AMBIENT;
-
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), false, &lightList);
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT;
+
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
 			// Also render any objects which have receive shadows disabled
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesNoShadow(), true);
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
 		}
 	}
 	else // render the rest of the passes
 	{
-		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup);
+		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
 	}
 }
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
-	RenderQueueGroup* pGroup)
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
    if (mIsHierarchicalCulling)
@@ -866,15 +875,20 @@
 
 		   // Do (shadowable) solids
-		   OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), true);
+		   OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
 	   }
    }
    else
    {
-	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup);
+	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
    }
 }
 
+const String& VisibilityTerrainSceneManager::getTypeName(void) const
+{
+	return VisibilityTerrainSceneManagerFactory::FACTORY_TYPE_NAME;
+}
+
 //-------------------------------------------------------------------------
-void VisibilityTerrainSceneManager::setWorldGeometry( const String& filename )
+void VisibilityTerrainSceneManager::setWorldGeometry( DataStreamPtr& stream, const String& typeName )
 {
     // Clear out any existing world resources (if not default)
@@ -885,8 +899,9 @@
             ResourceGroupManager::getSingleton().getWorldResourceGroupName());
     }
-
+	destroyLevelIndexes();
     mTerrainPages.clear();
     // Load the configuration
-    loadConfig(filename);
+    loadConfig( stream );
+	initLevelIndexes();
 
     // Resize the octree, allow for 1 page for now
@@ -895,17 +910,58 @@
     float max_z = mOptions.scale.z * mOptions.pageSize;
 
-	//-- note: slows down view frustum culling!
-#if 1
 	float maxAxis = std::max(max_x, max_y);
 	maxAxis = std::max(maxAxis, max_z);
 	resize( AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis ) );
-#else
-	resize( AxisAlignedBox( 0, 0, 0, max_x, max_y, max_z ) );
-#endif
-
+    
     setupTerrainMaterial();
+
     setupTerrainPages();
 
  }
 
+	//-----------------------------------------------------------------------
+	const String VisibilityTerrainSceneManagerFactory::FACTORY_TYPE_NAME = "VisibilityTerrainSceneManager";
+	//-----------------------------------------------------------------------
+	VisibilityTerrainSceneManagerFactory::VisibilityTerrainSceneManagerFactory(
+		GtpVisibility::VisibilityManager *vm)
+	{
+		visManager = vm;
+	}
+	//-----------------------------------------------------------------------
+	VisibilityTerrainSceneManagerFactory::~VisibilityTerrainSceneManagerFactory()
+	{
+		for (TerrainPageSources::iterator i = mTerrainPageSources.begin();
+			i != mTerrainPageSources.end(); ++i)
+		{
+			delete *i;
+		}
+		mTerrainPageSources.clear();
+	}
+	//-----------------------------------------------------------------------
+	void VisibilityTerrainSceneManagerFactory::initMetaData(void) const
+	{
+		mMetaData.typeName = FACTORY_TYPE_NAME;
+		mMetaData.description = "Scene manager which generally organises the scene on "
+			"the basis of an octree, but also supports terrain world geometry and has awesome (TM) occlusion culling capabilities. ";
+		mMetaData.sceneTypeMask = ST_EXTERIOR_CLOSE; // previous compatiblity
+		mMetaData.worldGeometrySupported = true;
+	}
+	//-----------------------------------------------------------------------
+	SceneManager* VisibilityTerrainSceneManagerFactory::createInstance(
+		const String& instanceName)
+	{
+		VisibilityTerrainSceneManager* tsm = new VisibilityTerrainSceneManager(instanceName, visManager);
+		// Create & register default sources (one per manager)
+		HeightmapTerrainPageSource* ps = new HeightmapTerrainPageSource();
+		mTerrainPageSources.push_back(ps);
+		tsm->registerPageSource("Heightmap", ps);
+
+		return tsm;
+	}
+	//-----------------------------------------------------------------------
+	void VisibilityTerrainSceneManagerFactory::destroyInstance(SceneManager* instance)
+	{
+		delete instance;
+	}
+
 } // namespace Ogre
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 868)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 897)
@@ -10,4 +10,5 @@
 #include <OgreEntity.h>
 #include <OgreSubEntity.h>
+#include <OgreMaterialManager.h>
 #include <OgreIteratorWrappers.h>
 #include "VspBspTree.h"
@@ -22,7 +23,7 @@
 
 //-----------------------------------------------------------------------
-OcclusionCullingSceneManager::OcclusionCullingSceneManager(
-							GtpVisibility::VisibilityManager *visManager): 
-TerrainSceneManager(),
+OcclusionCullingSceneManager::OcclusionCullingSceneManager(const String& name, 
+							GtpVisibility::VisibilityManager *visManager):
+TerrainSceneManager(name),
 mVisibilityManager(visManager), 
 mShowVisualization(false),
@@ -35,4 +36,5 @@
 mIsDepthPassPhase(false),
 mUseItemBuffer(false),
+//mUseItemBuffer(true),
 mIsItemBufferPhase(false),
 mCurrentEntityId(1),
@@ -105,4 +107,35 @@
 	//mItemBufferPass->setAmbient(1, 1, 0);
 }
+//-------------------------------------------------------------------------
+void OcclusionCullingSceneManager::setWorldGeometry( DataStreamPtr& stream, const String& typeName )
+{
+    // Clear out any existing world resources (if not default)
+    if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() != 
+        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
+    {
+        ResourceGroupManager::getSingleton().clearResourceGroup(
+            ResourceGroupManager::getSingleton().getWorldResourceGroupName());
+    }
+	destroyLevelIndexes();
+    mTerrainPages.clear();
+    // Load the configuration
+    loadConfig( stream );
+	initLevelIndexes();
+
+    // Resize the octree, allow for 1 page for now
+    float max_x = mOptions.scale.x * mOptions.pageSize;
+    float max_y = mOptions.scale.y;
+    float max_z = mOptions.scale.z * mOptions.pageSize;
+
+	float maxAxis = std::max(max_x, max_y);
+	maxAxis = std::max(maxAxis, max_z);
+	resize( AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis ) );
+    
+    setupTerrainMaterial();
+
+    setupTerrainPages();
+
+ }
+
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::PrepareVisualization(Camera *cam)
@@ -157,9 +190,9 @@
 }
 //-----------------------------------------------------------------------
-Pass *OcclusionCullingSceneManager::setPass(Pass* pass)
+const Pass *OcclusionCullingSceneManager::_setPass(Pass* pass)
 {
 	if (NORMAL_RENDER_HACK)
 	{
-		return SceneManager::setPass(pass);
+		return SceneManager::_setPass(pass);
 	}
 
@@ -217,5 +250,5 @@
 
 	//-- set actual pass here
-	Pass *result = SceneManager::setPass(usedPass);
+	const Pass *result = SceneManager::_setPass(usedPass);
 
 
@@ -232,5 +265,6 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
+void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam,
+														bool onlyShadowCasters)
 {
 	if (NORMAL_RENDER_HACK)
@@ -335,5 +369,5 @@
 		addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
 		addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
-			
+	
 		// exclude this queues from hierarchical rendering
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
@@ -343,5 +377,5 @@
 		InitVisibilityCulling(mCameraInProgress);
 
-	
+
 		/** 
 		* the hierarchical culling algorithm
@@ -366,5 +400,5 @@
 		
 		mLeavePassesInQueue = 0;
-
+		
 #if 1	
 		// add visible nodes found by the visibility culling algorithm
@@ -495,14 +529,13 @@
 		if (useArbQueries)
 		{
-			mHierarchyInterface->DeleteQueries();
+			mHierarchyInterface->ResetQueries();
 			mDestRenderSystem->setConfigOption("ArbQueries", "Yes");
 		}
 		else
 		{
-			mHierarchyInterface->DeleteQueries();
+			mHierarchyInterface->ResetQueries();
 			mDestRenderSystem->setConfigOption("ArbQueries", "No");
 		}
 	}
-
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || TerrainSceneManager::setOption(key, val);
@@ -564,5 +597,6 @@
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::renderObjects(
-	const RenderPriorityGroup::TransparentRenderablePassList& objs, 
+	const QueuedRenderableCollection& objs,
+	QueuedRenderableCollection::OrganisationMode om,
     bool doLightIteration, const LightList* manualLightList)
 {
@@ -571,5 +605,5 @@
 	if (NORMAL_RENDER_HACK || !mSkipTransparents)
 	{
-		OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
+		OctreeSceneManager::renderObjects(objs, om, doLightIteration, manualLightList);
 	}
 }
@@ -596,12 +630,14 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
+void OcclusionCullingSceneManager::_renderQueueGroupObjects(RenderQueueGroup* pGroup,
+															QueuedRenderableCollection::OrganisationMode om)
 {
 	if (NORMAL_RENDER_HACK || !mIsItemBufferPhase)
 	{
-		TerrainSceneManager::renderQueueGroupObjects(pGroup);
+		TerrainSceneManager::_renderQueueGroupObjects(pGroup, om);
 		return;
 	}
-
+#ifdef  ITEM_BUFFER
+	//-- item buffer
 	//-- item buffer: render objects using false colors
 
@@ -613,10 +649,12 @@
 		RenderItemBuffer(groupIt.getNext());
 	}
-}
+#endif // ITEM_BUFFER
+}
+#ifdef ITEM_BUFFER
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
 {
 	// Do solids
-	RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses();
+	QueuedRenderableCollection solidObjs = pGroup->getSolidsBasic();//msz
 
 	// ----- SOLIDS LOOP -----
@@ -658,6 +696,5 @@
 	if (mRenderTransparentsForItemBuffer)
 	{
-		RenderPriorityGroup::TransparentRenderablePassList transpObjs = 
-			pGroup->_getTransparentPasses();
+		QueuedRenderableCollection transpObjs = pGroup->getTransparents(); //msz
 		RenderPriorityGroup::TransparentRenderablePassList::const_iterator 
 			itrans, itransend;
@@ -713,5 +750,5 @@
 	}
 
-	Pass *usedPass = setPass(mItemBufferPass); 
+	const Pass *usedPass = _setPass(mItemBufferPass); 
 
 
@@ -719,4 +756,5 @@
 	renderSingleObject(rend, usedPass, false, &nullLightList);
 }
+#endif // ITEM_BUFFER
 //-----------------------------------------------------------------------
 GtpVisibility::VisibilityManager *OcclusionCullingSceneManager::GetVisibilityManager()
@@ -749,5 +787,6 @@
 	mLeavePassesInQueue = 0;
 
-	if (!mUseDepthPass && !mUseItemBuffer)
+	// if we have the depth pass or use an item buffer, no passes are left in the queue
+	if (1 && !mUseDepthPass && !mUseItemBuffer)
 	{
 		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
@@ -761,6 +800,6 @@
 
 			// just render ambient stuff
-			mIlluminationStage = IRS_AMBIENT;
-			getRenderQueue()->setSplitPassesByLightingType(true);
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT; 
 		}
 	
@@ -820,5 +859,6 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
+void OcclusionCullingSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
 	// only render solid passes during hierarchical culling
@@ -839,18 +879,20 @@
 
 			// Render all the ambient passes first, no light iteration, no lights
-			mIlluminationStage = IRS_AMBIENT;
-
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), false, &lightList);
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT;
+
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
 			// Also render any objects which have receive shadows disabled
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesNoShadow(), true);
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
 		}
 	}
 	else
 	{
-		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup);
-	}
-}
-//-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
+		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
+	}
+}
+//-----------------------------------------------------------------------
+void OcclusionCullingSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
    if (mIsHierarchicalCulling)
@@ -867,37 +909,11 @@
 
 		   // Do (shadowable) solids
-		   OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), true);
+		   OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
 	   }
    }
    else
    {
-	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup);
+	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
    }
-}
-//-------------------------------------------------------------------------
-void OcclusionCullingSceneManager::setWorldGeometry( const String& filename )
-{
-    // Clear out any existing world resources (if not default)
-    if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() != 
-        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
-    {
-        ResourceGroupManager::getSingleton().clearResourceGroup(
-            ResourceGroupManager::getSingleton().getWorldResourceGroupName());
-    }
-    mTerrainPages.clear();
-    // Load the configuration
-    loadConfig(filename);
-
-    // Resize the octree, allow for 1 page for now
-    float max_x = mOptions.scale.x * mOptions.pageSize;
-    float max_y = mOptions.scale.y;
-    float max_z = mOptions.scale.z * mOptions.pageSize;
-
-	float maxAxis = std::max(max_x, max_y);
-	maxAxis = std::max(maxAxis, max_z);
-	resize( AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis ) );
-    
-    setupTerrainMaterial();
-    setupTerrainPages();
 }
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 115)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformOcclusionQuery.cpp	(revision 897)
@@ -28,5 +28,15 @@
 											const bool waitForResult) const
 {
-	return mHardwareOcclusionQuery->pullOcclusionQuery(&visiblePixels, waitForResult);
+	// return mHardwareOcclusionQuery->pullOcclusionQuery(&visiblePixels, waitForResult);
+
+	bool isAvailable = true;
+
+	if (!waitForResult)
+		isAvailable = !mHardwareOcclusionQuery->isStillOutstanding();
+
+	if (isAvailable)
+		return mHardwareOcclusionQuery->pullOcclusionQuery(&visiblePixels);
+
+	return isAvailable;
 }
 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 870)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 897)
@@ -28,10 +28,11 @@
 //#include <OgreVisibilityDotSceneManager.h>
 
-#include <OgreHeightmapTerrainPageSource.h>
+//#include <OgreHeightmapTerrainPageSource.h>
 #include <OgreRoot.h>
 #include <OgreLogManager.h>
+
 #include "VisibilityManager.h"
 #include "VisibilityEnvironment.h"
-
+		
 GtpVisibility::VisibilityEnvironment *visEnv;
 GtpVisibility::VisibilityManager *visManager;
@@ -39,9 +40,6 @@
 namespace Ogre {
 
-VisibilityOctreeSceneManager *visibilityOctreePlugin;
-VisibilityTerrainSceneManager *visibilityTerrainPlugin;
-//VisibilityDotSceneManager *visibilityDotPlugin;
-
-HeightmapTerrainPageSource *heightmapTerrainPageSource;
+VisibilityOctreeSceneManagerFactory *visibilityOctreePlugin;
+VisibilityTerrainSceneManagerFactory *visibilityTerrainPlugin;
 
 //-----------------------------------------------------------------------
@@ -53,22 +51,20 @@
 
 	// Create new scene manager
-	visibilityOctreePlugin = new VisibilityOctreeSceneManager(visManager);
-	visibilityTerrainPlugin = new VisibilityTerrainSceneManager(visManager);
-	//occlusionDotPlugin = new VisibilityDotSceneManager();
+	visibilityOctreePlugin = new VisibilityOctreeSceneManagerFactory(visManager);
+	visibilityTerrainPlugin = new VisibilityTerrainSceneManagerFactory(visManager);
+	// Construct listener manager singleton
+	new TerrainPageSourceListenerManager();
 
-	heightmapTerrainPageSource = new HeightmapTerrainPageSource();
-	
 	// Register
-	Root::getSingleton().setSceneManager(ST_GENERIC, visibilityOctreePlugin);
-	Root::getSingleton().setSceneManager(ST_EXTERIOR_CLOSE, visibilityTerrainPlugin);
-	//Root::getSingleton().setSceneManager(ST_GENERIC, occlusionDotPlugin);
-
-	visibilityTerrainPlugin->registerPageSource("Heightmap", heightmapTerrainPageSource);
+	Root::getSingleton().addSceneManagerFactory(visibilityOctreePlugin);
+	Root::getSingleton().addSceneManagerFactory(visibilityTerrainPlugin);
 }
 //-----------------------------------------------------------------------
 extern "C" void __declspec(dllexport) dllShutdownPlugin()
 {
-	visibilityTerrainPlugin->shutdown();
-	heightmapTerrainPageSource->shutdown();
+	Root::getSingleton().removeSceneManagerFactory(visibilityOctreePlugin);
+	Root::getSingleton().removeSceneManagerFactory(visibilityTerrainPlugin);
+	// destroy listener manager
+	delete TerrainPageSourceListenerManager::getSingletonPtr();
 }
 //-----------------------------------------------------------------------
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 254)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOptionsManager.cpp	(revision 897)
@@ -16,5 +16,5 @@
 	{
 		// delete old queries (not needed for e.g., view frustum culling)
-		mHierarchyInterface->DeleteQueries();
+		mHierarchyInterface->ResetQueries();
 		mVisibilityManager->SetCullingManager(*static_cast<const 
 			GtpVisibility::VisibilityEnvironment::CullingManagerType *>(val));
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp	(revision 415)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp	(revision 897)
@@ -207,5 +207,5 @@
 		mEntities.pop_back();
 		
-		mSceneMgr->removeEntity(ent);
+		mSceneMgr->destroyEntity(ent);
 	}
 }
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp	(revision 155)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManager.cpp	(revision 897)
@@ -11,6 +11,7 @@
 
 //-----------------------------------------------------------------------
-VisibilitySceneManager::VisibilitySceneManager(GtpVisibility::VisibilityManager *visManager)
-:mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false)
+VisibilitySceneManager::VisibilitySceneManager(const String& name, 
+											   GtpVisibility::VisibilityManager *visManager)
+:SceneManager(name), mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false)
 {
 	mHierarchyInterface = 
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 880)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp	(revision 897)
@@ -9,4 +9,5 @@
 #include <OgreEntity.h>
 #include <OgreSubEntity.h>
+#include <OgreMaterialManager.h>
 #include <OgreIteratorWrappers.h>
 #include "VspBspTree.h"
@@ -24,7 +25,8 @@
 
 //-----------------------------------------------------------------------
-VisibilityOctreeSceneManager::VisibilityOctreeSceneManager(
-	GtpVisibility::VisibilityManager *visManager):
-OctreeSceneManager(),
+VisibilityOctreeSceneManager::VisibilityOctreeSceneManager(const String& name, 
+	GtpVisibility::VisibilityManager *visManager)
+:
+OctreeSceneManager(name),
 mVisibilityManager(visManager), 
 mShowVisualization(false),
@@ -135,5 +137,5 @@
     }
 	// add bounding boxes of rendered objects
-	if (0)
+	if (1)
 	for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
 {
@@ -159,6 +161,6 @@
 					(*it)->getAttachedObject(0)->isVisible())
 				{
-					getRenderQueue()->addRenderable((*it));
-				}
+				getRenderQueue()->addRenderable((*it));
+			}
 			}
 			// add renderables itself
@@ -171,9 +173,9 @@
 }
 //-----------------------------------------------------------------------
-Pass *VisibilityOctreeSceneManager::setPass(Pass* pass)
+const Pass *VisibilityOctreeSceneManager::_setPass(Pass* pass)
 {
 	if (NORMAL_RENDER_HACK)
 	{
-		return SceneManager::setPass(pass);
+		return SceneManager::_setPass(pass);
 	}
 
@@ -230,5 +232,5 @@
 
 	//-- set actual pass here
-	Pass *result = SceneManager::setPass(usedPass);
+	const Pass *result = SceneManager::_setPass(usedPass);
 
 
@@ -291,5 +293,5 @@
 	{
 		OctreeSceneManager::_renderVisibleObjects();
-
+	
 		return;
 	}
@@ -357,4 +359,5 @@
 		// exclude this queues from hierarchical rendering
 		setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
+	
 
 		// set all necessary parameters for 
@@ -402,8 +405,11 @@
 		//-- used for depth pass, transparents, overlay
 		clearSpecialCaseRenderQueues();
-
+	
+		//-- we render all remaining queue objects
+		// used for depth pass, transparents, overlay 
+		clearSpecialCaseRenderQueues();
 		OctreeSceneManager::_renderVisibleObjects();
 	
-	} // hierarchical culling
+	}   // hierarchical culling
 
 	// reset ambient light
@@ -535,5 +541,5 @@
 		return true;
 	}
-
+	
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || OctreeSceneManager::setOption(key, val);
@@ -593,5 +599,6 @@
 //-----------------------------------------------------------------------
 void VisibilityOctreeSceneManager::renderObjects(
-	const RenderPriorityGroup::TransparentRenderablePassList& objs, 
+			const QueuedRenderableCollection& objs, 
+			QueuedRenderableCollection::OrganisationMode om,
             bool doLightIteration, const LightList* manualLightList)
 {
@@ -600,5 +607,5 @@
 	if (NORMAL_RENDER_HACK || !mSkipTransparents)
 	{
-		OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
+		OctreeSceneManager::renderObjects(objs, om, doLightIteration, manualLightList);
 	}
 }
@@ -625,13 +632,14 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup)
+void VisibilityOctreeSceneManager::_renderQueueGroupObjects(
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
 	if (NORMAL_RENDER_HACK || !mIsItemBufferPhase)
 	{
-		OctreeSceneManager::renderQueueGroupObjects(pGroup);
+		OctreeSceneManager::_renderQueueGroupObjects(pGroup, om);
 		return;
 	}
-
-	//-- item buffer: render objects using false colors
+#ifdef ITEM_BUFFER
+	//-- renders item buffer
 
     // Iterate through priorities
@@ -642,5 +650,7 @@
 		RenderItemBuffer(groupIt.getNext());
 	}
-}
+#endif // ITEM_BUFFER
+}
+#ifdef ITEM_BUFFER
 //-----------------------------------------------------------------------
 void VisibilityOctreeSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup)
@@ -748,4 +758,5 @@
 	renderSingleObject(rend, usedPass, false, &nullLightList);
 }
+#endif // ITEM_BUFFER
 //-----------------------------------------------------------------------
 GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::GetVisibilityManager()
@@ -789,6 +800,7 @@
 			mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES;
 
-			// just render ambient stuff
-			mIlluminationStage = IRS_AMBIENT;
+			// just render ambient passes
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT;
 			getRenderQueue()->setSplitPassesByLightingType(true);
 		}
@@ -821,4 +833,6 @@
 							mLeavePassesInQueue);
 		
+	//std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;
+	//LogManager::getSingleton().logMessage(d.str());
 }
 //-----------------------------------------------------------------------
@@ -845,5 +859,5 @@
 //-----------------------------------------------------------------------
 void VisibilityOctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(
-	RenderQueueGroup* pGroup)
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
 	// only render solid passes during hierarchical culling
@@ -864,9 +878,10 @@
 
 			// Render all the ambient passes first, no light iteration, no lights
-			mIlluminationStage = IRS_AMBIENT;
-
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), false, &lightList);
+			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+			// mIlluminationStage = IRS_AMBIENT;
+
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
 			// Also render any objects which have receive shadows disabled
-			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesNoShadow(), true);
+			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);		
 #if 0		
 			std::stringstream d; 
@@ -881,9 +896,10 @@
 	else // render the rest of the passes
 	{
-		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup);
-	}
-}
-//-----------------------------------------------------------------------
-void VisibilityOctreeSceneManager::renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
+		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
+	}
+}
+//-----------------------------------------------------------------------
+void VisibilityOctreeSceneManager::renderModulativeStencilShadowedQueueGroupObjects(
+	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
    if (mIsHierarchicalCulling)
@@ -900,13 +916,49 @@
 
 		   // Do (shadowable) solids
-		   OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), true);
+		   OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
 	   }
    }
    else
    {
-	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup);
+	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
    }
 }
-
+//-------------------------------------------------------------------------
+void VisibilityOctreeSceneManager::SetObjectsVisible(const bool visible)
+{
+	GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
+
+	for (it = mObjects.begin(); it != it_end; ++ it)
+	{
+		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*it);
+		Entity *ent = omi->GetMesh();
+		ent->setVisible(visible);
+	}
+}
+//-------------------------------------------------------------------------
+void VisibilityOctreeSceneManager::loadVisibilityConfig(const String& filename)
+{
+	// TODO matt
+	// Set up the options
+	ConfigFile config;
+	String val;
+
+	config.load(filename);
+
+	val = config.getSetting("Algorithm");
+
+    if (!val.empty())
+	{
+		 VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).setOption("Algorithm", val.c_str());
+	}
+
+	val = config.getSetting("UseDepthPass");
+
+	if (!val.empty())
+	{
+		 setOption("UseDepthPass", val.c_str());
+	}
+}
+//-------------------------------------------------------------------------
 inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box)
 {
@@ -1056,55 +1108,4 @@
 }
 //-------------------------------------------------------------------------
-void VisibilityOctreeSceneManager::SetObjectsVisible(const bool visible)
-{
-	// for OGRE 1.2
-//#ifdef OGRE12
-	//MovableObjectIterator mit = getMovableObjectIterator("Entity");
-#if 0
-	EntityIterator eit = getEntityIterator();
-
-	// set all objects to invisible (initially);
-	while (eit.hasMoreElements())
-	{
-		Entity *ent = eit.getNext();
-		ent->setVisible(visible);
-	}
-
-#else
-	GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
-
-	for (it = mObjects.begin(); it != it_end; ++ it)
-	{
-		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*it);
-		Entity *ent = omi->GetMesh();
-		ent->setVisible(visible);
-	}
-#endif
-}
-//-------------------------------------------------------------------------
-void VisibilityOctreeSceneManager::loadVisibilityConfig(const String &filename)
-{
-	// TODO matt
-	// Set up the options
-	ConfigFile config;
-	String val;
-
-	config.load(filename);
-
-	val = config.getSetting("Algorithm");
-
-    if (!val.empty())
-	{
-		 VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).setOption("Algorithm", val.c_str());
-	}
-
-	val = config.getSetting("UseDepthPass");
-
-	if (!val.empty())
-	{
-		 setOption("UseDepthPass", val.c_str());
-	}
-}
-//-------------------------------------------------------------------------
 void VisibilityOctreeSceneManager::updatePvs(Camera *cam)
 {
@@ -1156,3 +1157,27 @@
 }
 
+
+
+//-----------------------------------------------------------------------
+const String VisibilityOctreeSceneManagerFactory::FACTORY_TYPE_NAME = "VisibilityOctreeSceneManager";
+//-----------------------------------------------------------------------
+void VisibilityOctreeSceneManagerFactory::initMetaData(void) const
+{
+	mMetaData.typeName = FACTORY_TYPE_NAME;
+	mMetaData.description = "Scene manager organising the scene on the basis of an octree with advanced occlusion culling (TM).";
+	mMetaData.sceneTypeMask = 0xFFFF; // support all types
+	mMetaData.worldGeometrySupported = false;
+}
+//-----------------------------------------------------------------------
+SceneManager* VisibilityOctreeSceneManagerFactory::createInstance(
+	const String& instanceName)
+{
+	return new VisibilityOctreeSceneManager(instanceName, visManager);
+}
+//-----------------------------------------------------------------------
+void VisibilityOctreeSceneManagerFactory::destroyInstance(SceneManager* instance)
+{
+	delete instance;
+}
+
 }  // namespace Ogre
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 726)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 897)
@@ -4,4 +4,5 @@
 #include <OgreEntity.h>
 #include <OgreMovableObject.h>
+#include <OgreMaterialManager.h>
 #include "OgreSolidBoundingBox.h"
 #include "OgrePlatformHierarchyInterface.h"
@@ -73,16 +74,15 @@
 PlatformHierarchyInterface::~PlatformHierarchyInterface()
 {
-	DeleteQueries();
+	ResetQueries();
 
 	OGRE_DELETE(mSolidBoundingBox);
 }
 //-----------------------------------------------------------------------
-void PlatformHierarchyInterface::DeleteQueries()
-{
-	for (int i = 0; i < (int)mOcclusionQueries.size(); ++ i)
-		OGRE_DELETE(mOcclusionQueries[i]);
+void PlatformHierarchyInterface::ResetQueries()
+{
+//	for (int i = 0; i < (int)mOcclusionQueries.size(); ++ i) OGRE_DELETE(mOcclusionQueries[i]);
 
 	mCurrentTestIdx = 0;
-    mOcclusionQueries.clear();
+    //mOcclusionQueries.clear();
 }
 //-----------------------------------------------------------------------
@@ -97,5 +97,6 @@
 	
 	// set no depth write, no color, no lighting material
-	mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
+	//mSceneManager->setPassWrapper(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
+	mSceneManager->_setPass(solidBox->getTechnique()->getPass(0)); // HACK! (mySetPass should be setPass)
 	//SetOcclusionPass();
 
@@ -119,5 +120,6 @@
 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::GetNextOcclusionQuery()
 {
-	if (mCurrentTestIdx == mOcclusionQueries.size())
+	// create new query if there is no query left
+	if (mCurrentTestIdx == (int)mOcclusionQueries.size())
 	{
 		mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp	(revision 726)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformQueryManager.cpp	(revision 897)
@@ -111,5 +111,5 @@
 	mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0));
 	//pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR | FBT_DEPTH);
-
+#ifdef ITEM_BUFFER
 	// initialise item buffer (if not already initialised)
 	InitItemBuffer(visibleGeometry, visiblePatches);
@@ -120,9 +120,9 @@
 	bool useItemBuffer = true;
 	sm->setOption("UseItemBuffer", &useItemBuffer);
-
+#endif // ITEM_BUFFER
 
 	sm->_renderScene(pCam, mViewport, false); // render item buffer
    
-
+#ifdef ITEM_BUFFER
 	//-- collect results
 	CollectItemBufferResults(visibleGeometry, visiblePatches);
@@ -132,4 +132,5 @@
 	useItemBuffer = false; // don't need item buffer anymore
 	sm->setOption("UseItemBuffer", &useItemBuffer);
+#endif // ITEM_BUFFER
 
 	mWasInitialised = false; // reset initialised - flag
@@ -137,4 +138,5 @@
 	mViewport->setBackgroundColour(bg); // reset background color
 }
+#ifdef ITEM_BUFFER
 //-----------------------------------------------------------------------
 void PlatformQueryManager::CollectItemBufferResults(
@@ -232,4 +234,5 @@
 	}
 }
+#endif // ITEM_BUFFER
 //-----------------------------------------------------------------------
 void PlatformQueryManager::SetViewport(Viewport *vp)
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 897)
@@ -29,5 +29,5 @@
   // compute histogram from the samples
   int bins = 100;
-  int maxPvs;
+  int maxPvs = 0;
 
   vector<int> histogram(bins);
