Index: trunk/VUT/doc/SciReport/code/actualcode.tex
===================================================================
--- trunk/VUT/doc/SciReport/code/actualcode.tex	(revision 243)
+++ trunk/VUT/doc/SciReport/code/actualcode.tex	(revision 251)
Index: trunk/VUT/doc/SciReport/code/c2tex.tex
===================================================================
--- trunk/VUT/doc/SciReport/code/c2tex.tex	(revision 243)
+++ trunk/VUT/doc/SciReport/code/c2tex.tex	(revision 251)
Index: trunk/VUT/doc/SciReport/code/pseudocode.tex
===================================================================
--- trunk/VUT/doc/SciReport/code/pseudocode.tex	(revision 243)
+++ trunk/VUT/doc/SciReport/code/pseudocode.tex	(revision 251)
@@ -1,113 +1,57 @@
 \input default.mac
-\comment{}\leftline{//----\ initialisation
- }
-\normal{}\leftline{ 1:\ \ \ Stack.Push\symbol{}(\normal{}kDTree.Root\symbol{});\normal{}
-\symbol{} }
-\comment{}\leftline{ 2:\ \ \ //----\ while\ there\ are\ some\ nodes\ in\ the\ stack\ or\ the\ query\ queue
- }
-\keya{}\leftline{ 3:\ \ \ while\symbol{}\ (!\normal{}Stack.Empty\symbol{}()\ \normal{}$\symbol{}||\normal{}$\symbol{}\ !\normal{}QueryQueue.Empty\symbol{}())\ $\{$\normal{}
-\symbol{} }
-\leftline{ 4:\ \ \ \ \ \comment{}//----\ PART\ 1:\ processing\ finished\ occlusion\ queries
- }
-\symbol{}\leftline{ 5:\ \ \ \ \ \keya{}while\symbol{}\ (!\normal{}QueryQueue.Empty\symbol{}()\ \&\&\normal{}
-\symbol{} }
-\leftline{ 6:\ \ \ \ \ \ \ \ \ \ \ (\normal{}ResultAvailable\symbol{}(\normal{}QueryQueue.Front\symbol{}())\ \normal{}$\symbol{}||\normal{}$\symbol{}\ \normal{}Stack.Empty\symbol{}()))\ $\{$\normal{}
-\symbol{} }
-\leftline{ 7:\ \ \ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}ResultAvailable\symbol{}(\normal{}QueryQueue.Front\symbol{}()))\ $\{$\normal{}
-\symbol{} }
-\leftline{ 8:\ \ \ \ \ \ \ \ \ \comment{}//---\ result\ is\ not\ available\ and\ the\ stack\ is\ empty
- }
-\symbol{}\leftline{ 9:\ \ \ \ \ \ \ \ \ \comment{}//---\ check\ if\ we\ can\ do\ some\ conservative\ decision
- }
-\symbol{}\leftline{10:\ \ \ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}QueryQueue.GetLeastCostNode\symbol{}();\normal{}
-\symbol{} }
-\leftline{11:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}N.renderingCost\symbol{}\ <\ \normal{}MaxRenderCost\symbol{})\ $\{$\normal{}
-\symbol{} }
-\leftline{12:\ \ \ \ \ \ \ \ \ \ \normal{}RenderSubtree\symbol{}(\normal{}N\symbol{});\normal{}
-\symbol{} }
-\leftline{13:\ \ \ \ \ \ \ \ \ \ \normal{}QueryQueue.DequeLeastCostNode\symbol{}();\normal{}
-\symbol{} }
-\leftline{14:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ we\ do\ not\ change\ N's\ visibility\ classfication\ -
- }
-\symbol{}\leftline{15:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ N\ remains\ in\ the\ cut\ for\ the\ next\ frame
- }
-\symbol{}\leftline{16:\ \ \ \ \ \ \ \ \ $\}$\ \normal{}else
-\symbol{} }
-\leftline{17:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ wait\ for\ the\ availability\ of\ the\ result
- }
-\symbol{}\leftline{18:\ \ \ \ \ \ \ \ \ \ \keya{}while\symbol{}\ (!\normal{}QueryQueue.ResultAvailable\symbol{})\ \normal{}Wait\symbol{}();\normal{}
-\symbol{} }
-\leftline{19:\ \ \ \ \ \ \ $\}$\ \keya{}else\symbol{}\ $\{$\normal{}
-\symbol{} }
-\leftline{20:\ \ \ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}QueryQueue.Dequeue\symbol{}();\normal{}
-\symbol{} }
-\leftline{21:\ \ \ \ \ \ \ \ \ \comment{}//--\ check\ the\ result\ of\ the\ query
- }
-\symbol{}\leftline{22:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\ \normal{}N.visiblePixels\symbol{}\ \normal{}$\symbol{}>\normal{}$\symbol{}\ \normal{}VisibilityThreshold\symbol{}\ )\ \ $\{$\normal{}
-\symbol{} }
-\leftline{23:\ \ \ \ \ \ \ \ \ \ \normal{}N.visibility\symbol{}\ =\ \normal{}VISIBLE\symbol{};\normal{}
-\symbol{} }
-\leftline{24:\ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}IsLeaf\symbol{}(\normal{}N\symbol{}))\normal{}
-\symbol{} }
-\leftline{25:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Render\symbol{}(\normal{}N\symbol{});\normal{}
-\symbol{} }
-\leftline{26:\ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{}\ $\{$\normal{}
-\symbol{} }
-\leftline{27:\ \ \ \ \ \ \ \ \ \ \ \ \comment{}//--\ pull\ down
- }
-\symbol{}\leftline{28:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Stack.Push\symbol{}(\normal{}FarChild\symbol{}(\normal{}N\symbol{}));\ \normal{}Stack.Push\symbol{}(\normal{}CloseChild\symbol{}(\normal{}N\symbol{}));\normal{}
-\symbol{} }
-\leftline{29:\ \ \ \ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{30:\ \ \ \ \ \ \ \ \ $\}$\ \keya{}else\symbol{}\ $\{$\normal{}
-\symbol{} }
-\leftline{31:\ \ \ \ \ \ \ \ \ \ \normal{}N.visibility\symbol{}\ =\ \normal{}INVISIBLE\symbol{};\normal{}
-\symbol{} }
-\leftline{32:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ pull\ up
- }
-\symbol{}\leftline{33:\ \ \ \ \ \ \ \ \ \ \normal{}PullUpInvisibility\symbol{}(\normal{}N\symbol{});\normal{}
-\symbol{} }
-\leftline{34:\ \ \ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{35:\ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{36:\ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{37:\ \ \ \ \ \normal{}
-\symbol{} }
-\leftline{38:\ \ \ \ \ \comment{}//----\ PART\ 2:\ kd-tree\ traversal
- }
-\symbol{}\leftline{39:\ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}Stack.Empty\symbol{}())\ $\{$\normal{}
-\symbol{} }
-\leftline{40:\ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}Stack.Pop\symbol{}();\normal{}
-\symbol{} }
-\leftline{41:\ \ \ \ \ \ \ \normal{}N.lastVisited\symbol{}\ =\ \normal{}frameID\symbol{};\normal{}
-\symbol{} }
-\leftline{42:\ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}InsideViewFrustum\symbol{}(\normal{}N\symbol{}))\ $\{$\normal{}
-\symbol{} }
-\leftline{43:\ \ \ \ \ \ \ \ \ \comment{}//--\ skip\ testing\ of\ all\ nodes\ above\ the\ cut
- }
-\symbol{}\leftline{44:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}IsAboveTheCut\symbol{}(\normal{}N\symbol{}))\ $\{$\normal{}
-\symbol{} }
-\leftline{45:\ \ \ \ \ \ \ \ \ \ \normal{}IssueOcclustionQuery\symbol{}(\normal{}N\symbol{});\ \normal{}QueryQueue.Enqueue\symbol{}(\normal{}N\symbol{});\normal{}
-\symbol{} }
-\leftline{46:\ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}WasVisible\symbol{}(\normal{}N\symbol{})\ \normal{}$\symbol{}\&\&\normal{}$\symbol{}\ \normal{}IsLeaf\symbol{}(\normal{}N\symbol{}))\normal{}
-\symbol{} }
-\leftline{47:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Render\symbol{}(\normal{}N\symbol{});\normal{}
-\symbol{} }
-\leftline{48:\ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{}\ $\{$\normal{}
-\symbol{} }
-\leftline{49:\ \ \ \ \ \ \ \ \ \ \ \ \comment{}//--\ go\ down\ the\ kD-tree
- }
-\symbol{}\leftline{50:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Stack.Push\symbol{}(\normal{}FarChild\symbol{}(\normal{}N\symbol{}));\ \normal{}Stack.Push\symbol{}(\normal{}CloseChild\symbol{}(\normal{}N\symbol{}));\ \normal{}
-\symbol{} }
-\leftline{51:\ \ \ \ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{52:\ \ \ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{53:\ \ \ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{54:\ \ \ \ \ $\}$\normal{}
-\symbol{} }
-\leftline{55:\ \ \ $\}$\normal{}
-\symbol{} }
+\comment{}\leftline{//----\ initialisation }
+\normal{}\leftline{ 1:\ \ \ Stack.Push\symbol{}(\normal{}kDTree.Root\symbol{}); }
+\comment{}\leftline{ 2:\ \ \ //----\ while\ there\ are\ some\ nodes\ in\ the\ stack\ or\ the\ query\ queue }
+\keya{}\leftline{ 3:\ \ \ while\symbol{}\ (!\normal{}Stack.Empty\symbol{}()\ \normal{}$\symbol{}||\normal{}$\symbol{}\ !\normal{}QueryQueue.Empty\symbol{}())\ $\{$ }
+\leftline{ 4:\ \ \ \ \ \comment{}//----\ PART\ 1:\ processing\ finished\ occlusion\ queries }
+\symbol{}\leftline{ 5:\ \ \ \ \ \keya{}while\symbol{}\ (!\normal{}QueryQueue.Empty\symbol{}()\ \&\& }
+\leftline{ 6:\ \ \ \ \ \ \ \ \ \ \ (\normal{}ResultAvailable\symbol{}(\normal{}QueryQueue.Front\symbol{}())\ \normal{}$\symbol{}||\normal{}$\symbol{}\ \normal{}Stack.Empty\symbol{}()))\ $\{$ }
+\leftline{ 7:\ \ \ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}ResultAvailable\symbol{}(\normal{}QueryQueue.Front\symbol{}()))\ $\{$ }
+\leftline{ 8:\ \ \ \ \ \ \ \ \ \comment{}//---\ result\ is\ not\ available\ and\ the\ stack\ is\ empty }
+\symbol{}\leftline{ 9:\ \ \ \ \ \ \ \ \ \comment{}//---\ check\ if\ we\ can\ do\ some\ conservative\ decision }
+\symbol{}\leftline{10:\ \ \ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}QueryQueue.GetLeastCostNode\symbol{}(); }
+\leftline{11:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}N.renderingCost\symbol{}\ <\ \normal{}MaxRenderCost\symbol{})\ $\{$ }
+\leftline{12:\ \ \ \ \ \ \ \ \ \ \normal{}RenderSubtree\symbol{}(\normal{}N\symbol{}); }
+\leftline{13:\ \ \ \ \ \ \ \ \ \ \normal{}QueryQueue.DequeLeastCostNode\symbol{}(); }
+\leftline{14:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ we\ do\ not\ change\ N's\ visibility\ classfication\ - }
+\symbol{}\leftline{15:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ N\ remains\ in\ the\ cut\ for\ the\ next\ frame }
+\symbol{}\leftline{16:\ \ \ \ \ \ \ \ \ $\}$\ \keya{}else\symbol{} }
+\leftline{17:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ wait\ for\ the\ availability\ of\ the\ result }
+\symbol{}\leftline{18:\ \ \ \ \ \ \ \ \ \ \keya{}while\symbol{}\ (!\normal{}QueryQueue.ResultAvailable\symbol{})\ \normal{}Wait\symbol{}(); }
+\leftline{19:\ \ \ \ \ \ \ $\}$\ \keya{}else\symbol{}\ $\{$ }
+\leftline{20:\ \ \ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}QueryQueue.Dequeue\symbol{}(); }
+\leftline{21:\ \ \ \ \ \ \ \ \ \comment{}//--\ check\ the\ result\ of\ the\ query }
+\symbol{}\leftline{22:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\ \normal{}N.visiblePixels\symbol{}\ \normal{}$\symbol{}>\normal{}$\symbol{}\ \normal{}VisibilityThreshold\symbol{}\ )\ \ $\{$ }
+\leftline{23:\ \ \ \ \ \ \ \ \ \ \normal{}N.visibility\symbol{}\ =\ \normal{}VISIBLE\symbol{}; }
+\leftline{24:\ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}IsLeaf\symbol{}(\normal{}N\symbol{})) }
+\leftline{25:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Render\symbol{}(\normal{}N\symbol{}); }
+\leftline{26:\ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{}\ $\{$ }
+\leftline{27:\ \ \ \ \ \ \ \ \ \ \ \ \comment{}//--\ pull\ down }
+\symbol{}\leftline{28:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Stack.Push\symbol{}(\normal{}FarChild\symbol{}(\normal{}N\symbol{}));\ \normal{}Stack.Push\symbol{}(\normal{}CloseChild\symbol{}(\normal{}N\symbol{})); }
+\leftline{29:\ \ \ \ \ \ \ \ \ \ $\}$ }
+\leftline{30:\ \ \ \ \ \ \ \ \ $\}$\ \keya{}else\symbol{}\ $\{$ }
+\leftline{31:\ \ \ \ \ \ \ \ \ \ \normal{}N.visibility\symbol{}\ =\ \normal{}INVISIBLE\symbol{}; }
+\leftline{32:\ \ \ \ \ \ \ \ \ \ \comment{}//--\ pull\ up }
+\symbol{}\leftline{33:\ \ \ \ \ \ \ \ \ \ \normal{}PullUpInvisibility\symbol{}(\normal{}N\symbol{}); }
+\leftline{34:\ \ \ \ \ \ \ \ \ $\}$ }
+\leftline{35:\ \ \ \ \ \ \ $\}$ }
+\leftline{36:\ \ \ \ \ $\}$ }
+\leftline{37:\ \ \ \ \  }
+\leftline{38:\ \ \ \ \ \comment{}//----\ PART\ 2:\ kd-tree\ traversal }
+\symbol{}\leftline{39:\ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}Stack.Empty\symbol{}())\ $\{$ }
+\leftline{40:\ \ \ \ \ \ \ \normal{}N\symbol{}\ =\ \normal{}Stack.Pop\symbol{}(); }
+\leftline{41:\ \ \ \ \ \ \ \normal{}N.lastVisited\symbol{}\ =\ \normal{}frameID\symbol{}; }
+\leftline{42:\ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}InsideViewFrustum\symbol{}(\normal{}N\symbol{}))\ $\{$ }
+\leftline{43:\ \ \ \ \ \ \ \ \ \comment{}//--\ skip\ testing\ of\ all\ nodes\ above\ the\ cut }
+\symbol{}\leftline{44:\ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}IsAboveTheCut\symbol{}(\normal{}N\symbol{}))\ $\{$ }
+\leftline{45:\ \ \ \ \ \ \ \ \ \ \normal{}IssueOcclustionQuery\symbol{}(\normal{}N\symbol{});\ \normal{}QueryQueue.Enqueue\symbol{}(\normal{}N\symbol{}); }
+\leftline{46:\ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}WasVisible\symbol{}(\normal{}N\symbol{})\ \normal{}$\symbol{}\&\&\normal{}$\symbol{}\ \normal{}IsLeaf\symbol{}(\normal{}N\symbol{})) }
+\leftline{47:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Render\symbol{}(\normal{}N\symbol{}); }
+\leftline{48:\ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{}\ $\{$ }
+\leftline{49:\ \ \ \ \ \ \ \ \ \ \ \ \comment{}//--\ go\ down\ the\ kD-tree }
+\symbol{}\leftline{50:\ \ \ \ \ \ \ \ \ \ \ \ \normal{}Stack.Push\symbol{}(\normal{}FarChild\symbol{}(\normal{}N\symbol{}));\ \normal{}Stack.Push\symbol{}(\normal{}CloseChild\symbol{}(\normal{}N\symbol{}));\  }
+\leftline{51:\ \ \ \ \ \ \ \ \ \ $\}$ }
+\leftline{52:\ \ \ \ \ \ \ \ \ $\}$ }
+\leftline{53:\ \ \ \ \ \ \ $\}$ }
+\leftline{54:\ \ \ \ \ $\}$ }
+\leftline{55:\ \ \ $\}$ }
Index: trunk/VUT/doc/SciReport/code/pseudocode_batching.cpp
===================================================================
--- trunk/VUT/doc/SciReport/code/pseudocode_batching.cpp	(revision 251)
+++ trunk/VUT/doc/SciReport/code/pseudocode_batching.cpp	(revision 251)
@@ -0,0 +1,60 @@
+Algorithm: Traversal of the kD-tree applying batching of multiple queries
+TraversalStack.Push(kDTree.Root);
+while ( not TraversalStack.Empty() or
+        not QueryQueue.Empty() ) {
+  //---- PART 1: processing finished occlusion queries
+  while ( not QueryQueue.Empty() and
+	  (ResultAvailable(QueryQueue.Front()) or
+	   TraversalStack.Empty()) ) {
+    N = QueryQueue.Dequeue();
+    // wait if result not available
+    visiblePixels = GetOcclussionQueryResult(N);
+    if ( visiblePixels > VisibilityThreshold ) {
+      PullUpVisibility(N);
+      TraverseNode(N);
+    }
+  }
+  //---- PART 2: kd-tree traversal
+  if ( not TraversalStack.Empty() ) {
+    N = TraversalStack.Pop();
+    if ( InsideViewFrustum(N) ) {
+      // identify previously visible nodes
+      wasVisible = N.visible && (N.lastVisited == frameID -1);
+      // identify previously opened nodes
+      opened = wasVisible && !IsLeaf(N);
+      // reset node's visibility classification
+      N.visible = false;
+      // update node's visited flag
+      N.lastVisited = frameID;
+      // skip testing all previously opened nodes
+      if ( !opened ) {
+		  // add to the pending queue instead of immediate query
+		  if (PendingQueue.size() < n)
+			  PendingQueue.Enqueue(N);
+		  else
+		  {
+			  IssueMultipleOcclusionQueries(PendingQueue);
+			  AddToQueryQueue(PendingQueue, QueryQueue);
+			  PendingQueue.clear();
+		  }
+      }
+      // traverse a node unless it was invisible
+      if ( wasVisible )
+	TraverseNode(N);
+    }
+  }
+
+  // add rest to query queue
+  IssueMultipleOcclusionQueries(PendingQueue);
+  AddToQueryQueue(PendingQueue, QueryQueue);
+  PendingQueue.clear();
+}
+TraverseNode(N) {
+  if ( IsLeaf(N) )
+    Render(N);
+  else
+    TraversalStack.PushChildren(N);
+}
+PullUpVisibility(N) {
+  while (!N.visible) { N.visible = true; N = N.parent; }
+}
Index: trunk/VUT/doc/SciReport/code/pseudocode2.tex
===================================================================
--- trunk/VUT/doc/SciReport/code/pseudocode2.tex	(revision 243)
+++ trunk/VUT/doc/SciReport/code/pseudocode2.tex	(revision 251)
