--- ray/src/gen/mkillum.c 1991/07/23 16:13:28 1.2 +++ ray/src/gen/mkillum.c 1992/11/19 20:27:48 2.5 @@ -10,12 +10,15 @@ static char SCCSid[] = "$SunId$ LBL"; #include "mkillum.h" +#include + #include /* default parameters */ -#define SAMPDENS 128 /* points per projected steradian */ +#define SAMPDENS 48 /* points per projected steradian */ #define NSAMPS 32 /* samples per point */ #define DFLMAT "illum_mat" /* material name */ +#define DFLDAT "illum" /* data file name */ /* selection options */ #define S_NONE 0 /* select none */ #define S_ELEM 1 /* select specified element */ @@ -23,24 +26,25 @@ static char SCCSid[] = "$SunId$ LBL"; #define S_ALL 3 /* select all */ /* rtrace command and defaults */ -char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-ab", "2", - "-ad", "256", "-as", "128", "-aa", ".15" }; -int rtargc = 13; +char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-", + "-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; +int rtargc = 14; /* overriding rtrace options */ -char *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL }; +char *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", "-y", "0", NULL }; struct rtproc rt; /* our rtrace process */ struct illum_args thisillum = { /* our illum and default values */ 0, DFLMAT, - DFLMAT, + DFLDAT, 0, VOIDID, + SAMPDENS, NSAMPS, + 0., }; -int sampdens = SAMPDENS; /* sample point density */ char matcheck[MAXSTR]; /* current material to include or exclude */ int matselect = S_ALL; /* selection criterion */ @@ -56,7 +60,7 @@ int doneheader = 0; /* printed header yet? */ int warnings = 1; /* print warnings? */ extern char *fgetline(), *fgetword(), *sskip(), - *atos(), *iskip(), *fskip(); + *atos(), *iskip(), *fskip(), *strcpy(); extern FILE *popen(); @@ -66,23 +70,27 @@ char *argv[]; { extern char *getenv(), *getpath(); char *rtpath; + FILE *fp; register int i; /* set global arguments */ - gargc = argc; gargv = argv; + gargv = argv; /* set up rtrace command */ - if (argc < 2) - error(USER, "too few arguments"); - for (i = 1; i < argc-1; i++) { + for (i = 1; i < argc; i++) { + if (argv[i][0] == '<' && !argv[i][1]) + break; rtargv[rtargc++] = argv[i]; if (argv[i][0] == '-' && argv[i][1] == 'w') warnings = !warnings; } + gargc = i; + rtargc--; for (i = 0; myrtopts[i] != NULL; i++) rtargv[rtargc++] = myrtopts[i]; - rtargv[rtargc++] = argv[argc-1]; + rtargv[rtargc++] = argv[gargc-1]; rtargv[rtargc] = NULL; /* just asking for defaults? */ - if (!strcmp(argv[argc-1], "-defaults")) { + if (!strcmp(argv[gargc-1], "-defaults")) { + printopts(); fflush(stdout); rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); if (rtpath == NULL) { eputs(rtargv[0]); @@ -93,17 +101,54 @@ char *argv[]; perror(rtpath); exit(1); } + if (gargc < 2 || argv[gargc-1][0] == '-') + error(USER, "missing octree argument"); /* else initialize and run our calculation */ init(); - filter(stdin, "standard input"); + if (gargc+1 < argc) + for (i = gargc+1; i < argc; i++) { + if ((fp = fopen(argv[i], "r")) == NULL) { + sprintf(errmsg, + "cannot open scene file \"%s\"", argv[i]); + error(SYSTEM, errmsg); + } + filter(fp, argv[i]); + fclose(fp); + } + else + filter(stdin, "standard input"); quit(0); } +quit(status) /* exit with status */ +int status; +{ + int rtstat; + + rtstat = close_process(rt.pd); + if (status == 0) + if (rtstat < 0) + error(WARNING, + "unknown return status from rtrace process"); + else + status = rtstat; + exit(status); +} + + init() /* start rtrace and set up buffers */ { + extern int o_face(), o_sphere(), o_ring(); int maxbytes; - + /* set up object functions */ + ofun[OBJ_FACE].funp = o_face; + ofun[OBJ_SPHERE].funp = o_sphere; + ofun[OBJ_RING].funp = o_ring; + /* set up signal handling */ + signal(SIGPIPE, quit); + /* start rtrace process */ + errno = 0; maxbytes = open_process(rt.pd, rtargv); if (maxbytes == 0) { eputs(rtargv[0]); @@ -113,30 +158,16 @@ init() /* start rtrace and set up buffers */ if (maxbytes < 0) error(SYSTEM, "cannot start rtrace process"); rt.bsiz = maxbytes/(6*sizeof(float)); - rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float))); - if (rt.buf == NULL) + rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--); + rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz); + if (rt.buf == NULL || rt.dest == NULL) error(SYSTEM, "out of memory in init"); - rt.bsiz--; /* allow for flush ray */ rt.nrays = 0; + /* set up urand */ + initurand(2048); } -quit(status) /* exit with status */ -int status; -{ - int rtstat; - - rtstat = close_process(rt.pd); - if (status == 0) - if (rtstat < 0) - error(WARNING, - "unknown return status from rtrace process"); - else - status = rtstat; - exit(status); -} - - eputs(s) /* put string to stderr */ register char *s; { @@ -229,6 +260,8 @@ char *nm; if (*++cp != '=') break; if (!*++cp) { + strcpy(thisillum.datafile,thisillum.matname); + thisillum.dfnum = 0; thisillum.flags &= ~IL_DATCLB; continue; } @@ -239,10 +272,11 @@ char *nm; continue; case 'i': /* include material */ case 'e': /* exclude material */ - matselect = (*cp == 'i') ? S_ELEM : S_COMPL; - if (*++cp != '=') + if (cp[1] != '=') break; - atos(matcheck, MAXSTR, ++cp); + matselect = (*cp == 'i') ? S_ELEM : S_COMPL; + cp += 2; + atos(matcheck, MAXSTR, cp); cp = sskip(cp); continue; case 'a': /* use everything */ @@ -258,12 +292,11 @@ char *nm; break; switch (*++cp) { case 'a': /* average */ - thisillum.flags |= IL_COLAVG; - thisillum.flags &= ~IL_COLDST; + thisillum.flags = (thisillum.flags|IL_COLAVG) + & ~IL_COLDST; break; case 'd': /* distribution */ - thisillum.flags |= IL_COLDST; - thisillum.flags &= ~IL_COLAVG; + thisillum.flags |= (IL_COLDST|IL_COLAVG); break; case 'n': /* none */ thisillum.flags &= ~(IL_COLAVG|IL_COLDST); @@ -278,7 +311,7 @@ char *nm; break; if (!isintd(++cp, " \t\n")) break; - sampdens = atoi(cp); + thisillum.sampdens = atoi(cp); cp = sskip(cp); continue; case 's': /* point super-samples */ @@ -289,6 +322,26 @@ char *nm; thisillum.nsamps = atoi(cp); cp = sskip(cp); continue; + case 'l': /* light sources */ + cp++; + if (*cp == '+') + thisillum.flags |= IL_LIGHT; + else if (*cp == '-') + thisillum.flags &= ~IL_LIGHT; + else + break; + cp++; + continue; + case 'b': /* brightness */ + if (*++cp != '=') + break; + if (!isfltd(++cp, " \t\n")) + break; + thisillum.minbrt = atof(cp); + if (thisillum.minbrt < 0.) + thisillum.minbrt = 0.; + cp = sskip(cp); + continue; case 'o': /* output file */ if (*++cp != '=') break; @@ -303,6 +356,11 @@ char *nm; } doneheader = 0; continue; + case '!': /* processed file! */ + sprintf(errmsg, "(%s): already processed!", nm); + error(WARNING, errmsg); + matselect = S_NONE; + return; } opterr: /* skip faulty option */ cp = sskip(cp); @@ -320,10 +378,31 @@ char *nm; progname, nerrs); } /* print pure comment */ - putchar('#'); putchar(' '); fputs(s+2, stdout); + printf("# %s", s+2); } +printopts() /* print out option default values */ +{ + printf("m=%-15s\t\t# material name\n", thisillum.matname); + printf("f=%-15s\t\t# data file name\n", thisillum.datafile); + if (thisillum.flags & IL_COLAVG) + if (thisillum.flags & IL_COLDST) + printf("c=d\t\t\t\t# color distribution\n"); + else + printf("c=a\t\t\t\t# color average\n"); + else + printf("c=n\t\t\t\t# color none\n"); + if (thisillum.flags & IL_LIGHT) + printf("l+\t\t\t\t# light type on\n"); + else + printf("l-\t\t\t\t# light type off\n"); + printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); + printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); + printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); +} + + printhead(ac, av) /* print out header */ register int ac; register char **av; @@ -333,7 +412,7 @@ register char **av; putchar(' '); fputs(*av++, stdout); } - putchar('\n'); + fputs("\n#@mkillum !\n", stdout); } @@ -356,10 +435,10 @@ char *nm; printf("\n%s %s %s", thisillum.altmat, ALIASID, str); if (fgetword(str, MAXSTR, fp) == NULL) goto readerr; - printf(" %s\n", str); + printf("\t%s\n", str); return; } - thisobj.omod = OVOID; + thisobj.omod = OVOID; /* unused field */ if ((thisobj.otype = otype(str)) < 0) { sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str); error(USER, errmsg); @@ -376,7 +455,7 @@ char *nm; doit = 0; break; case S_ALL: - doit = issurface(thisobj.otype); + doit = 1; break; case S_ELEM: doit = !strcmp(thisillum.altmat, matcheck); @@ -385,26 +464,12 @@ char *nm; doit = strcmp(thisillum.altmat, matcheck); break; } - if (doit) /* make sure we can do it */ - switch (thisobj.otype) { - case OBJ_SPHERE: - case OBJ_FACE: - case OBJ_RING: - break; - default: - sprintf(errmsg, - "(%s): cannot make illum for %s \"%s\"", - nm, ofun[thisobj.otype].funame, - thisobj.oname); - error(WARNING, errmsg); - doit = 0; - break; - } + doit = doit && issurface(thisobj.otype); /* print header? */ checkhead(); /* process object */ if (doit) - mkillum(&thisobj, &thisillum, &rt); + (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); else printobj(thisillum.altmat, &thisobj); /* free arguments */ @@ -414,20 +479,3 @@ readerr: sprintf(errmsg, "(%s): error reading scene", nm); error(USER, errmsg); } - - -int -otype(ofname) /* get object function number from its name */ -char *ofname; -{ - register int i; - - for (i = 0; i < NUMOTYPE; i++) - if (!strcmp(ofun[i].funame, ofname)) - return(i); - - return(-1); /* not found */ -} - - -o_default() {}