ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/genambpos.pl
Revision: 2.4
Committed: Thu May 1 02:52:03 2014 UTC (9 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +22 -13 lines
Log Message:
Fixed a number of issues with zero values and corrected direction gradient

File Contents

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