| 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" |
| 19 |
– |
#include "paths.h" |
| 20 |
|
#include "pmapray.h" |
| 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 |
+ |
/* initialize calcomp routines */ |
| 118 |
+ |
initfunc(); |
| 119 |
|
/* add trace notify function */ |
| 120 |
|
for (i = 0; addobjnotify[i] != NULL; i++) |
| 121 |
|
; |
| 160 |
|
check(2,"i"); |
| 161 |
|
vresolu = atoi(argv[++i]); |
| 162 |
|
break; |
| 163 |
< |
case 'w': /* warnings */ |
| 163 |
> |
case 'w': /* warnings & spectral */ |
| 164 |
|
rval = erract[WARNING].pf != NULL; |
| 165 |
|
check_bool(2,rval); |
| 166 |
|
if (rval) erract[WARNING].pf = wputs; |
| 262 |
|
goto badopt; |
| 263 |
|
} |
| 264 |
|
break; |
| 265 |
+ |
case 'p': /* value output */ |
| 266 |
+ |
switch (argv[i][2]) { |
| 267 |
+ |
case 'R': /* standard RGB output */ |
| 268 |
+ |
if (strcmp(argv[i]+2, "RGB")) |
| 269 |
+ |
goto badopt; |
| 270 |
+ |
out_prims = stdprims; |
| 271 |
+ |
out_scalefactor = 1; |
| 272 |
+ |
sens_curve = NULL; |
| 273 |
+ |
break; |
| 274 |
+ |
case 'X': /* XYZ output */ |
| 275 |
+ |
if (strcmp(argv[i]+2, "XYZ")) |
| 276 |
+ |
goto badopt; |
| 277 |
+ |
out_prims = xyzprims; |
| 278 |
+ |
out_scalefactor = WHTEFFICACY; |
| 279 |
+ |
sens_curve = NULL; |
| 280 |
+ |
break; |
| 281 |
+ |
case 'c': { |
| 282 |
+ |
int j; |
| 283 |
+ |
check(3,"ffffffff"); |
| 284 |
+ |
rval = 0; |
| 285 |
+ |
for (j = 0; j < 8; j++) { |
| 286 |
+ |
our_prims[0][j] = atof(argv[++i]); |
| 287 |
+ |
rval |= fabs(our_prims[0][j]-stdprims[0][j]) > .001; |
| 288 |
+ |
} |
| 289 |
+ |
if (rval) { |
| 290 |
+ |
if (!colorprimsOK(our_prims)) |
| 291 |
+ |
error(USER, "illegal primary chromaticities"); |
| 292 |
+ |
out_prims = our_prims; |
| 293 |
+ |
} else |
| 294 |
+ |
out_prims = stdprims; |
| 295 |
+ |
out_scalefactor = 1; |
| 296 |
+ |
sens_curve = NULL; |
| 297 |
+ |
} break; |
| 298 |
+ |
case 'Y': /* photopic response */ |
| 299 |
+ |
if (argv[i][3]) |
| 300 |
+ |
goto badopt; |
| 301 |
+ |
sens_curve = scolor_photopic; |
| 302 |
+ |
out_scalefactor = WHTEFFICACY; |
| 303 |
+ |
break; |
| 304 |
+ |
case 'S': /* scotopic response */ |
| 305 |
+ |
if (argv[i][3]) |
| 306 |
+ |
goto badopt; |
| 307 |
+ |
sens_curve = scolor_scotopic; |
| 308 |
+ |
out_scalefactor = WHTSCOTOPIC; |
| 309 |
+ |
break; |
| 310 |
+ |
case 'M': /* melanopic response */ |
| 311 |
+ |
if (argv[i][3]) |
| 312 |
+ |
goto badopt; |
| 313 |
+ |
sens_curve = scolor_melanopic; |
| 314 |
+ |
out_scalefactor = WHTMELANOPIC; |
| 315 |
+ |
break; |
| 316 |
+ |
default: |
| 317 |
+ |
goto badopt; |
| 318 |
+ |
} |
| 319 |
+ |
break; |
| 320 |
+ |
#if MAXCSAMP>3 |
| 321 |
+ |
case 'c': /* output spectral results */ |
| 322 |
+ |
if (argv[i][2] != 'o') |
| 323 |
+ |
goto badopt; |
| 324 |
+ |
rval = (out_prims == NULL) & (sens_curve == NULL); |
| 325 |
+ |
check_bool(3,rval); |
| 326 |
+ |
if (rval) { |
| 327 |
+ |
out_prims = NULL; |
| 328 |
+ |
sens_curve = NULL; |
| 329 |
+ |
} else if (out_prims == NULL) |
| 330 |
+ |
out_prims = stdprims; |
| 331 |
+ |
break; |
| 332 |
+ |
#endif |
| 333 |
|
#ifdef PERSIST |
| 334 |
|
case 'P': /* persist file */ |
| 335 |
|
if (argv[i][2] == 'P') { |
| 346 |
|
goto badopt; |
| 347 |
|
} |
| 348 |
|
} |
| 349 |
< |
if (nproc > 1) { |
| 350 |
< |
if (persist) |
| 351 |
< |
error(USER, "multiprocessing incompatible with persist file"); |
| 352 |
< |
if (!vresolu && hresolu > 0 && hresolu < nproc) |
| 353 |
< |
error(WARNING, "number of cores should not exceed horizontal resolution"); |
| 354 |
< |
if (trace != NULL) |
| 355 |
< |
error(WARNING, "multiprocessing does not work properly with trace mode"); |
| 356 |
< |
} |
| 349 |
> |
/* set/check spectral sampling */ |
| 350 |
> |
rval = setspectrsamp(CNDX, WLPART); |
| 351 |
> |
if (rval < 0) |
| 352 |
> |
error(USER, "unsupported spectral sampling"); |
| 353 |
> |
if (sens_curve != NULL) |
| 354 |
> |
out_prims = NULL; |
| 355 |
> |
else if (out_prims != NULL) { |
| 356 |
> |
if (!rval) |
| 357 |
> |
error(WARNING, "spectral range incompatible with color output"); |
| 358 |
> |
} else if (NCSAMP == 3) |
| 359 |
> |
out_prims = stdprims; /* 3 samples do not a spectrum make */ |
| 360 |
> |
if (nproc > 1 && persist) |
| 361 |
> |
error(USER, "multiprocessing incompatible with persist file"); |
| 362 |
|
/* initialize object types */ |
| 363 |
|
initotypes(); |
| 364 |
|
/* initialize urand */ |
| 365 |
< |
if (rand_samp) { |
| 266 |
< |
srandom((long)time(0)); |
| 267 |
< |
initurand(0); |
| 268 |
< |
} else { |
| 269 |
< |
srandom(0L); |
| 270 |
< |
initurand(2048); |
| 271 |
< |
} |
| 365 |
> |
reset_random(); |
| 366 |
|
/* set up signal handling */ |
| 367 |
|
sigdie(SIGINT, "Interrupt"); |
| 368 |
|
#ifdef SIGHUP |
| 411 |
|
if (outform != 'a') |
| 412 |
|
SET_FILE_BINARY(stdout); |
| 413 |
|
rval = setrtoutput(); |
| 414 |
< |
readoct(octname = octnm, loadflags, &thescene, NULL); |
| 414 |
> |
octname = savqstr(octnm); |
| 415 |
> |
readoct(octname, loadflags, &thescene, NULL); |
| 416 |
|
nsceneobjs = nobjects; |
| 417 |
|
|
| 418 |
|
if (loadflags & IO_INFO) { /* print header */ |
| 420 |
|
printf("SOFTWARE= %s\n", VersionID); |
| 421 |
|
fputnow(stdout); |
| 422 |
|
if (rval > 0) /* saved from setrtoutput() call */ |
| 423 |
< |
printf("NCOMP=%d\n", rval); |
| 423 |
> |
fputncomp(rval, stdout); |
| 424 |
> |
if (NCSAMP > 3) |
| 425 |
> |
fputwlsplit(WLPART, stdout); |
| 426 |
> |
if ((out_prims != stdprims) & (out_prims != NULL)) |
| 427 |
> |
fputprims(out_prims, stdout); |
| 428 |
|
if ((outform == 'f') | (outform == 'd')) |
| 429 |
|
fputendian(stdout); |
| 430 |
|
fputformat(formstr(outform), stdout); |
| 431 |
< |
putchar('\n'); |
| 431 |
> |
fputc('\n', stdout); /* end of header */ |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
if (!castonly) { /* any actual ray traversal to do? */ |
| 438 |
|
marksources(); /* find and mark sources */ |
| 439 |
|
|
| 440 |
|
setambient(); /* initialize ambient calculation */ |
| 441 |
< |
} |
| 441 |
> |
} else |
| 442 |
> |
distantsources(); /* else mark only distant sources */ |
| 443 |
> |
|
| 444 |
> |
fflush(stdout); /* in case we're duplicating header */ |
| 445 |
> |
|
| 446 |
|
#ifdef PERSIST |
| 447 |
|
if (persist) { |
| 345 |
– |
fflush(stdout); |
| 448 |
|
/* reconnect stdout */ |
| 449 |
|
dup2(duped1, fileno(stdout)); |
| 450 |
|
close(duped1); |
| 451 |
|
if (persist == PARALLEL) { /* multiprocessing */ |
| 452 |
< |
preload_objs(); /* preload scene */ |
| 351 |
< |
shm_boundary = (char *)malloc(16); |
| 352 |
< |
strcpy(shm_boundary, "SHM_BOUNDARY"); |
| 452 |
> |
cow_memshare(); /* preloads scene */ |
| 453 |
|
while ((rval=fork()) == 0) { /* keep on forkin' */ |
| 454 |
|
pflock(1); |
| 455 |
|
pfhold(); |
| 502 |
|
|
| 503 |
|
void |
| 504 |
|
wputs( /* warning output function */ |
| 505 |
< |
char *s |
| 505 |
> |
const char *s |
| 506 |
|
) |
| 507 |
|
{ |
| 508 |
|
int lasterrno = errno; |
| 509 |
+ |
if (erract[WARNING].pf == NULL) |
| 510 |
+ |
return; /* called by calcomp or someone */ |
| 511 |
|
eputs(s); |
| 512 |
|
errno = lasterrno; |
| 513 |
|
} |
| 515 |
|
|
| 516 |
|
void |
| 517 |
|
eputs( /* put string to stderr */ |
| 518 |
< |
register char *s |
| 518 |
> |
const char *s |
| 519 |
|
) |
| 520 |
|
{ |
| 521 |
|
static int midline = 0; |
| 570 |
|
static void |
| 571 |
|
printdefaults(void) /* print default values to stdout */ |
| 572 |
|
{ |
| 573 |
< |
register char *cp; |
| 573 |
> |
char *cp; |
| 574 |
|
|
| 575 |
+ |
printf(erract[WARNING].pf != NULL ? |
| 576 |
+ |
"-w+\t\t\t\t# warning messages on\n" : |
| 577 |
+ |
"-w-\t\t\t\t# warning messages off\n"); |
| 578 |
|
if (imm_irrad) |
| 579 |
|
printf("-I+\t\t\t\t# immediate irradiance on\n"); |
| 580 |
|
printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); |
| 583 |
|
printf("-y %-9d\t\t\t# y resolution\n", vresolu); |
| 584 |
|
printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : |
| 585 |
|
"-ld-\t\t\t\t# limit distance off\n"); |
| 586 |
< |
printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', |
| 587 |
< |
loadflags & IO_INFO ? "output" : "no"); |
| 586 |
> |
printf(loadflags & IO_INFO ? "-h+\t\t\t\t# output header\n" : |
| 587 |
> |
"-h-\t\t\t\t# no header\n"); |
| 588 |
|
printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", |
| 589 |
|
inform, outform, formstr(inform), formstr(outform)); |
| 590 |
|
printf("-o%-9s\t\t\t# output", outvals); |
| 609 |
|
case 'W': printf(" coefficient"); break; |
| 610 |
|
case 'm': printf(" modifier"); break; |
| 611 |
|
case 'M': printf(" material"); break; |
| 612 |
< |
case '-': printf(" stroke"); break; |
| 612 |
> |
case '~': printf(" tilde"); break; |
| 613 |
|
} |
| 614 |
< |
putchar('\n'); |
| 615 |
< |
printf(erract[WARNING].pf != NULL ? |
| 616 |
< |
"-w+\t\t\t\t# warning messages on\n" : |
| 617 |
< |
"-w-\t\t\t\t# warning messages off\n"); |
| 614 |
> |
fputc('\n', stdout); |
| 615 |
> |
if (sens_curve == scolor_photopic) |
| 616 |
> |
printf("-pY\t\t\t\t# photopic output\n"); |
| 617 |
> |
else if (sens_curve == scolor_scotopic) |
| 618 |
> |
printf("-pS\t\t\t\t# scotopic output\n"); |
| 619 |
> |
else if (sens_curve == scolor_melanopic) |
| 620 |
> |
printf("-pM\t\t\t\t# melanopic output\n"); |
| 621 |
> |
else if (out_prims == stdprims) |
| 622 |
> |
printf("-pRGB\t\t\t\t# standard RGB color output\n"); |
| 623 |
> |
else if (out_prims == xyzprims) |
| 624 |
> |
printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); |
| 625 |
> |
else if (out_prims != NULL) |
| 626 |
> |
printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", |
| 627 |
> |
out_prims[RED][0], out_prims[RED][1], |
| 628 |
> |
out_prims[GRN][0], out_prims[GRN][1], |
| 629 |
> |
out_prims[BLU][0], out_prims[BLU][1], |
| 630 |
> |
out_prims[WHT][0], out_prims[WHT][1]); |
| 631 |
> |
if ((sens_curve == NULL) & (NCSAMP > 3)) |
| 632 |
> |
printf(out_prims != NULL ? "-co-\t\t\t\t# output tristimulus colors\n" : |
| 633 |
> |
"-co+\t\t\t\t# output spectral values\n"); |
| 634 |
|
print_rdefaults(); |
| 635 |
|
} |