--- ray/src/gen/mkillum.c 1991/07/23 17:18:21 1.3 +++ ray/src/gen/mkillum.c 1991/08/13 14:43:49 1.11 @@ -15,9 +15,10 @@ static char SCCSid[] = "$SunId$ LBL"; #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 */ @@ -25,18 +26,18 @@ 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", "-di+", + "-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", NULL }; struct rtproc rt; /* our rtrace process */ struct illum_args thisillum = { /* our illum and default values */ 0, DFLMAT, - DFLMAT, + DFLDAT, 0, VOIDID, SAMPDENS, @@ -58,7 +59,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(); @@ -89,6 +90,7 @@ char *argv[]; rtargv[rtargc] = NULL; /* just asking for defaults? */ if (!strcmp(argv[gargc-1], "-defaults")) { + printopts(); fflush(stdout); rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); if (rtpath == NULL) { eputs(rtargv[0]); @@ -103,7 +105,7 @@ char *argv[]; init(); if (gargc+1 < argc) for (i = gargc+1; i < argc; i++) { - if ((fp = fopen(argv[i], "r")) == NULL { + if ((fp = fopen(argv[i], "r")) == NULL) { sprintf(errmsg, "cannot open scene file \"%s\"", argv[i]); error(SYSTEM, errmsg); @@ -135,10 +137,11 @@ int status; init() /* start rtrace and set up buffers */ { - extern int o_face(), o_ring(); + 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); @@ -152,11 +155,13 @@ 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); } @@ -252,6 +257,8 @@ char *nm; if (*++cp != '=') break; if (!*++cp) { + strcpy(thisillum.datafile,thisillum.matname); + thisillum.dfnum = 0; thisillum.flags &= ~IL_DATCLB; continue; } @@ -262,10 +269,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 */ @@ -281,12 +289,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); @@ -313,12 +320,14 @@ char *nm; cp = sskip(cp); continue; case 'l': /* light sources */ - if (*++cp != '+' && *cp != '-') - break; - if (*cp++ == '+') + cp++; + if (*cp == '+') thisillum.flags |= IL_LIGHT; - else + else if (*cp == '-') thisillum.flags &= ~IL_LIGHT; + else + break; + cp++; continue; case 'o': /* output file */ if (*++cp != '=') @@ -334,6 +343,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); @@ -351,10 +365,20 @@ 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); + printf("c=n\t\t\t\t# color none\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); +} + + printhead(ac, av) /* print out header */ register int ac; register char **av; @@ -364,7 +388,7 @@ register char **av; putchar(' '); fputs(*av++, stdout); } - putchar('\n'); + fputs("\n#@mkillum !\n", stdout); } @@ -387,10 +411,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); @@ -407,7 +431,7 @@ char *nm; doit = 0; break; case S_ALL: - doit = issurface(thisobj.otype); + doit = 1; break; case S_ELEM: doit = !strcmp(thisillum.altmat, matcheck); @@ -416,17 +440,12 @@ char *nm; doit = strcmp(thisillum.altmat, matcheck); break; } - if (doit && ofun[thisobj.otype].funp == o_default) { - sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", - nm, ofun[thisobj.otype].funame, thisobj.oname); - error(WARNING, errmsg); - doit = 0; - } + doit = doit && issurface(thisobj.otype); /* print header? */ checkhead(); /* process object */ if (doit) - (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt); + (*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); else printobj(thisillum.altmat, &thisobj); /* free arguments */ @@ -436,20 +455,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() {}