--- ray/src/rt/rview.c 1991/05/03 15:22:24 1.12 +++ ray/src/rt/rview.c 1993/08/25 13:44:17 2.11 @@ -1,4 +1,4 @@ -/* Copyright (c) 1987 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,10 +10,8 @@ static char SCCSid[] = "$SunId$ LBL"; * 3/24/87 */ -#include "standard.h" +#include "ray.h" -#include "color.h" - #include "rpaint.h" #include @@ -23,20 +21,31 @@ static char SCCSid[] = "$SunId$ LBL"; VIEW ourview = STDVIEW; /* viewing parameters */ int hresolu, vresolu; /* image resolution */ +int dimlist[MAXDIM]; /* sampling dimensions */ +int ndims = 0; /* number of sampling dimensions */ +int samplendx = 0; /* index for this sample */ + int psample = 8; /* pixel sample size */ -double maxdiff = .15; /* max. sample difference */ +double maxdiff = .15; /* max. sample difference */ -double exposure = 1.0; /* exposure for scene */ +double exposure = 1.0; /* exposure for scene */ -double dstrsrc = 0.0; /* square source distribution */ -double shadthresh = .1; /* shadow threshold */ -double shadcert = .25; /* shadow certainty */ +double dstrsrc = 0.0; /* square source distribution */ +double shadthresh = .1; /* shadow threshold */ +double shadcert = .25; /* shadow certainty */ +int directrelay = 0; /* number of source relays */ +int vspretest = 128; /* virtual source pretest density */ +int directvis = 1; /* sources visible? */ +double srcsizerat = 0.; /* maximum ratio source size/dist. */ +double specthresh = .3; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ + int maxdepth = 4; /* maximum recursion depth */ -double minweight = 1e-2; /* minimum ray weight */ +double minweight = 1e-2; /* minimum ray weight */ COLOR ambval = BLKCOLOR; /* ambient value */ -double ambacc = 0.2; /* ambient accuracy */ +double ambacc = 0.2; /* ambient accuracy */ int ambres = 8; /* ambient resolution */ int ambdiv = 32; /* ambient divisions */ int ambssamp = 0; /* ambient super-samples */ @@ -49,6 +58,8 @@ char *devname = dev_default; /* output device name * struct driver *dev = NULL; /* driver functions */ +char rifname[128]; /* rad input file name */ + VIEW oldview; /* previous view parameters */ PNODE ptrunk; /* the base of our image */ @@ -57,14 +68,18 @@ int pdepth; /* image depth in current frame */ static char *reserve_mem = NULL; /* pre-allocated reserve memory */ -#define RESERVE_AMT 8192 /* amount of memory to reserve */ +#define RESERVE_AMT 32768 /* amount of memory to reserve */ -#define CTRL(c) ('c'-'@') +#define CTRL(c) ((c)-'@') quit(code) /* quit program */ int code; { +#ifdef MSTATS + if (code == 2 && errno == ENOMEM) + printmemstats(stderr); +#endif devclose(); exit(code); } @@ -86,11 +101,13 @@ char *dname; error(USER, errmsg); } else return; +#ifndef NIX /* not there, try exec */ if ((dev = comm_init(dname, id)) == NULL) { sprintf(errmsg, "cannot start device \"%s\"", dname); error(USER, errmsg); } +#endif } @@ -116,15 +133,15 @@ rview() /* do a view */ char buf[32]; devopen(devname); /* open device */ - newimage(); /* set up image */ + newimage(); /* start image (calls fillreserves) */ for ( ; ; ) { /* quit in command() */ - while (hresolu <= 1<comout)(buf); rsample(); @@ -133,41 +150,37 @@ rview() /* do a view */ (*dev->comout)(buf); refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); } - if (dev->inpready) + if (errno == ENOMEM) /* ran out of memory */ + freereserves(); + else if (dev->inpready) /* noticed some input */ command(": "); - else + else /* finished this depth */ pdepth++; } } -memreserve() /* fill memory reserves */ +fillreserves() /* fill memory reserves */ { if (reserve_mem != NULL) - return; /* got some already */ + return; reserve_mem = malloc(RESERVE_AMT); } -memerror(detail) /* try and rescue a memory error */ -char *detail; +freereserves() /* free memory reserves */ { - if (reserve_mem == NULL) { - sprintf(errmsg, "out of memory %s", detail); - error(SYSTEM, errmsg); - } + if (reserve_mem == NULL) + return; free(reserve_mem); reserve_mem = NULL; - for ( ; ; ) - command("out of memory: "); } command(prompt) /* get/execute command */ char *prompt; { -#define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) - double atof(); +#define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) char inpbuf[256]; char *args; again: @@ -178,9 +191,13 @@ again: else *++args = '\0'; switch (inpbuf[0]) { - case 'f': /* new frame */ - if (badcom("frame")) - goto commerr; + case 'f': /* new frame (or free mem.) */ + if (badcom("frame")) { + if (badcom("free")) + goto commerr; + free_objmem(); + break; + } getframe(args); break; case 'v': /* view */ @@ -193,6 +210,16 @@ again: goto commerr; lastview(args); break; + case 'V': /* save view */ + if (badcom("V")) + goto commerr; + saveview(args); + break; + case 'L': /* load view */ + if (badcom("L")) + goto commerr; + loadview(args); + break; case 'e': /* exposure */ if (badcom("exposure")) goto commerr; @@ -218,9 +245,18 @@ again: goto commerr; getaim(args); break; - case 'm': /* move camera */ + case 'm': /* move camera (or memstats) */ if (badcom("move")) +#ifdef MSTATS + { + if (badcom("memory")) + goto commerr; + printmemstats(stderr); + break; + } +#else goto commerr; +#endif getmove(args); break; case 'r': /* rotate/repaint */ @@ -237,7 +273,7 @@ again: goto commerr; getpivot(args); break; - case CTRL(R): /* redraw */ + case CTRL('R'): /* redraw */ redraw(); break; case 'w': /* write */ @@ -249,10 +285,10 @@ again: if (badcom("quit")) goto commerr; quit(0); - case CTRL(C): /* interrupt */ + case CTRL('C'): /* interrupt */ goto again; -#ifdef SIGTSTP - case CTRL(Z): /* stop */ +#ifdef SIGTSTP + case CTRL('Z'): /* stop */ devclose(); kill(0, SIGTSTP); /* pc stops here */ @@ -272,7 +308,7 @@ commerr: error(COMMAND, errmsg); break; } -#undef badcom +#undef badcom } @@ -282,11 +318,11 @@ rsample() /* sample the image */ RECT r; PNODE *p; register RECT *rl; - register PNODE **pl; + register PNODE **pl; register int x; /* * We initialize the bottom row in the image at our current - * resolution. During sampling, we check super-pixels to the + * resolution. During sampling, we check super-pixels to the * right and above by calling bigdiff(). If there is a significant * difference, we subsample the super-pixels. The testing process * includes initialization of the next row. @@ -295,10 +331,12 @@ rsample() /* sample the image */ ysiz = (((pframe.u-pframe.d)<inpready) + if (dev->inpready || errno == ENOMEM) goto escape; /* * Test super-pixel to the right. @@ -330,7 +368,7 @@ rsample() /* sample the image */ if (y >= ysiz-1) break; for (x = 0; x < xsiz; x++) { - if (dev->inpready) + if (dev->inpready || errno == ENOMEM) goto escape; /* * Find super-pixel at this position in next row. @@ -364,7 +402,7 @@ escape: int refine(p, xmin, ymin, xmax, ymax, pd) /* refine a node */ -register PNODE *p; +register PNODE *p; int xmin, ymin, xmax, ymax; int pd; { @@ -385,10 +423,10 @@ int pd; if (p->kid == NULL) { /* subdivide */ if ((p->kid = newptree()) == NULL) - memerror("in refine"); + return(0); /* * The following paint order can leave a black pixel - * when redraw() is called in (*dev->paintr)(). + * if redraw() is called in (*dev->paintr)(). */ if (p->x >= mx && p->y >= my) pcopy(p, p->kid+UR);