| 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); |
| 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 ' . ($tensortree ? "h=-sc$ns\n" : "h=-kf\n"); |
| 188 |
< |
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; |
| 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"); |
| 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%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]; |
| 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: |
| 222 |
|
do_matrix_bsdf(); |
| 223 |
|
} |
| 224 |
|
# Output XML |
| 224 |
– |
my $old_fh = select(STDOUT); |
| 225 |
– |
$| = 1; |
| 226 |
– |
select($old_fh); |
| 227 |
– |
print "<!-- Created by: genBSDF @savedARGV -->\n"; |
| 225 |
|
# print STDERR "Running: $wrapper\n"; |
| 226 |
< |
system $wrapper; |
| 226 |
> |
system "$wrapper -C 'Created by: genBSDF @savedARGV'"; |
| 227 |
|
die "Could not wrap BSDF data\n" if ( $? ); |
| 228 |
|
# Clean up temporary files and exit |
| 229 |
|
exec $rmtmp; |