ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/bsdfview.pl
Revision: 2.7
Committed: Fri Jul 20 00:50:40 2018 UTC (5 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad5R3
Changes since 2.6: +7 -3 lines
Log Message:
Added "-r" option to bsdf2rad and bsdfview to fix plotting range

File Contents

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