ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rview.c
(Generate patch)

Comparing ray/src/rt/rview.c (file contents):
Revision 1.4 by greg, Tue Jun 13 10:57:49 1989 UTC vs.
Revision 2.6 by greg, Thu Jan 16 12:05:26 1992 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     3/24/87
11   */
12  
13 < #include  "standard.h"
13 > #include  "ray.h"
14  
15 #include  "color.h"
16
15   #include  "rpaint.h"
16  
17   #include  <signal.h>
18  
19   #include  <ctype.h>
20  
21 < VIEW  ourview = STDVIEW(470);           /* viewing parameters */
21 > VIEW  ourview = STDVIEW;                /* viewing parameters */
22 > int  hresolu, vresolu;                  /* image resolution */
23  
24 + int  dimlist[MAXDIM];                   /* sampling dimensions */
25 + int  ndims = 0;                         /* number of sampling dimensions */
26 + int  samplendx = 0;                     /* index for this sample */
27 +
28   int  psample = 8;                       /* pixel sample size */
29   double  maxdiff = .15;                  /* max. sample difference */
30  
# Line 30 | Line 33 | double  exposure = 1.0;                        /* exposure for scene */
33   double  dstrsrc = 0.0;                  /* square source distribution */
34   double  shadthresh = .1;                /* shadow threshold */
35   double  shadcert = .25;                 /* shadow certainty */
36 + int  directrelay = 0;                   /* number of source relays */
37 + int  vspretest = 128;                   /* virtual source pretest density */
38 + int  directinvis = 0;                   /* sources invisible? */
39 + double  srcsizerat = 0.;                /* maximum ratio source size/dist. */
40  
41 + double  specthresh = .3;                /* specular sampling threshold */
42 + double  specjitter = 1.;                /* specular sampling jitter */
43 +
44   int  maxdepth = 4;                      /* maximum recursion depth */
45   double  minweight = 1e-2;               /* minimum ray weight */
46  
47   COLOR  ambval = BLKCOLOR;               /* ambient value */
48   double  ambacc = 0.2;                   /* ambient accuracy */
49 < int  ambres = 64;                       /* ambient resolution */
49 > int  ambres = 8;                        /* ambient resolution */
50   int  ambdiv = 32;                       /* ambient divisions */
51   int  ambssamp = 0;                      /* ambient super-samples */
52   int  ambounce = 0;                      /* ambient bounces */
# Line 44 | Line 54 | char  *amblist[128];                   /* ambient include/exclude list
54   int  ambincl = -1;                      /* include == 1, exclude == 0 */
55  
56   int  greyscale = 0;                     /* map colors to brightness? */
57 < char  *devname = "X";                   /* output device name */
57 > char  *devname = dev_default;           /* output device name */
58  
59   struct driver  *dev = NULL;             /* driver functions */
60  
# Line 54 | Line 64 | PNODE  ptrunk;                         /* the base of our image */
64   RECT  pframe;                           /* current frame boundaries */
65   int  pdepth;                            /* image depth in current frame */
66  
67 < #define  CTRL(c)        ('c'-'@')
67 > static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
68  
69 + #define RESERVE_AMT     32768           /* amount of memory to reserve */
70  
71 + #define  CTRL(c)        ((c)-'@')
72 +
73 +
74   quit(code)                      /* quit program */
75   int  code;
76   {
# Line 68 | Line 82 | int  code;
82   devopen(dname)                          /* open device driver */
83   char  *dname;
84   {
85 <        extern char  *progname;
86 <        char  *devargv[3];
85 >        extern char  *progname, *octname;
86 >        char  *id;
87          register int  i;
88 +
89 +        id = octname!=NULL ? octname : progname;
90                                                  /* check device table */
91          for (i = 0; devtable[i].name; i++)
92                  if (!strcmp(dname, devtable[i].name))
93 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
93 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
94                                  sprintf(errmsg, "cannot initialize %s", dname);
95                                  error(USER, errmsg);
96                          } else
97                                  return;
98                                                  /* not there, try exec */
99 <        devargv[0] = dname;
84 <        devargv[1] = progname;
85 <        devargv[2] = NULL;
86 <        if ((dev = comm_init(devargv)) == NULL) {
99 >        if ((dev = comm_init(dname, id)) == NULL) {
100                  sprintf(errmsg, "cannot start device \"%s\"", dname);
101                  error(USER, errmsg);
102          }
# Line 112 | Line 125 | rview()                                /* do a view */
125          char  buf[32];
126  
127          devopen(devname);               /* open device */
128 <        newimage();                     /* set up image */
128 >        newimage();                     /* start image (calls fillreserves) */
129  
130          for ( ; ; ) {                   /* quit in command() */
131 <                while (ourview.hresolu <= 1<<pdepth &&
119 <                                ourview.vresolu <= 1<<pdepth)
131 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
132                          command("done: ");
133 <
134 <                if (ourview.hresolu <= psample<<pdepth &&
135 <                                ourview.vresolu <= psample<<pdepth) {
133 >                while (reserve_mem == NULL)
134 >                        command("out of memory: ");
135 >                errno = 0;
136 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
137                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
138                          (*dev->comout)(buf);
139                          rsample();
140                  } else {
141                          sprintf(buf, "%d refining...\n", 1<<pdepth);
142                          (*dev->comout)(buf);
143 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
131 <                                        ourview.vresolu, pdepth+1);
143 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
144                  }
145 <                if (dev->inpready)
145 >                if (errno == ENOMEM)            /* ran out of memory */
146 >                        freereserves();
147 >                else if (dev->inpready)         /* noticed some input */
148                          command(": ");
149 <                else
149 >                else                            /* finished this depth */
150                          pdepth++;
151          }
152   }
153  
154  
155 + fillreserves()                  /* fill memory reserves */
156 + {
157 +        if (reserve_mem != NULL)
158 +                return;
159 +        reserve_mem = malloc(RESERVE_AMT);
160 + }
161 +
162 +
163 + freereserves()                  /* free memory reserves */
164 + {
165 +        if (reserve_mem == NULL)
166 +                return;
167 +        free(reserve_mem);
168 +        reserve_mem = NULL;
169 + }
170 +
171 +
172   command(prompt)                 /* get/execute command */
173   char  *prompt;
174   {
175   #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
145        double  atof();
176          char  inpbuf[256];
177          char  *args;
178   again:
179 <        (*dev->comout)(prompt);                 /* get command + arguments */
150 <        (*dev->comin)(inpbuf);
179 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
180          for (args = inpbuf; *args && *args != ' '; args++)
181                  ;
182          if (*args) *args++ = '\0';
# Line 196 | Line 225 | again:
225                  break;
226          case 'm':                               /* move camera */
227                  if (badcom("move"))
228 + #ifdef  MSTATS
229 +                {
230 +                        if (badcom("memory"))
231 +                                goto commerr;
232 +                        printmemstats(stderr);
233 +                        break;
234 +                }
235 + #else
236                          goto commerr;
237 + #endif
238                  getmove(args);
239                  break;
240 <        case 'r':                               /* rotate camera */
241 <                if (badcom("rotate"))
242 <                        goto commerr;
240 >        case 'r':                               /* rotate/repaint */
241 >                if (badcom("rotate")) {
242 >                        if (badcom("repaint"))
243 >                                goto commerr;
244 >                        getrepaint(args);
245 >                        break;
246 >                }
247                  getrotate(args);
248                  break;
249          case 'p':                               /* pivot view */
# Line 209 | Line 251 | again:
251                          goto commerr;
252                  getpivot(args);
253                  break;
254 <        case CTRL(R):                           /* redraw */
254 >        case CTRL('R'):                         /* redraw */
255                  redraw();
256                  break;
257          case 'w':                               /* write */
# Line 221 | Line 263 | again:
263                  if (badcom("quit"))
264                          goto commerr;
265                  quit(0);
266 <        case CTRL(C):                           /* interrupt */
266 >        case CTRL('C'):                         /* interrupt */
267                  goto again;
268   #ifdef  SIGTSTP
269 <        case CTRL(Z):                           /* stop */
269 >        case CTRL('Z'):                         /* stop */
270                  devclose();
271                  kill(0, SIGTSTP);
272                  /* pc stops here */
# Line 263 | Line 305 | rsample()                      /* sample the image */
305           * difference, we subsample the super-pixels.  The testing process
306           * includes initialization of the next row.
307           */
308 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
309 <                        ourview.hresolu;
268 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
269 <                        ourview.vresolu;
308 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
309 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
310          rl = (RECT *)malloc(xsiz*sizeof(RECT));
311 +        if (rl == NULL)
312 +                return;
313          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
314 <        if (rl == NULL || pl == NULL)
315 <                error(SYSTEM, "out of memory in rsample");
314 >        if (pl == NULL)
315 >                return;
316          /*
317           * Initialize the bottom row.
318           */
319          rl[0].l = rl[0].d = 0;
320 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
320 >        rl[0].r = hresolu; rl[0].u = vresolu;
321          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
322          for (x = 1; x < xsiz; x++) {
323                  rl[x].l = rl[x].d = 0;
324 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
325 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
324 >                rl[x].r = hresolu; rl[x].u = vresolu;
325 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
326                                  pframe.d, &ptrunk, rl+x, pdepth);
327          }
328                                                  /* sample the image */
329          for (y = 0; /* y < ysiz */ ; y++) {
330                  for (x = 0; x < xsiz-1; x++) {
331 <                        if (dev->inpready)
331 >                        if (dev->inpready || errno == ENOMEM)
332                                  goto escape;
333                          /*
334                           * Test super-pixel to the right.
# Line 302 | Line 344 | rsample()                      /* sample the image */
344                  if (y >= ysiz-1)
345                          break;
346                  for (x = 0; x < xsiz; x++) {
347 <                        if (dev->inpready)
347 >                        if (dev->inpready || errno == ENOMEM)
348                                  goto escape;
349                          /*
350                           * Find super-pixel at this position in next row.
351                           */
352                          r.l = r.d = 0;
353 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
354 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
355 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
353 >                        r.r = hresolu; r.u = vresolu;
354 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
355 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
356                                          &ptrunk, &r, pdepth);
357                          /*
358                           * Test super-pixel in next row.
# Line 357 | Line 399 | int  pd;
399          if (p->kid == NULL) {                   /* subdivide */
400  
401                  if ((p->kid = newptree()) == NULL)
402 <                        error(SYSTEM, "out of memory in refine");
402 >                        return(0);
403                  /*
404                   *  The following paint order can leave a black pixel
405                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines