ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/bsdfview.pl
Revision: 2.2
Committed: Sat Aug 12 01:31:29 2017 UTC (6 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +7 -2 lines
Log Message:
Improved handling of repeat runs

File Contents

# User Rev Content
1 greg 2.1 #!/usr/bin/perl
2 greg 2.2 # RCSid $Id: bsdfview.pl,v 2.1 2017/08/11 21:39:52 greg Exp $
3 greg 2.1 #
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 $vw = "def";
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     $vw = $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/^-\w/) {
42     die("bsdfview: Bad option: $_\n");
43     } else {
44     last;
45     }
46     shift @ARGV;
47     }
48    
49     # We need at least one XML or SIR file
50     if ($#ARGV < 0) {
51     die("Missing input XML or SIR file(s)\n");
52     }
53    
54     my @objects = @ARGV;
55    
56     # Make this work under Windoze
57     if ( $^O =~ /MSWin32/ ) {
58     for my $i (0 .. $#objects) {
59     # rad doesn't like Windows-style backslashes.
60     $objects[$i] =~ s{\\}{/}g;
61     }
62     $octree =~ s{\\}{/}g;
63     $ambf =~ s{\\}{/}g;
64     $raddev = "qt";
65     }
66    
67     my $name = $objects[0];
68     $name =~ s{.*/}{}; # remove leading path
69     $name =~ s{\.[^.]+$}{}; # remove file extension
70    
71     my $rif = "$name.rif";
72    
73 greg 2.2 if (-e $rif) { # RIF already exists?
74     print "Attempting to run with existing rad input file '$rif'\n";
75     system "rad -o $raddev -w -v $vw $opts $rif QUA=$qual";
76     die("\nTry removing '$rif' and starting again\n\n") if $?;
77     exit;
78     }
79 greg 2.1
80     print "bsdfview: creating rad input file '$rif'\n";
81    
82     my $scene = qq("!bsdf2rad @objects"); # let bsdf2rad do complaining
83    
84     my $objects = join(' ', @objects);
85     open(FH, ">$rif") or
86     die("bsdfview: Can't write to temporary file $rif\n");
87     print FH <<EndOfRif;
88     scene= $scene
89     objects= $objects
90     ZONE= E -35 35 -20 15 -5 15
91     PICTURE= $name
92     RESOLU= 1024
93     EXPOSURE= 1
94     UP= +Z
95     OCTREE= $octree
96     oconv= -w -f
97     AMBF= $ambf
98     QUAL = $qual
99     render= $rendopts
100     view= def -vp 0 -50 50 -vd 0 50 -50 -vh 45 -vv 30
101     view= fr -vp 15 -30 30 -vd 0 30 -30
102     view= br -vp -15 -30 30 -vd 0 30 -30
103     view= ft -vta -vp 15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
104     view= bt -vta -vp -15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
105     view= pr -vtl -vp 0 0 20 -vd 0 0 -1 -vu 0 1 0 -vv 35 -vh 65
106     view= pt -vtl -vp 0 0 -10 -vd 0 0 1 -vu 0 1 0 -vv 35 -vh 65
107     EndOfRif
108     close(FH);
109    
110     system "rad -o $raddev -v $vw $opts $rif";
111    
112     #EOF