17 |
|
#include "ambient.h" |
18 |
|
#include "random.h" |
19 |
|
#include "paths.h" |
20 |
+ |
#include "pmapray.h" |
21 |
|
|
22 |
+ |
extern char *progname; /* global argv[0] */ |
23 |
+ |
|
24 |
+ |
extern char *shm_boundary; /* boundary of shared memory */ |
25 |
+ |
|
26 |
|
/* persistent processes define */ |
27 |
|
#ifdef F_SETLKW |
28 |
|
#define PERSIST 1 /* normal persist */ |
30 |
|
#define PCHILD 3 /* child of normal persist */ |
31 |
|
#endif |
32 |
|
|
28 |
– |
char *progname; /* argv[0] */ |
29 |
– |
char *octname; /* octree name */ |
33 |
|
char *sigerr[NSIG]; /* signal error messages */ |
31 |
– |
char *shm_boundary = NULL; /* boundary of shared memory */ |
34 |
|
char *errfile = NULL; /* error output file */ |
35 |
|
|
36 |
< |
extern char *formstr(); /* string from format */ |
35 |
< |
extern int inform; /* input format */ |
36 |
< |
extern int outform; /* output format */ |
37 |
< |
extern char *outvals; /* output values */ |
36 |
> |
int nproc = 1; /* number of processes */ |
37 |
|
|
38 |
< |
extern int hresolu; /* horizontal resolution */ |
39 |
< |
extern int vresolu; /* vertical resolution */ |
38 |
> |
extern char *formstr(int f); /* string from format */ |
39 |
> |
extern int setrtoutput(void); /* set output values */ |
40 |
|
|
41 |
< |
extern int imm_irrad; /* compute immediate irradiance? */ |
42 |
< |
extern int lim_dist; /* limit distance? */ |
41 |
> |
int inform = 'a'; /* input format */ |
42 |
> |
int outform = 'a'; /* output format */ |
43 |
> |
char *outvals = "v"; /* output specification */ |
44 |
|
|
45 |
< |
extern char *tralist[]; /* list of modifers to trace (or no) */ |
46 |
< |
extern int traincl; /* include == 1, exclude == 0 */ |
45 |
> |
int hresolu = 0; /* horizontal (scan) size */ |
46 |
> |
int vresolu = 0; /* vertical resolution */ |
47 |
|
|
48 |
+ |
extern int castonly; /* only doing ray-casting? */ |
49 |
+ |
|
50 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
51 |
+ |
int lim_dist = 0; /* limit distance? */ |
52 |
+ |
|
53 |
+ |
#ifndef MAXMODLIST |
54 |
+ |
#define MAXMODLIST 1024 /* maximum modifiers we'll track */ |
55 |
+ |
#endif |
56 |
+ |
|
57 |
+ |
extern void (*addobjnotify[])(); /* object notification calls */ |
58 |
+ |
extern void tranotify(OBJECT obj); |
59 |
+ |
|
60 |
+ |
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
61 |
+ |
int traincl = -1; /* include == 1, exclude == 0 */ |
62 |
+ |
|
63 |
|
static int loadflags = ~IO_FILES; /* what to load from octree */ |
64 |
|
|
65 |
|
static void onsig(int signo); |
73 |
|
#define check(ol,al) if (argv[i][ol] || \ |
74 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
75 |
|
goto badopt |
76 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
76 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
77 |
|
case '\0': var = !var; break; \ |
78 |
|
case 'y': case 'Y': case 't': case 'T': \ |
79 |
|
case '+': case '1': var = 1; break; \ |
80 |
|
case 'n': case 'N': case 'f': case 'F': \ |
81 |
|
case '-': case '0': var = 0; break; \ |
82 |
|
default: goto badopt; } |
83 |
+ |
extern char *octname; |
84 |
|
int persist = 0; |
85 |
< |
char **tralp; |
86 |
< |
int duped1; |
85 |
> |
char *octnm = NULL; |
86 |
> |
char **tralp = NULL; |
87 |
> |
int duped1 = -1; |
88 |
|
int rval; |
89 |
|
int i; |
90 |
|
/* global program name */ |
91 |
|
progname = argv[0] = fixargv0(argv[0]); |
92 |
+ |
/* add trace notify function */ |
93 |
+ |
for (i = 0; addobjnotify[i] != NULL; i++) |
94 |
+ |
; |
95 |
+ |
addobjnotify[i] = tranotify; |
96 |
|
/* option city */ |
97 |
|
for (i = 1; i < argc; i++) { |
98 |
|
/* expand arguments */ |
119 |
|
continue; |
120 |
|
} |
121 |
|
switch (argv[i][1]) { |
122 |
+ |
case 'n': /* number of cores */ |
123 |
+ |
check(2,"i"); |
124 |
+ |
nproc = atoi(argv[++i]); |
125 |
+ |
if (nproc <= 0) |
126 |
+ |
error(USER, "bad number of processes"); |
127 |
+ |
break; |
128 |
|
case 'x': /* x resolution */ |
129 |
|
check(2,"i"); |
130 |
|
hresolu = atoi(argv[++i]); |
135 |
|
break; |
136 |
|
case 'w': /* warnings */ |
137 |
|
rval = erract[WARNING].pf != NULL; |
138 |
< |
bool(2,rval); |
138 |
> |
check_bool(2,rval); |
139 |
|
if (rval) erract[WARNING].pf = wputs; |
140 |
|
else erract[WARNING].pf = NULL; |
141 |
|
break; |
146 |
|
case 'l': /* limit distance */ |
147 |
|
if (argv[i][2] != 'd') |
148 |
|
goto badopt; |
149 |
< |
bool(3,lim_dist); |
149 |
> |
check_bool(3,lim_dist); |
150 |
|
break; |
151 |
|
case 'I': /* immed. irradiance */ |
152 |
< |
bool(2,imm_irrad); |
152 |
> |
check_bool(2,imm_irrad); |
153 |
|
break; |
154 |
|
case 'f': /* format i/o */ |
155 |
|
switch (argv[i][2]) { |
181 |
|
break; |
182 |
|
case 'h': /* header output */ |
183 |
|
rval = loadflags & IO_INFO; |
184 |
< |
bool(2,rval); |
184 |
> |
check_bool(2,rval); |
185 |
|
loadflags = rval ? loadflags | IO_INFO : |
186 |
|
loadflags & ~IO_INFO; |
187 |
|
break; |
195 |
|
tralp = tralist; |
196 |
|
} |
197 |
|
if (argv[i][2] == 'I') { /* file */ |
198 |
< |
rval = wordfile(tralp, |
198 |
> |
rval = wordfile(tralp, MAXMODLIST-(tralp-tralist), |
199 |
|
getpath(argv[++i],getrlibpath(),R_OK)); |
200 |
|
if (rval < 0) { |
201 |
|
sprintf(errmsg, |
217 |
|
tralp = tralist; |
218 |
|
} |
219 |
|
if (argv[i][2] == 'E') { /* file */ |
220 |
< |
rval = wordfile(tralp, |
220 |
> |
rval = wordfile(tralp, MAXMODLIST-(tralp-tralist), |
221 |
|
getpath(argv[++i],getrlibpath(),R_OK)); |
222 |
|
if (rval < 0) { |
223 |
|
sprintf(errmsg, |
251 |
|
goto badopt; |
252 |
|
} |
253 |
|
} |
254 |
+ |
if (nproc > 1 && persist) |
255 |
+ |
error(USER, "multiprocessing incompatible with persist file"); |
256 |
|
/* initialize object types */ |
257 |
|
initotypes(); |
258 |
|
/* initialize urand */ |
294 |
|
#endif |
295 |
|
/* get octree */ |
296 |
|
if (i == argc) |
297 |
< |
octname = NULL; |
297 |
> |
octnm = NULL; |
298 |
|
else if (i == argc-1) |
299 |
< |
octname = argv[i]; |
299 |
> |
octnm = argv[i]; |
300 |
|
else |
301 |
|
goto badopt; |
302 |
< |
if (octname == NULL) |
302 |
> |
if (octnm == NULL) |
303 |
|
error(USER, "missing octree argument"); |
304 |
|
/* set up output */ |
305 |
|
#ifdef PERSIST |
310 |
|
#endif |
311 |
|
if (outform != 'a') |
312 |
|
SET_FILE_BINARY(stdout); |
313 |
< |
readoct(octname, loadflags, &thescene, NULL); |
313 |
> |
rval = setrtoutput(); |
314 |
> |
readoct(octname = octnm, loadflags, &thescene, NULL); |
315 |
|
nsceneobjs = nobjects; |
316 |
|
|
317 |
|
if (loadflags & IO_INFO) { /* print header */ |
318 |
|
printargs(i, argv, stdout); |
319 |
|
printf("SOFTWARE= %s\n", VersionID); |
320 |
|
fputnow(stdout); |
321 |
+ |
if (rval > 0) /* saved from setrtoutput() call */ |
322 |
+ |
printf("NCOMP=%d\n", rval); |
323 |
+ |
if ((outform == 'f') | (outform == 'd')) |
324 |
+ |
fputendian(stdout); |
325 |
|
fputformat(formstr(outform), stdout); |
326 |
|
putchar('\n'); |
327 |
|
} |
328 |
|
|
329 |
< |
marksources(); /* find and mark sources */ |
329 |
> |
if (!castonly) { /* any actual ray traversal to do? */ |
330 |
|
|
331 |
< |
setambient(); /* initialize ambient calculation */ |
331 |
> |
ray_init_pmap(); /* PMAP: set up & load photon maps */ |
332 |
> |
|
333 |
> |
marksources(); /* find and mark sources */ |
334 |
|
|
335 |
+ |
setambient(); /* initialize ambient calculation */ |
336 |
+ |
} else |
337 |
+ |
distantsources(); /* else mark only distant sources */ |
338 |
+ |
|
339 |
+ |
fflush(stdout); /* in case we're duplicating header */ |
340 |
+ |
|
341 |
|
#ifdef PERSIST |
342 |
|
if (persist) { |
301 |
– |
fflush(stdout); |
343 |
|
/* reconnect stdout */ |
344 |
|
dup2(duped1, fileno(stdout)); |
345 |
|
close(duped1); |
362 |
|
dupheader(); /* send header to stdout */ |
363 |
|
#endif |
364 |
|
/* trace rays */ |
365 |
< |
rtrace(NULL); |
365 |
> |
rtrace(NULL, nproc); |
366 |
|
/* flush ambient file */ |
367 |
|
ambsync(); |
368 |
|
#ifdef PERSIST |
377 |
|
} |
378 |
|
} |
379 |
|
if (persist == PCHILD) { /* wait for a signal then go again */ |
339 |
– |
close(duped1); /* release output handle */ |
380 |
|
pfhold(); |
381 |
|
raynum = nrays = 0; /* reinitialize */ |
382 |
|
goto runagain; |
383 |
|
} |
384 |
|
#endif |
385 |
+ |
|
386 |
+ |
ray_done_pmap(); /* PMAP: free photon maps */ |
387 |
+ |
|
388 |
|
quit(0); |
389 |
|
|
390 |
|
badopt: |
393 |
|
return 1; /* pro forma return */ |
394 |
|
|
395 |
|
#undef check |
396 |
< |
#undef bool |
396 |
> |
#undef check_bool |
397 |
|
} |
398 |
|
|
399 |
|
|
469 |
|
|
470 |
|
if (imm_irrad) |
471 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
472 |
< |
printf("-x %-9d\t\t\t# x resolution (flush interval)\n", hresolu); |
472 |
> |
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
473 |
> |
printf("-x %-9d\t\t\t# %s\n", hresolu, |
474 |
> |
vresolu && hresolu ? "x resolution" : "flush interval"); |
475 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
476 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
477 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
485 |
|
case 't': case 'T': printf(" trace"); break; |
486 |
|
case 'o': printf(" origin"); break; |
487 |
|
case 'd': printf(" direction"); break; |
488 |
+ |
case 'r': printf(" reflect_contrib"); break; |
489 |
+ |
case 'R': printf(" reflect_length"); break; |
490 |
+ |
case 'x': printf(" unreflect_contrib"); break; |
491 |
+ |
case 'X': printf(" unreflect_length"); break; |
492 |
|
case 'v': printf(" value"); break; |
493 |
|
case 'V': printf(" contribution"); break; |
494 |
|
case 'l': printf(" length"); break; |
501 |
|
case 'W': printf(" coefficient"); break; |
502 |
|
case 'm': printf(" modifier"); break; |
503 |
|
case 'M': printf(" material"); break; |
504 |
< |
case '-': printf(" stroke"); break; |
504 |
> |
case '~': printf(" tilde"); break; |
505 |
|
} |
506 |
|
putchar('\n'); |
507 |
|
printf(erract[WARNING].pf != NULL ? |