--- ray/src/rt/rview.c 1990/03/09 14:00:06 1.11 +++ ray/src/rt/rview.c 1991/12/23 23:18:29 2.4 @@ -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,6 +21,10 @@ 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 */ @@ -31,6 +33,10 @@ 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. */ int maxdepth = 4; /* maximum recursion depth */ double minweight = 1e-2; /* minimum ray weight */ @@ -55,9 +61,13 @@ PNODE ptrunk; /* the base of our image */ RECT pframe; /* current frame boundaries */ int pdepth; /* image depth in current frame */ -#define CTRL(c) ('c'-'@') +static char *reserve_mem = NULL; /* pre-allocated reserve memory */ +#define RESERVE_AMT 32768 /* amount of memory to reserve */ +#define CTRL(c) ((c)-'@') + + quit(code) /* quit program */ int code; { @@ -112,15 +122,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(); @@ -129,19 +139,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++; } } +fillreserves() /* fill memory reserves */ +{ + if (reserve_mem != NULL) + return; + reserve_mem = malloc(RESERVE_AMT); +} + + +freereserves() /* free memory reserves */ +{ + if (reserve_mem == NULL) + return; + free(reserve_mem); + reserve_mem = NULL; +} + + command(prompt) /* get/execute command */ char *prompt; { #define badcom(s) strncmp(s, inpbuf, args-inpbuf-1) - double atof(); char inpbuf[256]; char *args; again: @@ -194,7 +222,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 */ @@ -211,7 +248,7 @@ again: goto commerr; getpivot(args); break; - case CTRL(R): /* redraw */ + case CTRL('R'): /* redraw */ redraw(); break; case 'w': /* write */ @@ -223,10 +260,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 */ @@ -268,9 +305,11 @@ rsample() /* sample the image */ xsiz = (((pframe.r-pframe.l)<inpready) + if (dev->inpready || errno == ENOMEM) goto escape; /* * Test super-pixel to the right. @@ -302,7 +341,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. @@ -357,7 +396,7 @@ int pd; if (p->kid == NULL) { /* subdivide */ if ((p->kid = newptree()) == NULL) - error(SYSTEM, "out of memory in refine"); + return(0); /* * The following paint order can leave a black pixel * when redraw() is called in (*dev->paintr)().