ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcode2bmp.pl
Revision: 2.2
Committed: Tue Jan 21 18:00:17 2020 UTC (4 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R3
Changes since 2.1: +2 -2 lines
Log Message:
Made reference depth unit extraction more robust

File Contents

# User Rev Content
1 greg 2.1 #!/usr/bin/perl
2 greg 2.2 # RCSid $Id: rcode2bmp.pl,v 2.1 2019/07/26 00:34:07 greg Exp $
3 greg 2.1 #
4     # Convert one or more rtpict outputs into BMP for convenient viewing
5     #
6    
7     use strict;
8     use warnings;
9    
10     my $xres=0;
11     my $yres=0;
12     my $pfilt="";
13    
14     # Get options, which must precede input maps
15     while ($#ARGV >= 0 && "$ARGV[0]" =~ /^-[a-zA-Z]/) {
16     if ("$ARGV[0]" eq '-x') {
17     shift @ARGV;
18     $xres = shift(@ARGV);
19     } elsif ("$ARGV[0]" eq '-y') {
20     shift @ARGV;
21     $yres = shift(@ARGV);
22     } else {
23     die "Bad option: $ARGV[0]\n";
24     }
25     }
26     # Set up resizing operation if requested
27     if ($xres > 0 && $yres > 0) {
28     $pfilt = "pfilt -x $xres -y $yres -pa 1 -1 -r .6";
29     }
30     # Load/convert each file
31     INPUT_MAP:
32     while ($#ARGV >= 0) {
33     if ("$ARGV[0]" =~ /\.bmp$/i) {
34     print STDERR "Skipping file '$ARGV[0]' already in BMP format\n";
35     shift @ARGV;
36     next INPUT_MAP;
37     }
38     my $format = `getinfo < '$ARGV[0]' | sed -n 's/^FORMAT= *//p'`;
39     chomp $format;
40     die "Cannot get format from $ARGV[0]\n" if ( $? || ! $format );
41     my ($dest) = ("$ARGV[0]" =~ /^([^.]+)/);
42     $dest .= ".bmp";
43     my $cmd="";
44     if ("$format" =~ /^32-bit_rle_(rgb|xyz)e$/) {
45     if ($pfilt) {
46     $cmd = $pfilt . " '$ARGV[0]' | ra_bmp -e auto - '$dest'";
47     } else {
48     $cmd = "ra_bmp -e auto '$ARGV[0]' '$dest'";
49     }
50     } elsif ("$format" eq "16-bit_encoded_depth") {
51     $cmd = "rcode_depth -r -ff -ho -Ho '$ARGV[0]' ";
52     $cmd .= q{| rcalc -if -of -e 'cond=9e9-$1;$1=$1' | total -if -u};
53     my $dmax=`$cmd`;
54     $dmax = 2**(int(log($dmax)/log(2))+1);
55 greg 2.2 my $unit=`getinfo < '$ARGV[0]' | sed -n 's/^REFDEPTH= *[0-9.]*[^a-zA-Z]*//p'`;
56 greg 2.1 chomp $unit;
57     $unit="Depth" if ( ! $unit );
58     $cmd = "rcode_depth -r -ff '$ARGV[0]' | pvalue -r -df -b ";
59     $cmd .= "| $pfilt " if ($pfilt);
60     $cmd .= "| falsecolor -l '$unit' -m 1 -s $dmax | ra_bmp - '$dest'";
61     } elsif ("$format" =~ /[1-9][0-9]*-bit_indexed_name$/) {
62     $cmd = "rcode_ident -r -n '$ARGV[0]' " .
63     "| getinfo +d -c rcalc -e 'cc(x):(.1+.8*rand(x))^2' " .
64     q{-e '$1=cc(.398*$1-11.2);$2=cc(-1.152*$1+41.7);$3=cc(8.571*$1-8.15)' } .
65     "| pvalue -r -d ";
66     $cmd .= "| $pfilt " if ($pfilt);
67     $cmd .= "| ra_bmp - '$dest'";
68     } elsif ("$format" eq "32-bit_encoded_normal") {
69     $cmd = "rcode_norm -r -ff '$ARGV[0]' | getinfo +d -c " .
70     "rcalc -if3 -of -e `vwright v < '$ARGV[0]'` " .
71     q{-e 'dot(vx,vy,vz)=vx*$1+vy*$2+vz*$3' } .
72     "-e 'h=dot(vhx,vhy,vhz)' " .
73     "-e 'v=dot(vvx,vvy,vvz)' " .
74     "-e 'n=-dot(vdx,vdy,vdz)' " .
75     "-f hsv_rgb.cal -e 'hue=mod(180/PI*atan2(v,h),360)' " .
76     "-e 'sat=sqrt(h*h+v*v)' -e 'val=if(n,1,1+n)' " .
77     q{-e '$1=R(hue,sat,val);$2=G(hue,sat,val);$3=B(hue,sat,val)' } .
78     "| pvalue -r -df ";
79     $cmd .= "| $pfilt " if ($pfilt);
80     $cmd .= "| ra_bmp - '$dest'";
81     }
82     if ($cmd) {
83     system $cmd;
84     die "Cannot convert $ARGV[0]\n" if ( $? );
85     print "Converted $ARGV[0] to $dest\n";
86     } else {
87     print STDERR "Skipping unsupported format '$format' for input '$ARGV[0]'\n";
88     }
89     shift @ARGV;
90     }
91     # EOF