--- ray/src/rt/rpict.c 2003/06/30 14:59:12 2.57 +++ ray/src/rt/rpict.c 2004/10/23 18:55:53 2.71 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id"; +static const char RCSid[] = "$Id: rpict.c,v 2.71 2004/10/23 18:55:53 schorsch Exp $"; #endif /* * rpict.c - routines and variables for picture generation. @@ -7,8 +7,6 @@ static const char RCSid[] = "$Id"; #include "copyright.h" -#include "ray.h" - #include #ifndef NON_POSIX @@ -25,9 +23,13 @@ static const char RCSid[] = "$Id"; #include #include "platform.h" +#include "ray.h" +#include "paths.h" +#include "ambient.h" #include "view.h" #include "random.h" #include "paths.h" +#include "rtmisc.h" /* myhostname() */ #define RFTEMPLATE "rfXXXXXX" @@ -45,7 +47,7 @@ int dimlist[MAXDIM]; /* sampling dimensions */ int ndims = 0; /* number of sampling dimensions */ int samplendx; /* sample index number */ -extern void ambnotify(); +//extern void ambnotify(); void (*addobjnotify[])() = {ambnotify, NULL}; VIEW ourview = STDVIEW; /* view parameters */ @@ -81,16 +83,16 @@ double specjitter = 1.; /* specular sampling jitter * int backvis = 1; /* back face visibility */ -int maxdepth = 6; /* maximum recursion depth */ -double minweight = 5e-3; /* minimum ray weight */ +int maxdepth = 7; /* maximum recursion depth */ +double minweight = 4e-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 */ -int ambres = 32; /* ambient resolution */ -int ambdiv = 128; /* ambient divisions */ -int ambssamp = 0; /* ambient super-samples */ +int ambres = 64; /* ambient resolution */ +int ambdiv = 512; /* ambient divisions */ +int ambssamp = 128; /* ambient super-samples */ int ambounce = 0; /* ambient bounces */ char *amblist[128]; /* ambient include/exclude list */ int ambincl = -1; /* include == 1, exclude == 0 */ @@ -109,15 +111,26 @@ int hres, vres; /* resolution for this frame */ static VIEW lastview; /* the previous view input */ -extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ +//extern char *mktemp(); /* XXX should be in stdlib.h or unistd.h */ -void report(); +//double pixvalue(); -double pixvalue(); +static void report(int); +static int nextview(FILE *fp); +static void render(char *zfile, char *oldfile); +static void fillscanline(COLOR *scanline, float *zline, char *sd, int xres, + int y, int xstep); +static void fillscanbar(COLOR *scanbar[], float *zbar[], int xres, + int y, int ysize); +static int fillsample(COLOR *colline, float *zline, int x, int y, + int xlen, int ylen, int b); +static double pixvalue(COLOR col, int x, int y); +static int salvage(char *oldfile); +static int pixnumber(int x, int y, int xres, int yres); -#ifdef RHAS_ACCESS -#define file_exists(f) (access(f,F_OK)==0) -#else + + +#ifdef RHAS_STAT #include #include int @@ -128,6 +141,8 @@ char *fname; if (stat(fname, &sbuf) < 0) return(0); return((sbuf.st_mode & S_IFREG) != 0); } +#else +#define file_exists(f) (access(f,F_OK)==0) #endif @@ -136,7 +151,7 @@ quit(code) /* quit program */ int code; { if (code) /* report status */ - report(); + report(0); #ifndef NON_POSIX headclean(); /* delete header file */ pfclean(); /* clean up persist files */ @@ -146,10 +161,9 @@ int code; #ifndef NON_POSIX -void -report() /* report progress */ +static void +report(int dummy) /* report progress */ { - extern char *myhostname(); double u, s; #ifdef BSD struct rusage rubuf; @@ -187,8 +201,8 @@ report() /* report progress */ #endif } #else -void -report() /* report progress */ +static void +report(int dummy) /* report progress */ { tlastrept = time((time_t *)NULL); sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n", @@ -198,10 +212,13 @@ report() /* report progress */ #endif -void -rpict(seq, pout, zout, prvr) /* generate image(s) */ -int seq; -char *pout, *zout, *prvr; +extern void +rpict( /* generate image(s) */ + int seq, + char *pout, + char *zout, + char *prvr +) /* * If seq is greater than zero, then we will render a sequence of * images based on view parameter strings read from the standard input. @@ -243,7 +260,7 @@ char *pout, *zout, *prvr; setview(&ourview); prvr = fbuf; /* mark for renaming */ } - if (pout != NULL & prvr != NULL) { + if ((pout != NULL) & (prvr != NULL)) { sprintf(fbuf, pout, seq); if (!strcmp(prvr, fbuf)) { /* rename */ strcpy(fbuf2, fbuf); @@ -253,7 +270,7 @@ char *pout, *zout, *prvr; cp--; strcpy(cp, RFTEMPLATE); prvr = mktemp(fbuf2); - if (rename(fbuf, prvr) < 0) + if (rename(fbuf, prvr) < 0) { if (errno == ENOENT) { /* ghost file */ sprintf(errmsg, "new output file \"%s\"", @@ -266,6 +283,7 @@ char *pout, *zout, *prvr; fbuf, prvr); error(SYSTEM, errmsg); } + } } } npicts = 0; /* render sequence */ @@ -294,9 +312,8 @@ char *pout, *zout, *prvr; dupheader(); } hres = hresolu; vres = vresolu; pa = pixaspect; - if (prvr != NULL) - if (viewfile(prvr, &ourview, &rs) <= 0 - || rs.rt != PIXSTANDARD) { + if (prvr != NULL) { + if (viewfile(prvr, &ourview, &rs) <= 0) { sprintf(errmsg, "cannot recover view parameters from \"%s\"", prvr); error(WARNING, errmsg); @@ -305,6 +322,7 @@ char *pout, *zout, *prvr; hres = scanlen(&rs); vres = numscans(&rs); } + } if ((cp = setview(&ourview)) != NULL) error(USER, cp); normaspect(viewaspect(&ourview), &pa, &hres, &vres); @@ -322,6 +340,7 @@ char *pout, *zout, *prvr; putchar('\n'); if (pa < .99 || pa > 1.01) fputaspect(pa, stdout); + fputnow(stdout); fputformat(COLRFMT, stdout); putchar('\n'); if (zout != NULL) @@ -338,12 +357,14 @@ char *pout, *zout, *prvr; } -nextview(fp) /* get next view from fp */ -FILE *fp; +static int +nextview( /* get next view from fp */ + FILE *fp +) { char linebuf[256]; - copystruct(&lastview, &ourview); + lastview = ourview; while (fgets(linebuf, sizeof(linebuf), fp) != NULL) if (isview(linebuf) && sscanview(&ourview, linebuf) > 0) return(0); @@ -351,8 +372,11 @@ FILE *fp; } -render(zfile, oldfile) /* render the scene */ -char *zfile, *oldfile; +static void +render( /* render the scene */ + char *zfile, + char *oldfile +) { COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ float *zbar[MAXDIV+1]; /* z values */ @@ -410,11 +434,11 @@ char *zfile, *oldfile; if (i >= vres) goto alldone; if (zfd != -1 && i > 0 && - lseek(zfd, (off_t)i*hres*sizeof(float), 0) < 0) + lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0) error(SYSTEM, "z-file seek error in render"); pctdone = 100.0*i/vres; if (ralrm > 0) /* report init stats */ - report(); + report(0); #ifdef SIGCONT else signal(SIGCONT, report); @@ -460,7 +484,7 @@ char *zfile, *oldfile; /* record progress */ pctdone = 100.0*(vres-1-ypos)/vres; if (ralrm > 0 && time((time_t *)NULL) >= tlastrept+ralrm) - report(); + report(0); #ifdef SIGCONT else signal(SIGCONT, report); @@ -489,7 +513,7 @@ alldone: free(sampdens); pctdone = 100.0; if (ralrm > 0) - report(); + report(0); #ifdef SIGCONT signal(SIGCONT, SIG_DFL); #endif @@ -501,11 +525,15 @@ memerr: } -fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ -register COLOR *scanline; -register float *zline; -register char *sd; -int xres, y, xstep; +static void +fillscanline( /* fill scan at y */ + register COLOR *scanline, + register float *zline, + register char *sd, + int xres, + int y, + int xstep +) { static int nc = 0; /* number of calls */ int bl = xstep, b = xstep; @@ -536,10 +564,14 @@ int xres, y, xstep; } -fillscanbar(scanbar, zbar, xres, y, ysize) /* fill interior */ -register COLOR *scanbar[]; -register float *zbar[]; -int xres, y, ysize; +static void +fillscanbar( /* fill interior */ + register COLOR *scanbar[], + register float *zbar[], + int xres, + int y, + int ysize +) { COLOR vline[MAXDIV+1]; float zline[MAXDIV+1]; @@ -565,13 +597,16 @@ int xres, y, ysize; } -int -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; +static int +fillsample( /* fill interior points */ + register COLOR *colline, + register float *zline, + int x, + int y, + int xlen, + int ylen, + int b +) { double ratio; double z; @@ -618,14 +653,16 @@ int b; } -double -pixvalue(col, x, y) /* compute pixel value */ -COLOR col; /* returned color */ -int x, y; /* pixel position */ +static double +pixvalue( /* compute pixel value */ + COLOR col, /* returned color */ + int x, /* pixel position */ + int y +) { RAY thisray; FVECT lorg, ldir; - double hpos, vpos, lmax, d; + double hpos, vpos, lmax; /* compute view ray */ hpos = (x+pixjitter())/hres; vpos = (y+pixjitter())/vres; @@ -662,9 +699,10 @@ int x, y; /* pixel position */ } -int -salvage(oldfile) /* salvage scanlines from killed program */ -char *oldfile; +static int +salvage( /* salvage scanlines from killed program */ + char *oldfile +) { COLR *scanline; FILE *fp; @@ -718,13 +756,17 @@ gotzip: writerr: sprintf(errmsg, "write error during recovery of \"%s\"", oldfile); error(SYSTEM, errmsg); + return -1; /* pro forma return */ } -int -pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ -register int x, y; -int xres, yres; +static int +pixnumber( /* compute pixel index (brushed) */ + register int x, + register int y, + int xres, + int yres +) { x -= y; while (x < 0)