ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/genambpos.pl
Revision: 2.7
Committed: Sat May 10 01:58:22 2014 UTC (9 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.6: +12 -12 lines
Log Message:
Added significant digits to some of the output formats

File Contents

# User Rev Content
1 greg 2.1 #!/usr/bin/perl -w
2 greg 2.7 # RCSid $Id: genambpos.pl,v 2.6 2014/05/09 23:49:05 greg Exp $
3 greg 2.1 #
4     # Visualize ambient positions and gradients
5     #
6     use strict;
7     sub userror {
8 greg 2.5 print STDERR "Usage: genambpos [-l lvl][-w minwt][-r rad][-s sf][-p][-d] scene.amb > ambloc.rad\n";
9 greg 2.1 exit 1;
10     }
11     my $lvlsel = -1;
12     my $scale = 0.25;
13     my $doposgrad = 0;
14     my $dodirgrad = 0;
15 greg 2.2 my $minwt = 0.5001**6;
16 greg 2.5 my $fixedrad="";
17 greg 2.1 my $savedARGV = "genambpos @ARGV";
18     # Get options
19     while ($#ARGV >= 0) {
20     if ("$ARGV[0]" =~ /^-p/) {
21     $doposgrad=1;
22     } elsif ("$ARGV[0]" =~ /^-d/) {
23     $dodirgrad=1;
24     } elsif ("$ARGV[0]" =~ /^-l/) {
25     $lvlsel = $ARGV[1];
26     shift @ARGV;
27 greg 2.2 } elsif ("$ARGV[0]" =~ /^-w/) {
28     $minwt = $ARGV[1];
29     shift @ARGV;
30 greg 2.1 } elsif ("$ARGV[0]" =~ /^-s/) {
31     $scale = $ARGV[1];
32     shift @ARGV;
33 greg 2.5 } elsif ("$ARGV[0]" =~ /^-r/) {
34     $fixedrad = "-e psiz:$ARGV[1]";
35     shift @ARGV;
36 greg 2.1 } elsif ("$ARGV[0]" =~ /^-./) {
37     userror();
38     } else {
39     last;
40     }
41     shift @ARGV;
42     }
43     userror() if ($#ARGV != 0);
44     my $cmd = "getinfo < $ARGV[0] " .
45 greg 2.3 q[| sed -n 's/^.* -aa \([.0-9][^ ]*\) .*$/\1/p'];
46 greg 2.1 my $ambacc=`$cmd`;
47     die "Missing -aa setting in header\n" if (! $ambacc );
48 greg 2.6 die "Zero -aa setting in header\n" if ($ambacc <= .00001);
49 greg 2.4 $scale *= $ambacc;
50     my $ambfmt = '
51 greg 2.1 void glow posglow
52     0
53     0
54     4 ${agr} ${agg} ${agb} 0
55    
56     posglow sphere position${recno}
57     0
58     0
59 greg 2.6 4 ${ px } ${ py } ${ pz } ${ psiz }
60 greg 2.4 ';
61     my $posgradfmt = '
62 greg 2.2 void glow arrglow
63     0
64     0
65     4 ${wt*agr} ${wt*agg} ${wt*agb} 0
66    
67     arrglow cone pgarrow${recno}
68 greg 2.1 0
69     0
70     8
71 greg 2.7 ${ cx0 } ${ cy0 } ${ cz0 }
72     ${ cx1 } ${ cy1 } ${ cz1 }
73     ${ cr0 } 0
74 greg 2.4
75 greg 2.1 void brightfunc pgpat
76     2 posfunc ambpos.cal
77     0
78     6 ${ px } ${ py } ${ pz } ${ pgx } ${ pgy } ${ pgz }
79    
80     pgpat glow pgval
81     0
82     0
83     4 ${avr} ${avg} ${avb} 0
84    
85     void mixfunc pgeval
86     4 pgval void ellipstencil ambpos.cal
87     0
88     9 ${ px } ${ py } ${ pz } ${ux/r0} ${uy/r0} ${uz/r0} ${vx/r1} ${vy/r1} ${vz/r1}
89    
90     pgeval polygon pgellipse${recno}
91     0
92     0
93     12
94 greg 2.7 ${ px1 } ${ py1 } ${ pz1 }
95     ${ px2 } ${ py2 } ${ pz2 }
96     ${ px3 } ${ py3 } ${ pz3 }
97     ${ px4 } ${ py4 } ${ pz4 }
98 greg 2.1 ';
99 greg 2.4 $posgradfmt .= '
100 greg 2.1 void glow tipglow
101     0
102     0
103     4 ${2*agr} ${2*agg} ${2*agb} 0
104    
105     tipglow sphere atip
106     0
107     0
108 greg 2.7 4 ${ cx1 } ${ cy1 } ${ cz1 } ${psiz/7}
109 greg 2.4 ' if ($dodirgrad);
110     my $dirgradfmt='
111 greg 2.1 void brightfunc dgpat
112     2 dirfunc ambpos.cal
113     0
114     9 ${ px } ${ py } ${ pz } ${ nx } ${ ny } ${ nz } ${ dgx } ${ dgy } ${ dgz }
115    
116     dgpat glow dgval
117     0
118     0
119     4 ${avr} ${avg} ${avb} 0
120    
121     dgval ring dgdisk${recno}a
122     0
123     0
124     8
125 greg 2.7 ${ px+dgx*.0002 } ${ py+dgy*.0002 } ${ pz+dgz*.0002 }
126 greg 2.1 ${ dgx } ${ dgy } ${ dgz }
127 greg 2.7 0 ${ r0/2 }
128 greg 2.1
129     dgval ring dgdisk${recno}b
130     0
131     0
132     8
133 greg 2.4 ${ px-dgx*.001 } ${ py-dgy*.001 } ${ pz-dgz*.001 }
134 greg 2.1 ${ -dgx } ${ -dgy } ${ -dgz }
135 greg 2.7 0 ${ r0/2 }
136 greg 2.1 ';
137     # Load & convert ambient values
138     print "# Output produced by: $savedARGV\n";
139 greg 2.2 system "lookamb -h -d $ARGV[0] | rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" .
140 greg 2.5 " -f rambpos.cal -e cond=acond $fixedrad -o '$ambfmt'";
141 greg 2.4 if ($doposgrad) {
142     system "lookamb -h -d $ARGV[0] " .
143     "| rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" .
144 greg 2.5 " -f rambpos.cal -e cond=pcond $fixedrad -o '$posgradfmt'";
145 greg 2.4 }
146     if ($dodirgrad) {
147     system "lookamb -h -d $ARGV[0] " .
148     "| rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" .
149     " -f rambpos.cal -e cond=dcond -o '$dirgradfmt'";
150     }
151 greg 2.1 exit;