21 |
|
|
22 |
|
extern char *progname; /* global argv[0] */ |
23 |
|
|
24 |
– |
extern char *shm_boundary; /* boundary of shared memory */ |
25 |
– |
|
24 |
|
/* persistent processes define */ |
25 |
|
#ifdef F_SETLKW |
26 |
|
#define PERSIST 1 /* normal persist */ |
33 |
|
|
34 |
|
int nproc = 1; /* number of processes */ |
35 |
|
|
38 |
– |
extern char *formstr(int f); /* string from format */ |
36 |
|
extern int setrtoutput(void); /* set output values */ |
37 |
|
|
38 |
|
int inform = 'a'; /* input format */ |
42 |
|
int hresolu = 0; /* horizontal (scan) size */ |
43 |
|
int vresolu = 0; /* vertical resolution */ |
44 |
|
|
45 |
< |
int castonly = 0; /* only doing ray-casting? */ |
45 |
> |
extern int castonly; /* only doing ray-casting? */ |
46 |
|
|
47 |
|
int imm_irrad = 0; /* compute immediate irradiance? */ |
48 |
|
int lim_dist = 0; /* limit distance? */ |
57 |
|
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
58 |
|
int traincl = -1; /* include == 1, exclude == 0 */ |
59 |
|
|
60 |
+ |
double (*sens_curve)(const SCOLOR scol) = NULL; /* spectral conversion for 1-channel */ |
61 |
+ |
double out_scalefactor = 1; /* output calibration scale factor */ |
62 |
+ |
RGBPRIMP out_prims = stdprims; /* output color primitives (NULL if spectral) */ |
63 |
+ |
static RGBPRIMS our_prims; /* private output color primitives */ |
64 |
+ |
|
65 |
|
static int loadflags = ~IO_FILES; /* what to load from octree */ |
66 |
|
|
67 |
|
static void onsig(int signo); |
68 |
|
static void sigdie(int signo, char *msg); |
69 |
|
static void printdefaults(void); |
70 |
|
|
71 |
+ |
#ifdef PERSIST |
72 |
+ |
#define RTRACE_FEATURES "Persist\nParallelPersist\nMultiprocessing\n" \ |
73 |
+ |
"IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \ |
74 |
+ |
"ParticipatingMedia=Mist\n" \ |
75 |
+ |
"HessianAmbientCache\nAmbientAveraging\n" \ |
76 |
+ |
"AmbientValueSharing\nAdaptiveShadowTesting\n" \ |
77 |
+ |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
78 |
+ |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \ |
79 |
+ |
"OutputCS=RGB,XYZ,Y,S,M,prims,spec\n" |
80 |
+ |
#else |
81 |
+ |
#define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \ |
82 |
+ |
"ParticipatingMedia=Mist\n" \ |
83 |
+ |
"HessianAmbientCache\nAmbientAveraging\n" \ |
84 |
+ |
"AmbientValueSharing\nAdaptiveShadowTesting\n" \ |
85 |
+ |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
86 |
+ |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \ |
87 |
+ |
"OutputCS=RGB,XYZ,Y,S,M,prims,spec\n" |
88 |
+ |
#endif |
89 |
|
|
90 |
+ |
|
91 |
|
int |
92 |
|
main(int argc, char *argv[]) |
93 |
|
{ |
110 |
|
int i; |
111 |
|
/* global program name */ |
112 |
|
progname = argv[0] = fixargv0(argv[0]); |
113 |
+ |
/* feature check only? */ |
114 |
+ |
strcat(RFeatureList, RTRACE_FEATURES); |
115 |
+ |
if (argc > 1 && !strcmp(argv[1], "-features")) |
116 |
+ |
return feature_status(argc-2, argv+2); |
117 |
|
/* add trace notify function */ |
118 |
|
for (i = 0; addobjnotify[i] != NULL; i++) |
119 |
|
; |
158 |
|
check(2,"i"); |
159 |
|
vresolu = atoi(argv[++i]); |
160 |
|
break; |
161 |
< |
case 'w': /* warnings */ |
161 |
> |
case 'w': /* warnings & spectral */ |
162 |
|
rval = erract[WARNING].pf != NULL; |
163 |
|
check_bool(2,rval); |
164 |
|
if (rval) erract[WARNING].pf = wputs; |
260 |
|
goto badopt; |
261 |
|
} |
262 |
|
break; |
263 |
+ |
case 'p': /* value output */ |
264 |
+ |
switch (argv[i][2]) { |
265 |
+ |
case 'R': /* standard RGB output */ |
266 |
+ |
if (strcmp(argv[i]+2, "RGB")) |
267 |
+ |
goto badopt; |
268 |
+ |
out_prims = stdprims; |
269 |
+ |
out_scalefactor = 1; |
270 |
+ |
sens_curve = NULL; |
271 |
+ |
break; |
272 |
+ |
case 'X': /* XYZ output */ |
273 |
+ |
if (strcmp(argv[i]+2, "XYZ")) |
274 |
+ |
goto badopt; |
275 |
+ |
out_prims = xyzprims; |
276 |
+ |
out_scalefactor = WHTEFFICACY; |
277 |
+ |
sens_curve = NULL; |
278 |
+ |
break; |
279 |
+ |
case 'c': { |
280 |
+ |
int j; |
281 |
+ |
check(3,"ffffffff"); |
282 |
+ |
rval = 0; |
283 |
+ |
for (j = 0; j < 8; j++) { |
284 |
+ |
our_prims[0][j] = atof(argv[++i]); |
285 |
+ |
rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001; |
286 |
+ |
} |
287 |
+ |
if (rval) { |
288 |
+ |
if (!colorprimsOK(our_prims)) |
289 |
+ |
error(USER, "illegal primary chromaticities"); |
290 |
+ |
out_prims = our_prims; |
291 |
+ |
} else |
292 |
+ |
out_prims = stdprims; |
293 |
+ |
out_scalefactor = 1; |
294 |
+ |
sens_curve = NULL; |
295 |
+ |
} break; |
296 |
+ |
case 'Y': /* photopic response */ |
297 |
+ |
if (argv[i][3]) |
298 |
+ |
goto badopt; |
299 |
+ |
sens_curve = scolor_photopic; |
300 |
+ |
out_scalefactor = WHTEFFICACY; |
301 |
+ |
break; |
302 |
+ |
case 'S': /* scotopic response */ |
303 |
+ |
if (argv[i][3]) |
304 |
+ |
goto badopt; |
305 |
+ |
sens_curve = scolor_scotopic; |
306 |
+ |
out_scalefactor = WHTSCOTOPIC; |
307 |
+ |
break; |
308 |
+ |
case 'M': /* melanopic response */ |
309 |
+ |
if (argv[i][3]) |
310 |
+ |
goto badopt; |
311 |
+ |
sens_curve = scolor_melanopic; |
312 |
+ |
out_scalefactor = WHTMELANOPIC; |
313 |
+ |
break; |
314 |
+ |
default: |
315 |
+ |
goto badopt; |
316 |
+ |
} |
317 |
+ |
break; |
318 |
+ |
#if MAXCSAMP>3 |
319 |
+ |
case 'c': /* output spectral results */ |
320 |
+ |
if (argv[i][2] != 'o') |
321 |
+ |
goto badopt; |
322 |
+ |
rval = (out_prims == NULL) & (sens_curve == NULL); |
323 |
+ |
check_bool(3,rval); |
324 |
+ |
if (rval) { |
325 |
+ |
out_prims = NULL; |
326 |
+ |
sens_curve = NULL; |
327 |
+ |
} else if (out_prims == NULL) |
328 |
+ |
out_prims = stdprims; |
329 |
+ |
break; |
330 |
+ |
#endif |
331 |
|
#ifdef PERSIST |
332 |
|
case 'P': /* persist file */ |
333 |
|
if (argv[i][2] == 'P') { |
344 |
|
goto badopt; |
345 |
|
} |
346 |
|
} |
347 |
< |
if (nproc > 1) { |
348 |
< |
if (persist) |
349 |
< |
error(USER, "multiprocessing incompatible with persist file"); |
350 |
< |
if (!vresolu && hresolu > 0 && hresolu < nproc) |
351 |
< |
error(WARNING, "number of cores should not exceed horizontal resolution"); |
352 |
< |
if (trace != NULL) |
353 |
< |
error(WARNING, "multiprocessing does not work properly with trace mode"); |
354 |
< |
} |
347 |
> |
/* set/check spectral sampling */ |
348 |
> |
rval = setspectrsamp(CNDX, WLPART); |
349 |
> |
if (rval < 0) |
350 |
> |
error(USER, "unsupported spectral sampling"); |
351 |
> |
if (out_prims != NULL) { |
352 |
> |
if (!rval) |
353 |
> |
error(WARNING, "spectral range incompatible with color output"); |
354 |
> |
} else if (NCSAMP == 3) |
355 |
> |
out_prims = stdprims; /* 3 samples do not a spectrum make */ |
356 |
> |
if (nproc > 1 && persist) |
357 |
> |
error(USER, "multiprocessing incompatible with persist file"); |
358 |
|
/* initialize object types */ |
359 |
|
initotypes(); |
360 |
|
/* initialize urand */ |
413 |
|
if (outform != 'a') |
414 |
|
SET_FILE_BINARY(stdout); |
415 |
|
rval = setrtoutput(); |
416 |
< |
readoct(octname = octnm, loadflags, &thescene, NULL); |
416 |
> |
octname = savqstr(octnm); |
417 |
> |
readoct(octname, loadflags, &thescene, NULL); |
418 |
|
nsceneobjs = nobjects; |
419 |
|
|
420 |
|
if (loadflags & IO_INFO) { /* print header */ |
422 |
|
printf("SOFTWARE= %s\n", VersionID); |
423 |
|
fputnow(stdout); |
424 |
|
if (rval > 0) /* saved from setrtoutput() call */ |
425 |
< |
printf("NCOMP=%d\n", rval); |
425 |
> |
fputncomp(rval, stdout); |
426 |
> |
if (NCSAMP > 3) |
427 |
> |
fputwlsplit(WLPART, stdout); |
428 |
> |
if ((out_prims != stdprims) & (out_prims != NULL)) |
429 |
> |
fputprims(out_prims, stdout); |
430 |
|
if ((outform == 'f') | (outform == 'd')) |
431 |
|
fputendian(stdout); |
432 |
|
fputformat(formstr(outform), stdout); |
433 |
< |
putchar('\n'); |
433 |
> |
fputc('\n', stdout); /* end of header */ |
434 |
|
} |
435 |
|
|
436 |
|
if (!castonly) { /* any actual ray traversal to do? */ |
440 |
|
marksources(); /* find and mark sources */ |
441 |
|
|
442 |
|
setambient(); /* initialize ambient calculation */ |
443 |
< |
} |
443 |
> |
} else |
444 |
> |
distantsources(); /* else mark only distant sources */ |
445 |
> |
|
446 |
> |
fflush(stdout); /* in case we're duplicating header */ |
447 |
> |
|
448 |
|
#ifdef PERSIST |
449 |
|
if (persist) { |
345 |
– |
fflush(stdout); |
450 |
|
/* reconnect stdout */ |
451 |
|
dup2(duped1, fileno(stdout)); |
452 |
|
close(duped1); |
453 |
|
if (persist == PARALLEL) { /* multiprocessing */ |
454 |
< |
preload_objs(); /* preload scene */ |
351 |
< |
shm_boundary = (char *)malloc(16); |
352 |
< |
strcpy(shm_boundary, "SHM_BOUNDARY"); |
454 |
> |
cow_memshare(); /* preloads scene */ |
455 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
456 |
|
pflock(1); |
457 |
|
pfhold(); |
504 |
|
|
505 |
|
void |
506 |
|
wputs( /* warning output function */ |
507 |
< |
char *s |
507 |
> |
const char *s |
508 |
|
) |
509 |
|
{ |
510 |
|
int lasterrno = errno; |
511 |
+ |
if (erract[WARNING].pf == NULL) |
512 |
+ |
return; /* called by calcomp or someone */ |
513 |
|
eputs(s); |
514 |
|
errno = lasterrno; |
515 |
|
} |
517 |
|
|
518 |
|
void |
519 |
|
eputs( /* put string to stderr */ |
520 |
< |
register char *s |
520 |
> |
const char *s |
521 |
|
) |
522 |
|
{ |
523 |
|
static int midline = 0; |
572 |
|
static void |
573 |
|
printdefaults(void) /* print default values to stdout */ |
574 |
|
{ |
575 |
< |
register char *cp; |
575 |
> |
char *cp; |
576 |
|
|
577 |
+ |
printf(erract[WARNING].pf != NULL ? |
578 |
+ |
"-w+\t\t\t\t# warning messages on\n" : |
579 |
+ |
"-w-\t\t\t\t# warning messages off\n"); |
580 |
|
if (imm_irrad) |
581 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
582 |
|
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
585 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
586 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
587 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
588 |
< |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
589 |
< |
loadflags & IO_INFO ? "output" : "no"); |
588 |
> |
printf(loadflags & IO_INFO ? "-h+\t\t\t\t# output header\n" : |
589 |
> |
"-h-\t\t\t\t# no header\n"); |
590 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
591 |
|
inform, outform, formstr(inform), formstr(outform)); |
592 |
|
printf("-o%-9s\t\t\t# output", outvals); |
611 |
|
case 'W': printf(" coefficient"); break; |
612 |
|
case 'm': printf(" modifier"); break; |
613 |
|
case 'M': printf(" material"); break; |
614 |
< |
case '-': printf(" stroke"); break; |
614 |
> |
case '~': printf(" tilde"); break; |
615 |
|
} |
616 |
< |
putchar('\n'); |
617 |
< |
printf(erract[WARNING].pf != NULL ? |
618 |
< |
"-w+\t\t\t\t# warning messages on\n" : |
619 |
< |
"-w-\t\t\t\t# warning messages off\n"); |
616 |
> |
fputc('\n', stdout); |
617 |
> |
if (sens_curve == scolor_photopic) |
618 |
> |
printf("-pY\t\t\t\t# photopic output\n"); |
619 |
> |
else if (sens_curve == scolor_scotopic) |
620 |
> |
printf("-pS\t\t\t\t# scotopic output\n"); |
621 |
> |
else if (sens_curve == scolor_melanopic) |
622 |
> |
printf("-pM\t\t\t\t# melanopic output\n"); |
623 |
> |
else if (out_prims == stdprims) |
624 |
> |
printf("-pRGB\t\t\t\t# standard RGB color output\n"); |
625 |
> |
else if (out_prims == xyzprims) |
626 |
> |
printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); |
627 |
> |
else if (out_prims != NULL) |
628 |
> |
printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", |
629 |
> |
out_prims[RED][0], out_prims[RED][1], |
630 |
> |
out_prims[GRN][0], out_prims[GRN][1], |
631 |
> |
out_prims[BLU][0], out_prims[BLU][1], |
632 |
> |
out_prims[WHT][0], out_prims[WHT][1]); |
633 |
> |
if ((sens_curve == NULL) & (NCSAMP > 3)) |
634 |
> |
printf(out_prims != NULL ? "-co-\t\t\t\t# output tristimulus colors\n" : |
635 |
> |
"-co+\t\t\t\t# output spectral values\n"); |
636 |
|
print_rdefaults(); |
637 |
|
} |