#
# Makefile for running experiments on stratified sampling.
#
SRT = time ../srt
OPTS = -x 90 -y 90 -N -an


#
# Make sure the model is up-to-date
#
testmodel.sml : testmodel.l
	model testmodel.l > testmodel.sml

aliased.im : testmodel.sml
	$(SRT) $(OPTS) < testmodel.sml > aliased.im

#
# Generate a sequence of images showing the effect of various
# filter functions using stratified sampling.
#
# In this test, the place where the Gaussian filter function
# is truncated is varied, as is the radius of support as measured
# in pixels.
#
FILTEROPTS = $(OPTS) -as -ar 96
filtertest : aliased.im
#
#	 Generate a sequence truncated at 1 sigma
#
	$(SRT) $(FILTEROPTS) -at 1.0 -af 0.5 < testmodel.sml > filter.1-0.5.im
	rcp june:~/nrays.im nrays.filter.1-0.5.im

	$(SRT) $(FILTEROPTS) -at 1.0 -af 1.0 < testmodel.sml > filter.1-1.0.im
	rcp june:~/nrays.im nrays.filter.1-1.0.im

	$(SRT) $(FILTEROPTS) -at 1.0 -af 1.5 < testmodel.sml > filter.1-1.5.im
	rcp june:~/nrays.im nrays.filter.1-1.5.im

	$(SRT) $(FILTEROPTS) -at 1.0 -af 2.0 < testmodel.sml > filter.1-2.0.im
	rcp june:~/nrays.im nrays.filter.1-2.0.im
#
# 	Generate a sequence truncated at 2 sigma
#
	$(SRT) $(FILTEROPTS) -at 2.0 -af 0.5 < testmodel.sml > filter.2-0.5.im
	rcp june:~/nrays.im nrays.filter.2-0.5.im

	$(SRT) $(FILTEROPTS) -at 2.0 -af 1.0 < testmodel.sml > filter.2-1.0.im
	rcp june:~/nrays.im nrays.filter.2-1.0.im

	$(SRT) $(FILTEROPTS) -at 2.0 -af 1.5 < testmodel.sml > filter.2-1.5.im
	rcp june:~/nrays.im nrays.filter.2-1.5.im

	$(SRT) $(FILTEROPTS) -at 2.0 -af 2.0 < testmodel.sml > filter.2-2.0.im
	rcp june:~/nrays.im nrays.filter.2-2.0.im
#
# 	Generate a sequence truncated at 3 sigma
#
	$(SRT) $(FILTEROPTS) -at 3.0 -af 0.5 < testmodel.sml > filter.3-0.5.im
	rcp june:~/nrays.im nrays.filter.3-0.5.im

	$(SRT) $(FILTEROPTS) -at 3.0 -af 1.0 < testmodel.sml > filter.3-1.0.im
	rcp june:~/nrays.im nrays.filter.3-1.0.im

	$(SRT) $(FILTEROPTS) -at 3.0 -af 1.5 < testmodel.sml > filter.3-1.5.im
	rcp june:~/nrays.im nrays.filter.3-1.5.im

	$(SRT) $(FILTEROPTS) -at 3.0 -af 2.0 < testmodel.sml > filter.3-2.0.im
	rcp june:~/nrays.im nrays.filter.3-2.0.im

#
# Compose an image from the results of filtertest.
#
filterimage : 
	fill 120 120 120 1

#
#	The un-antialiased image
#
	ikshow -C 255 100 aliased.im

#
# The images where filter is truncated at 1 sigma
#
	ikshow -C 100 200 filter.1-0.5.im
	ikshow -C 200 200 filter.1-1.0.im
	ikshow -C 300 200 filter.1-1.5.im
	ikshow -C 400 200 filter.1-2.0.im

#
# 	The images where filter is truncated at 2 sigma
#
	ikshow -C 100 300 filter.2-0.5.im
	ikshow -C 200 300 filter.2-1.0.im
	ikshow -C 300 300 filter.2-1.5.im
	ikshow -C 400 300 filter.2-2.0.im

#
# 	The images where filter is truncated at 3 sigma
#
	ikshow -C 100 400 filter.3-0.5.im
	ikshow -C 200 400 filter.3-1.0.im
	ikshow -C 300 400 filter.3-1.5.im
	ikshow -C 400 400 filter.3-2.0.im

#
# 	Put up some text
#
	iklabel 175 25 "Stratified Sampling" 255 255 255
	iklabel 20 75  "Max. 96 Rays/Pixel" 255 255 255
	iklabel 325 75 "Gaussian Filter" 255 255 255
	iklabel 20 175 "1s" 255 255 255
	iklabel 20 275 "2s" 255 255 255
	iklabel 20 375 "3s" 255 255 255

	iklabel 75  480 "0.5pxls" 255 255 255
	iklabel 175 480 "1.0pxls" 255 255 255
	iklabel 275 480 "1.5pxls" 255 255 255
	iklabel 375 480 "2.0pxls" 255 255 255
#
# Compose an image from the results of the number of samples drawn
# from each of the test cases in filtertest.
#
nraysfilterimage : 
	fill 120 120 120 1

#
# The images where filter is truncated at 1 sigma
#
	ikshow -C 100 200 nrays.filter.1-0.5.im
	ikshow -C 200 200 nrays.filter.1-1.0.im
	ikshow -C 300 200 nrays.filter.1-1.5.im
	ikshow -C 400 200 nrays.filter.1-2.0.im

#
# 	The images where filter is truncated at 2 sigma
#
	ikshow -C 100 300 nrays.filter.2-0.5.im
	ikshow -C 200 300 nrays.filter.2-1.0.im
	ikshow -C 300 300 nrays.filter.2-1.5.im
	ikshow -C 400 300 nrays.filter.2-2.0.im

#
# 	The images where filter is truncated at 3 sigma
#
	ikshow -C 100 400 nrays.filter.3-0.5.im
	ikshow -C 200 400 nrays.filter.3-1.0.im
	ikshow -C 300 400 nrays.filter.3-1.5.im
	ikshow -C 400 400 nrays.filter.3-2.0.im

#
# 	Put up some text
#
	iklabel 175 25 "Stratified Sampling" 255 255 255
	iklabel 20 75  "Max. 96 Rays/Pixel" 255 255 255
	iklabel 325 75 "Gaussian Filter" 255 255 255
	iklabel 20 175 "1s" 255 255 255
	iklabel 20 275 "2s" 255 255 255
	iklabel 20 375 "3s" 255 255 255

	iklabel 75  480 "0.5pxls" 255 255 255
	iklabel 175 480 "1.0pxls" 255 255 255
	iklabel 275 480 "1.5pxls" 255 255 255
	iklabel 375 480 "2.0pxls" 255 255 255
	
#
# Generate a sequence of images showing the effect of varying
# the maximum number of samples.  The filter function is a Gaussian
# truncated at 3sigma with a radius of 1.0 pixels.
#
SAMPLEOPTS = $(OPTS) -as -at 3.0 -af 1.0
sampletest: aliased.im
	$(SRT) $(SAMPLEOPTS) -ar 8 < testmodel.sml > num.8.im
	cp nrays.im nrays.num.8.im

	$(SRT) $(SAMPLEOPTS) -ar 16 < testmodel.sml > num.16.im
	cp nrays.im nrays.num.16.im

	$(SRT) $(SAMPLEOPTS) -ar 32 < testmodel.sml > num.32.im
	cp nrays.im nrays.num.32.im

	$(SRT) $(SAMPLEOPTS) -ar 48 < testmodel.sml > num.48.im
	cp nrays.im nrays.num.48.im

	$(SRT) $(SAMPLEOPTS) -ar 64 < testmodel.sml > num.64.im
	cp nrays.im nrays.num.64.im

	$(SRT) $(SAMPLEOPTS) -ar 80 < testmodel.sml  > num.80.im
	cp nrays.im nrays.num.80.im

	$(SRT) $(SAMPLEOPTS) -ar 96 < testmodel.sml > num.96.im
	cp nrays.im nrays.num.96.im


#
# Compose an image from the results of sampletest
#
sampleimage : 
	fill 120 120 120 1

	ikshow -C 255 100 aliased.im

	iklabel 175 25 "Stratified Sampling" 255 255 255
	iklabel 20  75 "Gaussian Filter" 255 255 255
	iklabel 325 75 "3s, 1.0pxl" 255 255 255

	ikshow -C 100 225 num.16.im
	ikshow -C 255 225 num.32.im
	ikshow -C 400 225 num.48.im

	ikshow -C 100 375 num.64.im
	ikshow -C 255 375 num.80.im
	ikshow -C 400 375 num.96.im

	iklabel 55  280 "16max,10avg"  255 255 255
	iklabel 210 280 "32max,14avg" 255 255 255
	iklabel 355 280 "48max,19avg" 255 255 255

	iklabel 55  430 "64max,24avg" 255 255 255
	iklabel 210 430 "80max,28avg" 255 255 255
	iklabel 355 430 "96max,33avg" 255 255 255

alltests :
	make filtertest
	make sampletest

