# HG changeset patch # User Axel Jacobs # Date 1396994170 -3600 # Node ID 7e56c36eb1aed141b05b8464ad5876b1d4469f70 # Parent f10a54c3213d38de2231fd880b138dca7aa533ce ltview: IES input works now diff -r f10a54c3213d -r 7e56c36eb1ae 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 <$rif") or - die("ltview: Can't write to temporary file $rif\n"); + die("ltview: Can't write to temporary file '$rif'\n"); print FH <