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.52 by greg, Mon Mar 16 00:40:51 2015 UTC vs.
Revision 2.64 by greg, Wed Jul 13 00:51:17 2016 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 39 | Line 39 | if ($windoz) {
39          $tbz = "$td\\tbz.dat";
40          $rbz = "$td\\rbz.dat";
41          chomp $td;
42 <        $rmtmp = "rmdir /S /Q $td";
42 >        $rmtmp = "rd /S /Q $td";
43   } else {
44          $td = mkdtemp("/tmp/genBSDF.XXXXXX");
45          chomp $td;
# 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 149 | Line 152 | if ( $mgfin ) {
152   if ($#dim != 5) {
153          @dim = split ' ', `getbbox -h $radscn`;
154   }
155 < print STDERR "Warning: Device extends into room\n" if ($dim[5] > 1e-5);
156 < $wrapper .= ' -f "t=' . ($dim[5] - $dim[4]) . ';w=' . ($dim[1] - $dim[0]) .
155 > die "Device entirely inside room!\n" if ($dim[4] >= 0);
156 > if ($dim[5] > 1e-5) {
157 >        print STDERR "Warning: Device extends into room\n";
158 > } elsif ($dim[5]*$dim[5] < .01*($dim[1]-$dim[0])*($dim[3]-$dim[2])) {
159 >        print STDERR "Warning: Device far behind Z==0 plane\n";
160 > }
161 > # Assume Zmax==0 to derive thickness so pkgBSDF will work
162 > $wrapper .= ' -f "t=' . (-$dim[4]) . ';w=' . ($dim[1] - $dim[0]) .
163                  ';h=' . ($dim[3] - $dim[2]) . '"';
164   # Generate octree
165   system "oconv -w $radscn > $octree";
# Line 171 | Line 180 | if ( $geout ) {
180          $wrapper .= " -g $mgfscn";
181   }
182   # Create receiver & sender surfaces (rectangular)
183 + my $FEPS = 1e-5;
184   my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1);
185   my $ny = int($nsamp/$nx + 1);
186   $nsamp = $nx * $ny;
187   my $ns = 2**$ttlog2;
188   open(RADSCN, "> $receivers");
189 < print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=sc$ns\n" : "h=kf\n");
190 < print RADSCN '#@rfluxmtx ' . "u=Y o=$facedat\n\n";
189 > print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=-sc$ns\n" : "h=-kf\n");
190 > print RADSCN '#@rfluxmtx ' . "u=-Y o=$facedat\n\n";
191   print RADSCN "void glow receiver_face\n0\n0\n4 1 1 1 0\n\n";
192   print RADSCN "receiver_face source f_receiver\n0\n0\n4 0 0 1 180\n\n";
193 < print RADSCN '#@rfluxmtx ' . "u=Y o=$behinddat\n\n";
193 > print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=+sc$ns\n" : "h=+kf\n");
194 > print RADSCN '#@rfluxmtx ' . "u=-Y o=$behinddat\n\n";
195   print RADSCN "void glow receiver_behind\n0\n0\n4 1 1 1 0\n\n";
196   print RADSCN "receiver_behind source b_receiver\n0\n0\n4 0 0 -1 180\n";
197   close RADSCN;
# Line 188 | Line 199 | close RADSCN;
199   $rfluxmtx .= " -n $nproc -c $nsamp";
200   if ( $tensortree != 3 ) {       # Isotropic tensor tree is exception
201          open (RADSCN, "> $fsender");
202 <        print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n");
202 >        print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=-sc$ns\n\n" : "h=-kf\n\n");
203          print RADSCN "void polygon fwd_sender\n0\n0\n12\n";
204 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[4];
205 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[4];
206 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[4];
207 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[4];
204 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[4]-$FEPS;
205 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[4]-$FEPS;
206 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[4]-$FEPS;
207 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[4]-$FEPS;
208          close RADSCN;
209          open (RADSCN, "> $bsender");
210 <        print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n");
211 <        print RADSCN "void polygon fwd_sender\n0\n0\n12\n";
212 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[5];
213 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[5];
214 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[5];
215 <        printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[5];
210 >        print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=+sc$ns\n\n" : "h=+kf\n\n");
211 >        print RADSCN "void polygon bwd_sender\n0\n0\n12\n";
212 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[5]+$FEPS;
213 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[5]+$FEPS;
214 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[5]+$FEPS;
215 >        printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[5]+$FEPS;
216          close RADSCN;
217   }
218 + # Calculate CIE (u',v') from Radiance RGB:
219 + my $CIEuv =     'Xi=.5141*Ri+.3239*Gi+.1620*Bi;' .
220 +                'Yi=.2651*Ri+.6701*Gi+.0648*Bi;' .
221 +                'Zi=.0241*Ri+.1229*Gi+.8530*Bi;' .
222 +                'den=Xi+15*Yi+3*Zi;' .
223 +                'uprime=4*Xi/den;vprime=9*Yi/den;' ;
224   # Create data segments (all the work happens here)
225   if ( $tensortree ) {
226          do_tree_bsdf();
# Line 211 | Line 228 | if ( $tensortree ) {
228          do_matrix_bsdf();
229   }
230   # Output XML
214 my $old_fh = select(STDOUT);
215 $| = 1;
216 select($old_fh);
217 print "<!-- Created by: genBSDF @savedARGV -->\n";
231   # print STDERR "Running: $wrapper\n";
232 < system $wrapper;
232 > system "$wrapper -C \"Created by: genBSDF @savedARGV\"";
233   die "Could not wrap BSDF data\n" if ( $? );
234   # Clean up temporary files and exit
235 < system $rmtmp;
235 > exec $rmtmp;
236  
237   #-------------- End of main program segment --------------#
238  
# Line 295 | Line 308 | sub ttree_out {
308                  my $ttyp = ("tb","tf")[$forw];
309                  ttree_comp($ttyp, "Visible", $transdat, ($tb,$tf)[$forw]);
310                  if ( $docolor ) {
311 <                        ttree_comp($ttyp, "CIE-X", $transdat, ($tbx,$tfx)[$forw]);
312 <                        ttree_comp($ttyp, "CIE-Z", $transdat, ($tbz,$tfz)[$forw]);
311 >                        ttree_comp($ttyp, "CIE-u", $transdat, ($tbx,$tfx)[$forw]);
312 >                        ttree_comp($ttyp, "CIE-v", $transdat, ($tbz,$tfz)[$forw]);
313                  }
314          }
315          # Output reflection
316          my $rtyp = ("rb","rf")[$forw];
317          ttree_comp($rtyp, "Visible", $refldat, ($rb,$rf)[$forw]);
318          if ( $docolor ) {
319 <                ttree_comp($rtyp, "CIE-X", $refldat, ($rbx,$rfx)[$forw]);
320 <                ttree_comp($rtyp, "CIE-Z", $refldat, ($rbz,$rfz)[$forw]);
319 >                ttree_comp($rtyp, "CIE-u", $refldat, ($rbx,$rfx)[$forw]);
320 >                ttree_comp($rtyp, "CIE-v", $refldat, ($rbz,$rfz)[$forw]);
321          }
322   }       # end of ttree_out()
323  
# Line 318 | Line 331 | sub ttree_comp {
331          if ($windoz) {
332                  if ("$spec" eq "Visible") {
333                          $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
334 <                                q{-e "$1=(0.265*$1+0.670*$2+0.065*$3)/Omega"};
335 <                } elsif ("$spec" eq "CIE-X") {
336 <                        $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
337 <                                q{-e "$1=(0.514*$1+0.324*$2+0.162*$3)/Omega"};
338 <                } elsif ("$spec" eq "CIE-Z") {
339 <                        $cmd = qq{rcalc -e "Omega:PI/($ns*$ns)" } .
340 <                                q{-e "$1=(0.024*$1+0.123*$2+0.853*$3)/Omega"};
334 >                                q{-e "Ri=$1;Gi=$2;Bi=$3" } .
335 >                                qq{-e "$CIEuv" } .
336 >                                q{-e "$1=Yi/Omega"};
337 >                } elsif ("$spec" eq "CIE-u") {
338 >                        $cmd = q{rcalc -e "Ri=$1;Gi=$2;Bi=$3" } .
339 >                                qq{-e "$CIEuv" } .
340 >                                q{-e "$1=uprime"};
341 >                } elsif ("$spec" eq "CIE-v") {
342 >                        $cmd = q{rcalc -e "Ri=$1;Gi=$2;Bi=$3" } .
343 >                                qq{-e "$CIEuv" } .
344 >                                q{-e "$1=vprime"};
345                  }
346          } else {
347                  if ("$spec" eq "Visible") {
348                          $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
349 <                                q{-e '$1=(0.265*$1+0.670*$2+0.065*$3)/Omega'};
350 <                } elsif ("$spec" eq "CIE-X") {
351 <                        $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
352 <                                q{-e '$1=(0.514*$1+0.324*$2+0.162*$3)/Omega'};
353 <                } elsif ("$spec" eq "CIE-Z") {
354 <                        $cmd = "rcalc -if3 -e 'Omega:PI/($ns*$ns)' " .
355 <                                q{-e '$1=(0.024*$1+0.123*$2+0.853*$3)/Omega'};
349 >                                q{-e 'Ri=$1;Gi=$2;Bi=$3' } .
350 >                                "-e '$CIEuv' " .
351 >                                q{-e '$1=Yi/Omega'};
352 >                } elsif ("$spec" eq "CIE-u") {
353 >                        $cmd = q{rcalc -if3 -e 'Ri=$1;Gi=$2;Bi=$3' } .
354 >                                "-e '$CIEuv' " .
355 >                                q{-e '$1=uprime'};
356 >                } elsif ("$spec" eq "CIE-v") {
357 >                        $cmd = q{rcalc -if3 -e 'Ri=$1;Gi=$2;Bi=$3' } .
358 >                                "-e '$CIEuv' " .
359 >                                q{-e '$1=vprime'};
360                  }
361          }
362          if ($pctcull >= 0) {
363                  my $avg = ( "$typ" =~ /^r[fb]/ ) ? " -a" : "";
364 +                my $pcull = ("$spec" eq "Visible") ? $pctcull :
365 +                                                     (100 - (100-$pctcull)*.25) ;
366                  if ($windoz) {
367                          $cmd = "rcollate -ho -oc 1 $src | " .
368                                          $cmd .
369 <                                        " | rttree_reduce$avg -h -fa -t $pctcull -r $tensortree -g $ttlog2";
369 >                                        " | rttree_reduce$avg -h -fa -t $pcull -r $tensortree -g $ttlog2";
370                  } else {
371                          $cmd .= " -of $src " .
372 <                                        "| rttree_reduce$avg -h -ff -t $pctcull -r $tensortree -g $ttlog2";
372 >                                        "| rttree_reduce$avg -h -ff -t $pcull -r $tensortree -g $ttlog2";
373                  }
374                  # print STDERR "Running: $cmd\n";
375                  system "$cmd > $dest";
# Line 434 | Line 457 | sub matrix_comp {
457          my $dest = shift;
458          my $cmd = "rmtxop -fa -t";
459          if ("$spec" eq "Visible") {
460 <                $cmd .= " -c 0.265 0.670 0.065";
460 >                $cmd .= " -c 0.2651 0.6701 0.0648";
461          } elsif ("$spec" eq "CIE-X") {
462 <                $cmd .= " -c 0.514 0.324 0.162";
462 >                $cmd .= " -c 0.5141 0.3239 0.1620";
463          } elsif ("$spec" eq "CIE-Z") {
464 <                $cmd .= " -c 0.024 0.123 0.853";
464 >                $cmd .= " -c 0.0241 0.1229 0.8530";
465          }
466          $cmd .= " $src | rcollate -ho -oc 145";
467          # print STDERR "Running: $cmd\n";
468          system "$cmd > $dest";
469 <        die "Failure running rttree_reduce" if ( $? );
469 >        die "Failure running rmtxop" if ( $? );
470          if ( "$spec" ne "$curspec" ) {
471                  $wrapper .= " -s $spec";
472                  $curspec = $spec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines