Index: trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 502)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 504)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.0) on: ?t 5. I 09:42:49 2006
+# Generated by qmake (2.00a) (Qt 4.1.0) on: pá 6. I 11:25:45 2006
 # Project:  preprocessor.pro
 # Template: app
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 492)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 504)
@@ -6,4 +6,5 @@
 #include "KdTree.h"
 #include "ViewCell.h"
+#include "Frustum.h"
 
 int KdNode::mailID = 1;
@@ -963,2 +964,13 @@
   return NULL;
 }
+
+
+int
+CastFrustum(
+			Frustum &frustum
+			)
+{
+  
+
+  return 0;
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h	(revision 487)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h	(revision 504)
@@ -24,6 +24,6 @@
 
   Plane3(const Vector3 &normal,
-	 const Vector3 &point
-	 ):mNormal(normal)
+		 const Vector3 &point
+		 ):mNormal(normal)
   {
     mD = -DotProd(normal, point);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.h	(revision 504)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.h	(revision 504)
@@ -0,0 +1,46 @@
+#ifndef __FRUSTUM_H
+#define __FRUSTUM_H
+
+#include <vector>
+using namespace std;
+
+class KdNode;
+class Intersectable;
+#include "AxisAlignedBox3.h"
+
+class Frustum {
+  
+public:			
+  enum {STORE_KD_NODES=1, STORE_OBJECTS=2};
+  int mFlags;
+  
+  // list of nodes intersected by the frustum
+  vector<KdNode *> mKdNodes;
+  // lits of objects intersected by the frum
+  vector<Intersectable *> mObjects;
+
+
+  // spatial box
+  AxisAlignedBox3 mBox;
+  // directional box (it is actually a 2D box - only x and y ranges are valid)
+  // directional parametrization according to VssRay::GetDirParametrization
+  AxisAlignedBox3 mDirBox;
+
+  vector<Plane3> mPlanes;
+  
+  Frustum():mFlags(STORE_KD_NODES+STORE_OBJECTS)
+  {
+  }
+  
+  void Construct(const  AxisAlignedBox3 &box,
+				 const  AxisAlignedBox3 &dBox);
+  
+
+  int
+  ComputeIntersection(const  AxisAlignedBox3 &box);
+
+  
+};
+
+
+#endif
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 503)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 504)
@@ -548,6 +548,6 @@
 		//Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
 		Vector3 viewpoint; 
-		//		mViewCellsManager->GetViewPoint(viewpoint);
-		viewpoint = GetViewpoint(mViewSpaceBox);
+		mViewCellsManager->GetViewPoint(viewpoint);
+		//		viewpoint = GetViewpoint(mViewSpaceBox);
 		Vector3 direction = InitialGetDirection(viewpoint, mViewSpaceBox);
 		
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h	(revision 469)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h	(revision 504)
@@ -16,4 +16,5 @@
 class Intersectable;
 //class KdViewCell;
+class Frustum;
 
 // --------------------------------------------------------------
