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 |
+ |
"ValueContribution\nImmediateIrradiance\n" \ |
59 |
+ |
"ProgressReporting\nDistanceLimiting\n" \ |
60 |
+ |
"Outputs=V,W\n" |
61 |
+ |
#else |
62 |
+ |
#define RCONTRIB_FEATURES "Multiprocessing\n" \ |
63 |
+ |
"Accumulation\nSummation\nRecovery\n" \ |
64 |
+ |
"ValueContribution\nImmediateIrradiance\n" \ |
65 |
+ |
"ProgressReporting\nDistanceLimiting\n" \ |
66 |
+ |
"Outputs=V,W\n" |
67 |
+ |
#endif |
68 |
|
|
69 |
|
static void |
70 |
|
printdefaults(void) /* print default values to stdout */ |
71 |
|
{ |
54 |
– |
char *cp; |
55 |
– |
|
72 |
|
printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate); |
73 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
74 |
|
contrib ? "contributions" : "coefficients"); |
178 |
|
#define check(ol,al) if (argv[i][ol] || \ |
179 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
180 |
|
goto badopt |
181 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
181 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
182 |
|
case '\0': var = !var; break; \ |
183 |
|
case 'y': case 'Y': case 't': case 'T': \ |
184 |
|
case '+': case '1': var = 1; break; \ |
186 |
|
case '-': case '0': var = 0; break; \ |
187 |
|
default: goto badopt; } |
188 |
|
char *curout = NULL; |
189 |
+ |
char *prms = NULL; |
190 |
|
char *binval = NULL; |
191 |
|
int bincnt = 0; |
192 |
|
int rval; |
195 |
|
progname = argv[0] = fixargv0(argv[0]); |
196 |
|
gargv = argv; |
197 |
|
gargc = argc; |
198 |
+ |
/* feature check only? */ |
199 |
+ |
strcat(RFeatureList, RCONTRIB_FEATURES); |
200 |
+ |
if (argc > 1 && !strcmp(argv[1], "-features")) |
201 |
+ |
return feature_status(argc-2, argv+2); |
202 |
+ |
#if defined(_WIN32) || defined(_WIN64) /* increase file limit to maximum */ |
203 |
+ |
for (i = 8192; i > _IOB_ENTRIES; i >>= 1) |
204 |
+ |
if (_setmaxstdio(i) == i) |
205 |
+ |
break; |
206 |
+ |
#endif |
207 |
|
/* initialize calcomp routines early */ |
208 |
|
initfunc(); |
209 |
< |
setcontext(RCCONTEXT); |
209 |
> |
calcontext(RCCONTEXT); |
210 |
|
/* option city */ |
211 |
|
for (i = 1; i < argc; i++) { |
212 |
|
/* expand arguments */ |
241 |
|
error(USER, "bad number of processes"); |
242 |
|
break; |
243 |
|
case 'V': /* output contributions */ |
244 |
< |
bool(2,contrib); |
244 |
> |
check_bool(2,contrib); |
245 |
|
break; |
246 |
|
case 'x': /* x resolution */ |
247 |
|
check(2,"i"); |
253 |
|
break; |
254 |
|
case 'w': /* warnings */ |
255 |
|
rval = (erract[WARNING].pf != NULL); |
256 |
< |
bool(2,rval); |
256 |
> |
check_bool(2,rval); |
257 |
|
if (rval) erract[WARNING].pf = wputs; |
258 |
|
else erract[WARNING].pf = NULL; |
259 |
|
break; |
264 |
|
case 'l': /* limit distance */ |
265 |
|
if (argv[i][2] != 'd') |
266 |
|
goto badopt; |
267 |
< |
bool(3,lim_dist); |
267 |
> |
check_bool(3,lim_dist); |
268 |
|
break; |
269 |
|
case 'I': /* immed. irradiance */ |
270 |
< |
bool(2,imm_irrad); |
270 |
> |
check_bool(2,imm_irrad); |
271 |
|
break; |
272 |
|
case 'f': /* file or force or format */ |
273 |
|
if (!argv[i][2]) { |
276 |
|
break; |
277 |
|
} |
278 |
|
if (argv[i][2] == 'o') { |
279 |
< |
bool(3,force_open); |
279 |
> |
check_bool(3,force_open); |
280 |
|
break; |
281 |
|
} |
282 |
|
setformat(argv[i]+2); |
290 |
|
accumulate = atoi(argv[++i]); |
291 |
|
break; |
292 |
|
case 'r': /* recover output */ |
293 |
< |
bool(2,recover); |
293 |
> |
check_bool(2,recover); |
294 |
|
break; |
295 |
|
case 'h': /* header output */ |
296 |
< |
bool(2,header); |
296 |
> |
check_bool(2,header); |
297 |
|
break; |
298 |
+ |
case 'p': /* parameter setting(s) */ |
299 |
+ |
check(2,"s"); |
300 |
+ |
set_eparams(prms = argv[++i]); |
301 |
+ |
break; |
302 |
|
case 'b': /* bin expression/count */ |
303 |
|
if (argv[i][2] == 'n') { |
304 |
|
check(3,"s"); |
310 |
|
break; |
311 |
|
case 'm': /* modifier name */ |
312 |
|
check(2,"s"); |
313 |
< |
addmodifier(argv[++i], curout, binval, bincnt); |
313 |
> |
addmodifier(argv[++i], curout, prms, binval, bincnt); |
314 |
|
break; |
315 |
|
case 'M': /* modifier file */ |
316 |
|
check(2,"s"); |
317 |
< |
addmodfile(argv[++i], curout, binval, bincnt); |
317 |
> |
addmodfile(argv[++i], curout, prms, binval, bincnt); |
318 |
|
break; |
319 |
+ |
case 't': /* reporting interval */ |
320 |
+ |
check(2,"i"); |
321 |
+ |
report_intvl = atoi(argv[++i]); |
322 |
+ |
break; |
323 |
|
default: |
324 |
|
goto badopt; |
325 |
|
} |
326 |
|
} |
327 |
+ |
if (nmods <= 0) |
328 |
+ |
error(USER, "missing required modifier argument"); |
329 |
|
/* override some option settings */ |
330 |
|
override_options(); |
331 |
|
/* initialize object types */ |
370 |
|
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
371 |
|
nsceneobjs = nobjects; |
372 |
|
|
373 |
+ |
/* PMAP: set up & load photon maps */ |
374 |
+ |
ray_init_pmap(); |
375 |
+ |
|
376 |
|
marksources(); /* find and mark sources */ |
377 |
+ |
|
378 |
+ |
/* PMAP: init photon map for light source contributions */ |
379 |
+ |
initPmapContrib(&modconttab, nmods); |
380 |
|
|
381 |
|
setambient(); /* initialize ambient calculation */ |
382 |
< |
|
382 |
> |
|
383 |
|
rcontrib(); /* trace ray contributions (loop) */ |
384 |
|
|
385 |
|
ambsync(); /* flush ambient file */ |
386 |
|
|
387 |
+ |
/* PMAP: free photon maps */ |
388 |
+ |
ray_done_pmap(); |
389 |
+ |
|
390 |
|
quit(0); /* exit clean */ |
391 |
|
|
392 |
|
badopt: |
393 |
|
fprintf(stderr, |
394 |
< |
"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", |
394 |
> |
"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", |
395 |
|
progname); |
396 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
397 |
|
error(USER, errmsg); |
398 |
|
return(1); /* pro forma return */ |
399 |
|
|
400 |
|
#undef check |
401 |
< |
#undef bool |
401 |
> |
#undef check_bool |
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
|
void |
406 |
|
wputs( /* warning output function */ |
407 |
< |
char *s |
407 |
> |
const char *s |
408 |
|
) |
409 |
|
{ |
410 |
|
int lasterrno = errno; |
415 |
|
|
416 |
|
void |
417 |
|
eputs( /* put string to stderr */ |
418 |
< |
char *s |
418 |
> |
const char *s |
419 |
|
) |
420 |
|
{ |
421 |
|
static int midline = 0; |