--- ray/src/rt/rpict.c 1992/08/08 18:45:02 2.10 +++ ray/src/rt/rpict.c 1993/01/21 10:08:59 2.22 @@ -18,7 +18,6 @@ static char SCCSid[] = "$SunId$ LBL"; #endif #include -#include #include "view.h" @@ -26,6 +25,14 @@ static char SCCSid[] = "$SunId$ LBL"; #include "random.h" +#include "paths.h" + +#define RFTEMPLATE "rfXXXXXX" + +#ifndef SIGCONT +#define SIGCONT SIGIO +#endif + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx; /* sample index number */ @@ -33,28 +40,28 @@ int samplendx; /* sample index number */ VIEW ourview = STDVIEW; /* view parameters */ int hresolu = 512; /* horizontal resolution */ int vresolu = 512; /* vertical resolution */ -double pixaspect = 1.0; /* pixel aspect ratio */ +double pixaspect = 1.0; /* pixel aspect ratio */ int psample = 4; /* pixel sample size */ -double maxdiff = .05; /* max. difference for interpolation */ -double dstrpix = 0.67; /* square pixel distribution */ +double maxdiff = .05; /* max. difference for interpolation */ +double dstrpix = 0.67; /* square pixel distribution */ -double dstrsrc = 0.0; /* square source distribution */ -double shadthresh = .05; /* shadow threshold */ -double shadcert = .5; /* shadow certainty */ +double dstrsrc = 0.0; /* square source distribution */ +double shadthresh = .05; /* shadow threshold */ +double shadcert = .5; /* shadow certainty */ int directrelay = 1; /* number of source relays */ int vspretest = 512; /* virtual source pretest density */ -int directinvis = 0; /* sources invisible? */ -double srcsizerat = .25; /* maximum ratio source size/dist. */ +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 */ +double specthresh = .15; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ int maxdepth = 6; /* maximum recursion depth */ -double minweight = 5e-3; /* minimum ray weight */ +double minweight = 5e-3; /* minimum ray weight */ COLOR ambval = BLKCOLOR; /* ambient value */ -double ambacc = 0.2; /* ambient accuracy */ +double ambacc = 0.2; /* ambient accuracy */ int ambres = 32; /* ambient resolution */ int ambdiv = 128; /* ambient divisions */ int ambssamp = 0; /* ambient super-samples */ @@ -62,9 +69,13 @@ int ambounce = 0; /* ambient bounces */ char *amblist[128]; /* ambient include/exclude list */ int ambincl = -1; /* include == 1, exclude == 0 */ +#ifdef MSDOS +int ralrm = 60; /* seconds between reports */ +#else int ralrm = 0; /* seconds between reports */ +#endif -double pctdone = 0.0; /* percentage done */ +double pctdone = 0.0; /* percentage done */ long tlastrept = 0L; /* time at last report */ @@ -73,21 +84,15 @@ extern long tstart; /* starting time */ extern long nrays; /* number of rays traced */ -#define MAXDIV 16 /* maximum sample size */ +#define MAXDIV 16 /* maximum sample size */ -#define pixjitter() (.5+dstrpix*(.5-frandom())) +#define pixjitter() (.5+dstrpix*(.5-frandom())) -#define RFTEMPLATE "rfXXXXXX" -#define HFTEMPLATE "/tmp/hfXXXXXX" - -static char *hfname = NULL; /* header file name */ -static FILE *hfp = NULL; /* header file pointer */ - static int hres, vres; /* resolution for this frame */ extern char *mktemp(); -double pixvalue(); +double pixvalue(); quit(code) /* quit program */ @@ -95,11 +100,8 @@ int code; { if (code) /* report status */ report(); - if (hfname != NULL) { /* delete header file */ - if (hfp != NULL) - fclose(hfp); - unlink(hfname); - } + headclean(); /* delete header file */ + pfclean(); /* clean up persist files */ exit(code); } @@ -108,7 +110,7 @@ int code; report() /* report progress */ { struct rusage rubuf; - double t; + double t; getrusage(RUSAGE_SELF, &rubuf); t = (rubuf.ru_utime.tv_usec + rubuf.ru_stime.tv_usec) / 1e6; @@ -129,41 +131,11 @@ report() /* report progress */ sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", nrays, pctdone, (tlastrept-tstart)/3600.0); eputs(errmsg); - signal(SIGALRM, report); + signal(SIGCONT, report); } #endif -openheader() /* save standard output to header file */ -{ - hfname = mktemp(HFTEMPLATE); - if (freopen(hfname, "w", stdout) == NULL) { - sprintf(errmsg, "cannot open header file \"%s\"", hfname); - error(SYSTEM, errmsg); - } -} - - -closeheader() /* done with header output */ -{ - if (hfname == NULL) - return; - if (fflush(stdout) == EOF || (hfp = fopen(hfname, "r")) == NULL) - error(SYSTEM, "error reopening header file"); -} - - -dupheader() /* repeat header on standard output */ -{ - register int c; - - if (fseek(hfp, 0L, 0) < 0) - error(SYSTEM, "seek error on header file"); - while ((c = getc(hfp)) != EOF) - putchar(c); -} - - rpict(seq, pout, zout, prvr) /* generate image(s) */ int seq; char *pout, *zout, *prvr; @@ -179,13 +151,11 @@ char *pout, *zout, *prvr; * sequenced file naming. */ { - extern char *rindex(), *strncpy(), *strcat(); + extern char *rindex(), *strncpy(), *strcat(), *strcpy(); char fbuf[128], fbuf2[128]; register char *cp; - RESOLU rs; - double pa; - /* finished writing header */ - closeheader(); + RESOLU rs; + double pa; /* check sampling */ if (psample < 1) psample = 1; @@ -209,13 +179,15 @@ char *pout, *zout, *prvr; error(USER, "unexpected EOF on view input"); prvr = fbuf; /* mark for renaming */ } - if (pout != NULL) { + if (pout != NULL & prvr != NULL) { sprintf(fbuf, pout, seq); - if (prvr != NULL && !strcmp(prvr, fbuf)) { /* rename */ - fbuf2[0] = '\0'; - if ((cp = rindex(fbuf, '/')) != NULL) - strncpy(fbuf2, fbuf, cp-fbuf+1); - strcat(fbuf2, RFTEMPLATE); + if (!strcmp(prvr, fbuf)) { /* rename */ + strcpy(fbuf2, fbuf); + for (cp = fbuf2; *cp; cp++) + ; + while (cp > fbuf2 && !ISDIRSEP(cp[-1])) + cp--; + strcpy(cp, RFTEMPLATE); prvr = mktemp(fbuf2); if (rename(fbuf, prvr) < 0 && errno != ENOENT) { sprintf(errmsg, @@ -236,6 +208,9 @@ char *pout, *zout, *prvr; "cannot open output file \"%s\"", fbuf); error(SYSTEM, errmsg); } +#ifdef MSDOS + setmode(fileno(stdout), O_BINARY); +#endif dupheader(); } hres = hresolu; vres = vresolu; pa = pixaspect; @@ -255,8 +230,10 @@ char *pout, *zout, *prvr; normaspect(viewaspect(&ourview), &pa, &hres, &vres); if (seq) { if (ralrm > 0) { - sprintf(errmsg, "starting frame %d\n", seq); - eputs(errmsg); + fprintf(stderr, "FRAME %d:", seq); + fprintview(&ourview, stderr); + putc('\n', stderr); + fflush(stderr); } printf("FRAME=%d\n", seq); } @@ -325,6 +302,9 @@ char *zfile, *oldfile; sprintf(errmsg, "cannot open z file \"%s\"", zfile); error(SYSTEM, errmsg); } +#ifdef MSDOS + setmode(zfd, O_BINARY); +#endif for (i = 0; i <= psample; i++) { zbar[i] = (float *)malloc(hres*sizeof(float)); if (zbar[i] == NULL) @@ -345,10 +325,10 @@ char *zfile, *oldfile; pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ report(); -#ifndef BSD +#ifndef BSD else #endif - signal(SIGALRM, report); + signal(SIGCONT, report); ypos = vres-1 - i; fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep); /* compute scanlines */ @@ -370,8 +350,8 @@ char *zfile, *oldfile; /* fill bar */ fillscanbar(scanbar, zbar, hres, ypos, ystep); /* write it out */ -#ifndef BSD - signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ +#ifndef BSD + signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ #endif for (i = ystep; i > 0; i--) { if (zfd != -1 && write(zfd, (char *)zbar[i], @@ -387,13 +367,13 @@ char *zfile, *oldfile; pctdone = 100.0*(vres-1-ypos)/vres; if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) report(); -#ifndef BSD +#ifndef BSD else - signal(SIGALRM, report); + signal(SIGCONT, report); #endif } /* clean up */ - signal(SIGALRM, SIG_IGN); + signal(SIGCONT, SIG_IGN); if (zfd != -1) { if (write(zfd, (char *)zbar[0], hres*sizeof(float)) < hres*sizeof(float)) @@ -411,6 +391,8 @@ char *zfile, *oldfile; if (sampdens != NULL) free(sampdens); pctdone = 100.0; + if (ralrm > 0) + report(); return; writerr: error(SYSTEM, "write error in render"); @@ -420,14 +402,14 @@ memerr: fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ -register COLOR *scanline; -register float *zline; +register COLOR *scanline; +register float *zline; register char *sd; int xres, y, xstep; { static int nc = 0; /* number of calls */ int bl = xstep, b = xstep; - double z; + double z; register int i; z = pixvalue(scanline[0], 0, y); @@ -455,8 +437,8 @@ int xres, y, xstep; fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ -register COLOR *scanbar[]; -register float *zbar[]; +register COLOR *scanbar[]; +register float *zbar[]; int xres, y, ysize; { COLOR vline[MAXDIV+1]; @@ -486,16 +468,15 @@ int xres, y, ysize; int -fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ -register COLOR *colline; -register float *zline; +fillsample(colline, zline, x, y, xlen, ylen, b) /* fill interior points */ +register COLOR *colline; +register float *zline; int x, y; int xlen, ylen; int b; { - extern double fabs(); - double ratio; - double z; + double ratio; + double z; COLOR ctmp; int ncut; register int len; @@ -581,8 +562,11 @@ char *oldfile; error(WARNING, errmsg); return(0); } +#ifdef MSDOS + setmode(fileno(fp), O_BINARY); +#endif /* discard header */ - getheader(fp, NULL); + getheader(fp, NULL, NULL); /* get picture size */ if (!fscnresolu(&x, &y, fp)) { sprintf(errmsg, "bad recover file \"%s\"", oldfile);