--- ray/src/rt/rtrace.c 1991/07/18 14:43:03 1.18 +++ ray/src/rt/rtrace.c 1992/11/19 20:26:10 2.10 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -30,6 +30,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "otypes.h" +#include "resolu.h" + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx = 0; /* index for this sample */ @@ -46,10 +48,14 @@ int vresolu = 0; /* vertical resolution */ double dstrsrc = 0.0; /* square source distribution */ double shadthresh = .05; /* shadow threshold */ double shadcert = .5; /* shadow certainty */ -int directrelay = 0; /* number of source relays */ +int directrelay = 1; /* number of source relays */ int vspretest = 512; /* virtual source pretest density */ -int directinvis = 0; /* sources invisible? */ +int directvis = 1; /* sources visible? */ +double srcsizerat = .25; /* maximum ratio source size/dist. */ +double specthresh = .15; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ + int maxdepth = 6; /* maximum recursion depth */ double minweight = 4e-3; /* minimum ray weight */ @@ -66,8 +72,8 @@ extern OBJREC Lamb; /* a Lambertian surface */ static RAY thisray; /* for our convenience */ -static int oputo(), oputd(), oputv(), oputl(), - oputp(), oputn(), oputs(), oputw(), oputm(); +static int oputo(), oputd(), oputv(), oputl(), oputL(), + oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); static int (*ray_out[10])(), (*every_out[10])(); static int castonly; @@ -84,6 +90,20 @@ int code; } +char * +formstr(f) /* return format identifier */ +int f; +{ + switch (f) { + case 'a': return("ascii"); + case 'f': return("float"); + case 'd': return("double"); + case 'c': return(COLRFMT); + } + return("unknown"); +} + + rtrace(fname) /* trace rays from file */ char *fname; { @@ -98,13 +118,25 @@ char *fname; sprintf(errmsg, "cannot open input file \"%s\"", fname); error(SYSTEM, errmsg); } +#ifdef MSDOS + if (inform != 'a') + setmode(fileno(fp), O_BINARY); +#endif /* set up output */ setoutput(outvals); switch (outform) { case 'a': putreal = puta; break; case 'f': putreal = putf; break; case 'd': putreal = putd; break; + case 'c': + if (strcmp(outvals, "v")) + error(USER, "color format with value output only"); + break; + default: + error(CONSISTENCY, "botched output format"); } + if (hresolu > 0 && vresolu > 0) + fprtresolu(hresolu, vresolu, stdout); /* process file */ while (getvec(orig, inform, fp) == 0 && getvec(direc, inform, fp) == 0) { @@ -160,16 +192,23 @@ register char *vs; *table++ = oputv; castonly = 0; break; - case 'l': /* length */ + case 'l': /* effective distance */ *table++ = oputl; castonly = 0; break; + case 'L': /* single ray length */ + *table++ = oputL; + break; case 'p': /* point */ *table++ = oputp; break; - case 'n': /* normal */ + case 'n': /* perturbed normal */ *table++ = oputn; + castonly = 0; break; + case 'N': /* unperturbed normal */ + *table++ = oputN; + break; case 's': /* surface */ *table++ = oputs; break; @@ -235,12 +274,20 @@ register FVECT vec; int fmt; FILE *fp; { + extern char *fgetword(); static float vf[3]; + static double vd[3]; + char buf[32]; + register int i; switch (fmt) { case 'a': /* ascii */ - if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) - return(-1); + for (i = 0; i < 3; i++) { + if (fgetword(buf, sizeof(buf), fp) == NULL || + !isflt(buf)) + return(-1); + vec[i] = atof(buf); + } break; case 'f': /* binary float */ if (fread((char *)vf, sizeof(float), 3, fp) != 3) @@ -248,9 +295,12 @@ FILE *fp; vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; break; case 'd': /* binary double */ - if (fread((char *)vec, sizeof(double), 3, fp) != 3) + if (fread((char *)vd, sizeof(double), 3, fp) != 3) return(-1); + vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; break; + default: + error(CONSISTENCY, "botched input format"); } return(0); } @@ -306,6 +356,15 @@ static oputv(r) /* print value */ register RAY *r; { + COLR cout; + + if (outform == 'c') { + setcolr(cout, colval(r->rcol,RED), + colval(r->rcol,GRN), + colval(r->rcol,BLU)); + fwrite((char *)cout, sizeof(cout), 1, stdout); + return; + } (*putreal)(colval(r->rcol,RED)); (*putreal)(colval(r->rcol,GRN)); (*putreal)(colval(r->rcol,BLU)); @@ -313,7 +372,7 @@ register RAY *r; static -oputl(r) /* print length */ +oputl(r) /* print effective distance */ register RAY *r; { (*putreal)(r->rt); @@ -321,6 +380,14 @@ register RAY *r; static +oputL(r) /* print single ray length */ +register RAY *r; +{ + (*putreal)(r->rot); +} + + +static oputp(r) /* print point */ register RAY *r; { @@ -337,7 +404,7 @@ register RAY *r; static -oputn(r) /* print normal */ +oputN(r) /* print unperturbed normal */ register RAY *r; { if (r->rot < FHUGE) { @@ -349,6 +416,25 @@ register RAY *r; (*putreal)(0.0); (*putreal)(0.0); } +} + + +static +oputn(r) /* print perturbed normal */ +RAY *r; +{ + FVECT pnorm; + + if (r->rot >= FHUGE) { + (*putreal)(0.0); + (*putreal)(0.0); + (*putreal)(0.0); + return; + } + raynormal(pnorm, r); + (*putreal)(pnorm[0]); + (*putreal)(pnorm[1]); + (*putreal)(pnorm[2]); }