8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include <signal.h> |
11 |
+ |
#include <time.h> |
12 |
|
#include "rcontrib.h" |
13 |
|
#include "random.h" |
14 |
|
#include "source.h" |
15 |
|
#include "ambient.h" |
16 |
+ |
#include "pmapray.h" |
17 |
+ |
#include "pmapcontrib.h" |
18 |
|
|
19 |
|
int gargc; /* global argc */ |
20 |
|
char **gargv; /* global argv */ |
43 |
|
int imm_irrad = 0; /* compute immediate irradiance? */ |
44 |
|
int lim_dist = 0; /* limit distance? */ |
45 |
|
|
46 |
< |
const char *modname[MAXMODLIST]; /* ordered modifier name list */ |
44 |
< |
int nmods = 0; /* number of modifiers */ |
46 |
> |
int report_intvl = 0; /* reporting interval (seconds) */ |
47 |
|
|
48 |
+ |
char **modname = NULL; /* ordered modifier name list */ |
49 |
+ |
int nmods = 0; /* number of modifiers */ |
50 |
+ |
int modasiz = 0; /* allocated modifier array size */ |
51 |
+ |
|
52 |
|
void (*addobjnotify[8])() = {ambnotify, NULL}; |
53 |
|
|
54 |
< |
char RCCONTEXT[] = "RCONTRIB"; /* our special evaluation context */ |
54 |
> |
char RCCONTEXT[] = "RC."; /* our special evaluation context */ |
55 |
|
|
56 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
57 |
+ |
#define RCONTRIB_FEATURES "Accumulation\nSummation\nRecovery\n" \ |
58 |
+ |
"ImmediateIrradiance\n" \ |
59 |
+ |
"ProgressReporting\nDistanceLimiting\n" \ |
60 |
+ |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
61 |
+ |
"Outputs=V,W\n" \ |
62 |
+ |
"OutputCS=RGB,spec\n" |
63 |
+ |
#else |
64 |
+ |
#define RCONTRIB_FEATURES "Multiprocessing\n" \ |
65 |
+ |
"Accumulation\nSummation\nRecovery\n" \ |
66 |
+ |
"ImmediateIrradiance\n" \ |
67 |
+ |
"ProgressReporting\nDistanceLimiting\n" \ |
68 |
+ |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
69 |
+ |
"Outputs=V,W\n" \ |
70 |
+ |
"OutputCS=RGB,spec\n" |
71 |
+ |
#endif |
72 |
|
|
73 |
|
static void |
74 |
|
printdefaults(void) /* print default values to stdout */ |
75 |
|
{ |
54 |
– |
char *cp; |
55 |
– |
|
76 |
|
printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate); |
77 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
78 |
|
contrib ? "contributions" : "coefficients"); |
84 |
|
printf("-y %-9d\t\t\t# y resolution\n", yres); |
85 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
86 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
87 |
< |
printf("-h%c\t\t\t\t# %s header\n", header ? '+' : '-', |
88 |
< |
header ? "output" : "no"); |
87 |
> |
printf(header ? "-h+\t\t\t\t# output header\n" : |
88 |
> |
"-h-\t\t\t\t# no header\n"); |
89 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
90 |
|
inpfmt, outfmt, formstr(inpfmt), formstr(outfmt)); |
91 |
+ |
if (report_intvl > 0) |
92 |
+ |
printf("-t %-9d\t\t\t# time between reports\n", report_intvl); |
93 |
|
printf(erract[WARNING].pf != NULL ? |
94 |
|
"-w+\t\t\t\t# warning messages on\n" : |
95 |
|
"-w-\t\t\t\t# warning messages off\n"); |
184 |
|
#define check(ol,al) if (argv[i][ol] || \ |
185 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
186 |
|
goto badopt |
187 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
187 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
188 |
|
case '\0': var = !var; break; \ |
189 |
|
case 'y': case 'Y': case 't': case 'T': \ |
190 |
|
case '+': case '1': var = 1; break; \ |
192 |
|
case '-': case '0': var = 0; break; \ |
193 |
|
default: goto badopt; } |
194 |
|
char *curout = NULL; |
195 |
+ |
char *prms = NULL; |
196 |
|
char *binval = NULL; |
197 |
|
int bincnt = 0; |
198 |
|
int rval; |
201 |
|
progname = argv[0] = fixargv0(argv[0]); |
202 |
|
gargv = argv; |
203 |
|
gargc = argc; |
204 |
+ |
/* feature check only? */ |
205 |
+ |
strcat(RFeatureList, RCONTRIB_FEATURES); |
206 |
+ |
if (argc > 1 && !strcmp(argv[1], "-features")) |
207 |
+ |
return feature_status(argc-2, argv+2); |
208 |
+ |
#if defined(_WIN32) || defined(_WIN64) /* increase file limit to maximum */ |
209 |
+ |
for (i = 8192; i > _IOB_ENTRIES; i >>= 1) |
210 |
+ |
if (_setmaxstdio(i) == i) |
211 |
+ |
break; |
212 |
+ |
#endif |
213 |
|
/* initialize calcomp routines early */ |
214 |
|
initfunc(); |
215 |
< |
setcontext(RCCONTEXT); |
215 |
> |
calcontext(RCCONTEXT); |
216 |
|
/* option city */ |
217 |
|
for (i = 1; i < argc; i++) { |
218 |
|
/* expand arguments */ |
247 |
|
error(USER, "bad number of processes"); |
248 |
|
break; |
249 |
|
case 'V': /* output contributions */ |
250 |
< |
bool(2,contrib); |
250 |
> |
check_bool(2,contrib); |
251 |
|
break; |
252 |
|
case 'x': /* x resolution */ |
253 |
|
check(2,"i"); |
259 |
|
break; |
260 |
|
case 'w': /* warnings */ |
261 |
|
rval = (erract[WARNING].pf != NULL); |
262 |
< |
bool(2,rval); |
262 |
> |
check_bool(2,rval); |
263 |
|
if (rval) erract[WARNING].pf = wputs; |
264 |
|
else erract[WARNING].pf = NULL; |
265 |
|
break; |
270 |
|
case 'l': /* limit distance */ |
271 |
|
if (argv[i][2] != 'd') |
272 |
|
goto badopt; |
273 |
< |
bool(3,lim_dist); |
273 |
> |
check_bool(3,lim_dist); |
274 |
|
break; |
275 |
|
case 'I': /* immed. irradiance */ |
276 |
< |
bool(2,imm_irrad); |
276 |
> |
check_bool(2,imm_irrad); |
277 |
|
break; |
278 |
|
case 'f': /* file or force or format */ |
279 |
|
if (!argv[i][2]) { |
282 |
|
break; |
283 |
|
} |
284 |
|
if (argv[i][2] == 'o') { |
285 |
< |
bool(3,force_open); |
285 |
> |
check_bool(3,force_open); |
286 |
|
break; |
287 |
|
} |
288 |
|
setformat(argv[i]+2); |
291 |
|
check(2,"s"); |
292 |
|
curout = argv[++i]; |
293 |
|
break; |
262 |
– |
case 'c': /* input rays per output */ |
263 |
– |
check(2,"i"); |
264 |
– |
accumulate = atoi(argv[++i]); |
265 |
– |
break; |
294 |
|
case 'r': /* recover output */ |
295 |
< |
bool(2,recover); |
295 |
> |
check_bool(2,recover); |
296 |
|
break; |
297 |
|
case 'h': /* header output */ |
298 |
< |
bool(2,header); |
298 |
> |
check_bool(2,header); |
299 |
|
break; |
300 |
+ |
case 'p': /* parameter setting(s) */ |
301 |
+ |
check(2,"s"); |
302 |
+ |
set_eparams(prms = argv[++i]); |
303 |
+ |
break; |
304 |
+ |
case 'c': /* sample count */ |
305 |
+ |
check(2,"i"); |
306 |
+ |
accumulate = atoi(argv[++i]); |
307 |
+ |
break; |
308 |
|
case 'b': /* bin expression/count */ |
309 |
|
if (argv[i][2] == 'n') { |
310 |
|
check(3,"s"); |
316 |
|
break; |
317 |
|
case 'm': /* modifier name */ |
318 |
|
check(2,"s"); |
319 |
< |
addmodifier(argv[++i], curout, binval, bincnt); |
319 |
> |
addmodifier(argv[++i], curout, prms, binval, bincnt); |
320 |
|
break; |
321 |
|
case 'M': /* modifier file */ |
322 |
|
check(2,"s"); |
323 |
< |
addmodfile(argv[++i], curout, binval, bincnt); |
323 |
> |
addmodfile(argv[++i], curout, prms, binval, bincnt); |
324 |
|
break; |
325 |
+ |
case 't': /* reporting interval */ |
326 |
+ |
check(2,"i"); |
327 |
+ |
report_intvl = atoi(argv[++i]); |
328 |
+ |
break; |
329 |
|
default: |
330 |
|
goto badopt; |
331 |
|
} |
332 |
|
} |
333 |
+ |
if (nmods <= 0) |
334 |
+ |
error(USER, "missing required modifier argument"); |
335 |
|
/* override some option settings */ |
336 |
|
override_options(); |
337 |
+ |
/* set/check spectral sampling */ |
338 |
+ |
if (setspectrsamp(CNDX, WLPART) < 0) |
339 |
+ |
error(USER, "unsupported spectral sampling"); |
340 |
|
/* initialize object types */ |
341 |
|
initotypes(); |
342 |
|
/* initialize urand */ |
379 |
|
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
380 |
|
nsceneobjs = nobjects; |
381 |
|
|
382 |
+ |
/* PMAP: set up & load photon maps */ |
383 |
+ |
ray_init_pmap(); |
384 |
+ |
|
385 |
|
marksources(); /* find and mark sources */ |
386 |
+ |
|
387 |
+ |
/* PMAP: init photon map for light source contributions */ |
388 |
+ |
initPmapContrib(&modconttab, nmods); |
389 |
|
|
390 |
|
setambient(); /* initialize ambient calculation */ |
391 |
< |
|
391 |
> |
|
392 |
|
rcontrib(); /* trace ray contributions (loop) */ |
393 |
|
|
394 |
< |
ambsync(); /* flush ambient file */ |
395 |
< |
|
394 |
> |
/* PMAP: free photon maps */ |
395 |
> |
ray_done_pmap(); |
396 |
> |
|
397 |
|
quit(0); /* exit clean */ |
398 |
|
|
399 |
|
badopt: |
400 |
|
fprintf(stderr, |
401 |
< |
"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", |
401 |
> |
"Usage: %s [-n nprocs][-V][-c count][-r][-e expr][-f source][-o ospec][-p p1=V1,p2=V2][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", |
402 |
|
progname); |
403 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
404 |
|
error(USER, errmsg); |
405 |
|
return(1); /* pro forma return */ |
406 |
|
|
407 |
|
#undef check |
408 |
< |
#undef bool |
408 |
> |
#undef check_bool |
409 |
|
} |
410 |
|
|
411 |
|
|
412 |
|
void |
413 |
|
wputs( /* warning output function */ |
414 |
< |
char *s |
414 |
> |
const char *s |
415 |
|
) |
416 |
|
{ |
417 |
|
int lasterrno = errno; |
418 |
+ |
if (erract[WARNING].pf == NULL) |
419 |
+ |
return; /* called by calcomp or someone */ |
420 |
|
eputs(s); |
421 |
|
errno = lasterrno; |
422 |
|
} |
424 |
|
|
425 |
|
void |
426 |
|
eputs( /* put string to stderr */ |
427 |
< |
char *s |
427 |
> |
const char *s |
428 |
|
) |
429 |
|
{ |
430 |
|
static int midline = 0; |