--- ray/src/rt/rview.c 1990/01/08 13:38:12 1.9 +++ ray/src/rt/rview.c 1992/01/14 16:16:00 2.5 @@ -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,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 */ @@ -45,7 +54,7 @@ char *amblist[128]; /* ambient include/exclude list int ambincl = -1; /* include == 1, exclude == 0 */ int greyscale = 0; /* map colors to brightness? */ -char *devname = "X"; /* output device name */ +char *devname = dev_default; /* output device name */ struct driver *dev = NULL; /* driver functions */ @@ -55,9 +64,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 +125,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,24 +142,41 @@ 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: - (*dev->comout)(prompt); /* get command + arguments */ - (*dev->comin)(inpbuf); + (*dev->comin)(inpbuf, prompt); /* get command + arguments */ for (args = inpbuf; *args && *args != ' '; args++) ; if (*args) *args++ = '\0'; @@ -195,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 */ @@ -212,7 +251,7 @@ again: goto commerr; getpivot(args); break; - case CTRL(R): /* redraw */ + case CTRL('R'): /* redraw */ redraw(); break; case 'w': /* write */ @@ -224,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 */ @@ -269,9 +308,11 @@ rsample() /* sample the image */ xsiz = (((pframe.r-pframe.l)<inpready) + if (dev->inpready || errno == ENOMEM) goto escape; /* * Test super-pixel to the right. @@ -303,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. @@ -358,7 +399,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)().