@@ -282,8 +283,14 @@
   int
   CastRay(
-	  Ray &ray
-	  );
-
-
+		  Ray &ray
+		  );
+  
+
+  int
+  CastFrustum(
+			  Frustum &frustum
+			  );
+  
+  
   /** Casts line segment into tree.
 	  @returns intersected view cells.
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 502)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 504)
@@ -13,7 +13,7 @@
 #;../data/vienna/vienna-plane.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
-# filename ../data/atlanta/atlanta2.x3d
+filename ../data/atlanta/atlanta2.x3d
 # filename ../data/soda/soda.dat
-filename ../data/soda/soda5.dat
+# filename ../data/soda/soda5.dat
 }
 
@@ -69,5 +69,5 @@
 RssPreprocessor {
 	samplesPerPass  100000
-	initialSamples 500000
+	initialSamples 1000000
 	vssSamples 10000000
 	vssSamplesPerPass 500000
@@ -169,6 +169,6 @@
 	#type kdTree
 	#type vspKdTree
-	type bspTree
-	#type vspBspTree
+	# type bspTree
+	type vspBspTree
 	
 	#type sceneDependent
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 502)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 504)
@@ -173,4 +173,6 @@
   void mouseMoveEvent(QMouseEvent *);
 
+  void keyPressEvent ( QKeyEvent * e ) ;
+  
   float
   RenderErrors();
Index: trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 492)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 504)
@@ -30,5 +30,5 @@
 # Input
 HEADERS += Halton.h VssRay.h VssPreprocessor.h RssTree.h GlRenderer.h \
-PreprocessorThread.h Preprocessor.h
+PreprocessorThread.h Preprocessor.h Frustum.h
 
 
@@ -43,4 +43,4 @@
 RenderSimulator.cpp VspKdTree.cpp RayInfo.cpp RssTree.cpp RssPreprocessor.cpp \
 ViewCellsManager.cpp VspBspTree.cpp GlRenderer.cpp \
-PreprocessorThread.cpp Renderer.cpp
+PreprocessorThread.cpp Renderer.cpp Frustum.cpp
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.cpp	(revision 504)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Frustum.cpp	(revision 504)
@@ -0,0 +1,63 @@
+#include "Frustum.h"
+#include "VssRay.h"
+
+
+
+
+void
+Frustum::Construct(const  AxisAlignedBox3 &box,
+				   const  AxisAlignedBox3 &dBox)
+{
+  // the frustum is defined by set of negative halfspace described by mPlanes
+  
+  // construct
+  Vector3 center = box.Center();
+  Vector3 dCenter = dBox.Center();
+
+  // "back plane"
+  mPlanes.push_back(Plane3(-VssRay::GetDirection(dCenter.x, dCenter.y), center));
+
+  Vector3 directions[4];
+  directions[0] = VssRay::GetDirection(dBox.Min().x, dBox.Min().y);
+  directions[1] = VssRay::GetDirection(dBox.Max().x, dBox.Min().y);
+  directions[2] = VssRay::GetDirection(dBox.Max().x, dBox.Max().y);
+  directions[3] = VssRay::GetDirection(dBox.Min().x, dBox.Max().y);
+  
+  // side planes
+  mPlanes.push_back(Plane3(CrossProd(directions[0], directions[1]), center));
+  mPlanes.push_back(Plane3(CrossProd(directions[1], directions[2]), center));
+  mPlanes.push_back(Plane3(CrossProd(directions[2], directions[3]), center));
+  mPlanes.push_back(Plane3(CrossProd(directions[3], directions[0]), center));
+
+
+  // now make sure all planes contain the spatial box
+  int i, j;
+  for (i=0; i < mPlanes.size(); i++) {
+	for (j=0; j < 8; j++) {
+	  float dist = mPlanes[i].Distance(box.GetVertex(j));
+	  if (dist > 0)
+		mPlanes[i].mD -= dist;
+	}
+  }
+}
+
+// conservative frustum box intersection
+// returns
+// 0 - box intersects the frustum
+// -1 - box intersects the frustum and is fully inside
+// 1 - box does not intersect the frustum
+
+int
+Frustum::ComputeIntersection(const  AxisAlignedBox3 &box)
+{
+  int i;
+  int result = -1;
+  for (i=0; i < mPlanes.size(); i++) {
+	int side = box.Side(mPlanes[i]);
+	if (side == 1)
+	  return 1;
+	if (side > result)
+	  result = side;
+  }
+  return result;
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 502)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 504)
@@ -83,7 +83,7 @@
   for (i=0; i < mesh->mFaces.size(); i++) {
 	if (mWireFrame)
+	  glBegin(GL_LINE_LOOP);
+	else
 	  glBegin(GL_POLYGON);
-	else
-	  glBegin(GL_LINE_LOOP);
 
 	Face *face = mesh->mFaces[i];
@@ -501,5 +501,5 @@
 	float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05;
 	Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x,
-											1,
+											-1,
 											mViewDirection.y);
 	
@@ -508,5 +508,5 @@
 	
 	glLoadIdentity();
-	gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z,
+	gluLookAt(pos.x, pos.y, pos.z,
 			  target.x, target.y, target.z,
 			  up.x, up.y, up.z);
@@ -514,2 +514,17 @@
 
 }
+
+void
+GlRendererWidget::keyPressEvent ( QKeyEvent * e )
+{
+  switch (e->key()) {
+  case Qt::Key_T:
+	mTopView = !mTopView;
+	updateGL();
+	break;
+  default:
+	e->ignore();
+	break;
+  }
+  
+}
