ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/genskyvec.pl
(Generate patch)

Comparing ray/src/util/genskyvec.pl (file contents):
Revision 2.4 by greg, Sat Jan 23 22:30:29 2010 UTC vs.
Revision 2.10 by greg, Mon Dec 12 17:40:07 2016 UTC

# Line 6 | Line 6
6   #       G. Ward
7   #
8   use strict;
9 + my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64");
10   my @skycolor = (0.960, 1.004, 1.118);
11   my $mf = 4;
12 + my $dosky = 1;
13 + my $headout = 1;
14 + my @origARGV = @ARGV;
15   while ($#ARGV >= 0) {
16          if ("$ARGV[0]" eq "-c") {
17                  @skycolor = @ARGV[1..3];
18 <                shift @ARGV; shift @ARGV; shift @ARGV;
18 >                shift @ARGV for (1..3);
19          } elsif ("$ARGV[0]" eq "-m") {
20                  $mf = $ARGV[1];
21                  shift @ARGV;
22 +        } elsif ("$ARGV[0]" eq "-d") {
23 +                $dosky = 0;
24 +        } elsif ("$ARGV[0]" eq "-h") {
25 +                $headout = 0;
26 +        } else {
27 +                die "Unexpected command-line argument: $ARGV[0]\n";
28          }
29          shift @ARGV;
30   }
# Line 32 | Line 42 | while (<>) {
42                  $srcmod = $_;
43                  $lightline = $#skydesc;
44          } elsif (defined($srcmod) && /^($srcmod)\s+source\s/) {
45 <                @sunval = split(/\s+/, $skydesc[$lightline + 3]);
45 >                @sunval = split(' ', $skydesc[$lightline + 3]);
46                  shift @sunval;
47                  $sunline = $#skydesc;
48          } elsif (/\sskyfunc\s*$/) {
# Line 43 | Line 53 | die "Bad sky description!\n" if (! $skyOK);
53   # Strip out the solar source if present
54   my @sundir;
55   if (defined $sunline) {
56 <        @sundir = split(/\s+/, $skydesc[$sunline + 3]);
56 >        @sundir = split(' ', $skydesc[$sunline + 3]);
57          shift @sundir;
58          undef @sundir if ($sundir[2] <= 0);
59          splice(@skydesc, $sunline, 5);
60   }
61   # Reinhart sky sample generator
62 < my $rhcal = '
63 < DEGREE : PI/180;
64 < x1 = .5; x2 = .5;
65 < alpha : 90/(MF*7 + .5);
66 < tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);
67 < rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));
68 < raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);
69 < RowMax : 7*MF + 1;
70 < Rmax : raccum(RowMax);
71 < Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r);
72 < Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin));
73 < Rcol = Rbin - raccum(Rrow) - 1;
74 < Razi_width = 2*PI / rnaz(Rrow);
75 < RAH : alpha*DEGREE;
76 < Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2);
77 < Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1));
78 < Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin,
79 <        Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)),
80 <        2*PI*(1 - cos(RAH/2)) ) );
81 < cos_ralt = cos(Ralt);
82 < Dx = sin(Razi)*cos_ralt;
83 < Dy = cos(Razi)*cos_ralt;
84 < Dz = sin(Ralt);
85 < ';
86 < my $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`;
87 < chomp $nbins;
88 < # Create octree for rtrace
89 < my $octree = "/tmp/gtv$$.oct";
90 < open OCONV, "| oconv - > $octree";
91 < print OCONV @skydesc;
92 < print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n";
93 < print OCONV "skyglow source sky 0 0 4 0 0 1 360\n";
94 < close OCONV;
95 < # Run rtrace and average output for every 16 samples
96 < my $tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " .
97 <        q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } .
98 <        q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } .
99 <        "| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m";
100 < my @tregval = `$tregcommand`;
101 < unlink $octree;
62 > my $rhcal = 'DEGREE : PI/180;' .
63 >        'x1 = .5; x2 = .5;' .
64 >        'alpha : 90/(MF*7 + .5);' .
65 >        'tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);' .
66 >        'rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));' .
67 >        'raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);' .
68 >        'RowMax : 7*MF + 1;' .
69 >        'Rmax : raccum(RowMax);' .
70 >        'Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r);' .
71 >        'Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin));' .
72 >        'Rcol = Rbin - raccum(Rrow) - 1;' .
73 >        'Razi_width = 2*PI / rnaz(Rrow);' .
74 >        'RAH : alpha*DEGREE;' .
75 >        'Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2);' .
76 >        'Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1));' .
77 >        'Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin, ' .
78 >        '       Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)),' .
79 >        '       2*PI*(1 - cos(RAH/2)) ) );' .
80 >        'cos_ralt = cos(Ralt);' .
81 >        'Dx = sin(Razi)*cos_ralt;' .
82 >        'Dy = cos(Razi)*cos_ralt;' .
83 >        'Dz = sin(Ralt);' ;
84 > my ($nbins, $octree, $tregcommand, $suncmd);
85 > if ($windoz) {
86 >        $nbins = `rcalc -n -e MF:$mf -e \"$rhcal\" -e \"\$1=Rmax+1\"`;
87 >        chomp $nbins;
88 >        $octree = "gtv$$.oct";
89 >        $tregcommand = "cnt $nbins 16 | rcalc -e MF:$mf -e \"$rhcal\" " .
90 >                q{-e "Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)" } .
91 >                q{-e "$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz" } .
92 >                "| rtrace -h -ab 0 -w $octree | total -16 -m";
93 >        if (@sundir) {
94 >                $suncmd = "cnt " . ($nbins-1) .
95 >                        " | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " .
96 >                        "-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " .
97 >                        "-e \"cond=dot-.866\" " .
98 >                        q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" };
99 >        }
100 > } else {
101 >        $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`;
102 >        chomp $nbins;
103 >        $octree = "/tmp/gtv$$.oct";
104 >        $tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " .
105 >                q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } .
106 >                q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } .
107 >                "| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m";
108 >        if (@sundir) {
109 >                $suncmd = "cnt " . ($nbins-1) .
110 >                        " | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " .
111 >                        "-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " .
112 >                        "-e 'cond=dot-.866' " .
113 >                        q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' };
114 >        }
115 > }
116 > my @tregval;
117 > if ($dosky) {
118 >        # Create octree for rtrace
119 >        open OCONV, "| oconv - > $octree";
120 >        print OCONV @skydesc;
121 >        print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n";
122 >        print OCONV "skyglow source sky 0 0 4 0 0 1 360\n";
123 >        close OCONV;
124 >        # Run rtrace and average output for every 16 samples
125 >        @tregval = `$tregcommand`;
126 >        unlink $octree;
127 > } else {
128 >        push @tregval, "0\t0\t0\n" for (1..$nbins);
129 > }
130   # Find closest 3 patches to sun and divvy up direct solar contribution
131 < my @bestdir;
131 > sub numSort1 {
132 >        my @a1 = split("\t", $a);
133 >        my @b1 = split("\t", $b);
134 >        return ($a1[0] <=> $b1[0]);
135 > }
136   if (@sundir) {
137          my $somega = ($sundir[3]/360)**2 * 3.141592654**3;
138 <        my $cmd = "cnt " . ($nbins-1) .
139 <                " | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " .
98 <                "-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " .
99 <                "-e 'cond=dot-.866' " .
100 <                q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' };
101 <        @bestdir = `$cmd | sort -n | head -3`;
138 >        my @bestdir = `$suncmd`;
139 >        @bestdir = sort numSort1 @bestdir;
140          my (@ang, @dom, @ndx);
141          my $wtot = 0;
142          for my $i (0..2) {
143 <                ($ang[$i], $dom[$i], $ndx[$i]) = split(/\s+/, $bestdir[$i]);
143 >                ($ang[$i], $dom[$i], $ndx[$i]) = split(' ', $bestdir[$i]);
144                  $wtot += 1./($ang[$i]+.02);
145          }
146          for my $i (0..2) {
147                  my $wt = 1./($ang[$i]+.02)/$wtot * $somega / $dom[$i];
148 <                my @scolor = split(/\s+/, $tregval[$ndx[$i]]);
148 >                my @scolor = split(' ', $tregval[$ndx[$i]]);
149                  for my $j (0..2) { $scolor[$j] += $wt * $sunval[$j]; }
150                  $tregval[$ndx[$i]] = "$scolor[0]\t$scolor[1]\t$scolor[2]\n";
151          }
152 + }
153 + # Output header if requested
154 + if ($headout) {
155 +        print "#?RADIANCE\n";
156 +        print "genskyvec @origARGV\n";
157 +        print "NROWS=", $#tregval+1, "\n";
158 +        print "NCOLS=1\nNCOMP=3\n";
159 +        print "FORMAT=ascii\n";
160 +        print "\n";
161   }
162   # Output our final vector
163   print @tregval;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines