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.3 by greg, Wed Jun 7 21:00:54 1989 UTC vs.
Revision 2.15 by greg, Fri Dec 8 18:49:24 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1995 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 */
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 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
42 + double  salbedo = 0.;                   /* global scattering albedo */
43 + double  seccg = 0.;                     /* global scattering eccentricity */
44 + double  ssampdist = 0.;                 /* scatter sampling distance */
45 +
46 + double  specthresh = .3;                /* specular sampling threshold */
47 + double  specjitter = 1.;                /* specular sampling jitter */
48 +
49 + int  backvis = 1;                       /* back face visibility */
50 +
51   int  maxdepth = 4;                      /* maximum recursion depth */
52 < double  minweight = 1e-2;               /* minimum ray weight */
52 > double  minweight = 1e-2;               /* minimum ray weight */
53  
54   COLOR  ambval = BLKCOLOR;               /* ambient value */
55 < double  ambacc = 0.2;                   /* ambient accuracy */
56 < int  ambres = 64;                       /* ambient resolution */
55 > double  ambacc = 0.2;                   /* ambient accuracy */
56 > int  ambres = 8;                        /* ambient resolution */
57   int  ambdiv = 32;                       /* ambient divisions */
58   int  ambssamp = 0;                      /* ambient super-samples */
59   int  ambounce = 0;                      /* ambient bounces */
# Line 43 | Line 61 | char  *amblist[128];                   /* ambient include/exclude list
61   int  ambincl = -1;                      /* include == 1, exclude == 0 */
62  
63   int  greyscale = 0;                     /* map colors to brightness? */
64 < char  *devname = "X";                   /* output device name */
64 > char  *devname = dev_default;           /* output device name */
65  
66   struct driver  *dev = NULL;             /* driver functions */
67  
68 + char  rifname[128];                     /* rad input file name */
69 +
70   VIEW  oldview;                          /* previous view parameters */
71  
72   PNODE  ptrunk;                          /* the base of our image */
73   RECT  pframe;                           /* current frame boundaries */
74   int  pdepth;                            /* image depth in current frame */
75  
76 < #define  CTRL(c)        ('c'-'@')
76 > static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
77  
78 + #define RESERVE_AMT     32768           /* amount of memory to reserve */
79  
80 + #define  CTRL(c)        ((c)-'@')
81 +
82 +
83   quit(code)                      /* quit program */
84   int  code;
85   {
86 + #ifdef MSTATS
87 +        if (code == 2 && errno == ENOMEM)
88 +                printmemstats(stderr);
89 + #endif
90          devclose();
91          exit(code);
92   }
# Line 67 | Line 95 | int  code;
95   devopen(dname)                          /* open device driver */
96   char  *dname;
97   {
98 <        extern char  *progname;
99 <        char  *devargv[3];
98 >        extern char  *progname, *octname;
99 >        char  *id;
100          register int  i;
101 +
102 +        id = octname!=NULL ? octname : progname;
103                                                  /* check device table */
104          for (i = 0; devtable[i].name; i++)
105                  if (!strcmp(dname, devtable[i].name))
106 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
106 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
107                                  sprintf(errmsg, "cannot initialize %s", dname);
108                                  error(USER, errmsg);
109                          } else
110                                  return;
111 + #ifndef NIX                                                
112                                                  /* not there, try exec */
113 <        devargv[0] = dname;
83 <        devargv[1] = progname;
84 <        devargv[2] = NULL;
85 <        if ((dev = comm_init(devargv)) == NULL) {
113 >        if ((dev = comm_init(dname, id)) == NULL) {
114                  sprintf(errmsg, "cannot start device \"%s\"", dname);
115                  error(USER, errmsg);
116          }
117 + #endif
118   }
119  
120  
# Line 111 | Line 140 | rview()                                /* do a view */
140          char  buf[32];
141  
142          devopen(devname);               /* open device */
143 <        newimage();                     /* set up image */
143 >        newimage();                     /* start image (calls fillreserves) */
144  
145          for ( ; ; ) {                   /* quit in command() */
146 <                while (ourview.hresolu <= 1<<pdepth &&
118 <                                ourview.vresolu <= 1<<pdepth)
146 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
147                          command("done: ");
148 <
149 <                if (ourview.hresolu <= psample<<pdepth &&
150 <                                ourview.vresolu <= psample<<pdepth) {
148 >                while (reserve_mem == NULL)
149 >                        command("out of memory: ");
150 >                errno = 0;
151 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
152                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
153                          (*dev->comout)(buf);
154                          rsample();
155                  } else {
156                          sprintf(buf, "%d refining...\n", 1<<pdepth);
157                          (*dev->comout)(buf);
158 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
130 <                                        ourview.vresolu, pdepth+1);
158 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
159                  }
160 <                if (dev->inpready)
160 >                if (errno == ENOMEM)            /* ran out of memory */
161 >                        freereserves();
162 >                else if (dev->inpready)         /* noticed some input */
163                          command(": ");
164 <                else
164 >                else                            /* finished this depth */
165                          pdepth++;
166          }
167   }
168  
169  
170 + fillreserves()                  /* fill memory reserves */
171 + {
172 +        if (reserve_mem != NULL)
173 +                return;
174 +        reserve_mem = malloc(RESERVE_AMT);
175 + }
176 +
177 +
178 + freereserves()                  /* free memory reserves */
179 + {
180 +        if (reserve_mem == NULL)
181 +                return;
182 +        free(reserve_mem);
183 +        reserve_mem = NULL;
184 + }
185 +
186 +
187   command(prompt)                 /* get/execute command */
188   char  *prompt;
189   {
190 < #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
144 <        double  atof();
190 > #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
191          char  inpbuf[256];
192          char  *args;
193   again:
194 <        (*dev->comout)(prompt);                 /* get command + arguments */
149 <        (*dev->comin)(inpbuf);
194 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
195          for (args = inpbuf; *args && *args != ' '; args++)
196                  ;
197          if (*args) *args++ = '\0';
198          else *++args = '\0';
199          
200          switch (inpbuf[0]) {
201 <        case 'f':                               /* new frame */
202 <                if (badcom("frame"))
203 <                        goto commerr;
201 >        case 'f':                               /* new frame (or free mem.) */
202 >                if (badcom("frame")) {
203 >                        if (badcom("free"))
204 >                                goto commerr;
205 >                        free_objmem();
206 >                        break;
207 >                }
208                  getframe(args);
209                  break;
210          case 'v':                               /* view */
# Line 168 | Line 217 | again:
217                          goto commerr;
218                  lastview(args);
219                  break;
220 +        case 'V':                               /* save view */
221 +                if (badcom("V"))
222 +                        goto commerr;
223 +                saveview(args);
224 +                break;
225 +        case 'L':                               /* load view */
226 +                if (badcom("L"))
227 +                        goto commerr;
228 +                loadview(args);
229 +                break;
230          case 'e':                               /* exposure */
231                  if (badcom("exposure"))
232                          goto commerr;
233                  getexposure(args);
234                  break;
235          case 's':                               /* set a parameter */
236 <                if (badcom("set"))
236 >                if (badcom("set")) {
237 > #ifdef  SIGTSTP
238 >                        if (!badcom("stop"))
239 >                                goto dostop;
240 > #endif
241                          goto commerr;
242 +                }
243                  setparam(args);
244                  break;
245          case 'n':                               /* new picture */
# Line 193 | Line 257 | again:
257                          goto commerr;
258                  getaim(args);
259                  break;
260 <        case 'm':                               /* move camera */
260 >        case 'm':                               /* move camera (or memstats) */
261                  if (badcom("move"))
262 + #ifdef  MSTATS
263 +                {
264 +                        if (badcom("memory"))
265 +                                goto commerr;
266 +                        printmemstats(stderr);
267 +                        break;
268 +                }
269 + #else
270                          goto commerr;
271 + #endif
272                  getmove(args);
273                  break;
274 <        case 'r':                               /* rotate camera */
275 <                if (badcom("rotate"))
276 <                        goto commerr;
274 >        case 'r':                               /* rotate/repaint */
275 >                if (badcom("rotate")) {
276 >                        if (badcom("repaint")) {
277 >                                if (badcom("redraw"))
278 >                                        goto commerr;
279 >                                redraw();
280 >                                break;
281 >                        }
282 >                        getrepaint(args);
283 >                        break;
284 >                }
285                  getrotate(args);
286                  break;
287          case 'p':                               /* pivot view */
288 <                if (badcom("pivot"))
289 <                        goto commerr;
288 >                if (badcom("pivot")) {
289 >                        if (badcom("pause"))
290 >                                goto commerr;
291 >                        goto again;
292 >                }
293                  getpivot(args);
294                  break;
295 <        case CTRL(R):                           /* redraw */
295 >        case CTRL('R'):                         /* redraw */
296                  redraw();
297                  break;
298          case 'w':                               /* write */
# Line 220 | Line 304 | again:
304                  if (badcom("quit"))
305                          goto commerr;
306                  quit(0);
307 <        case CTRL(C):                           /* interrupt */
307 >        case CTRL('C'):                         /* interrupt */
308                  goto again;
309 < #ifdef  SIGTSTP
310 <        case CTRL(Z):                           /* stop */
309 > #ifdef  SIGTSTP
310 >        case CTRL('Z'):;                        /* stop */
311 > dostop:
312                  devclose();
313                  kill(0, SIGTSTP);
314                  /* pc stops here */
# Line 243 | Line 328 | commerr:
328                  error(COMMAND, errmsg);
329                  break;
330          }
331 < #undef  badcom
331 > #undef  badcom
332   }
333  
334  
# Line 253 | Line 338 | rsample()                      /* sample the image */
338          RECT  r;
339          PNODE  *p;
340          register RECT  *rl;
341 <        register PNODE  **pl;
341 >        register PNODE  **pl;
342          register int  x;
343          /*
344           *     We initialize the bottom row in the image at our current
345 <         * resolution.  During sampling, we check super-pixels to the
345 >         * resolution.  During sampling, we check super-pixels to the
346           * right and above by calling bigdiff().  If there is a significant
347           * difference, we subsample the super-pixels.  The testing process
348           * includes initialization of the next row.
349           */
350 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
351 <                        ourview.hresolu;
267 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
268 <                        ourview.vresolu;
350 >        xsiz = (((long)(pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
351 >        ysiz = (((long)(pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
352          rl = (RECT *)malloc(xsiz*sizeof(RECT));
353 +        if (rl == NULL)
354 +                return;
355          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
356 <        if (rl == NULL || pl == NULL)
357 <                error(SYSTEM, "out of memory in rsample");
356 >        if (pl == NULL) {
357 >                free((char *)rl);
358 >                return;
359 >        }
360          /*
361           * Initialize the bottom row.
362           */
363          rl[0].l = rl[0].d = 0;
364 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
364 >        rl[0].r = hresolu; rl[0].u = vresolu;
365          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
366          for (x = 1; x < xsiz; x++) {
367                  rl[x].l = rl[x].d = 0;
368 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
369 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
368 >                rl[x].r = hresolu; rl[x].u = vresolu;
369 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
370                                  pframe.d, &ptrunk, rl+x, pdepth);
371          }
372                                                  /* sample the image */
373          for (y = 0; /* y < ysiz */ ; y++) {
374                  for (x = 0; x < xsiz-1; x++) {
375 <                        if (dev->inpready)
375 >                        if (dev->inpready || errno == ENOMEM)
376                                  goto escape;
377                          /*
378                           * Test super-pixel to the right.
# Line 301 | Line 388 | rsample()                      /* sample the image */
388                  if (y >= ysiz-1)
389                          break;
390                  for (x = 0; x < xsiz; x++) {
391 <                        if (dev->inpready)
391 >                        if (dev->inpready || errno == ENOMEM)
392                                  goto escape;
393                          /*
394                           * Find super-pixel at this position in next row.
395                           */
396                          r.l = r.d = 0;
397 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
398 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
399 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
397 >                        r.r = hresolu; r.u = vresolu;
398 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
399 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
400                                          &ptrunk, &r, pdepth);
401                          /*
402                           * Test super-pixel in next row.
# Line 335 | Line 422 | escape:
422  
423   int
424   refine(p, xmin, ymin, xmax, ymax, pd)           /* refine a node */
425 < register PNODE  *p;
425 > register PNODE  *p;
426   int  xmin, ymin, xmax, ymax;
427   int  pd;
428   {
# Line 356 | Line 443 | int  pd;
443          if (p->kid == NULL) {                   /* subdivide */
444  
445                  if ((p->kid = newptree()) == NULL)
446 <                        error(SYSTEM, "out of memory in refine");
446 >                        return(0);
447                  /*
448                   *  The following paint order can leave a black pixel
449 <                 *  when redraw() is called in (*dev->paintr)().
449 >                 *  if redraw() is called in (*dev->paintr)().
450                   */
451                  if (p->x >= mx && p->y >= my)
452                          pcopy(p, p->kid+UR);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines