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