ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ltview.pl
Revision: 2.1
Committed: Tue Apr 15 22:36:25 2014 UTC (10 years ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Added ltview and ltpict scripts

File Contents

# Content
1 #!/usr/bin/perl
2 #
3 # Make an interactive preview of a luminaire
4 #
5 # This script is based on Radiance's objview.pl plus
6 # Rob Guglielmetti's ltview extension to his objview.rb
7 #
8 # Written by Axel Jacobs <[email protected]>
9
10 use strict;
11 use warnings;
12 use Math::Trig;
13 use File::Copy qw(copy);
14 use File::Temp qw/ tempdir /;
15
16 my $td = tempdir( CLEANUP => 1 );
17 my $oct = "$td/ltview.oct";
18 my $room = "$td/room.rad";
19 my $box; # Overall box dimensions
20 my $default_box = 10; # Default box dimensions
21 my $rif = "$td/ltview.rif";
22 my $lumi = "$td/lumi.rad"; # Fitting as given on cmd line, or generated by ies2rad
23 my $lumi2 = "$td/lumi2.rad"; # Fitting scaled to max unity
24 my $raddev = "x11"; # default output device. Overwrite with -o
25 my $is_ies = 0; # input file is IES photometry, not a Radiance luminaire
26
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
32 while (@ARGV) {
33 $_ = $ARGV[0];
34 if (m/-i/) {
35 $is_ies = 1;
36 } elsif (m/-o/) { # output device (rvu -devices)
37 $raddev = $ARGV[1];
38 $radopt = 1;
39 shift @ARGV;
40 } elsif (m/-b/) {
41 $box = $ARGV[1]; # Box dimensions
42 shift @ARGV;
43 } elsif (m/^-\w/) {
44 die("objview: Bad option: '$_'\n");
45 } else {
46 last;
47 }
48 shift @ARGV;
49 }
50
51 # We need exactly one Radiance luminaires or IES file
52 if (! $#ARGV == 0) {
53 die("ltview: Need one Radiance luminaire or IES file.\n");
54 }
55
56 if ($is_ies == 0) {
57 # Input file is a Radiance luminaire
58 $lumi = $ARGV[0];
59 } else {
60 # Input file is IES photometry
61 system "ies2rad -p $td -o lumi $ARGV[0]";
62 }
63
64
65 open(FH, ">$room") or
66 die("ltview: Can't write to temporary file '$room'\n");
67 print FH "void plastic wall_mat 0 0 5 .2 .2 .2 0 0\n";
68
69 my $b2;
70 if (defined $box) {
71 # Room dimensions are giving explicitly. Don't touch the fitting.
72 $b2 = $box / 2;
73
74 $lumi2 = $ARGV[0];
75 } else {
76 # Scale fitting so it fits nicely into our default test room.
77 $b2 = $default_box; # Default room dimension
78
79 # Work out how large the luminaire is and scale so that the longest
80 # 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";
101 }
102
103 print FH <<EndOfRoom;
104 # Don't generate -y face so we can look into the box (could use clipping)
105 #wall_mat polygon box.1540 0 0 12 $b2 -$b2 -$b2 $b2 -$b2 $b2 -$b2 -$b2 $b2 -$b2 -$b2 -$b2
106 wall_mat polygon box.4620 0 0 12 -$b2 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2
107 wall_mat polygon box.2310 0 0 12 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2 -$b2
108 wall_mat polygon box.3267 0 0 12 $b2 $b2 -$b2 -$b2 $b2 -$b2 -$b2 $b2 $b2 $b2 $b2 $b2
109 wall_mat polygon box.5137 0 0 12 $b2 -$b2 $b2 $b2 -$b2 -$b2 $b2 $b2 -$b2 $b2 $b2 $b2
110 wall_mat polygon box.6457 0 0 12 -$b2 $b2 $b2 -$b2 -$b2 $b2 $b2 -$b2 $b2 $b2 $b2 $b2
111 EndOfRoom
112 close(FH);
113
114 my $scene = "$room $lumi";
115 # Make this work under Windoze
116 if ( $^O =~ /MSWin32/ ) {
117 $scene =~ s{\\}{/}g;
118 $oct =~ s{\\}{/}g;
119 $raddev = "qt";
120 }
121
122 # Tweak bounding box so we get a nice view covering all of the box, without
123 # having a wasteful black border around it. Must work for arbitrary box dims.
124 my $zone = 1.1 * $b2 * ( 1 + 1/tan(22.5*pi/180) );
125
126 open(FH, ">$rif") or
127 die("ltview: Can't write to temporary file '$rif'\n");
128 print FH <<EndOfRif;
129 scene= $scene
130 EXPOSURE= 2
131 ZONE= Interior -$zone $zone -$zone $zone -$zone $zone
132 UP= Z
133 view= y
134 OCTREE= $oct
135 oconv= -f
136 render= $render
137 EndOfRif
138 close(FH);
139
140 exec "rad -o $raddev $opts $rif";
141
142 #EOF