8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include <signal.h> |
11 |
+ |
#include <time.h> |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
|
#include "ray.h" |
15 |
|
#include "source.h" |
16 |
|
#include "ambient.h" |
17 |
+ |
#include "rpaint.h" |
18 |
|
#include "random.h" |
19 |
|
#include "paths.h" |
20 |
|
#include "view.h" |
21 |
|
|
22 |
< |
char *progname; /* argv[0] */ |
22 |
> |
extern char *progname; /* global argv[0] */ |
23 |
|
|
24 |
< |
char *octname; /* octree name */ |
24 |
> |
VIEW ourview = STDVIEW; /* viewing parameters */ |
25 |
> |
int hresolu, vresolu; /* image resolution */ |
26 |
|
|
27 |
< |
char *sigerr[NSIG]; /* signal error messages */ |
27 |
> |
int psample = 8; /* pixel sample size */ |
28 |
> |
double maxdiff = .15; /* max. sample difference */ |
29 |
|
|
30 |
< |
char *shm_boundary = NULL; /* boundary of shared memory */ |
30 |
> |
int greyscale = 0; /* map colors to brightness? */ |
31 |
> |
char *dvcname = dev_default; /* output device name */ |
32 |
|
|
33 |
< |
char *errfile = NULL; /* error output file */ |
33 |
> |
double exposure = 1.0; /* exposure for scene */ |
34 |
|
|
35 |
< |
extern int greyscale; /* map colors to brightness? */ |
36 |
< |
extern char *dvcname; /* output device name */ |
37 |
< |
extern double exposure; /* exposure compensation */ |
35 |
> |
int newparam = 1; /* parameter setting changed */ |
36 |
> |
|
37 |
> |
struct driver *dev = NULL; /* driver functions */ |
38 |
|
|
39 |
< |
extern VIEW ourview; /* viewing parameters */ |
39 |
> |
char rifname[128]; /* rad input file name */ |
40 |
|
|
41 |
< |
extern char rifname[]; /* rad input file name */ |
41 |
> |
VIEW oldview; /* previous view parameters */ |
42 |
|
|
43 |
< |
extern int hresolu; /* horizontal resolution */ |
44 |
< |
extern int vresolu; /* vertical resolution */ |
43 |
> |
PNODE ptrunk; /* the base of our image */ |
44 |
> |
RECT pframe; /* current frame boundaries */ |
45 |
> |
int pdepth; /* image depth in current frame */ |
46 |
|
|
47 |
< |
extern int psample; /* pixel sample size */ |
42 |
< |
extern double maxdiff; /* max. sample difference */ |
47 |
> |
char *errfile = NULL; /* error output file */ |
48 |
|
|
49 |
< |
void onsig(); |
45 |
< |
void sigdie(); |
46 |
< |
void printdefaults(); |
49 |
> |
int nproc = 1; /* number of processes */ |
50 |
|
|
51 |
+ |
char *sigerr[NSIG]; /* signal error messages */ |
52 |
|
|
53 |
+ |
static void onsig(int signo); |
54 |
+ |
static void sigdie(int signo, char *msg); |
55 |
+ |
static void printdefaults(void); |
56 |
+ |
|
57 |
+ |
|
58 |
|
int |
59 |
< |
main(argc, argv) |
51 |
< |
int argc; |
52 |
< |
char *argv[]; |
59 |
> |
main(int argc, char *argv[]) |
60 |
|
{ |
61 |
|
#define check(ol,al) if (argv[i][ol] || \ |
62 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
68 |
|
case 'n': case 'N': case 'f': case 'F': \ |
69 |
|
case '-': case '0': var = 0; break; \ |
70 |
|
default: goto badopt; } |
71 |
+ |
char *octnm = NULL; |
72 |
|
char *err; |
73 |
|
int rval; |
74 |
|
int i; |
75 |
|
/* global program name */ |
76 |
|
progname = argv[0] = fixargv0(argv[0]); |
77 |
+ |
/* set our defaults */ |
78 |
+ |
shadthresh = .1; |
79 |
+ |
shadcert = .25; |
80 |
+ |
directrelay = 0; |
81 |
+ |
vspretest = 128; |
82 |
+ |
srcsizerat = 0.; |
83 |
+ |
specthresh = .3; |
84 |
+ |
specjitter = 1.; |
85 |
+ |
maxdepth = 6; |
86 |
+ |
minweight = 1e-2; |
87 |
+ |
ambacc = 0.3; |
88 |
+ |
ambres = 32; |
89 |
+ |
ambdiv = 256; |
90 |
+ |
ambssamp = 64; |
91 |
|
/* option city */ |
92 |
|
for (i = 1; i < argc; i++) { |
93 |
|
/* expand arguments */ |
123 |
|
continue; |
124 |
|
} |
125 |
|
switch (argv[i][1]) { |
126 |
+ |
case 'n': /* # processes */ |
127 |
+ |
check(2,"i"); |
128 |
+ |
nproc = atoi(argv[++i]); |
129 |
+ |
if (nproc <= 0) |
130 |
+ |
error(USER, "bad number of processes"); |
131 |
+ |
break; |
132 |
|
case 'v': /* view file */ |
133 |
|
if (argv[i][2] != 'f') |
134 |
|
goto badopt; |
194 |
|
err = setview(&ourview); /* set viewing parameters */ |
195 |
|
if (err != NULL) |
196 |
|
error(USER, err); |
197 |
< |
/* initialize object types */ |
170 |
< |
initotypes(); |
171 |
< |
/* initialize urand */ |
172 |
< |
initurand(2048); |
173 |
< |
/* set up signal handling */ |
197 |
> |
/* set up signal handling */ |
198 |
|
sigdie(SIGINT, "Interrupt"); |
175 |
– |
sigdie(SIGHUP, "Hangup"); |
199 |
|
sigdie(SIGTERM, "Terminate"); |
200 |
+ |
#ifndef _WIN32 |
201 |
+ |
sigdie(SIGHUP, "Hangup"); |
202 |
|
sigdie(SIGPIPE, "Broken pipe"); |
203 |
|
sigdie(SIGALRM, "Alarm clock"); |
179 |
– |
#ifdef SIGXCPU |
180 |
– |
sigdie(SIGXCPU, "CPU limit exceeded"); |
181 |
– |
sigdie(SIGXFSZ, "File size exceeded"); |
204 |
|
#endif |
205 |
|
/* open error file */ |
206 |
|
if (errfile != NULL) { |
217 |
|
#endif |
218 |
|
/* get octree */ |
219 |
|
if (i == argc) |
220 |
< |
octname = NULL; |
220 |
> |
octnm = NULL; |
221 |
|
else if (i == argc-1) |
222 |
< |
octname = argv[i]; |
222 |
> |
octnm = argv[i]; |
223 |
|
else |
224 |
|
goto badopt; |
225 |
< |
if (octname == NULL) |
225 |
> |
if (octnm == NULL) |
226 |
|
error(USER, "missing octree argument"); |
227 |
< |
/* set up output */ |
227 |
> |
/* set up output & start process(es) */ |
228 |
|
SET_FILE_BINARY(stdout); |
229 |
< |
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
230 |
< |
nsceneobjs = nobjects; |
229 |
> |
|
230 |
> |
ray_init(octnm); |
231 |
|
|
210 |
– |
marksources(); /* find and mark sources */ |
211 |
– |
|
212 |
– |
setambient(); /* initialize ambient calculation */ |
213 |
– |
|
232 |
|
rview(); /* run interactive viewer */ |
233 |
|
|
234 |
< |
ambsync(); /* flush ambient file */ |
234 |
> |
devclose(); /* close output device */ |
235 |
|
|
236 |
|
quit(0); |
237 |
|
|
238 |
|
badopt: |
239 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
240 |
|
error(USER, errmsg); |
241 |
+ |
return 1; /* pro forma return */ |
242 |
|
|
243 |
|
#undef check |
244 |
|
#undef bool |
246 |
|
|
247 |
|
|
248 |
|
void |
249 |
< |
wputs(s) /* warning output function */ |
250 |
< |
char *s; |
249 |
> |
wputs( /* warning output function */ |
250 |
> |
char *s |
251 |
> |
) |
252 |
|
{ |
253 |
|
int lasterrno = errno; |
254 |
|
eputs(s); |
257 |
|
|
258 |
|
|
259 |
|
void |
260 |
< |
eputs(s) /* put string to stderr */ |
261 |
< |
register char *s; |
260 |
> |
eputs( /* put string to stderr */ |
261 |
> |
char *s |
262 |
> |
) |
263 |
|
{ |
264 |
|
static int midline = 0; |
265 |
|
|
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
< |
void |
281 |
< |
onsig(signo) /* fatal signal */ |
282 |
< |
int signo; |
280 |
> |
static void |
281 |
> |
onsig( /* fatal signal */ |
282 |
> |
int signo |
283 |
> |
) |
284 |
|
{ |
285 |
|
static int gotsig = 0; |
286 |
|
|
287 |
|
if (gotsig++) /* two signals and we're gone! */ |
288 |
|
_exit(signo); |
289 |
|
|
290 |
+ |
#ifndef _WIN32 |
291 |
|
alarm(15); /* allow 15 seconds to clean up */ |
292 |
|
signal(SIGALRM, SIG_DFL); /* make certain we do die */ |
293 |
+ |
#endif |
294 |
|
eputs("signal - "); |
295 |
|
eputs(sigerr[signo]); |
296 |
|
eputs("\n"); |
297 |
+ |
devclose(); |
298 |
|
quit(3); |
299 |
|
} |
300 |
|
|
301 |
|
|
302 |
< |
void |
303 |
< |
sigdie(signo, msg) /* set fatal signal */ |
304 |
< |
int signo; |
305 |
< |
char *msg; |
302 |
> |
static void |
303 |
> |
sigdie( /* set fatal signal */ |
304 |
> |
int signo, |
305 |
> |
char *msg |
306 |
> |
) |
307 |
|
{ |
308 |
|
if (signal(signo, onsig) == SIG_IGN) |
309 |
|
signal(signo, SIG_IGN); |
311 |
|
} |
312 |
|
|
313 |
|
|
314 |
< |
void |
315 |
< |
printdefaults() /* print default values to stdout */ |
314 |
> |
static void |
315 |
> |
printdefaults(void) /* print default values to stdout */ |
316 |
|
{ |
317 |
< |
register char *cp; |
292 |
< |
|
317 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
318 |
|
printf(greyscale ? "-b+\t\t\t\t# greyscale on\n" : |
319 |
|
"-b-\t\t\t\t# greyscale off\n"); |
320 |
|
printf("-vt%c\t\t\t\t# view type %s\n", ourview.type, |
323 |
|
ourview.type==VT_HEM ? "hemispherical" : |
324 |
|
ourview.type==VT_ANG ? "angular" : |
325 |
|
ourview.type==VT_CYL ? "cylindrical" : |
326 |
+ |
ourview.type==VT_PLS ? "planisphere" : |
327 |
|
"unknown"); |
328 |
|
printf("-vp %f %f %f\t# view point\n", |
329 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |