10 |
|
use strict; |
11 |
|
use warnings; |
12 |
|
use Math::Trig; |
13 |
– |
use File::Copy qw(copy); |
13 |
|
use File::Temp qw/ tempdir /; |
14 |
|
|
15 |
< |
my $td = tempdir( CLEANUP => 1 ); |
16 |
< |
my $oct = "$td/ltview.oct"; |
17 |
< |
my $room = "$td/room.rad"; |
18 |
< |
my $box; # Overall box dimensions |
19 |
< |
my $default_box = 10; # Default box dimensions |
20 |
< |
my $rif = "$td/ltview.rif"; |
21 |
< |
my $lumi = "$td/lumi.rad"; # Fitting as given on cmd line, or generated by ies2rad |
22 |
< |
my $lumi2 = "$td/lumi2.rad"; # Fitting scaled to max unity |
23 |
< |
my $raddev = "x11"; # default output device. Overwrite with -o |
25 |
< |
my $is_ies = 0; # input file is IES photometry, not a Radiance luminaire |
15 |
> |
my $td = tempdir( CLEANUP => 1 ); |
16 |
> |
my $oct = "$td/ltview.oct"; |
17 |
> |
my $room = "$td/room.rad"; |
18 |
> |
my $box; # Overall box dimensions |
19 |
> |
my $rif = "$td/ltview.rif"; |
20 |
> |
my $lumi = "$td/lumi.rad"; # Fitting as given on cmd line, or generated by ies2rad |
21 |
> |
my $lumi2 = "$td/lumi2.rad"; # Fitting centred at origin |
22 |
> |
my $raddev = "x11"; # Default output device. Overwrite with -o |
23 |
> |
my $is_ies = 0; # Input file is IES photometry, not a Radiance luminaire |
24 |
|
|
27 |
– |
my $maxscale = 1; # Maximum luminiare dimension after scaling |
28 |
– |
my $opts = ""; # Options common to rad and glrad |
29 |
– |
my $render = "-ab 1 -ds .15 -av 0 0 0"; # render= line in rif file |
30 |
– |
my $radopt = 0; # An option specific to rad was passed (Boolean). |
31 |
– |
|
25 |
|
while (@ARGV) { |
26 |
< |
$_ = $ARGV[0]; |
27 |
< |
if (m/-i/) { |
28 |
< |
$is_ies = 1; |
29 |
< |
} elsif (m/-o/) { # output device (rvu -devices) |
30 |
< |
$raddev = $ARGV[1]; |
31 |
< |
$radopt = 1; |
32 |
< |
shift @ARGV; |
33 |
< |
} elsif (m/-b/) { |
34 |
< |
$box = $ARGV[1]; # Box dimensions |
35 |
< |
shift @ARGV; |
36 |
< |
} elsif (m/^-\w/) { |
37 |
< |
die("objview: Bad option: '$_'\n"); |
38 |
< |
} else { |
39 |
< |
last; |
40 |
< |
} |
48 |
< |
shift @ARGV; |
26 |
> |
$_ = $ARGV[0]; |
27 |
> |
if (m/-i/) { |
28 |
> |
$is_ies = 1; |
29 |
> |
} elsif (m/-o/) { # output device (rvu -devices) |
30 |
> |
$raddev = $ARGV[1]; |
31 |
> |
shift @ARGV; |
32 |
> |
} elsif (m/-b/) { |
33 |
> |
$box = $ARGV[1]; # Box dimensions |
34 |
> |
shift @ARGV; |
35 |
> |
} elsif (m/^-\w/) { |
36 |
> |
die("ltview: Bad option: '$_'\n"); |
37 |
> |
} else { |
38 |
> |
last; |
39 |
> |
} |
40 |
> |
shift @ARGV; |
41 |
|
} |
42 |
|
|
43 |
|
# We need exactly one Radiance luminaires or IES file |
44 |
< |
if (! $#ARGV == 0) { |
45 |
< |
die("ltview: Need one Radiance luminaire or IES file.\n"); |
46 |
< |
} |
44 |
> |
if ( !$#ARGV == 0 ) { |
45 |
> |
die("ltview: Need one Radiance luminaire or IES file.\n"); |
46 |
> |
} elsif ( $is_ies == 0 ) { |
47 |
|
|
48 |
< |
if ($is_ies == 0) { |
49 |
< |
# Input file is a Radiance luminaire |
58 |
< |
$lumi = $ARGV[0]; |
48 |
> |
# Input file is a Radiance luminaire |
49 |
> |
$lumi = $ARGV[0]; |
50 |
|
} else { |
51 |
< |
# Input file is IES photometry |
52 |
< |
system "ies2rad -p $td -o lumi $ARGV[0]"; |
51 |
> |
|
52 |
> |
# Input file is IES photometry |
53 |
> |
system qq[ ies2rad -p $td -o lumi "$ARGV[0]" ]; |
54 |
|
} |
55 |
|
|
56 |
+ |
# Work out centre of luminaire |
57 |
+ |
my $dimstr = `getbbox -h "$lumi"`; |
58 |
+ |
chomp $dimstr; |
59 |
|
|
60 |
< |
open(FH, ">$room") or |
61 |
< |
die("ltview: Can't write to temporary file '$room'\n"); |
62 |
< |
print FH "void plastic wall_mat 0 0 5 .2 .2 .2 0 0\n"; |
60 |
> |
# Values returned by getbbox are indented and delimited with multiple spaces. |
61 |
> |
$dimstr =~ s/^\s+//; # remove leading spaces |
62 |
> |
my @dims = split( /\s+/, $dimstr ); # convert to array |
63 |
|
|
64 |
+ |
# Find largest axes-aligned luminaire dimension |
65 |
+ |
# The box will be ten times as large, unless overwritten with -b option. |
66 |
+ |
my @diffs = reverse sort { $a <=> $b } |
67 |
+ |
( $dims[1] - $dims[0], $dims[3] - $dims[2], $dims[5] - $dims[4] ); |
68 |
+ |
my $lsize = $diffs[0]; |
69 |
+ |
|
70 |
+ |
# Centre fitting at origin |
71 |
+ |
my $xtrans = -1.0 * ( $dims[0] + $dims[1] ) / 2; |
72 |
+ |
my $ytrans = -1.0 * ( $dims[2] + $dims[3] ) / 2; |
73 |
+ |
my $ztrans = -1.0 * ( $dims[4] + $dims[5] ) / 2; |
74 |
+ |
system qq[ xform -t $xtrans $ytrans $ztrans "$lumi" > $lumi2 ]; |
75 |
+ |
|
76 |
+ |
# Make the enclosing box |
77 |
|
my $b2; |
78 |
< |
if (defined $box) { |
71 |
< |
# Room dimensions are giving explicitly. Don't touch the fitting. |
72 |
< |
$b2 = $box / 2; |
78 |
> |
if ( defined $box ) { |
79 |
|
|
80 |
< |
$lumi2 = $ARGV[0]; |
80 |
> |
# Room dimensions are giving explicitly. |
81 |
> |
$b2 = $box / 2; |
82 |
|
} else { |
76 |
– |
# Scale fitting so it fits nicely into our default test room. |
77 |
– |
$b2 = $default_box; # Default room dimension |
83 |
|
|
84 |
< |
# Work out how large the luminaire is and scale so that the longest |
85 |
< |
# axis-align dimension is $maxscale |
81 |
< |
my $dimstr = `getbbox -h $lumi`; |
82 |
< |
chomp $dimstr; |
83 |
< |
# Values returned by getbbox are indented and delimited with multiple spaces. |
84 |
< |
$dimstr =~ s/^\s+//; # remove leading spaces |
85 |
< |
my @dims = split(/\s+/, $dimstr); # convert to array |
86 |
< |
|
87 |
< |
# Find largest axes-aligned dimension |
88 |
< |
my @diffs = ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]); |
89 |
< |
@diffs = reverse sort { $a <=> $b } @diffs; |
90 |
< |
my $size = $diffs[0]; |
91 |
< |
|
92 |
< |
# Move objects so centre is at origin |
93 |
< |
my $xtrans = -1.0 * ($dims[0] + $dims[1]) / 2; |
94 |
< |
my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2; |
95 |
< |
my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2; |
96 |
< |
# Scale so that largest object dimension is $maxscale |
97 |
< |
my $scale = $maxscale / $size; |
98 |
< |
|
99 |
< |
#system "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi"; |
100 |
< |
system "xform -t $xtrans $ytrans $ztrans -s $scale $lumi > $lumi2"; |
84 |
> |
# Box dimensions are ten times largest luminaire bbox dimensions. |
85 |
> |
$b2 = $lsize * 10.0 / 2.0; |
86 |
|
} |
87 |
|
|
88 |
+ |
open( FH, ">$room" ) |
89 |
+ |
or die("ltview: Can't write to temporary file '$room'\n"); |
90 |
|
print FH <<EndOfRoom; |
91 |
< |
# Don't generate -y face so we can look into the box (could use clipping) |
91 |
> |
void plastic wall_mat 0 0 5 .2 .2 .2 0 0 |
92 |
> |
|
93 |
> |
# Don't generate -y face so we can look into the box |
94 |
|
#wall_mat polygon box.1540 0 0 12 $b2 -$b2 -$b2 $b2 -$b2 $b2 -$b2 -$b2 $b2 -$b2 -$b2 -$b2 |
95 |
|
wall_mat polygon box.4620 0 0 12 -$b2 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2 |
96 |
|
wall_mat polygon box.2310 0 0 12 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2 -$b2 |
100 |
|
EndOfRoom |
101 |
|
close(FH); |
102 |
|
|
103 |
< |
my $scene = "$room $lumi"; |
103 |
> |
my $scene = "$room $lumi2"; |
104 |
> |
|
105 |
|
# Make this work under Windoze |
106 |
|
if ( $^O =~ /MSWin32/ ) { |
107 |
< |
$scene =~ s{\\}{/}g; |
108 |
< |
$oct =~ s{\\}{/}g; |
109 |
< |
$raddev = "qt"; |
107 |
> |
$scene =~ s{\\}{/}g; |
108 |
> |
$oct =~ s{\\}{/}g; |
109 |
> |
$raddev = "qt"; |
110 |
|
} |
111 |
|
|
112 |
< |
# Tweak bounding box so we get a nice view covering all of the box, without |
112 |
> |
# Tweak scene bounding box so we get a nice view covering all of the box, without |
113 |
|
# having a wasteful black border around it. Must work for arbitrary box dims. |
114 |
< |
my $zone = 1.1 * $b2 * ( 1 + 1/tan(22.5*pi/180) ); |
114 |
> |
my $zone = 1.1 * $b2 * ( 1 + 1 / tan( 22.5 * pi / 180 ) ); |
115 |
|
|
116 |
< |
open(FH, ">$rif") or |
117 |
< |
die("ltview: Can't write to temporary file '$rif'\n"); |
116 |
> |
open( FH, ">$rif" ) |
117 |
> |
or die("ltview: Can't write to temporary file '$rif'\n"); |
118 |
|
print FH <<EndOfRif; |
119 |
|
scene= $scene |
130 |
– |
EXPOSURE= 2 |
120 |
|
ZONE= Interior -$zone $zone -$zone $zone -$zone $zone |
121 |
|
UP= Z |
122 |
|
view= y |
123 |
|
OCTREE= $oct |
124 |
|
oconv= -f |
125 |
< |
render= $render |
125 |
> |
render= -av 0 0 0 |
126 |
> |
INDIRECT= 0 |
127 |
> |
QUALITY= Med |
128 |
> |
DETAIL= Low |
129 |
> |
VARIABILITY= Med |
130 |
|
EndOfRif |
131 |
|
close(FH); |
132 |
|
|
133 |
< |
exec "rad -o $raddev $opts $rif"; |
133 |
> |
exec "rad -o $raddev $rif"; |
134 |
|
|
135 |
|
#EOF |