Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h	(revision 435)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h	(revision 438)
@@ -44,19 +44,19 @@
   // totals number of rays
   int rays;
-	// initial size of the pvs
+  // initial size of the pvs
   int initialPvsSize;
-	// total number of query domains
+  // total number of query domains
   int queryDomains;
   // total number of ray references
   int rayRefs;
 
-	// max depth nodes
+  // max depth nodes
   int maxDepthNodes;
   // max depth nodes
   int minPvsNodes;
   int minRaysNodes;
-	// max ray contribution nodes
+  // max ray contribution nodes
   int maxRayContribNodes;
-	// max depth nodes
+  // max depth nodes
   int minSizeNodes;
   int maxCostRatioNodes;
@@ -89,8 +89,8 @@
     maxRayRefs = 0;
     addedRayRefs = removedRayRefs = 0;
-		initialPvsSize = 0;
-		maxRayContribNodes = 0;
-		minSizeNodes = 0;
-		maxCostRatioNodes = 0;
+	initialPvsSize = 0;
+	maxRayContribNodes = 0;
+	minSizeNodes = 0;
+	maxCostRatioNodes = 0;
   }
 
@@ -123,6 +123,6 @@
   SortableEntry() {}
   SortableEntry(const int t, const float v, void *d):type(t),
-																										 value(v),
-																										 data(d) {}
+													 value(v),
+													 data(d) {}
 	
   friend bool operator<(const SortableEntry &a, const SortableEntry &b) {
@@ -144,6 +144,6 @@
 #define USE_FIXEDPOINT_T 0
 
-struct RayInfo
-{
+  struct RayInfo
+  {
 	// pointer to the actual ray
 	VssRay *mRay;
@@ -161,72 +161,72 @@
 #if USE_FIXEDPOINT_T
 #define FIXEDPOINT_ONE 0x7FFE
-										 //			  mMaxT(0xFFFF)
-										 mMaxT(FIXEDPOINT_ONE)
+					   //			  mMaxT(0xFFFF)
+					   mMaxT(FIXEDPOINT_ONE)
 #else
-		mMaxT(1.0f)
+	  mMaxT(1.0f)
 #endif
 	{}
 	
 	RayInfo(VssRay *r,
-					const float _min,
-					const float _max
-					):mRay(r) {
-		SetMinT(_min);
-		SetMaxT(_max);
+			const float _min,
+			const float _max
+			):mRay(r) {
+	  SetMinT(_min);
+	  SetMaxT(_max);
 	}
 	
 	RayInfo(VssRay *r,
-					const short _min,
-					const float _max
-					):mRay(r), mMinT(_min) {
-		SetMaxT(_max);
+			const short _min,
+			const float _max
+			):mRay(r), mMinT(_min) {
+	  SetMaxT(_max);
 	}
 	
 	RayInfo(VssRay *r,
-										const float _min,
-										const short _max
-										):mRay(r), mMaxT(_max) {
-		SetMinT(_min);
+			const float _min,
+			const short _max
+			):mRay(r), mMaxT(_max) {
+	  SetMinT(_min);
 	}
 
 	enum {
-				SOURCE_RAY = 0,
-				TERMINATION_RAY,
-				PASSING_RAY,
-				CONTAINED_RAY
+	  SOURCE_RAY = 0,
+	  TERMINATION_RAY,
+	  PASSING_RAY,
+	  CONTAINED_RAY
 	};
 	
 	int GetRayClass() const {
 		
-		bool startsBefore = GetMinT() > 0.0f;
-		bool terminatesAfter = GetMaxT() < 1.0f;
+	  bool startsBefore = GetMinT() > 0.0f;
+	  bool terminatesAfter = GetMaxT() < 1.0f;
 		
-		if (startsBefore && terminatesAfter)
-			return PASSING_RAY;
-
-		if (!startsBefore && !terminatesAfter)
-			return CONTAINED_RAY;
+	  if (startsBefore && terminatesAfter)
+		return PASSING_RAY;
+
+	  if (!startsBefore && !terminatesAfter)
+		return CONTAINED_RAY;
 		
-		if (!startsBefore)
-			return SOURCE_RAY;
+	  if (!startsBefore)
+		return SOURCE_RAY;
 		
-		return TERMINATION_RAY;
+	  return TERMINATION_RAY;
 	}
 	
 	friend bool operator<(const RayInfo &a, const RayInfo &b) {
-		return a.mRay < b.mRay;
+	  return a.mRay < b.mRay;
 	}
   
 	
 	float ExtrapOrigin(const int axis) const {
-		return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis);
+	  return mRay->GetOrigin(axis) + GetMinT()*mRay->GetDir(axis);
 	}
 	
 	float ExtrapTermination(const int axis) const {
-		return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis);
+	  return mRay->GetOrigin(axis) + GetMaxT()*mRay->GetDir(axis);
 	}
 
 	Vector3 Extrap(const float t) const {
-		return mRay->Extrap(t);
+	  return mRay->Extrap(t);
 	}
 	
@@ -236,12 +236,12 @@
 	
 	void SetMinT (const float t) {
-		mMinT = (short) (t*(float)(FIXEDPOINT_ONE));
+	  mMinT = (short) (t*(float)(FIXEDPOINT_ONE));
 	}
 	
 	void SetMaxT (const float t) {
-		mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
-		mMaxT++;
-		//      if (mMaxT!=0xFFFF)
-		//	mMaxT++;
+	  mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
+	  mMaxT++;
+	  //      if (mMaxT!=0xFFFF)
+	  //	mMaxT++;
 	}
 #else
@@ -254,32 +254,32 @@
 
 
-  int ComputeRayIntersection(const int axis,
-														 const float position,
-														 float &t
-														 ) const {
+	int ComputeRayIntersection(const int axis,
+							   const float position,
+							   float &t
+							   ) const {
 		
-		// intersect the ray with the plane
-    float denom = mRay->GetDir(axis);
+	  // intersect the ray with the plane
+	  float denom = mRay->GetDir(axis);
     
-    if (fabs(denom) < 1e-20)
-      //if (denom == 0.0f)
-      return (mRay->GetOrigin(axis) > position) ? 1 : -1;
+	  if (fabs(denom) < 1e-20)
+		//if (denom == 0.0f)
+		return (mRay->GetOrigin(axis) > position) ? 1 : -1;
     
-    t = (position - mRay->GetOrigin(axis))/denom;
-
-    if (t < GetMinT())
-      return (denom > 0) ? 1 : -1;
-
-    if (t > GetMaxT())
-      return (denom > 0) ? -1 : 1;
-
-		return 0;
-	}
-
-
-};
-
-
-	typedef vector<RayInfo> RayInfoContainer;
+	  t = (position - mRay->GetOrigin(axis))/denom;
+
+	  if (t < GetMinT())
+		return (denom > 0) ? 1 : -1;
+
+	  if (t > GetMaxT())
+		return (denom > 0) ? -1 : 1;
+
+	  return 0;
+	}
+
+
+  };
+
+
+  typedef vector<RayInfo> RayInfoContainer;
 	
   enum { EInterior, ELeaf };
@@ -346,8 +346,8 @@
   
   VssTreeInterior(VssTreeInterior *p):VssTreeNode(p),
-					back(NULL),
-					front(NULL),
-					accesses(0),
-					lastAccessTime(-1)
+									  back(NULL),
+									  front(NULL),
+									  accesses(0),
+									  lastAccessTime(-1)
   { }
 
@@ -383,7 +383,7 @@
     else
       if (axis == 1)
-	s<<"y ";
+		s<<"y ";
       else
-	s<<"z ";
+		s<<"z ";
     s<<position<<" ";
     back->Print(s);
@@ -394,7 +394,7 @@
 	
   int ComputeRayIntersection(const RayInfo &rayData,
-														 float &t
-														 ) {
-		return rayData.ComputeRayIntersection(axis, position, t);
+							 float &t
+							 ) {
+	return rayData.ComputeRayIntersection(axis, position, t);
   }
 
@@ -409,5 +409,5 @@
 {
 private:
-	int mPvsSize;
+  int mPvsSize;
 public:
   static int mailID;
@@ -415,13 +415,13 @@
   
   RayInfoContainer rays;
-	int mPassingRays;
-	
-	bool mValidPvs;
-	
-	
+  int mPassingRays;
+	
+  bool mValidPvs;
+  float mEntropyImportance;
+  
 	
   VssTreeLeaf(VssTreeInterior *p,
-							const int nRays
-							):VssTreeNode(p), rays(), mPvsSize(0), mPassingRays(0), mValidPvs(false) {
+			  const int nRays
+			  ):VssTreeNode(p), rays(), mPvsSize(0), mPassingRays(0), mValidPvs(false) {
     rays.reserve(nRays);
   }
@@ -436,21 +436,34 @@
   
   void AddRay(const RayInfo &data) {
-		mValidPvs = false;
+	mValidPvs = false;
     rays.push_back(data);
     data.mRay->Ref();
-		if (data.GetRayClass() == RayInfo::PASSING_RAY)
-			mPassingRays++;
-  }
-	
-	int GetPvsSize() const {
-		return mPvsSize;
-	}
-	void SetPvsSize(const int s) {
-		mPvsSize = s;
-		mValidPvs = true;
-	}
-
-	void
-	UpdatePvsSize();
+	if (data.GetRayClass() == RayInfo::PASSING_RAY)
+	  mPassingRays++;
+  }
+	
+  int GetPvsSize() const {
+	return mPvsSize;
+  }
+
+  void SetPvsSize(const int s) {
+	mPvsSize = s;
+	mValidPvs = true;
+  }
+
+  void
+  UpdatePvsSize();
+
+  float
+  ComputePvsEntropy();
+  
+  float
+  ComputeRayLengthEntropy();
+  
+  float
+  ComputeRayTerminationEntropy();
+  
+  void
+  ComputeEntropyImportance();
 
   void Mail() { mailbox = mailID; }
@@ -462,35 +475,35 @@
   }
 
-	float GetAvgRayContribution() const {
-		return GetPvsSize()/((float)rays.size() + Limits::Small);
-	}
+  float GetAvgRayContribution() const {
+	return GetPvsSize()/((float)rays.size() + Limits::Small);
+  }
 
   float GetImportance() const;
-
-	float GetSqrRayContribution() const {
-		return sqr(GetPvsSize()/((float)rays.size() + Limits::Small));
-	}
-
-	// comparator for the 
-	struct less_contribution : public
-	binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> {
-		
-		bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) {
-			return a->GetAvgRayContribution() < b->GetAvgRayContribution();
-		}
-	};
-
-	struct greater_contribution : public
-	binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> {
-		
-		bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) {
-			return a->GetAvgRayContribution() > b->GetAvgRayContribution();
-		}
-	};
-	
-	friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) {
-		return a->GetAvgRayContribution() > b->GetAvgRayContribution();
-	}
-	
+  
+  float GetSqrRayContribution() const {
+	return sqr(GetPvsSize()/((float)rays.size() + Limits::Small));
+  }
+  
+  // comparator for the 
+  struct less_contribution : public
+  binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> {
+	
+	bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) {
+	  return a->GetAvgRayContribution() < b->GetAvgRayContribution();
+	}
+  };
+  
+  struct greater_contribution : public
+  binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> {
+	
+	bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) {
+	  return a->GetAvgRayContribution() > b->GetAvgRayContribution();
+	}
+  };
+  
+  friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) {
+	return a->GetAvgRayContribution() > b->GetAvgRayContribution();
+  }
+  
 };
 
@@ -521,6 +534,6 @@
 
     TraversalData(VssTreeNode *n,
-		   const AxisAlignedBox3 &b,
-		   const int d):
+				  const AxisAlignedBox3 &b,
+				  const int d):
       node(n), bbox(b), depth(d) {}
     
@@ -531,5 +544,5 @@
 			
       bool operator()(const TraversalData a, const TraversalData b) {
-				return a.priority < b.priority;
+		return a.priority < b.priority;
       }
       
@@ -540,37 +553,37 @@
     
     friend bool operator<(const TraversalData &a,
-													const TraversalData &b) {
+						  const TraversalData &b) {
       //      return a.node->queries.size() < b.node->queries.size();
       VssTreeLeaf *leafa = (VssTreeLeaf *) a.node;
       VssTreeLeaf *leafb = (VssTreeLeaf *) b.node;
 #if 0
-			return
-				leafa->rays.size()*a.bbox.GetVolume()
-				<
-				leafb->rays.size()*b.bbox.GetVolume();
+	  return
+		leafa->rays.size()*a.bbox.GetVolume()
+		<
+		leafb->rays.size()*b.bbox.GetVolume();
 #endif
 #if 0
-			return
-				leafa->GetPvsSize()*a.bbox.GetVolume()
-				<
-				leafb->GetPvsSize()*b.bbox.GetVolume();
+	  return
+		leafa->GetPvsSize()*a.bbox.GetVolume()
+		<
+		leafb->GetPvsSize()*b.bbox.GetVolume();
 #endif
 #if 0
-			return
-				leafa->GetPvsSize()
-				<
-				leafb->GetPvsSize();
+	  return
+		leafa->GetPvsSize()
+		<
+		leafb->GetPvsSize();
 #endif
 #if 0
-			return
-				leafa->GetPvsSize()/(leafa->rays.size()+1)
-				>
-				leafb->GetPvsSize()/(leafb->rays.size()+1);
+	  return
+		leafa->GetPvsSize()/(leafa->rays.size()+1)
+		>
+		leafb->GetPvsSize()/(leafb->rays.size()+1);
 #endif
 #if 1
-			return
-				leafa->GetPvsSize()*leafa->rays.size()
-				<
-				leafb->GetPvsSize()*leafb->rays.size();
+	  return
+		leafa->GetPvsSize()*leafa->rays.size()
+		<
+		leafb->GetPvsSize()*leafb->rays.size();
 #endif
     }
@@ -586,5 +599,5 @@
     RayTraversalData() {}
     RayTraversalData(VssTreeNode *n,
-										 const VssTreeNode::RayInfo &data):
+					 const VssTreeNode::RayInfo &data):
       rayData(data), node(n) {}
   };
@@ -619,8 +632,8 @@
   float termMinSize;
 
-	// minimal pvs per node to still get subdivided
+  // minimal pvs per node to still get subdivided
   int termMinPvs;
 
-	// minimal ray number per node to still get subdivided
+  // minimal ray number per node to still get subdivided
   int termMinRays;
 	
@@ -628,20 +641,27 @@
   float termMaxCostRatio;
 	
-	// maximal contribution per ray to subdivide the node
-	float termMaxRayContribution;
+  // maximal contribution per ray to subdivide the node
+  float termMaxRayContribution;
 
 	
   // randomized construction
   bool randomize;
-
+  
   // type of the splitting to use fo rthe tree construction
   enum {ESplitRegular, ESplitHeuristic, ESplitHybrid };
   int splitType;
 
-	bool mSplitUseOnlyDrivingAxis;
-
-	// use ray space subdivision instead of view space subdivision
-	bool mUseRss;
-	
+  bool mSplitUseOnlyDrivingAxis;
+  
+  // use ray space subdivision instead of view space subdivision
+  bool mUseRss;
+
+  // interleave directional and spatial splits based on their costs
+  // if false directional splits are only performed after spatial splits
+  bool mInterleaveDirSplits;
+
+  // depth at which directional splits are performed if mInterleaveDirSplits is false
+  int mDirSplitDepth;
+  
   // maximal size of the box on which the refdir splitting can be performed
   // (relative to the scene bbox
@@ -662,5 +682,5 @@
   int accessTimeThreshold;
 
-	// minimal depth at which to perform collapse
+  // minimal depth at which to perform collapse
   int minCollapseDepth;
 
@@ -670,5 +690,5 @@
   /////////////////////////////
 
-	VssStatistics stat;
+  VssStatistics stat;
 	
   
@@ -678,20 +698,20 @@
   virtual void
   Construct(
-						VssRayContainer &rays,
-						AxisAlignedBox3 *forcedBoundingBox = NULL
-						);
+			VssRayContainer &rays,
+			AxisAlignedBox3 *forcedBoundingBox = NULL
+			);
 	
   // incemental construction
   virtual void UpdateRays(VssRayContainer &remove,
-													VssRayContainer &add
-													);
-
-	virtual void AddRays(
-											 VssRayContainer &add
-											 )
-	{
-		VssRayContainer remove;
-		UpdateRays(remove, add);
-	}
+						  VssRayContainer &add
+						  );
+
+  virtual void AddRays(
+					   VssRayContainer &add
+					   )
+  {
+	VssRayContainer remove;
+	UpdateRays(remove, add);
+  }
 
   
@@ -702,8 +722,8 @@
   VssTreeNode *
   SubdivideNode(VssTreeLeaf *leaf,
-								const AxisAlignedBox3 &box,
-								AxisAlignedBox3 &backBox,
-								AxisAlignedBox3 &frontBox
-								);
+				const AxisAlignedBox3 &box,
+				AxisAlignedBox3 &backBox,
+				AxisAlignedBox3 &frontBox
+				);
 	
   VssTreeNode *
@@ -712,17 +732,17 @@
   int
   SelectPlane(VssTreeLeaf *leaf,
-							const AxisAlignedBox3 &box,
-							float &position,
-							int &raysBack,
-							int &raysFront,
-							int &pvsBack,
-							int &pvsFront
-							);
+			  const AxisAlignedBox3 &box,
+			  float &position,
+			  int &raysBack,
+			  int &raysFront,
+			  int &pvsBack,
+			  int &pvsFront
+			  );
 
   void
   SortSplitCandidates(
-											VssTreeLeaf *node,
-											const int axis
-											);
+					  VssTreeLeaf *node,
+					  const int axis
+					  );
 	
   
@@ -742,47 +762,47 @@
   
 
-	float
-	BestCostRatio(
-								VssTreeLeaf *node,
-								int &axis,
-								float &position,
-								int &raysBack,
-								int &raysFront,
-								int &pvsBack,
-								int &pvsFront
-								);
-	
-	float
-	EvalCostRatio(
-								VssTreeLeaf *node,
-								const int axis,
-								const float position,
-								int &raysBack,
-								int &raysFront,
-								int &pvsBack,
-								int &pvsFront
-								);
-
-	float
-	EvalCostRatioHeuristic(
-												 VssTreeLeaf *node,
-												 const int axis,
-												 float &position,
-												 int &raysBack,
-												 int &raysFront,
-												 int &pvsBack,
-												 int &pvsFront
-												 );
-
-	float
-	GetCostRatio(
-							 VssTreeLeaf *leaf,
-							 const int axis,
-							 const float position,
-							 const int raysBack,
-							 const int raysFront,
-							 const int pvsBack,
-							 const int pvsFront
-							 );
+  float
+  BestCostRatio(
+				VssTreeLeaf *node,
+				int &axis,
+				float &position,
+				int &raysBack,
+				int &raysFront,
+				int &pvsBack,
+				int &pvsFront
+				);
+	
+  float
+  EvalCostRatio(
+				VssTreeLeaf *node,
+				const int axis,
+				const float position,
+				int &raysBack,
+				int &raysFront,
+				int &pvsBack,
+				int &pvsFront
+				);
+
+  float
+  EvalCostRatioHeuristic(
+						 VssTreeLeaf *node,
+						 const int axis,
+						 float &position,
+						 int &raysBack,
+						 int &raysFront,
+						 int &pvsBack,
+						 int &pvsFront
+						 );
+
+  float
+  GetCostRatio(
+			   VssTreeLeaf *leaf,
+			   const int axis,
+			   const float position,
+			   const int raysBack,
+			   const int raysFront,
+			   const int pvsBack,
+			   const int pvsFront
+			   );
 
   AxisAlignedBox3 GetBBox(const VssTreeNode *node) const {
@@ -838,78 +858,78 @@
   VssTreeNode *
   SubdivideLeaf(
-								VssTreeLeaf *leaf
-								);
+				VssTreeLeaf *leaf
+				);
 
   void
   RemoveRay(VssRay *ray,
-						vector<VssTreeLeaf *> *affectedLeaves,
-						const bool removeAllScheduledRays
-						);
-
-	//  void
-	//  AddRay(VssRay *ray);
-	void
-	AddRay(VssTreeNode::RayInfo &info);
-
+			vector<VssTreeLeaf *> *affectedLeaves,
+			const bool removeAllScheduledRays
+			);
+
+  //  void
+  //  AddRay(VssRay *ray);
+  void
+  AddRay(VssTreeNode::RayInfo &info);
+  
   void
   TraverseInternalNode(
-											 RayTraversalData &data,
-											 stack<RayTraversalData> &tstack);
-
-	void
+					   RayTraversalData &data,
+					   stack<RayTraversalData> &tstack);
+
+  void
   EvaluateLeafStats(const TraversalData &data);
 
 
-	int
-	GetRootPvsSize() const {
-		return GetPvsSize(bbox);
-	}
-	
-	int
-	GetPvsSize(const AxisAlignedBox3 &box) const;
-
-	void
-	GetRayContributionStatistics(
-															 float &minRayContribution,
-															 float &maxRayContribution,
-															 float &avgRayContribution
-															 );
-
-	int
-	GenerateRays(const float ratioPerLeaf,
-							 SimpleRayContainer &rays);
-
-	int
-	GenerateRays(const int numberOfRays,
-							 const int numberOfLeaves,
-							 SimpleRayContainer &rays);
+  int
+  GetRootPvsSize() const {
+	return GetPvsSize(bbox);
+  }
+  
+  int
+  GetPvsSize(const AxisAlignedBox3 &box) const;
+
+  void
+  GetRayContributionStatistics(
+							   float &minRayContribution,
+							   float &maxRayContribution,
+							   float &avgRayContribution
+							   );
+
+  int
+  GenerateRays(const float ratioPerLeaf,
+			   SimpleRayContainer &rays);
+
+  int
+  GenerateRays(const int numberOfRays,
+			   const int numberOfLeaves,
+			   SimpleRayContainer &rays);
 		
-	float
-	GetAvgPvsSize();
-
-	int
-	UpdateSubdivision();
-
-	bool
-	TerminationCriteriaSatisfied(VssTreeLeaf *leaf);
-
-	void
-	CollectLeaves(vector<VssTreeLeaf *> &leaves);
-
-	bool
-	ClipRay(
-					VssTreeNode::RayInfo &rayInfo,
-					const AxisAlignedBox3 &box
-					);
-
-	VssTreeNode *GetRoot() const { return root; }
-
-	bool
-	ValidLeaf(VssTreeLeaf *leaf) const;
-
-	void
-	GenerateLeafRays(VssTreeLeaf *leaf,
-									 const int numberOfRays,
-									 SimpleRayContainer &rays);
+  float
+  GetAvgPvsSize();
+
+  int
+  UpdateSubdivision();
+
+  bool
+  TerminationCriteriaSatisfied(VssTreeLeaf *leaf);
+
+  void
+  CollectLeaves(vector<VssTreeLeaf *> &leaves);
+
+  bool
+  ClipRay(
+		  VssTreeNode::RayInfo &rayInfo,
+		  const AxisAlignedBox3 &box
+		  );
+
+  VssTreeNode *GetRoot() const { return root; }
+
+  bool
+  ValidLeaf(VssTreeLeaf *leaf) const;
+
+  void
+  GenerateLeafRays(VssTreeLeaf *leaf,
+				   const int numberOfRays,
+				   SimpleRayContainer &rays);
 
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 434)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 438)
@@ -1442,8 +1442,8 @@
   RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
   RegisterOption("VssTree.minRays", optInt, "kd_minrays=", "10");
-	RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
-	RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
-
-	RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
+  RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.95");
+  RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5");
+
+  RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6");
   RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0");
   RegisterOption("VssTree.randomize", optBool, "randomize", "false");
@@ -1470,4 +1470,10 @@
   RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000");
   RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4");
+
+  RegisterOption("VssTree.interleaveDirSplits", optBool, "interleavedirsplits", "true");
+
+  RegisterOption("VssTree.dirSplitDepth", optInt, "dirsplidepth=", "10");
+
+
 }
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 434)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 438)
@@ -49,6 +49,11 @@
   ExportKdTree(const KdTree &tree) = 0;
 
-	virtual bool
+  virtual bool
   ExportVssTree(const VssTree &tree) = 0;
+
+  virtual bool
+  ExportVssTree2(const VssTree &tree,
+				 const Vector3 direction
+				 ) = 0;
 
   virtual bool
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 435)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 438)
@@ -25,4 +25,5 @@
 #include "Ray.h"
 
+#define DEBUG_SPLIT_COST 0
 
 // Static variables
@@ -119,5 +120,8 @@
   environment->GetBoolValue("VssTree.splitUseOnlyDrivingAxis", mSplitUseOnlyDrivingAxis);
   environment->GetBoolValue("VssTree.useRss", mUseRss);
-	
+
+  environment->GetBoolValue("VssTree.interleaveDirSplits", mInterleaveDirSplits);
+  environment->GetIntValue("VssTree.dirSplitDepth", mDirSplitDepth);
+
   root = NULL;
   
@@ -230,4 +234,5 @@
 	mPvsSize = pvsSize;
 	mValidPvs = true;
+
   }
 }
@@ -316,4 +321,6 @@
   stat.rays = leaf->rays.size();
   leaf->UpdatePvsSize();
+  leaf->ComputeEntropyImportance();
+
   stat.initialPvsSize = leaf->GetPvsSize();
   // Subdivide();
@@ -478,7 +485,7 @@
 							pvsFront
 							);
-
+#if DEBUG_SPLIT_COST
   cout<<axis<<" r="<<costRatio<<endl;
-	
+#endif
   if (costRatio > termMaxCostRatio) {
 	//		cout<<"Too big cost ratio "<<costRatio<<endl;
@@ -675,73 +682,77 @@
   bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size());
 		
-
-  for (axis = 0; axis < 5; axis++) {
-	if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) {
-
-
-	  if (splitType == ESplitRegular) {
-		if (axis < 3)
-		  nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;
+  
+  for (axis = 0; axis < 5; axis++)
+	if (mInterleaveDirSplits ||
+		(axis < 3 && leaf->depth < mDirSplitDepth) ||
+		(axis >= 3 && leaf->depth >= mDirSplitDepth)
+		) {
+	  if (!mSplitUseOnlyDrivingAxis || axis == sAxis || axis == dAxis) {
+		
+		
+		if (splitType == ESplitRegular) {
+		  if (axis < 3)
+			nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;
+		  else
+			nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f;
+		  
+		  nCostRatio[axis] = EvalCostRatio(leaf,
+										   axis,
+										   nPosition[axis],
+										   nRaysBack[axis],
+										   nRaysFront[axis],
+										   nPvsBack[axis],
+										   nPvsFront[axis]
+										   );
+		} else
+		  if (splitType == ESplitHeuristic) {
+			nCostRatio[axis] = EvalCostRatioHeuristic(
+													  leaf,
+													  axis,
+													  nPosition[axis],
+													  nRaysBack[axis],
+													  nRaysFront[axis],
+													  nPvsBack[axis],
+													  nPvsFront[axis]);
+		  } else
+			if (splitType == ESplitHybrid) {
+			  if (leaf->depth > 7)
+				nCostRatio[axis] = EvalCostRatioHeuristic(
+														  leaf,
+														  axis,
+														  nPosition[axis],
+														  nRaysBack[axis],
+														  nRaysFront[axis],
+														  nPvsBack[axis],
+														  nPvsFront[axis]);
+			  else {
+				if (axis < 3)
+				  nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;
+				else
+				  nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f;
+				
+				nCostRatio[axis] = EvalCostRatio(leaf,
+												 axis,
+												 nPosition[axis],
+												 nRaysBack[axis],
+												 nRaysFront[axis],
+												 nPvsBack[axis],
+												 nPvsFront[axis]
+												 );
+			  }
+			} else {
+			  cerr<<"VssTree: Unknown split heuristics\n";
+			  exit(1);
+			}
+		
+		
+		if ( bestAxis == -1)
+		  bestAxis = axis;
 		else
-		  nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f;
-				
-		nCostRatio[axis] = EvalCostRatio(leaf,
-										 axis,
-										 nPosition[axis],
-										 nRaysBack[axis],
-										 nRaysFront[axis],
-										 nPvsBack[axis],
-										 nPvsFront[axis]
-										 );
-	  } else
-		if (splitType == ESplitHeuristic) {
-		  nCostRatio[axis] = EvalCostRatioHeuristic(
-													leaf,
-													axis,
-													nPosition[axis],
-													nRaysBack[axis],
-													nRaysFront[axis],
-													nPvsBack[axis],
-													nPvsFront[axis]);
-		} else
-		  if (splitType == ESplitHybrid) {
-			if (leaf->depth > 7)
-			  nCostRatio[axis] = EvalCostRatioHeuristic(
-														leaf,
-														axis,
-														nPosition[axis],
-														nRaysBack[axis],
-														nRaysFront[axis],
-														nPvsBack[axis],
-														nPvsFront[axis]);
-			else {
-			  if (axis < 3)
-				nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f;
-			  else
-				nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f;
-							
-			  nCostRatio[axis] = EvalCostRatio(leaf,
-											   axis,
-											   nPosition[axis],
-											   nRaysBack[axis],
-											   nRaysFront[axis],
-											   nPvsBack[axis],
-											   nPvsFront[axis]
-											   );
-			}
-		  } else {
-			cerr<<"VssTree: Unknown split heuristics\n";
-			exit(1);
-		  }
-			
-				
-	  if ( bestAxis == -1)
-		bestAxis = axis;
-	  else
-		if ( nCostRatio[axis] < nCostRatio[bestAxis] )
-		  bestAxis = axis;
-	}
-  }
-
+		  if ( nCostRatio[axis] < nCostRatio[bestAxis] )
+			bestAxis = axis;
+	  }
+	}
+  
   axis = bestAxis;
   position = nPosition[bestAxis];
@@ -775,6 +786,5 @@
 	minBox = box.Min(axis);
 	maxBox = box.Max(axis);
-  }
-  else {
+  } else {
 	box = GetDirBBox(leaf);
 	minBox = box.Min(axis-3);
@@ -1111,5 +1121,8 @@
   front->SetPvsSize(pvsFront);
   back->SetPvsSize(pvsBack);
-
+  // compute entropy as well
+  front->ComputeEntropyImportance();
+  back->ComputeEntropyImportance();
+  
   // update stats
   stat.rayRefs -= leaf->rays.size();
@@ -1832,4 +1845,123 @@
 VssTreeLeaf::GetImportance()  const
 {
-  return GetAvgRayContribution();
-}
+
+  if (1) {
+	//	return GetAvgRayContribution();
+	return GetPvsSize();
+  } else {
+	return GetAvgRayContribution()*mEntropyImportance;
+  }
+}
+
+
+float
+VssTreeLeaf::ComputePvsEntropy()
+{
+  int samples = 0;
+  Intersectable::NewMail();
+  // set all object as belonging to the fron pvs
+  for(VssTreeNode::RayInfoContainer::iterator ri = rays.begin();
+	  ri != rays.end();
+	  ri++)
+	if ((*ri).mRay->IsActive()) {
+	  Intersectable *object = (*ri).mRay->mTerminationObject;
+	  if (object) {
+		if (!object->Mailed()) {
+		  object->Mail();
+		  object->mCounter = 1;
+		} else
+		  object->mCounter++;
+		samples++;
+	  }
+	}
+  
+  float entropy = 0.0f;
+  
+  if (samples > 1) {
+	Intersectable::NewMail();
+	for(RayInfoContainer::const_iterator ri = rays.begin();
+		ri != rays.end();
+		ri++) 
+	  if ((*ri).mRay->IsActive()) {
+		Intersectable *object = (*ri).mRay->mTerminationObject;
+		if (object) {
+		  if (!object->Mailed()) {
+			object->Mail();
+			float p = object->mCounter/(float)samples;
+			entropy -= p*log(p);
+		  }
+		}
+	  }
+	entropy = entropy/log((float)samples);
+  }
+  else
+	entropy = 1.0f;
+  
+  return entropy;
+}
+
+float
+VssTreeLeaf::ComputeRayLengthEntropy()
+{
+  // get sum of all ray lengths
+  // consider only passing rays or originating rays
+  float sum = 0.0f;
+  int samples = 0;
+
+  for(RayInfoContainer::const_iterator ri = rays.begin();
+      ri != rays.end();
+      ri++) {
+	int rayClass = (*ri).GetRayClass();
+	if (
+		rayClass == RayInfo::PASSING_RAY
+		//		||
+		//		rayClass == RayInfo::SOURCE_RAY
+		//		rayClass == RayInfo::TERMINATION_RAY
+		) {
+	  float c = 1.0f - (*ri).GetMaxT();
+	  sum += (*ri).mRay->GetSize()*c;
+	  samples++;
+	}
+  }
+  
+  float entropy = 0.0f;
+  
+  if (samples > 1) {
+	for(RayInfoContainer::const_iterator ri = rays.begin();
+		ri != rays.end();
+		ri++) {
+	  int rayClass = (*ri).GetRayClass();
+	  if (
+		  rayClass == RayInfo::PASSING_RAY
+		  //		  ||
+		  //		  rayClass == RayInfo::SOURCE_RAY
+		  // rayClass == RayInfo::TERMINATION_RAY
+		  ) {
+		float c = 1.0f - (*ri).GetMaxT();
+		float p = (*ri).mRay->GetSize()*c/sum;
+		entropy -= p*log(p);
+	  }
+	}
+	entropy = entropy/log((float)samples);
+  } else
+	entropy = 1.0f;
+  
+  return entropy;
+}
+  
+float
+VssTreeLeaf::ComputeRayTerminationEntropy()
+{
+
+  return 0.0f;
+}
+
+
+void
+VssTreeLeaf::ComputeEntropyImportance()
+{
+  //  mEntropy = 1.0f - ComputeRayLengthEntropy();
+  mEntropyImportance = 1.0f - ComputePvsEntropy();
+  
+  //  cout<<"ei="<<mEntropyImportance<<" ";
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 434)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 438)
@@ -39,7 +39,12 @@
   ExportKdTree(const KdTree &tree);
 
-	bool
+  bool
   ExportVssTree(const VssTree &tree);
 
+  bool
+  ExportVssTree2(const VssTree &tree,
+				 const Vector3 direction
+				 );
+  
   bool 
   ExportVspKdTree(const VspKdTree &tree, const int maxPvs);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 434)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 438)
