Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 579)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 580)
@@ -21,5 +21,5 @@
 class ViewCellsStatistics;
 class ViewCellsManager;
-class BspMergeCandidate;
+class MergeCandidate;
 class Beam;
 
@@ -252,15 +252,4 @@
 	int TreeDistance(BspNode *n1, BspNode *n2) const;
 
-	/** Merges view cells according to some cost heuristics.
-	*/
-	int MergeViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
-	
-	/** Refines view cells using shuffling, i.e., border leaves 
-		of two view cells are exchanged if the resulting view cells
-		are tested to be "better" than the old ones.
-		@returns number of refined view cells
-	*/
-	int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
-
 	/** Collapses the tree with respect to the view cell partition.
 		@returns number of collapsed nodes
@@ -272,12 +261,4 @@
 	ViewCell *GetViewCell(const Vector3 &point);
 
-	/** Constructs bsp rays for post processing and visualization.
-	*/
-	void ConstructBspRays(vector<BspRay *> &bspRays,
-						  const VssRayContainer &rays);
-	
-	/** Merge view cells of leaves l1 and l2.
-	*/
-	bool MergeViewCells(BspLeaf *l1, BspLeaf *l2); //const;
 
 	/** Returns true if this view point is in a valid view space,
@@ -369,9 +350,4 @@
 	BspNode *CollapseTree(BspNode *node, int &collapsed);
 
-	/** Shuffles the leaves, i.e., tests if exchanging
-		the leaves helps in improving the view cells.
-	*/
-	bool ShuffleLeaves(BspLeaf *leaf1, BspLeaf *leaf2) const;
-
 	/** Helper function revalidating the view cell leaf list after merge.
 	*/
@@ -573,14 +549,8 @@
 
 
-	/** Collects candidates for the merge in the merge queue.
-		@param leaves the leaves to be merged
-		@returns number of leaves in queue
-	*/
-	int CollectMergeCandidates(const vector<BspLeaf *> leaves);
-	/** Collects candidates for the merge in the merge queue.
-		@returns number of leaves in queue
-	*/
-	int CollectMergeCandidates(const VssRayContainer &rays);
-
+
+
+
+	
 	/** Take 3 ray endpoints, where two are minimum and one a maximum
 		point or the other way round.
@@ -599,11 +569,16 @@
 	Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const;
   
-	/** Shuffles, i.e. takes border leaf from view cell 1 and adds it 
-		to view cell 2.
-	*/
-	void ShuffleLeaf(BspLeaf *leaf, 
-					 BspViewCell *vc1, 
-					 BspViewCell *vc2) const;
-
+	/** Collects candidates for merging.
+		@param leaves the leaves to be merged
+		@returns number of leaves in queue
+	*/
+	int CollectMergeCandidates(const vector<BspLeaf *> leaves, vector<MergeCandidate> &candidates);
+
+	/** Collects candidates for the merge in the merge queue.
+		@returns number of leaves in queue
+	*/
+	int CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
+	
+	
 	
 	/** Propagates valid flag up the tree.
@@ -620,11 +595,5 @@
 	float GetMemUsage() const;
 
-	/** Calculates cost for merge of view cell 1 and 2.
-	*/
-	float GetShuffledVcCost(BspLeaf *leaf, BspViewCell *vc1, BspViewCell *vc2) const;
-
-	void ExportMergedViewCells(ViewCellContainer &viewCells, 
-							   const ObjectContainer &objects,
-							   const int nViewCells);
+
 
 	/// Pointer to the root of the tree
@@ -658,5 +627,5 @@
 	float mTermMinAccRayLength;
 
-	ofstream mStats;
+	
 
 	//-- termination criteria for axis aligned split
@@ -701,8 +670,5 @@
 	/// maximal number of view cells
 	int mMaxViewCells;
-	/// minimal number of view cells
-	int mMergeMinViewCells;
-	/// maximal cost ratio for the merge
-	float mMergeMaxCostRatio;
+	
 
 	// if rays should be stored in leaves
@@ -716,16 +682,8 @@
 	vector<SortableEntry> *mSplitCandidates;
 
-
-	typedef priority_queue<BspMergeCandidate> MergeQueue;
-
-	MergeQueue mMergeQueue;
-
-	/// if rays should be used to collect merge candidates
-	bool mUseRaysForMerge;
-	
+	
+	float mRenderCostWeight;
 	/// View cell corresponding to the space outside the valid view space
 	BspViewCell *mOutOfBoundsCell;
