ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ltpict.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

# User Rev Content
1 greg 2.1 #!/usr/bin/perl
2    
3     # Make a four-view picture of the photometry of a luminaire
4     #
5     # This is inspired by objpict.pl that renders four-view
6     # images of objects that are not light sources.
7     #
8     # Written by Axel Jacobs <[email protected]>
9    
10     use strict;
11     use warnings;
12    
13     use File::Temp qw/ tempdir /;
14     my $td = tempdir( CLEANUP => 1 );
15    
16     my $res = 1024; # Default output image dimensions. Same as objpict.
17     my $tiny = 0.01;
18     my $maxsize = 0.001; # max luminaire size after scaling
19     my $is_ies = 0;
20    
21     my $ies = "$td/dist.ies";
22     my $lumi = "$td/lumi.rad"; # Fitting given on cmd line, or generated by ies2rad
23     my $lumi2 = "$td/lumi2.rad"; # Fitting scaled to size
24     my $mat = "$td/lt.mat";
25     my $room1 = "$td/room1.rad";
26     my $room2 = "$td/room2.rad";
27     my $room3 = "$td/room3.rad";
28     my $room4 = "$td/room4.rad";
29     my $oct1 = "$td/lt1.oct";
30     my $oct2 = "$td/lt2.oct";
31     my $oct3 = "$td/lt3.oct";
32     my $oct4 = "$td/lt4.oct";
33    
34     # Parse command line arguments
35     while (@ARGV) {
36     $_ = $ARGV[0];
37     if (m/-i/) { # File is an IES file, not a Radiance luminaire
38     $is_ies = 1;
39     } elsif (m/-d/) { # Resolution of the output HDR image
40     $res = $ARGV[1];
41     shift @ARGV;
42     } elsif (m/^-\w/) { # Oops! Illegal option
43     die("ltpict: bad option '$_'\n");
44     } else {
45     last; # No more options. What's left is the actual file name.
46     }
47     shift @ARGV;
48     }
49    
50     if ($is_ies == 0) {
51     # Input file is a Radiance luminaire
52     $lumi = $ARGV[0];
53     } else {
54     # Input file is IES photometry
55     system "ies2rad -p $td -o lumi $ARGV[0]";
56     }
57    
58     my $res2 = $res / 2; # Each rendering is half the size of final composite
59    
60     # Scale luminaire and center at origin
61     my $dimstr = `getbbox -h $lumi`;
62     chomp $dimstr;
63     # Values returned by getbbox are indented and delimited with multiple spaces.
64     $dimstr =~ s/^\s+//; # remove leading spaces
65     my @dims = split(/\s+/, $dimstr); # convert to array
66    
67     # Find largest axes-aligned dimension
68     my @diffs = ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]);
69     @diffs = reverse sort { $a <=> $b } @diffs;
70     my $size = $diffs[0];
71    
72     # Move luminaire so centre is at origin, and scale
73     my $xtrans = -1.0 * ($dims[0] + $dims[1]) / 2;
74     my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2;
75     my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2;
76     my $scale = $maxsize / $size;
77    
78     open(FH, ">$lumi2") or
79     die("ltpict: Cannot write to temporary file $lumi");
80     print FH "!xform -t $xtrans $ytrans $ztrans -s $scale $lumi";
81     close FH;
82    
83    
84     # Material for the room
85     open(FH, ">$mat") or
86     die("ltpict: Cannot write to temporary file $mat");
87     print FH "void plastic wall_mat 0 0 5 .5 .5 .5 0 0";
88     close FH;
89    
90    
91     # Different 'room' geometry for different views
92     my $o = 0.1; # Offset
93    
94     # C0-C180
95     open(FH, ">$room1") or
96     die("ltpict: Cannot write to temporary file $room1");
97     print FH "wall_mat polygon box.4620 0 0 12 -$o -5 5 -$o 5 5 -$o 5 -5 -$o -5 -5";
98     close(FH);
99    
100     # C90-C270
101     open(FH, ">$room2") or
102     die("ltpict: Cannot write to temporary file $room2");
103     print FH "wall_mat polygon box.1540 0 0 12 5 $o -5 5 $o 5 -5 $o 5 -5 $o -5";
104     close(FH);
105    
106     # Lower hemisphere
107     open(FH, ">$room3") or
108     die("ltpict: Cannot write to temporary file $room3");
109     print FH "wall_mat bubble lower 0 0 4 0 0 $dims[4] 5";
110     close(FH);
111    
112     # Upper hemisphere
113     open(FH, ">$room4") or
114     die("ltpict: Cannot write to temporary file $room4");
115     print FH "wall_mat bubble upper 0 0 4 0 0 $dims[5] 5";
116     close(FH);
117    
118    
119     # Call bbox again, for the translated and scaled luminaire.
120     $dimstr = `getbbox -h $lumi2`;
121     chomp $dimstr;
122     # Values returned by getbbox are indented and delimited with multiple spaces.
123     $dimstr =~ s/^\s+//; # remove leading spaces
124     @dims = split(/\s+/, $dimstr); # convert to array
125    
126     # Define the four views
127     my $vw1 = "-vtl -vp 4.5 0 0 -vd -1 0 0 -vh 10 -vv 10";
128     my $vw2 = "-vtl -vp 0 -4.5 0 -vd 0 1 0 -vh 10 -vv 10";
129     my $zcent3 = $dims[4] - $tiny;
130     my $vw3 = "-vta -vp 0 0 $zcent3 -vd 0 0 -1 -vu 0 1 0 -vh 180 -vv 180";
131     my $zcent4 = $dims[5] + $tiny;
132     my $vw4 = "-vta -vp 0 0 $zcent4 -vd 0 0 1 -vu 0 1 0 -vh 180 -vv 180";
133    
134     system "oconv $mat $room1 $lumi2 > $oct1";
135     system "oconv $mat $room2 $lumi2 > $oct2";
136     system "oconv $mat $room3 $lumi2 > $oct3";
137     system "oconv $mat $room4 $lumi2 > $oct4";
138    
139     # Render four different views of the objects
140     my $rpict_cmd = "rpict -ab 0 -ds 0 -dv -av 0 0 0 -x $res2 -y $res2";
141     system "$rpict_cmd $vw1 $oct1 > $td/right.hdr";
142     system "$rpict_cmd $vw2 $oct2 > $td/front.hdr";
143     system "$rpict_cmd $vw3 $oct3 > $td/down.hdr";
144     system "$rpict_cmd $vw4 $oct4 > $td/up.hdr";
145    
146     # Compose the four views into one image
147     my $vtl = "$td/vtl.hdr"; # The two parallel views
148     my $vta = "$td/vta.hdr"; # The two fisheye views
149    
150     # Auto-expose right/front and down/up pairs separately
151     my $pcond_cmd = "pcond -l";
152     system "pcompos -a 2 $td/right.hdr $td/front.hdr > $td/rf.hdr";
153     system "$pcond_cmd $td/rf.hdr > $vtl";
154     system "pcompos -a 2 $td/down.hdr $td/up.hdr > $td/du.hdr";
155     system "$pcond_cmd $td/du.hdr > $vta";
156    
157     # Combine top two images with bottom row. Output HDR.
158     exec "pcompos -a 1 $vtl $vta";
159    
160     #EOF