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.5 by greg, Thu Jan 27 22:28:12 2011 UTC vs.
Revision 2.6 by greg, Mon May 16 23:56:32 2011 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   while ($#ARGV >= 0) {
# Line 49 | Line 50 | if (defined $sunline) {
50          splice(@skydesc, $sunline, 5);
51   }
52   # Reinhart sky sample generator
53 < my $rhcal = '
54 < DEGREE : PI/180;
55 < x1 = .5; x2 = .5;
56 < alpha : 90/(MF*7 + .5);
57 < tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);
58 < rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));
59 < raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);
60 < RowMax : 7*MF + 1;
61 < Rmax : raccum(RowMax);
62 < Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r);
63 < Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin));
64 < Rcol = Rbin - raccum(Rrow) - 1;
65 < Razi_width = 2*PI / rnaz(Rrow);
66 < RAH : alpha*DEGREE;
67 < Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2);
68 < Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1));
69 < Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin,
70 <        Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)),
71 <        2*PI*(1 - cos(RAH/2)) ) );
72 < cos_ralt = cos(Ralt);
73 < Dx = sin(Razi)*cos_ralt;
74 < Dy = cos(Razi)*cos_ralt;
75 < Dz = sin(Ralt);
76 < ';
77 < my $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`;
78 < chomp $nbins;
53 > my $rhcal = 'DEGREE : PI/180;' .
54 >        'x1 = .5; x2 = .5;' .
55 >        'alpha : 90/(MF*7 + .5);' .
56 >        'tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);' .
57 >        'rnaz(r) : if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));' .
58 >        'raccum(r) : if(r-.5, rnaz(r-1) + raccum(r-1), 0);' .
59 >        'RowMax : 7*MF + 1;' .
60 >        'Rmax : raccum(RowMax);' .
61 >        'Rfindrow(r, rem) : if(rem-rnaz(r)-.5, Rfindrow(r+1, rem-rnaz(r)), r);' .
62 >        'Rrow = if(Rbin-(Rmax-.5), RowMax-1, Rfindrow(0, Rbin));' .
63 >        'Rcol = Rbin - raccum(Rrow) - 1;' .
64 >        'Razi_width = 2*PI / rnaz(Rrow);' .
65 >        'RAH : alpha*DEGREE;' .
66 >        'Razi = if(Rbin-.5, (Rcol + x2 - .5)*Razi_width, 2*PI*x2);' .
67 >        'Ralt = if(Rbin-.5, (Rrow + x1)*RAH, asin(-x1));' .
68 >        'Romega = if(.5-Rbin, 2*PI, if(Rmax-.5-Rbin, ' .
69 >        '       Razi_width*(sin(RAH*(Rrow+1)) - sin(RAH*Rrow)),' .
70 >        '       2*PI*(1 - cos(RAH/2)) ) );' .
71 >        'cos_ralt = cos(Ralt);' .
72 >        'Dx = sin(Razi)*cos_ralt;' .
73 >        'Dy = cos(Razi)*cos_ralt;' .
74 >        'Dz = sin(Ralt);' ;
75 > my ($nbins, $octree, $tregcommand, $suncmd);
76 > if ($windoz) {
77 >        $nbins = `rcalc -n -e MF:$mf -e \"$rhcal\" -e \"\$1=Rmax+1\"`;
78 >        chomp $nbins;
79 >        $octree = "gtv$$.oct";
80 >        $tregcommand = "cnt $nbins 16 | rcalc -e MF:$mf -e \"$rhcal\" " .
81 >                q{-e "Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)" } .
82 >                q{-e "$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz" } .
83 >                "| rtrace -h -ab 0 -w $octree | total -16 -m";
84 >        $suncmd = "cnt " . ($nbins-1) .
85 >                " | rcalc -e MF:$mf -e \"$rhcal\" -e Rbin=recno " .
86 >                "-e \"dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]\" " .
87 >                "-e \"cond=dot-.866\" " .
88 >                q{-e "$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno" };
89 > } else {
90 >        $nbins = `rcalc -n -e MF:$mf -e \'$rhcal\' -e \'\$1=Rmax+1\'`;
91 >        chomp $nbins;
92 >        $octree = "/tmp/gtv$$.oct";
93 >        $tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " .
94 >                q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } .
95 >                q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } .
96 >                "| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m";
97 >        $suncmd = "cnt " . ($nbins-1) .
98 >                " | rcalc -e MF:$mf -e '$rhcal' -e Rbin=recno " .
99 >                "-e 'dot=Dx*$sundir[0] + Dy*$sundir[1] + Dz*$sundir[2]' " .
100 >                "-e 'cond=dot-.866' " .
101 >                q{-e '$1=if(1-dot,acos(dot),0);$2=Romega;$3=recno' };
102 > }
103   # Create octree for rtrace
79 my $octree = "/tmp/gtv$$.oct";
104   open OCONV, "| oconv - > $octree";
105   print OCONV @skydesc;
106   print OCONV "skyfunc glow skyglow 0 0 4 @skycolor 0\n";
107   print OCONV "skyglow source sky 0 0 4 0 0 1 360\n";
108   close OCONV;
109   # Run rtrace and average output for every 16 samples
86 my $tregcommand = "cnt $nbins 16 | rcalc -of -e MF:$mf -e '$rhcal' " .
87        q{-e 'Rbin=$1;x1=rand(recno*.37-5.3);x2=rand(recno*-1.47+.86)' } .
88        q{-e '$1=0;$2=0;$3=0;$4=Dx;$5=Dy;$6=Dz' } .
89        "| rtrace -h -ff -ab 0 -w $octree | total -if3 -16 -m";
110   my @tregval = `$tregcommand`;
111   unlink $octree;
112   # Find closest 3 patches to sun and divvy up direct solar contribution
113 < my @bestdir;
113 > sub numSort1 {
114 >        my @a1 = split("\t", $a);
115 >        my @b1 = split("\t", $b);
116 >        return ($a1[0] <=> $b1[0]);
117 > }
118   if (@sundir) {
119          my $somega = ($sundir[3]/360)**2 * 3.141592654**3;
120 <        my $cmd = "cnt " . ($nbins-1) .
121 <                " | 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`;
120 >        my @bestdir = `$suncmd`;
121 >        @bestdir = sort numSort1 @bestdir;
122          my (@ang, @dom, @ndx);
123          my $wtot = 0;
124          for my $i (0..2) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines