--- ray/src/rt/rview.c 1991/05/03 15:43:32 1.13 +++ ray/src/rt/rview.c 1992/01/14 16:16:00 2.5 @@ -10,21 +10,21 @@ static char SCCSid[] = "$SunId$ LBL"; * 3/24/87 */ -#include "standard.h" +#include "ray.h" -#include "color.h" - #include "rpaint.h" #include -#include - #include 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 */ @@ -33,7 +33,14 @@ double exposure = 1.0; /* exposure for scene */ 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 directinvis = 0; /* sources invisible? */ +double srcsizerat = 0.; /* maximum ratio source size/dist. */ +double specthresh = .5; /* specular sampling threshold */ +double specjitter = 1.; /* specular sampling jitter */ + int maxdepth = 4; /* maximum recursion depth */ double minweight = 1e-2; /* minimum ray weight */ @@ -57,12 +64,11 @@ PNODE ptrunk; /* the base of our image */ RECT pframe; /* current frame boundaries */ int pdepth; /* image depth in current frame */ -static jmp_buf mainloop; /* longjmp back to main loop */ 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 */ @@ -119,15 +125,15 @@ rview() /* do a view */ char buf[32]; devopen(devname); /* open device */ - newimage(); /* set up image */ - setjmp(mainloop); + newimage(); /* start image (calls fillreserves) */ + for ( ; ; ) { /* quit in command() */ - while (hresolu <= 1<comout)(buf); rsample(); @@ -136,35 +142,30 @@ 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; - do - command("out of memory: "); - while (reserve_mem == NULL); - longjmp(mainloop, 1); } @@ -172,7 +173,6 @@ command(prompt) /* get/execute command */ char *prompt; { #define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) - double atof(); char inpbuf[256]; char *args; again: @@ -225,7 +225,16 @@ again: break; case 'm': /* move camera */ if (badcom("move")) +#ifdef MSTATS + { + if (badcom("memory")) + goto commerr; + printmemstats(stderr); + break; + } +#else goto commerr; +#endif getmove(args); break; case 'r': /* rotate/repaint */ @@ -242,7 +251,7 @@ again: goto commerr; getpivot(args); break; - case CTRL(R): /* redraw */ + case CTRL('R'): /* redraw */ redraw(); break; case 'w': /* write */ @@ -254,10 +263,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 */ + case CTRL('Z'): /* stop */ devclose(); kill(0, SIGTSTP); /* pc stops here */ @@ -300,10 +309,10 @@ rsample() /* sample the image */ ysiz = (((pframe.u-pframe.d)<inpready) + if (dev->inpready || errno == ENOMEM) goto escape; /* * Test super-pixel to the right. @@ -335,7 +344,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. @@ -390,7 +399,7 @@ 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)().