--- ray/src/rt/rv2.c 1989/05/30 09:57:13 1.4 +++ ray/src/rt/rv2.c 1991/07/18 15:49:06 1.23 @@ -28,58 +28,34 @@ extern char *progname; getframe(s) /* get a new frame */ char *s; { - int x0, y0, x1, y1; - - if (!strcmp("all", s)) { - pframe.l = pframe.d = 0; - pframe.r = ourview.hresolu; - pframe.u = ourview.vresolu; - pdepth = 0; + if (getrect(s, &pframe) < 0) return; - } - if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) { - if (dev->getcur == NULL) - return; - (*dev->comout)("Pick first corner\n"); - if ((*dev->getcur)(&x0, &y0) == ABORT) - return; - (*dev->comout)("Pick second corner\n"); - if ((*dev->getcur)(&x1, &y1) == ABORT) - return; - } - if (x0 < x1) { - pframe.l = x0; - pframe.r = x1; - } else { - pframe.l = x1; - pframe.r = x0; - } - if (y0 < y1) { - pframe.d = y0; - pframe.u = y1; - } else { - pframe.d = y1; - pframe.u = y0; - } - if (pframe.l < 0) pframe.l = 0; - if (pframe.d < 0) pframe.d = 0; - if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu; - if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu; pdepth = 0; } +getrepaint(s) /* get area and repaint */ +char *s; +{ + RECT box; + + if (getrect(s, &box) < 0) + return; + paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box); +} + + getview(s) /* get/show view parameters */ char *s; { FILE *fp; char buf[128]; - char *fname, *getpath(); + char *fname; int change = 0; VIEW nv; if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ - if ((fname = getpath(buf, NULL)) == NULL || + if ((fname = getpath(buf, NULL, 0)) == NULL || (fp = fopen(fname, "a")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); @@ -87,13 +63,14 @@ char *s; } fputs(progname, fp); fprintview(&ourview, fp); + fputs(sskip(s), fp); fputs("\n", fp); fclose(fp); return; } sprintf(buf, "view type (%c): ", ourview.type); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; if (buf[0] && buf[0] != ourview.type) { nv.type = buf[0]; @@ -103,7 +80,7 @@ char *s; sprintf(buf, "view point (%.6g %.6g %.6g): ", ourview.vp[0], ourview.vp[1], ourview.vp[2]); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) change++; @@ -112,7 +89,7 @@ char *s; sprintf(buf, "view direction (%.6g %.6g %.6g): ", ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) change++; @@ -121,7 +98,7 @@ char *s; sprintf(buf, "view up (%.6g %.6g %.6g): ", ourview.vup[0], ourview.vup[1], ourview.vup[2]); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) change++; @@ -130,22 +107,22 @@ char *s; sprintf(buf, "view horiz and vert size (%.6g %.6g): ", ourview.horiz, ourview.vert); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) change++; else { nv.horiz = ourview.horiz; nv.vert = ourview.vert; } - sprintf(buf, "x and y resolution (%d %d): ", - ourview.hresolu, ourview.vresolu); + sprintf(buf, "view shift and lift (%.6g %.6g): ", + ourview.hoff, ourview.voff); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (buf[0] == CTRL(C)) return; - if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2) + if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) change++; else { - nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; + nv.hoff = ourview.hoff; nv.voff = ourview.voff; } if (change) newview(&nv); @@ -156,14 +133,14 @@ lastview(s) /* return to a previous view */ char *s; { char buf[128]; - char *fname, *getpath(); + char *fname; int success; VIEW nv; if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ - bcopy(&stdview, &nv, sizeof(VIEW)); - if ((fname = getpath(buf, NULL)) == NULL || - (success = viewfile(fname, &nv)) == -1) { + copystruct(&nv, &stdview); + if ((fname = getpath(buf, NULL, 0)) == NULL || + (success = viewfile(fname, &nv, 0, 0)) == -1) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); return; @@ -174,64 +151,17 @@ char *s; newview(&nv); return; } - if (oldview.hresolu == 0) { /* no old view! */ + if (oldview.type == 0) { /* no old view! */ error(COMMAND, "no previous view"); return; } - bcopy(&ourview, &nv, sizeof(VIEW)); - bcopy(&oldview, &ourview, sizeof(VIEW)); - bcopy(&nv, &oldview, sizeof(VIEW)); + copystruct(&nv, &ourview); + copystruct(&ourview, &oldview); + copystruct(&oldview, &nv); newimage(); } -getinterest(s, direc, vec, mp) /* get area of interest */ -char *s; -int direc; -FVECT vec; -double *mp; -{ - int x, y; - RAY thisray; - register int i; - - if (sscanf(s, "%lf", mp) != 1) - *mp = 1.0; - else if (*mp < -FTINY) /* negative zoom is reduction */ - *mp = -1.0 / *mp; - else if (*mp <= FTINY) { /* too small */ - error(COMMAND, "illegal magnification"); - return(-1); - } - if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) { - if (dev->getcur == NULL) - return(-1); - (*dev->comout)("Pick view center\n"); - if ((*dev->getcur)(&x, &y) == ABORT) - return(-1); - rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); - if (!direc || ourview.type == VT_PAR) { - rayorigin(&thisray, NULL, PRIMARY, 1.0); - if (!localhit(&thisray, &thescene)) { - error(COMMAND, "not a local object"); - return(-1); - } - } - if (direc) - if (ourview.type == VT_PAR) - for (i = 0; i < 3; i++) - vec[i] = thisray.rop[i] - ourview.vp[i]; - else - VCOPY(vec, thisray.rdir); - else - VCOPY(vec, thisray.rop); - } else if (direc) - for (i = 0; i < 3; i++) - vec[i] -= ourview.vp[i]; - return(0); -} - - getaim(s) /* aim camera */ char *s; { @@ -241,18 +171,12 @@ char *s; if (getinterest(s, 1, nv.vdir, &zfact) < 0) return; + nv.type = ourview.type; VCOPY(nv.vp, ourview.vp); VCOPY(nv.vup, ourview.vup); - nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; - if ((nv.type = ourview.type) == VT_PAR) { - nv.horiz = ourview.horiz / zfact; - nv.vert = ourview.vert / zfact; - } else { - nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / - (PI/180./2.); - nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / - (PI/180./2.); - } + nv.hoff = ourview.hoff; nv.voff = ourview.voff; + nv.horiz = ourview.horiz; nv.vert = ourview.vert; + zoomview(&nv, zfact); newview(&nv); } @@ -282,24 +206,18 @@ char *s; error(COMMAND, "missing angle"); return; } + nv.type = ourview.type; VCOPY(nv.vp, ourview.vp); VCOPY(nv.vup, ourview.vup); - nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu; + nv.hoff = ourview.hoff; nv.voff = ourview.voff; spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); if (elev != 0.0) { fcross(v1, nv.vdir, ourview.vup); normalize(v1); spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); } - if ((nv.type = ourview.type) == VT_PAR) { - nv.horiz = ourview.horiz / zfact; - nv.vert = ourview.vert / zfact; - } else { - nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / - (PI/180./2.); - nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / - (PI/180./2.); - } + nv.horiz = ourview.horiz; nv.vert = ourview.vert; + zoomview(&nv, zfact); newview(&nv); } @@ -341,7 +259,7 @@ char *s; if ((*dev->getcur)(&x, &y) == ABORT) return; r.l = r.d = 0; - r.r = ourview.hresolu; r.u = ourview.vresolu; + r.r = hresolu; r.u = vresolu; p = findrect(x, y, &ptrunk, &r, -1); e = 1.0; } else { @@ -353,7 +271,7 @@ char *s; if (*cp == '\0') { /* interactive */ sprintf(buf, "exposure (%lf): ", exposure); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); for (cp = buf; isspace(*cp); cp++) ; if (*cp == '\0') @@ -369,11 +287,11 @@ char *s; e *= atof(cp); } if (p != NULL) { /* relative setting */ - if (intens(p->v) <= FTINY) { + if (bright(p->v) <= FTINY) { error(COMMAND, "cannot normalize to zero"); return; } - e *= 0.5 / intens(p->v); + e *= 0.5 / bright(p->v); } if (e <= FTINY || fabs(1.0 - e) <= FTINY) return; @@ -391,6 +309,8 @@ register char *s; extern double minweight; extern int maxdepth; extern double dstrsrc; + extern double shadthresh; + extern double shadcert; extern COLOR ambval; extern double ambacc; extern double minarad; @@ -398,13 +318,16 @@ register char *s; extern int ambdiv; extern int ambssamp; extern int ambounce; + extern int directinvis; + extern int do_irrad; int i0; double d0, d1, d2; - char buf[128]; + char buf[128], ans[4]; if (s[0] == '\0') { - (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: "); - (*dev->comin)(buf); + (*dev->comout)( + "aa ab ad ar as av b dc dj di dt i lr lw sp st: "); + (*dev->comin)(buf, NULL); s = buf; } switch (s[0]) { @@ -415,7 +338,7 @@ register char *s; sprintf(buf, "limit weight (%.6g): ", minweight); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%lf", &d0) != 1) break; } @@ -426,7 +349,7 @@ register char *s; sprintf(buf, "limit reflection (%d): ", maxdepth); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } @@ -436,18 +359,78 @@ register char *s; goto badparam; } break; - case 'd': /* distribute source */ - if (s[1] != '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; + 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; + 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; + 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'; + break; + default: goto badparam; - if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "distribute source (%.6g): ", dstrsrc); + } + 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); - if (sscanf(buf, "%lf", &d0) != 1) + (*dev->comin)(buf, NULL); + if (sscanf(buf, "%1s", ans) != 1) break; } - dstrsrc = d0; + greyscale = tolower(ans[0]) == 'y'; 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'; + break; case 'a': /* ambient */ switch (s[1]) { case 'v': /* value */ @@ -458,7 +441,7 @@ register char *s; colval(ambval,GRN), colval(ambval,BLU)); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) break; @@ -470,7 +453,7 @@ register char *s; sprintf(buf, "ambient accuracy (%.6g): ", ambacc); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%lf", &d0) != 1) break; } @@ -481,7 +464,7 @@ register char *s; sprintf(buf, "ambient divisions (%d): ", ambdiv); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } @@ -492,7 +475,7 @@ register char *s; sprintf(buf, "ambient super-samples (%d): ", ambssamp); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } @@ -503,7 +486,7 @@ register char *s; sprintf(buf, "ambient bounces (%d): ", ambounce); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } @@ -514,7 +497,7 @@ register char *s; sprintf(buf, "ambient resolution (%d): ", ambres); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } @@ -531,19 +514,19 @@ register char *s; if (sscanf(s+2, "%d", &i0) != 1) { sprintf(buf, "sample pixel (%d): ", psample); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%d", &i0) != 1) break; } psample = i0; pdepth = 0; break; - case 'd': /* difference */ + case 't': /* threshold */ if (sscanf(s+2, "%lf", &d0) != 1) { - sprintf(buf, "sample difference (%.6g): ", + sprintf(buf, "sample threshold (%.6g): ", maxdiff); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (sscanf(buf, "%lf", &d0) != 1) break; } @@ -582,8 +565,12 @@ char *s; if ((*dev->getcur)(&x, &y) == ABORT) return; - rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5); - + if (viewray(thisray.rorg, thisray.rdir, &ourview, + (x+.5)/hresolu, (y+.5)/vresolu) < 0) { + error(COMMAND, "not on image"); + return; + } + } else if (normalize(thisray.rdir) == 0.0) { error(COMMAND, "zero ray direction"); return; @@ -601,7 +588,7 @@ char *s; ofun[thisray.ro->otype].funame, thisray.ro->oname); (*dev->comout)(buf); - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); if (thisray.rot >= FHUGE) (*dev->comout)("at infinity"); else { @@ -609,14 +596,14 @@ char *s; thisray.rop[1], thisray.rop[2]); (*dev->comout)(buf); } - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); sprintf(buf, "with value (%.6g %.6g %.6g)", colval(thisray.rcol,RED), colval(thisray.rcol,GRN), colval(thisray.rcol,BLU)); (*dev->comout)(buf); } - (*dev->comin)(buf); + (*dev->comin)(buf, NULL); } @@ -624,7 +611,7 @@ writepict(s) /* write the picture to a file */ char *s; { static char buf[128]; - char *fname, *getpath(); + char *fname; FILE *fp; COLR *scanline; int y; @@ -633,7 +620,7 @@ char *s; error(COMMAND, "no file"); return; } - if ((fname = getpath(buf, NULL)) == NULL || + if ((fname = getpath(buf, NULL, 0)) == NULL || (fp = fopen(fname, "w")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", buf); error(COMMAND, errmsg); @@ -645,18 +632,21 @@ char *s; /* write header */ fputs(progname, fp); fprintview(&ourview, fp); - fputs("\n", fp); + putc('\n', fp); if (exposure != 1.0) - fprintf(fp, "EXPOSURE=%e\n", exposure); - fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu); + fputexpos(exposure, fp); + if (dev->pixaspect != 1.0) + fputaspect(dev->pixaspect, fp); + fputformat(COLRFMT, fp); + putc('\n', fp); + fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); - scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR)); + scanline = (COLR *)malloc(hresolu*sizeof(COLR)); if (scanline == NULL) error(SYSTEM, "out of memory in writepict"); - for (y = ourview.vresolu-1; y >= 0; y--) { - getpictcolrs(y, scanline, &ptrunk, - ourview.hresolu, ourview.vresolu); - if (fwritecolrs(scanline, ourview.hresolu, fp) < 0) + for (y = vresolu-1; y >= 0; y--) { + getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); + if (fwritecolrs(scanline, hresolu, fp) < 0) break; } if (fclose(fp) < 0)