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 |
+ |
int report_intvl = 0; /* reporting interval (seconds) */ |
47 |
+ |
|
48 |
|
const char *modname[MAXMODLIST]; /* ordered modifier name list */ |
49 |
|
int nmods = 0; /* number of modifiers */ |
50 |
|
|
51 |
|
void (*addobjnotify[8])() = {ambnotify, NULL}; |
52 |
|
|
53 |
< |
char RCCONTEXT[] = "RCONTRIB"; /* our special evaluation context */ |
53 |
> |
char RCCONTEXT[] = "RC."; /* our special evaluation context */ |
54 |
|
|
55 |
|
|
56 |
|
static void |
57 |
|
printdefaults(void) /* print default values to stdout */ |
58 |
|
{ |
53 |
– |
char *cp; |
54 |
– |
|
59 |
|
printf("-c %-5d\t\t\t# accumulated rays per record\n", accumulate); |
60 |
|
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
61 |
|
contrib ? "contributions" : "coefficients"); |
165 |
|
#define check(ol,al) if (argv[i][ol] || \ |
166 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
167 |
|
goto badopt |
168 |
< |
#define bool(olen,var) switch (argv[i][olen]) { \ |
168 |
> |
#define check_bool(olen,var) switch (argv[i][olen]) { \ |
169 |
|
case '\0': var = !var; break; \ |
170 |
|
case 'y': case 'Y': case 't': case 'T': \ |
171 |
|
case '+': case '1': var = 1; break; \ |
172 |
|
case 'n': case 'N': case 'f': case 'F': \ |
173 |
|
case '-': case '0': var = 0; break; \ |
174 |
|
default: goto badopt; } |
171 |
– |
int nprocs = 1; |
175 |
|
char *curout = NULL; |
176 |
+ |
char *prms = NULL; |
177 |
|
char *binval = NULL; |
178 |
|
int bincnt = 0; |
179 |
|
int rval; |
182 |
|
progname = argv[0] = fixargv0(argv[0]); |
183 |
|
gargv = argv; |
184 |
|
gargc = argc; |
185 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
186 |
+ |
_setmaxstdio(2048); /* increase file limit to maximum */ |
187 |
+ |
#endif |
188 |
|
/* initialize calcomp routines early */ |
189 |
|
initfunc(); |
190 |
|
setcontext(RCCONTEXT); |
222 |
|
error(USER, "bad number of processes"); |
223 |
|
break; |
224 |
|
case 'V': /* output contributions */ |
225 |
< |
bool(2,contrib); |
225 |
> |
check_bool(2,contrib); |
226 |
|
break; |
227 |
|
case 'x': /* x resolution */ |
228 |
|
check(2,"i"); |
234 |
|
break; |
235 |
|
case 'w': /* warnings */ |
236 |
|
rval = (erract[WARNING].pf != NULL); |
237 |
< |
bool(2,rval); |
237 |
> |
check_bool(2,rval); |
238 |
|
if (rval) erract[WARNING].pf = wputs; |
239 |
|
else erract[WARNING].pf = NULL; |
240 |
|
break; |
245 |
|
case 'l': /* limit distance */ |
246 |
|
if (argv[i][2] != 'd') |
247 |
|
goto badopt; |
248 |
< |
bool(3,lim_dist); |
248 |
> |
check_bool(3,lim_dist); |
249 |
|
break; |
250 |
|
case 'I': /* immed. irradiance */ |
251 |
< |
bool(2,imm_irrad); |
251 |
> |
check_bool(2,imm_irrad); |
252 |
|
break; |
253 |
|
case 'f': /* file or force or format */ |
254 |
|
if (!argv[i][2]) { |
257 |
|
break; |
258 |
|
} |
259 |
|
if (argv[i][2] == 'o') { |
260 |
< |
bool(3,force_open); |
260 |
> |
check_bool(3,force_open); |
261 |
|
break; |
262 |
|
} |
263 |
|
setformat(argv[i]+2); |
271 |
|
accumulate = atoi(argv[++i]); |
272 |
|
break; |
273 |
|
case 'r': /* recover output */ |
274 |
< |
bool(2,recover); |
274 |
> |
check_bool(2,recover); |
275 |
|
break; |
276 |
|
case 'h': /* header output */ |
277 |
< |
bool(2,header); |
277 |
> |
check_bool(2,header); |
278 |
|
break; |
279 |
+ |
case 'p': /* parameter setting(s) */ |
280 |
+ |
check(2,"s"); |
281 |
+ |
set_eparams(prms = argv[++i]); |
282 |
+ |
break; |
283 |
|
case 'b': /* bin expression/count */ |
284 |
|
if (argv[i][2] == 'n') { |
285 |
|
check(3,"s"); |
291 |
|
break; |
292 |
|
case 'm': /* modifier name */ |
293 |
|
check(2,"s"); |
294 |
< |
addmodifier(argv[++i], curout, binval, bincnt); |
294 |
> |
addmodifier(argv[++i], curout, prms, binval, bincnt); |
295 |
|
break; |
296 |
|
case 'M': /* modifier file */ |
297 |
|
check(2,"s"); |
298 |
< |
addmodfile(argv[++i], curout, binval, bincnt); |
298 |
> |
addmodfile(argv[++i], curout, prms, binval, bincnt); |
299 |
|
break; |
300 |
+ |
case 't': /* reporting interval */ |
301 |
+ |
check(2,"i"); |
302 |
+ |
report_intvl = atoi(argv[++i]); |
303 |
+ |
break; |
304 |
|
default: |
305 |
|
goto badopt; |
306 |
|
} |
307 |
|
} |
308 |
+ |
if (nmods <= 0) |
309 |
+ |
error(USER, "missing required modifier argument"); |
310 |
|
/* override some option settings */ |
311 |
|
override_options(); |
312 |
|
/* initialize object types */ |
351 |
|
readoct(octname, ~(IO_FILES|IO_INFO), &thescene, NULL); |
352 |
|
nsceneobjs = nobjects; |
353 |
|
|
354 |
+ |
/* PMAP: set up & load photon maps */ |
355 |
+ |
ray_init_pmap(); |
356 |
+ |
|
357 |
|
marksources(); /* find and mark sources */ |
358 |
+ |
|
359 |
+ |
/* PMAP: init photon map for light source contributions */ |
360 |
+ |
initPmapContrib(&modconttab, nmods); |
361 |
|
|
362 |
|
setambient(); /* initialize ambient calculation */ |
363 |
< |
|
363 |
> |
|
364 |
|
rcontrib(); /* trace ray contributions (loop) */ |
365 |
|
|
366 |
|
ambsync(); /* flush ambient file */ |
367 |
|
|
368 |
+ |
/* PMAP: free photon maps */ |
369 |
+ |
ray_done_pmap(); |
370 |
+ |
|
371 |
|
quit(0); /* exit clean */ |
372 |
|
|
373 |
|
badopt: |
374 |
|
fprintf(stderr, |
375 |
< |
"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv][-bn N] {-m mod | -M file} [rtrace options] octree\n", |
375 |
> |
"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", |
376 |
|
progname); |
377 |
|
sprintf(errmsg, "command line error at '%s'", argv[i]); |
378 |
|
error(USER, errmsg); |
379 |
|
return(1); /* pro forma return */ |
380 |
|
|
381 |
|
#undef check |
382 |
< |
#undef bool |
382 |
> |
#undef check_bool |
383 |
|
} |
384 |
|
|
385 |
|
|