ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/falsecolor.pl
(Generate patch)

Comparing ray/src/px/falsecolor.pl (file contents):
Revision 2.4 by greg, Wed Mar 23 21:57:11 2011 UTC vs.
Revision 2.5 by greg, Wed Oct 26 03:42:49 2011 UTC

# Line 1 | Line 1
1   #!/usr/bin/perl -w
2   # RCSid $Id$
3  
4 + use warnings;
5   use strict;
6   use File::Temp qw/ tempdir /;
7   use POSIX qw/ floor /;
8  
9 < my $mult = 179.0;    # Multiplier. Default W/sr/m2 -> cd/m2
10 < my $label = 'cd/m2';    # Units shown in legend
11 < my $scale = 1000;    # Top of the scale
12 < my $decades = 0;    # Default is linear mapping
13 < my $redv = 'def_red(v)';    # Mapping function for R,G,B
14 < my $grnv = 'def_grn(v)';
15 < my $bluv = 'def_blu(v)';
16 < my $ndivs = 8;    # Number of lines in legend
9 > my @palettes = ('def', 'spec', 'pm3d', 'hot');
10 >
11 > my $mult = 179.0;              # Multiplier. Default W/sr/m2 -> cd/m2
12 > my $label = 'cd/m2';           # Units shown in legend
13 > my $scale = 1000;              # Top of the scale
14 > my $decades = 0;               # Default is linear mapping
15 > my $pal = 'def';               # Palette
16 > my $redv = "${pal}_red(v)";    # Mapping functions for R,G,B
17 > my $grnv = "${pal}_grn(v)";
18 > my $bluv = "${pal}_blu(v)";
19 > my $ndivs = 8;                 # Number of lines in legend
20   my $picture = '-';
21   my $cpict = '';
22 < my $legwidth = 100;   # Legend width and height
22 > my $legwidth = 100;            # Legend width and height
23   my $legheight = 200;
24 < my $docont = '';    # Contours
25 < my $loff = 0;    # Offset to align with values
26 < my $doextrem = 0;    # Don't mark extrema
24 > my $docont = '';               # Contours
25 > my $loff = 0;                  # Offset to align with values
26 > my $doextrem = 0;              # Don't mark extrema
27   my $needfile = 0;
28  
29   while ($#ARGV >= 0) {
30 <        # Options with qualifiers
31 <    if ("$ARGV[0]" eq '-lw') {    # Legend width
32 <        $legwidth = $ARGV[1];
33 <        shift @ARGV;
34 <    } elsif ("$ARGV[0]" eq '-lh') {    # Legend height
35 <        $legheight = $ARGV[1];
36 <        shift @ARGV;
37 <    } elsif ("$ARGV[0]" eq '-m') {    # Multiplier
38 <        $mult = $ARGV[1];
39 <        shift @ARGV;
36 <    } elsif ("$ARGV[0]" eq '-s') {    # Scale
37 <        $scale = $ARGV[1];
38 <        shift @ARGV;
30 >    $_ = shift;
31 >    # Options with qualifiers
32 >    if (m/-lw/) {              # Legend width
33 >        $legwidth = shift;
34 >    } elsif (m/-lh/) {         # Legend height
35 >        $legheight = shift;
36 >    } elsif (m/-m/) {          # Multiplier
37 >        $mult = shift;
38 >    } elsif (m/-s/) {          # Scale
39 >        $scale = shift;
40          if ($scale =~ m/[aA].*/) {
41              $needfile = 1;
42          }
43 <    } elsif ("$ARGV[0]" eq '-l') {    # Label
44 <        $label = $ARGV[1];
45 <        shift @ARGV;
46 <    } elsif ("$ARGV[0]" eq '-log') {    # Logarithmic mapping
47 <        $decades = $ARGV[1];
48 <        shift @ARGV;
49 <    } elsif ("$ARGV[0]" eq '-r') {
50 <        $redv = $ARGV[1];
51 <        shift @ARGV;
52 <    } elsif ("$ARGV[0]" eq '-g') {
53 <        $grnv = $ARGV[1];
54 <        shift @ARGV;
55 <    } elsif ("$ARGV[0]" eq '-b') {
56 <        $bluv = $ARGV[1];
57 <        shift @ARGV;
58 <    } elsif ("$ARGV[0]" eq '-pal') {
59 <        $redv = "$ARGV[1]_red(v)";
60 <        $grnv = "$ARGV[1]_grn(v)";
61 <        $bluv = "$ARGV[1]_blu(v)";
62 <        shift @ARGV;
63 <    } elsif ("$ARGV[0]" eq '-i') {    # Image for intensity mapping
64 <        $picture = $ARGV[1];
65 <        shift @ARGV;
66 <    } elsif ("$ARGV[0]" eq '-p') {    # Image for background
67 <        $cpict = $ARGV[1];
68 <        shift @ARGV;
69 <    } elsif ("$ARGV[0]" eq '-ip' || "$ARGV[0]" eq '-pi') {
69 <        $picture = $ARGV[1];
70 <        $cpict = $ARGV[1];
71 <        shift @ARGV;
72 <    } elsif ("$ARGV[0]" eq '-n') {    # Number of contour lines
73 <        $ndivs = $ARGV[1];
74 <        shift @ARGV;
43 >    } elsif (m/-l$/) {         # Label
44 >        $label = shift;
45 >    } elsif (m/-log/) {        # Logarithmic mapping
46 >        $decades = shift;
47 >    } elsif (m/-r/) {          # Custom palette functions for R,G,B
48 >        $redv = shift;
49 >    } elsif (m/-g/) {
50 >        $grnv = shift;
51 >    } elsif (m/-b/) {
52 >        $bluv = shift;
53 >    } elsif (m/-pal$/) {        # Color palette
54 >        $pal = shift;
55 >        if (! grep $_ eq $pal, @palettes) {
56 >            die("invalid palette '$pal'.\n");
57 >        }
58 >        $redv = "${pal}_red(v)";
59 >        $grnv = "${pal}_grn(v)";
60 >        $bluv = "${pal}_blu(v)";
61 >    } elsif (m/-i$/) {          # Image for intensity mapping
62 >        $picture = shift;
63 >    } elsif (m/-p$/) {         # Image for background
64 >        $cpict = shift;
65 >    } elsif (m/-ip/ || m/-pi/) {
66 >        $picture = shift;
67 >        $cpict = $picture;
68 >    } elsif (m/-n/) {          # Number of contour lines
69 >        $ndivs = shift;
70  
71 <        # Switches
72 <    } elsif ("$ARGV[0]" eq '-cl') {    # Contour lines
71 >    # Switches
72 >    } elsif (m/-cl/) {         # Contour lines
73          $docont = 'a';
74          $loff = 0.48;
75 <    } elsif ("$ARGV[0]" eq '-cb') {    # Contour bands
75 >    } elsif (m/-cb/) {         # Contour bands
76          $docont = 'b';
77          $loff = 0.52;
78 <    } elsif ("$ARGV[0]" eq '-e') {
78 >    } elsif (m/-e/) {
79          $doextrem = 1;
80          $needfile = 1;
81  
82 <        # Oops! Illegal option
82 >    # Oops! Illegal option
83      } else {
84 <        die("bad option \"$ARGV[0]\"\n");
84 >        die("bad option \"$_\"\n");
85      }
91    shift @ARGV;
86   }
87  
88   # Temporary directory. Will be removed upon successful program exit.
89   my $td = tempdir( CLEANUP => 1 );
90  
91   if ($needfile == 1 && $picture eq '-') {
92 <        # Pretend that $td/stdin.rad is the actual filename.
92 >    # Pretend that $td/stdin.rad is the actual filename.
93      $picture = "$td/stdin.hdr";
94      open(FHpic, ">$picture") or
95              die("Unable to write to file $picture\n");
96 <        # Input is from STDIN: Capture to file.
97 <        while (<>) {
98 <                print FHpic;
99 <        }
96 >    # Input is from STDIN: Capture to file.
97 >    while (<>) {
98 >        print FHpic;
99 >    }
100      close(FHpic);
101  
102 <        if ($cpict eq '-') {
103 <                $cpict =  "$td/stdin.hdr";
104 <        }
102 >    if ($cpict eq '-') {
103 >        $cpict =  "$td/stdin.hdr";
104 >    }
105   }
106  
107   # Find a good scale for auto mode.
108   if ($scale =~ m/[aA].*/) {
109 <        my @histo = split(/\s/, `phisto $picture| tail -2`);
110 <        # e.g. $ phisto tests/richmond.hdr| tail -2
111 <        # 3.91267       14
112 <        # 3.94282       6
113 <        my $LogLmax = $histo[0];
109 >    my @histo = split(/\s/, `phisto $picture| tail -2`);
110 >    # e.g. $ phisto tests/richmond.hdr| tail -2
111 >    # 3.91267   14
112 >    # 3.94282   6
113 >    my $LogLmax = $histo[0];
114      $scale = $mult / 179 * 10**$LogLmax;
115   }
116  
# Line 142 | Line 136 | spec_grn(x) = if(x-.375, 1.6-1.6*x, 8/3*x);
136   spec_blu(x) = 1 - 8/3*x;
137  
138   pm3d_red(x) = sqrt(x) ^ gamma;
139 < pm3d_grn(x) = x*x*x ^ gamma;
139 > pm3d_grn(x) = (x*x*x) ^ gamma;
140   pm3d_blu(x) = clip(sin(2*PI*x)) ^ gamma;
141  
142   hot_red(x) = clip(3*x) ^ gamma;
# Line 232 | Line 226 | my $slabpic = "$td/slab.hdr";
226   my $cmd;
227  
228   if (($legwidth > 20) && ($legheight > 40)) {
229 <        # Legend: Create the text labels
229 >    # Legend: Create the text labels
230      my $sheight = floor($legheight / $ndivs + 0.5);
231      $legheight = $sheight * $ndivs;
232      $loff = floor($loff * $sheight + 0.5);
233      my $text = "$label";
234      for (my $i=0; $i<$ndivs; $i++) {
235          my $imap = ($ndivs - 0.5 - $i) / $ndivs;
236 <                my $value = $scale;
236 >        my $value = $scale;
237          if ($decades > 0) {
238              $value *= 10**(($imap - 1) * $decades);
239          } else {
# Line 253 | Line 247 | if (($legwidth > 20) && ($legheight > 40)) {
247      $cmd .= " -h $sheight > $slabpic";
248      system $cmd;
249  
250 <        # Legend: Create the background colours
250 >    # Legend: Create the background colours
251      $cmd = "pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v'";
252      $cmd .= " -e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres'";
253      $cmd .= " -x $legwidth -y $legheight > $scolpic";
254      system $cmd;
255   } else {
256 <        # Legend is too small to be legible. Don't bother doing one.
256 >    # Legend is too small to be legible. Don't bother doing one.
257      $legwidth = 0;
258      $legheight = 0;
259      $loff = 0;
260 <        # Create dummy colour scale and legend labels so we don't
261 <        # need to change the final command line.
260 >    # Create dummy colour scale and legend labels so we don't
261 >    # need to change the final command line.
262      open(FHscolpic, ">$scolpic");
263      print FHscolpic "\n-Y 1 +X 1\naaa\n";
264      close(FHscolpic);
# Line 285 | Line 279 | $cmd .= "| pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $l
279   $cmd .= " -t .5 $slabpic 0 $loff - $legwidth 0";
280  
281   if ($doextrem == 1) {
282 <        # Get min/max image luminance
282 >    # Get min/max image luminance
283      my $cmd1 = 'pextrem -o ' . $picture;
284      my $retval = `$cmd1`;
285      # e.g.
# Line 295 | Line 289 | if ($doextrem == 1) {
289  
290      my @extrema = split(/\s/, $retval);
291      my ($lxmin, $ymin, $rmin, $gmin, $bmin, $lxmax, $ymax, $rmax, $gmax, $bmax) = @extrema;
292 <        $lxmin += $legwidth;
293 <        $lxmax += $legwidth;
292 >    $lxmin += $legwidth;
293 >    $lxmax += $legwidth;
294  
295 <        # Weighted average of R,G,B
295 >    # Weighted average of R,G,B
296      my $minpos = "$lxmin $ymin";
297      my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
298      $minval =~ s/(\.[0-9]{3})[0-9]*/$1/;
# Line 306 | Line 300 | if ($doextrem == 1) {
300      my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
301      $maxval =~ s/(\.[0-9]{3})[0-9]*/$1/;
302  
303 <        # Create the labels for min/max intensity
303 >    # Create the labels for min/max intensity
304      my $minvpic = "$td/minv.hdr";
305      $cmd1 = "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
306      system $cmd1;
# Line 314 | Line 308 | if ($doextrem == 1) {
308      $cmd1 = "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
309      system $cmd1;
310  
311 <        # Add extrema labels to command line
311 >    # Add extrema labels to command line
312      $cmd .= " $minvpic $minpos $maxvpic $maxpos";
313   }
314  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines