--- ray/src/rt/rpict.c 1998/03/03 19:14:28 2.49 +++ ray/src/rt/rpict.c 2003/06/30 14:59:12 2.57 @@ -1,18 +1,17 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id"; #endif - /* * rpict.c - routines and variables for picture generation. */ +#include "copyright.h" + #include "ray.h" #include -#ifndef NIX +#ifndef NON_POSIX #ifdef BSD #include #include @@ -22,28 +21,33 @@ static char SCCSid[] = "$SunId$ LBL"; #endif #endif -extern time_t time(); - +#include #include +#include "platform.h" #include "view.h" - -#include "resolu.h" - #include "random.h" - #include "paths.h" + #define RFTEMPLATE "rfXXXXXX" #ifndef SIGCONT +#ifdef SIGIO /* XXX can we live without this? */ #define SIGCONT SIGIO #endif +#endif +CUBE thescene; /* our scene */ +OBJECT nsceneobjs; /* number of objects in our scene */ + int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx; /* sample index number */ +extern void ambnotify(); +void (*addobjnotify[])() = {ambnotify, NULL}; + VIEW ourview = STDVIEW; /* view parameters */ int hresolu = 512; /* horizontal resolution */ int vresolu = 512; /* vertical resolution */ @@ -55,6 +59,10 @@ double dstrpix = 0.67; /* square pixel distribution double mblur = 0.; /* motion blur parameter */ +void (*trace)() = NULL; /* trace call */ + +int do_irrad = 0; /* compute irradiance? */ + double dstrsrc = 0.0; /* square source distribution */ double shadthresh = .05; /* shadow threshold */ double shadcert = .5; /* shadow certainty */ @@ -76,6 +84,7 @@ int backvis = 1; /* back face visibility */ int maxdepth = 6; /* maximum recursion depth */ double minweight = 5e-3; /* minimum ray weight */ +char *ambfile = NULL; /* ambient file name */ COLOR ambval = BLKCOLOR; /* ambient value */ int ambvwt = 0; /* initial weight for ambient value */ double ambacc = 0.2; /* ambient accuracy */ @@ -86,20 +95,12 @@ 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 */ - time_t tlastrept = 0L; /* time at last report */ +time_t tstart; /* starting time */ -extern time_t tstart; /* starting time */ - -extern unsigned long nrays; /* number of rays traced */ - #define MAXDIV 16 /* maximum sample size */ #define pixjitter() (.5+dstrpix*(.5-frandom())) @@ -108,11 +109,13 @@ int hres, vres; /* resolution for this frame */ static VIEW lastview; /* the previous view input */ -extern char *mktemp(); +extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ +void report(); + double pixvalue(); -#ifdef NIX +#ifdef RHAS_ACCESS #define file_exists(f) (access(f,F_OK)==0) #else #include @@ -128,18 +131,22 @@ char *fname; #endif +void quit(code) /* quit program */ int code; { if (code) /* report status */ report(); +#ifndef NON_POSIX headclean(); /* delete header file */ pfclean(); /* clean up persist files */ +#endif exit(code); } -#ifndef NIX +#ifndef NON_POSIX +void report() /* report progress */ { extern char *myhostname(); @@ -175,11 +182,12 @@ report() /* report progress */ nrays, pctdone, u/3600., s/3600., (tlastrept-tstart)/3600., myhostname()); eputs(errmsg); -#ifndef BSD +#ifdef SIGCONT signal(SIGCONT, report); #endif } #else +void report() /* report progress */ { tlastrept = time((time_t *)NULL); @@ -190,6 +198,7 @@ report() /* report progress */ #endif +void rpict(seq, pout, zout, prvr) /* generate image(s) */ int seq; char *pout, *zout, *prvr; @@ -205,7 +214,6 @@ char *pout, *zout, *prvr; * sequenced file naming. */ { - extern char *rindex(), *strncpy(), *strcat(), *strcpy(); char fbuf[128], fbuf2[128]; int npicts; register char *cp; @@ -232,6 +240,7 @@ char *pout, *zout, *prvr; for ( ; seq < rn; seq++) if (nextview(stdin) == EOF) error(USER, "unexpected EOF on view input"); + setview(&ourview); prvr = fbuf; /* mark for renaming */ } if (pout != NULL & prvr != NULL) { @@ -273,6 +282,7 @@ char *pout, *zout, *prvr; fbuf); error(USER, errmsg); } + setview(&ourview); continue; /* don't clobber */ } if (freopen(fbuf, "w", stdout) == NULL) { @@ -280,15 +290,13 @@ char *pout, *zout, *prvr; "cannot open output file \"%s\"", fbuf); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); -#endif + SET_FILE_BINARY(stdout); dupheader(); } hres = hresolu; vres = vresolu; pa = pixaspect; if (prvr != NULL) if (viewfile(prvr, &ourview, &rs) <= 0 - || rs.or != PIXSTANDARD) { + || rs.rt != PIXSTANDARD) { sprintf(errmsg, "cannot recover view parameters from \"%s\"", prvr); error(WARNING, errmsg); @@ -346,7 +354,6 @@ FILE *fp; render(zfile, oldfile) /* render the scene */ char *zfile, *oldfile; { - extern long lseek(); COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ float *zbar[MAXDIV+1]; /* z values */ char *sampdens; /* previous sample density */ @@ -357,6 +364,12 @@ char *zfile, *oldfile; COLOR *colptr; float *zptr; register int i; + /* check for empty image */ + if (hres <= 0 || vres <= 0) { + error(WARNING, "empty output picture"); + fprtresolu(0, 0, stdout); + return; + } /* allocate scanlines */ for (i = 0; i <= psample; i++) { scanbar[i] = (COLOR *)malloc(hres*sizeof(COLOR)); @@ -367,7 +380,7 @@ char *zfile, *oldfile; ystep = (psample*99+70)/140; if (hstep > 2) { i = hres/hstep + 2; - if ((sampdens = malloc(i)) == NULL) + if ((sampdens = (char *)malloc(i)) == NULL) goto memerr; while (i--) sampdens[i] = hstep; @@ -379,9 +392,7 @@ char *zfile, *oldfile; sprintf(errmsg, "cannot open z-file \"%s\"", zfile); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(zfd, O_BINARY); -#endif + SET_FD_BINARY(zfd); for (i = 0; i <= psample; i++) { zbar[i] = (float *)malloc(hres*sizeof(float)); if (zbar[i] == NULL) @@ -399,15 +410,15 @@ char *zfile, *oldfile; if (i >= vres) goto alldone; if (zfd != -1 && i > 0 && - lseek(zfd, (long)i*hres*sizeof(float), 0) == -1) + lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) error(SYSTEM, "z-file seek error in render"); pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ report(); -#ifndef BSD +#ifdef SIGCONT else -#endif signal(SIGCONT, report); +#endif ypos = vres-1 - i; /* initialize sampling */ if (directvis) init_drawsources(psample); @@ -433,7 +444,7 @@ char *zfile, *oldfile; if (directvis) /* add bitty sources */ drawsources(scanbar, zbar, 0, hres, ypos, ystep); /* write it out */ -#ifndef BSD +#ifdef SIGCONT signal(SIGCONT, SIG_IGN); /* don't interrupt writes */ #endif for (i = ystep; i > 0; i--) { @@ -450,13 +461,15 @@ char *zfile, *oldfile; pctdone = 100.0*(vres-1-ypos)/vres; if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) report(); -#ifndef BSD +#ifdef SIGCONT else signal(SIGCONT, report); #endif } /* clean up */ +#ifdef SIGCONT signal(SIGCONT, SIG_IGN); +#endif if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float)) < hres*sizeof(float)) goto writerr; @@ -468,16 +481,18 @@ alldone: if (close(zfd) == -1) goto writerr; for (i = 0; i <= psample; i++) - free((char *)zbar[i]); + free((void *)zbar[i]); } for (i = 0; i <= psample; i++) - free((char *)scanbar[i]); + free((void *)scanbar[i]); if (sampdens != NULL) free(sampdens); pctdone = 100.0; if (ralrm > 0) report(); +#ifdef SIGCONT signal(SIGCONT, SIG_DFL); +#endif return; writerr: error(SYSTEM, "write error in render"); @@ -663,9 +678,7 @@ char *oldfile; error(WARNING, errmsg); goto gotzip; } -#ifdef MSDOS - setmode(fileno(fp), O_BINARY); -#endif + SET_FILE_BINARY(fp); /* discard header */ getheader(fp, NULL, NULL); /* get picture size */ @@ -694,7 +707,7 @@ char *oldfile; } if (fflush(stdout) == EOF) goto writerr; - free((char *)scanline); + free((void *)scanline); fclose(fp); unlink(oldfile); return(y);