@@ -12,5 +12,5 @@
 class VssRay {
 public:
-	// various flags
+  // various flags
   enum {
     FPosDirX = 1,  // the direction of ray in X-axis is positive
@@ -19,20 +19,20 @@
   };
 
-	static int mailID;
+  static int mailID;
   int mMailbox;
 	
-	// side of the ray - used for the ray classification
-	//  char mSide;
-	
-	// computed t
+  // side of the ray - used for the ray classification
+  //  char mSide;
+	
+  // computed t
   float mT;
 
-	// inverse of the ray size
-	float mInvSize;
-	
-	// counter of references to this ray
+  // inverse of the ray size
+  float mInvSize;
+  
+  // counter of references to this ray
   short mRefCount;
-
-	// various flags
+  
+  // various flags
   char mFlags;
 	
@@ -40,68 +40,68 @@
   Vector3 mTermination;
 	
-	/// Termination object for the ray
-	/// only the termination object is actually used
-	Intersectable *mOriginObject;
-	Intersectable *mTerminationObject;
-	
-	//////////////////////////////
-	VssRay(const Vector3 &origin,
-				 const Vector3 &termination,
-				 Intersectable *originObject,
-				 Intersectable *terminationObject):
-		mMailbox(-1),
+  /// Termination object for the ray
+  /// only the termination object is actually used
+  Intersectable *mOriginObject;
+  Intersectable *mTerminationObject;
+	
+  //////////////////////////////
+  VssRay(const Vector3 &origin,
+		 const Vector3 &termination,
+		 Intersectable *originObject,
+		 Intersectable *terminationObject):
+	mMailbox(-1),
     mOrigin(origin),
     mTermination(termination),
-		mOriginObject(originObject),
-		mTerminationObject(terminationObject),
-		mRefCount(0),
+	mOriginObject(originObject),
+	mTerminationObject(terminationObject),
+	mRefCount(0),
     mFlags(0),
 	mT(1.0f)
-	{
+  {
     Precompute();
   }
 	
-	VssRay(const Ray &ray):
-		mRefCount(0),
-		mFlags(0),
-		mMailbox(-1),
-		mOriginObject(ray.sourceObject.mObject),
-		mT(1.0f)
-	{
-		if (ray.sourceObject.mObject)
-			mOrigin = ray.Extrap(ray.sourceObject.mT);
-		else
-			mOrigin = ray.GetLoc(); 
-
-		//Debug << "origin: " << mOrigin << endl;
-
-		if (!ray.intersections.empty())
-		{
-			mTermination = ray.Extrap(ray.intersections[0].mT);
-			mTerminationObject = ray.intersections[0].mObject;
-		}
-		else
-		{
-			mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity
-			mTerminationObject = NULL;
-		}
-
-		Precompute();
-	}
+  VssRay(const Ray &ray):
+	mRefCount(0),
+	mFlags(0),
+	mMailbox(-1),
+	mOriginObject(ray.sourceObject.mObject),
+	mT(1.0f)
+  {
+	if (ray.sourceObject.mObject)
+	  mOrigin = ray.Extrap(ray.sourceObject.mT);
+	else
+	  mOrigin = ray.GetLoc(); 
+
+	//Debug << "origin: " << mOrigin << endl;
+
+	if (!ray.intersections.empty())
+	  {
+		mTermination = ray.Extrap(ray.intersections[0].mT);
+		mTerminationObject = ray.intersections[0].mObject;
+	  }
+	else
+	  {
+		mTermination = ray.Extrap(1e6);//TODO: should be Limits::Infinity
+		mTerminationObject = NULL;
+	  }
+
+	Precompute();
+  }
 
   void Precompute() {
     mFlags = 0;
-		Vector3 dir = GetDir();
+	Vector3 dir = GetDir();
 
 #define BIDIRECTIONAL_RAY 0
 #if BIDIRECTIONAL_RAY
-		if (dir.y < 0) {
-			// swap objects and poits	
-			swap(mOriginObject, mTerminationObject);
-			swap(mOrigin, mTermination);
-			dir = -dir;
-		}
+	if (dir.y < 0) {
+	  // swap objects and poits	
+	  swap(mOriginObject, mTerminationObject);
+	  swap(mOrigin, mTermination);
+	  dir = -dir;
+	}
 #endif
-		if (dir.x > 0.0f) mFlags |= FPosDirX;
+	if (dir.x > 0.0f) mFlags |= FPosDirX;
     if (dir.y > 0.0f) mFlags |= FPosDirY;
     if (dir.z > 0.0f) mFlags |= FPosDirZ;
@@ -118,17 +118,17 @@
   }
 
-	int HitCount() const {
+  int HitCount() const {
 #if BIDIRECTIONAL_RAY
-		if (mOriginObject && mTerminationObject)
-			return 2;
-		if (mOriginObject || mTerminationObject)
-			return 1;
-		return 0;
+	if (mOriginObject && mTerminationObject)
+	  return 2;
+	if (mOriginObject || mTerminationObject)
+	  return 1;
+	return 0;
 #else
-		return (mTerminationObject) ? 1 : 0;
+	return (mTerminationObject) ? 1 : 0;
 #endif
-	}
-	
-	Vector3 GetOrigin() const { return mOrigin; }
+  }
+	
+  Vector3 GetOrigin() const { return mOrigin; }
   Vector3 GetTermination() const { return mTermination; }
   Vector3 GetDir() const { return mTermination - mOrigin; }
@@ -136,11 +136,14 @@
   Vector3 GetNormalizedDir() const { return (mTermination - mOrigin)*mInvSize; }
 
-	Vector3 Extrap(const float t) const {
-		return GetOrigin() + t * GetDir();
-	}
-	
-	float GetDirParametrization(const int axis) const;
-	
-	float GetInvSize() const { return  mInvSize; }
+  Vector3 Extrap(const float t) const {
+	return GetOrigin() + t * GetDir();
+  }
+	
+  float GetDirParametrization(const int axis) const;
+
+  static float VssRay::GetDirParam(const int axis, const Vector3 dir);
+
+  float GetSize() const { return  1.0f/mInvSize; }
+  float GetInvSize() const { return  mInvSize; }
   float GetOrigin(const int axis) const { return mOrigin[axis]; }
   float GetTermination(const int axis) const { return mTermination[axis]; }
@@ -152,17 +155,17 @@
   bool
   ComputeMinMaxT(const AxisAlignedBox3 &box,
-								 float &tmin,
-								 float &tmax) const;
+				 float &tmin,
+				 float &tmax) const;
 	
   bool
   Intersects(const AxisAlignedBox3 &box,
-						 float &tmin,
-						 float &tmax) const;
+			 float &tmin,
+			 float &tmax) const;
 	
   bool
   IntersectsSphere(const Vector3 &center,
-									 const float sqrRadius,
-									 Vector3 &point,
-									 float &t) const;
+				   const float sqrRadius,
+				   Vector3 &point,
+				   float &t) const;
 	
   void
@@ -172,11 +175,11 @@
   }
 
-	void SetupEndPoints(const Vector3 &origin,
-											const Vector3 &termination)
-	{
-		mOrigin = origin;
-		mTermination = termination;
-		Precompute();
-	}
+  void SetupEndPoints(const Vector3 &origin,
+					  const Vector3 &termination)
+  {
+	mOrigin = origin;
+	mTermination = termination;
+	Precompute();
+  }
 											
   bool HasPosDir(const int axis) const { return mFlags & (1<<axis); }
@@ -198,15 +201,15 @@
     else
       if (mRefCount < 0)
-				mRefCount++;
+		mRefCount++;
       else {
-				cerr<<"Trying to unref already deleted ray!"<<endl;
-				exit(1);
+		cerr<<"Trying to unref already deleted ray!"<<endl;
+		exit(1);
       }
   }
 
-	static Vector3
-	GetDirection(const float a, const float b) {
-		return Vector3(sin(a), sin(b), cos(a));
-	}
+  static Vector3
+  GetDirection(const float a, const float b) {
+	return Vector3(sin(a), sin(b), cos(a));
+  }
 
 };
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 437)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 438)
@@ -236,5 +236,5 @@
 
   if (mViewSpaceBox) {
-	exporter->SetForcedMaterial(RgbColor(1,0,0));
+	exporter->SetForcedMaterial(RgbColor(1,0,1));
 	exporter->ExportBox(*mViewSpaceBox);
 	exporter->ResetForcedMaterial();
@@ -257,11 +257,13 @@
 bool
 VssPreprocessor::ExportVssTree(char *filename,
-							   VssTree *tree)
+							   VssTree *tree,
+							   const Vector3 &dir
+							   )
 {
   Exporter *exporter = Exporter::GetExporter(filename);
   exporter->SetFilled();
   exporter->ExportScene(mSceneGraph->mRoot);
-  exporter->SetWireframe();
-  bool result = exporter->ExportVssTree(*tree);
+  //  exporter->SetWireframe();
+  bool result = exporter->ExportVssTree2( *tree, dir );
   delete exporter;
   return result;
@@ -471,6 +473,9 @@
   vssTree->Construct(mVssRays, mViewSpaceBox);
   cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl;
-
-  ExportVssTree("vss-tree.x3d", vssTree);
+  
+  ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0));
+  ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(1,0,0));
+  ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1));
+  ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1));
 
   ExportVssTreeLeaves(vssTree, 10);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 436)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 438)
@@ -725,5 +725,6 @@
 
 bool
-X3dExporter::ExportVssTree(const VssTree &tree)
+X3dExporter::ExportVssTree(const VssTree &tree
+						   )
 {
   stack<VssTreeNode *> tStack;
@@ -763,5 +764,8 @@
 					
 					Vector3 direction = VssRay::GetDirection(v.x, v.y);
-					direction.Normalize();
+					if (Magnitude(direction) > Limits::Small)
+					  direction.Normalize();
+					else
+					  direction = Vector3(0, 1, 0);
 					float k = 100.0f*leaf->GetImportance();
 					// get 4 corners of the ray directions
@@ -775,7 +779,93 @@
 
   ExportMesh(mesh);
-	ExportRays(rays);
-	CLEAR_CONTAINER(rays);
+  ExportRays(rays);
+  CLEAR_CONTAINER(rays);
   delete mesh;
+  return true;
+}
+
+bool
+X3dExporter::ExportVssTree2(const VssTree &tree,
+							const Vector3 direction
+							)
+{
+  stack<VssTreeNode *> tStack;
+	
+
+  mUseForcedMaterial = true;
+
+  Vector3 dirParam;
+
+  dirParam.x = VssRay::GetDirParam(0, Normalize(direction));
+  dirParam.y = VssRay::GetDirParam(1, Normalize(direction));
+
+  float maxImportance = 0.0f;
+  tStack.push(tree.GetRoot());
+  while (!tStack.empty()) {
+	
+	VssTreeNode *node = tStack.top();
+    tStack.pop();
+	
+    if (!node->IsLeaf()) {
+      VssTreeInterior *interior = (VssTreeInterior *)node;
+	  if (interior->axis < 3) {
+		tStack.push(interior->front);
+		tStack.push(interior->back);
+	  } else {
+		if (dirParam[interior->axis-3] < interior->position)
+		  tStack.push(interior->back);
+		else
+		  tStack.push(interior->front);
+	  }
+    } else {
+	  VssTreeLeaf *leaf = (VssTreeLeaf *)node;
+	  if (tree.ValidLeaf(leaf)) {
+		float i = leaf->GetImportance();
+		if (i > maxImportance)
+		  maxImportance = i;
+	  }
+	}
+  }
+
+  tStack.push(tree.GetRoot());
+  while (!tStack.empty()) {
+
+	VssTreeNode *node = tStack.top();
+    tStack.pop();
+	
+			
+    if (!node->IsLeaf()) {
+      VssTreeInterior *interior = (VssTreeInterior *)node;
+	  if (interior->axis < 3) {
+		tStack.push(interior->front);
+		tStack.push(interior->back);
+	  } else {
+		if (dirParam[interior->axis-3] < interior->position)
+		  tStack.push(interior->back);
+		else
+		  tStack.push(interior->front);
+	  }
+    } else {
+	  VssTreeLeaf *leaf = (VssTreeLeaf *)node;
+	  if (tree.ValidLeaf(leaf)) {
+		AxisAlignedBox3 box;
+		box = tree.GetBBox(leaf);
+		Mesh *mesh = new Mesh;
+		AddBoxToMesh(box, mesh);
+		
+		// get 4 corners of the ray directions
+		
+		mForcedMaterial.mDiffuseColor.b = 1.0f;
+		mForcedMaterial.mDiffuseColor.r = leaf->GetImportance()/maxImportance;
+		mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
+		
+		ExportMesh(mesh);
+		delete mesh;
+	  }
+	}
+  }
+
+  mUseForcedMaterial = false;
+
   return true;
 }
@@ -808,10 +898,10 @@
 			{
 				float importance = 
-					vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays;
-
+				  vc->mPassingRays.mContributions / (float)vc->mPassingRays.mRays;
+				
 				mForcedMaterial.mDiffuseColor.r = importance;
 				mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r;
 				ExportViewCell(vc);
-			}  
+			}
 		} else 
 		{
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp	(revision 382)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp	(revision 438)
@@ -9,6 +9,6 @@
 bool
 VssRay::ComputeMinMaxT(const AxisAlignedBox3 &box,
-															float &tmin,
-															float &tmax) const
+					   float &tmin,
+					   float &tmax) const
 {
 	
@@ -144,13 +144,13 @@
 
 float
+VssRay::GetDirParam(const int axis, const Vector3 dir)
+{
+  return (axis == 0) ? atan2(dir.x, dir.z) : asin(dir.y);
+}
+
+float
 VssRay::GetDirParametrization(const int axis) const
 {
-	float angle;
-	Vector3 dir = GetNormalizedDir();
-	if (axis == 0) {
-		angle = atan2(dir.x, dir.z);
-	} else {
-		angle = asin(dir.y);
-	}
-	return angle;
+  Vector3 dir = GetNormalizedDir();
+  return GetDirParam(axis, dir);
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 435)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 438)
@@ -15,5 +15,5 @@
 # filename ../data/atlanta/atlanta2.x3d
 # filename ../data/soda/soda.dat
- filename ../data/soda/soda5.dat
+filename ../data/soda/soda5.dat
 }
 
@@ -25,5 +25,5 @@
 VssPreprocessor {
 	samplesPerPass  100000
-	initialSamples 200000
+	initialSamples 500000
 	vssSamples 1000000
 	vssSamplesPerPass 50000
@@ -39,9 +39,9 @@
 	minRays		100
 	minSize		0.001
- 	maxCostRatio	0.98
+ 	maxCostRatio	2.0
 	maxRayContribution 0.05
 	
 	maxTotalMemory	200
-	maxStaticMemory	50
+	maxStaticMemory	100
 
 	splitType regular
@@ -49,4 +49,7 @@
 #	splitType hybrid
 	splitUseOnlyDrivingAxis true
+
+	interleaveDirSplits	false
+    dirSplitDepth 12
 
 	numberOfEndPointDomains	10000
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 434)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 438)
@@ -88,5 +88,7 @@
   bool
   ExportVssTree(char *filename,
-				VssTree *tree);
+				VssTree *tree,
+				const Vector3 &dir
+				);
 
 
