| 1 | 
– | 
/* Copyright (c) 1991 Regents of the University of California */ | 
| 2 | 
– | 
 | 
| 1 | 
  | 
#ifndef lint | 
| 2 | 
< | 
static char SCCSid[] = "$SunId$ LBL"; | 
| 2 | 
> | 
static const char RCSid[] = "$Id$"; | 
| 3 | 
  | 
#endif | 
| 6 | 
– | 
 | 
| 4 | 
  | 
/* | 
| 5 | 
  | 
 * Make illum sources for optimizing rendering process | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 11 | 
– | 
#include  "mkillum.h" | 
| 12 | 
– | 
 | 
| 8 | 
  | 
#include  <signal.h> | 
| 14 | 
– | 
 | 
| 9 | 
  | 
#include  <ctype.h> | 
| 10 | 
  | 
 | 
| 11 | 
+ | 
#include  "mkillum.h" | 
| 12 | 
+ | 
#include  "platform.h" | 
| 13 | 
+ | 
 | 
| 14 | 
  | 
                                /* default parameters */ | 
| 15 | 
  | 
#define  SAMPDENS       48              /* points per projected steradian */ | 
| 16 | 
  | 
#define  NSAMPS         32              /* samples per point */ | 
| 23 | 
  | 
#define  S_ALL          3               /* select all */ | 
| 24 | 
  | 
 | 
| 25 | 
  | 
                                /* rtrace command and defaults */ | 
| 26 | 
< | 
char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+", | 
| 26 | 
> | 
char  *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-", | 
| 27 | 
  | 
                "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; | 
| 28 | 
  | 
int  rtargc = 14; | 
| 29 | 
  | 
                                /* overriding rtrace options */ | 
| 30 | 
< | 
char  *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL }; | 
| 30 | 
> | 
char  *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-", | 
| 31 | 
> | 
                        "-fff", "-y", "0", NULL }; | 
| 32 | 
  | 
 | 
| 33 | 
  | 
struct rtproc   rt;             /* our rtrace process */ | 
| 34 | 
  | 
 | 
| 57 | 
  | 
 | 
| 58 | 
  | 
int     warnings = 1;           /* print warnings? */ | 
| 59 | 
  | 
 | 
| 62 | 
– | 
extern char     *fgetline(), *fgetword(), *sskip(),  | 
| 63 | 
– | 
                *atos(), *iskip(), *fskip(), *strcpy(); | 
| 64 | 
– | 
extern FILE     *popen(); | 
| 60 | 
  | 
 | 
| 66 | 
– | 
 | 
| 61 | 
  | 
main(argc, argv)                /* compute illum distributions using rtrace */ | 
| 62 | 
  | 
int     argc; | 
| 63 | 
  | 
char    *argv[]; | 
| 64 | 
  | 
{ | 
| 71 | 
– | 
        extern char     *getenv(), *getpath(); | 
| 65 | 
  | 
        char    *rtpath; | 
| 66 | 
  | 
        FILE    *fp; | 
| 67 | 
  | 
        register int    i; | 
| 69 | 
  | 
        gargv = argv; | 
| 70 | 
  | 
                                /* set up rtrace command */ | 
| 71 | 
  | 
        for (i = 1; i < argc; i++) { | 
| 72 | 
< | 
                if (argv[i][0] == '<' && !argv[i][1]) | 
| 72 | 
> | 
                if (argv[i][0] == '<' && argv[i][1] == '\0') | 
| 73 | 
  | 
                        break; | 
| 74 | 
  | 
                rtargv[rtargc++] = argv[i]; | 
| 75 | 
  | 
                if (argv[i][0] == '-' && argv[i][1] == 'w') | 
| 76 | 
< | 
                        warnings = !warnings; | 
| 76 | 
> | 
                        switch (argv[i][2]) { | 
| 77 | 
> | 
                        case '\0': | 
| 78 | 
> | 
                                warnings = !warnings; | 
| 79 | 
> | 
                                break; | 
| 80 | 
> | 
                        case '+': | 
| 81 | 
> | 
                        case 'T': case 't': | 
| 82 | 
> | 
                        case 'Y': case 'y': | 
| 83 | 
> | 
                        case '1': | 
| 84 | 
> | 
                                warnings = 1; | 
| 85 | 
> | 
                                break; | 
| 86 | 
> | 
                        case '-': | 
| 87 | 
> | 
                        case 'F': case 'f': | 
| 88 | 
> | 
                        case 'N': case 'n': | 
| 89 | 
> | 
                        case '0': | 
| 90 | 
> | 
                                warnings = 0; | 
| 91 | 
> | 
                                break; | 
| 92 | 
> | 
                        } | 
| 93 | 
  | 
        } | 
| 94 | 
< | 
        if ((gargc = i) < 2) | 
| 86 | 
< | 
                error(USER, "too few arguments"); | 
| 94 | 
> | 
        gargc = i; | 
| 95 | 
  | 
        rtargc--; | 
| 96 | 
  | 
        for (i = 0; myrtopts[i] != NULL; i++) | 
| 97 | 
  | 
                rtargv[rtargc++] = myrtopts[i]; | 
| 110 | 
  | 
                perror(rtpath); | 
| 111 | 
  | 
                exit(1); | 
| 112 | 
  | 
        } | 
