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

Comparing ray/src/util/genBSDF.pl (file contents):
Revision 2.50 by greg, Wed Mar 4 17:42:54 2015 UTC vs.
Revision 2.57 by greg, Thu Apr 2 17:42:46 2015 UTC

# Line 9 | Line 9 | use strict;
9   my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64");
10   use File::Temp qw/ :mktemp  /;
11   sub userror {
12 <        print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-f \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n";
12 >        print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-s \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n";
13          exit 1;
14   }
15   my ($td,$radscn,$mgfscn,$octree,$fsender,$bsender,$receivers,$facedat,$behinddat,$rmtmp);
# Line 66 | Line 66 | if ($windoz) {
66          $rmtmp = "rm -rf $td";
67   }
68   my @savedARGV = @ARGV;
69 < my $rfluxmtx = "rfluxmtx -v -ab 5 -ad 700 -lw 3e-6";
69 > my $rfluxmtx = "rfluxmtx -ab 5 -ad 700 -lw 3e-6";
70   my $wrapper = "wrapBSDF";
71   my $tensortree = 0;
72   my $ttlog2 = 4;
# Line 104 | Line 104 | while ($#ARGV >= 0) {
104          } elsif ("$ARGV[0]" eq "-t") {
105                  # Use value < 0 for rttree_reduce bypass
106                  $pctcull = $ARGV[1];
107 +                if ($pctcull >= 100) {
108 +                        die "Illegal -t culling percentage, must be < 100\n";
109 +                }
110                  shift @ARGV;
111          } elsif ("$ARGV[0]" =~ /^-t[34]$/) {
112                  $tensortree = substr($ARGV[0], 2, 1);
113                  $ttlog2 = $ARGV[1];
114                  shift @ARGV;
115 <        } elsif ("$ARGV[0]" eq "-f") {
115 >        } elsif ("$ARGV[0]" eq "-s") {
116                  $wrapper .= " -f \"$ARGV[1]\"";
117                  shift @ARGV;
118          } elsif ("$ARGV[0]" eq "-W") {
# Line 171 | Line 174 | if ( $geout ) {
174          $wrapper .= " -g $mgfscn";
175   }
176   # Create receiver & sender surfaces (rectangular)
177 + my $FEPS = 1e-5;
178   my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1);
179   my $ny = int($nsamp/$nx + 1);
180   $nsamp = $nx * $ny;
181   my $ns = 2**$ttlog2;
182   open(RADSCN, "> $receivers");
183 < print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=sc$ns\n" : "h=kf\n");
184 < print RADSCN '#@rfluxmtx ' . "u=Y o=$facedat\n\n";
183 > print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=-sc$ns\n" : "h=-kf\n");
184 > print RADSCN '#@rfluxmtx ' . "u=-Y o=$facedat\n\n";
185   print RADSCN "void glow receiver_face\n0\n0\n4 1 1 1 0\n\n";
186   print RADSCN "receiver_face source f_receiver\n0\n0\n4 0 0 1 180\n\n";
187 < print RADSCN '#@rfluxmtx ' . "u=Y o=$behinddat\n\n";
187 > print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=+sc$ns\n" : "h=+kf\n");
188 > print RADSCN '#@rfluxmtx ' . "u=-Y o=$behinddat\n\n";
189   print RADSCN "void glow receiver_behind\n0\n0\n4 1 1 1 0\n\n";
190   print RADSCN "receiver_behind source b_receiver\n0\n0\n4 0 0 -1 180\n";
191   close RADSCN;
# Line 188 | Line 193 | close RADSCN;
193   $rfluxmtx .= " -n $nproc -c $nsamp";
194   if ( $tensortree != 3 ) {       # Isotropic tensor tree is exception
195          open (RADSCN, "> $fsender");
196 <        print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n");
196 >        print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=-sc$ns\n\n" : "h=-kf\n\n");
197          print RADSCN "void polygon fwd_sender\n0\n0\n12\n";
198 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[4];
199 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[4];
200 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[4];
201 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[4];
198 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[4]-$FEPS;
199 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[4]-$FEPS;
200 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[4]-$FEPS;
201 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[4]-$FEPS;
202          close RADSCN;
203          open (RADSCN, "> $bsender");
204 <        print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n");
205 <        print RADSCN "void polygon fwd_sender\n0\n0\n12\n";
206 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[5];
207 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[5];
208 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[5];
209 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[5];
204 >        print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=+sc$ns\n\n" : "h=+kf\n\n");
205 >        print RADSCN "void polygon bwd_sender\n0\n0\n12\n";
206 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[5]+$FEPS;
207 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[5]+$FEPS;
208 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[5]+$FEPS;
209 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[5]+$FEPS;
210          close RADSCN;
211   }
212 + # Calculate CIE (u',v') from Radiance RGB:
213 + my $CIEuv =     'Xi=.5141*Ri+.3239*Gi+.1620*Bi;' .
214 +                'Yi=.2651*Ri+.6701*Gi+.0648*Bi;' .
215 +                'Zi=.0241*Ri+.1229*Gi+.8530*Bi;' .
216 +                'den=Xi+15*Yi+3*Zi;' .
217 +                'uprime=4*Xi/den;vprime=9*Yi/den;' ;
218   # Create data segments (all the work happens here)
219   if ( $tensortree ) {
220          do_tree_bsdf();
# Line 219 | Line 230 | print "<!-- Created by: genBSDF @savedARGV -->\n";
230   system $wrapper;
231   die "Could not wrap BSDF data\n" if ( $? );
232   # Clean up temporary files and exit
233 < system $rmtmp;
233 > exec $rmtmp;
234  
235   #-------------- End of main program segment --------------#
236  
# Line 295 | Line 306 | sub ttree_out {
306                  my $ttyp = ("tb","tf")[$forw];
307                  ttree_comp($ttyp, "Visible", $transdat, ($tb,$tf)[$forw]);
308                  if ( $docolor ) {
309 <                        ttree_comp($ttyp, "CIE-X", $transdat, ($tbx,$tfx)[$forw]);
310 <                        ttree_comp($ttyp, "CIE-Z", $transdat, ($tbz,$tfz)[$forw]);
309 >                        ttree_comp($ttyp, "CIE-u", $transdat, ($tbx,$tfx)[$forw]);
310 >                        ttree_comp($ttyp, "CIE-v", $transdat, ($tbz,$tfz)[$forw]);
311                  }
312          }
313          # Output reflection
314          my $rtyp = ("rb","rf")[$forw];
315          ttree_comp($rtyp, "Visible", $refldat, ($rb,$rf)[$forw]);
316          if ( $docolor ) {
317 <                ttree_comp($rtyp, "CIE-X", $refldat, ($rbx,$rfx)[$forw]);
318 <                ttree_comp($rtyp, "CIE-Z", $refldat, ($rbz,$rfz)[$forw]);
317 >                ttree_comp($rtyp, "CIE-u", $refldat, ($rbx,$rfx)[$forw]);
318 >                ttree_comp($rtyp, "CIE-v", $refldat, ($rbz,$rfz)[$forw]);
319          }
320   }       # end of ttree_out()
321  
# Line 318 | Line 329 | sub ttree_comp {
329          if ($windoz) {
330                  if ("$spec" eq "Visible") {
331                          $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
332 <                                q{-e "$1=(0.265*$1+0.670*$2+0.065*$3)/Omega"};
333 <                } elsif ("$spec" eq "CIE-X") {
334 <                        $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
335 <                                q{-e "$1=(0.514*$1+0.324*$2+0.162*$3)/Omega"};
336 <                } elsif ("$spec" eq "CIE-Z") {
337 <                        $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
338 <                                q{-e "$1=(0.024*$1+0.123*$2+0.853*$3)/Omega"};
332 >                                q{-e "Ri=$1;Gi=$2;Bi=$3" } .
333 >                                qq{-e "$CIEuv" } .
334 >                                q{-e "$1=Yi/Omega"};
335 >                } elsif ("$spec" eq "CIE-u") {
336 >                        $cmd = q{rcalc -e "Ri=$1;Gi=$2;Bi=$3" } .
337 >                                qq{-e "$CIEuv" } .
338 >                                q{-e "$1=uprime"};
339 >                } elsif ("$spec" eq "CIE-v") {
340 >                        $cmd = q{rcalc -e "Ri=$1;Gi=$2;Bi=$3" } .
341 >                                qq{-e "$CIEuv" } .
342 >                                q{-e "$1=vprime"};
343                  }
344          } else {
345                  if ("$spec" eq "Visible") {
346                          $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
347 <                                q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega'};
348 <                } elsif ("$spec" eq "CIE-X") {
349 <                        $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
350 <                                q{-e '$1=(0.514*$1+0.324*$2+0.162*$3)/Omega'};
351 <                } elsif ("$spec" eq "CIE-Z") {
352 <                        $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
353 <                                q{-e '$1=(0.024*$1+0.123*$2+0.853*$3)/Omega'};
347 >                                q{-e 'Ri=$1;Gi=$2;Bi=$3' } .
348 >                                "-e '$CIEuv' " .
349 >                                q{-e '$1=Yi/Omega'};
350 >                } elsif ("$spec" eq "CIE-u") {
351 >                        $cmd = q{rcalc -if3 -e 'Ri=$1;Gi=$2;Bi=$3' } .
352 >                                "-e '$CIEuv' " .
353 >                                q{-e '$1=uprime'};
354 >                } elsif ("$spec" eq "CIE-v") {
355 >                        $cmd = q{rcalc -if3 -e 'Ri=$1;Gi=$2;Bi=$3' } .
356 >                                "-e '$CIEuv' " .
357 >                                q{-e '$1=vprime'};
358                  }
359          }
360          if ($pctcull >= 0) {
361                  my $avg = ( "$typ" =~ /^r[fb]/ ) ? " -a" : "";
362 +                my $pcull = ("$spec" eq "Visible") ? $pctcull :
363 +                                                     (100 - (100-$pctcull)*.25) ;
364                  if ($windoz) {
365                          $cmd = "rcollate -ho -oc 1 $src | " .
366                                          $cmd .
367 <                                        " | rttree_reduce$avg -h -fa -t $pctcull -r $tensortree -g $ttlog2";
367 >                                        " | rttree_reduce$avg -h -fa -t $pcull -r $tensortree -g $ttlog2";
368                  } else {
369                          $cmd .= " -of $src " .
370 <                                        "| rttree_reduce$avg -h -ff -t $pctcull -r $tensortree -g $ttlog2";
370 >                                        "| rttree_reduce$avg -h -ff -t $pcull -r $tensortree -g $ttlog2";
371                  }
372                  # print STDERR "Running: $cmd\n";
373                  system "$cmd > $dest";
# Line 371 | Line 392 | sub ttree_comp {
392                  close DATOUT;
393          }
394          if ( "$spec" ne "$curspec" ) {
395 <                $wrapper .= " -s $spec"
395 >                $wrapper .= " -s $spec";
396                  $curspec = $spec;
397          }
398          $wrapper .= " -$typ $dest";
# Line 434 | Line 455 | sub matrix_comp {
455          my $dest = shift;
456          my $cmd = "rmtxop -fa -t";
457          if ("$spec" eq "Visible") {
458 <                $cmd .= " -c 0.265 0.670 0.065";
458 >                $cmd .= " -c 0.2651 0.6701 0.0648";
459          } elsif ("$spec" eq "CIE-X") {
460 <                $cmd .= " -c 0.514 0.324 0.162";
460 >                $cmd .= " -c 0.5141 0.3239 0.1620";
461          } elsif ("$spec" eq "CIE-Z") {
462 <                $cmd .= " -c 0.024 0.123 0.853";
462 >                $cmd .= " -c 0.0241 0.1229 0.8530";
463          }
464 <        $cmd .= " $src | rcollate -ho";
464 >        $cmd .= " $src | rcollate -ho -oc 145";
465          # print STDERR "Running: $cmd\n";
466          system "$cmd > $dest";
467          die "Failure running rttree_reduce" if ( $? );
468          if ( "$spec" ne "$curspec" ) {
469 <                $wrapper .= " -s $spec"
469 >                $wrapper .= " -s $spec";
470                  $curspec = $spec;
471          }
472          $wrapper .= " -$typ $dest";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines