orig/glare.csh
author Axel Jacobs <axel@jaloxa.eu>
Mon, 14 Apr 2014 22:21:17 +0100
changeset 73 87fa3132a136
parent 0 0aa115157c9c
permissions -rw-r--r--
New IES test file with spaces in file name
axel@0
     1
#!/bin/csh -f
axel@0
     2
# RCSid: $Id: glare.csh,v 2.4 2003/02/22 02:07:30 greg Exp $
axel@0
     3
#
axel@0
     4
# Interactive program for calculating glare values
axel@0
     5
#
axel@0
     6
set fgargs=(-v)
axel@0
     7
set nofile="none"
axel@0
     8
set octree=$nofile
axel@0
     9
set picture=$nofile
axel@0
    10
set glarefile=$nofile
axel@0
    11
if ($#argv >= 1) then
axel@0
    12
	set glarefile=$argv[1]
axel@0
    13
	if ($#argv >= 2) then
axel@0
    14
		set picture=$argv[2]
axel@0
    15
		if ($#argv >= 3) then
axel@0
    16
			set octree=$argv[3]
axel@0
    17
		endif
axel@0
    18
	endif
axel@0
    19
endif
axel@0
    20
set rtargs=
axel@0
    21
set view=
axel@0
    22
set threshold=300
axel@0
    23
set maxangle=0
axel@0
    24
set stepangle=10
axel@0
    25
axel@0
    26
set gndxfile="glr$$.ndx"
axel@0
    27
set plotfile="glr$$.plt"
axel@0
    28
set tempfiles=($gndxfile $plotfile)
axel@0
    29
axel@0
    30
alias readvar 'echo -n Enter \!:1 "[$\!:1]: ";set ans="$<";if("$ans" != "")set \!:1="$ans"'
axel@0
    31
axel@0
    32
onintr quit
axel@0
    33
axel@0
    34
cat <<_EOF_
axel@0
    35
This script provides a convenient interface to the glare calculation
axel@0
    36
and analysis programs.  It works on a single output file from findglare,
axel@0
    37
which you must either create here or have created already before.
axel@0
    38
_EOF_
axel@0
    39
while ( $glarefile == $nofile )
axel@0
    40
	echo ""
axel@0
    41
	echo "Please specify a glare file, or use ^C to exit."
axel@0
    42
	readvar glarefile
axel@0
    43
end
axel@0
    44
if ( ! -f $glarefile ) then
axel@0
    45
	echo ""
axel@0
    46
	echo -n "The glare file '$glarefile' doesn't exist -- shall we create it? "
axel@0
    47
	if ("$<" =~ [nN]*) exit 0
axel@0
    48
	cat <<_EOF_
axel@0
    49
axel@0
    50
A glare file can be created from a wide-angle Radiance picture (preferably
axel@0
    51
a fisheye view), an octree, or both.  Computing glare source locations
axel@0
    52
from a finished image is faster, but using an octree is more reliable
axel@0
    53
since all of the scene information is there.  Whenever it is possible,
axel@0
    54
you should use both a picture and an octree to compute the glare file.
axel@0
    55
axel@0
    56
You must also have a viewpoint and direction for the glare calculation.
axel@0
    57
If the viewpoint is not the same as the picture, an error will result.
axel@0
    58
If no view is specified, the view parameters are taken from the picture,
axel@0
    59
so the view specification is optional unless you are starting from an
axel@0
    60
octree.
axel@0
    61
axel@0
    62
_EOF_
axel@0
    63
	if ( $picture == $nofile ) then
axel@0
    64
		readvar picture
axel@0
    65
	endif
axel@0
    66
	if ( $octree == $nofile ) then
axel@0
    67
		readvar octree
axel@0
    68
	endif
axel@0
    69
	readvar view
axel@0
    70
	if ( $picture == $nofile && $octree == $nofile ) then
axel@0
    71
		echo "You must specify a picture or an octree"
axel@0
    72
		exit 1
axel@0
    73
	endif
axel@0
    74
	if ( $picture == $nofile && "$view" == "" ) then
axel@0
    75
		echo "You must give a view if there is no picture"
axel@0
    76
		exit 1
axel@0
    77
	endif
axel@0
    78
	if ( $picture != $nofile ) then
axel@0
    79
		if ( ! -r $picture ) then
axel@0
    80
			echo "Cannot read $picture"
axel@0
    81
			exit 1
axel@0
    82
		endif
axel@0
    83
		set fgargs=($fgargs -p $picture)
axel@0
    84
		if ( "$view" != "" ) then
axel@0
    85
			set view=(-vf $picture $view)
axel@0
    86
		endif
axel@0
    87
	endif
axel@0
    88
	set fgargs=($fgargs $view)
axel@0
    89
	if ( $octree != $nofile ) then
axel@0
    90
		if ( ! -r $octree ) then
axel@0
    91
			echo "Cannot read $octree"
axel@0
    92
			exit 1
axel@0
    93
		endif
axel@0
    94
		cat <<_EOF_
axel@0
    95
axel@0
    96
With an octree, you should give the same options for -av, -ab and
axel@0
    97
so forth as are used to render the scene.  Please enter them below.
axel@0
    98
axel@0
    99
_EOF_
axel@0
   100
		if ($picture != $nofile) then
axel@0
   101
			echo "These are the parameters from the picture:"
axel@0
   102
			getinfo $picture
axel@0
   103
		endif
axel@0
   104
		readvar rtargs
axel@0
   105
		set fgargs=($fgargs $rtargs $octree)
axel@0
   106
	endif
axel@0
   107
	echo ""
axel@0
   108
	echo -n "Do you expect glare sources in the scene to be small? "
axel@0
   109
	if ("$<" =~ [yY]) then
axel@0
   110
		echo -n "Very small? "
axel@0
   111
		if ("$<" =~ [yY]) then
axel@0
   112
			set fgargs=(-r 400 $fgargs)
axel@0
   113
		else
axel@0
   114
			set fgargs=(-r 250 $fgargs)
axel@0
   115
		endif
axel@0
   116
		echo -n "Are these sources relatively bright? "
axel@0
   117
		if ("$<" =~ [nN]*) then
axel@0
   118
			set fgargs=(-c $fgargs)
axel@0
   119
		endif
axel@0
   120
	endif
axel@0
   121
	cat <<_EOF_
axel@0
   122
axel@0
   123
Glare sources are determined by a threshold level.  Any part of the
axel@0
   124
view that is above this threshold is considered to be part of a glare
axel@0
   125
source.  If you do not choose a threshold value, it will be set auto-
axel@0
   126
matically to 7 times the average field luminance (in candelas/sq.meter).
axel@0
   127
axel@0
   128
_EOF_
axel@0
   129
	echo -n "Do you wish to set the glare threshold manually? "
axel@0
   130
	if ("$<" =~ [yY]) then
axel@0
   131
		readvar threshold
axel@0
   132
		set fgargs=(-t $threshold $fgargs)
axel@0
   133
	endif
axel@0
   134
	cat <<_EOF_
axel@0
   135
axel@0
   136
It is often desirable to know how glare changes as a function of
axel@0
   137
viewing direction.  If you like, you can compute glare for up
axel@0
   138
to 180 degrees to the left and right of the view center.  Enter
axel@0
   139
the maximum angle that you would like to compute below.
axel@0
   140
axel@0
   141
_EOF_
axel@0
   142
	readvar maxangle
axel@0
   143
	if ( $maxangle >= $stepangle ) then
axel@0
   144
		set fgargs=(-ga $stepangle-$maxangle\:$stepangle $fgargs)
axel@0
   145
	endif
axel@0
   146
	echo ""
axel@0
   147
	echo "Starting calculation..."
axel@0
   148
	echo findglare $fgargs
axel@0
   149
	findglare $fgargs > $glarefile
axel@0
   150
	if ($status) then
axel@0
   151
		echo "Uh-oh.  Something went wrong with findglare\!"
axel@0
   152
		rm $glarefile
axel@0
   153
		exit 1
axel@0
   154
	endif
axel@0
   155
endif
axel@0
   156
if ($?DISPLAY && $picture != $nofile) then
axel@0
   157
	echo ""
axel@0
   158
	echo "Displaying glare sources in '$picture'..."
axel@0
   159
	xglaresrc $picture $glarefile
axel@0
   160
endif
axel@0
   161
set ndxnam=("Guth Visual Comfort Probability" "Guth Disability Glare Ratio" "CIE Glare Index" "BRS Glare Index" "Unified Glare Rating" "Daylight Glare Index")
axel@0
   162
set ndxcom=("glarendx -t guth_vcp" "glarendx -t guth_dgr" "glarendx -t cie_cgi" "glarendx -t brs_gi" "glarendx -t ugr" "glarendx -t dgi")
axel@0
   163
set bcdlvl=(50 124 18.5 18.5 18.5 21.7)
axel@0
   164
while ( 1 )
axel@0
   165
	echo ""
axel@0
   166
	echo "	0.  Quit"
axel@0
   167
	set i=1
axel@0
   168
	while ($i <= $#ndxnam)
axel@0
   169
		echo "	$i.  $ndxnam[$i]"
axel@0
   170
		@ i++
axel@0
   171
	end
axel@0
   172
	echo ""
axel@0
   173
	set choice=0
axel@0
   174
	readvar choice
axel@0
   175
	if ($choice < 1 || $choice > $#ndxcom) goto quit
axel@0
   176
	$ndxcom[$choice] $glarefile > $gndxfile
axel@0
   177
	echo ""
axel@0
   178
	echo $ndxnam[$choice]
axel@0
   179
	echo "Angle		Value"
axel@0
   180
	getinfo - < $gndxfile
axel@0
   181
	echo ""
axel@0
   182
	set save_file=$nofile
axel@0
   183
	readvar save_file
axel@0
   184
	if ($save_file != $nofile) then
axel@0
   185
		cp -i $gndxfile $save_file
axel@0
   186
	endif
axel@0
   187
	if ( `getinfo - < $gndxfile | wc -l` > 4 ) then
axel@0
   188
		echo ""
axel@0
   189
		echo -n "Do you want to plot this data? "
axel@0
   190
		if ( "$<" =~ [yY]* ) then
axel@0
   191
			set subtitle="$view"
axel@0
   192
			if ($picture != $nofile) then
axel@0
   193
				set subtitle="$picture $subtitle"
axel@0
   194
			else if ($octree != $nofile) then
axel@0
   195
				set subtitle="$subtitle $octree"
axel@0
   196
			endif
axel@0
   197
			if ( "$subtitle" == "" ) then
axel@0
   198
				set subtitle="`getinfo < $glarefile | grep findglare`"
axel@0
   199
			endif
axel@0
   200
			cat <<_EOF_ > $plotfile
axel@0
   201
include=line.plt
axel@0
   202
include=polar.plt
axel@0
   203
title="$ndxnam[$choice]"
axel@0
   204
subtitle="$subtitle"
axel@0
   205
Bdata=
axel@0
   206
	0	$bcdlvl[$choice]
axel@0
   207
	360	$bcdlvl[$choice]
axel@0
   208
;
axel@0
   209
Blabel="BCD level"
axel@0
   210
Adata=
axel@0
   211
_EOF_
axel@0
   212
			getinfo - < $gndxfile >> $plotfile
axel@0
   213
			igraph $plotfile
axel@0
   214
		endif
axel@0
   215
	endif
axel@0
   216
end
axel@0
   217
quit:
axel@0
   218
rm -f $tempfiles
axel@0
   219
exit 0