Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.sh	(revision 1919)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.sh	(revision 1919)
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+# add bin to path
+export PATH=../bin:$PATH
+
+#TARGET=debug
+TARGET=release
+
+PROGRAM=../bin/$TARGET/Preprocessor.exe
+
+SCENE=arena
+LOG_PREFIX=../scripts/tests/gi/$SCENE-35M-gi
+ENVIRONMENT=$SCENE.env
+
+echo "starting $TARGET mode for $SCENE scene"
+
+##################################################################################
+
+ METHOD=gradient-full
+ echo "$SCENE $METHOD"
+
+  $PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+  -hierarchy_construction_multilevel=false \
+  -bvh_use_sah=false \
+  -vsp_use_cost_heuristics=true \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+
+############################################################################
+
+NODES=10000
+USE_HEUR=true
+
+  METHOD=sequential-$NODES-$USE_HEUR
+  echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+ -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+ -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+ -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+ -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+ -hierarchy_construction_type=0 \
+ -vsp_use_cost_heuristics=$USE_HEUR \
+ -bvh_term_max_leaves=$NODES
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+
+############################################################################
+
+NODES=50000
+USE_HEUR=true
+
+  METHOD=sequential-$NODES-$USE_HEUR
+  echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+ -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+ -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+ -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+ -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+ -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+ -hierarchy_construction_type=0 \
+ -vsp_use_cost_heuristics=$USE_HEUR \
+ -bvh_term_max_leaves=$NODES
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+##################################################################################
+
+ METHOD=gradient-full-corr
+ echo "$SCENE $METHOD"
+
+  $PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+  -hierarchy_construction_multilevel=false \
+  -bvh_use_sah=false \
+  -vsp_use_cost_heuristics=true \
+  -hierarchy_construction_min_avg_raycontri=0.01 \
+  -hierarchy_construction_max_avg_raycontri=0.5 \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped_gi.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped_gi.env	(revision 1919)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped_gi.env	(revision 1919)
@@ -0,0 +1,345 @@
+##############################################################################
+# ERS default configuration file
+# Jiri Bittner 2003
+#############################################################################
+
+Scene {
+
+#	filename glasgow1.x3d
+#	filename vienna.x3d
+#	filename ../data/vienna/vienna-simple.x3d
+#	filename ../data/vienna/vienna-buildings.x3d
+#	filename ../data/vienna/vienna-roofs.x3d
+#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+#	filename ../data/vienna/vienna-buildings_vienna-roofs_vienna-roads_vienna-plane_cropped.obj
+	filename ../data/vienna/vienna_cropped.obj
+#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d;../data/vienna/vienna-plane.x3d
+#	filename ../data/vienna/viewcells-25-sel.x3d
+#	filename ../data/atlanta/atlanta2.x3d
+#	filename ../data/soda/soda.dat
+#	filename ../data/soda/soda5.dat
+#	filename ../data/artificial/cube_test.x3d
+#	filename ../data/grandcanyon1_RotXmin90.obj
+#	filename ../data/CityModel.obj
+#	filename ../data/arena/arena-high-lods.obj
+}
+
+
+Preprocessor {
+	samplesFilename rays.out
+#	useGlRenderer true
+	useGlRenderer false
+	type vss
+	detectEmptyViewSpace true
+	loadMeshes false
+	# internal raycaster
+	#rayCastMethod 0
+	# intel raycaster
+	rayCastMethod 1
+	exportVisibility false
+	loadKdTree false
+	exportKdTree false 
+	applyVisibilityFilter false
+	applyVisibilitySpatialFilter false
+
+	histogram {
+		intervals 20
+	}
+}
+
+
+VssPreprocessor {
+	initialSamples 0
+	vssSamples 0
+	useImportanceSampling true
+	loadInitialSamples  false
+	storeInitialSamples false
+}
+
+
+VssTree {
+	useRss    false
+	epsilon		1e-6
+	
+	maxDepth 	2
+	minPvs		30
+	minRays		800
+	minSize		0.001
+ 	maxCostRatio	1.5
+	maxRayContribution 0.5
+		
+	maxTotalMemory	50
+	maxStaticMemory	20
+	
+	splitType regular
+	#	splitType heuristic
+	#	splitType hybrid
+	splitUseOnlyDrivingAxis true
+	
+	interleaveDirSplits	true
+    	dirSplitDepth 0
+	
+	numberOfEndPointDomains	10000
+	ct_div_ci	0.0
+	randomize	false
+	
+	refDirBoxMaxSize	0.1
+}
+
+
+Limits {
+       threshold	1e-6
+       small		1e-6
+       infinity		1e9
+}
+
+
+Unigraphics {
+	meshGrouping 1
+}
+
+
+KdTree {
+	sahUseFaces true
+
+	Termination {
+		minCost 0
+		maxDepth 20
+		
+		maxCostRatio 1.5
+		ct_div_ci 0.5
+	}
+
+#	splitMethod spatialMedian
+	splitMethod SAH
+	splitBorder 0.01
+}
+
+MeshKdTree {
+	Termination {
+		minCost 1
+		maxDepth 18
+		maxCostRatio 0.9
+		ct_div_ci 0.5
+	}
+
+#	splitMethod spatialMedian
+	splitMethod SAH
+	splitBorder 0.01
+}
+
+
+ViewCells {
+	
+	# samples used for view cell construction 
+	# (after the sampling used for the hierarchy)
+	Construction {
+		samples 0
+		samplesPerPass 1000000
+	}
+
+	# number of active view cells
+	active 25000
+	maxStaticMemory	40
+
+	exportToFile true
+	loadFromFile false
+
+	exportPvs false
+
+	# type of view cells
+	type vspOspTree
+	
+	compressObjects true
+
+	#percentage of total visible objects where pvs is considered invalid
+	maxPvsRatio 1.0
+		
+	processOnlyValidViewCells false
+
+	#samplingType object_directional
+	#samplingType directional
+	samplingType box
+	#samplingType reverse_object
+	#samplingType object
+
+	PostProcess {
+		# how much samples are used for post processing
+		samples 0
+		maxMergesPerPass 5000
+		useRaysForMerge false
+		refine false
+		compress true
+		merge false
+	}
+
+	Visualization {
+		# how much samples we use for visualization
+		samples 200
+		exportRays true
+		exportGeometry true
+		exportMergedViewCells false
+		useClipPlane true
+		clipPlaneAxis 1
+		clipPlanePos 0.3
+		maxOutput 0
+	}
+
+	showVisualization true
+	#showVisualization false
+	evaluateViewCells true
+	
+	Evaluation {
+		samples         160000000
+		samplesForStats 80000000
+
+		#samples         60000000
+		#samplesForStats 20000000
+
+		samplesPerPass  1000000
+		
+		stepSize	500
+
+		#samplingType object_directional
+		#samplingType reverse_object
+		#samplingType object
+		samplingType box
+
+		histogram true
+		histoStepSize 200
+		histoMem 60
+
+		statsPrefix ../scripts/viewCells
+	}
+}
+
+
+################################
+#
+# View space partitioning kd tree
+#
+
+VspTree {
+	Construction {
+		renderCostDecreaseWeight 0.999
+	}
+
+	Termination {
+		minPvs 0
+		maxViewCells 500000
+	}
+
+	#useCostHeuristics true
+	#splitUseOnlyDrivingAxis true
+
+	useCostHeuristics false
+	splitUseOnlyDrivingAxis false
+
+	# maximum number of tests per node
+	maxTests 500000
+}
+
+
+##########################
+#
+# The bounding volume hierarchy
+#
+
+BvHierarchy {
+
+	Construction {		
+		renderCostDecreaseWeight 0.999
+	}
+
+	Termination {
+		maxLeaves 50000000
+	}
+
+	minRaysForVisibility 15
+
+	# use only surface area heuristic	
+	useCostHeuristics true
+	#useCostHeuristics false
+	useSah true
+
+	#splitUseOnlyDrivingAxis true
+	splitUseOnlyDrivingAxis false
+
+	maxTests 500000
+}
+
+
+###############################################################
+#
+# Manages the construction of view space and object space partition
+#
+
+Hierarchy {
+	# the type of object space partition: view space is always vsp (=kd) partition
+	type bvh
+	
+	Construction {
+
+		samples 6000000
+
+		# type 0 = sequential computation, 1 = interleaved, 2 = gradient
+		type 1
+
+		# if the object space should be subdivided first (if false, the view space is subdivided first)
+		startWithObjectSpace true
+
+		###############################
+		# only for interleaved method
+
+		# if dirty split candidates are reevaluated 
+		repairQueue true
+
+		# recompute split plane when "repairing" a candidate
+		recomputeSplitPlaneOnRepair true
+
+		###################################################
+
+		# iterative construction of vs partititon and os partition
+		useMultiLevel false
+
+		# number of iteration steps
+		levels 3
+
+		# minimal steps of same type: for interleaved, this is only valid for the first few splits
+		minStepsOfSameType 100
+		maxStepsOfSameType 900
+
+		maxAvgRayContri 9999
+		minAvgRayContri 9900
+
+		maxRepairs 2000
+	}
+
+	Termination {
+		# maximal number of leaves
+		maxLeaves 300000
+		# maximal memory in MB
+		#maxMemory 20
+		maxMemory 35
+		# minimum ratio of global cost decrease
+		minGlobalCostRatio -1
+	}
+}
+
+
+VspBspTree {
+	Construction {
+		samples 100000
+	}
+
+	Termination {
+		minPvs 0
+		maxViewCells 1000
+	}
+
+	useCostHeuristics true
+	splitUseOnlyDrivingAxis false
+
+	# maximum number of tests per node
+	maxTests 100000
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped.sh	(revision 1919)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna_cropped.sh	(revision 1919)
@@ -0,0 +1,102 @@
+#!/bin/sh
+
+# add bin to path
+export PATH=../bin:$PATH
+
+#TARGET=debug
+TARGET=release
+
+PROGRAM=../bin/$TARGET/Preprocessor.exe
+
+SCENE=vienna_cropped_gi
+LOG_PREFIX=../scripts/tests/gi/$SCENE-35MB
+ENVIRONMENT=$SCENE.env
+
+echo "starting $TARGET mode for $SCENE scene"
+
+############################################################################
+
+ METHOD=gradient-full
+ echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+  -hierarchy_construction_multilevel=false \
+  -bvh_use_sah=false \
+  -vsp_use_cost_heuristics=true \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+#######################################################
+
+NODES=50000
+USE_HEUR=true
+
+  METHOD=sequential-$NODES-$USE_HEUR
+  echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+ -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+ -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+ -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+ -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+ -hierarchy_construction_type=0 \
+ -vsp_use_cost_heuristics=$USE_HEUR \
+ -bvh_term_max_leaves=$NODES
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+
+#######################################################
+
+NODES=10000
+USE_HEUR=true
+
+  METHOD=sequential-$NODES-$USE_HEUR
+  echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+ -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+ -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+ -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+ -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+ -hierarchy_construction_type=0 \
+ -vsp_use_cost_heuristics=$USE_HEUR \
+ -bvh_term_max_leaves=$NODES
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+#######################################################
+
+ METHOD=gradient-full-corr
+ echo "$SCENE $METHOD"
+
+$PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+  -hierarchy_construction_multilevel=false \
+  -bvh_use_sah=false \
+  -vsp_use_cost_heuristics=true \
+  -hierarchy_construction_min_avg_raycontri=0.01 \
+  -hierarchy_construction_max_avg_raycontri=0.5 \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.env	(revision 1919)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/arena.env	(revision 1919)
@@ -0,0 +1,339 @@
+##############################################################################
+# ERS default configuration file
+# Jiri Bittner 2003
+#############################################################################
+
+Scene {
+
+#	filename glasgow1.x3d
+#	filename vienna.x3d
+#	filename ../data/vienna/vienna-simple.x3d
+#	filename ../data/vienna/vienna-buildings.x3d
+#	filename ../data/vienna/vienna-roofs.x3d
+#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+#	filename ../data/vienna/vienna-buildings_vienna-roofs_vienna-roads_vienna-plane_cropped.obj
+	filename ../data/vienna/vienna_cropped.obj
+#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d;../data/vienna/vienna-plane.x3d
+#	filename ../data/vienna/viewcells-25-sel.x3d
+#	filename ../data/atlanta/atlanta2.x3d
+#	filename ../data/soda/soda.dat
+#	filename ../data/soda/soda5.dat
+#	filename ../data/artificial/cube_test.x3d
+#	filename ../data/grandcanyon1_RotXmin90.obj
+#	filename ../data/CityModel.obj
+	filename ../data/arena/arena-high-lods.obj
+}
+
+
+Preprocessor {
+	samplesFilename rays.out
+#	useGlRenderer true
+	useGlRenderer false
+	type vss
+	detectEmptyViewSpace true
+	loadMeshes false
+	# internal raycaster
+	rayCastMethod 0
+	# intel raycaster
+	rayCastMethod 1
+	exportVisibility false
+	loadKdTree false
+	exportKdTree false 
+	applyVisibilityFilter false
+	applyVisibilitySpatialFilter false
+
+	histogram {
+		intervals 20
+	}
+}
+
+
+VssPreprocessor {
+	initialSamples 0
+	vssSamples 0
+	useImportanceSampling true
+	loadInitialSamples  false
+	storeInitialSamples false
+}
+
+
+VssTree {
+	useRss    false
+	epsilon		1e-6
+	
+	maxDepth 	2
+	minPvs		30
+	minRays		800
+	minSize		0.001
+ 	maxCostRatio	1.5
+	maxRayContribution 0.5
+		
+	maxTotalMemory	50
+	maxStaticMemory	20
+	
+	splitType regular
+	#	splitType heuristic
+	#	splitType hybrid
+	splitUseOnlyDrivingAxis true
+	
+	interleaveDirSplits	true
+    dirSplitDepth 0
+	
+	numberOfEndPointDomains	10000
+	ct_div_ci	0.0
+	randomize	false
+	
+	refDirBoxMaxSize	0.1
+}
+
+
+Limits {
+       threshold	1e-6
+       small		1e-6
+       infinity		1e9
+}
+
+
+Unigraphics {
+	meshGrouping 1
+}
+
+
+KdTree {
+	sahUseFaces true
+
+	Termination {
+		minCost 0
+		maxDepth 20
+		
+		maxCostRatio 1.5
+		ct_div_ci 0.5
+	}
+
+#	splitMethod spatialMedian
+	splitMethod SAH
+	splitBorder 0.01
+}
+
+MeshKdTree {
+	Termination {
+		minCost 1
+		maxDepth 18
+		maxCostRatio 0.9
+		ct_div_ci 0.5
+	}
+
+#	splitMethod spatialMedian
+	splitMethod SAH
+	splitBorder 0.01
+}
+
+
+ViewCells {
+	
+	# samples used for view cell construction 
+	# (after the sampling used for the hierarchy)
+	Construction {
+		samples 0
+		samplesPerPass 1000000
+	}
+
+	# number of active view cells
+	active 25000
+	maxStaticMemory	40
+
+	exportToFile true
+	loadFromFile false
+
+	exportPvs false
+
+	# type of view cells
+	type vspOspTree
+	
+	#percentage of total visible objects where pvs is considered invalid
+	maxPvsRatio 1.0
+		
+	processOnlyValidViewCells false
+
+	#samplingType object_directional
+	#samplingType directional
+	samplingType box
+	#samplingType reverse_object
+	#samplingType object
+
+	compressObjects true
+
+	PostProcess {
+		# how much samples are used for post processing
+		samples 0
+		maxMergesPerPass 5000
+		useRaysForMerge false
+		refine false
+		compress true
+		merge false
+	}
+
+	Visualization {
+		# how much samples we use for visualization
+		samples 200
+		exportRays true
+		exportGeometry true
+		exportMergedViewCells false
+		useClipPlane true
+		clipPlaneAxis 1
+		clipPlanePos 0.3
+		maxOutput 0
+	}
+
+	showVisualization true
+	evaluateViewCells true
+	
+	Evaluation {
+		samples         160000000
+		samplesForStats  80000000
+		samplesPerPass    1000000
+
+		stepSize	500
+
+		#samplingType object_directional
+		#samplingType reverse_object
+		#samplingType object
+		samplingType box
+
+		histogram true
+		histoStepSize 200
+		histoMem 60
+
+		statsPrefix ../scripts/viewCells
+	}
+}
+
+
+################################
+#
+# View space partitioning kd tree
+#
+
+VspTree {
+	Construction {
+		renderCostDecreaseWeight 0.999
+	}
+
+	Termination {
+		minPvs 0
+		maxViewCells 500000
+	}
+
+	#useCostHeuristics true
+	#splitUseOnlyDrivingAxis true
+
+	useCostHeuristics false
+	splitUseOnlyDrivingAxis false
+
+	# maximum number of tests per node
+	maxTests 500000
+}
+
+
+##########################
+#
+# The bounding volume hierarchy
+#
+
+BvHierarchy {
+
+	Construction {		
+		renderCostDecreaseWeight 0.999
+	}
+
+	Termination {
+		maxLeaves 50000000
+	}
+
+	minRaysForVisibility 15
+
+	# use only surface area heuristic	
+	useCostHeuristics true
+	#useCostHeuristics false
+	useSah true
+
+	#splitUseOnlyDrivingAxis true
+	splitUseOnlyDrivingAxis false
+
+	maxTests 500000
+}
+
+
+###############################################################
+#
+# Manages the construction of view space and object space partition
+#
+
+Hierarchy {
+	# the type of object space partition: view space is always vsp (=kd) partition
+	type bvh
+	
+	Construction {
+		
+		samples 6000000
+
+		# type 0 = sequential computation, 1 = interleaved, 2 = gradient
+		type 1
+
+		# if the object space should be subdivided first (if false, the view space is subdivided first)
+		startWithObjectSpace true
+
+		###############################
+		# only for interleaved method
+
+		# if dirty split candidates are reevaluated 
+		repairQueue true
+
+		# recompute split plane when "repairing" a candidate
+		recomputeSplitPlaneOnRepair true
+
+		###################################################
+
+		# iterative construction of vs partititon and os partition
+		useMultiLevel false
+
+		# number of iteration steps
+		levels 3
+
+		# minimal steps of same type: for interleaved, this is only valid for the first few splits
+		minStepsOfSameType 100
+		maxStepsOfSameType 900
+
+		maxRepairs 2000
+
+		maxAvgRayContri 9999
+		minAvgRayContri 9990
+	}
+
+	Termination {
+		# maximal number of leaves
+		maxLeaves 300000
+		# maximal memory in MB
+		maxMemory 35
+		# minimum ratio of global cost decrease
+		minGlobalCostRatio -1
+	}
+}
+
+
+VspBspTree {
+	Construction {
+		samples 100000
+	}
+
+	Termination {
+		minPvs 0
+		maxViewCells 1000
+	}
+
+	useCostHeuristics true
+	splitUseOnlyDrivingAxis false
+
+	# maximum number of tests per node
+	maxTests 100000
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1918)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1919)
@@ -92,5 +92,5 @@
 				Name="VCLinkerTool"
 				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib"
-				OutputFile="$(OutDir)/Preprocessor2.exe"
+				OutputFile="$(OutDir)/Preprocessor.exe"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1903)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1919)
@@ -440,4 +440,7 @@
 	void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
 
+	void EvalViewCellHistogramForPvsSize(const string filename, 
+										 ViewCellContainer &viewCells);
+
 	/** Evaluates the render cost of a view cell.
 	*/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1912)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1919)
@@ -1314,4 +1314,9 @@
 					"5000");
 
+	RegisterOption("ViewCells.Evaluation.histoMem",
+					optInt,
+					"view_cells_evaluation_histo_mem=",
+					"50");
+
 	RegisterOption("ViewCells.renderCostEvaluationType",
 					optString,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1912)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1919)
@@ -288,5 +288,8 @@
 	void EvaluateSubdivision2(ofstream &splitsStats,
 							  const int splitsStepSize,
-							  const bool useFilter);
+							  const bool useFilter,
+							  const bool useHisto,
+							  const int histoMem,
+							  const int pass);
 
 
@@ -526,5 +529,9 @@
 						  int &viewSpaceSplits,
 						  int &objectSpaceSplits,
-						  const bool useFilter);
+						  const bool useFilter,
+						  const bool useHisto,
+						  const int histoMem,
+						  const int pass,
+						  bool &histoUsed);
 
 	void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1918)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1919)
@@ -147,11 +147,17 @@
 
 	// mix of sampling strategies
-	mStrategies.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION);
-	
-	/*mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-	mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
-	mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
-	*/
-	//mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	if (0)
+	{
+		mStrategies.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION);
+	}
+	else
+	{
+		/*mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+		*/
+        
+		mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	}
 		
     Debug << "casting strategies: ";
@@ -955,4 +961,91 @@
 
 	it = viewCells.begin();
+	
+	for (int j = 0; j < intervals; ++ j)
+	{
+		float volDif = 0;
+		int smallerDif = 0;
+
+		while ((i < (int)viewCells.size()) && 
+			   (viewCells[i]->GetPvsCost() < currentPvs))
+		{
+			volDif += viewCells[i]->GetVolume();
+			volSum += viewCells[i]->GetVolume();
+
+			++ i;
+			++ smallerDif;
+			++ smallerSum;
+		}
+		
+		//		if (0 && (i < (int)viewCells.size()))
+		//		  Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i]) 
+		//				<< " " << currentPvs << endl;
+		
+		const float volRatioDif = volDif / totalVol;
+		const float volRatioSum = volSum / totalVol;
+
+		outstream << "#Pass\n" << j << endl;
+		outstream << "#Pvs\n" << currentPvs << endl;
+		outstream << "#ViewCellsDif\n" << smallerDif << endl;
+		outstream << "#ViewCellsSum\n" << smallerSum << endl;	
+		outstream << "#VolumeDif\n" << volRatioDif << endl << endl;
+		outstream << "#VolumeSum\n" << volRatioSum << endl << endl;
+	
+		//-- increase current pvs size to define next interval
+		currentPvs += stepSize;
+	}
+
+	outstream.close();
+}
+
+
+void ViewCellsManager::EvalViewCellHistogramForPvsSize(const string filename, 
+													   ViewCellContainer &viewCells)
+{
+	std::ofstream outstream;
+	outstream.open(filename.c_str());
+
+	float maxPvs, maxVal, minVal;
+	
+	// sort by pvs size
+	sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs);
+
+	maxPvs = viewCells.back()->GetPvsCost();
+	minVal = 0;
+
+	// hack: normalize pvs size
+	int histoMaxVal;
+	Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal);
+	maxVal = max((float)histoMaxVal, maxPvs);
+		
+	Debug << "histogram minpvssize: " << minVal << " maxpvssize: " << maxVal 
+		<< " real maxpvs " << maxPvs << endl;
+
+	int histoIntervals;
+	Environment::GetSingleton()->GetIntValue("Preprocessor.histogram.intervals", histoIntervals);
+	const int intervals = min(histoIntervals, (int)viewCells.size());
+
+	const float range = maxVal - minVal;
+	int stepSize = (int)(range / intervals);
+
+	// set step size to avoid endless loop
+	if (!stepSize) stepSize = 1;
+	
+	Debug << "intervals " << histoIntervals << endl;
+	Debug << "stepsize: " << stepSize << endl;
+	cout << "intervals " << histoIntervals << endl;
+	cout << "stepsize: " << stepSize << endl;
+
+	const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost();
+	const float totalVol = GetViewSpaceBox().GetVolume();
+
+	float currentPvs = minVal;
+	
+	int i = 0;
+	int j = 0;
+	float volSum = 0;
+	int smallerSum = 0;
+
+	//ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();	
 	
 	for (int j = 0; j < intervals; ++ j)
@@ -6031,4 +6124,10 @@
 	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.stepSize", splitsStepSize);
 	
+	bool useHisto;
+	int histoMem;
+
+	Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.histogram", useHisto);
+	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.histoMem", histoMem);
+
 	Debug << "step size: " << splitsStepSize << endl;
 	Debug << "view cell evaluation samples per pass: " << samplesPerPass << endl;
@@ -6047,11 +6146,16 @@
 
 	// mix of sampling strategies
-	evalStrats.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION);
-
-	/*evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-	evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
-	evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
-*/
-	//evalStrats.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	if (0)
+	{
+		evalStrats.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION);
+	}
+	else
+	{
+		/*evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+		*/
+		evalStrats.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	}
 			
     Debug << "casting eval strategies: ";
@@ -6064,4 +6168,6 @@
 		cout << evalStrats[i] << " ";
 	cout << endl;
+
+	int pass = 0;
 
 	while (castSamples < numSamples)
@@ -6122,5 +6228,5 @@
 
 			ofstream ofstr(filename.c_str());
-			mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize, false);
+			mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize, false, useHisto, histoMem, pass);
 
 			timeDiff = TimeDiff(startTime, GetTime());
@@ -6167,4 +6273,5 @@
 					 << (float)pvsSize * ObjectPvs::GetEntrySize() << endl;
 			}
+			++ pass;
 		}
 
@@ -6174,7 +6281,6 @@
 	////////////
 	//-- histogram
-
+#if 1
 	const int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot());
-	bool useHisto;
 	int histoStepSize;
 
@@ -6185,5 +6291,5 @@
 	{
 		// evaluate view cells in a histogram		
-		char s[64];
+		char str[64];
 
 		// hack: just show final view cells
@@ -6195,12 +6301,5 @@
 
 			cout << "computing histogram for " << pass << " view cells" << endl;
-#if 0
-			//-- evaluate histogram for render cost
-			sprintf(s, "-%09d-histo.log", pass);
-			filename = string(statsPrefix) + string(s);
-
-			EvalViewCellHistogram(filename, pass);
-
-#endif
+
 			//////////////////////////////////////////
             //-- evaluate histogram for pvs size
@@ -6208,15 +6307,16 @@
 			cout << "computing pvs histogram for " << pass << " view cells" << endl;
 
-			sprintf(s, "-%09d-histo-pvs.log", pass);
-			filename = string(statsPrefix) + string(s);
+			sprintf(str, "-%09d-histo-pvs2.log", pass);
+			filename = string(statsPrefix) + string(str);
 
 			EvalViewCellHistogramForPvsSize(filename, pass);
 		}
 	}
-}
-
 #endif
-
-
-
-}
+}
+
+#endif
+
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1918)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1919)
@@ -2949,5 +2949,6 @@
 
 	mTotalCost = vData.mCorrectedRenderCost = vData.mRenderCost = pvsCost;
-	mPvsEntries = vData.mCorrectedPvs = vData.mPvs = EvalPvsEntriesSize(rays);
+	mPvsEntries = EvalPvsEntriesSize(rays);
+	vData.mCorrectedPvs = vData.mPvs = (float)mPvsEntries;
 
 	//////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1917)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1919)
@@ -2058,5 +2058,9 @@
 										int &viewSpaceSplits,
 										int &objectSpaceSplits,
-										const bool useFilter)
+										const bool useFilter,
+										const bool useHisto,
+										const int histoMem,
+										const int pass,
+										bool &histoUsed)
 {
 	ViewCellContainer viewCells;
@@ -2121,4 +2125,5 @@
 		{
 			ComputePvs(vc->GetPvs(), rc, pvsEntries);
+			vc->SetPvsCost(rc);
 		}
 
@@ -2132,4 +2137,27 @@
 	viewSpaceSplits = (int)viewCells.size();
 	objectSpaceSplits = (int)bvhNodes.size();
+
+	////////////////////////
+    //-- evaluate histogram for pvs size
+
+	if (useHisto && (memory <= (float)histoMem))
+	{
+		char str[100];
+		char statsPrefix[100];
+		int histoStepSize;
+
+		Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);
+	
+		cout << "computing pvs histogram for " << histoMem << " memory" << endl;
+		Debug << "computing pvs histogram for " << histoMem << " memory" << endl;
+		
+		sprintf(str, "-%05d-%05d-histo-pvs.log", pass, histoMem);
+		const string filename = string(statsPrefix) + string(str);
+
+		mVspTree->mViewCellsManager->EvalViewCellHistogramForPvsSize(filename, viewCells);
+
+		histoUsed = true;
+	}
+
 	//cout << "viewCells: " << (int)viewCells.size() << " nodes: " << (int)bvhNodes.size() << " rc: " << renderCost << " entries: " << pvsEntries << endl;
 
@@ -2325,5 +2353,8 @@
 void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats,
 											const int splitsStepSize,
-											const bool useFilter)
+											const bool useFilter,
+											const bool useHisto,
+											const int histoMem,
+											const int pass)
 {
 	vector<HierarchySubdivisionStats> subStatsContainer;
@@ -2331,4 +2362,6 @@
 	int splits = (1 + (mHierarchyStats.Leaves() - 1) / splitsStepSize) * splitsStepSize;
 	cout << "splits: " << splits << endl;
+
+	bool histoUsed = false;
 
 	while (1)
@@ -2342,5 +2375,9 @@
 												subStats.mViewSpaceSplits,
 												subStats.mObjectSpaceSplits,
-												useFilter);
+												useFilter,
+												useHisto && !histoUsed,
+												histoMem,
+												pass,
+												histoUsed);
 
 		
