--- ray/src/rt/rpict.c 1998/06/17 13:29:55 2.51 +++ ray/src/rt/rpict.c 2003/02/25 02:47:23 2.53 @@ -1,13 +1,12 @@ -/* Copyright (c) 1996 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: rpict.c,v 2.53 2003/02/25 02:47:23 greg Exp $"; #endif - /* * rpict.c - routines and variables for picture generation. */ +#include "copyright.h" + #include "ray.h" #include @@ -28,8 +27,6 @@ extern time_t time(); #include "view.h" -#include "resolu.h" - #include "random.h" #include "paths.h" @@ -40,10 +37,16 @@ extern time_t time(); #define SIGCONT SIGIO #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 +58,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 +83,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 +94,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())) @@ -110,6 +110,8 @@ static VIEW lastview; /* the previous view input */ extern char *mktemp(); +void report(); + double pixvalue(); #ifdef NIX @@ -128,18 +130,22 @@ char *fname; #endif +void quit(code) /* quit program */ int code; { if (code) /* report status */ report(); +#ifndef NIX headclean(); /* delete header file */ pfclean(); /* clean up persist files */ +#endif exit(code); } #ifndef NIX +void report() /* report progress */ { extern char *myhostname(); @@ -180,6 +186,7 @@ report() /* report progress */ #endif } #else +void report() /* report progress */ { tlastrept = time((time_t *)NULL); @@ -190,6 +197,7 @@ report() /* report progress */ #endif +void rpict(seq, pout, zout, prvr) /* generate image(s) */ int seq; char *pout, *zout, *prvr; @@ -290,7 +298,7 @@ char *pout, *zout, *prvr; 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); @@ -358,6 +366,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)); @@ -368,7 +382,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; @@ -400,7 +414,7 @@ char *zfile, *oldfile; if (i >= vres) goto alldone; if (zfd != -1 && i > 0 && - lseek(zfd, (long)i*hres*sizeof(float), 0) < 0) + 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 */ @@ -469,10 +483,10 @@ 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; @@ -695,7 +709,7 @@ char *oldfile; } if (fflush(stdout) == EOF) goto writerr; - free((char *)scanline); + free((void *)scanline); fclose(fp); unlink(oldfile); return(y);