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.19 by greg, Fri Nov 11 16:30:06 2022 UTC vs.
Revision 2.20 by greg, Sat Nov 12 20:51:47 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;
# Line 41 | 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 76 | 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 84 | 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 108 | 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 134 | 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 143 | Line 166 | if ($docont ne '') {
166      $bluv = $newv;
167      $newv = join( "(v-1/ndivs)*ndivs/(ndivs-1)", split("v", $grnv) );
168      $grnv = $newv;
146 } elsif ($doposter == 1) {
147    # -cp -> $doposter = 1
148    my $newv = join( "seg2(v)", split("v", $redv) );
149    $redv = $newv;
150    $newv = join( "seg2(v)", split("v", $bluv) );
151    $bluv = $newv;
152    $newv = join( "seg2(v)", split("v", $grnv) );
153    $grnv = $newv;
169   }
170  
171   my $pc0 = "$td/pc0.cal";
# Line 225 | 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 255 | Line 271 | vbelow = map(li(1,0,-1)*norm);
271  
272   map(x) = x;
273  
258
274   ra = ri(nfiles);
275   ga = gi(nfiles);
276   ba = bi(nfiles);
# Line 265 | 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";
# Line 282 | Line 297 | if ($showpal == 1) {
297      exit 0;
298   }
299  
300 < # Contours
286 < if ($docont ne '') {
287 <    # -cl -> $docont = a
288 <    # -cb -> $docont = b
289 <    $pc0args .= qq[ -e "in=iscont$docont"];
290 < }
291 <
292 < if ($cpict eq '') {
300 > if ($cpict eq '' && $docont ne '0') {
301      $pc1args .= qq[ -e "ra=0;ga=0;ba=0"];
302   } elsif ($cpict eq $picture) {
303      $cpict = '';
# Line 300 | Line 308 | if ($decades > 0) {
308      $pc1args .= qq[ -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)"];
309   }
310  
311 + # Contours
312 + if ($docont ne '') {
313 +    # -cl -> $docont = a
314 +    # -cb -> $docont = b
315 +    # -c0 -> $docont = FALSE
316 +    $pc0args .= qq[ -e "in=iscont$docont"];
317 + }
318   # Colours in the legend
319   my $scolpic = "$td/scol.hdr";
320  
# Line 325 | Line 340 | if ($legwidth > 0) {
340          } else {
341              $value *= $imap;
342          }
343 <        # Have no more than 3 decimal places
344 <        $value =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
343 >        # Limit decimal places
344 >        if ($scaledigits <= 0) {
345 >                $value =~ s/\.[0-9]*//;
346 >        } else {
347 >                $value =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
348 >        }
349          $tslabpic = "$td/slab$i.hdr";
350          system "psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $stheight $value > $tslabpic";
351          $hlegheight = $sheight * ($loop - $i - 1) + $sheight * .5;
# Line 352 | Line 371 | if ($legwidth > 0) {
371  
372   # Legend: Invert the text labels (for dropshadow)
373   my $slabinvpic = "$td/slabinv.hdr";
374 < $cmd = qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
356 < system $cmd;
374 > system qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
375  
358
376   my $sh0 = -floor($legheight / $ndivs / 2);
377   if ($haszero < 1) {
378      $sh0 = -floor($legheight / ($ndivs)*1.5);
# Line 365 | Line 382 | if ($haszero < 1) {
382  
383      $cmd = qq[pcomb $pc0args $pc1args "$picture"];
384      $cmd .= qq[ "$cpict"] if ($cpict);
385 <    $cmd .= qq[ | pcompos -h -b 0 0 0 $scolpic 0 $sh0 +t .1 $slabinvpic 2 -1 ];
385 >    $cmd .= qq[ | pcompos -h -b 0 0 0 $scolpic 0 $sh0 +t .1 $slabinvpic 2 -1];
386      $cmd .= qq[ -t .5 $slabpic 0 0 - $legwidth 0];
387  
388 < if ($doextrem == 1) {
388 > my $cheight = 32;
389 >
390 > if ($overlayWH[0] && $overlayWH[1]) {
391 >    # Overlay picture  matrix values
392 >    my @picWH = split ' ', `getinfo -d < $picture`;
393 >    @picWH = ($picWH[3], $picWH[1]);
394 >    if ($#overlayRect != 3) {
395 >        @overlayRect = (0, 0, @picWH);
396 >    }
397 >    if ($overlayRect[2] <= $overlayRect[0] ||
398 >                $overlayRect[3] <= $overlayRect[1]) {
399 >        die("Illegal overlay rectangle\n");
400 >    }
401 >    # Compute spacing between values
402 >    my @cropWH = ($overlayRect[2]-$overlayRect[0], $overlayRect[3]-$overlayRect[1]);
403 >    my $ohspacing = $cropWH[0] / $overlayWH[0];
404 >    my $ovspacing = $cropWH[1] / $overlayWH[1];
405 >    # Compute character height from spacing
406 >    $cheight = int($ovspacing * 0.67 + 0.5);
407 >    if ($cheight >= 1.67/10 * $ohspacing) {
408 >        $cheight = int(1.67/10 * $ohspacing);
409 >    }
410 >    if ($cheight < 10) {
411 >        die "Overlay matrix spacing too tight\n";
412 >    }
413 >    my $cmd1 = qq[pcompos -x $cropWH[0] -y $cropWH[1] "$picture" @overlayRect[0..1]];
414 >    $cmd1 .= qq[ | pfilt -1 -b -x /$cheight -y /$cheight];
415 >    $cmd1 .= qq[ | pfilt -1 -r .5 -x $cropWH[0] -y $cropWH[1]];
416 >    $cmd1 .= qq[ | pvalue -o -h -H -b -d -e $mult];
417 >    # Compute matrix label center positions in subimage
418 >    my @xpos;
419 >    foreach (0 .. ($overlayWH[0]-1)) {
420 >        $xpos[$_] = int($ohspacing * ($_ + 0.5));
421 >    }
422 >    my @ypos;
423 >    foreach (0 .. ($overlayWH[1]-1)) {
424 >        $ypos[$_] = int($ovspacing * ($_ + 0.5));
425 >    }
426 >    open(FHsamp, "$cmd1 |");
427 >    $cmd1 = qq[pcompos -h -b 0 0 0 -x $cropWH[0] -y $cropWH[1]];
428 >    my $pscmd = qq[psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $cheight];
429 >    for (my $y = 0; $y < $cropWH[1]; $y++) {
430 >        my $ymatch = grep /^$y$/, @ypos;
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 >            $cmd1 .= qq[ =00 "!$pscmd $sampv" $x ] . ($cropWH[1]-1 - $y);
458 >        }
459 >    }
460 >    close(FHsamp);
461 >    my $overpic = "$td/overlay.hdr";
462 >    system "$cmd1 > $overpic";
463 >    die "Error creating overlay matrix image\n" if ($?);
464 >    my $overinvpic = "$td/overinv.hdr";
465 >    system qq[pcomb -e "lo=1-gi(1)" $overpic > $overinvpic];
466 >    my $xleft = $legwidth + $overlayRect[0];
467 >    my $ybottom = $overlayRect[1];
468 >    $cmd .= qq[ +t .1 $overinvpic $xleft $ybottom];
469 >    # Offset from drop shadow
470 >    $xleft -= 2;
471 >    $ybottom += 1;
472 >    $cmd .= qq[ -t .5 $overpic $xleft $ybottom];
473 > }
474 >
475 > if ($doextrem) {
476      # Get min/max image luminance
477      my $cmd1 = 'pextrem -o ' . $picture;
478      my $retval = `$cmd1`;
# Line 383 | Line 487 | if ($doextrem == 1) {
487      $lxmax += $legwidth;
488  
489      # Weighted average of R,G,B
386    my $minpos = "$lxmin $ymin";
490      my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
388    $minval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
491      my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
492 <    $maxval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
493 <
492 >    if ($scaledigits <= 0) {
493 >        $minval =~ s/\.[0-9]*//;
494 >        $maxval =~ s/\.[0-9]*//;
495 >    } else {
496 >        $minval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
497 >        $maxval =~ s/(\.[0-9]{$scaledigits})[0-9]*/$1/;
498 >    }
499      # Create the labels for min/max intensity
500      my $minvpic = "$td/minv.hdr";
501 <    system "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
501 >    system "psign -s -.15 -a 2 -h $cheight $minval > $minvpic";
502      my $maxvpic = "$td/maxv.hdr";
503 <    system "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
503 >    system "psign -s -.15 -a 2 -h $cheight $maxval > $maxvpic";
504  
505      # Add extrema labels to command line
506 <    $cmd .= qq[ $minvpic $minpos $maxvpic $lxmax $ymax];
506 >    $cmd .= qq[ =00 $minvpic $lxmin $ymin =00 $maxvpic $lxmax $ymax];
507   }
508  
509 < # Clean up and simplify info header with this command
509 > # Clean up and simplify info header with out command arguments
510   $cmd .= qq[ | getinfo -r "pcompos " "falsecolor @savedARGV"];
511  
512   # Process image and combine with legend
513   system "$cmd";
514 + exit $?;
515  
516   #EOF

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines