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