-
-	int mCurrentViewCellsId;
 
 	/// maximal tree memory
@@ -733,13 +691,8 @@
 	/// the tree is out of memory
 	bool mOutOfMemory;
-	/// if merge visualization should be shown
-	bool mExportMergedViewCells;
-	/// if merge statistics should be exported
-	bool mExportMergeStats;
-
+	
+	
 private:
-	
-	ViewCellContainer mOldViewCells;
-	ViewCellContainer mNewViewCells;
+
 
 	static const float sLeastRaySplitsTable[5];
@@ -758,150 +711,6 @@
 };
 
-/**
-	Candidate for leaf merging based on priority.
-*/
-class BspMergeCandidate
-{  
-	friend class VspBspTree;
-
-public:
-
-	BspMergeCandidate(BspLeaf *l1, BspLeaf *l2);
-
-	/** If this merge pair is still valid.
-	*/
-	bool Valid() const;
-
-	/** Sets this merge candidate to be valid.
-	*/
-	void SetValid();
-
-	friend bool operator<(const BspMergeCandidate &leafa, const BspMergeCandidate &leafb)
-	{
-		return leafb.GetMergeCost() < leafa.GetMergeCost();
-	}
-
-	void SetLeaf1(BspLeaf *l);
-	void SetLeaf2(BspLeaf *l);
-
-	BspLeaf *GetLeaf1() const;
-	BspLeaf *GetLeaf2() const;
-
-	/** Merge cost of this candidate pair.
-	*/
-	float GetMergeCost() const;
-
-	/** Render cost of this candidate.
-	*/
-	float GetRenderCost() const;
-
-	/** returns increase in variance of this view cell.
-	*/
-	float GetVarianceIncr() const;
-
-	/** Returns cost of leaf 1.
-	*/
-	float GetLeaf1Cost() const;
-	
-	/** Returns cost of leaf 2.
-	*/
-	float GetLeaf2Cost() const;
-
-	/** Variance of leaf1
-	*/
-	float GetLeaf1Variance() const;
-
-	/** Variance of leaf2
-	*/
-	float GetLeaf2Variance() const;
-
-	/// overall cost used to normalize cost ratio
-	static float sOverallCost;
-	static float sExpectedCost;
-	static float sVariance;
-
-	static int sNumViewCells;
-
-	// weights between variance and render cost increase (must between zero and one)
-	static float sRenderCostWeight;
-
-	/// if area or volume should be used for the merge heuristics
-	static bool sUseArea;
-
-	/// pointer to view cells manager
-	static ViewCellsManager *sViewCellsManager;
-
-protected:
-
-	
-	/** Evaluates the merge costs of the leaves.
-	*/
-	void EvalMergeCost();
-
-	/** render cost of a view cell.
-	*/
-	float GetRenderCost(ViewCell *vc) const;
-	
-	int mLeaf1Id;
-	int mLeaf2Id;
-
-	/// render cost increase by this merge
-	float mRenderCost;
-	/// increase / decrease of variance
-	float mVarianceIncr;
-
-	BspLeaf *mLeaf1;
-	BspLeaf *mLeaf2;
-};
-
-
-class MergeStatistics: public StatisticsBase
-{
-public:
-	
-	int merged;
-	int siblings;
-	int candidates;
-	int nodes;
-
-	int accTreeDist;
-	int maxTreeDist;
-	
-	Real collectTime;
-	Real mergeTime;
-
-	Real overallCost;
-
-	// Constructor
-	MergeStatistics() 
-	{
-		Reset();
-	}
-	
-	double AvgTreeDist() const {return (double)accTreeDist / (double)merged;}; 
-
-	void Reset() 
-	{
-		nodes = 0;
-		merged = 0;
-		siblings = 0;
-		candidates = 0;
-	
-		accTreeDist = 0;
-		maxTreeDist = 0;
-
-		collectTime = 0;
-		mergeTime = 0;
-		overallCost = 0;
-	}
-
-	void Print(ostream &app) const;
-
-	friend ostream &operator<<(ostream &s, const MergeStatistics &stat) 
-	{
-		stat.Print(s);
-		return s;
-	} 
-};
+
+
 
 #endif
