ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/bsdfview.pl
Revision: 2.8
Committed: Wed Jan 26 18:01:41 2022 UTC (8 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.7: +6 -1 lines
Log Message:
feat(bsdfview): Added call to checkBSDF for XML input

File Contents

# Content
1 #!/usr/bin/perl
2 # RCSid $Id: bsdfview.pl,v 2.7 2018/07/20 00:50:40 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 if ($objects[0] =~ /\.xml$/i) {
95 system "checkBSDF $objects[0]";
96 die "Bad XML input\n" if ( $? );
97 }
98
99 print "bsdfview: creating rad input file '$rif'\n";
100
101 my $scene = qq("!bsdf2rad @range @objects"); # let bsdf2rad do complaining
102
103 my $objects = join(' ', @objects);
104 open(FH, ">$rif") or
105 die("bsdfview: Can't write to temporary file $rif\n");
106 print FH <<EndOfRif;
107 scene= $scene
108 objects= $objects
109 ZONE= E -35 35 -20 15 -5 15
110 PICTURE= $name
111 RESOLU= 1024
112 EXPOSURE= 1
113 UP= +Z
114 OCTREE= $octree
115 oconv= -w -f
116 AMBF= $ambf
117 QUAL= $qual
118 render= $rendopts
119 view= def -vp 0 -50 50 -vd 0 50 -50 -vh 45 -vv 30
120 view= fr -vp 15 -30 30 -vd 0 30 -30
121 view= br -vp -15 -30 30 -vd 0 30 -30
122 view= ft -vta -vp 15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
123 view= bt -vta -vp -15 0 0 -vd 0 0 1 -vu 0 1 0 -vh 200 -vv 200
124 view= pr -vtl -vp 0 0 20 -vd 0 0 -1 -vu 0 1 0 -vv 35 -vh 65
125 view= pt -vtl -vp 0 0 -10 -vd 0 0 1 -vu 0 1 0 -vv 35 -vh 65
126 EndOfRif
127 close(FH);
128
129 if ($usetrad) {
130 system "rad -v 0 $rif ; trad $rif";
131 } else {
132 system "rad -o $raddev $opts $rif";
133 }
134 #EOF