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.17 by greg, Wed Oct 14 02:39:10 2020 UTC vs.
Revision 2.21 by greg, Mon Nov 14 00:35:05 2022 UTC

# Line 22 | Line 22 | my $picture = '-';
22   my $cpict = '';
23   my $legwidth = 100;            # Legend width and height
24   my $legheight = 200;
25 + my @overlayWH = (0,0);          # Overlay matrix width and height (default = none)
26 + my @overlayRect;                # Overlay rectangle (left, lower, right, upper)
27   my $haszero = 1;               # print 0 in scale for falsecolor images only
28 < my $docont = '';               # Contours: -cl and -cb
28 > my $docont = '';               # Contours: -cl, -cb, and -c0
29   my $doposter = 0;              # Posterization: -cp
30   my $doextrem = 0;              # Don't mark extrema
31   my $needfile = 0;
32 < my $showpal = 0;               # Show availabel colour palettes
32 > my $showpal = 0;               # Show available colour palettes
33  
34 + my @savedARGV = @ARGV;          # Save for final header
35 +
36   while ($#ARGV >= 0) {
37      $_ = shift;
38      # Options with qualifiers
# Line 39 | Line 43 | while ($#ARGV >= 0) {
43      } elsif (m/-m/) {          # Multiplier
44          $mult = shift;
45      } elsif (m/-spec/) {
46 <        die("depricated option '-spec'. Please use '-pal spec' instead.");
46 >        die("depricated option '-spec'. Please use '-pal spec' instead.\n");
47      } elsif (m/-s/) {          # Scale
48          $scale = shift;
49          if ($scale =~ m/[aA].*/) {
# Line 74 | Line 78 | while ($#ARGV >= 0) {
78          $cpict = $picture;
79      } elsif (m/-n/) {          # Number of contour lines
80          $ndivs = shift;
81 +    } elsif (m/-odim$/) {       # Overlay width and height
82 +        $overlayWH[0] = shift;
83 +        $overlayWH[1] = shift;
84 +        $needfile ||= $overlayWH[0] && $overlayWH[1];
85 +    } elsif (m/-orct/) {        # Overlay rectangle
86 +        $overlayRect[0] = shift;
87 +        $overlayRect[1] = shift;
88 +        $overlayRect[2] = shift;
89 +        $overlayRect[3] = shift;
90  
91      # Switches
92      } elsif (m/-cl/) {         # Contour lines
# Line 82 | Line 95 | while ($#ARGV >= 0) {
95      } elsif (m/-cb/) {         # Contour bands
96          $docont = 'b';
97          $haszero = 0;
98 <    } elsif (m/-cp/) {              # Posterize
98 >    } elsif (m/-cp/) {         # Posterize
99          $doposter = 1;
100          $haszero = 0;
101 +    } elsif (m/-c0/) {          # Turn off falsecolor operation
102 +        $docont = '0';
103 +        $legwidth = 0;
104 +        $legheight = 0;
105      } elsif (m/-palettes/) {        # Show all available palettes
106          $scale   = 45824;           # 256 * 179
107          $showpal = 1;
# Line 106 | Line 123 | if (($legwidth <= 20) || ($legheight <= 40)) {
123   # Temporary directory. Will be removed upon successful program exit.
124   my $td = tempdir( CLEANUP => 1 );
125  
126 < if ($needfile == 1 && $picture eq '-') {
126 > if ($needfile && $picture eq '-') {
127      # Pretend that $td/stdin.rad is the actual filename.
128      $picture = "$td/stdin.hdr";
129      open(FHpic, ">$picture") or
# Line 118 | Line 135 | if ($needfile == 1 && $picture eq '-') {
135      close(FHpic);
136  
137      if ($cpict eq '-') {
138 <        $cpict = "$td/stdin.hdr";
138 >        $cpict = $picture;
139      }
140   }
141  
# Line 132 | Line 149 | if ($scale =~ m/[aA].*/) {
149      $scale = $mult / 179 * 10**$LogLmax;
150   }
151  
152 < if ($docont ne '') {
152 > if ($doposter) {
153 >    # -cp -> $doposter = 1
154 >    my $newv = join( "seg2(v)", split("v", $redv) );
155 >    $redv = $newv;
156 >    $newv = join( "seg2(v)", split("v", $bluv) );
157 >    $bluv = $newv;
158 >    $newv = join( "seg2(v)", split("v", $grnv) );
159 >    $grnv = $newv;
160 > } elsif ($docont) {
161      # -cl -> $docont = a
162      # -cb -> $docont = b
163      my $newv = join( "(v-1/ndivs)*ndivs/(ndivs-1)", split("v", $redv) );
# Line 141 | Line 166 | if ($docont ne '') {
166      $bluv = $newv;
167      $newv = join( "(v-1/ndivs)*ndivs/(ndivs-1)", split("v", $grnv) );
168      $grnv = $newv;
144 } elsif ($doposter == 1) {
145    # -cp -> $doposter = 1
146    my $newv = join( "seg2(v)", split("v", $redv) );
147    $redv = $newv;
148    $newv = join( "seg2(v)", split("v", $bluv) );
149    $bluv = $newv;
150    $newv = join( "seg2(v)", split("v", $grnv) );
151    $grnv = $newv;
169   }
170  
171   my $pc0 = "$td/pc0.cal";
# Line 164 | Line 181 | or(a,b) : if(a,a,b);
181   EPS : 1e-7;
182   neq(a,b) : if(a-b-EPS,1,b-a-EPS);
183   btwn(a,x,b) : if(a-x,-1,b-x);
184 < clip(x) : if(x-1,1,if(x,x,0));
184 > clip(x) : min(1,max(x,0));
185   frac(x) : x - floor(x);
186   boundary(a,b) : neq(floor(ndivs*a),floor(ndivs*b));
187 < round(x):if(x-floor(x)-0.5,ceil(x),floor(x));
187 > round(x) : floor(x+.5);
188  
189   spec_red(x) = 1.6*x - .6;
190   spec_grn(x) = if(x-.375, 1.6-1.6*x, 8/3*x);
# Line 223 | Line 240 | tbo_blu(x):interp_tbo(x,tbo_blup) ^ gamma;
240  
241   isconta = if(btwn(1/ndivs/2,v,1+1/ndivs/2),or(boundary(vleft,vright),boundary(vabove,vbelow)),-1);
242   iscontb = if(btwn(1/ndivs/2,v,1+1/ndivs/2),-btwn(.1,frac(ndivs*v),.9),-1);
243 + iscont0 = -1;
244  
245   seg(x)=(floor(v*ndivs)+.5)/ndivs;
246   seg2(x)=(seg(x)-1/ndivs)*ndivs/(ndivs-1);
# Line 253 | Line 271 | vbelow = map(li(1,0,-1)*norm);
271  
272   map(x) = x;
273  
256
274   ra = ri(nfiles);
275   ga = gi(nfiles);
276   ba = bi(nfiles);
# Line 263 | Line 280 | close FHpc1;
280   my $pc0args = "-f $pc0";
281   my $pc1args = "-f $pc1";
282  
283 < if ($showpal == 1) {
283 > if ($showpal) {
284      my $pc = "pcompos -a 1";
285      foreach my $pal (@palettes) {
286          my $fcimg = "$td/$pal.hdr";
287          my $lbimg = "$td/${pal}_label.hdr";
288          system "psign -cb 0 0 0 -cf 1 1 1 -h 20 $pal > $lbimg";
272
289          my $cmd = qq[pcomb $pc0args -e "v=x/256"];
290          $cmd .= qq[ -e "ro=clip(${pal}_red(v));go=clip(${pal}_grn(v));bo=clip(${pal}_blu(v))"];
291          $cmd .= qq[ -x 256 -y 30 > $fcimg];
# Line 280 | Line 296 | if ($showpal == 1) {
296      exit 0;
297   }
298  
299 < # Contours
284 < if ($docont ne '') {
285 <    # -cl -> $docont = a
286 <    # -cb -> $docont = b
287 <    $pc0args .= qq[ -e "in=iscont$docont"];
288 < }
289 <
290 < if ($cpict eq '') {
299 > if ($cpict eq '' && $docont ne '0') {
300      $pc1args .= qq[ -e "ra=0;ga=0;ba=0"];
301   } elsif ($cpict eq $picture) {
302      $cpict = '';
# Line 298 | Line 307 | if ($decades > 0) {
307      $pc1args .= qq[ -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)"];
308   }
309  
310 + # Contours
311 + if ($docont ne '') {
312 +    # -cl -> $docont = a
313 +    # -cb -> $docont = b
314 +    # -c0 -> $docont = FALSE
315 +    $pc0args .= qq[ -e "in=iscont$docont"];
316 + }
317   # Colours in the legend
318   my $scolpic = "$td/scol.hdr";
319  
# Line 310 | Line 326 | if ($legwidth > 0) {
326      my $theight = floor($legwidth/(8/1.67));
327      my $stheight = $sheight <= $theight ? $sheight : $theight;
328      my $vlegheight = $sheight * $ndivs * (1+1.5/$ndivs);
313    my $text = "$label\n";
329      my $tslabpic = "$td/slabT.hdr";
330 <    open PSIGN, "| psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $stheight > $tslabpic";
316 <    print PSIGN "$text";
317 <    close PSIGN;
330 >    system "psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $stheight $label > $tslabpic";
331      my $loop = $ndivs+$haszero;
332      my $hlegheight = $sheight * ($loop) + $sheight * .5;
333      my $pcompost = qq[pcompos -b 0 0 0 =-0 $tslabpic 0 $hlegheight ];
# Line 326 | Line 339 | if ($legwidth > 0) {
339          } else {
340              $value *= $imap;
341          }
342 <        # Have no more than 3 decimal places
343 <        $value =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
344 <        $text = "$value\n";
342 >        # Limit decimal places
343 >        if ($scaledigits <= 0) {
344 >                $value =~ s/\.[0-9]*//;
345 >        } else {
346 >                $value =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
347 >        }
348          $tslabpic = "$td/slab$i.hdr";
349 <        open PSIGN, "| psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $stheight > $tslabpic";
334 <        print PSIGN "$text";
335 <        close PSIGN;
349 >        system "psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $stheight $value > $tslabpic";
350          $hlegheight = $sheight * ($loop - $i - 1) + $sheight * .5;
351          $pcompost .= qq[=-0 $tslabpic 0 $hlegheight ];
352      }
# Line 356 | Line 370 | if ($legwidth > 0) {
370  
371   # Legend: Invert the text labels (for dropshadow)
372   my $slabinvpic = "$td/slabinv.hdr";
373 < $cmd = qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
360 < system $cmd;
373 > system qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
374  
362
375   my $sh0 = -floor($legheight / $ndivs / 2);
376   if ($haszero < 1) {
377      $sh0 = -floor($legheight / ($ndivs)*1.5);
# Line 369 | Line 381 | if ($haszero < 1) {
381  
382      $cmd = qq[pcomb $pc0args $pc1args "$picture"];
383      $cmd .= qq[ "$cpict"] if ($cpict);
384 <    $cmd .= qq[ | pcompos -b 0 0 0 $scolpic 0 $sh0 +t .1 $slabinvpic 2 -1 ];
384 >    $cmd .= qq[ | pcompos -h -b 0 0 0 $scolpic 0 $sh0 +t .1 $slabinvpic 2 -1];
385      $cmd .= qq[ -t .5 $slabpic 0 0 - $legwidth 0];
386  
387 < if ($doextrem == 1) {
387 > my $cheight = 32;
388 >
389 > if ($overlayWH[0] && $overlayWH[1]) {
390 >    # Overlay picture  matrix values
391 >    my @picWH = split ' ', `getinfo -d < $picture`;
392 >    @picWH = ($picWH[3], $picWH[1]);
393 >    if ($#overlayRect != 3) {
394 >        @overlayRect = (0, 0, @picWH);
395 >    }
396 >    if ($overlayRect[2] <= $overlayRect[0] ||
397 >                $overlayRect[3] <= $overlayRect[1]) {
398 >        die("Illegal overlay rectangle\n");
399 >    }
400 >    # Compute spacing between values
401 >    my @cropWH = ($overlayRect[2]-$overlayRect[0], $overlayRect[3]-$overlayRect[1]);
402 >    my $ohspacing = $cropWH[0] / $overlayWH[0];
403 >    my $ovspacing = $cropWH[1] / $overlayWH[1];
404 >    # Compute character height from spacing
405 >    $cheight = int($ovspacing * 0.67 + 0.5);
406 >    if ($cheight >= 1.67/10 * $ohspacing) {
407 >        $cheight = int(1.67/10 * $ohspacing);
408 >    }
409 >    if ($cheight < 10) {
410 >        die "Overlay matrix spacing too tight\n";
411 >    }
412 >    my $cmd1 = qq[pcompos -x $cropWH[0] -y $cropWH[1] "$picture" @overlayRect[0..1]];
413 >    $cmd1 .= qq[ | pfilt -1 -b -x /$cheight -y /$cheight];
414 >    $cmd1 .= qq[ | pfilt -1 -r .5 -x $cropWH[0] -y $cropWH[1]];
415 >    $cmd1 .= qq[ | pvalue -o -h -H -b -d -e $mult];
416 >    # Compute matrix label center positions in subimage
417 >    my @xpos;
418 >    foreach (0 .. ($overlayWH[0]-1)) {
419 >        $xpos[$_] = int($ohspacing * ($_ + 0.5));
420 >    }
421 >    my @ypos;
422 >    foreach (0 .. ($overlayWH[1]-1)) {
423 >        $ypos[$_] = int($ovspacing * ($_ + 0.5));
424 >    }
425 >    open(FHsamp, "$cmd1 |");
426 >    $cmd1 = qq[pcompos -h -b 0 0 0 -x $cropWH[0] -y $cropWH[1]];
427 >    my $pscmd = qq[psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $cheight];
428 >    for (my $y = 0; $y < $cropWH[1]; $y++) {
429 >        my $ymatch = grep /^$y$/, @ypos;
430 >        my $cmd2 = qq[pcompos -b 0 0 0 -x $cropWH[0]];
431 >        for (my $x = 0; $x < $cropWH[0]; $x++) {
432 >            my $sampv = <FHsamp>;
433 >            next if (! $ymatch);
434 >            next if (! grep /^$x$/, @xpos);
435 >            chomp $sampv;
436 >            # Reformatting assumes %e from pvalue
437 >            $sampv =~ /^\s*([0-9])\.([0-9]+)[eE]([-+]?[0-9]+)$/;
438 >            my $manti = $1;
439 >            my $mantf = $2;
440 >            my $expi = $3;
441 >            if ($expi < -4) {
442 >                # use exponent format
443 >            } elsif ($expi < 0) {
444 >                my $pref = '0.';
445 >                for (my $i = $expi; ++$i < 0; ) {
446 >                        $pref .= '0';
447 >                }
448 >                $sampv = $pref . $manti . $mantf;
449 >            } elsif ($expi < length($mantf)) {
450 >                $sampv = sprintf("%g", $sampv);
451 >            } elsif ($expi <= 8) {
452 >                $sampv = $manti . $mantf;
453 >                for (my $i = $expi - length($mantf); $i-- > 0; ) {
454 >                        $sampv .= '0';
455 >                }
456 >            } # else use exponent format
457 >            $cmd2 .= qq[ =0- "!$pscmd $sampv" $x 0];
458 >        }
459 >        next if (! $ymatch);
460 >        my $rowpic = "$td/mrow$y.hdr";
461 >        system "$cmd2 > $rowpic";
462 >        $cmd1 .= qq[ =-0 $rowpic 0 ] . ($cropWH[1]-1 - $y);
463 >    }
464 >    close(FHsamp);
465 >    my $overpic = "$td/overlay.hdr";
466 >    system "$cmd1 > $overpic";
467 >    my $overinvpic = "$td/overinv.hdr";
468 >    system qq[pcomb -e "lo=1-gi(1)" $overpic > $overinvpic];
469 >    my $xleft = $legwidth + $overlayRect[0];
470 >    my $ybottom = $overlayRect[1];
471 >    $cmd .= qq[ +t .1 $overinvpic $xleft $ybottom];
472 >    # Offset from drop shadow
473 >    $xleft -= 2;
474 >    $ybottom += 1;
475 >    $cmd .= qq[ -t .5 $overpic $xleft $ybottom];
476 > }
477 >
478 > if ($doextrem) {
479      # Get min/max image luminance
480      my $cmd1 = 'pextrem -o ' . $picture;
481      my $retval = `$cmd1`;
# Line 387 | Line 490 | if ($doextrem == 1) {
490      $lxmax += $legwidth;
491  
492      # Weighted average of R,G,B
390    my $minpos = "$lxmin $ymin";
493      my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
392    $minval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
494      my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
495 <    $maxval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
496 <
495 >    if ($scaledigits <= 0) {
496 >        $minval =~ s/\.[0-9]*//;
497 >        $maxval =~ s/\.[0-9]*//;
498 >    } else {
499 >        $minval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
500 >        $maxval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
501 >    }
502      # Create the labels for min/max intensity
503      my $minvpic = "$td/minv.hdr";
504 <    system "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
504 >    system "psign -s -.15 -a 2 -h $cheight $minval > $minvpic";
505      my $maxvpic = "$td/maxv.hdr";
506 <    system "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
506 >    system "psign -s -.15 -a 2 -h $cheight $maxval > $maxvpic";
507  
508      # Add extrema labels to command line
509 <    $cmd .= qq[ $minvpic $minpos $maxvpic $lxmax $ymax];
509 >    $cmd .= qq[ =00 $minvpic $lxmin $ymin =00 $maxvpic $lxmax $ymax];
510   }
511  
512 + # Clean up and simplify info header with out command arguments
513 + $cmd .= qq[ | getinfo -r "pcompos " "falsecolor @savedARGV"];
514  
407
408
515   # Process image and combine with legend
516   system "$cmd";
517 + exit $?;
518  
519   #EOF

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines