Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3243)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h	(revision 3245)
@@ -24,5 +24,4 @@
 {
 	friend class RenderQueue;
-	friend class EntityMerger;
 
 public:
@@ -31,7 +30,4 @@
 	*/
 	SceneEntity(Transform3 *trafo);
-	/** Copy constructur.
-	*/
-	//SceneEntity(const SceneEntity &e);
 	/** Destructor.
 	*/
@@ -45,8 +41,8 @@
 	/** See set
 	*/
-	inline Shape *GetShape(int i) const { return mShapes[i]; }
+	inline Shape *GetShape(int i) const;
 	/** Returns number of shapes in vector.
 	*/
-	inline int GetNumShapes() { return (int)mShapes.size(); }
+	inline int GetNumShapes();
 	/** Set pointer to the geometry
 	*/
@@ -54,11 +50,11 @@
 	/** set frame where we last rendered this node
 	*/
-	void SetLastRendered(int lastRendered);
+	void SetLastRenderedFrame(int lastRendered);
 	/** returns frame where we last visited this node
 	*/
-	int GetLastRendered() const;
+	int GetLastRenderedFrame() const;
 	/** Returns the trafo of this scene entity.
 	*/
-	inline Transform3 *GetTransform() const  { return mTransform; }
+	inline Transform3 *GetTransform() const;
 	/** Counts number of triangles in this entity using the specified lod level
 		with 0 being the highest or the current lod level (if the argument is -1).
@@ -71,5 +67,13 @@
 	*/
 	AxisAlignedBox3 GetWorldBoundingBox() const;
-	
+	/** Only the scene entities are visible that match the global id.
+	*/
+	void SetVisibleId(int id);
+	/** See set
+	*/
+	int GetVisibleId(int id) const;
+	/** Returns true if this entity is visible.
+	*/
+	bool IsVisible() const;
 
 
@@ -85,11 +89,11 @@
 	/** Adds a new lod level.
 	*/
-	void AddLODLevel(const LODLevel &lod) { mLODLevels.push_back(lod); }
+	void AddLODLevel(const LODLevel &lod);
 	/** Returns numbers of lod levels.
 	*/
-	int GetNumLODLevels() const { return (int)mLODLevels.size(); }
+	int GetNumLODLevels() const;
 	/** Returns center point of this shape.
 	*/
-	Vector3 GetCenter() const {return mCenter; }
+	Vector3 GetCenter() const;
 	/** Returns transformed center point of this shape.
 	*/
@@ -107,8 +111,12 @@
 	/** If false, the highest (most detailed) LOD level is used for all entities.
 	*/
-	static void SetUseLODs(bool useLODs) { sUseLODs = useLODs; }
+	static void SetUseLODs(bool useLODs);
 	/** See set
 	*/
-	static bool GetUseLODs() { return sUseLODs; }
+	static bool GetUseLODs();
+	/** Sets the global visible id. Scene entities are visible only if
+		this id is -1 or their id matches this id.
+	*/
+	static void SetGlobalVisibleId(int id);
 
 protected:
@@ -133,5 +141,5 @@
 	ShapeContainer mShapes;
 	/// when this entity was last rendered
-	int mLastRendered;
+	int mLastRenderedFrame;
 	/// the LOD level currently used for rendering
 	int mCurrentLODLevel;
@@ -145,7 +153,82 @@
 	static bool sUseLODs;
 	static int sCurrentId;
+
+	int mVisibleId;
+	static int sVisibleId;
 };
 
 
+inline void SceneEntity::AddLODLevel(const LODLevel &lod)
+{ 
+	mLODLevels.push_back(lod); 
+}
+
+
+inline int SceneEntity::GetNumLODLevels() const 
+{
+	return (int)mLODLevels.size(); 
+}
+
+
+inline Vector3 SceneEntity::GetCenter() const 
+{ 
+	return mCenter; 
+}
+
+
+inline void SceneEntity::SetUseLODs(bool useLODs) 
+{
+	sUseLODs = useLODs; 
+}
+
+
+inline bool SceneEntity::GetUseLODs() 
+{ 
+	return sUseLODs; 
+}
+
+
+inline Shape *SceneEntity::GetShape(int i) const 
+{ 
+	return mShapes[i]; 
+}
+
+
+inline int SceneEntity::GetNumShapes()
+{
+	return (int)mShapes.size(); 
+}
+
+
+inline Transform3 *SceneEntity::GetTransform() const  
+{ 
+	return mTransform; 
+}
+
+
+inline void SceneEntity::SetVisibleId(int id)
+{
+	mVisibleId = id;
+}
+
+
+inline void SceneEntity::SetGlobalVisibleId(int id)
+{
+	sVisibleId = id;
+}
+
+
+inline int SceneEntity::GetVisibleId(int id) const
+{
+	return mVisibleId;
+}
+
+
+inline bool SceneEntity::IsVisible() const
+{
+	return (sVisibleId == -1) || (mVisibleId == sVisibleId);
+}
+
+
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3244)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3245)
@@ -76,4 +76,5 @@
 
 	// get the bounding box
+	// exchange x and y coordinates and recompute box
 	fread(&mBox, sizeof(AxisAlignedBox3), 1, fr);
 
@@ -81,12 +82,8 @@
 	Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y);
 	
-	Vector3 newMin = v1;
-	Vector3 newMax = v2;
+	mBox.Initialize();
 
-	Minimize(newMin, v2);
-	Maximize(newMax, v1);
-
-	mBox.SetMin(newMin);
-	mBox.SetMax(newMax);
+	mBox.Include(v1);
+	mBox.Include(v2);
 
 	stack<ViewCellsTreeNode **> nodeStack;
@@ -96,4 +93,6 @@
 
 	int numViewCells = 0;
+
+	int axes[] = {0, 0, 0};
 
 	while (!nodeStack.empty()) 
@@ -108,5 +107,5 @@
 		fread(&axis, sizeof(int), 1, fr);
 
-		// exchange y and z axis like we have to do for the scene
+		// exchange y and z axis like for whole scene
 		if (axis == 2) axis = 1;
 		else if (axis == 1) axis = 2;
@@ -114,20 +113,30 @@
 		node->mAxis = axis;
 
-		if (node->mAxis > 2 || node->mAxis < -1) cout << "a " << node->mAxis << " ";
-
 		if (!node->IsLeaf())
 		{
-			float pos;
-			fread(&pos, sizeof(float), 1, fr);
+			++ axes[node->mAxis];
 
-			if (axis == 1) pos = -pos;
-			node->mPosition = pos;
-			
-			nodeStack.push(&node->mFront);
-			nodeStack.push(&node->mBack);
+			float mypos;
+			fread(&mypos, sizeof(float), 1, fr);
+			// changed coordinate system must be considered also here
+			if (node->mAxis == 1) 
+			{
+				node->mPosition = -mypos;
+
+				nodeStack.push(&node->mBack);
+				nodeStack.push(&node->mFront);
+				//cout << mypos << " ";
+			}
+			else
+			{
+				node->mPosition = mypos;
+				
+				nodeStack.push(&node->mFront);
+				nodeStack.push(&node->mBack);
+			}
 		}
 	}
 
-	cout << "loaded " << numViewCells << " view cells" << endl;
+	cout << "\nloaded " << numViewCells << " view cells" << " " << axes[0] << " " << axes[1] << " " << axes[2] << endl;
 	return true;
 }
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3244)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3245)
@@ -112,5 +112,7 @@
 		{
 			SceneEntity *ent = entities[i];
-		
+	
+			if (!ent->IsVisible()) continue;
+
 			mStats.mNumRenderedTriangles += ent->CountNumTriangles();
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 3063)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 3245)
@@ -14,4 +14,5 @@
 class AxisAlignedBox3;
 class GLUquadric;
+struct ViewCell;
 
 
@@ -48,5 +49,11 @@
 	*/
 	void RenderFrustum();
+	/** Sets the current view cell.
+	*/
+	void SetViewCell(ViewCell *vc);
 
+	/** Renders box as wireframe.
+	*/
+	static void RenderBoxForViz(const AxisAlignedBox3 &box);
 
 protected:
@@ -65,4 +72,6 @@
 	/// the current frame id
 	int mFrameId;
+
+	ViewCell *mViewCell;
 };
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3244)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3245)
@@ -90,5 +90,5 @@
 {
 	std::stack<BvhNode *> tStack;
-	tStack.push(bvh->GetRoot());
+	tStack.push(bvh->GetStaticRoot());
 	
 	while (!tStack.empty())
@@ -140,5 +140,5 @@
 		fread(&entries, sizeof(int), 1, fw);
 
-		for (int j=0; j < entries; ++ j) 
+		for (int j = 0; j < entries; ++ j) 
 		{
 			int objectId;
@@ -154,4 +154,6 @@
 			entities = bvh->GetGeometry(node, geometrySize);
 
+			//if (node->IsLeaf() && (geometrySize != 1))
+			//if (geometrySize != 1) cout << "Error!! " << geometrySize << endl;
 			for (int k = 0; k < geometrySize; ++ k)
 			{
@@ -175,5 +177,6 @@
 
 	mViewCells.clear();
-	
+	int axes[] = {0, 0, 0};
+
 	while (!nodeStack.empty()) 
 	{
@@ -198,23 +201,32 @@
 			nodeStack.pop();
 
-			AxisAlignedBox3 newBox = box;
-			newBox.SetMin(node->mAxis, node->mPosition);
-
-			nodeStack.push(
-				pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox)
-				);
-
-			newBox = box;
-			newBox.SetMax(node->mAxis, node->mPosition);
-
-			nodeStack.push(
-				pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox)
-				);
+			AxisAlignedBox3 newBox1 = box;
+			AxisAlignedBox3 newBox2 = box;
+			/*if (node->mPosition < newBox.Min(node->mAxis))
+				cout << "e: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl;
+			else if (node->mPosition > newBox.Min(node->mAxis))
+				cout << "o: " << node->mPosition << " " << newBox.Min(node->mAxis) << endl;
+*/
+			newBox1.SetMin(node->mAxis, node->mPosition);
+			newBox2.SetMax(node->mAxis, node->mPosition);
+
+			++ axes[node->mAxis];
+
+			if (node->mAxis == 1)
+			{
+				nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox2));
+				nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox1));
+			}
+			else
+			{
+				nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mFront, newBox1));
+				nodeStack.push(pair<ViewCellsTreeNode *, AxisAlignedBox3>(node->mBack, newBox2));
+			}
 		}
 	}
 
-	cout << "#of viewcells = " << id << endl;
-}
-
-
-}
+	cout << "#of viewcells = " << id << " " << axes[0] << " " << axes[1] << " " << axes[2] << endl;
+}
+
+
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3214)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3245)
@@ -97,5 +97,4 @@
 	tech.SetLightingEnabled(false);
 	tech.SetDepthWriteEnabled(false);
-	//tech.SetCullFaceEnabled(false);
 
 	return tech;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp	(revision 3126)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntityConverter.cpp	(revision 3245)
@@ -39,6 +39,4 @@
 	}
 
-	cout << "number of triangles in box: " << (int)triangles.size() << endl;
-
 	Geometry *geom = new Geometry(vertices, normals, NULL, 36, false, NULL);
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3063)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3245)
@@ -6,4 +6,8 @@
 #include "RenderState.h"
 #include "ShadowMapping.h"
+#include "ViewCellsTree.h"
+#include "Material.h"
+
+
 #include <stack>
 
@@ -16,5 +20,5 @@
 
 
-static void RenderBoxForViz(const AxisAlignedBox3 &box)
+void Visualization::RenderBoxForViz(const AxisAlignedBox3 &box)
 {
 	glBegin(GL_LINE_LOOP);
@@ -76,5 +80,6 @@
 mVizCamera(vizCamera),
 mRenderState(renderState),
-mFrameId(0)
+mFrameId(0),
+mViewCell(NULL)
 {
 }
@@ -101,4 +106,26 @@
 {
 	mFrameId = frameId;
+}
+
+
+void Visualization::SetViewCell(ViewCell *vc)
+{
+	mViewCell = vc;
+}
+
+
+static Technique GetVizTechnique()
+{
+	Technique tech;
+	tech.Init();
+
+	//tech.SetLightingEnabled(false);
+	//tech.SetDepthWriteEnabled(false);
+
+	tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+	tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+	tech.SetAmbient(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+
+	return tech;
 }
 
@@ -134,8 +161,19 @@
 				{
 					SceneEntity *ent = entities[i];
-					ent->Render(mRenderState);
+					
+					if (ent->IsVisible())
+						ent->Render(mRenderState);
 				}		
 			}
 		}
+	}
+
+	// render current view cell
+	static Technique vcTechnique = GetVizTechnique();
+
+	if (mViewCell)
+	{
+		vcTechnique.Render(mRenderState);
+		Visualization::RenderBoxForViz(mViewCell->GetBox());
 	}
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3147)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.h	(revision 3245)
@@ -37,5 +37,5 @@
 	*/
 	GPUProgramParameters(ShaderProgram *p);
-	/** Sets the assoziated program (a 1:n relationship)
+	/** Sets the program associated with these parameters (a 1:n relationship)
 	*/
 	void SetProgram(ShaderProgram *p) { mProgram = p; }
@@ -46,5 +46,5 @@
 
 	///////////
-	//-- set parameters by index
+	//-- functions for setting parameters by index
 
 	void SetValue1f(int idx, float value);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3244)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3245)
@@ -1295,8 +1295,11 @@
 	if (!useTightBounds)
 	{
+#if 1
 		RenderBoxForViz(node->GetBox());
-		/*glPolygonMode(GL_FRONT, GL_LINE);
+#else
+		glPolygonMode(GL_FRONT, GL_LINE);
 		RenderBoundingBoxImmediate(node->GetBox());
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);*/
+		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+#endif
 	}
 	else
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3120)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp	(revision 3245)
@@ -17,8 +17,12 @@
 int SceneEntity::sCurrentId = 0;
 bool SceneEntity::sUseLODs = true;
-
+int SceneEntity::sVisibleId = -1;
 
 SceneEntity::SceneEntity(Transform3 *trafo): 
-mTransform(trafo), mCurrentLODLevel(0), mLODLastUpdated(-1), mId(sCurrentId ++)
+mTransform(trafo), 
+mCurrentLODLevel(0), 
+mLODLastUpdated(-1),
+mId(sCurrentId ++),
+mVisibleId(0)
 {
 	mBox.Initialize();
@@ -121,13 +125,13 @@
 
 
-void SceneEntity::SetLastRendered(int lastRendered)
+void SceneEntity::SetLastRenderedFrame(int lastRenderedFrame)
 {
-	mLastRendered = lastRendered;
+	mLastRenderedFrame = lastRenderedFrame;
 }
 
 
-int SceneEntity::GetLastRendered() const
+int SceneEntity::GetLastRenderedFrame() const
 {
-	return mLastRendered;
+	return mLastRenderedFrame;
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3244)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3245)
@@ -141,4 +141,8 @@
 ViewCellsTree *viewCellsTree = NULL;
 
+static int globalVisibleId = 0;
+
+ViewCell *viewCell = NULL;
+
 
 /// the technique used for rendering
@@ -655,5 +659,9 @@
 	SceneEntityConverter conv;
 
-	// toto clean up material
+
+	//////////////////
+	//-- occlusion query for sun
+
+	// todo: clean up material
 	Material *mat = resourceManager->CreateMaterial();
 
@@ -662,5 +670,4 @@
 
 	sunBox = conv.ConvertBox(sbox, mat, trafo);
-	
 	resourceManager->AddSceneEntity(sunBox);
 
@@ -1253,8 +1260,8 @@
 	else
 	{
+		RenderPvs();
+
 		// actually render the scene geometry using the specified algorithm
-		//traverser->RenderScene();
-
-		RenderPvs();
+		traverser->RenderScene();
 	}
 
@@ -1954,5 +1961,6 @@
 {
 	visualization->SetFrameId(traverser->GetCurrentFrameId());
-	
+	visualization->SetViewCell(viewCell);
+
 	Begin2D();
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -2518,12 +2526,45 @@
 
 
+static Technique GetVizTechnique()
+{
+	Technique tech;
+	tech.Init();
+
+	//tech.SetLightingEnabled(false);
+	//tech.SetDepthWriteEnabled(false);
+
+	tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+	tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+	tech.SetAmbient(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
+
+	return tech;
+}
+
+
 void RenderPvs()
 {
-	ViewCell *vc = viewCellsTree->GetViewCell(camera->GetPosition());
-
-	for (int i = 0; i < vc->mPvs.Size(); ++ i)
-	{
-		SceneEntity *ent = vc->mPvs.GetEntry(i);
-		ent->Render(&renderState);
-	}
-}
+	viewCell = viewCellsTree->GetViewCell(camera->GetPosition());
+
+	int numTriangles = 0;
+
+	for (int i = 0; i < viewCell->mPvs.Size(); ++ i)
+	{
+		SceneEntity *ent = viewCell->mPvs.GetEntry(i);
+		//ent->Render(&renderState);
+		ent->SetVisibleId(globalVisibleId);
+
+		numTriangles += ent->CountNumTriangles();
+	}
+
+	SceneEntity::SetGlobalVisibleId(globalVisibleId ++);
+
+	// render current view cell
+	static Technique vcTechnique = GetVizTechnique();
+
+	vcTechnique.Render(&renderState);
+	Visualization::RenderBoxForViz(viewCell->GetBox());
+
+	visualization->SetViewCell(viewCell);
+
+	//cout << "pvs: " << vc->mPvs.Size() << " triangles: " << numTriangles << endl;
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3243)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3245)
@@ -16,5 +16,7 @@
 statsFilename=mystats.log
 
-visibilitySolution=vienna_full-8x3-refu
+#visibilitySolution=vienna_full-8x3-refu
+visibilitySolution=vienna_full-8x3-pgv
+#visibilitySolution=vienna_full-8x3-spgvu
 
 ############
@@ -39,10 +41,10 @@
 
 # initial camera position
-#camPosition=483.398f 242.364f 186.078f
+camPosition=483.398f 242.364f 186.078f
 # initial camera orientation
-#camDirection=1 0 0
+camDirection=1 0 0
 
-camPosition=468.025 267.591 182.478
-camDirection=0.937282 0.348573 -0
+#camPosition=468.025 267.591 182.478
+#camDirection=0.937282 0.348573 -0
 
 #lightDirection=-0.8f 1.0f -0.7f
