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