ltview: IES input works now
authorAxel Jacobs <axel@jaloxa.eu>
Tue, 08 Apr 2014 22:56:10 +0100
changeset 66 7e56c36eb1ae
parent 65 f10a54c3213d
child 67 cb1224fcd2c2
ltview: IES input works now
bin/ltview.pl
--- a/bin/ltview.pl	Tue Apr 08 22:56:02 2014 +0100
+++ b/bin/ltview.pl	Tue Apr 08 22:56:10 2014 +0100
@@ -10,16 +10,17 @@
 use strict;
 use warnings;
 use Math::Trig;
-use File::Copy;
+use File::Copy qw(copy);
 use File::Temp qw/ tempdir /;
 
 my $td     = tempdir( CLEANUP => 1 );
 my $oct    = "$td/ltview.oct";
 my $room   = "$td/room.rad";
-my $rdim;               # Overall room dimensions
+my $box;                # Overall box dimensions
+my $default_box = 10;   # Default box dimensions
 my $rif    = "$td/ltview.rif";
-my $lumi   = "$td/lumi.rad";
-my $ies    = "$td/lumi.ies";
+my $lumi   = "$td/lumi.rad";    # Fitting as given on cmd line, or generated by ies2rad
+my $lumi2  = "$td/lumi2.rad";   # Fitting scaled to max unity
 my $raddev = "x11";     # default output device. Overwrite with -o
 my $is_ies = 0;         # input file is IES photometry, not a Radiance luminaire
 
@@ -36,39 +37,48 @@
 		$raddev = $ARGV[1];
 		$radopt = 1;
 		shift @ARGV;
-	} elsif (m/-r/) {
-		$rdim = $ARGV[1];    # Room dimensions
+	} elsif (m/-b/) {
+		$box = $ARGV[1];    # Box dimensions
 		shift @ARGV;
 	} elsif (m/^-\w/) {
-		die("objview: Bad option: $_\n");
+		die("objview: Bad option: '$_'\n");
 	} else {
 		last;
 	}
 	shift @ARGV;
 }
 
-# We need one Radiance luminaires description, or an IES file
+# We need exactly one Radiance luminaires or IES file
 if (! $#ARGV == 0) {
 	die("ltview: Need one Radiance luminaire or IES file.\n");
 }
 
+if ($is_ies == 0) {
+	# Input file is a Radiance luminaire
+	$lumi = $ARGV[0];
+} else {
+	# Input file is IES photometry
+	system "ies2rad -p $td -o lumi $ARGV[0]";
+}
+
+
 open(FH, ">$room") or
-		die("ltview: Can't write to temporary file $room\n");
+		die("ltview: Can't write to temporary file '$room'\n");
 print FH "void plastic wall_mat  0  0  5 .2 .2 .2 0 0\n";
 
-my $r;
-if (defined $rdim) {
+my $b2;
+if (defined $box) {
 	# Room dimensions are giving explicitly.  Don't touch the fitting.
-	$r = $rdim;
+	$b2 = $box / 2;
 
-	copy ($ARGV[0], $lumi);
+	$lumi2 = $ARGV[0];
 } else {
 	# Scale fitting so it fits nicely into our default test room.
-	$r = 5;    # Default room dimension
+	$b2 = $default_box;    # Default room dimension
 
 	# Work out how large the luminaire is and scale so that the longest
 	# axis-align dimension is $maxscale
-	my $dimstr = `getbbox -h $ARGV[0]`;
+	my $dimstr = `getbbox -h $lumi`;
 	chomp $dimstr;
 	# Values returned by getbbox are indented and delimited with multiple spaces.
 	$dimstr =~ s/^\s+//;   # remove leading spaces
@@ -86,17 +96,18 @@
 	# Scale so that largest object dimension is $maxscale
 	my $scale = $maxscale / $size;
 
-	system "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi";
+	#system "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi";
+	system "xform -t $xtrans $ytrans $ztrans -s $scale $lumi > $lumi2";
 }
 
 print FH <<EndOfRoom;
 # Don't generate -y face so we can look into the box (could use clipping)
-#wall_mat polygon box.1540  0  0  12  $r -$r -$r  $r -$r $r  -$r -$r $r  -$r -$r -$r
-wall_mat polygon box.4620  0  0  12  -$r -$r $r  -$r $r $r  -$r $r -$r  -$r -$r -$r
-wall_mat polygon box.2310  0  0  12  -$r $r -$r  $r $r -$r  $r -$r -$r  -$r -$r -$r
-wall_mat polygon box.3267  0  0  12  $r $r -$r  -$r $r -$r  -$r $r $r  $r $r $r
-wall_mat polygon box.5137  0  0  12  $r -$r $r  $r -$r -$r  $r $r -$r  $r $r $r
-wall_mat polygon box.6457  0  0  12  -$r $r $r  -$r -$r $r  $r -$r $r  $r $r $r
+#wall_mat polygon box.1540  0  0  12  $b2 -$b2 -$b2  $b2 -$b2 $b2  -$b2 -$b2 $b2  -$b2 -$b2 -$b2
+wall_mat polygon box.4620  0  0  12  -$b2 -$b2 $b2  -$b2 $b2 $b2  -$b2 $b2 -$b2  -$b2 -$b2 -$b2
+wall_mat polygon box.2310  0  0  12  -$b2 $b2 -$b2  $b2 $b2 -$b2  $b2 -$b2 -$b2  -$b2 -$b2 -$b2
+wall_mat polygon box.3267  0  0  12  $b2 $b2 -$b2  -$b2 $b2 -$b2  -$b2 $b2 $b2  $b2 $b2 $b2
+wall_mat polygon box.5137  0  0  12  $b2 -$b2 $b2  $b2 -$b2 -$b2  $b2 $b2 -$b2  $b2 $b2 $b2
+wall_mat polygon box.6457  0  0  12  -$b2 $b2 $b2  -$b2 -$b2 $b2  $b2 -$b2 $b2  $b2 $b2 $b2
 EndOfRoom
 close(FH);
 
@@ -110,10 +121,10 @@
 
 # Tweak bounding box so we get a nice view covering all of the box, without
 # having a wasteful black border around it.  Must work for arbitrary box dims.
-my $zone = 1.1 * $r * ( 1 + 1/tan(22.5*pi/180) );
+my $zone = 1.1 * $b2 * ( 1 + 1/tan(22.5*pi/180) );
 
 open(FH, ">$rif") or
-		die("ltview: Can't write to temporary file $rif\n");
+		die("ltview: Can't write to temporary file '$rif'\n");
 print FH <<EndOfRif;
 scene= $scene
 EXPOSURE= 2
@@ -126,6 +137,6 @@
 EndOfRif
 close(FH);
 
-system "rad -o $raddev $opts $rif";
+exec "rad -o $raddev $opts $rif";
 
 #EOF