--- ray/src/rt/rv2.c 1991/07/18 15:49:06 1.23 +++ ray/src/rt/rv2.c 1991/11/11 17:42:19 1.33 @@ -1,4 +1,4 @@ -/* Copyright (c) 1987 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -18,11 +18,15 @@ static char SCCSid[] = "$SunId$ LBL"; #include "rpaint.h" +#include "resolu.h" + #include #define CTRL(c) ('c'-'@') +extern char VersionID[]; extern char *progname; +extern char *octname; getframe(s) /* get a new frame */ @@ -140,7 +144,7 @@ char *s; if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ copystruct(&nv, &stdview); if ((fname = getpath(buf, NULL, 0)) == NULL || - (success = viewfile(fname, &nv, 0, 0)) == -1) { + (success = viewfile(fname, &nv, NULL)) == -1) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); return; @@ -301,6 +305,69 @@ char *s; } +getparam(str, dsc, typ, ptr) /* get variable from user */ +char *str, *dsc; +int typ; +register union {int i; double d; COLOR C;} *ptr; +{ + extern char *index(); + int i0; + double d0, d1, d2; + char buf[48]; + + switch (typ) { + case 'i': /* integer */ + if (sscanf(str, "%d", &i0) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%d): ", ptr->i); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%d", &i0) != 1) + return(0); + } + ptr->i = i0; + return(1); + case 'r': /* real */ + if (sscanf(str, "%lf", &d0) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%.6g): ", ptr->d); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%lf", &d0) != 1) + return(0); + } + ptr->d = d0; + return(1); + case 'b': /* boolean */ + if (sscanf(str, "%1s", buf) != 1) { + (*dev->comout)(dsc); + sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n'); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (buf[0] == '\0' || + index("yY+1tTnN-0fF", buf[0]) == NULL) + return(0); + } + ptr->i = index("yY+1tT", buf[0]) != NULL; + return(1); + case 'C': /* color */ + if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { + (*dev->comout)(dsc); + sprintf(buf, " (%.6g %.6g %.6g): ", + colval(ptr->C,RED), + colval(ptr->C,GRN), + colval(ptr->C,BLU)); + (*dev->comout)(buf); + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) + return(0); + } + setcolor(ptr->C, d0, d1, d2); + return(1); + } +} + + setparam(s) /* get/set program parameter */ register char *s; { @@ -319,14 +386,13 @@ register char *s; extern int ambssamp; extern int ambounce; extern int directinvis; + extern double srcsizerat; extern int do_irrad; - int i0; - double d0, d1, d2; - char buf[128], ans[4]; + char buf[128]; if (s[0] == '\0') { (*dev->comout)( - "aa ab ad ar as av b dc dj di dt i lr lw sp st: "); + "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: "); (*dev->comin)(buf, NULL); s = buf; } @@ -334,26 +400,10 @@ register char *s; case 'l': /* limit */ switch (s[1]) { case 'w': /* weight */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "limit weight (%.6g): ", - minweight); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - minweight = d0; + getparam(s+2, "limit weight", 'r', &minweight); break; case 'r': /* reflection */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "limit reflection (%d): ", - maxdepth); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - maxdepth = i0; + getparam(s+2, "limit reflection", 'i', &maxdepth); break; default: goto badparam; @@ -362,147 +412,52 @@ register char *s; case 'd': /* direct */ switch (s[1]) { case 'j': /* jitter */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct jitter (%.6g): ", - dstrsrc); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - dstrsrc = d0; + getparam(s+2, "direct jitter", 'r', &dstrsrc); break; case 'c': /* certainty */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct certainty (%.6g): ", - shadcert); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - shadcert = d0; + getparam(s+2, "direct certainty", 'r', &shadcert); break; case 't': /* threshold */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "direct threshold (%.6g): ", - shadthresh); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - shadthresh = d0; + getparam(s+2, "direct threshold", 'r', &shadthresh); break; case 'i': /* invisibility */ - if (sscanf(s+2, "%1s", ans) != 1) { - sprintf(buf, "direct invisibility (%c): ", - directinvis ? 'y' : 'n'); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%1s", ans) != 1) - break; - } - directinvis = tolower(ans[0]) == 'y'; + getparam(s+2, "direct invisibility", + 'b', &directinvis); break; + case 's': /* sampling */ + getparam(s+2, "direct sampling", 'r', &srcsizerat); + break; default: goto badparam; } break; case 'b': /* black and white */ - if (sscanf(s+1, "%1s", ans) != 1) { - sprintf(buf, "black and white (%c): ", - greyscale ? 'y' : 'n'); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%1s", ans) != 1) - break; - } - greyscale = tolower(ans[0]) == 'y'; + getparam(s+1, "black and white", 'b', &greyscale); break; case 'i': /* irradiance */ - if (sscanf(s+1, "%1s", ans) != 1) { - sprintf(buf, "irradiance (%c): ", - do_irrad ? 'y' : 'n'); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%1s", ans) != 1) - break; - } - do_irrad = tolower(ans[0]) == 'y'; + getparam(s+1, "irradiance", 'b', &do_irrad); break; case 'a': /* ambient */ switch (s[1]) { case 'v': /* value */ - if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { - sprintf(buf, - "ambient value (%.6g %.6g %.6g): ", - colval(ambval,RED), - colval(ambval,GRN), - colval(ambval,BLU)); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf %lf %lf", - &d0, &d1, &d2) != 3) - break; - } - setcolor(ambval, d0, d1, d2); + getparam(s+2, "ambient value", 'C', ambval); break; case 'a': /* accuracy */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "ambient accuracy (%.6g): ", - ambacc); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - ambacc = d0; + getparam(s+2, "ambient accuracy", 'r', &ambacc); break; case 'd': /* divisions */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient divisions (%d): ", - ambdiv); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambdiv = i0; + getparam(s+2, "ambient divisions", 'i', &ambdiv); break; case 's': /* samples */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient super-samples (%d): ", - ambssamp); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambssamp = i0; + getparam(s+2, "ambient super-samples", 'i', &ambssamp); break; case 'b': /* bounces */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient bounces (%d): ", - ambounce); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambounce = i0; + getparam(s+2, "ambient bounces", 'i', &ambounce); break; case 'r': - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "ambient resolution (%d): ", - ambres); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - ambres = i0; - minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; + if (getparam(s+2, "ambient resolution", 'i', &ambres)) + minarad = ambres > 0 ? + thescene.cusize/ambres : 0.0; break; default: goto badparam; @@ -511,27 +466,12 @@ register char *s; case 's': /* sample */ switch (s[1]) { case 'p': /* pixel */ - if (sscanf(s+2, "%d", &i0) != 1) { - sprintf(buf, "sample pixel (%d): ", psample); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%d", &i0) != 1) - break; - } - psample = i0; - pdepth = 0; + if (getparam(s+2, "sample pixel", 'i', &psample)) + pdepth = 0; break; case 't': /* threshold */ - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "sample threshold (%.6g): ", - maxdiff); - (*dev->comout)(buf); - (*dev->comin)(buf, NULL); - if (sscanf(buf, "%lf", &d0) != 1) - break; - } - maxdiff = d0; - pdepth = 0; + if (getparam(s+2, "sample threshold", 'r', &maxdiff)) + pdepth = 0; break; default: goto badparam; @@ -541,6 +481,7 @@ register char *s; break; default:; badparam: + *sskip(s) = '\0'; sprintf(errmsg, "%s: unknown variable", s); error(COMMAND, errmsg); break; @@ -597,10 +538,11 @@ char *s; (*dev->comout)(buf); } (*dev->comin)(buf, NULL); - sprintf(buf, "with value (%.6g %.6g %.6g)", + sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", colval(thisray.rcol,RED), colval(thisray.rcol,GRN), - colval(thisray.rcol,BLU)); + colval(thisray.rcol,BLU), + luminance(thisray.rcol)); (*dev->comout)(buf); } (*dev->comin)(buf, NULL); @@ -632,24 +574,32 @@ char *s; /* write header */ fputs(progname, fp); fprintview(&ourview, fp); - putc('\n', fp); + if (octname != NULL) + fprintf(fp, " %s\n", octname); + else + putc('\n', fp); + fprintf(fp, "SOFTWARE= %s\n", VersionID); if (exposure != 1.0) fputexpos(exposure, fp); if (dev->pixaspect != 1.0) fputaspect(dev->pixaspect, fp); fputformat(COLRFMT, fp); putc('\n', fp); - fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); + fprtresolu(hresolu, vresolu, fp); scanline = (COLR *)malloc(hresolu*sizeof(COLR)); - if (scanline == NULL) - error(SYSTEM, "out of memory in writepict"); + if (scanline == NULL) { + error(COMMAND, "not enough memory!"); + fclose(fp); + unlink(fname); + return; + } for (y = vresolu-1; y >= 0; y--) { getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); if (fwritecolrs(scanline, hresolu, fp) < 0) break; } + free((char *)scanline); if (fclose(fp) < 0) error(COMMAND, "write error"); - free((char *)scanline); }