| author | Axel Jacobs <axel@jaloxa.eu> |
| Mon, 10 Mar 2014 20:15:36 +0000 | |
| changeset 57 | ce1ccea91e6c |
| parent 56 | 259ce6d95331 |
| child 58 | e4892d4ef026 |
| permissions | -rwxr-xr-x |
| 54 | 1 |
#!/usr/bin/perl |
2 |
||
3 |
# Make a nice multi-view picture of a luminaire |
|
4 |
# |
|
5 |
# This is based on objpict.pl that renders four-view |
|
6 |
# images of objects that are not light sources. |
|
7 |
# |
|
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
8 |
# Written by Axel Jacobs |
| 54 | 9 |
|
10 |
use strict; |
|
11 |
use warnings; |
|
12 |
||
13 |
use File::Temp qw/ tempdir /; |
|
14 |
#my $td = tempdir( CLEANUP => 1 ); |
|
15 |
my $td = "tmp"; |
|
16 |
||
17 |
#my $xres = 1024; |
|
18 |
#my $yres = 1024; |
|
19 |
my $xres = 600; |
|
20 |
my $yres = 600; |
|
21 |
my $tiny = 0.01; |
|
|
55
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
22 |
my $is_ies = 0; |
| 54 | 23 |
my $rpict_cmd = "rpict -ab 0 -ds 0 -dv -av 0 0 0 -x $xres -y $yres"; |
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
24 |
my $pcond_cmd = "pcond -l"; |
| 54 | 25 |
|
|
55
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
26 |
my $ies = "$td/dist.ies"; |
|
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
27 |
my $fittings = "$td/fitting.rad"; |
| 54 | 28 |
my $material = "$td/lt.mat"; |
29 |
my $testroom1 = "$td/testroom1.rad"; |
|
30 |
my $testroom2 = "$td/testroom2.rad"; |
|
31 |
my $testroom3 = "$td/testroom3.rad"; |
|
32 |
my $testroom4 = "$td/testroom4.rad"; |
|
33 |
my $octree1 = "$td/lt1.oct"; |
|
34 |
my $octree2 = "$td/lt2.oct"; |
|
35 |
my $octree3 = "$td/lt3.oct"; |
|
36 |
my $octree4 = "$td/lt4.oct"; |
|
37 |
||
|
55
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
38 |
# Parse command line arguments |
|
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
39 |
if ("$ARGV[0]" eq '-i') { # File is an IES file, not Radiance luminaire
|
|
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
40 |
$is_ies = 1; |
|
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
41 |
shift @ARGV; |
|
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
42 |
} |
| 54 | 43 |
# We need at least one Radiance file or a scene on STDIN (but not both) |
44 |
if ($#ARGV < 0) {
|
|
45 |
open(FH, ">$td/stdin.rad") or |
|
46 |
die("objview: Can't write to temporary file $td/stdin.rad\n");
|
|
47 |
while (<>) {
|
|
48 |
print FH; |
|
49 |
} |
|
50 |
# Pretend stdin.rad was passed as argument. |
|
51 |
@ARGV = ("$td/stdin.rad");
|
|
52 |
} |
|
53 |
||
54 |
||
55 |
# Scale fitting and center at origin |
|
56 |
my $dimstr = `getbbox -h @ARGV`; |
|
57 |
chomp $dimstr; |
|
58 |
# Values returned by getbbox are indented and delimited with multiple spaces. |
|
59 |
$dimstr =~ s/^\s+//; # remove leading spaces |
|
60 |
my @dims = split(/\s+/, $dimstr); # convert to array |
|
61 |
||
62 |
# Find largest axes-aligned dimension |
|
63 |
my @diffs = ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]); |
|
64 |
@diffs = reverse sort { $a <=> $b } @diffs;
|
|
65 |
my $size = $diffs[0]; |
|
66 |
||
67 |
# Move fitting so centre is at origin |
|
68 |
my $xtrans = -1.0 * ($dims[0] + $dims[1]) / 2; |
|
69 |
my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2; |
|
70 |
my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2; |
|
71 |
# Scale so that largest object dimension is unity |
|
|
55
e00e7d28865e
ltpict: Change default scale factor.
Axel Jacobs <axel@jaloxa.eu>
parents:
54
diff
changeset
|
72 |
my $scale = 0.001 / $size; |
| 54 | 73 |
|
74 |
my $fitting = "$td/fitting.rad"; |
|
75 |
open(FH, ">$fitting") or |
|
76 |
die("Can\'t write to temporary file $fitting");
|
|
77 |
print FH "!xform -t $xtrans $ytrans $ztrans -s $scale @ARGV"; |
|
78 |
close FH; |
|
79 |
||
80 |
||
81 |
# Material for the room |
|
82 |
open(FH, ">$material") or |
|
83 |
die("Can\'t write to temporary file $material");
|
|
84 |
print FH "void plastic wall_mat 0 0 5 .5 .5 .5 0 0"; |
|
85 |
close FH; |
|
86 |
||
87 |
||
88 |
# Different 'room' geometry for different views |
|
89 |
my $OFFSET = 0.1; |
|
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
90 |
open(FH, ">$testroom1") or die("Can't write to temporary file $testroom1");
|
| 54 | 91 |
# C0-C180 |
92 |
print FH "wall_mat polygon box.4620 0 0 12 -$OFFSET -5 5 -$OFFSET 5 5 -$OFFSET 5 -5 -$OFFSET -5 -5"; |
|
93 |
close(FH); |
|
94 |
||
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
95 |
open(FH, ">$testroom2") or die("Can't write to temporary file $testroom2");
|
| 54 | 96 |
# C90-C270 |
97 |
print FH "wall_mat polygon box.1540 0 0 12 5 $OFFSET -5 5 $OFFSET 5 -5 $OFFSET 5 -5 $OFFSET -5"; |
|
98 |
close(FH); |
|
99 |
||
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
100 |
open(FH, ">$testroom3") or die("Can't write to temporary file $testroom3");
|
| 54 | 101 |
# Lower hemisphere |
102 |
print FH "wall_mat bubble lower 0 0 4 0 0 $dims[4] 5"; |
|
103 |
close(FH); |
|
104 |
||
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
105 |
open(FH, ">$testroom4") or die("Can't write to temporary file $testroom4");
|
| 54 | 106 |
# Upper hemisphere |
107 |
print FH "wall_mat bubble upper 0 0 4 0 0 $dims[5] 5"; |
|
108 |
close(FH); |
|
109 |
||
110 |
||
111 |
# Get bbox again, for the translated and scaled fitting. |
|
112 |
$dimstr = `getbbox -h $fitting`; |
|
113 |
chomp $dimstr; |
|
114 |
# Values returned by getbbox are indented and delimited with multiple spaces. |
|
115 |
$dimstr =~ s/^\s+//; # remove leading spaces |
|
116 |
@dims = split(/\s+/, $dimstr); # convert to array |
|
117 |
||
118 |
# Define the four views |
|
119 |
my $vw1 = "-vtl -vp 4.5 0 0 -vd -1 0 0 -vh 10 -vv 10"; |
|
120 |
my $vw2 = "-vtl -vp 0 -4.5 0 -vd 0 1 0 -vh 10 -vv 10"; |
|
121 |
my $zcent3 = $dims[4] - $tiny; |
|
122 |
my $vw3 = "-vta -vp 0 0 $zcent3 -vd 0 0 -1 -vu 0 1 0 -vh 180 -vv 180"; |
|
123 |
my $zcent4 = $dims[5] + $tiny; |
|
124 |
my $vw4 = "-vta -vp 0 0 $zcent4 -vd 0 0 1 -vu 0 1 0 -vh 180 -vv 180"; |
|
125 |
||
126 |
system "oconv $material $testroom1 $fitting > $octree1"; |
|
127 |
system "oconv $material $testroom2 $fitting > $octree2"; |
|
128 |
system "oconv $material $testroom3 $fitting > $octree3"; |
|
129 |
system "oconv $material $testroom4 $fitting > $octree4"; |
|
130 |
||
131 |
# Render four different views of the objects |
|
132 |
system "$rpict_cmd $vw1 $octree1 > $td/right.hdr"; |
|
133 |
system "$rpict_cmd $vw2 $octree2 > $td/front.hdr"; |
|
134 |
system "$rpict_cmd $vw3 $octree3 > $td/down.hdr"; |
|
135 |
system "$rpict_cmd $vw4 $octree4 > $td/up.hdr"; |
|
136 |
||
137 |
# Compose the four views into one image |
|
138 |
my $cmd; |
|
139 |
my $vtl = "$td/vtl.hdr"; |
|
140 |
my $vta = "$td/vta.hdr"; |
|
141 |
||
142 |
# Auto-expose right/front and down/up pairs separately |
|
|
56
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
143 |
system "pcompos $td/right.hdr 0 0 $td/front.hdr $xres 0 > $td/rf.hdr"; |
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
144 |
system "$pcond_cmd $td/rf.hdr > $vtl"; |
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
145 |
system "pcompos $td/down.hdr 0 0 $td/up.hdr $xres 0 > $td/du.hdr"; |
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
146 |
system "$pcond_cmd $td/du.hdr > $vta"; |
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
147 |
|
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
148 |
# Combine top two images with bottom row |
|
259ce6d95331
ltpict: Minor changes for readability
Axel Jacobs <axel@jaloxa.eu>
parents:
55
diff
changeset
|
149 |
exec "pcompos -a 1 $vtl $vta"; |
| 54 | 150 |
|
151 |
#EOF |