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.5 by greg, Wed Oct 26 03:42:49 2011 UTC vs.
Revision 2.11 by greg, Tue Sep 5 22:42:52 2017 UTC

# Line 6 | Line 6 | use strict;
6   use File::Temp qw/ tempdir /;
7   use POSIX qw/ floor /;
8  
9 < my @palettes = ('def', 'spec', 'pm3d', 'hot');
9 > my @palettes = ('def', 'spec', 'pm3d', 'hot', 'eco');
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 $matchscale = 1;            # Adjust top of scale to match given label
15   my $decades = 0;               # Default is linear mapping
16   my $pal = 'def';               # Palette
17   my $redv = "${pal}_red(v)";    # Mapping functions for R,G,B
# Line 21 | Line 22 | my $picture = '-';
22   my $cpict = '';
23   my $legwidth = 100;            # Legend width and height
24   my $legheight = 200;
25 < my $docont = '';               # Contours
25 > my $docont = '';               # Contours: -cl and -cb
26 > my $doposter = 0;              # Posterization: -cp
27   my $loff = 0;                  # Offset to align with values
28   my $doextrem = 0;              # Don't mark extrema
29   my $needfile = 0;
30 + my $showpal = 0;               # Show availabel colour palettes
31  
32   while ($#ARGV >= 0) {
33      $_ = shift;
# Line 35 | Line 38 | while ($#ARGV >= 0) {
38          $legheight = shift;
39      } elsif (m/-m/) {          # Multiplier
40          $mult = shift;
41 +    } elsif (m/-spec/) {
42 +        die("depricated option '-spec'. Please use '-pal spec' instead.");
43      } elsif (m/-s/) {          # Scale
44          $scale = shift;
45          if ($scale =~ m/[aA].*/) {
46 +            $matchscale = 0;
47              $needfile = 1;
48 <        }
48 >       } else {
49 >            $matchscale = 1;
50 >        }
51      } elsif (m/-l$/) {         # Label
52          $label = shift;
53      } elsif (m/-log/) {        # Logarithmic mapping
# Line 75 | Line 83 | while ($#ARGV >= 0) {
83      } elsif (m/-cb/) {         # Contour bands
84          $docont = 'b';
85          $loff = 0.52;
86 +    } elsif (m/-cp/) {              # Posterize
87 +        $doposter = 1;
88 +    } elsif (m/-palettes/) {        # Show all available palettes
89 +        $scale   = 45824;           # 256 * 179
90 +        $showpal = 1;
91      } elsif (m/-e/) {
92          $doextrem = 1;
93          $needfile = 1;
# Line 85 | Line 98 | while ($#ARGV >= 0) {
98      }
99   }
100  
101 + if (($legwidth <= 20) || ($legheight <= 40)) {
102 +    # Legend is too small to be legible. Don't bother doing one.
103 +    $legwidth = 0;
104 +    $legheight = 0;
105 +    $loff = 0;
106 +    $matchscale = 0;
107 + }
108 +
109   # Temporary directory. Will be removed upon successful program exit.
110   my $td = tempdir( CLEANUP => 1 );
111  
# Line 100 | Line 121 | if ($needfile == 1 && $picture eq '-') {
121      close(FHpic);
122  
123      if ($cpict eq '-') {
124 <        $cpict =  "$td/stdin.hdr";
124 >        $cpict = "$td/stdin.hdr";
125      }
126   }
127  
# Line 112 | Line 133 | if ($scale =~ m/[aA].*/) {
133      # 3.94282   6
134      my $LogLmax = $histo[0];
135      $scale = $mult / 179 * 10**$LogLmax;
136 + } elsif ($matchscale) {
137 +    # Adjust scale so legend reflects -s setting
138 +    if ($decades > 0) {
139 +        $scale *= 10**($decades/(2.*$ndivs));
140 +    } else {
141 +        $scale *= $ndivs/($ndivs - .5);
142 +    }
143   }
144  
145   my $pc0 = "$td/pc0.cal";
# Line 137 | Line 165 | spec_blu(x) = 1 - 8/3*x;
165  
166   pm3d_red(x) = sqrt(x) ^ gamma;
167   pm3d_grn(x) = (x*x*x) ^ gamma;
168 < pm3d_blu(x) = clip(sin(2*PI*x)) ^ gamma;
168 > pm3d_blu(x) = clip(sin(2*PI*clip(x))) ^ gamma;
169  
170   hot_red(x) = clip(3*x) ^ gamma;
171   hot_grn(x) = clip(3*x - 1) ^ gamma;
172   hot_blu(x) = clip(3*x - 2) ^ gamma;
173  
174 + eco_red(x) = clip(2*x) ^ gamma;
175 + eco_grn(x) = clip(2*(x-0.5)) ^ gamma;
176 + eco_blu(x) = clip(2*(0.5-x)) ^ gamma;
177 +
178   interp_arr2(i,x,f):(i+1-x)*f(i)+(x-i)*f(i+1);
179   interp_arr(x,f):if(x-1,if(f(0)-x,interp_arr2(floor(x),x,f),f(f(0))),f(1));
180  
# Line 180 | Line 212 | ro = if(in,clip($redv),ra);
212   go = if(in,clip($grnv),ga);
213   bo = if(in,clip($bluv),ba);
214   EndOfPC0
215 + close FHpc0;
216  
217   my $pc1 = "$td/pc1.cal";
218   open(FHpc1, ">$pc1");
# Line 199 | Line 232 | ra = ri(nfiles);
232   ga = gi(nfiles);
233   ba = bi(nfiles);
234   EndOfPC1
235 + close FHpc1;
236  
237   my $pc0args = "-f $pc0";
238   my $pc1args = "-f $pc1";
239  
240 < # Contour lines or bands
240 > if ($showpal == 1) {
241 >    my $pc = "pcompos -a 1";
242 >    foreach my $pal (@palettes) {
243 >        my $fcimg = "$td/$pal.hdr";
244 >        my $lbimg = "$td/${pal}_label.hdr";
245 >        system "psign -cb 0 0 0 -cf 1 1 1 -h 20 $pal > $lbimg";
246 >
247 >        my $cmd = qq[pcomb $pc0args -e "v=x/256"];
248 >        $cmd .= qq[ -e "ro=clip(${pal}_red(v));go=clip(${pal}_grn(v));bo=clip(${pal}_blu(v))"];
249 >        $cmd .= qq[ -x 256 -y 30 > $fcimg];
250 >        system "$cmd";
251 >        $pc .= " $fcimg $lbimg";
252 >    }
253 >    system "$pc";
254 >    exit 0;
255 > }
256 >
257 > # Contours
258   if ($docont ne '') {
259 <    $pc0args .= " -e 'in=iscont$docont'";
259 >    # -cl -> $docont = a
260 >    # -cb -> $docont = b
261 >    $pc0args .= qq[ -e "in=iscont$docont"];
262 > } elsif ($doposter == 1) {
263 >    # -cp -> $doposter = 1
264 >    $pc0args .= qq[ -e "ro=${pal}_red(seg(v));go=${pal}_grn(seg(v));bo=${pal}_blu(seg(v))"];
265 >    $pc0args .= q[ -e "seg(x)=(floor(v*ndivs)+.5)/ndivs"];
266   }
267  
268   if ($cpict eq '') {
269 <    $pc1args .= " -e 'ra=0;ga=0;ba=0'";
269 >    $pc1args .= qq[ -e "ra=0;ga=0;ba=0"];
270   } elsif ($cpict eq $picture) {
271      $cpict = '';
272   }
273  
274   # Logarithmic mapping
275   if ($decades > 0) {
276 <    $pc1args .= " -e 'map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)'";
276 >    $pc1args .= qq[ -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)"];
277   }
278  
279   # Colours in the legend
280   my $scolpic = "$td/scol.hdr";
281 +
282   # Labels in the legend
283   my $slabpic = "$td/slab.hdr";
284   my $cmd;
285  
286 < if (($legwidth > 20) && ($legheight > 40)) {
286 > if ($legwidth > 0) {
287      # Legend: Create the text labels
288      my $sheight = floor($legheight / $ndivs + 0.5);
289      $legheight = $sheight * $ndivs;
# Line 239 | Line 297 | if (($legwidth > 20) && ($legheight > 40)) {
297          } else {
298              $value *= $imap;
299          }
300 +
301          # Have no more than 3 decimal places
302          $value =~ s/(\.[0-9]{3})[0-9]*/$1/;
303          $text .= "\n$value";
304      }
305 <    $cmd = "echo '$text' | psign -s -.15 -cf 1 1 1 -cb 0 0 0";
306 <    $cmd .= " -h $sheight > $slabpic";
307 <    system $cmd;
305 >    open PSIGN, "| psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $sheight > $slabpic";
306 >    print PSIGN "$text\n";
307 >    close PSIGN;
308  
309      # Legend: Create the background colours
310 <    $cmd = "pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v'";
311 <    $cmd .= " -e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres'";
312 <    $cmd .= " -x $legwidth -y $legheight > $scolpic";
310 >    $cmd = qq[pcomb $pc0args];
311 >    $cmd .= q[ -e "v=(y+.5)/yres;vleft=v;vright=v"];
312 >    $cmd .= q[ -e "vbelow=(y-.5)/yres;vabove=(y+1.5)/yres"];
313 >    $cmd .= qq[ -x $legwidth -y $legheight > $scolpic];
314      system $cmd;
315   } else {
256    # Legend is too small to be legible. Don't bother doing one.
257    $legwidth = 0;
258    $legheight = 0;
259    $loff = 0;
316      # Create dummy colour scale and legend labels so we don't
317      # need to change the final command line.
318      open(FHscolpic, ">$scolpic");
# Line 269 | Line 325 | if (($legwidth > 20) && ($legheight > 40)) {
325  
326   # Legend: Invert the text labels (for dropshadow)
327   my $slabinvpic = "$td/slabinv.hdr";
328 < $cmd = "pcomb -e 'lo=1-gi(1)' $slabpic > $slabinvpic";
328 > $cmd = qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
329   system $cmd;
330  
331   my $loff1 = $loff - 1;
332 +
333   # Command line without extrema
334 < $cmd = "pcomb $pc0args $pc1args $picture $cpict";
335 < $cmd .= "| pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $loff1";
336 < $cmd .= " -t .5 $slabpic 0 $loff - $legwidth 0";
334 > $cmd = qq[pcomb $pc0args $pc1args "$picture"];
335 > $cmd .= qq[ "$cpict"] if ($cpict);
336 > $cmd .= qq[ | pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $loff1];
337 > $cmd .= qq[ -t .5 $slabpic 0 $loff - $legwidth 0];
338  
339   if ($doextrem == 1) {
340      # Get min/max image luminance
# Line 296 | Line 354 | if ($doextrem == 1) {
354      my $minpos = "$lxmin $ymin";
355      my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
356      $minval =~ s/(\.[0-9]{3})[0-9]*/$1/;
299    my $maxpos = "$lxmax $ymax";
357      my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
358      $maxval =~ s/(\.[0-9]{3})[0-9]*/$1/;
359  
360      # Create the labels for min/max intensity
361      my $minvpic = "$td/minv.hdr";
362 <    $cmd1 = "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
306 <    system $cmd1;
362 >    system "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
363      my $maxvpic = "$td/maxv.hdr";
364 <    $cmd1 = "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
309 <    system $cmd1;
364 >    system "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
365  
366      # Add extrema labels to command line
367 <    $cmd .= " $minvpic $minpos $maxvpic $maxpos";
367 >    $cmd .= qq[ $minvpic $minpos $maxvpic $lxmax $ymax];
368   }
369  
370   # Process image and combine with legend

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines