ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/genambpos.pl
Revision: 2.5
Committed: Thu May 1 04:51:12 2014 UTC (9 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +8 -4 lines
Log Message:
Added -r option to specify ambient value radius at fixed size

File Contents

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