| 35 | 
  | 
 | 
| 36 | 
  | 
int  nproc = 1;                         /* number of processes */ | 
| 37 | 
  | 
 | 
| 38 | 
– | 
extern char  *formstr(int f);           /* string from format */ | 
| 38 | 
  | 
extern int  setrtoutput(void);          /* set output values */ | 
| 39 | 
  | 
 | 
| 40 | 
  | 
int  inform = 'a';                      /* input format */ | 
| 44 | 
  | 
int  hresolu = 0;                       /* horizontal (scan) size */ | 
| 45 | 
  | 
int  vresolu = 0;                       /* vertical resolution */ | 
| 46 | 
  | 
 | 
| 47 | 
< | 
int  castonly = 0;                      /* only doing ray-casting? */ | 
| 47 | 
> | 
extern int  castonly;                   /* only doing ray-casting? */ | 
| 48 | 
  | 
 | 
| 49 | 
  | 
int  imm_irrad = 0;                     /* compute immediate irradiance? */ | 
| 50 | 
  | 
int  lim_dist = 0;                      /* limit distance? */ | 
| 59 | 
  | 
char  *tralist[MAXMODLIST];             /* list of modifers to trace (or no) */ | 
| 60 | 
  | 
int  traincl = -1;                      /* include == 1, exclude == 0 */ | 
| 61 | 
  | 
 | 
| 62 | 
+ | 
double  (*sens_curve)(SCOLOR scol) = NULL;      /* spectral conversion for 1-channel */ | 
| 63 | 
+ | 
double  out_scalefactor = 1;            /* output calibration scale factor */ | 
| 64 | 
+ | 
RGBPRIMP  out_prims = stdprims;         /* output color primitives (NULL if spectral) */ | 
| 65 | 
+ | 
static RGBPRIMS  our_prims;             /* private output color primitives */ | 
| 66 | 
+ | 
 | 
| 67 | 
  | 
static int  loadflags = ~IO_FILES;      /* what to load from octree */ | 
| 68 | 
  | 
 | 
| 69 | 
  | 
static void onsig(int  signo); | 
| 70 | 
  | 
static void sigdie(int  signo, char  *msg); | 
| 71 | 
  | 
static void printdefaults(void); | 
| 72 | 
  | 
 | 
| 73 | 
+ | 
#ifdef PERSIST | 
| 74 | 
+ | 
#define RTRACE_FEATURES "Persist\nParallelPersist\nMultiprocessing\n" \ | 
| 75 | 
+ | 
                        "IrradianceCalc\nImmediateIrradiance\nDistanceLimiting\n" \ | 
| 76 | 
+ | 
                        "ParticipatingMedia=Mist\n" \ | 
| 77 | 
+ | 
                        "HessianAmbientCache\nAmbientAveraging\n" \ | 
| 78 | 
+ | 
                        "AmbientValueSharing\nAdaptiveShadowTesting\n" \ | 
| 79 | 
+ | 
                        "InputFormats=a,f,d\nOutputFormats=a,f,d,c\n" \ | 
| 80 | 
+ | 
                        "Outputs=o,d,v,V,w,W,l,L,c,p,n,N,s,m,M,r,x,R,X,~\n" | 
| 81 | 
+ | 
#else | 
| 82 | 
+ | 
#define RTRACE_FEATURES "IrradianceCalc\nIrradianceCalc\nDistanceLimiting\n" \ | 
| 83 | 
+ | 
                        "ParticipatingMedia=Mist\n" \ | 
| 84 | 
+ | 
                        "HessianAmbientCache\nAmbientAveraging\n" \ | 
| 85 | 
+ | 
                        "AmbientValueSharing\nAdaptiveShadowTesting\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 | 
+ | 
#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 | 
+ | 
                                sens_curve = scolor_photopic; | 
| 298 | 
+ | 
                                out_scalefactor = WHTEFFICACY; | 
| 299 | 
+ | 
                                break; | 
| 300 | 
+ | 
                        case 'S':                       /* scotopic response */ | 
| 301 | 
+ | 
                                sens_curve = scolor_scotopic; | 
| 302 | 
+ | 
                                out_scalefactor = WHTSCOTOPIC; | 
| 303 | 
+ | 
                                break; | 
| 304 | 
+ | 
                        case 'M':                       /* melanopic response */ | 
| 305 | 
+ | 
                                sens_curve = scolor_melanopic; | 
| 306 | 
+ | 
                                out_scalefactor = WHTMELANOPIC; | 
| 307 | 
+ | 
                                break; | 
| 308 | 
+ | 
                        default: | 
| 309 | 
+ | 
                                goto badopt; | 
| 310 | 
+ | 
                        } | 
| 311 | 
+ | 
                        break; | 
| 312 | 
+ | 
#if MAXCSAMP>3 | 
| 313 | 
+ | 
                case 'c':                               /* output spectral results */ | 
| 314 | 
+ | 
                        if (argv[i][2] != 'o') | 
| 315 | 
+ | 
                                goto badopt; | 
| 316 | 
+ | 
                        rval = (out_prims == NULL) & (sens_curve == NULL); | 
| 317 | 
+ | 
                        check_bool(3,rval); | 
| 318 | 
+ | 
                        if (rval) { | 
| 319 | 
+ | 
                                out_prims = NULL; | 
| 320 | 
+ | 
                                sens_curve = NULL; | 
| 321 | 
+ | 
                        } else if (out_prims == NULL) | 
| 322 | 
+ | 
                                out_prims = stdprims; | 
| 323 | 
+ | 
                        break; | 
| 324 | 
+ | 
#endif | 
| 325 | 
  | 
#ifdef  PERSIST | 
| 326 | 
  | 
                case 'P':                               /* persist file */ | 
| 327 | 
  | 
                        if (argv[i][2] == 'P') { | 
| 338 | 
  | 
                        goto badopt; | 
| 339 | 
  | 
                } | 
| 340 | 
  | 
        } | 
| 341 | 
< | 
        if (nproc > 1) { | 
| 342 | 
< | 
                if (persist) | 
| 343 | 
< | 
                        error(USER, "multiprocessing incompatible with persist file"); | 
| 344 | 
< | 
                if (!vresolu && hresolu > 0 && hresolu < nproc) | 
| 345 | 
< | 
                        error(WARNING, "number of cores should not exceed horizontal resolution"); | 
| 346 | 
< | 
                if (trace != NULL) | 
| 347 | 
< | 
                        error(WARNING, "multiprocessing does not work properly with trace mode"); | 
| 348 | 
< | 
        } | 
| 341 | 
> | 
                                        /* set/check spectral sampling */ | 
| 342 | 
> | 
        rval = setspectrsamp(CNDX, WLPART); | 
| 343 | 
> | 
        if (rval < 0) | 
| 344 | 
> | 
                error(USER, "unsupported spectral sampling"); | 
| 345 | 
> | 
        if (out_prims != NULL) { | 
| 346 | 
> | 
                if (!rval) | 
| 347 | 
> | 
                        error(WARNING, "spectral range incompatible with color output"); | 
| 348 | 
> | 
        } else if (NCSAMP == 3) | 
| 349 | 
> | 
                out_prims = stdprims;   /* 3 samples do not a spectrum make */ | 
| 350 | 
> | 
        if (nproc > 1 && persist) | 
| 351 | 
> | 
                error(USER, "multiprocessing incompatible with persist file"); | 
| 352 | 
  | 
                                        /* initialize object types */ | 
| 353 | 
  | 
        initotypes(); | 
| 354 | 
  | 
                                        /* initialize urand */ | 
| 407 | 
  | 
        if (outform != 'a') | 
| 408 | 
  | 
                SET_FILE_BINARY(stdout); | 
| 409 | 
  | 
        rval = setrtoutput(); | 
| 410 | 
< | 
        readoct(octname = octnm, loadflags, &thescene, NULL); | 
| 410 | 
> | 
        octname = savqstr(octnm); | 
| 411 | 
> | 
        readoct(octname, loadflags, &thescene, NULL); | 
| 412 | 
  | 
        nsceneobjs = nobjects; | 
| 413 | 
  | 
 | 
| 414 | 
  | 
        if (loadflags & IO_INFO) {      /* print header */ | 
| 416 | 
  | 
                printf("SOFTWARE= %s\n", VersionID); | 
| 417 | 
  | 
                fputnow(stdout); | 
| 418 | 
  | 
                if (rval > 0)           /* saved from setrtoutput() call */ | 
| 419 | 
< | 
                        printf("NCOMP=%d\n", rval); | 
| 419 | 
> | 
                        fputncomp(rval, stdout); | 
| 420 | 
> | 
                if (NCSAMP > 3) | 
| 421 | 
> | 
                        fputwlsplit(WLPART, stdout); | 
| 422 | 
> | 
                if ((out_prims != stdprims) & (out_prims != NULL)) | 
| 423 | 
> | 
                        fputprims(out_prims, stdout); | 
| 424 | 
  | 
                if ((outform == 'f') | (outform == 'd')) | 
| 425 | 
  | 
                        fputendian(stdout); | 
| 426 | 
  | 
                fputformat(formstr(outform), stdout); | 
| 427 | 
< | 
                putchar('\n'); | 
| 427 | 
> | 
                fputc('\n', stdout);    /* end of header */ | 
| 428 | 
  | 
        } | 
| 429 | 
  | 
 | 
| 430 | 
  | 
        if (!castonly) {        /* any actual ray traversal to do? */ | 
| 434 | 
  | 
                marksources();          /* find and mark sources */ | 
| 435 | 
  | 
 | 
| 436 | 
  | 
                setambient();           /* initialize ambient calculation */ | 
| 437 | 
< | 
        } | 
| 437 | 
> | 
        } else | 
| 438 | 
> | 
                distantsources();       /* else mark only distant sources */ | 
| 439 | 
> | 
 | 
| 440 | 
> | 
        fflush(stdout);                 /* in case we're duplicating header */ | 
| 441 | 
> | 
 | 
| 442 | 
  | 
#ifdef  PERSIST | 
| 443 | 
  | 
        if (persist) { | 
| 345 | 
– | 
                fflush(stdout); | 
| 444 | 
  | 
                                                /* reconnect stdout */ | 
| 445 | 
  | 
                dup2(duped1, fileno(stdout)); | 
| 446 | 
  | 
                close(duped1); | 
| 500 | 
  | 
 | 
| 501 | 
  | 
void | 
| 502 | 
  | 
wputs(                          /* warning output function */ | 
| 503 | 
< | 
        char    *s | 
| 503 | 
> | 
        const char      *s | 
| 504 | 
  | 
) | 
| 505 | 
  | 
{ | 
| 506 | 
  | 
        int  lasterrno = errno; | 
| 511 | 
  | 
 | 
| 512 | 
  | 
void | 
| 513 | 
  | 
eputs(                          /* put string to stderr */ | 
| 514 | 
< | 
        register char  *s | 
| 514 | 
> | 
        const char  *s | 
| 515 | 
  | 
) | 
| 516 | 
  | 
{ | 
| 517 | 
  | 
        static int  midline = 0; | 
| 566 | 
  | 
static void | 
| 567 | 
  | 
printdefaults(void)                     /* print default values to stdout */ | 
| 568 | 
  | 
{ | 
| 569 | 
< | 
        register char  *cp; | 
| 569 | 
> | 
        char  *cp; | 
| 570 | 
  | 
 | 
| 571 | 
+ | 
        printf(erract[WARNING].pf != NULL ? | 
| 572 | 
+ | 
                        "-w+\t\t\t\t# warning messages on\n" : | 
| 573 | 
+ | 
                        "-w-\t\t\t\t# warning messages off\n"); | 
| 574 | 
  | 
        if (imm_irrad) | 
| 575 | 
  | 
                printf("-I+\t\t\t\t# immediate irradiance on\n"); | 
| 576 | 
  | 
        printf("-n %-2d\t\t\t\t# number of rendering processes\n", nproc); | 
| 579 | 
  | 
        printf("-y %-9d\t\t\t# y resolution\n", vresolu); | 
| 580 | 
  | 
        printf(lim_dist ? "-ld+\t\t\t\t# limit distance on\n" : | 
| 581 | 
  | 
                        "-ld-\t\t\t\t# limit distance off\n"); | 
| 582 | 
< | 
        printf("-h%c\t\t\t\t# %s header\n", loadflags & IO_INFO ? '+' : '-', | 
| 583 | 
< | 
                        loadflags & IO_INFO ? "output" : "no"); | 
| 582 | 
> | 
        printf(loadflags & IO_INFO ? "-h+\t\t\t\t# output header\n" : | 
| 583 | 
> | 
                        "-h-\t\t\t\t# no header\n"); | 
| 584 | 
  | 
        printf("-f%c%c\t\t\t\t# format input/output = %s/%s\n", | 
| 585 | 
  | 
                        inform, outform, formstr(inform), formstr(outform)); | 
| 586 | 
  | 
        printf("-o%-9s\t\t\t# output", outvals); | 
| 605 | 
  | 
                case 'W': printf(" coefficient"); break; | 
| 606 | 
  | 
                case 'm': printf(" modifier"); break; | 
| 607 | 
  | 
                case 'M': printf(" material"); break; | 
| 608 | 
< | 
                case '-': printf(" stroke"); break; | 
| 608 | 
> | 
                case '~': printf(" tilde"); break; | 
| 609 | 
  | 
                } | 
| 610 | 
< | 
        putchar('\n'); | 
| 611 | 
< | 
        printf(erract[WARNING].pf != NULL ? | 
| 612 | 
< | 
                        "-w+\t\t\t\t# warning messages on\n" : | 
| 613 | 
< | 
                        "-w-\t\t\t\t# warning messages off\n"); | 
| 610 | 
> | 
        fputc('\n', stdout); | 
| 611 | 
> | 
        if (sens_curve == scolor_photopic) | 
| 612 | 
> | 
                printf("-pY\t\t\t\t# photopic output\n"); | 
| 613 | 
> | 
        else if (sens_curve == scolor_scotopic) | 
| 614 | 
> | 
                printf("-pS\t\t\t\t# scotopic output\n"); | 
| 615 | 
> | 
        else if (sens_curve == scolor_melanopic) | 
| 616 | 
> | 
                printf("-pM\t\t\t\t# melanopic output\n"); | 
| 617 | 
> | 
        else if (out_prims == stdprims) | 
| 618 | 
> | 
                printf("-pRGB\t\t\t\t# standard RGB color output\n"); | 
| 619 | 
> | 
        else if (out_prims == xyzprims) | 
| 620 | 
> | 
                printf("-pXYZ\t\t\t\t# CIE XYZ color output\n"); | 
| 621 | 
> | 
        else if (out_prims != NULL) | 
| 622 | 
> | 
                printf("-pc %.4f %.4f %.4f %.4f %.4f %.4f %.4f %.4f\t# output color primaries and white point\n", | 
| 623 | 
> | 
                                out_prims[RED][0], out_prims[RED][1], | 
| 624 | 
> | 
                                out_prims[GRN][0], out_prims[GRN][1], | 
| 625 | 
> | 
                                out_prims[BLU][0], out_prims[BLU][1], | 
| 626 | 
> | 
                                out_prims[WHT][0], out_prims[WHT][1]); | 
| 627 | 
> | 
        if (NCSAMP > 3) | 
| 628 | 
> | 
                printf(out_prims != NULL ? "-co-\t\t\t\t# output tristimulus colors\n" : | 
| 629 | 
> | 
                                "-co+\t\t\t\t# output spectral values\n"); | 
| 630 | 
  | 
        print_rdefaults(); | 
| 631 | 
  | 
} |