| 113 | 
+ | 
        if (gargc < 2 || argv[gargc-1][0] == '-') | 
| 114 | 
+ | 
                error(USER, "missing octree argument"); | 
| 115 | 
  | 
                                /* else initialize and run our calculation */ | 
| 116 | 
  | 
        init(); | 
| 117 | 
  | 
        if (gargc+1 < argc) | 
| 130 | 
  | 
} | 
| 131 | 
  | 
 | 
| 132 | 
  | 
 | 
| 133 | 
+ | 
void | 
| 134 | 
  | 
quit(status)                    /* exit with status */ | 
| 135 | 
  | 
int  status; | 
| 136 | 
  | 
{ | 
| 137 | 
  | 
        int     rtstat; | 
| 138 | 
  | 
 | 
| 139 | 
< | 
        rtstat = close_process(rt.pd); | 
| 139 | 
> | 
        rtstat = close_process(&(rt.pd)); | 
| 140 | 
  | 
        if (status == 0) | 
| 141 | 
  | 
                if (rtstat < 0) | 
| 142 | 
  | 
                        error(WARNING, | 
| 156 | 
  | 
        ofun[OBJ_SPHERE].funp = o_sphere; | 
| 157 | 
  | 
        ofun[OBJ_RING].funp = o_ring; | 
| 158 | 
  | 
                                        /* set up signal handling */ | 
| 159 | 
+ | 
#ifdef SIGPIPE /* not present on Windows */ | 
| 160 | 
  | 
        signal(SIGPIPE, quit); | 
| 161 | 
+ | 
#endif | 
| 162 | 
  | 
                                        /* start rtrace process */ | 
| 163 | 
< | 
        maxbytes = open_process(rt.pd, rtargv); | 
| 163 | 
> | 
        errno = 0; | 
| 164 | 
> | 
        maxbytes = open_process(&(rt.pd), rtargv); | 
| 165 | 
  | 
        if (maxbytes == 0) { | 
| 166 | 
  | 
                eputs(rtargv[0]); | 
| 167 | 
  | 
                eputs(": command not found\n"); | 
| 176 | 
  | 
                error(SYSTEM, "out of memory in init"); | 
| 177 | 
  | 
        rt.nrays = 0; | 
| 178 | 
  | 
                                        /* set up urand */ | 
| 179 | 
< | 
        initurand(2048); | 
| 179 | 
> | 
        initurand(16384); | 
| 180 | 
  | 
} | 
| 181 | 
  | 
 | 
| 182 | 
  | 
 | 
| 183 | 
+ | 
void | 
| 184 | 
  | 
eputs(s)                                /* put string to stderr */ | 
| 185 | 
  | 
register char  *s; | 
| 186 | 
  | 
{ | 
| 196 | 
  | 
} | 
| 197 | 
  | 
 | 
| 198 | 
  | 
 | 
| 199 | 
+ | 
void | 
| 200 | 
  | 
wputs(s)                        /* print warning if enabled */ | 
| 201 | 
  | 
char  *s; | 
| 202 | 
  | 
{ | 
| 256 | 
  | 
                case ' ': | 
| 257 | 
  | 
                case '\t': | 
| 258 | 
  | 
                case '\n': | 
| 259 | 
+ | 
                case '\r': | 
| 260 | 
+ | 
                case '\f': | 
| 261 | 
  | 
                        cp++; | 
| 262 | 
  | 
                        continue; | 
| 263 | 
  | 
                case 'm':                       /* material name */ | 
| 264 | 
  | 
                        if (*++cp != '=') | 
| 265 | 
  | 
                                break; | 
| 266 | 
< | 
                        if (!*++cp) | 
| 266 | 
> | 
                        if (!*++cp || isspace(*cp)) | 
| 267 | 
  | 
                                break; | 
| 268 | 
  | 
                        atos(thisillum.matname, MAXSTR, cp); | 
| 269 | 
  | 
                        cp = sskip(cp); | 
| 275 | 
  | 
                case 'f':                       /* data file name */ | 
| 276 | 
  | 
                        if (*++cp != '=') | 
| 277 | 
  | 
                                break; | 
| 278 | 
< | 
                        if (!*++cp) { | 
| 278 | 
> | 
                        if (!*++cp || isspace(*cp)) { | 
| 279 | 
  | 
                                strcpy(thisillum.datafile,thisillum.matname); | 
| 280 | 
  | 
                                thisillum.dfnum = 0; | 
| 281 | 
  | 
                                thisillum.flags &= ~IL_DATCLB; | 
| 325 | 
  | 
                case 'd':                       /* point sample density */ | 
| 326 | 
  | 
                        if (*++cp != '=') | 
| 327 | 
  | 
                                break; | 
| 328 | 
< | 
                        if (!isintd(++cp, " \t\n")) | 
| 328 | 
> | 
                        if (!isintd(++cp, " \t\n\r")) | 
| 329 | 
  | 
                                break; | 
| 330 | 
  | 
                        thisillum.sampdens = atoi(cp); | 
| 331 | 
  | 
                        cp = sskip(cp); | 
| 333 | 
  | 
                case 's':                       /* point super-samples */ | 
| 334 | 
  | 
                        if (*++cp != '=') | 
| 335 | 
  | 
                                break; | 
| 336 | 
< | 
                        if (!isintd(++cp, " \t\n")) | 
| 336 | 
> | 
                        if (!isintd(++cp, " \t\n\r")) | 
| 337 | 
  | 
                                break; | 
| 338 | 
  | 
                        thisillum.nsamps = atoi(cp); | 
| 339 | 
  | 
                        cp = sskip(cp); | 
| 351 | 
  | 
                case 'b':                       /* brightness */ | 
| 352 | 
  | 
                        if (*++cp != '=') | 
| 353 | 
  | 
                                break; | 
| 354 | 
< | 
                        if (!isfltd(++cp, " \t\n")) | 
| 354 | 
> | 
                        if (!isfltd(++cp, " \t\n\r")) | 
| 355 | 
  | 
                                break; | 
| 356 | 
  | 
                        thisillum.minbrt = atof(cp); | 
| 357 | 
  | 
                        if (thisillum.minbrt < 0.) | 
| 361 | 
  | 
                case 'o':                       /* output file */ | 
| 362 | 
  | 
                        if (*++cp != '=') | 
| 363 | 
  | 
                                break; | 
| 364 | 
< | 
                        if (!*++cp) | 
| 364 | 
> | 
                        if (!*++cp || isspace(*cp)) | 
| 365 | 
  | 
                                break; | 
| 366 | 
  | 
                        atos(buf, sizeof(buf), cp); | 
| 367 | 
  | 
                        cp = sskip(cp); | 
| 379 | 
  | 
                        return; | 
| 380 | 
  | 
                } | 
| 381 | 
  | 
        opterr:                                 /* skip faulty option */ | 
| 382 | 
< | 
                cp = sskip(cp); | 
| 382 | 
> | 
                while (*cp && !isspace(*cp)) | 
| 383 | 
> | 
                        cp++; | 
| 384 | 
  | 
                nerrs++; | 
| 385 | 
  | 
        } | 
| 386 | 
  | 
                                                /* print header? */ | 
| 403 | 
  | 
{ | 
| 404 | 
  | 
        printf("m=%-15s\t\t# material name\n", thisillum.matname); | 
| 405 | 
  | 
        printf("f=%-15s\t\t# data file name\n", thisillum.datafile); | 
| 406 | 
< | 
        printf("c=n\t\t\t\t# color none\n"); | 
| 406 | 
> | 
        if (thisillum.flags & IL_COLAVG) | 
| 407 | 
> | 
                if (thisillum.flags & IL_COLDST) | 
| 408 | 
> | 
                        printf("c=d\t\t\t\t# color distribution\n"); | 
| 409 | 
> | 
                else | 
| 410 | 
> | 
                        printf("c=a\t\t\t\t# color average\n"); | 
| 411 | 
> | 
        else | 
| 412 | 
> | 
                printf("c=n\t\t\t\t# color none\n"); | 
| 413 | 
> | 
        if (thisillum.flags & IL_LIGHT) | 
| 414 | 
> | 
                printf("l+\t\t\t\t# light type on\n"); | 
| 415 | 
> | 
        else | 
| 416 | 
> | 
                printf("l-\t\t\t\t# light type off\n"); | 
| 417 | 
  | 
        printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); | 
| 418 | 
  | 
        printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); | 
| 419 | 
  | 
        printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); | 
| 446 | 
  | 
        if (fgetword(str, MAXSTR, fp) == NULL) | 
| 447 | 
  | 
                goto readerr; | 
| 448 | 
  | 
                                        /* is it an alias? */ | 
| 449 | 
< | 
        if (!strcmp(str, ALIASID)) { | 
| 449 | 
> | 
        if (!strcmp(str, ALIASKEY)) { | 
| 450 | 
  | 
                if (fgetword(str, MAXSTR, fp) == NULL) | 
| 451 | 
  | 
                        goto readerr; | 
| 452 | 
< | 
                printf("\n%s %s %s", thisillum.altmat, ALIASID, str); | 
| 452 | 
> | 
                printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str); | 
| 453 | 
  | 
                if (fgetword(str, MAXSTR, fp) == NULL) | 
| 454 | 
  | 
                        goto readerr; | 
| 455 | 
  | 
                printf("\t%s\n", str); |