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.9 by greg, Thu Nov 19 20:25:55 1992 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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 */
29 > double  maxdiff = .15;                  /* max. sample difference */
30  
31 < double  exposure = 1.0;                 /* exposure for scene */
31 > double  exposure = 1.0;                 /* exposure for scene */
32  
33 < double  dstrsrc = 0.0;                  /* square source distribution */
34 < double  shadthresh = .1;                /* shadow threshold */
35 < double  shadcert = .25;                 /* shadow certainty */
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  directvis = 1;                     /* sources visible? */
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 */
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 */
48 > double  ambacc = 0.2;                   /* ambient accuracy */
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 + #ifndef NIX                                                
99                                                  /* not there, try exec */
100 <        devargv[0] = dname;
84 <        devargv[1] = progname;
85 <        devargv[2] = NULL;
86 <        if ((dev = comm_init(devargv)) == NULL) {
100 >        if ((dev = comm_init(dname, id)) == NULL) {
101                  sprintf(errmsg, "cannot start device \"%s\"", dname);
102                  error(USER, errmsg);
103          }
104 + #endif
105   }
106  
107  
# Line 112 | Line 127 | rview()                                /* do a view */
127          char  buf[32];
128  
129          devopen(devname);               /* open device */
130 <        newimage();                     /* set up image */
130 >        newimage();                     /* start image (calls fillreserves) */
131  
132          for ( ; ; ) {                   /* quit in command() */
133 <                while (ourview.hresolu <= 1<<pdepth &&
119 <                                ourview.vresolu <= 1<<pdepth)
133 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
134                          command("done: ");
135 <
136 <                if (ourview.hresolu <= psample<<pdepth &&
137 <                                ourview.vresolu <= psample<<pdepth) {
135 >                while (reserve_mem == NULL)
136 >                        command("out of memory: ");
137 >                errno = 0;
138 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
139                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
140                          (*dev->comout)(buf);
141                          rsample();
142                  } else {
143                          sprintf(buf, "%d refining...\n", 1<<pdepth);
144                          (*dev->comout)(buf);
145 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
131 <                                        ourview.vresolu, pdepth+1);
145 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
146                  }
147 <                if (dev->inpready)
147 >                if (errno == ENOMEM)            /* ran out of memory */
148 >                        freereserves();
149 >                else if (dev->inpready)         /* noticed some input */
150                          command(": ");
151 <                else
151 >                else                            /* finished this depth */
152                          pdepth++;
153          }
154   }
155  
156  
157 + fillreserves()                  /* fill memory reserves */
158 + {
159 +        if (reserve_mem != NULL)
160 +                return;
161 +        reserve_mem = malloc(RESERVE_AMT);
162 + }
163 +
164 +
165 + freereserves()                  /* free memory reserves */
166 + {
167 +        if (reserve_mem == NULL)
168 +                return;
169 +        free(reserve_mem);
170 +        reserve_mem = NULL;
171 + }
172 +
173 +
174   command(prompt)                 /* get/execute command */
175   char  *prompt;
176   {
177 < #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
145 <        double  atof();
177 > #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
178          char  inpbuf[256];
179          char  *args;
180   again:
181 <        (*dev->comout)(prompt);                 /* get command + arguments */
150 <        (*dev->comin)(inpbuf);
181 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
182          for (args = inpbuf; *args && *args != ' '; args++)
183                  ;
184          if (*args) *args++ = '\0';
# Line 196 | Line 227 | again:
227                  break;
228          case 'm':                               /* move camera */
229                  if (badcom("move"))
230 + #ifdef  MSTATS
231 +                {
232 +                        if (badcom("memory"))
233 +                                goto commerr;
234 +                        printmemstats(stderr);
235 +                        break;
236 +                }
237 + #else
238                          goto commerr;
239 + #endif
240                  getmove(args);
241                  break;
242 <        case 'r':                               /* rotate camera */
243 <                if (badcom("rotate"))
244 <                        goto commerr;
242 >        case 'r':                               /* rotate/repaint */
243 >                if (badcom("rotate")) {
244 >                        if (badcom("repaint"))
245 >                                goto commerr;
246 >                        getrepaint(args);
247 >                        break;
248 >                }
249                  getrotate(args);
250                  break;
251          case 'p':                               /* pivot view */
# Line 209 | Line 253 | again:
253                          goto commerr;
254                  getpivot(args);
255                  break;
256 <        case CTRL(R):                           /* redraw */
256 >        case CTRL('R'):                         /* redraw */
257                  redraw();
258                  break;
259          case 'w':                               /* write */
# Line 221 | Line 265 | again:
265                  if (badcom("quit"))
266                          goto commerr;
267                  quit(0);
268 <        case CTRL(C):                           /* interrupt */
268 >        case CTRL('C'):                         /* interrupt */
269                  goto again;
270 < #ifdef  SIGTSTP
271 <        case CTRL(Z):                           /* stop */
270 > #ifdef  SIGTSTP
271 >        case CTRL('Z'):                         /* stop */
272                  devclose();
273                  kill(0, SIGTSTP);
274                  /* pc stops here */
# Line 244 | Line 288 | commerr:
288                  error(COMMAND, errmsg);
289                  break;
290          }
291 < #undef  badcom
291 > #undef  badcom
292   }
293  
294  
# Line 254 | Line 298 | rsample()                      /* sample the image */
298          RECT  r;
299          PNODE  *p;
300          register RECT  *rl;
301 <        register PNODE  **pl;
301 >        register PNODE  **pl;
302          register int  x;
303          /*
304           *     We initialize the bottom row in the image at our current
305 <         * resolution.  During sampling, we check super-pixels to the
305 >         * resolution.  During sampling, we check super-pixels to the
306           * right and above by calling bigdiff().  If there is a significant
307           * difference, we subsample the super-pixels.  The testing process
308           * includes initialization of the next row.
309           */
310 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
311 <                        ourview.hresolu;
268 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
269 <                        ourview.vresolu;
310 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
311 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
312          rl = (RECT *)malloc(xsiz*sizeof(RECT));
313 +        if (rl == NULL)
314 +                return;
315          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
316 <        if (rl == NULL || pl == NULL)
317 <                error(SYSTEM, "out of memory in rsample");
316 >        if (pl == NULL) {
317 >                free((char *)rl);
318 >                return;
319 >        }
320          /*
321           * Initialize the bottom row.
322           */
323          rl[0].l = rl[0].d = 0;
324 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
324 >        rl[0].r = hresolu; rl[0].u = vresolu;
325          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
326          for (x = 1; x < xsiz; x++) {
327                  rl[x].l = rl[x].d = 0;
328 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
329 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
328 >                rl[x].r = hresolu; rl[x].u = vresolu;
329 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
330                                  pframe.d, &ptrunk, rl+x, pdepth);
331          }
332                                                  /* sample the image */
333          for (y = 0; /* y < ysiz */ ; y++) {
334                  for (x = 0; x < xsiz-1; x++) {
335 <                        if (dev->inpready)
335 >                        if (dev->inpready || errno == ENOMEM)
336                                  goto escape;
337                          /*
338                           * Test super-pixel to the right.
# Line 302 | Line 348 | rsample()                      /* sample the image */
348                  if (y >= ysiz-1)
349                          break;
350                  for (x = 0; x < xsiz; x++) {
351 <                        if (dev->inpready)
351 >                        if (dev->inpready || errno == ENOMEM)
352                                  goto escape;
353                          /*
354                           * Find super-pixel at this position in next row.
355                           */
356                          r.l = r.d = 0;
357 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
358 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
359 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
357 >                        r.r = hresolu; r.u = vresolu;
358 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
359 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
360                                          &ptrunk, &r, pdepth);
361                          /*
362                           * Test super-pixel in next row.
# Line 336 | Line 382 | escape:
382  
383   int
384   refine(p, xmin, ymin, xmax, ymax, pd)           /* refine a node */
385 < register PNODE  *p;
385 > register PNODE  *p;
386   int  xmin, ymin, xmax, ymax;
387   int  pd;
388   {
# Line 357 | Line 403 | int  pd;
403          if (p->kid == NULL) {                   /* subdivide */
404  
405                  if ((p->kid = newptree()) == NULL)
406 <                        error(SYSTEM, "out of memory in refine");
406 >                        return(0);
407                  /*
408                   *  The following paint order can leave a black pixel
409 <                 *  when redraw() is called in (*dev->paintr)().
409 >                 *  if redraw() is called in (*dev->paintr)().
410                   */
411                  if (p->x >= mx && p->y >= my)
412                          pcopy(p, p->kid+UR);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines