bin/ltpict.pl
changeset 65 f10a54c3213d
parent 60 448b4b706fa5
child 68 67aa83bdbddd
equal deleted inserted replaced
64:5fb0b190e5ef 65:f10a54c3213d
    10 use strict;
    10 use strict;
    11 use warnings;
    11 use warnings;
    12 
    12 
    13 use File::Temp qw/ tempdir /;
    13 use File::Temp qw/ tempdir /;
    14 my $td = tempdir( CLEANUP => 1 );
    14 my $td = tempdir( CLEANUP => 1 );
    15 use File::Copy qw(copy);
       
    16 
    15 
    17 my $res     = 1024;            # Default output image dimensions
    16 my $res     = 1024;            # Default output image dimensions. Same as objpict.
    18 my $tiny    = 0.01;
    17 my $tiny    = 0.01;
    19 my $maxsize = 0.001;           # max luminaire size after scaling
    18 my $maxsize = 0.001;           # max luminaire size after scaling
    20 my $is_ies  = 0;
    19 my $is_ies  = 0;
    21 
    20 
    22 my $ies = "$td/dist.ies";
    21 my $ies   = "$td/dist.ies";
    23 my $lumi = "$td/lumi.rad";     # Fitting as given on cmd line, or as generated by ies2rad
    22 my $lumi  = "$td/lumi.rad";    # Fitting given on cmd line, or generated by ies2rad
    24 my $lumi2 = "$td/lumi2.rad";   # Fitting scaled to size
    23 my $lumi2 = "$td/lumi2.rad";   # Fitting scaled to size
    25 my $mat = "$td/lt.mat";
    24 my $mat   = "$td/lt.mat";
    26 my $room1 = "$td/room1.rad";
    25 my $room1 = "$td/room1.rad";
    27 my $room2 = "$td/room2.rad";
    26 my $room2 = "$td/room2.rad";
    28 my $room3 = "$td/room3.rad";
    27 my $room3 = "$td/room3.rad";
    29 my $room4 = "$td/room4.rad";
    28 my $room4 = "$td/room4.rad";
    30 my $oct1 = "$td/lt1.oct";
    29 my $oct1  = "$td/lt1.oct";
    31 my $oct2 = "$td/lt2.oct";
    30 my $oct2  = "$td/lt2.oct";
    32 my $oct3 = "$td/lt3.oct";
    31 my $oct3  = "$td/lt3.oct";
    33 my $oct4 = "$td/lt4.oct";
    32 my $oct4  = "$td/lt4.oct";
    34 
    33 
    35 # Parse command line arguments
    34 # Parse command line arguments
    36 while ($#ARGV >= 0) {
    35 while (@ARGV) {
    37 	$_ = $ARGV[0];
    36 	$_ = $ARGV[0];
    38 	if (m/-i/) {         # File is an IES file, not Radiance luminaire
    37 	if (m/-i/) {         # File is an IES file, not a Radiance luminaire
    39 		$is_ies = 1;
    38 		$is_ies = 1;
    40 	} elsif (m/-d/) {    # Resolution of the output HDR image
    39 	} elsif (m/-d/) {    # Resolution of the output HDR image
    41 		$res = $ARGV[1];
    40 		$res = $ARGV[1];
    42 		shift @ARGV;
    41 		shift @ARGV;
    43 
    42     } elsif (m/^-\w/) { 	 # Oops! Illegal option
    44     } elsif (m/^-/) { 	 # Oops! Illegal option
    43         die("ltpict: bad option '$_'\n");
    45         die("ltpict: bad option \"$ARGV[0]\"\n");
       
    46     } else {
    44     } else {
    47 		last;    # No more options.  What's left is the actual file name.
    45 		last;    # No more options.  What's left is the actual file name.
    48 	}
    46 	}
    49     shift @ARGV;
    47     shift @ARGV;
    50 }
    48 }
    51 
    49 
    52 # We need one Radiance luminaire or an IES file
       
    53 if ($is_ies == 0) {
    50 if ($is_ies == 0) {
    54 	# Input file is a Radiance luminaire
    51 	# Input file is a Radiance luminaire
    55 	copy $ARGV[0], $lumi or
    52 	$lumi = $ARGV[0];
    56 			die("ltpict: Cannot copy file '$ARGV[0]' to $lumi\n");
       
    57 } else {
    53 } else {
    58 	# Input file is IES photometry
    54 	# Input file is IES photometry
    59 	system "ies2rad -p $td -o lumi $ARGV[0]";
    55 	system "ies2rad -p $td -o lumi $ARGV[0]";
    60 }
    56 }
    61 
    57 
    91 print FH "void plastic wall_mat  0  0  5  .5 .5 .5  0 0";
    87 print FH "void plastic wall_mat  0  0  5  .5 .5 .5  0 0";
    92 close FH;
    88 close FH;
    93 
    89 
    94 
    90 
    95 # Different 'room' geometry for different views
    91 # Different 'room' geometry for different views
    96 my $offset = 0.1;
    92 my $o = 0.1;   # Offset
    97 
    93 
    98 # C0-C180
    94 # C0-C180
    99 open(FH, ">$room1") or die("ltpict: Cannot write to temporary file $room1");
    95 open(FH, ">$room1") or
   100 print FH "wall_mat polygon box.4620  0  0  12  -$offset -5 5  -$offset 5 5  -$offset 5 -5  -$offset -5 -5";
    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";
   101 close(FH);
    98 close(FH);
   102 
    99 
   103 # C90-C270
   100 # C90-C270
   104 open(FH, ">$room2") or die("ltpict: Cannot write to temporary file $room2");
   101 open(FH, ">$room2") or
   105 print FH "wall_mat polygon box.1540  0  0  12  5 $offset -5  5 $offset 5  -5 $offset 5  -5 $offset -5";
   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";
   106 close(FH);
   104 close(FH);
   107 
   105 
   108 # Lower hemisphere
   106 # Lower hemisphere
   109 open(FH, ">$room3") or die("ltpict: Cannot write to temporary file $room3");
   107 open(FH, ">$room3") or 
       
   108 		die("ltpict: Cannot write to temporary file $room3");
   110 print FH "wall_mat bubble lower  0  0  4 0 0 $dims[4] 5";
   109 print FH "wall_mat bubble lower  0  0  4 0 0 $dims[4] 5";
   111 close(FH);
   110 close(FH);
   112 
   111 
   113 # Upper hemisphere
   112 # Upper hemisphere
   114 open(FH, ">$room4") or die("ltpict: Cannot write to temporary file $room4");
   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";
   115 print FH "wall_mat bubble upper  0  0  4 0 0 $dims[5] 5";
   116 close(FH);
   116 close(FH);
   117 
   117 
   118 
   118 
   119 # Get bbox again, for the translated and scaled luminaire.
   119 # Call bbox again, for the translated and scaled luminaire.
   120 $dimstr = `getbbox -h $lumi2`;
   120 $dimstr = `getbbox -h $lumi2`;
   121 chomp $dimstr;
   121 chomp $dimstr;
   122 # Values returned by getbbox are indented and delimited with multiple spaces.
   122 # Values returned by getbbox are indented and delimited with multiple spaces.
   123 $dimstr =~ s/^\s+//;   # remove leading spaces
   123 $dimstr =~ s/^\s+//;             # remove leading spaces
   124 @dims = split(/\s+/, $dimstr);   # convert to array
   124 @dims = split(/\s+/, $dimstr);   # convert to array
   125 
   125 
   126 # Define the four views
   126 # Define the four views
   127 my $vw1 = "-vtl -vp 4.5 0 0 -vd -1 0 0 -vh 10 -vv 10";
   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";
   128 my $vw2 = "-vtl -vp 0 -4.5 0 -vd 0 1 0 -vh 10 -vv 10";