ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/bsdfview.pl
Revision: 2.3
Committed: Thu Aug 17 21:32:29 2017 UTC (6 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R1
Changes since 2.2: +20 -7 lines
Log Message:
Final check-ins to get evalglare working and addition of bsdfview -t option

File Contents

# Content
1 #!/usr/bin/perl
2 # RCSid $Id: bsdfview.pl,v 2.2 2017/08/12 01:31:29 greg Exp $
3 #
4 # Call bsdf2rad to render BSDF and start viewing it.
5 # Arguments are BSDF XML or SIR file(s)
6 #
7 use strict;
8 use warnings;
9 use File::Temp qw/ tempdir /;
10
11 my $td = tempdir( CLEANUP => 0 );
12 my $octree = "$td/bv$$.oct";
13 my $ambf = "$td/af$$.amb";
14 my $raddev = "x11"; # default output device. Overwrite with -o
15 my $qual = "Low";
16 my $usetrad = 0;
17
18 my $opts = ""; # Options common to rad
19 my $rendopts = "-w-"; # For render= line in rif file
20
21 while (@ARGV) {
22 $_ = $ARGV[0];
23 if ((m/^-s\b/) or (m/^-w/)) { # silent, no warnings
24 $opts .= " $_";
25 } elsif (m/^-v\b/) { # standard view
26 # Let rad do any error handling...
27 $opts .= qq( -v "$ARGV[1]");
28 shift @ARGV;
29 } elsif (m/^-[nN]\b/) { # No. of parallel processes
30 $opts .= ' -N ' . $ARGV[1];
31 shift @ARGV;
32 } elsif (m/^-o\b/) { # output device (rvu -devices)
33 $raddev = $ARGV[1];
34 shift @ARGV;
35 } elsif (m/^-q/) { # quality setting
36 $qual = $ARGV[1];
37 shift @ARGV;
38 } elsif ((m/^-V\b/) or (m/^-e\b/)) { # print view, explicate variables
39 # Think of those two as '-verbose'.
40 $opts .= " $_";
41 } elsif (m/^-t\b/) { # start trad instead of rad
42 $usetrad = 1;
43 } elsif (m/^-\w/) {
44 die("bsdfview: Bad option: $_\n");
45 } else {
46 last;
47 }
48 shift @ARGV;
49 }
50
51 # We need at least one XML or SIR file
52 if ($#ARGV < 0) {
53 die("bsdfview: missing input XML or SIR file(s)\n");
54 }
55
56 if (length($opts) and $usetrad) {
57 die("bsdfview: rad options not supported when calling trad (-t)\n");
58 }
59
60 my @objects = @ARGV;
61
62 # Make this work under Windoze
63 if ( $^O =~ /MSWin32/ ) {
64 for my $i (0 .. $#objects) {
65 # rad doesn't like Windows-style backslashes.
66 $objects[$i] =~ s{\\}{/}g;
67 }
68 $octree =~ s{\\}{/}g;
69 $ambf =~ s{\\}{/}g;
70 $raddev = "qt";
71 }
72
73 my $name = $objects[0];
74 $name =~ s{.*/}{}; # remove leading path
75 $name =~ s{\.[^.]+$}{}; # remove file extension
76
77 my $rif = "$name.rif";
78
79 if (-e $rif) { # RIF already exists?
80 print "Attempting to run with existing rad input file '$rif'\n";
81 if ($usetrad) {
82 system "trad $rif";
83 } else {
84 system "rad -o $raddev -w $opts $rif QUA=$qual";
85 }
86 die("\nTry removing '$rif' and starting again\n\n") if $?;
87 exit;
88 }
89
90 print "bsdfview: creating rad input file '$rif'\n";
91
92 my $scene = qq("!bsdf2rad @objects"); # let bsdf2rad do complaining
93
94 my $objects = join(' ', @objects);
95 open(FH, ">$rif") or
96 die("bsdfview: Can't write to temporary file $rif\n");
97 print FH <<EndOfRif;
98 scene= $scene
99 objects= $objects
100 ZONE= E -35 35 -20 15 -5 15
101 PICTURE= $name
102 RESOLU= 1024
103 EXPOSURE= 1
104 UP= +Z
105 OCTREE= $octree
106 oconv= -w -f
107 AMBF= $ambf
108 QUAL = $qual
109 render= $rendopts
110 view= def -vp 0 -50 50 -vd 0 50 -50 -vh 45 -vv 30
111 view= fr -vp 15 -30 30 -vd 0 30 -30
112 view= br -vp -15 -30 30 -vd 0 30 -30
113 view= ft -vta -vp 15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
114 view= bt -vta -vp -15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
115 view= pr -vtl -vp 0 0 20 -vd 0 0 -1 -vu 0 1 0 -vv 35 -vh 65
116 view= pt -vtl -vp 0 0 -10 -vd 0 0 1 -vu 0 1 0 -vv 35 -vh 65
117 EndOfRif
118 close(FH);
119
120 if ($usetrad) {
121 system "trad $rif";
122 } else {
123 system "rad -o $raddev $opts $rif";
124 }
125 #EOF