13 |
|
#include "rtprocess.h" /* getpid() */ |
14 |
|
#include "resolu.h" |
15 |
|
#include "ray.h" |
16 |
+ |
#include "func.h" |
17 |
|
#include "source.h" |
18 |
|
#include "ambient.h" |
19 |
|
#include "random.h" |
22 |
|
|
23 |
|
extern char *progname; /* global argv[0] */ |
24 |
|
|
24 |
– |
extern char *shm_boundary; /* boundary of shared memory */ |
25 |
– |
|
25 |
|
/* persistent processes define */ |
26 |
|
#ifdef F_SETLKW |
27 |
|
#define PERSIST 1 /* normal persist */ |
34 |
|
|
35 |
|
int nproc = 1; /* number of processes */ |
36 |
|
|
38 |
– |
extern char *formstr(int f); /* string from format */ |
37 |
|
extern int setrtoutput(void); /* set output values */ |
38 |
|
|
39 |
|
int inform = 'a'; /* input format */ |
58 |
|
char *tralist[MAXMODLIST]; /* list of modifers to trace (or no) */ |
59 |
|
int traincl = -1; /* include == 1, exclude == 0 */ |
60 |
|
|
61 |
+ |
double (*sens_curve)(const SCOLOR scol) = NULL; /* spectral conversion for 1-channel */ |
62 |
+ |
double out_scalefactor = 1; /* output calibration scale factor */ |
63 |
+ |
RGBPRIMP out_prims = stdprims; /* output color primitives (NULL if spectral) */ |
64 |
+ |
static RGBPRIMS our_prims; /* private output color primitives */ |
65 |
+ |
|
66 |
|
static int loadflags = ~IO_FILES; /* what to load from octree */ |
67 |
|
|
68 |
|
static void onsig(int signo); |
70 |
|
static void printdefaults(void); |
71 |
|
|
72 |
|
#ifdef PERSIST |
73 |
< |
#define RTRACE_FEATURES "Persist\nParallelPersist\nMultiProcessing\n" \ |
73 |
> |
#define RTRACE_FEATURES "Persist\nParallelPersist\nMultiprocessing\n" \ |
74 |
|
"IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \ |
75 |
+ |
"ParticipatingMedia=Mist\n" \ |
76 |
|
"HessianAmbientCache\nAmbientAveraging\n" \ |
77 |
|
"AmbientValueSharing\nAdaptiveShadowTesting\n" \ |
78 |
< |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" |
78 |
> |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
79 |
> |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \ |
80 |
> |
"OutputCS=RGB,XYZ,Y,S,M,prims,spec\n" |
81 |
|
#else |
82 |
|
#define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \ |
83 |
+ |
"ParticipatingMedia=Mist\n" \ |
84 |
|
"HessianAmbientCache\nAmbientAveraging\n" \ |
85 |
|
"AmbientValueSharing\nAdaptiveShadowTesting\n" \ |
86 |
< |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" |
86 |
> |
"InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ |
87 |
> |
"Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" \ |
88 |
> |
"OutputCS=RGB,XYZ,Y,S,M,prims,spec\n" |
89 |
|
#endif |
90 |
|
|
91 |
|
|
113 |
|
progname = argv[0] = fixargv0(argv[0]); |
114 |
|
/* feature check only? */ |
115 |
|
strcat(RFeatureList, RTRACE_FEATURES); |
116 |
< |
if (!strcmp(argv[1], "-features")) |
116 |
> |
if (argc > 1 && !strcmp(argv[1], "-features")) |
117 |
|
return feature_status(argc-2, argv+2); |
118 |
+ |
/* initialize calcomp routines */ |
119 |
+ |
initfunc(); |
120 |
|
/* add trace notify function */ |
121 |
|
for (i = 0; addobjnotify[i] != NULL; i++) |
122 |
|
; |
161 |
|
check(2,"i"); |
162 |
|
vresolu = atoi(argv[++i]); |
163 |
|
break; |
164 |
< |
case 'w': /* warnings */ |
164 |
> |
case 'w': /* warnings & spectral */ |
165 |
|
rval = erract[WARNING].pf != NULL; |
166 |
|
check_bool(2,rval); |
167 |
|
if (rval) erract[WARNING].pf = wputs; |
263 |
|
goto badopt; |
264 |
|
} |
265 |
|
break; |
266 |
+ |
case 'p': /* value output */ |
267 |
+ |
switch (argv[i][2]) { |
268 |
+ |
case 'R': /* standard RGB output */ |
269 |
+ |
if (strcmp(argv[i]+2, "RGB")) |
270 |
+ |
goto badopt; |
271 |
+ |
out_prims = stdprims; |
272 |
+ |
out_scalefactor = 1; |
273 |
+ |
sens_curve = NULL; |
274 |
+ |
break; |
275 |
+ |
case 'X': /* XYZ output */ |
276 |
+ |
if (strcmp(argv[i]+2, "XYZ")) |
277 |
+ |
goto badopt; |
278 |
+ |
out_prims = xyzprims; |
279 |
+ |
out_scalefactor = WHTEFFICACY; |
280 |
+ |
sens_curve = NULL; |
281 |
+ |
break; |
282 |
+ |
case 'c': { |
283 |
+ |
int j; |
284 |
+ |
check(3,"ffffffff"); |
285 |
+ |
rval = 0; |
286 |
+ |
for (j = 0; j < 8; j++) { |
287 |
+ |
our_prims[0][j] = atof(argv[++i]); |
288 |
+ |
rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001; |
289 |
+ |
} |
290 |
+ |
if (rval) { |
291 |
+ |
if (!colorprimsOK(our_prims)) |
292 |
+ |
error(USER, "illegal primary chromaticities"); |
293 |
+ |
out_prims = our_prims; |
294 |
+ |
} else |
295 |
+ |
out_prims = stdprims; |
296 |
+ |
out_scalefactor = 1; |
297 |
+ |
sens_curve = NULL; |
298 |
+ |
} break; |
299 |
+ |
case 'Y': /* photopic response */ |
300 |
+ |
if (argv[i][3]) |
301 |
+ |
goto badopt; |
302 |
+ |
sens_curve = scolor_photopic; |
303 |
+ |
out_scalefactor = WHTEFFICACY; |
304 |
+ |
break; |
305 |
+ |
case 'S': /* scotopic response */ |
306 |
+ |
if (argv[i][3]) |
307 |
+ |
goto badopt; |
308 |
+ |
sens_curve = scolor_scotopic; |
309 |
+ |
out_scalefactor = WHTSCOTOPIC; |
310 |
+ |
break; |
311 |
+ |
case 'M': /* melanopic response */ |
312 |
+ |
if (argv[i][3]) |
313 |
+ |
goto badopt; |
314 |
+ |
sens_curve = scolor_melanopic; |
315 |
+ |
out_scalefactor = WHTMELANOPIC; |
316 |
+ |
break; |
317 |
+ |
default: |
318 |
+ |
goto badopt; |
319 |
+ |
} |
320 |
+ |
break; |
321 |
+ |
#if MAXCSAMP>3 |
322 |
+ |
case 'c': /* output spectral results */ |
323 |
+ |
if (argv[i][2] != 'o') |
324 |
+ |
goto badopt; |
325 |
+ |
rval = (out_prims == NULL) & (sens_curve == NULL); |
326 |
+ |
check_bool(3,rval); |
327 |
+ |
if (rval) { |
328 |
+ |
out_prims = NULL; |
329 |
+ |
sens_curve = NULL; |
330 |
+ |
} else if (out_prims == NULL) |
331 |
+ |
out_prims = stdprims; |
332 |
+ |
break; |
333 |
+ |
#endif |
334 |
|
#ifdef PERSIST |
335 |
|
case 'P': /* persist file */ |
336 |
|
if (argv[i][2] == 'P') { |
347 |
|
goto badopt; |
348 |
|
} |
349 |
|
} |
350 |
+ |
/* set/check spectral sampling */ |
351 |
+ |
rval = setspectrsamp(CNDX, WLPART); |
352 |
+ |
if (rval < 0) |
353 |
+ |
error(USER, "unsupported spectral sampling"); |
354 |
+ |
if (sens_curve != NULL) |
355 |
+ |
out_prims = NULL; |
356 |
+ |
else if (out_prims != NULL) { |
357 |
+ |
if (!rval) |
358 |
+ |
error(WARNING, "spectral range incompatible with color output"); |
359 |
+ |
} else if (NCSAMP == 3) |
360 |
+ |
out_prims = stdprims; /* 3 samples do not a spectrum make */ |
361 |
|
if (nproc > 1 && persist) |
362 |
|
error(USER, "multiprocessing incompatible with persist file"); |
363 |
|
/* initialize object types */ |
427 |
|
printf("SOFTWARE= %s\n", VersionID); |
428 |
|
fputnow(stdout); |
429 |
|
if (rval > 0) /* saved from setrtoutput() call */ |
430 |
< |
printf("NCOMP=%d\n", rval); |
430 |
> |
fputncomp(rval, stdout); |
431 |
> |
if (NCSAMP > 3) |
432 |
> |
fputwlsplit(WLPART, stdout); |
433 |
> |
if ((out_prims != stdprims) & (out_prims != NULL)) |
434 |
> |
fputprims(out_prims, stdout); |
435 |
|
if ((outform == 'f') | (outform == 'd')) |
436 |
|
fputendian(stdout); |
437 |
|
fputformat(formstr(outform), stdout); |
438 |
< |
putchar('\n'); |
438 |
> |
fputc('\n', stdout); /* end of header */ |
439 |
|
} |
440 |
|
|
441 |
|
if (!castonly) { /* any actual ray traversal to do? */ |
456 |
|
dup2(duped1, fileno(stdout)); |
457 |
|
close(duped1); |
458 |
|
if (persist == PARALLEL) { /* multiprocessing */ |
459 |
< |
preload_objs(); /* preload scene */ |
366 |
< |
shm_boundary = (char *)malloc(16); |
367 |
< |
strcpy(shm_boundary, "SHM_BOUNDARY"); |
459 |
> |
cow_memshare(); /* preloads scene */ |
460 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
461 |
|
pflock(1); |
462 |
|
pfhold(); |
509 |
|
|
510 |
|
void |
511 |
|
wputs( /* warning output function */ |
512 |
< |
char *s |
512 |
> |
const char *s |
513 |
|
) |
514 |
|
{ |
515 |
|
int lasterrno = errno; |
516 |
+ |
if (erract[WARNING].pf == NULL) |
517 |
+ |
return; /* called by calcomp or someone */ |
518 |
|
eputs(s); |
519 |
|
errno = lasterrno; |
520 |
|
} |
522 |
|
|
523 |
|
void |
524 |
|
eputs( /* put string to stderr */ |
525 |
< |
char *s |
525 |
> |
const char *s |
526 |
|
) |
527 |
|
{ |
528 |
|
static int midline = 0; |
579 |
|
{ |
580 |
|
char *cp; |
581 |
|
|
582 |
+ |
printf(erract[WARNING].pf != NULL ? |
583 |
+ |
"-w+\t\t\t\t# warning messages on\n" : |
584 |
+ |
"-w-\t\t\t\t# warning messages off\n"); |
585 |
|
if (imm_irrad) |
586 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
587 |
|
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
590 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
591 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
592 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
593 |
< |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
594 |
< |
loadflags & IO_INFO ? "output" : "no"); |
593 |
> |
printf(loadflags & IO_INFO ? "-h+\t\t\t\t# output header\n" : |
594 |
> |
"-h-\t\t\t\t# no header\n"); |
595 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
596 |
|
inform, outform, formstr(inform), formstr(outform)); |
597 |
|
printf("-o%-9s\t\t\t# output", outvals); |
618 |
|
case 'M': printf(" material"); break; |
619 |
|
case '~': printf(" tilde"); break; |
620 |
|
} |
621 |
< |
putchar('\n'); |
622 |
< |
printf(erract[WARNING].pf != NULL ? |
623 |
< |
"-w+\t\t\t\t# warning messages on\n" : |
624 |
< |
"-w-\t\t\t\t# warning messages off\n"); |
621 |
> |
fputc('\n', stdout); |
622 |
> |
if (sens_curve == scolor_photopic) |
623 |
> |
printf("-pY\t\t\t\t# photopic output\n"); |
624 |
> |
else if (sens_curve == scolor_scotopic) |
625 |
> |
printf("-pS\t\t\t\t# scotopic output\n"); |
626 |
> |
else if (sens_curve == scolor_melanopic) |
627 |
> |
printf("-pM\t\t\t\t# melanopic output\n"); |
628 |
> |
else if (out_prims == stdprims) |
629 |
> |
printf("-pRGB\t\t\t\t# standard RGB color output\n"); |
630 |
> |
else if (out_prims == xyzprims) |
631 |
> |
printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); |
632 |
> |
else if (out_prims != NULL) |
633 |
> |
printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", |
634 |
> |
out_prims[RED][0], out_prims[RED][1], |
635 |
> |
out_prims[GRN][0], out_prims[GRN][1], |
636 |
> |
out_prims[BLU][0], out_prims[BLU][1], |
637 |
> |
out_prims[WHT][0], out_prims[WHT][1]); |
638 |
> |
if ((sens_curve == NULL) & (NCSAMP > 3)) |
639 |
> |
printf(out_prims != NULL ? "-co-\t\t\t\t# output tristimulus colors\n" : |
640 |
> |
"-co+\t\t\t\t# output spectral values\n"); |
641 |
|
print_rdefaults(); |
642 |
|
} |