Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/ViewCellBspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/ViewCellBspTree.h	(revision 727)
+++ 	(revision )
@@ -1,284 +1,0 @@
-#ifndef _VspBspTree_H__
-#define _VspBspTree_H__
-
-#include "Mesh.h"
-#include "Containers.h"
-#include "Polygon3.h"
-#include <stack>
-#include "Statistics.h"
-#include "VssRay.h"
-#include "RayInfo.h"
-#include "ViewCellBsp.h"
-
-class ViewCell;
-//class BspViewCell;
-class Plane3;
-class VspBspTree;  
-class BspInterior;
-class BspNode;
-class AxisAlignedBox3;
-class Ray;
-class ViewCellsStatistics;
-class ViewCellsManager;
-class MergeCandidate;
-class Beam;
-class ViewCellsTree;
-
-
-struct BspRay;
-
-
-/**
-    BspNode abstract class serving for interior and leaf node implementation
-*/
-class BspNode 
-{
-	friend class BspTree;
-
-public:
-	BspNode();
-	virtual ~BspNode(){};
-	BspNode(BspInterior *parent);
-
-	/** Determines whether this node is a leaf or not
-	@return true if leaf
-	*/
-	virtual bool IsLeaf() const = 0;
-
-	/** Determines whether this node is a root
-	@return true if root
-	*/
-	virtual bool IsRoot() const;
-
-	/** Returns parent node.
-	*/
-	BspInterior *GetParent();
-
-	/** Sets parent node.
-	*/
-	void SetParent(BspInterior *parent);
-
-	/** Returns true if this node is a sibling of node n.
-	*/
-	bool IsSibling(BspNode *n) const;
-
-	/** returns depth of the node.
-	*/
-	int GetDepth() const;
-
-	/** returns true if the whole subtree is valid
-	*/
-	bool TreeValid() const;
-
-	void SetTreeValid(const bool v);
-
-	//-- mailing options
-
-	void Mail() { mMailbox = sMailId; }
-	static void NewMail() { ++ sMailId; }
-	bool Mailed() const { return mMailbox == sMailId; }
-
-	static int sMailId;
-	int mMailbox;
-
-	int mTimeStamp;
-
-protected:
-
-	/// if this sub tree is a completely valid view space region
-	bool mTreeValid;
-	/// parent of this node
-	BspInterior *mParent;
-};
-
-/** BSP interior node implementation 
-*/
-class BspInterior: public BspNode 
-{
-	friend class BspTree;
-public:
-	/** Standard contructor taking split plane as argument.
-	*/
-	BspInterior(const Plane3 &plane);
-	~BspInterior();
-	/** @return false since it is an interior node 
-	*/
-	bool IsLeaf() const;
-
-	BspNode *GetBack();
-	BspNode *GetFront();
-
-	/** Returns split plane.
-	*/
-	Plane3 GetPlane() const;
-
-	/** Replace front or back child with new child.
-	*/
-	void ReplaceChildLink(BspNode *oldChild, BspNode *newChild);
-	/** Replace front and back child.
-	*/
-	void SetupChildLinks(BspNode *b, BspNode *f);
-
-	friend ostream &operator<<(ostream &s, const BspInterior &A)
-	{
-		return s << A.mPlane;
-	}
-
-protected:
-
-	/// Splitting plane corresponding to this node
-	Plane3 mPlane;
-
-	/// back node
-	BspNode *mBack;
-	/// front node
-	BspNode *mFront;
-};
-
-/** BSP leaf node implementation.
-*/
-class BspLeaf: public BspNode 
-{
-	friend class BspTree;
-
-public:
-	BspLeaf();
-	BspLeaf(ViewCell *viewCell);
-	BspLeaf(BspInterior *parent);
-	BspLeaf(BspInterior *parent, ViewCell *viewCell);
-
-	~BspLeaf();
-
-	/** @return true since it is an interior node 
-	*/
-	bool IsLeaf() const;
-	
-	/** Returns pointer of view cell.
-	*/
-	ViewCell *GetViewCell() const;
-
-	/** Sets pointer to view cell.
-	*/
-	void SetViewCell(ViewCell *viewCell);
-
-	/// Rays piercing this leaf.
-	VssRayContainer mVssRays;
-	
-	/// leaf pvs
-	ObjectPvs *mPvs;
-
-	/// Probability that the view point lies in this leaf
-	float mProbability;
-
-protected:
-	
-	/// if NULL this does not correspond to feasible viewcell
-	ViewCell *mViewCell;
-};
-
-/**
-	This bsp tree spatially organizes the view cells.  
-*/
-class ViewCellBspTree 
-{
-public:		
-	/** Default constructor creating an empty tree.
-	*/ 
-	VspBspTree();
-
-	/** Default destructor.
-	*/
-	~VspBspTree();
-
-	/** Returns list of BSP leaves with pvs smaller than
-		a certain threshold.
-		@param onlyUnmailed if only the unmailed leaves should be considered
-		@param maxPvs the maximal pvs (-1 means unlimited)
-	*/
-	void CollectLeaves(vector<BspLeaf *> &leaves, 
-					   const bool onlyUnmailed = false,
-					   const int maxPvs = -1) const;
-
-	/** Returns box which bounds the whole tree.
-	*/
-	AxisAlignedBox3 GetBoundingBox() const;
-
-	/** Returns root of BSP tree.
-	*/
-	BspNode *GetRoot() const;
-
-	/** Collects the leaf view cells of the tree
-		@param viewCells returns the view cells 
-	*/
-	void CollectViewCells(ViewCellContainer &viewCells, bool onlyValid) const;
-
-	/** A ray is cast possible intersecting the tree.
-		@param the ray that is cast.
-		@returns the number of intersections with objects stored in the tree.
-	*/
-	int CastRay(Ray &ray);
-
-	/** finds neighbouring leaves of this tree node.
-	*/
-	int FindNeighbors(BspNode *n, 
-					  vector<BspLeaf *> &neighbors, 
-					  const bool onlyUnmailed) const;
-
-	/** Constructs geometry associated with the half space intersections 
-		leading to this node.
-	*/
-	void ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const;
-	
-	/** Construct geometry of view cell.
-	*/
-	void ConstructGeometry(ViewCell *vc, BspNodeGeometry &geom) const;
-
-	/** Returns random leaf of BSP tree.
-		@param halfspace defines the halfspace from which the leaf is taken.
-	*/
-	BspLeaf *GetRandomLeaf(const Plane3 &halfspace);
-
-	/** Returns random leaf of BSP tree.
-		@param onlyUnmailed if only unmailed leaves should be returned.
-	*/
-	BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
-
-	/** Casts line segment into the tree.
-		@param origin the origin of the line segment
-		@param termination the end point of the line segment
-		@returns view cells intersecting the line segment.
-	*/
-    int CastLineSegment(const Vector3 &origin,
-						const Vector3 &termination,
-						ViewCellContainer &viewcells);
-
-	/** Returns view cell the current point is located in.
-	*/
-	ViewCell *GetViewCell(const Vector3 &point);
-
-
-	/** Returns true if this view point is in a valid view space,
-		false otherwise.
-	*/
-	bool ViewPointValid(const Vector3 &viewPoint) const;
-
-	/** Returns view cell corresponding to 
-		the invalid view space.
-	*/
-	BspViewCell *GetOutOfBoundsCell();
-
-
-
-protected:
-
-	
-	
-	/// Pointer to the root of the tree
-	BspNode *mRoot;
-		
-};
-
-
-
-
-#endif
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 828)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 853)
@@ -10,4 +10,5 @@
 #include <OgreSubEntity.h>
 #include "VspBspTree.h"
+#include <OgreIteratorWrappers.h>
 
 namespace Ogre {
@@ -835,8 +836,33 @@
 }
 
+bool OcclusionCullingSceneManager::CompareBoundingBoxes(const AxisAlignedBox &boxa, 
+														const AxisAlignedBox &boxb)
+{
+}
+
 void OcclusionCullingSceneManager::LoadViewCells(string filename)
 {
 	ObjectContainer objects;
 	mViewCellsManager->LoadViewCells(filename, &objects);
+
+	AxisAlignedBox box;
+	list<SceneNode *> sceneNodeList;
+
+	findNodesIn(box, sceneNodeList, NULL);
+
+	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
+
+	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
+	{
+		SceneNode *sn = *sit;
+		SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator();
+
+		 while (oit.hasMoreElements())
+		 {
+			 MovableObject *mo = oit.getNext();
+			 AxisAlignedBox bbox = mo->getWorldBoundingBox();
+		CompareBoundingBoxes(*oit, box);
+		 }
+	}
 }
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/ViewCellBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/ViewCellBspTree.cpp	(revision 727)
+++ 	(revision )
@@ -1,461 +1,0 @@
-#include <stack>
-#include <time.h>
-#include <iomanip>
-
-#include "Plane3.h"
-#include "VspBspTree.h"
-#include "Mesh.h"
-#include "common.h"
-#include "ViewCell.h"
-#include "Environment.h"
-#include "Polygon3.h"
-#include "Ray.h"
-#include "AxisAlignedBox3.h"
-#include "Exporter.h"
-#include "Plane3.h"
-#include "ViewCellBsp.h"
-#include "ViewCellsManager.h"
-#include "Beam.h"
-
-#define USE_FIXEDPOINT_T 0
-
-
-//-- static members
-
-
-int VspBspTree::sFrontId = 0;
-int VspBspTree::sBackId = 0;
-int VspBspTree::sFrontAndBackId = 0;
-
-typedef pair<BspNode *, BspNodeGeometry *> bspNodePair;
-
-
-// pvs penalty can be different from pvs size
-inline float EvalPvsPenalty(const int pvs, 
-							const int lower,
-							const int upper)
-{
-	// clamp to minmax values
-	if (pvs < lower)
-		return (float)lower;
-	if (pvs > upper)
-		return (float)upper;
-
-	return (float)pvs;
-}
-
-
-
-
-/******************************************************************************/
-/*                       class ViewCellBspTree implementation                 */
-/******************************************************************************/
-
-
-BspViewCell *VspBspTree::GetOutOfBoundsCell()
-{
-	return mOutOfBoundsCell;
-}
-
-VspBspTree::~VspBspTree()
-{
-	DEL_PTR(mRoot);
-}
-
-void VspBspTree::CollectViewCells(BspNode *root,
-								  bool onlyValid,
-								  ViewCellContainer &viewCells,
-								  bool onlyUnmailed) const
-{
-	stack<BspNode *> nodeStack;
-
-	if (!root)
-		return;
-
-	nodeStack.push(root);
-	
-	while (!nodeStack.empty()) 
-	{
-		BspNode *node = nodeStack.top();
-		nodeStack.pop();
-		
-		if (node->IsLeaf())
-		{
-			if (!onlyValid || node->TreeValid())
-			{
-				ViewCell *leafVc = dynamic_cast<BspLeaf *>(node)->GetViewCell();
-
-				ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leafVc);
-						
-				if (!onlyUnmailed || !viewCell->Mailed()) 
-				{
-					viewCell->Mail();
-					viewCells.push_back(viewCell);
-				}
-			}
-		}
-		else
-		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
-		
-			nodeStack.push(interior->GetFront());
-			nodeStack.push(interior->GetBack());
-		}
-	}
-
-}
-
-
-int ViewCellBspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors,
-								   const bool onlyUnmailed) const
-{
-	stack<bspNodePair> nodeStack;
-	
-	BspNodeGeometry nodeGeom;
-	ConstructGeometry(n, nodeGeom);
-	
-	// split planes from the root to this node
-	// needed to verify that we found neighbor leaf
-	// TODO: really needed?
-	vector<Plane3> halfSpaces;
-	ExtractHalfSpaces(n, halfSpaces);
-
-
-	BspNodeGeometry *rgeom = new BspNodeGeometry();
-	ConstructGeometry(mRoot, *rgeom);
-
-	nodeStack.push(bspNodePair(mRoot, rgeom));
-
-	while (!nodeStack.empty())
-	{
-		BspNode *node = nodeStack.top().first;
-		BspNodeGeometry *geom = nodeStack.top().second;
-	
-		nodeStack.pop();
-
-		if (node->IsLeaf())
-		{
-			// test if this leaf is in valid view space
-			if (node->TreeValid() &&
-				(node != n) && 
-				(!onlyUnmailed || !node->Mailed()))
-			{
-				bool isAdjacent = true;
-
-				if (1)
-				{
-					// test all planes of current node if still adjacent
-					for (int i = 0; (i < halfSpaces.size()) && isAdjacent; ++ i)
-					{
-						const int cf =
-							Polygon3::ClassifyPlane(geom->GetPolys(),
-													halfSpaces[i],
-													mEpsilon);
-
-						if (cf == Polygon3::FRONT_SIDE)
-						{
-							isAdjacent = false;
-						}
-					}
-				}
-				else
-				{
-					// TODO: why is this wrong??
-					// test all planes of current node if still adjacent
-					for (int i = 0; (i < nodeGeom.Size()) && isAdjacent; ++ i)
-					{
-						Polygon3 *poly = nodeGeom.GetPolys()[i];
-
-						const int cf =
-							Polygon3::ClassifyPlane(geom->GetPolys(),
-													poly->GetSupportingPlane(),
-													mEpsilon);
-
-						if (cf == Polygon3::FRONT_SIDE)
-						{
-							isAdjacent = false;
-						}
-					}
-				}
-				// neighbor was found
-				if (isAdjacent)
-				{	
-					neighbors.push_back(dynamic_cast<BspLeaf *>(node));
-				}
-			}
-		}
-		else
-		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
-
-			const int cf = Polygon3::ClassifyPlane(nodeGeom.GetPolys(),
-												   interior->GetPlane(),
-												   mEpsilon);
-			
-			BspNode *front = interior->GetFront();
-			BspNode *back = interior->GetBack();
-            
-			BspNodeGeometry *fGeom = new BspNodeGeometry();
-			BspNodeGeometry *bGeom = new BspNodeGeometry();
-
-			geom->SplitGeometry(*fGeom,
-								*bGeom,
-								interior->GetPlane(),
-								mBox,
-								//0.0000001f);
-								mEpsilon);
-		
-			if (cf == Polygon3::BACK_SIDE)
-			{
-				nodeStack.push(bspNodePair(interior->GetBack(), bGeom));
-				DEL_PTR(fGeom);
-			}
-			else
-			{
-				if (cf == Polygon3::FRONT_SIDE)
-				{
-					nodeStack.push(bspNodePair(interior->GetFront(), fGeom));
-					DEL_PTR(bGeom);
-				}
-				else
-				{	// random decision
-					nodeStack.push(bspNodePair(front, fGeom));
-					nodeStack.push(bspNodePair(back, bGeom));
-				}
-			}
-		}
-	
-		DEL_PTR(geom);
-	}
-
-	return (int)neighbors.size();
-}
-
-
-
-BspLeaf *ViewCellBspTree::GetRandomLeaf(const Plane3 &halfspace)
-{
-    stack<BspNode *> nodeStack;
-  	nodeStack.push(mRoot);
-
-	int mask = rand();
-
-	while (!nodeStack.empty())
-	{
-		BspNode *node = nodeStack.top();
-		nodeStack.pop();
-
-		if (node->IsLeaf())
-		{
-			return dynamic_cast<BspLeaf *>(node);
-		}
-		else
-		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
-			BspNode *next;
-			BspNodeGeometry geom;
-
-			// todo: not very efficient: constructs full cell everytime
-			ConstructGeometry(interior, geom);
-
-			const int cf = 
-				Polygon3::ClassifyPlane(geom.GetPolys(), halfspace, mEpsilon);
-
-			if (cf == Polygon3::BACK_SIDE)
-				next = interior->GetFront();
-			else
-				if (cf == Polygon3::FRONT_SIDE)
-					next = interior->GetFront();
-			else
-			{
-				// random decision
-				if (mask & 1)
-					next = interior->GetBack();
-				else
-					next = interior->GetFront();
-				mask = mask >> 1;
-			}
-
-			nodeStack.push(next);
-		}
-	}
-
-	return NULL;
-}
-
-
-BspLeaf *ViewCellBspTree::GetRandomLeaf(const bool onlyUnmailed)
-{
-	stack<BspNode *> nodeStack;
-
-	nodeStack.push(mRoot);
-
-	int mask = rand();
-
-	while (!nodeStack.empty())
-	{
-		BspNode *node = nodeStack.top();
-		nodeStack.pop();
-
-		if (node->IsLeaf())
-		{
-			if ( (!onlyUnmailed || !node->Mailed()) )
-				return dynamic_cast<BspLeaf *>(node);
-		}
-		else
-		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
-
-			// random decision
-			if (mask & 1)
-				nodeStack.push(interior->GetBack());
-			else
-				nodeStack.push(interior->GetFront());
-
-			mask = mask >> 1;
-		}
-	}
-
-	return NULL;
-}
-
-
-float ViewCellBspTree::GetEpsilon() const
-{
-	return mEpsilon;
-}
-
-
-int ViewCellBspTree::CastLineSegment(const Vector3 &origin,
-									 const Vector3 &termination,
-									 vector<ViewCell *> &viewcells)
-{
-	int hits = 0;
-	stack<BspRayTraversalData> tQueue;
-
-	float mint = 0.0f, maxt = 1.0f;
-
-	Intersectable::NewMail();
-	ViewCell::NewMail();
-
-	Vector3 entp = origin;
-	Vector3 extp = termination;
-
-	BspNode *node = mRoot;
-	BspNode *farChild = NULL;
-
-	float t;
-	const float thresh = 1e-6f; // matt: change this
-	
-	while (1)
-	{
-		if (!node->IsLeaf())
-		{
-			BspInterior *in = dynamic_cast<BspInterior *>(node);
-
-			Plane3 splitPlane = in->GetPlane();
-			
-			const int entSide = splitPlane.Side(entp, thresh);
-			const int extSide = splitPlane.Side(extp, thresh);
-
-			if (entSide < 0) 
-			{
-				node = in->GetBack();
-				
-				// plane does not split ray => no far child
-				if (extSide <= 0) 
-					continue;
-  
-				farChild = in->GetFront(); // plane splits ray
-			} 
-			else if (entSide > 0)
-			{
-				node = in->GetFront();
-
-				if (extSide >= 0) // plane does not split ray => no far child
-					continue;
-
-				farChild = in->GetBack(); // plane splits ray
-			}
-			else // one of the ray end points is on the plane
-			{	// NOTE: what to do if ray is coincident with plane?
-				if (extSide < 0)
-					node = in->GetBack();
-				else //if (extSide > 0)
-					node = in->GetFront();
-				//else break; // coincident => count no intersections
-
-				continue; // no far child
-			}
-
-			// push data for far child
-			tQueue.push(BspRayTraversalData(farChild, extp));
-
-			// find intersection of ray segment with plane
-			extp = splitPlane.FindIntersection(origin, extp, &t);
-		} 
-		else
-		{
-			// reached leaf => intersection with view cell
-			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
-			ViewCell *viewCell;
-			
-			if (0)
-				viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
-			else
-				viewCell = leaf->GetViewCell();
-
-			if (!viewCell->Mailed())
-			{
-				viewcells.push_back(viewCell);
-				viewCell->Mail();
-				++ hits;
-			}
-
-			//-- fetch the next far child from the stack
-			if (tQueue.empty())
-				break;
-
-			entp = extp;
-			
-			BspRayTraversalData &s = tQueue.top();
-
-			node = s.mNode;
-			extp = s.mExitPoint;
-
-			tQueue.pop();
-		}
-	}
-
-	return hits;
-}
-
-
-bool ViewCellBspTree::ViewPointValid(const Vector3 &viewPoint) const
-{
-	BspNode *node = mRoot;
-
-	while (1)
-	{
-		// early exit
-		if (node->TreeValid())
-			return true;
-
-		if (node->IsLeaf())
-			return false;
-			
-		BspInterior *in = dynamic_cast<BspInterior *>(node);
-					
-		if (in->GetPlane().Side(viewPoint) <= 0) 
-		{
-			node = in->GetBack();
-		} 
-		else
-		{
-			node = in->GetFront();
-		}
-	}
-
-	// should never come here
-	return false;
-}
