1 |
– |
/* Copyright (c) 1993 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Executive program for oconv, rpict and pfilt |
6 |
|
*/ |
7 |
|
|
8 |
|
#include "standard.h" |
9 |
< |
#include "paths.h" |
9 |
> |
|
10 |
|
#include <ctype.h> |
11 |
+ |
#include <time.h> |
12 |
|
|
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" |
15 |
+ |
#include "view.h" |
16 |
+ |
#include "paths.h" |
17 |
+ |
#include "vars.h" |
18 |
|
|
19 |
< |
typedef struct { |
20 |
< |
char *name; /* variable name */ |
21 |
< |
short nick; /* # characters required for nickname */ |
22 |
< |
short nass; /* # assignments made */ |
23 |
< |
char *value; /* assigned value(s) */ |
24 |
< |
int (*fixval)(); /* assignment checking function */ |
25 |
< |
} VARIABLE; |
19 |
> |
#ifdef _WIN32 |
20 |
> |
#define DELCMD "del" |
21 |
> |
#define RENAMECMD "rename" |
22 |
> |
#else |
23 |
> |
#define DELCMD "rm -f" |
24 |
> |
#define RENAMECMD "mv" |
25 |
> |
#include <sys/types.h> |
26 |
> |
#include <sys/wait.h> |
27 |
> |
#endif |
28 |
|
|
29 |
< |
int onevalue(), catvalues(); |
30 |
< |
|
31 |
< |
/* variables */ |
32 |
< |
#define OBJECT 0 /* object files */ |
33 |
< |
#define SCENE 1 /* scene files */ |
34 |
< |
#define MATERIAL 2 /* material files */ |
35 |
< |
#define RENDER 3 /* rendering options */ |
36 |
< |
#define OCONV 4 /* oconv options */ |
37 |
< |
#define PFILT 5 /* pfilt options */ |
38 |
< |
#define VIEW 6 /* view(s) for picture(s) */ |
39 |
< |
#define ZONE 7 /* simulation zone */ |
40 |
< |
#define QUALITY 8 /* desired rendering quality */ |
41 |
< |
#define OCTREE 9 /* octree file name */ |
42 |
< |
#define PICTURE 10 /* picture file name */ |
43 |
< |
#define AMBFILE 11 /* ambient file name */ |
44 |
< |
#define OPTFILE 12 /* rendering options file */ |
45 |
< |
#define EXPOSURE 13 /* picture exposure setting */ |
46 |
< |
#define RESOLUTION 14 /* maximum picture resolution */ |
47 |
< |
#define UP 15 /* view up (X, Y or Z) */ |
48 |
< |
#define INDIRECT 16 /* indirection in lighting */ |
49 |
< |
#define DETAIL 17 /* level of scene detail */ |
50 |
< |
#define PENUMBRAS 18 /* shadow penumbras are desired */ |
51 |
< |
#define VARIABILITY 19 /* level of light variability */ |
52 |
< |
#define REPORT 20 /* report frequency and errfile */ |
29 |
> |
/* variables (alphabetical by name) */ |
30 |
> |
#define AMBFILE 0 /* ambient file name */ |
31 |
> |
#define DETAIL 1 /* level of scene detail */ |
32 |
> |
#define EXPOSURE 2 /* picture exposure setting */ |
33 |
> |
#define EYESEP 3 /* interocular distance */ |
34 |
> |
#define ILLUM 4 /* mkillum input files */ |
35 |
> |
#define INDIRECT 5 /* indirection in lighting */ |
36 |
> |
#define MATERIAL 6 /* material files */ |
37 |
> |
#define MKILLUM 7 /* mkillum options */ |
38 |
> |
#define OBJECT 8 /* object files */ |
39 |
> |
#define OCONV 9 /* oconv options */ |
40 |
> |
#define OCTREE 10 /* octree file name */ |
41 |
> |
#define OPTFILE 11 /* rendering options file */ |
42 |
> |
#define PENUMBRAS 12 /* shadow penumbras are desired */ |
43 |
> |
#define PFILT 13 /* pfilt options */ |
44 |
> |
#define PICTURE 14 /* picture file root name */ |
45 |
> |
#define QUALITY 15 /* desired rendering quality */ |
46 |
> |
#define RAWFILE 16 /* raw picture file root name */ |
47 |
> |
#define RENDER 17 /* rendering options */ |
48 |
> |
#define REPORT 18 /* report frequency and errfile */ |
49 |
> |
#define RESOLUTION 19 /* maximum picture resolution */ |
50 |
> |
#define SCENE 20 /* scene files */ |
51 |
> |
#define UP 21 /* view up (X, Y or Z) */ |
52 |
> |
#define VARIABILITY 22 /* level of light variability */ |
53 |
> |
#define VIEWS 23 /* view(s) for picture(s) */ |
54 |
> |
#define ZFILE 24 /* distance file root name */ |
55 |
> |
#define ZONE 25 /* simulation zone */ |
56 |
|
/* total number of variables */ |
57 |
< |
#define NVARS 21 |
57 |
> |
int NVARS = 26; |
58 |
|
|
59 |
< |
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
60 |
< |
{"objects", 3, 0, NULL, catvalues}, |
61 |
< |
{"scene", 3, 0, NULL, catvalues}, |
59 |
> |
VARIABLE vv[] = { /* variable-value pairs */ |
60 |
> |
{"AMBFILE", 3, 0, NULL, onevalue}, |
61 |
> |
{"DETAIL", 3, 0, NULL, qualvalue}, |
62 |
> |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
63 |
> |
{"EYESEP", 3, 0, NULL, fltvalue}, |
64 |
> |
{"illum", 3, 0, NULL, catvalues}, |
65 |
> |
{"INDIRECT", 3, 0, NULL, intvalue}, |
66 |
|
{"materials", 3, 0, NULL, catvalues}, |
67 |
< |
{"render", 3, 0, NULL, catvalues}, |
67 |
> |
{"mkillum", 3, 0, NULL, catvalues}, |
68 |
> |
{"objects", 3, 0, NULL, catvalues}, |
69 |
|
{"oconv", 3, 0, NULL, catvalues}, |
57 |
– |
{"pfilt", 2, 0, NULL, catvalues}, |
58 |
– |
{"view", 2, 0, NULL, NULL}, |
59 |
– |
{"ZONE", 2, 0, NULL, onevalue}, |
60 |
– |
{"QUALITY", 3, 0, NULL, onevalue}, |
70 |
|
{"OCTREE", 3, 0, NULL, onevalue}, |
62 |
– |
{"PICTURE", 3, 0, NULL, onevalue}, |
63 |
– |
{"AMBFILE", 3, 0, NULL, onevalue}, |
71 |
|
{"OPTFILE", 3, 0, NULL, onevalue}, |
72 |
< |
{"EXPOSURE", 3, 0, NULL, onevalue}, |
72 |
> |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
73 |
> |
{"pfilt", 2, 0, NULL, catvalues}, |
74 |
> |
{"PICTURE", 3, 0, NULL, onevalue}, |
75 |
> |
{"QUALITY", 3, 0, NULL, qualvalue}, |
76 |
> |
{"RAWFILE", 3, 0, NULL, onevalue}, |
77 |
> |
{"render", 3, 0, NULL, catvalues}, |
78 |
> |
{"REPORT", 3, 0, NULL, onevalue}, |
79 |
|
{"RESOLUTION", 3, 0, NULL, onevalue}, |
80 |
+ |
{"scene", 3, 0, NULL, catvalues}, |
81 |
|
{"UP", 2, 0, NULL, onevalue}, |
82 |
< |
{"INDIRECT", 3, 0, NULL, onevalue}, |
83 |
< |
{"DETAIL", 3, 0, NULL, onevalue}, |
84 |
< |
{"PENUMBRAS", 3, 0, NULL, onevalue}, |
85 |
< |
{"VARIABILITY", 3, 0, NULL, onevalue}, |
72 |
< |
{"REPORT", 3, 0, NULL, onevalue}, |
82 |
> |
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
83 |
> |
{"view", 2, 0, NULL, NULL}, |
84 |
> |
{"ZFILE", 2, 0, NULL, onevalue}, |
85 |
> |
{"ZONE", 2, 0, NULL, onevalue}, |
86 |
|
}; |
87 |
|
|
75 |
– |
VARIABLE *matchvar(); |
76 |
– |
char *nvalue(); |
77 |
– |
int vscale(); |
78 |
– |
|
79 |
– |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
80 |
– |
|
81 |
– |
#define vnam(vc) (vv[vc].name) |
82 |
– |
#define vdef(vc) (vv[vc].nass) |
83 |
– |
#define vval(vc) (vv[vc].value) |
84 |
– |
#define vint(vc) atoi(vval(vc)) |
85 |
– |
#define vlet(vc) UPPER(vval(vc)[0]) |
86 |
– |
#define vbool(vc) (vlet(vc)=='T') |
87 |
– |
|
88 |
– |
#define HIGH 2 |
89 |
– |
#define MEDIUM 1 |
90 |
– |
#define LOW 0 |
91 |
– |
|
92 |
– |
int lowqopts(), medqopts(), hiqopts(); |
93 |
– |
int (*setqopts[3])() = {lowqopts, medqopts, hiqopts}; |
94 |
– |
|
95 |
– |
#define renderopts (*setqopts[vscale(QUALITY)]) |
96 |
– |
|
88 |
|
/* overture calculation file */ |
89 |
< |
#ifdef NIX |
90 |
< |
char overfile[] = "overture.raw"; |
89 |
> |
#ifdef NULL_DEVICE |
90 |
> |
char overfile[] = NULL_DEVICE; |
91 |
|
#else |
92 |
< |
char overfile[] = "/dev/null"; |
92 |
> |
char overfile[] = "overture.unf"; |
93 |
|
#endif |
94 |
|
|
104 |
– |
extern long fdate(), time(); |
95 |
|
|
96 |
< |
long scenedate; /* date of latest scene or object file */ |
97 |
< |
long octreedate; /* date of octree */ |
96 |
> |
time_t scenedate; /* date of latest scene or object file */ |
97 |
> |
time_t octreedate; /* date of octree */ |
98 |
> |
time_t matdate; /* date of latest material file */ |
99 |
> |
time_t illumdate; /* date of last illum file */ |
100 |
|
|
101 |
+ |
char *oct0name; /* name of pre-mkillum octree */ |
102 |
+ |
time_t oct0date; /* date of pre-mkillum octree */ |
103 |
+ |
char *oct1name; /* name of post-mkillum octree */ |
104 |
+ |
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
105 |
+ |
|
106 |
+ |
int nowarn = 0; /* no warnings */ |
107 |
|
int explicate = 0; /* explicate variables */ |
108 |
|
int silent = 0; /* do work silently */ |
109 |
< |
int noaction = 0; /* don't do anything */ |
110 |
< |
char *rvdevice = NULL; /* rview output device */ |
109 |
> |
int touchonly = 0; /* touch files only */ |
110 |
> |
int nprocs = 1; /* maximum executing processes */ |
111 |
> |
int sayview = 0; /* print view out */ |
112 |
> |
char *rvdevice = NULL; /* rvu output device */ |
113 |
|
char *viewselect = NULL; /* specific view only */ |
114 |
|
|
115 |
|
int overture = 0; /* overture calculation needed */ |
116 |
|
|
117 |
+ |
int children_running = 0; /* set negative in children */ |
118 |
+ |
|
119 |
|
char *progname; /* global argv[0] */ |
120 |
+ |
char *rifname; /* global rad input file name */ |
121 |
|
|
122 |
< |
char radname[MAXPATH]; /* root Radiance file name */ |
122 |
> |
char radname[PATH_MAX]; /* root Radiance file name */ |
123 |
|
|
124 |
+ |
#define inchild() (children_running < 0) |
125 |
|
|
126 |
< |
main(argc, argv) |
127 |
< |
int argc; |
128 |
< |
char *argv[]; |
126 |
> |
static void rootname(char *rn, char *fn); |
127 |
> |
static time_t checklast(char *fnames); |
128 |
> |
static char * newfname(char *orig, int pred); |
129 |
> |
static void checkfiles(void); |
130 |
> |
static void getoctcube(double org[3], double *sizp); |
131 |
> |
static void setdefaults(void); |
132 |
> |
static void oconv(void); |
133 |
> |
static char * addarg(char *op, char *arg); |
134 |
> |
static void oconvopts(char *oo); |
135 |
> |
static void mkillumopts(char *mo); |
136 |
> |
static void checkambfile(void); |
137 |
> |
static double ambval(void); |
138 |
> |
static void renderopts(char *op, char *po); |
139 |
> |
static void lowqopts(char *op, char *po); |
140 |
> |
static void medqopts(char *op, char *po); |
141 |
> |
static void hiqopts(char *op, char *po); |
142 |
> |
static void xferopts(char *ro); |
143 |
> |
static void pfiltopts(char *po); |
144 |
> |
static int matchword(char *s1, char *s2); |
145 |
> |
static char * specview(char *vs); |
146 |
> |
static char * getview(int n, char *vn); |
147 |
> |
static int myprintview(char *vopts, FILE *fp); |
148 |
> |
static void rvu(char *opts, char *po); |
149 |
> |
static void rpict(char *opts, char *po); |
150 |
> |
static int touch(char *fn); |
151 |
> |
static int runcom(char *cs); |
152 |
> |
static int rmfile(char *fn); |
153 |
> |
static int mvfile(char *fold, char *fnew); |
154 |
> |
static int next_process(void); |
155 |
> |
static void wait_process(int all); |
156 |
> |
static void finish_process(void); |
157 |
> |
static void badvalue(int vc); |
158 |
> |
static void syserr(char *s); |
159 |
> |
|
160 |
> |
|
161 |
> |
int |
162 |
> |
main( |
163 |
> |
int argc, |
164 |
> |
char *argv[] |
165 |
> |
) |
166 |
|
{ |
167 |
|
char ropts[512]; |
168 |
+ |
char popts[64]; |
169 |
|
int i; |
170 |
|
|
171 |
|
progname = argv[0]; |
176 |
|
silent++; |
177 |
|
break; |
178 |
|
case 'n': |
179 |
< |
noaction++; |
179 |
> |
nprocs = 0; |
180 |
|
break; |
181 |
+ |
case 'N': |
182 |
+ |
nprocs = atoi(argv[++i]); |
183 |
+ |
if (nprocs < 0) |
184 |
+ |
nprocs = 0; |
185 |
+ |
break; |
186 |
+ |
case 't': |
187 |
+ |
touchonly++; |
188 |
+ |
break; |
189 |
|
case 'e': |
190 |
|
explicate++; |
191 |
|
break; |
192 |
|
case 'o': |
193 |
|
rvdevice = argv[++i]; |
194 |
|
break; |
195 |
+ |
case 'V': |
196 |
+ |
sayview++; |
197 |
+ |
break; |
198 |
|
case 'v': |
199 |
|
viewselect = argv[++i]; |
200 |
|
break; |
201 |
+ |
case 'w': |
202 |
+ |
nowarn++; |
203 |
+ |
break; |
204 |
|
default: |
205 |
|
goto userr; |
206 |
|
} |
207 |
|
if (i >= argc) |
208 |
|
goto userr; |
209 |
+ |
rifname = argv[i]; |
210 |
+ |
/* check command-line options */ |
211 |
+ |
if ((nprocs > 1) & (viewselect != NULL)) |
212 |
+ |
nprocs = 1; |
213 |
|
/* assign Radiance root file name */ |
214 |
< |
rootname(radname, argv[i]); |
214 |
> |
rootname(radname, rifname); |
215 |
|
/* load variable values */ |
216 |
< |
load(argv[i]); |
216 |
> |
loadvars(rifname); |
217 |
|
/* get any additional assignments */ |
218 |
|
for (i++; i < argc; i++) |
219 |
< |
setvariable(argv[i]); |
219 |
> |
if (setvariable(argv[i], matchvar) < 0) { |
220 |
> |
fprintf(stderr, "%s: unknown variable: %s\n", |
221 |
> |
progname, argv[i]); |
222 |
> |
quit(1); |
223 |
> |
} |
224 |
|
/* check assignments */ |
225 |
|
checkvalues(); |
226 |
|
/* check files and dates */ |
229 |
|
setdefaults(); |
230 |
|
/* print all values if requested */ |
231 |
|
if (explicate) |
232 |
< |
printvals(); |
233 |
< |
/* build octree */ |
232 |
> |
printvars(stdout); |
233 |
> |
/* build octree (and run mkillum) */ |
234 |
|
oconv(); |
235 |
|
/* check date on ambient file */ |
236 |
|
checkambfile(); |
237 |
|
/* run simulation */ |
238 |
< |
renderopts(ropts); |
238 |
> |
renderopts(ropts, popts); |
239 |
|
xferopts(ropts); |
240 |
|
if (rvdevice != NULL) |
241 |
< |
rview(ropts); |
241 |
> |
rvu(ropts, popts); |
242 |
|
else |
243 |
< |
rpict(ropts); |
244 |
< |
exit(0); |
243 |
> |
rpict(ropts, popts); |
244 |
> |
quit(0); |
245 |
|
userr: |
246 |
|
fprintf(stderr, |
247 |
< |
"Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n", |
247 |
> |
"Usage: %s [-w][-s][-n|-N npr][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
248 |
|
progname); |
249 |
< |
exit(1); |
249 |
> |
quit(1); |
250 |
> |
return 1; /* pro forma return */ |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
< |
rootname(rn, fn) /* remove tail from end of fn */ |
255 |
< |
register char *rn, *fn; |
254 |
> |
static void |
255 |
> |
rootname( /* remove tail from end of fn */ |
256 |
> |
register char *rn, |
257 |
> |
register char *fn |
258 |
> |
) |
259 |
|
{ |
260 |
|
char *tp, *dp; |
261 |
|
|
262 |
< |
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
262 |
> |
for (tp = NULL, dp = rn; (*rn = *fn++); rn++) |
263 |
|
if (ISDIRSEP(*rn)) |
264 |
|
dp = rn; |
265 |
|
else if (*rn == '.') |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
< |
load(rfname) /* load Radiance simulation file */ |
273 |
< |
char *rfname; |
272 |
> |
static time_t |
273 |
> |
checklast( /* check files and find most recent */ |
274 |
> |
register char *fnames |
275 |
> |
) |
276 |
|
{ |
277 |
< |
FILE *fp; |
278 |
< |
char buf[512]; |
209 |
< |
register char *cp; |
277 |
> |
char thisfile[PATH_MAX]; |
278 |
> |
time_t thisdate, lastdate = 0; |
279 |
|
|
280 |
< |
if (rfname == NULL) |
281 |
< |
fp = stdin; |
282 |
< |
else if ((fp = fopen(rfname, "r")) == NULL) |
283 |
< |
syserr(rfname); |
284 |
< |
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
285 |
< |
for (cp = buf; *cp; cp++) { |
286 |
< |
switch (*cp) { |
287 |
< |
case '\\': |
219 |
< |
case '\n': |
220 |
< |
*cp = ' '; |
221 |
< |
continue; |
222 |
< |
case '#': |
223 |
< |
*cp = '\0'; |
224 |
< |
break; |
225 |
< |
default: |
226 |
< |
continue; |
227 |
< |
} |
228 |
< |
break; |
280 |
> |
if (fnames == NULL) |
281 |
> |
return(0); |
282 |
> |
while ((fnames = nextword(thisfile, PATH_MAX, fnames)) != NULL) { |
283 |
> |
if (thisfile[0] == '!' || |
284 |
> |
(thisfile[0] == '\\' && thisfile[1] == '!')) { |
285 |
> |
if (!lastdate) |
286 |
> |
lastdate = 1; |
287 |
> |
continue; |
288 |
|
} |
289 |
< |
setvariable(buf); |
289 |
> |
if (!(thisdate = fdate(thisfile))) |
290 |
> |
syserr(thisfile); |
291 |
> |
if (thisdate > lastdate) |
292 |
> |
lastdate = thisdate; |
293 |
|
} |
294 |
< |
fclose(fp); |
294 |
> |
return(lastdate); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
< |
setvariable(ass) /* assign variable according to string */ |
299 |
< |
register char *ass; |
298 |
> |
static char * |
299 |
> |
newfname( /* create modified file name */ |
300 |
> |
char *orig, |
301 |
> |
int pred |
302 |
> |
) |
303 |
|
{ |
239 |
– |
char varname[32]; |
304 |
|
register char *cp; |
305 |
< |
register VARIABLE *vp; |
306 |
< |
register int i; |
243 |
< |
int n; |
305 |
> |
register int n; |
306 |
> |
int suffix; |
307 |
|
|
308 |
< |
while (isspace(*ass)) /* skip leading space */ |
309 |
< |
ass++; |
310 |
< |
cp = varname; /* extract name */ |
311 |
< |
while (cp < varname+sizeof(varname)-1 |
312 |
< |
&& *ass && !isspace(*ass) && *ass != '=') |
250 |
< |
*cp++ = *ass++; |
251 |
< |
*cp = '\0'; |
252 |
< |
if (!varname[0]) |
253 |
< |
return; /* no variable name! */ |
254 |
< |
/* trim value */ |
255 |
< |
while (isspace(*ass) || *ass == '=') |
256 |
< |
ass++; |
257 |
< |
cp = ass + strlen(ass); |
258 |
< |
do |
259 |
< |
*cp-- = '\0'; |
260 |
< |
while (cp >= ass && isspace(*cp)); |
261 |
< |
n = cp - ass + 1; |
262 |
< |
if (!n) { |
263 |
< |
fprintf(stderr, "%s: warning - missing value for variable '%s'\n", |
264 |
< |
progname, varname); |
265 |
< |
return; |
308 |
> |
n = 0; cp = orig; suffix = -1; /* suffix position, length */ |
309 |
> |
while (*cp) { |
310 |
> |
if (*cp == '.') suffix = n; |
311 |
> |
else if (ISDIRSEP(*cp)) suffix = -1; |
312 |
> |
cp++; n++; |
313 |
|
} |
314 |
< |
/* match variable from list */ |
315 |
< |
vp = matchvar(varname); |
269 |
< |
if (vp == NULL) { |
270 |
< |
fprintf(stderr, "%s: unknown variable '%s'\n", |
271 |
< |
progname, varname); |
272 |
< |
exit(1); |
273 |
< |
} |
274 |
< |
/* assign new value */ |
275 |
< |
if (i = vp->nass) { |
276 |
< |
cp = vp->value; |
277 |
< |
while (i--) |
278 |
< |
while (*cp++) |
279 |
< |
; |
280 |
< |
i = cp - vp->value; |
281 |
< |
vp->value = realloc(vp->value, i+n+1); |
282 |
< |
} else |
283 |
< |
vp->value = malloc(n+1); |
284 |
< |
if (vp->value == NULL) |
314 |
> |
if (suffix == -1) suffix = n; |
315 |
> |
if ((cp = bmalloc(n+2)) == NULL) |
316 |
|
syserr(progname); |
317 |
< |
strcpy(vp->value+i, ass); |
318 |
< |
vp->nass++; |
319 |
< |
} |
289 |
< |
|
290 |
< |
|
291 |
< |
VARIABLE * |
292 |
< |
matchvar(nam) /* match a variable by its name */ |
293 |
< |
char *nam; |
294 |
< |
{ |
295 |
< |
int n = strlen(nam); |
296 |
< |
register int i; |
297 |
< |
|
298 |
< |
for (i = 0; i < NVARS; i++) |
299 |
< |
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
300 |
< |
return(vv+i); |
301 |
< |
return(NULL); |
302 |
< |
} |
303 |
< |
|
304 |
< |
|
305 |
< |
char * |
306 |
< |
nvalue(vp, n) /* return nth variable value */ |
307 |
< |
VARIABLE *vp; |
308 |
< |
register int n; |
309 |
< |
{ |
310 |
< |
register char *cp; |
311 |
< |
|
312 |
< |
if (vp == NULL || n < 0 || n >= vp->nass) |
313 |
< |
return(NULL); |
314 |
< |
cp = vp->value; |
315 |
< |
while (n--) |
316 |
< |
while (*cp++) |
317 |
< |
; |
317 |
> |
strncpy(cp, orig, suffix); |
318 |
> |
cp[suffix] = pred; /* root name + pred + suffix */ |
319 |
> |
strcpy(cp+suffix+1, orig+suffix); |
320 |
|
return(cp); |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
< |
int |
325 |
< |
vscale(vc) /* return scale for variable vc */ |
324 |
< |
int vc; |
324 |
> |
static void |
325 |
> |
checkfiles(void) /* check for existence and modified times */ |
326 |
|
{ |
327 |
< |
switch(vlet(vc)) { |
327 |
< |
case 'H': |
328 |
< |
return(HIGH); |
329 |
< |
case 'M': |
330 |
< |
return(MEDIUM); |
331 |
< |
case 'L': |
332 |
< |
return(LOW); |
333 |
< |
} |
334 |
< |
badvalue(vc); |
335 |
< |
} |
327 |
> |
time_t objdate; |
328 |
|
|
337 |
– |
|
338 |
– |
checkvalues() /* check assignments */ |
339 |
– |
{ |
340 |
– |
register int i; |
341 |
– |
|
342 |
– |
for (i = 0; i < NVARS; i++) |
343 |
– |
if (vv[i].fixval != NULL) |
344 |
– |
(*vv[i].fixval)(vv+i); |
345 |
– |
} |
346 |
– |
|
347 |
– |
|
348 |
– |
onevalue(vp) /* only one assignment for this variable */ |
349 |
– |
register VARIABLE *vp; |
350 |
– |
{ |
351 |
– |
if (vp->nass < 2) |
352 |
– |
return; |
353 |
– |
fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n", |
354 |
– |
progname, vp->name); |
355 |
– |
do |
356 |
– |
vp->value += strlen(vp->value)+1; |
357 |
– |
while (--vp->nass > 1); |
358 |
– |
} |
359 |
– |
|
360 |
– |
|
361 |
– |
catvalues(vp) /* concatenate variable values */ |
362 |
– |
register VARIABLE *vp; |
363 |
– |
{ |
364 |
– |
register char *cp; |
365 |
– |
|
366 |
– |
if (vp->nass < 2) |
367 |
– |
return; |
368 |
– |
for (cp = vp->value; vp->nass > 1; vp->nass--) { |
369 |
– |
while (*cp) |
370 |
– |
cp++; |
371 |
– |
*cp++ = ' '; |
372 |
– |
} |
373 |
– |
} |
374 |
– |
|
375 |
– |
|
376 |
– |
long |
377 |
– |
checklast(fnames) /* check files and find most recent */ |
378 |
– |
register char *fnames; |
379 |
– |
{ |
380 |
– |
char thisfile[MAXPATH]; |
381 |
– |
long thisdate, lastdate = -1; |
382 |
– |
register char *cp; |
383 |
– |
|
384 |
– |
while (*fnames) { |
385 |
– |
while (isspace(*fnames)) fnames++; |
386 |
– |
cp = thisfile; |
387 |
– |
while (*fnames && !isspace(*fnames)) |
388 |
– |
*cp++ = *fnames++; |
389 |
– |
*cp = '\0'; |
390 |
– |
if ((thisdate = fdate(thisfile)) < 0) |
391 |
– |
syserr(thisfile); |
392 |
– |
if (thisdate > lastdate) |
393 |
– |
lastdate = thisdate; |
394 |
– |
} |
395 |
– |
return(lastdate); |
396 |
– |
} |
397 |
– |
|
398 |
– |
|
399 |
– |
checkfiles() /* check for existence and modified times */ |
400 |
– |
{ |
401 |
– |
char *cp; |
402 |
– |
long objdate; |
403 |
– |
|
329 |
|
if (!vdef(OCTREE)) { |
330 |
< |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) |
330 |
> |
if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL) |
331 |
|
syserr(progname); |
332 |
< |
sprintf(cp, "%s.oct", radname); |
408 |
< |
vval(OCTREE) = cp; |
332 |
> |
sprintf(vval(OCTREE), "%s.oct", radname); |
333 |
|
vdef(OCTREE)++; |
334 |
+ |
} else if (vval(OCTREE)[0] == '!') { |
335 |
+ |
fprintf(stderr, "%s: illegal '%s' specification\n", |
336 |
+ |
progname, vnam(OCTREE)); |
337 |
+ |
quit(1); |
338 |
|
} |
339 |
|
octreedate = fdate(vval(OCTREE)); |
340 |
< |
scenedate = -1; |
341 |
< |
if (vdef(SCENE)) { |
342 |
< |
scenedate = checklast(vval(SCENE)); |
343 |
< |
if (vdef(OBJECT)) { |
344 |
< |
objdate = checklast(vval(OBJECT)); |
345 |
< |
if (objdate > scenedate) |
346 |
< |
scenedate = objdate; |
347 |
< |
} |
340 |
> |
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
341 |
> |
oct0name = newfname(vval(OCTREE), '0'); |
342 |
> |
oct1name = newfname(vval(OCTREE), '1'); |
343 |
> |
oct0date = fdate(oct0name); |
344 |
> |
oct1date = fdate(oct1name); |
345 |
> |
} else |
346 |
> |
oct0name = oct1name = vval(OCTREE); |
347 |
> |
if ((scenedate = checklast(vval(SCENE))) && |
348 |
> |
(objdate = checklast(vval(OBJECT))) > scenedate) |
349 |
> |
scenedate = objdate; |
350 |
> |
illumdate = checklast(vval(ILLUM)); |
351 |
> |
if (!octreedate & !scenedate & !illumdate) { |
352 |
> |
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
353 |
> |
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
354 |
> |
quit(1); |
355 |
|
} |
356 |
< |
if (octreedate < 0 & scenedate < 0) { |
422 |
< |
fprintf(stderr, "%s: need '%s' or '%s'\n", progname, |
423 |
< |
vnam(OCTREE), vnam(SCENE)); |
424 |
< |
exit(1); |
425 |
< |
} |
356 |
> |
matdate = checklast(vval(MATERIAL)); |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
< |
getoctcube(org, sizp) /* get octree bounding cube */ |
361 |
< |
double org[3], *sizp; |
360 |
> |
static void |
361 |
> |
getoctcube( /* get octree bounding cube */ |
362 |
> |
double org[3], |
363 |
> |
double *sizp |
364 |
> |
) |
365 |
|
{ |
432 |
– |
extern FILE *popen(); |
366 |
|
static double oorg[3], osiz = 0.; |
367 |
< |
char buf[MAXPATH+16]; |
367 |
> |
double min[3], max[3]; |
368 |
> |
char buf[1024]; |
369 |
|
FILE *fp; |
370 |
+ |
register int i; |
371 |
|
|
372 |
|
if (osiz <= FTINY) { |
373 |
< |
oconv(); /* does nothing if done already */ |
374 |
< |
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
375 |
< |
if ((fp = popen(buf, "r")) == NULL) |
376 |
< |
syserr("getinfo"); |
377 |
< |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
378 |
< |
&oorg[2], &osiz) != 4) { |
379 |
< |
fprintf(stderr, |
373 |
> |
if (!nprocs && fdate(oct1name) < |
374 |
> |
(scenedate>illumdate?scenedate:illumdate)) { |
375 |
> |
/* run getbbox */ |
376 |
> |
sprintf(buf, "getbbox -w -h %s", |
377 |
> |
vdef(SCENE) ? vval(SCENE) : vval(ILLUM)); |
378 |
> |
if ((fp = popen(buf, "r")) == NULL) |
379 |
> |
syserr("getbbox"); |
380 |
> |
if (fscanf(fp, "%lf %lf %lf %lf %lf %lf", |
381 |
> |
&min[0], &max[0], &min[1], &max[1], |
382 |
> |
&min[2], &max[2]) != 6) { |
383 |
> |
fprintf(stderr, |
384 |
> |
"%s: error reading bounding box from getbbox\n", |
385 |
> |
progname); |
386 |
> |
quit(1); |
387 |
> |
} |
388 |
> |
for (i = 0; i < 3; i++) |
389 |
> |
if (max[i] - min[i] > osiz) |
390 |
> |
osiz = max[i] - min[i]; |
391 |
> |
for (i = 0; i < 3; i++) |
392 |
> |
oorg[i] = (max[i]+min[i]-osiz)*.5; |
393 |
> |
pclose(fp); |
394 |
> |
} else { /* from octree */ |
395 |
> |
oconv(); /* does nothing if done already */ |
396 |
> |
sprintf(buf, "getinfo -d < %s", oct1name); |
397 |
> |
if ((fp = popen(buf, "r")) == NULL) |
398 |
> |
syserr("getinfo"); |
399 |
> |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
400 |
> |
&oorg[2], &osiz) != 4) { |
401 |
> |
fprintf(stderr, |
402 |
|
"%s: error reading bounding cube from getinfo\n", |
403 |
< |
progname); |
404 |
< |
exit(1); |
403 |
> |
progname); |
404 |
> |
quit(1); |
405 |
> |
} |
406 |
> |
pclose(fp); |
407 |
|
} |
449 |
– |
pclose(fp); |
408 |
|
} |
409 |
|
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
410 |
|
} |
411 |
|
|
412 |
|
|
413 |
< |
setdefaults() /* set default values for unassigned var's */ |
413 |
> |
static void |
414 |
> |
setdefaults(void) /* set default values for unassigned var's */ |
415 |
|
{ |
416 |
< |
double org[3], size; |
416 |
> |
double org[3], lim[3], size; |
417 |
|
char buf[128]; |
418 |
|
|
419 |
|
if (!vdef(ZONE)) { |
423 |
|
vval(ZONE) = savqstr(buf); |
424 |
|
vdef(ZONE)++; |
425 |
|
} |
426 |
+ |
if (!vdef(EYESEP)) { |
427 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
428 |
+ |
&org[0], &lim[0], &org[1], &lim[1], |
429 |
+ |
&org[2], &lim[2]) != 6) |
430 |
+ |
badvalue(ZONE); |
431 |
+ |
sprintf(buf, "%f", |
432 |
+ |
0.01*(lim[0]-org[0]+lim[1]-org[1]+lim[2]-org[2])); |
433 |
+ |
vval(EYESEP) = savqstr(buf); |
434 |
+ |
vdef(EYESEP)++; |
435 |
+ |
} |
436 |
|
if (!vdef(INDIRECT)) { |
437 |
|
vval(INDIRECT) = "0"; |
438 |
|
vdef(INDIRECT)++; |
449 |
|
vval(PICTURE) = radname; |
450 |
|
vdef(PICTURE)++; |
451 |
|
} |
452 |
< |
if (!vdef(VIEW)) { |
453 |
< |
vval(VIEW) = "X"; |
454 |
< |
vdef(VIEW)++; |
452 |
> |
if (!vdef(VIEWS)) { |
453 |
> |
vval(VIEWS) = "X"; |
454 |
> |
vdef(VIEWS)++; |
455 |
|
} |
456 |
|
if (!vdef(DETAIL)) { |
457 |
|
vval(DETAIL) = "M"; |
468 |
|
} |
469 |
|
|
470 |
|
|
471 |
< |
printvals() /* print variable values */ |
471 |
> |
static void |
472 |
> |
oconv(void) /* run oconv and mkillum if necessary */ |
473 |
|
{ |
474 |
< |
register int i, j; |
474 |
> |
static char illumtmp[] = "ilXXXXXX"; |
475 |
> |
char combuf[PATH_MAX], ocopts[64], mkopts[1024]; |
476 |
|
|
477 |
< |
for (i = 0; i < NVARS; i++) |
478 |
< |
for (j = 0; j < vdef(i); j++) |
479 |
< |
printf("%s= %s\n", vnam(i), nvalue(vv+i, j)); |
480 |
< |
fflush(stdout); |
481 |
< |
} |
482 |
< |
|
483 |
< |
|
484 |
< |
oconv() /* run oconv if necessary */ |
485 |
< |
{ |
486 |
< |
char combuf[512], ocopts[64]; |
487 |
< |
|
488 |
< |
if (octreedate >= scenedate) /* check dates */ |
477 |
> |
oconvopts(ocopts); /* get options */ |
478 |
> |
if (octreedate < scenedate) { /* check date on original octree */ |
479 |
> |
if (touchonly && octreedate) |
480 |
> |
touch(vval(OCTREE)); |
481 |
> |
else { /* build command */ |
482 |
> |
if (vdef(MATERIAL)) |
483 |
> |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
484 |
> |
vval(MATERIAL), vval(SCENE), |
485 |
> |
vval(OCTREE)); |
486 |
> |
else |
487 |
> |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
488 |
> |
vval(SCENE), vval(OCTREE)); |
489 |
> |
|
490 |
> |
if (runcom(combuf)) { /* run it */ |
491 |
> |
fprintf(stderr, |
492 |
> |
"%s: error generating octree\n\t%s removed\n", |
493 |
> |
progname, vval(OCTREE)); |
494 |
> |
unlink(vval(OCTREE)); |
495 |
> |
quit(1); |
496 |
> |
} |
497 |
> |
} |
498 |
> |
octreedate = time((time_t *)NULL); |
499 |
> |
if (octreedate < scenedate) /* in case clock is off */ |
500 |
> |
octreedate = scenedate; |
501 |
> |
} |
502 |
> |
if (oct1name == vval(OCTREE)) /* no mkillum? */ |
503 |
> |
oct1date = octreedate > matdate ? octreedate : matdate; |
504 |
> |
if ((oct1date >= octreedate) & (oct1date >= matdate) |
505 |
> |
& (oct1date >= illumdate)) /* all done */ |
506 |
|
return; |
507 |
< |
/* build command */ |
508 |
< |
oconvopts(ocopts); |
509 |
< |
if (vdef(MATERIAL)) |
510 |
< |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
511 |
< |
vval(MATERIAL), vval(SCENE), vval(OCTREE)); |
512 |
< |
else |
513 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
514 |
< |
vval(SCENE), vval(OCTREE)); |
515 |
< |
|
516 |
< |
if (runcom(combuf)) { /* run it */ |
517 |
< |
fprintf(stderr, "%s: error generating octree\n\t%s removed\n", |
518 |
< |
progname, vval(OCTREE)); |
519 |
< |
unlink(vval(OCTREE)); |
520 |
< |
exit(1); |
507 |
> |
/* make octree0 */ |
508 |
> |
if ((oct0date < scenedate) | (oct0date < illumdate)) { |
509 |
> |
if (touchonly && oct0date) |
510 |
> |
touch(oct0name); |
511 |
> |
else { /* build command */ |
512 |
> |
if (octreedate) |
513 |
> |
sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, |
514 |
> |
vval(OCTREE), vval(ILLUM), oct0name); |
515 |
> |
else if (vdef(MATERIAL)) |
516 |
> |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
517 |
> |
vval(MATERIAL), vval(ILLUM), oct0name); |
518 |
> |
else |
519 |
> |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
520 |
> |
vval(ILLUM), oct0name); |
521 |
> |
if (runcom(combuf)) { /* run it */ |
522 |
> |
fprintf(stderr, |
523 |
> |
"%s: error generating octree\n\t%s removed\n", |
524 |
> |
progname, oct0name); |
525 |
> |
unlink(oct0name); |
526 |
> |
quit(1); |
527 |
> |
} |
528 |
> |
} |
529 |
> |
oct0date = time((time_t *)NULL); |
530 |
> |
if (oct0date < octreedate) /* in case clock is off */ |
531 |
> |
oct0date = octreedate; |
532 |
> |
if (oct0date < illumdate) /* ditto */ |
533 |
> |
oct0date = illumdate; |
534 |
> |
} |
535 |
> |
if (touchonly && oct1date) |
536 |
> |
touch(oct1name); |
537 |
> |
else { |
538 |
> |
mkillumopts(mkopts); /* build mkillum command */ |
539 |
> |
mktemp(illumtmp); |
540 |
> |
sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, |
541 |
> |
oct0name, vval(ILLUM), illumtmp); |
542 |
> |
if (runcom(combuf)) { /* run it */ |
543 |
> |
fprintf(stderr, "%s: error running mkillum\n", |
544 |
> |
progname); |
545 |
> |
unlink(illumtmp); |
546 |
> |
quit(1); |
547 |
> |
} |
548 |
> |
/* make octree1 (frozen) */ |
549 |
> |
if (octreedate) |
550 |
> |
sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, |
551 |
> |
vval(OCTREE), illumtmp, oct1name); |
552 |
> |
else if (vdef(MATERIAL)) |
553 |
> |
sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, |
554 |
> |
vval(MATERIAL), illumtmp, oct1name); |
555 |
> |
else |
556 |
> |
sprintf(combuf, "oconv%s -f %s > %s", ocopts, |
557 |
> |
illumtmp, oct1name); |
558 |
> |
if (runcom(combuf)) { /* run it */ |
559 |
> |
fprintf(stderr, |
560 |
> |
"%s: error generating octree\n\t%s removed\n", |
561 |
> |
progname, oct1name); |
562 |
> |
unlink(oct1name); |
563 |
> |
unlink(illumtmp); |
564 |
> |
quit(1); |
565 |
> |
} |
566 |
> |
rmfile(illumtmp); |
567 |
|
} |
568 |
< |
octreedate = time(0); |
568 |
> |
oct1date = time((time_t *)NULL); |
569 |
> |
if (oct1date < oct0date) /* in case clock is off */ |
570 |
> |
oct1date = oct0date; |
571 |
|
} |
572 |
|
|
573 |
|
|
574 |
< |
char * |
575 |
< |
addarg(op, arg) /* add argument and advance pointer */ |
576 |
< |
register char *op, *arg; |
574 |
> |
static char * |
575 |
> |
addarg( /* add argument and advance pointer */ |
576 |
> |
register char *op, |
577 |
> |
register char *arg |
578 |
> |
) |
579 |
|
{ |
580 |
|
*op = ' '; |
581 |
< |
while (*++op = *arg++) |
581 |
> |
while ( (*++op = *arg++) ) |
582 |
|
; |
583 |
|
return(op); |
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
< |
oconvopts(oo) /* get oconv options */ |
588 |
< |
register char *oo; |
587 |
> |
static void |
588 |
> |
oconvopts( /* get oconv options */ |
589 |
> |
register char *oo |
590 |
> |
) |
591 |
|
{ |
592 |
|
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
593 |
|
|
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
< |
checkambfile() /* check date on ambient file */ |
600 |
> |
static void |
601 |
> |
mkillumopts( /* get mkillum options */ |
602 |
> |
char *mo |
603 |
> |
) |
604 |
|
{ |
605 |
< |
long afdate; |
605 |
> |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
606 |
|
|
607 |
< |
if (vdef(AMBFILE)) { |
608 |
< |
afdate = fdate(vval(AMBFILE)); |
609 |
< |
if (afdate >= 0 & octreedate > afdate) |
607 |
> |
if (nprocs > 1) { |
608 |
> |
sprintf(mo, " -n %d", nprocs); |
609 |
> |
while (*mo) |
610 |
> |
mo++; |
611 |
> |
} else |
612 |
> |
*mo = '\0'; |
613 |
> |
if (vdef(MKILLUM)) |
614 |
> |
addarg(mo, vval(MKILLUM)); |
615 |
> |
} |
616 |
> |
|
617 |
> |
|
618 |
> |
static void |
619 |
> |
checkambfile(void) /* check date on ambient file */ |
620 |
> |
{ |
621 |
> |
time_t afdate; |
622 |
> |
|
623 |
> |
if (!vdef(AMBFILE)) |
624 |
> |
return; |
625 |
> |
if (!(afdate = fdate(vval(AMBFILE)))) |
626 |
> |
return; |
627 |
> |
if (oct1date > afdate) { |
628 |
> |
if (touchonly) |
629 |
> |
touch(vval(AMBFILE)); |
630 |
> |
else |
631 |
|
rmfile(vval(AMBFILE)); |
632 |
|
} |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
< |
double |
637 |
< |
ambval() /* compute ambient value */ |
636 |
> |
static double |
637 |
> |
ambval(void) /* compute ambient value */ |
638 |
|
{ |
639 |
|
if (vdef(EXPOSURE)) { |
640 |
|
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
641 |
< |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
642 |
< |
if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') |
579 |
< |
return(.5/atof(vval(EXPOSURE))); |
580 |
< |
badvalue(EXPOSURE); |
641 |
> |
return(.5/pow(2.,vflt(EXPOSURE))); |
642 |
> |
return(.5/vflt(EXPOSURE)); |
643 |
|
} |
644 |
|
if (vlet(ZONE) == 'E') |
645 |
|
return(10.); |
646 |
|
if (vlet(ZONE) == 'I') |
647 |
|
return(.01); |
648 |
|
badvalue(ZONE); |
649 |
+ |
return 0; /* pro forma return */ |
650 |
|
} |
651 |
|
|
652 |
|
|
653 |
< |
lowqopts(op) /* low quality rendering options */ |
654 |
< |
register char *op; |
653 |
> |
static void |
654 |
> |
renderopts( /* set rendering options */ |
655 |
> |
char *op, |
656 |
> |
char *po |
657 |
> |
) |
658 |
|
{ |
659 |
+ |
switch(vscale(QUALITY)) { |
660 |
+ |
case LOW: |
661 |
+ |
lowqopts(op, po); |
662 |
+ |
break; |
663 |
+ |
case MEDIUM: |
664 |
+ |
medqopts(op, po); |
665 |
+ |
break; |
666 |
+ |
case HIGH: |
667 |
+ |
hiqopts(op, po); |
668 |
+ |
break; |
669 |
+ |
} |
670 |
+ |
} |
671 |
+ |
|
672 |
+ |
|
673 |
+ |
static void |
674 |
+ |
lowqopts( /* low quality rendering options */ |
675 |
+ |
register char *op, |
676 |
+ |
char *po |
677 |
+ |
) |
678 |
+ |
{ |
679 |
|
double d, org[3], siz[3]; |
680 |
|
|
681 |
|
*op = '\0'; |
682 |
+ |
*po = '\0'; |
683 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
684 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
685 |
|
badvalue(ZONE); |
686 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
687 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
688 |
+ |
badvalue(ZONE); |
689 |
|
getoctcube(org, &d); |
690 |
|
d *= 3./(siz[0]+siz[1]+siz[2]); |
691 |
|
switch (vscale(DETAIL)) { |
692 |
|
case LOW: |
693 |
< |
op = addarg(op, "-ps 16 -dp 16"); |
694 |
< |
sprintf(op, " -ar %d", (int)(4*d)); |
693 |
> |
po = addarg(po, "-ps 16"); |
694 |
> |
op = addarg(op, "-dp 64"); |
695 |
> |
sprintf(op, " -ar %d", (int)(8*d)); |
696 |
|
op += strlen(op); |
697 |
|
break; |
698 |
|
case MEDIUM: |
699 |
< |
op = addarg(op, "-ps 8 -dp 32"); |
700 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
699 |
> |
po = addarg(po, "-ps 8"); |
700 |
> |
op = addarg(op, "-dp 128"); |
701 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
702 |
|
op += strlen(op); |
703 |
|
break; |
704 |
|
case HIGH: |
705 |
< |
op = addarg(op, "-ps 4 -dp 64"); |
706 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
705 |
> |
po = addarg(po, "-ps 4"); |
706 |
> |
op = addarg(op, "-dp 256"); |
707 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
708 |
|
op += strlen(op); |
709 |
|
break; |
710 |
|
} |
711 |
< |
op = addarg(op, "-pt .16"); |
711 |
> |
po = addarg(po, "-pt .16"); |
712 |
|
if (vbool(PENUMBRAS)) |
713 |
|
op = addarg(op, "-ds .4"); |
714 |
|
else |
715 |
|
op = addarg(op, "-ds 0"); |
716 |
< |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7"); |
716 |
> |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); |
717 |
|
if (vdef(AMBFILE)) { |
718 |
|
sprintf(op, " -af %s", vval(AMBFILE)); |
719 |
|
op += strlen(op); |
721 |
|
overture = 0; |
722 |
|
switch (vscale(VARIABILITY)) { |
723 |
|
case LOW: |
724 |
< |
op = addarg(op, "-aa .4 -ad 32"); |
724 |
> |
op = addarg(op, "-aa .3 -ad 256"); |
725 |
|
break; |
726 |
|
case MEDIUM: |
727 |
< |
op = addarg(op, "-aa .3 -ad 64"); |
727 |
> |
op = addarg(op, "-aa .25 -ad 512"); |
728 |
|
break; |
729 |
|
case HIGH: |
730 |
< |
op = addarg(op, "-aa .25 -ad 128"); |
730 |
> |
op = addarg(op, "-aa .2 -ad 1024"); |
731 |
|
break; |
732 |
|
} |
733 |
|
op = addarg(op, "-as 0"); |
734 |
|
d = ambval(); |
735 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
736 |
|
op += strlen(op); |
737 |
< |
op = addarg(op, "-lr 3 -lw .02"); |
737 |
> |
op = addarg(op, "-lr 6 -lw .01"); |
738 |
|
if (vdef(RENDER)) |
739 |
|
op = addarg(op, vval(RENDER)); |
740 |
|
} |
741 |
|
|
742 |
|
|
743 |
< |
medqopts(op) /* medium quality rendering options */ |
744 |
< |
register char *op; |
743 |
> |
static void |
744 |
> |
medqopts( /* medium quality rendering options */ |
745 |
> |
register char *op, |
746 |
> |
char *po |
747 |
> |
) |
748 |
|
{ |
749 |
< |
double d, org[3], siz[3]; |
749 |
> |
double d, org[3], siz[3], asz; |
750 |
|
|
751 |
|
*op = '\0'; |
752 |
+ |
*po = '\0'; |
753 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
754 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
755 |
|
badvalue(ZONE); |
756 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
757 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
758 |
+ |
badvalue(ZONE); |
759 |
|
getoctcube(org, &d); |
760 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
760 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
761 |
> |
d /= asz; |
762 |
|
switch (vscale(DETAIL)) { |
763 |
|
case LOW: |
764 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
765 |
< |
op = addarg(op, "-dp 64"); |
766 |
< |
sprintf(op, " -ar %d", (int)(8*d)); |
764 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
765 |
> |
op = addarg(op, "-dp 256"); |
766 |
> |
sprintf(op, " -ar %d", (int)(16*d)); |
767 |
|
op += strlen(op); |
768 |
+ |
sprintf(op, " -ms %.2g", asz/20.); |
769 |
+ |
op += strlen(op); |
770 |
|
break; |
771 |
|
case MEDIUM: |
772 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
773 |
< |
op = addarg(op, "-dp 128"); |
774 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
772 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
773 |
> |
op = addarg(op, "-dp 512"); |
774 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
775 |
|
op += strlen(op); |
776 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
777 |
+ |
op += strlen(op); |
778 |
|
break; |
779 |
|
case HIGH: |
780 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
781 |
< |
op = addarg(op, "-dp 256"); |
782 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
780 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
781 |
> |
op = addarg(op, "-dp 1024"); |
782 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
783 |
|
op += strlen(op); |
784 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
785 |
+ |
op += strlen(op); |
786 |
|
break; |
787 |
|
} |
788 |
< |
op = addarg(op, "-pt .08"); |
788 |
> |
po = addarg(po, "-pt .08"); |
789 |
|
if (vbool(PENUMBRAS)) |
790 |
< |
op = addarg(op, "-ds .2 -dj .35"); |
790 |
> |
op = addarg(op, "-ds .2 -dj .5"); |
791 |
|
else |
792 |
|
op = addarg(op, "-ds .3"); |
793 |
< |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); |
794 |
< |
if (overture = vint(INDIRECT)) { |
793 |
> |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); |
794 |
> |
if ( (overture = vint(INDIRECT)) ) { |
795 |
|
sprintf(op, " -ab %d", overture); |
796 |
|
op += strlen(op); |
797 |
|
} |
802 |
|
overture = 0; |
803 |
|
switch (vscale(VARIABILITY)) { |
804 |
|
case LOW: |
805 |
< |
op = addarg(op, "-aa .25 -ad 128 -as 0"); |
805 |
> |
op = addarg(op, "-aa .2 -ad 329 -as 42"); |
806 |
|
break; |
807 |
|
case MEDIUM: |
808 |
< |
op = addarg(op, "-aa .2 -ad 300 -as 64"); |
808 |
> |
op = addarg(op, "-aa .15 -ad 800 -as 128"); |
809 |
|
break; |
810 |
|
case HIGH: |
811 |
< |
op = addarg(op, "-aa .15 -ad 500 -as 128"); |
811 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 392"); |
812 |
|
break; |
813 |
|
} |
814 |
|
d = ambval(); |
815 |
|
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
816 |
|
op += strlen(op); |
817 |
< |
op = addarg(op, "-lr 6 -lw .002"); |
817 |
> |
op = addarg(op, "-lr 8 -lw .002"); |
818 |
|
if (vdef(RENDER)) |
819 |
|
op = addarg(op, vval(RENDER)); |
820 |
|
} |
821 |
|
|
822 |
|
|
823 |
< |
hiqopts(op) /* high quality rendering options */ |
824 |
< |
register char *op; |
823 |
> |
static void |
824 |
> |
hiqopts( /* high quality rendering options */ |
825 |
> |
register char *op, |
826 |
> |
char *po |
827 |
> |
) |
828 |
|
{ |
829 |
< |
double d, org[3], siz[3]; |
829 |
> |
double d, org[3], siz[3], asz; |
830 |
|
|
831 |
|
*op = '\0'; |
832 |
+ |
*po = '\0'; |
833 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
834 |
|
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
835 |
|
badvalue(ZONE); |
836 |
|
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
837 |
+ |
if ((siz[0] <= FTINY) | (siz[1] <= FTINY) | (siz[2] <= FTINY)) |
838 |
+ |
badvalue(ZONE); |
839 |
|
getoctcube(org, &d); |
840 |
< |
d *= 3./(siz[0]+siz[1]+siz[2]); |
840 |
> |
asz = (siz[0]+siz[1]+siz[2])/3.; |
841 |
> |
d /= asz; |
842 |
|
switch (vscale(DETAIL)) { |
843 |
|
case LOW: |
844 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
845 |
< |
op = addarg(op, "-dp 256"); |
846 |
< |
sprintf(op, " -ar %d", (int)(16*d)); |
844 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
845 |
> |
op = addarg(op, "-dp 1024"); |
846 |
> |
sprintf(op, " -ar %d", (int)(32*d)); |
847 |
|
op += strlen(op); |
848 |
+ |
sprintf(op, " -ms %.2g", asz/40.); |
849 |
+ |
op += strlen(op); |
850 |
|
break; |
851 |
|
case MEDIUM: |
852 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
853 |
< |
op = addarg(op, "-dp 512"); |
854 |
< |
sprintf(op, " -ar %d", (int)(32*d)); |
852 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
853 |
> |
op = addarg(op, "-dp 2048"); |
854 |
> |
sprintf(op, " -ar %d", (int)(64*d)); |
855 |
|
op += strlen(op); |
856 |
+ |
sprintf(op, " -ms %.2g", asz/80.); |
857 |
+ |
op += strlen(op); |
858 |
|
break; |
859 |
|
case HIGH: |
860 |
< |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
861 |
< |
op = addarg(op, "-dp 1024"); |
862 |
< |
sprintf(op, " -ar %d", (int)(64*d)); |
860 |
> |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
861 |
> |
op = addarg(op, "-dp 4096"); |
862 |
> |
sprintf(op, " -ar %d", (int)(128*d)); |
863 |
|
op += strlen(op); |
864 |
+ |
sprintf(op, " -ms %.2g", asz/160.); |
865 |
+ |
op += strlen(op); |
866 |
|
break; |
867 |
|
} |
868 |
< |
op = addarg(op, "-pt .04"); |
868 |
> |
po = addarg(po, "-pt .04"); |
869 |
|
if (vbool(PENUMBRAS)) |
870 |
< |
op = addarg(op, "-ds .1 -dj .7"); |
870 |
> |
op = addarg(op, "-ds .1 -dj .65"); |
871 |
|
else |
872 |
|
op = addarg(op, "-ds .2"); |
873 |
< |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03"); |
873 |
> |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); |
874 |
|
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
875 |
|
op += strlen(op); |
876 |
|
if (vdef(AMBFILE)) { |
880 |
|
overture = 0; |
881 |
|
switch (vscale(VARIABILITY)) { |
882 |
|
case LOW: |
883 |
< |
op = addarg(op, "-aa .15 -ad 200 -as 0"); |
883 |
> |
op = addarg(op, "-aa .125 -ad 512 -as 64"); |
884 |
|
break; |
885 |
|
case MEDIUM: |
886 |
< |
op = addarg(op, "-aa .125 -ad 512 -as 128"); |
886 |
> |
op = addarg(op, "-aa .1 -ad 1536 -as 768"); |
887 |
|
break; |
888 |
|
case HIGH: |
889 |
< |
op = addarg(op, "-aa .08 -ad 850 -as 256"); |
889 |
> |
op = addarg(op, "-aa .075 -ad 4096 -as 2048"); |
890 |
|
break; |
891 |
|
} |
892 |
|
d = ambval(); |
898 |
|
} |
899 |
|
|
900 |
|
|
901 |
< |
xferopts(ro) /* transfer options if indicated */ |
902 |
< |
char *ro; |
901 |
> |
static void |
902 |
> |
xferopts( /* transfer options if indicated */ |
903 |
> |
char *ro |
904 |
> |
) |
905 |
|
{ |
906 |
|
int fd, n; |
907 |
|
register char *cp; |
911 |
|
return; |
912 |
|
if (vdef(OPTFILE)) { |
913 |
|
for (cp = ro; cp[1]; cp++) |
914 |
< |
if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) |
914 |
> |
if (isspace(cp[1]) && (cp[2] == '@' || |
915 |
> |
(cp[2] == '-' && isalpha(cp[3])))) |
916 |
|
*cp = '\n'; |
917 |
|
else |
918 |
|
*cp = cp[1]; |
920 |
|
fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); |
921 |
|
if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) |
922 |
|
syserr(vval(OPTFILE)); |
923 |
< |
sprintf(ro, " \"^%s\"", vval(OPTFILE)); |
923 |
> |
sprintf(ro, " @%s", vval(OPTFILE)); |
924 |
|
} |
925 |
< |
#ifdef MSDOS |
925 |
> |
#ifdef _WIN32 |
926 |
|
else if (n > 50) { |
927 |
|
setenv("ROPT", ro+1); |
928 |
|
strcpy(ro, " $ROPT"); |
931 |
|
} |
932 |
|
|
933 |
|
|
934 |
< |
pfiltopts(po) /* get pfilt options */ |
935 |
< |
register char *po; |
934 |
> |
static void |
935 |
> |
pfiltopts( /* get pfilt options */ |
936 |
> |
register char *po |
937 |
> |
) |
938 |
|
{ |
939 |
|
*po = '\0'; |
940 |
|
if (vdef(EXPOSURE)) { |
941 |
|
po = addarg(po, "-1 -e"); |
942 |
|
po = addarg(po, vval(EXPOSURE)); |
943 |
|
} |
944 |
< |
if (vscale(QUALITY) == HIGH) |
945 |
< |
po = addarg(po, "-r .65"); |
944 |
> |
switch (vscale(QUALITY)) { |
945 |
> |
case MEDIUM: |
946 |
> |
po = addarg(po, "-r .6"); |
947 |
> |
break; |
948 |
> |
case HIGH: |
949 |
> |
po = addarg(po, "-m .25"); |
950 |
> |
break; |
951 |
> |
} |
952 |
|
if (vdef(PFILT)) |
953 |
|
po = addarg(po, vval(PFILT)); |
954 |
|
} |
955 |
|
|
956 |
|
|
957 |
< |
matchword(s1, s2) /* match white-delimited words */ |
958 |
< |
register char *s1, *s2; |
957 |
> |
static int |
958 |
> |
matchword( /* match white-delimited words */ |
959 |
> |
register char *s1, |
960 |
> |
register char *s2 |
961 |
> |
) |
962 |
|
{ |
963 |
|
while (isspace(*s1)) s1++; |
964 |
|
while (isspace(*s2)) s2++; |
969 |
|
} |
970 |
|
|
971 |
|
|
972 |
< |
char * |
973 |
< |
specview(vs) /* get proper view spec from vs */ |
974 |
< |
register char *vs; |
972 |
> |
static char * |
973 |
> |
specview( /* get proper view spec from vs */ |
974 |
> |
register char *vs |
975 |
> |
) |
976 |
|
{ |
977 |
|
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
978 |
|
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
990 |
|
upax = 1-'X'+UPPER(vval(UP)[1]); |
991 |
|
else |
992 |
|
upax = 1-'X'+vlet(UP); |
993 |
< |
if (upax < 1 | upax > 3) |
993 |
> |
if ((upax < 1) | (upax > 3)) |
994 |
|
badvalue(UP); |
995 |
|
if (vval(UP)[0] == '-') |
996 |
|
upax = -upax; |
1012 |
|
} else if (*vs == 'z') { |
1013 |
|
zpos = -1; vs++; |
1014 |
|
} |
1015 |
< |
viewtype = 'v'; |
1016 |
< |
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') |
1015 |
> |
switch (*vs) { |
1016 |
> |
case VT_PER: |
1017 |
> |
case VT_PAR: |
1018 |
> |
case VT_ANG: |
1019 |
> |
case VT_HEM: |
1020 |
> |
case VT_PLS: |
1021 |
> |
case VT_CYL: |
1022 |
|
viewtype = *vs++; |
1023 |
+ |
break; |
1024 |
+ |
default: |
1025 |
+ |
viewtype = VT_PER; |
1026 |
+ |
break; |
1027 |
+ |
} |
1028 |
|
cp = viewopts; |
1029 |
|
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
1030 |
|
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
1034 |
|
badvalue(ZONE); |
1035 |
|
for (i = 0; i < 3; i++) { |
1036 |
|
dim[i] -= cent[i]; |
1037 |
+ |
if (dim[i] <= FTINY) |
1038 |
+ |
badvalue(ZONE); |
1039 |
|
cent[i] += .5*dim[i]; |
1040 |
|
} |
1041 |
|
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
1066 |
|
} |
1067 |
|
cp = addarg(cp, vup[upax+3]); |
1068 |
|
switch (viewtype) { |
1069 |
< |
case 'v': |
1069 |
> |
case VT_PER: |
1070 |
|
cp = addarg(cp, "-vh 45 -vv 45"); |
1071 |
|
break; |
1072 |
< |
case 'l': |
1072 |
> |
case VT_PAR: |
1073 |
|
d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); |
1074 |
|
sprintf(cp, " -vh %.2g -vv %.2g", d, d); |
1075 |
|
cp += strlen(cp); |
1076 |
|
break; |
1077 |
< |
case 'a': |
1078 |
< |
case 'h': |
1077 |
> |
case VT_ANG: |
1078 |
> |
case VT_HEM: |
1079 |
> |
case VT_PLS: |
1080 |
|
cp = addarg(cp, "-vh 180 -vv 180"); |
1081 |
|
break; |
1082 |
+ |
case VT_CYL: |
1083 |
+ |
cp = addarg(cp, "-vh 180 -vv 90"); |
1084 |
+ |
break; |
1085 |
|
} |
1086 |
|
} else { |
1087 |
|
while (!isspace(*vs)) /* else skip id */ |
1092 |
|
cp += strlen(cp); |
1093 |
|
} |
1094 |
|
} |
1095 |
< |
strcpy(cp, vs); /* append any additional options */ |
1096 |
< |
#ifdef MSDOS |
1095 |
> |
if (cp == viewopts) /* append any additional options */ |
1096 |
> |
vs++; /* skip prefixed space if unneeded */ |
1097 |
> |
strcpy(cp, vs); |
1098 |
> |
#ifdef _WIN32 |
1099 |
|
if (strlen(viewopts) > 40) { |
1100 |
|
setenv("VIEW", viewopts); |
1101 |
|
return("$VIEW"); |
1105 |
|
} |
1106 |
|
|
1107 |
|
|
1108 |
< |
char * |
1109 |
< |
getview(n, vn) /* get view n, or NULL if none */ |
1110 |
< |
int n; |
1111 |
< |
char *vn; /* returned view name */ |
1108 |
> |
static char * |
1109 |
> |
getview( /* get view n, or NULL if none */ |
1110 |
> |
int n, |
1111 |
> |
char *vn /* returned view name */ |
1112 |
> |
) |
1113 |
|
{ |
1114 |
< |
register char *mv = NULL; |
1114 |
> |
register char *mv; |
1115 |
|
|
1116 |
|
if (viewselect != NULL) { /* command-line selected */ |
1117 |
|
if (n) /* only do one */ |
1126 |
|
; |
1127 |
|
*vn = '\0'; |
1128 |
|
} |
1129 |
+ |
/* view number? */ |
1130 |
+ |
if (isint(viewselect)) |
1131 |
+ |
return(specview(nvalue(VIEWS, atoi(viewselect)-1))); |
1132 |
|
/* check list */ |
1133 |
< |
while ((mv = nvalue(vv+VIEW, n++)) != NULL) |
1133 |
> |
while ((mv = nvalue(VIEWS, n++)) != NULL) |
1134 |
|
if (matchword(viewselect, mv)) |
1135 |
|
return(specview(mv)); |
1136 |
|
return(specview(viewselect)); /* standard view? */ |
1137 |
|
} |
1138 |
< |
mv = nvalue(vv+VIEW, n); /* use view n */ |
1139 |
< |
if (vn != NULL & mv != NULL) { |
1140 |
< |
if (*mv != '-') |
1141 |
< |
while (*mv && !isspace(*mv)) |
1142 |
< |
*vn++ = *mv++; |
1138 |
> |
mv = nvalue(VIEWS, n); /* use view n */ |
1139 |
> |
if ((vn != NULL) & (mv != NULL)) { |
1140 |
> |
register char *mv2 = mv; |
1141 |
> |
if (*mv2 != '-') |
1142 |
> |
while (*mv2 && !isspace(*mv2)) |
1143 |
> |
*vn++ = *mv2++; |
1144 |
|
*vn = '\0'; |
1145 |
|
} |
1146 |
|
return(specview(mv)); |
1147 |
|
} |
1148 |
|
|
1149 |
|
|
1150 |
< |
rview(opts) /* run rview with first view */ |
1151 |
< |
char *opts; |
1150 |
> |
static int |
1151 |
> |
myprintview( /* print out selected view */ |
1152 |
> |
register char *vopts, |
1153 |
> |
FILE *fp |
1154 |
> |
) |
1155 |
|
{ |
1156 |
< |
char combuf[512]; |
1156 |
> |
VIEW vwr; |
1157 |
> |
char buf[128]; |
1158 |
> |
register char *cp; |
1159 |
> |
#ifdef _WIN32 |
1160 |
> |
/* XXX Should we allow something like this for all platforms? */ |
1161 |
> |
/* XXX Or is it still required at all? */ |
1162 |
> |
again: |
1163 |
> |
#endif |
1164 |
> |
if (vopts == NULL) |
1165 |
> |
return(-1); |
1166 |
> |
#ifdef _WIN32 |
1167 |
> |
if (vopts[0] == '$') { |
1168 |
> |
vopts = getenv(vopts+1); |
1169 |
> |
goto again; |
1170 |
> |
} |
1171 |
> |
#endif |
1172 |
> |
vwr = stdview; |
1173 |
> |
sscanview(&vwr, cp=vopts); /* set initial options */ |
1174 |
> |
while ((cp = strstr(cp, "-vf ")) != NULL && |
1175 |
> |
*atos(buf, sizeof(buf), cp += 4)) { |
1176 |
> |
viewfile(buf, &vwr, NULL); /* load -vf file */ |
1177 |
> |
sscanview(&vwr, cp); /* reset tail */ |
1178 |
> |
} |
1179 |
> |
fputs(VIEWSTR, fp); |
1180 |
> |
fprintview(&vwr, fp); /* print full spec. */ |
1181 |
> |
fputc('\n', fp); |
1182 |
> |
return(0); |
1183 |
> |
} |
1184 |
> |
|
1185 |
> |
|
1186 |
> |
static void |
1187 |
> |
rvu( /* run rvu with first view */ |
1188 |
> |
char *opts, |
1189 |
> |
char *po |
1190 |
> |
) |
1191 |
> |
{ |
1192 |
> |
char *vw; |
1193 |
> |
char combuf[PATH_MAX]; |
1194 |
|
/* build command */ |
1195 |
< |
sprintf(combuf, "rview %s%s ", getview(0, NULL), opts); |
1195 |
> |
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1196 |
> |
return; |
1197 |
> |
if (sayview) |
1198 |
> |
myprintview(vw, stdout); |
1199 |
> |
sprintf(combuf, "rvu %s%s%s -R %s ", vw, po, opts, rifname); |
1200 |
> |
if (nprocs > 1) |
1201 |
> |
sprintf(combuf+strlen(combuf), "-n %d ", nprocs); |
1202 |
|
if (rvdevice != NULL) |
1203 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1204 |
< |
strcat(combuf, vval(OCTREE)); |
1204 |
> |
if (vdef(EXPOSURE)) |
1205 |
> |
sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); |
1206 |
> |
strcat(combuf, oct1name); |
1207 |
|
if (runcom(combuf)) { /* run it */ |
1208 |
< |
fprintf(stderr, "%s: error running rview\n", progname); |
1209 |
< |
exit(1); |
1208 |
> |
fprintf(stderr, "%s: error running rvu\n", progname); |
1209 |
> |
quit(1); |
1210 |
|
} |
1211 |
|
} |
1212 |
|
|
1213 |
|
|
1214 |
< |
rpict(opts) /* run rpict and pfilt for each view */ |
1215 |
< |
char *opts; |
1214 |
> |
static void |
1215 |
> |
rpict( /* run rpict and pfilt for each view */ |
1216 |
> |
char *opts, |
1217 |
> |
char *po |
1218 |
> |
) |
1219 |
|
{ |
1220 |
< |
char combuf[1024]; |
1221 |
< |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; |
1220 |
> |
char combuf[PATH_MAX]; |
1221 |
> |
char rawfile[PATH_MAX], picfile[PATH_MAX]; |
1222 |
> |
char zopt[PATH_MAX+4], rep[PATH_MAX+16], res[32]; |
1223 |
> |
char rppopt[128], *pfile = NULL; |
1224 |
|
char pfopts[128]; |
1225 |
|
char vs[32], *vw; |
1226 |
|
int vn, mult; |
1227 |
+ |
FILE *fp; |
1228 |
+ |
time_t rfdt, pfdt; |
1229 |
|
/* get pfilt options */ |
1230 |
|
pfiltopts(pfopts); |
1231 |
|
/* get resolution, reporting */ |
1232 |
< |
mult = vscale(QUALITY)+1; |
1232 |
> |
switch (vscale(QUALITY)) { |
1233 |
> |
case LOW: |
1234 |
> |
mult = 1; |
1235 |
> |
break; |
1236 |
> |
case MEDIUM: |
1237 |
> |
mult = 2; |
1238 |
> |
break; |
1239 |
> |
case HIGH: |
1240 |
> |
mult = 3; |
1241 |
> |
break; |
1242 |
> |
} |
1243 |
|
{ |
1244 |
|
int xres, yres; |
1245 |
|
double aspect; |
1266 |
|
else |
1267 |
|
badvalue(REPORT); |
1268 |
|
} |
1269 |
< |
/* do each view */ |
1270 |
< |
vn = 0; |
1269 |
> |
/* set up parallel rendering */ |
1270 |
> |
if ((nprocs > 1) & (!vdef(ZFILE))) { |
1271 |
> |
strcpy(rppopt, "-S 1 -PP pfXXXXXX"); |
1272 |
> |
pfile = rppopt+9; |
1273 |
> |
if (mktemp(pfile) == NULL) |
1274 |
> |
pfile = NULL; |
1275 |
> |
} |
1276 |
> |
vn = 0; /* do each view */ |
1277 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1278 |
+ |
if (sayview) |
1279 |
+ |
myprintview(vw, stdout); |
1280 |
|
if (!vs[0]) |
1281 |
|
sprintf(vs, "%d", vn); |
1282 |
|
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1283 |
+ |
if (vdef(ZFILE)) |
1284 |
+ |
sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); |
1285 |
+ |
else |
1286 |
+ |
zopt[0] = '\0'; |
1287 |
|
/* check date on picture */ |
1288 |
< |
if (fdate(picfile) > octreedate) |
1288 |
> |
pfdt = fdate(picfile); |
1289 |
> |
if (pfdt >= oct1date) |
1290 |
|
continue; |
1291 |
+ |
/* get raw file name */ |
1292 |
+ |
sprintf(rawfile, "%s_%s.unf", |
1293 |
+ |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs); |
1294 |
+ |
rfdt = fdate(rawfile); |
1295 |
+ |
if (touchonly) { /* update times only */ |
1296 |
+ |
if (rfdt) { |
1297 |
+ |
if (rfdt < oct1date) |
1298 |
+ |
touch(rawfile); |
1299 |
+ |
} else if (pfdt && pfdt < oct1date) |
1300 |
+ |
touch(picfile); |
1301 |
+ |
continue; |
1302 |
+ |
} |
1303 |
+ |
if (next_process()) { /* parallel running? */ |
1304 |
+ |
if (pfile != NULL) |
1305 |
+ |
sleep(20); |
1306 |
+ |
continue; |
1307 |
+ |
} |
1308 |
+ |
/* XXX Remember to call finish_process() */ |
1309 |
|
/* build rpict command */ |
1310 |
< |
sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); |
1311 |
< |
if (fdate(rawfile) > octreedate) /* recover */ |
1312 |
< |
sprintf(combuf, "rpict%s%s -ro %s %s", |
1313 |
< |
rep, opts, rawfile, vval(OCTREE)); |
1314 |
< |
else { |
1310 |
> |
if (rfdt >= oct1date) { /* recover */ |
1311 |
> |
sprintf(combuf, "rpict%s%s%s%s -ro %s %s", |
1312 |
> |
rep, po, opts, zopt, rawfile, oct1name); |
1313 |
> |
if (runcom(combuf)) /* run rpict */ |
1314 |
> |
goto rperror; |
1315 |
> |
} else { |
1316 |
|
if (overture) { /* run overture calculation */ |
1317 |
|
sprintf(combuf, |
1318 |
|
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1319 |
|
rep, vw, opts, |
1320 |
< |
vval(OCTREE), overfile); |
1320 |
> |
oct1name, overfile); |
1321 |
|
if (runcom(combuf)) { |
1322 |
|
fprintf(stderr, |
1323 |
|
"%s: error in overture for view %s\n", |
1324 |
|
progname, vs); |
1325 |
< |
exit(1); |
1325 |
> |
quit(1); |
1326 |
|
} |
1327 |
< |
#ifdef NIX |
1327 |
> |
#ifndef NULL_DEVICE |
1328 |
|
rmfile(overfile); |
1329 |
|
#endif |
1330 |
|
} |
1331 |
< |
sprintf(combuf, "rpict%s %s %s%s %s > %s", |
1332 |
< |
rep, vw, res, opts, |
1333 |
< |
vval(OCTREE), rawfile); |
1331 |
> |
sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", |
1332 |
> |
rep, vw, res, po, opts, |
1333 |
> |
zopt, oct1name, rawfile); |
1334 |
> |
if (pfile != NULL && inchild()) { |
1335 |
> |
/* rpict persistent mode */ |
1336 |
> |
if (!silent) |
1337 |
> |
printf("\t%s\n", combuf); |
1338 |
> |
fflush(stdout); |
1339 |
> |
sprintf(combuf, "rpict%s %s %s%s%s %s > %s", |
1340 |
> |
rep, rppopt, res, po, opts, |
1341 |
> |
oct1name, rawfile); |
1342 |
> |
fp = popen(combuf, "w"); |
1343 |
> |
if (fp == NULL) |
1344 |
> |
goto rperror; |
1345 |
> |
myprintview(vw, fp); |
1346 |
> |
if (pclose(fp)) |
1347 |
> |
goto rperror; |
1348 |
> |
} else { /* rpict normal mode */ |
1349 |
> |
if (runcom(combuf)) |
1350 |
> |
goto rperror; |
1351 |
> |
} |
1352 |
|
} |
1353 |
< |
if (runcom(combuf)) { /* run rpict */ |
1083 |
< |
fprintf(stderr, "%s: error rendering view %s\n", |
1084 |
< |
progname, vs); |
1085 |
< |
exit(1); |
1086 |
< |
} |
1353 |
> |
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1354 |
|
/* build pfilt command */ |
1355 |
< |
if (mult > 1) |
1356 |
< |
sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", |
1355 |
> |
if (mult > 1) |
1356 |
> |
sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", |
1357 |
|
pfopts, mult, mult, rawfile, picfile); |
1358 |
< |
else |
1359 |
< |
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1360 |
< |
rawfile, picfile); |
1361 |
< |
if (runcom(combuf)) { /* run pfilt */ |
1362 |
< |
fprintf(stderr, |
1363 |
< |
"%s: error filtering view %s\n\t%s removed\n", |
1364 |
< |
progname, vs, picfile); |
1365 |
< |
unlink(picfile); |
1366 |
< |
exit(1); |
1358 |
> |
else |
1359 |
> |
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1360 |
> |
rawfile, picfile); |
1361 |
> |
if (runcom(combuf)) { /* run pfilt */ |
1362 |
> |
fprintf(stderr, |
1363 |
> |
"%s: error filtering view %s\n\t%s removed\n", |
1364 |
> |
progname, vs, picfile); |
1365 |
> |
unlink(picfile); |
1366 |
> |
quit(1); |
1367 |
> |
} |
1368 |
|
} |
1369 |
< |
/* remove raw file */ |
1370 |
< |
rmfile(rawfile); |
1369 |
> |
/* remove/rename raw file */ |
1370 |
> |
if (vdef(RAWFILE)) { |
1371 |
> |
sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); |
1372 |
> |
mvfile(rawfile, combuf); |
1373 |
> |
} else |
1374 |
> |
rmfile(rawfile); |
1375 |
> |
finish_process(); /* exit if child */ |
1376 |
|
} |
1377 |
+ |
wait_process(1); /* wait for children to finish */ |
1378 |
+ |
if (pfile != NULL) { /* clean up rpict persistent mode */ |
1379 |
+ |
RT_PID pid; |
1380 |
+ |
fp = fopen(pfile, "r"); |
1381 |
+ |
if (fp != NULL) { |
1382 |
+ |
if (fscanf(fp, "%*s %d", &pid) != 1 || |
1383 |
+ |
kill(pid, 1) < 0) |
1384 |
+ |
unlink(pfile); |
1385 |
+ |
fclose(fp); |
1386 |
+ |
} |
1387 |
+ |
} |
1388 |
+ |
return; |
1389 |
+ |
rperror: |
1390 |
+ |
fprintf(stderr, "%s: error rendering view %s\n", progname, vs); |
1391 |
+ |
quit(1); |
1392 |
|
} |
1393 |
|
|
1394 |
|
|
1395 |
< |
runcom(cs) /* run command */ |
1396 |
< |
char *cs; |
1395 |
> |
static int |
1396 |
> |
touch( /* update a file */ |
1397 |
> |
char *fn |
1398 |
> |
) |
1399 |
|
{ |
1400 |
+ |
if (!silent) |
1401 |
+ |
printf("\ttouch %s\n", fn); |
1402 |
+ |
if (!nprocs) |
1403 |
+ |
return(0); |
1404 |
+ |
#ifdef notused |
1405 |
+ |
if (access(fn, F_OK) == -1) /* create it */ |
1406 |
+ |
if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1) |
1407 |
+ |
return(-1); |
1408 |
+ |
#endif |
1409 |
+ |
return(setfdate(fn, time((time_t *)NULL))); |
1410 |
+ |
} |
1411 |
+ |
|
1412 |
+ |
|
1413 |
+ |
static int |
1414 |
+ |
runcom( /* run command */ |
1415 |
+ |
char *cs |
1416 |
+ |
) |
1417 |
+ |
{ |
1418 |
|
if (!silent) /* echo it */ |
1419 |
|
printf("\t%s\n", cs); |
1420 |
< |
if (noaction) |
1420 |
> |
if (!nprocs) |
1421 |
|
return(0); |
1422 |
< |
fflush(stdout); /* flush output and pass to shell */ |
1422 |
> |
fflush(NULL); /* flush output and pass to shell */ |
1423 |
|
return(system(cs)); |
1424 |
|
} |
1425 |
|
|
1426 |
|
|
1427 |
< |
rmfile(fn) /* remove a file */ |
1428 |
< |
char *fn; |
1427 |
> |
static int |
1428 |
> |
rmfile( /* remove a file */ |
1429 |
> |
char *fn |
1430 |
> |
) |
1431 |
|
{ |
1432 |
|
if (!silent) |
1433 |
< |
#ifdef MSDOS |
1434 |
< |
printf("\tdel %s\n", fn); |
1125 |
< |
#else |
1126 |
< |
printf("\trm -f %s\n", fn); |
1127 |
< |
#endif |
1128 |
< |
if (noaction) |
1433 |
> |
printf("\t%s %s\n", DELCMD, fn); |
1434 |
> |
if (!nprocs) |
1435 |
|
return(0); |
1436 |
|
return(unlink(fn)); |
1437 |
|
} |
1438 |
|
|
1439 |
|
|
1440 |
< |
#ifdef MSDOS |
1440 |
> |
static int |
1441 |
> |
mvfile( /* move a file */ |
1442 |
> |
char *fold, |
1443 |
> |
char *fnew |
1444 |
> |
) |
1445 |
> |
{ |
1446 |
> |
if (!silent) |
1447 |
> |
printf("\t%s %s %s\n", RENAMECMD, fold, fnew); |
1448 |
> |
if (!nprocs) |
1449 |
> |
return(0); |
1450 |
> |
return(rename(fold, fnew)); |
1451 |
> |
} |
1452 |
> |
|
1453 |
> |
|
1454 |
> |
#ifdef RHAS_FORK_EXEC |
1455 |
> |
static int |
1456 |
> |
next_process(void) /* fork the next process (max. nprocs) */ |
1457 |
> |
{ |
1458 |
> |
RT_PID child_pid; |
1459 |
> |
|
1460 |
> |
if (nprocs <= 1) |
1461 |
> |
return(0); /* it's us or no one */ |
1462 |
> |
if (inchild()) { |
1463 |
> |
fprintf(stderr, "%s: internal error 1 in next_process()\n", |
1464 |
> |
progname); |
1465 |
> |
quit(1); |
1466 |
> |
} |
1467 |
> |
if (children_running >= nprocs) |
1468 |
> |
wait_process(0); /* wait for someone to finish */ |
1469 |
> |
fflush(NULL); /* flush output */ |
1470 |
> |
child_pid = fork(); /* split process */ |
1471 |
> |
if (child_pid == 0) { /* we're the child */ |
1472 |
> |
children_running = -1; |
1473 |
> |
return(0); |
1474 |
> |
} |
1475 |
> |
if (child_pid > 0) { /* we're the parent */ |
1476 |
> |
++children_running; |
1477 |
> |
return(1); |
1478 |
> |
} |
1479 |
> |
fprintf(stderr, "%s: warning -- fork() failed\n", progname); |
1480 |
> |
return(0); |
1481 |
> |
} |
1482 |
> |
|
1483 |
> |
static void |
1484 |
> |
wait_process( /* wait for process(es) to finish */ |
1485 |
> |
int all |
1486 |
> |
) |
1487 |
> |
{ |
1488 |
> |
int ourstatus = 0, status; |
1489 |
> |
RT_PID pid; |
1490 |
> |
|
1491 |
> |
if (all) |
1492 |
> |
all = children_running; |
1493 |
> |
else if (children_running > 0) |
1494 |
> |
all = 1; |
1495 |
> |
while (all-- > 0) { |
1496 |
> |
pid = wait(&status); |
1497 |
> |
if (pid < 0) |
1498 |
> |
syserr(progname); |
1499 |
> |
status = status>>8 & 0xff; |
1500 |
> |
--children_running; |
1501 |
> |
if (status != 0) { /* child's problem is our problem */ |
1502 |
> |
if ((ourstatus == 0) & (children_running > 0)) |
1503 |
> |
fprintf(stderr, "%s: waiting for remaining processes\n", |
1504 |
> |
progname); |
1505 |
> |
ourstatus = status; |
1506 |
> |
all = children_running; |
1507 |
> |
} |
1508 |
> |
} |
1509 |
> |
if (ourstatus != 0) |
1510 |
> |
quit(ourstatus); /* bad status from child */ |
1511 |
> |
} |
1512 |
> |
#else /* ! RHAS_FORK_EXEC */ |
1513 |
> |
static int |
1514 |
> |
next_process(void) |
1515 |
> |
{ |
1516 |
> |
return(0); /* cannot start new process */ |
1517 |
> |
} |
1518 |
> |
static void |
1519 |
> |
wait_process(all) |
1520 |
> |
int all; |
1521 |
> |
{ |
1522 |
> |
(void)all; /* no one to wait for */ |
1523 |
> |
} |
1524 |
> |
int |
1525 |
> |
kill(pid, sig) /* win|unix_process.c should also wait and kill */ |
1526 |
> |
RT_PID pid; |
1527 |
> |
int sig; |
1528 |
> |
{ |
1529 |
> |
return 0; |
1530 |
> |
} |
1531 |
> |
#endif /* ! RHAS_FORK_EXEC */ |
1532 |
> |
|
1533 |
> |
static void |
1534 |
> |
finish_process(void) /* exit a child process */ |
1535 |
> |
{ |
1536 |
> |
if (!inchild()) |
1537 |
> |
return; /* in parent -- noop */ |
1538 |
> |
exit(0); |
1539 |
> |
} |
1540 |
> |
|
1541 |
> |
#ifdef _WIN32 |
1542 |
|
setenv(vname, value) /* set an environment variable */ |
1543 |
|
char *vname, *value; |
1544 |
|
{ |
1550 |
|
sprintf(evp, "%s=%s", vname, value); |
1551 |
|
if (putenv(evp) != 0) { |
1552 |
|
fprintf(stderr, "%s: out of environment space\n", progname); |
1553 |
< |
exit(1); |
1553 |
> |
quit(1); |
1554 |
|
} |
1555 |
|
if (!silent) |
1556 |
|
printf("set %s\n", evp); |
1558 |
|
#endif |
1559 |
|
|
1560 |
|
|
1561 |
< |
badvalue(vc) /* report bad variable value and exit */ |
1562 |
< |
int vc; |
1561 |
> |
static void |
1562 |
> |
badvalue( /* report bad variable value and exit */ |
1563 |
> |
int vc |
1564 |
> |
) |
1565 |
|
{ |
1566 |
|
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1567 |
|
progname, vnam(vc)); |
1568 |
< |
exit(1); |
1568 |
> |
quit(1); |
1569 |
|
} |
1570 |
|
|
1571 |
|
|
1572 |
< |
syserr(s) /* report a system error and exit */ |
1573 |
< |
char *s; |
1572 |
> |
static void |
1573 |
> |
syserr( /* report a system error and exit */ |
1574 |
> |
char *s |
1575 |
> |
) |
1576 |
|
{ |
1577 |
|
perror(s); |
1578 |
< |
exit(1); |
1578 |
> |
quit(1); |
1579 |
> |
} |
1580 |
> |
|
1581 |
> |
|
1582 |
> |
void |
1583 |
> |
quit(ec) /* exit program */ |
1584 |
> |
int ec; |
1585 |
> |
{ |
1586 |
> |
exit(ec); |
1587 |
|
} |