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.5 by greg, Mon Jul 10 15:21:25 1989 UTC vs.
Revision 2.28 by greg, Mon Jun 13 20:07:56 2005 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rview.c - routines and variables for interactive view generation.
6   *
7 < *     3/24/87
7 > *  External symbols declared in rpaint.h
8   */
9  
10 < #include  "standard.h"
10 > #include "copyright.h"
11  
12 < #include  "color.h"
12 > #include  <signal.h>
13 > #include  <ctype.h>
14  
15 + #include  "ray.h"
16   #include  "rpaint.h"
17  
19 #include  <signal.h>
18  
19 < #include  <ctype.h>
19 > CUBE  thescene;                         /* our scene */
20 > OBJECT  nsceneobjs;                     /* number of objects in our scene */
21  
22 < VIEW  ourview = STDVIEW(470);           /* viewing parameters */
22 > int  dimlist[MAXDIM];                   /* sampling dimensions */
23 > int  ndims = 0;                         /* number of sampling dimensions */
24 > int  samplendx = 0;                     /* index for this sample */
25  
26 + extern void  ambnotify();
27 + void  (*addobjnotify[])() = {ambnotify, NULL};
28 +
29 + VIEW  ourview = STDVIEW;                /* viewing parameters */
30 + int  hresolu, vresolu;                  /* image resolution */
31 +
32 + void  (*trace)() = NULL;                /* trace call */
33 +
34 + int  do_irrad = 0;                      /* compute irradiance? */
35 +
36 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
37 +
38   int  psample = 8;                       /* pixel sample size */
39 < double  maxdiff = .15;                  /* max. sample difference */
39 > double  maxdiff = .15;                  /* max. sample difference */
40  
41 < double  exposure = 1.0;                 /* exposure for scene */
41 > double  exposure = 1.0;                 /* exposure for scene */
42  
43 < double  dstrsrc = 0.0;                  /* square source distribution */
44 < double  shadthresh = .1;                /* shadow threshold */
45 < double  shadcert = .25;                 /* shadow certainty */
43 > double  dstrsrc = 0.0;                  /* square source distribution */
44 > double  shadthresh = .1;                /* shadow threshold */
45 > double  shadcert = .25;                 /* shadow certainty */
46 > int  directrelay = 0;                   /* number of source relays */
47 > int  vspretest = 128;                   /* virtual source pretest density */
48 > int  directvis = 1;                     /* sources visible? */
49 > double  srcsizerat = 0.;                /* maximum ratio source size/dist. */
50  
51 < int  maxdepth = 4;                      /* maximum recursion depth */
52 < double  minweight = 1e-2;               /* minimum ray weight */
51 > COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
52 > COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
53 > double  seccg = 0.;                     /* global scattering eccentricity */
54 > double  ssampdist = 0.;                 /* scatter sampling distance */
55  
56 + double  specthresh = .3;                /* specular sampling threshold */
57 + double  specjitter = 1.;                /* specular sampling jitter */
58 +
59 + int  backvis = 1;                       /* back face visibility */
60 +
61 + int  maxdepth = 6;                      /* maximum recursion depth */
62 + double  minweight = 1e-2;               /* minimum ray weight */
63 +
64 + char  *ambfile = NULL;                  /* ambient file name */
65   COLOR  ambval = BLKCOLOR;               /* ambient value */
66 < double  ambacc = 0.2;                   /* ambient accuracy */
67 < int  ambres = 8;                        /* ambient resolution */
68 < int  ambdiv = 32;                       /* ambient divisions */
69 < int  ambssamp = 0;                      /* ambient super-samples */
66 > int  ambvwt = 0;                        /* initial weight for ambient value */
67 > double  ambacc = 0.3;                   /* ambient accuracy */
68 > int  ambres = 32;                       /* ambient resolution */
69 > int  ambdiv = 256;                      /* ambient divisions */
70 > int  ambssamp = 64;                     /* ambient super-samples */
71   int  ambounce = 0;                      /* ambient bounces */
72 < char  *amblist[128];                    /* ambient include/exclude list */
72 > char  *amblist[AMBLLEN];                /* ambient include/exclude list */
73   int  ambincl = -1;                      /* include == 1, exclude == 0 */
74  
75   int  greyscale = 0;                     /* map colors to brightness? */
76 < char  *devname = "X";                   /* output device name */
76 > char  *dvcname = dev_default;           /* output device name */
77  
78   struct driver  *dev = NULL;             /* driver functions */
79  
80 + char  rifname[128];                     /* rad input file name */
81 +
82   VIEW  oldview;                          /* previous view parameters */
83  
84   PNODE  ptrunk;                          /* the base of our image */
85   RECT  pframe;                           /* current frame boundaries */
86   int  pdepth;                            /* image depth in current frame */
87  
88 < #define  CTRL(c)        ('c'-'@')
88 > static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
89  
90 + #define RESERVE_AMT     32768           /* amount of memory to reserve */
91  
92 + #define  CTRL(c)        ((c)-'@')
93 +
94 +
95 + void
96   quit(code)                      /* quit program */
97   int  code;
98   {
99 + #ifdef MSTATS
100 +        if (code == 2 && errno == ENOMEM)
101 +                printmemstats(stderr);
102 + #endif
103          devclose();
104          exit(code);
105   }
106  
107  
108 + void
109   devopen(dname)                          /* open device driver */
110   char  *dname;
111   {
112 <        extern char  *progname;
113 <        char  *devargv[3];
112 >        extern char  *progname, *octname;
113 >        char  *id;
114          register int  i;
115 +
116 +        id = octname!=NULL ? octname : progname;
117                                                  /* check device table */
118          for (i = 0; devtable[i].name; i++)
119 <                if (!strcmp(dname, devtable[i].name))
120 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
119 >                if (!strcmp(dname, devtable[i].name)) {
120 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
121                                  sprintf(errmsg, "cannot initialize %s", dname);
122                                  error(USER, errmsg);
123                          } else
124                                  return;
125 +                }
126                                                  /* not there, try exec */
127 <        devargv[0] = dname;
84 <        devargv[1] = progname;
85 <        devargv[2] = NULL;
86 <        if ((dev = comm_init(devargv)) == NULL) {
127 >        if ((dev = comm_init(dname, id)) == NULL) {
128                  sprintf(errmsg, "cannot start device \"%s\"", dname);
129                  error(USER, errmsg);
130          }
131   }
132  
133  
134 + void
135   devclose()                              /* close our device */
136   {
137          if (dev != NULL)
# Line 98 | Line 140 | devclose()                             /* close our device */
140   }
141  
142  
143 + void
144   printdevices()                          /* print list of output devices */
145   {
146          register int  i;
# Line 107 | Line 150 | printdevices()                         /* print list of output devices */
150   }
151  
152  
153 + void
154   rview()                         /* do a view */
155   {
156          char  buf[32];
157  
158 <        devopen(devname);               /* open device */
159 <        newimage();                     /* set up image */
158 >        devopen(dvcname);               /* open device */
159 >        newimage();                     /* start image (calls fillreserves) */
160  
161          for ( ; ; ) {                   /* quit in command() */
162 <                while (ourview.hresolu <= 1<<pdepth &&
119 <                                ourview.vresolu <= 1<<pdepth)
162 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
163                          command("done: ");
164 <
165 <                if (ourview.hresolu <= psample<<pdepth &&
166 <                                ourview.vresolu <= psample<<pdepth) {
164 >                while (reserve_mem == NULL)
165 >                        command("out of memory: ");
166 >                errno = 0;
167 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
168                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
169                          (*dev->comout)(buf);
170                          rsample();
171                  } else {
172                          sprintf(buf, "%d refining...\n", 1<<pdepth);
173                          (*dev->comout)(buf);
174 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
131 <                                        ourview.vresolu, pdepth+1);
174 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
175                  }
176 <                if (dev->inpready)
176 >                if (errno == ENOMEM)            /* ran out of memory */
177 >                        freereserves();
178 >                else if (dev->inpready)         /* noticed some input */
179                          command(": ");
180 <                else
180 >                else                            /* finished this depth */
181                          pdepth++;
182          }
183   }
184  
185  
186 + void
187 + fillreserves()                  /* fill memory reserves */
188 + {
189 +        if (reserve_mem != NULL)
190 +                return;
191 +        reserve_mem = (char *)malloc(RESERVE_AMT);
192 + }
193 +
194 +
195 + void
196 + freereserves()                  /* free memory reserves */
197 + {
198 +        if (reserve_mem == NULL)
199 +                return;
200 +        free(reserve_mem);
201 +        reserve_mem = NULL;
202 + }
203 +
204 +
205 + void
206   command(prompt)                 /* get/execute command */
207   char  *prompt;
208   {
209 < #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
145 <        double  atof();
209 > #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
210          char  inpbuf[256];
211          char  *args;
212   again:
213 <        (*dev->comout)(prompt);                 /* get command + arguments */
150 <        (*dev->comin)(inpbuf);
213 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
214          for (args = inpbuf; *args && *args != ' '; args++)
215                  ;
216          if (*args) *args++ = '\0';
217          else *++args = '\0';
218          
219          switch (inpbuf[0]) {
220 <        case 'f':                               /* new frame */
221 <                if (badcom("frame"))
222 <                        goto commerr;
220 >        case 'f':                               /* new frame (|focus|free) */
221 >                if (badcom("frame")) {
222 >                        if (badcom("focus")) {
223 >                                if (badcom("free"))
224 >                                        goto commerr;
225 >                                free_objmem();
226 >                                break;
227 >                        }
228 >                        getfocus(args);
229 >                        break;
230 >                }
231                  getframe(args);
232                  break;
233          case 'v':                               /* view */
# Line 169 | Line 240 | again:
240                          goto commerr;
241                  lastview(args);
242                  break;
243 +        case 'V':                               /* save view */
244 +                if (badcom("V"))
245 +                        goto commerr;
246 +                saveview(args);
247 +                break;
248 +        case 'L':                               /* load view */
249 +                if (badcom("L"))
250 +                        goto commerr;
251 +                loadview(args);
252 +                break;
253          case 'e':                               /* exposure */
254                  if (badcom("exposure"))
255                          goto commerr;
256                  getexposure(args);
257                  break;
258          case 's':                               /* set a parameter */
259 <                if (badcom("set"))
259 >                if (badcom("set")) {
260 > #ifdef  SIGTSTP
261 >                        if (!badcom("stop"))
262 >                                goto dostop;
263 > #endif
264                          goto commerr;
265 +                }
266                  setparam(args);
267                  break;
268          case 'n':                               /* new picture */
# Line 194 | Line 280 | again:
280                          goto commerr;
281                  getaim(args);
282                  break;
283 <        case 'm':                               /* move camera */
283 >        case 'm':                               /* move camera (or memstats) */
284                  if (badcom("move"))
285 + #ifdef  MSTATS
286 +                {
287 +                        if (badcom("memory"))
288 +                                goto commerr;
289 +                        printmemstats(stderr);
290 +                        break;
291 +                }
292 + #else
293                          goto commerr;
294 + #endif
295                  getmove(args);
296                  break;
297 <        case 'r':                               /* rotate camera */
298 <                if (badcom("rotate"))
299 <                        goto commerr;
297 >        case 'r':                               /* rotate/repaint */
298 >                if (badcom("rotate")) {
299 >                        if (badcom("repaint")) {
300 >                                if (badcom("redraw"))
301 >                                        goto commerr;
302 >                                redraw();
303 >                                break;
304 >                        }
305 >                        getrepaint(args);
306 >                        break;
307 >                }
308                  getrotate(args);
309                  break;
310          case 'p':                               /* pivot view */
311 <                if (badcom("pivot"))
312 <                        goto commerr;
311 >                if (badcom("pivot")) {
312 >                        if (badcom("pause"))
313 >                                goto commerr;
314 >                        goto again;
315 >                }
316                  getpivot(args);
317                  break;
318 <        case CTRL(R):                           /* redraw */
318 >        case CTRL('R'):                         /* redraw */
319                  redraw();
320                  break;
321          case 'w':                               /* write */
# Line 221 | Line 327 | again:
327                  if (badcom("quit"))
328                          goto commerr;
329                  quit(0);
330 <        case CTRL(C):                           /* interrupt */
330 >        case CTRL('C'):                         /* interrupt */
331                  goto again;
332 < #ifdef  SIGTSTP
333 <        case CTRL(Z):                           /* stop */
332 > #ifdef  SIGTSTP
333 >        case CTRL('Z'):;                        /* stop */
334 > dostop:
335                  devclose();
336                  kill(0, SIGTSTP);
337                  /* pc stops here */
338 <                devopen(devname);
338 >                devopen(dvcname);
339                  redraw();
340                  break;
341   #endif
# Line 244 | Line 351 | commerr:
351                  error(COMMAND, errmsg);
352                  break;
353          }
354 < #undef  badcom
354 > #undef  badcom
355   }
356  
357  
358 + void
359   rsample()                       /* sample the image */
360   {
361          int  xsiz, ysiz, y;
362          RECT  r;
363          PNODE  *p;
364          register RECT  *rl;
365 <        register PNODE  **pl;
365 >        register PNODE  **pl;
366          register int  x;
367          /*
368           *     We initialize the bottom row in the image at our current
369 <         * resolution.  During sampling, we check super-pixels to the
369 >         * resolution.  During sampling, we check super-pixels to the
370           * right and above by calling bigdiff().  If there is a significant
371           * difference, we subsample the super-pixels.  The testing process
372           * includes initialization of the next row.
373           */
374 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
375 <                        ourview.hresolu;
268 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
269 <                        ourview.vresolu;
374 >        xsiz = (((long)(pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
375 >        ysiz = (((long)(pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
376          rl = (RECT *)malloc(xsiz*sizeof(RECT));
377 +        if (rl == NULL)
378 +                return;
379          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
380 <        if (rl == NULL || pl == NULL)
381 <                error(SYSTEM, "out of memory in rsample");
380 >        if (pl == NULL) {
381 >                free((void *)rl);
382 >                return;
383 >        }
384          /*
385           * Initialize the bottom row.
386           */
387          rl[0].l = rl[0].d = 0;
388 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
388 >        rl[0].r = hresolu; rl[0].u = vresolu;
389          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
390          for (x = 1; x < xsiz; x++) {
391                  rl[x].l = rl[x].d = 0;
392 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
393 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
392 >                rl[x].r = hresolu; rl[x].u = vresolu;
393 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
394                                  pframe.d, &ptrunk, rl+x, pdepth);
395          }
396                                                  /* sample the image */
397          for (y = 0; /* y < ysiz */ ; y++) {
398                  for (x = 0; x < xsiz-1; x++) {
399 <                        if (dev->inpready)
399 >                        if (dev->inpready || errno == ENOMEM)
400                                  goto escape;
401                          /*
402                           * Test super-pixel to the right.
# Line 302 | Line 412 | rsample()                      /* sample the image */
412                  if (y >= ysiz-1)
413                          break;
414                  for (x = 0; x < xsiz; x++) {
415 <                        if (dev->inpready)
415 >                        if (dev->inpready || errno == ENOMEM)
416                                  goto escape;
417                          /*
418                           * Find super-pixel at this position in next row.
419                           */
420                          r.l = r.d = 0;
421 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
422 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
423 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
421 >                        r.r = hresolu; r.u = vresolu;
422 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
423 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
424                                          &ptrunk, &r, pdepth);
425                          /*
426                           * Test super-pixel in next row.
# Line 329 | Line 439 | rsample()                      /* sample the image */
439                  }
440          }
441   escape:
442 <        free((char *)rl);
443 <        free((char *)pl);
442 >        free((void *)rl);
443 >        free((void *)pl);
444   }
445  
446  
447   int
448   refine(p, xmin, ymin, xmax, ymax, pd)           /* refine a node */
449 < register PNODE  *p;
449 > register PNODE  *p;
450   int  xmin, ymin, xmax, ymax;
451   int  pd;
452   {
# Line 357 | Line 467 | int  pd;
467          if (p->kid == NULL) {                   /* subdivide */
468  
469                  if ((p->kid = newptree()) == NULL)
470 <                        error(SYSTEM, "out of memory in refine");
470 >                        return(0);
471                  /*
472                   *  The following paint order can leave a black pixel
473 <                 *  when redraw() is called in (*dev->paintr)().
473 >                 *  if redraw() is called in (*dev->paintr)().
474                   */
475                  if (p->x >= mx && p->y >= my)
476                          pcopy(p, p->kid+UR);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines