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 2.22 by greg, Thu Jul 3 15:00:19 2003 UTC vs.
Revision 2.30 by greg, Fri Aug 22 17:39:26 2008 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  "ray.h"
16   #include  "rpaint.h"
17  
18
19 CUBE  thescene;                         /* our scene */
20 OBJECT  nsceneobjs;                     /* number of objects in our scene */
21
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  psample = 8;                       /* pixel sample size */
37 double  maxdiff = .15;                  /* max. sample difference */
38
39 double  exposure = 1.0;                 /* exposure for scene */
40
41 double  dstrsrc = 0.0;                  /* square source distribution */
42 double  shadthresh = .1;                /* shadow threshold */
43 double  shadcert = .25;                 /* shadow certainty */
44 int  directrelay = 0;                   /* number of source relays */
45 int  vspretest = 128;                   /* virtual source pretest density */
46 int  directvis = 1;                     /* sources visible? */
47 double  srcsizerat = 0.;                /* maximum ratio source size/dist. */
48
49 COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
50 COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
51 double  seccg = 0.;                     /* global scattering eccentricity */
52 double  ssampdist = 0.;                 /* scatter sampling distance */
53
54 double  specthresh = .3;                /* specular sampling threshold */
55 double  specjitter = 1.;                /* specular sampling jitter */
56
57 int  backvis = 1;                       /* back face visibility */
58
59 int  maxdepth = 4;                      /* maximum recursion depth */
60 double  minweight = 1e-2;               /* minimum ray weight */
61
62 char  *ambfile = NULL;                  /* ambient file name */
63 COLOR  ambval = BLKCOLOR;               /* ambient value */
64 int  ambvwt = 0;                        /* initial weight for ambient value */
65 double  ambacc = 0.2;                   /* ambient accuracy */
66 int  ambres = 8;                        /* ambient resolution */
67 int  ambdiv = 32;                       /* ambient divisions */
68 int  ambssamp = 0;                      /* ambient super-samples */
69 int  ambounce = 0;                      /* ambient bounces */
70 char  *amblist[128];                    /* ambient include/exclude list */
71 int  ambincl = -1;                      /* include == 1, exclude == 0 */
72
73 int  greyscale = 0;                     /* map colors to brightness? */
74 char  *dvcname = dev_default;           /* output device name */
75
76 struct driver  *dev = NULL;             /* driver functions */
77
78 char  rifname[128];                     /* rad input file name */
79
80 VIEW  oldview;                          /* previous view parameters */
81
82 PNODE  ptrunk;                          /* the base of our image */
83 RECT  pframe;                           /* current frame boundaries */
84 int  pdepth;                            /* image depth in current frame */
85
86 static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
87
88 #define RESERVE_AMT     32768           /* amount of memory to reserve */
89
18   #define  CTRL(c)        ((c)-'@')
19  
20  
21   void
22 < quit(code)                      /* quit program */
23 < int  code;
22 > devopen(                                /* open device driver */
23 >        char  *dname
24 > )
25   {
97 #ifdef MSTATS
98        if (code == 2 && errno == ENOMEM)
99                printmemstats(stderr);
100 #endif
101        devclose();
102        exit(code);
103 }
104
105
106 void
107 devopen(dname)                          /* open device driver */
108 char  *dname;
109 {
26          extern char  *progname, *octname;
27          char  *id;
28 <        register int  i;
28 >        int  i;
29  
30          id = octname!=NULL ? octname : progname;
31                                                  /* check device table */
32          for (i = 0; devtable[i].name; i++)
33 <                if (!strcmp(dname, devtable[i].name))
33 >                if (!strcmp(dname, devtable[i].name)) {
34                          if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
35                                  sprintf(errmsg, "cannot initialize %s", dname);
36                                  error(USER, errmsg);
37                          } else
38                                  return;
39 +                }
40                                                  /* not there, try exec */
41          if ((dev = comm_init(dname, id)) == NULL) {
42                  sprintf(errmsg, "cannot start device \"%s\"", dname);
# Line 129 | Line 46 | char  *dname;
46  
47  
48   void
49 < devclose()                              /* close our device */
49 > devclose(void)                          /* close our device */
50   {
51          if (dev != NULL)
52                  (*dev->close)();
# Line 138 | Line 55 | devclose()                             /* close our device */
55  
56  
57   void
58 < printdevices()                          /* print list of output devices */
58 > printdevices(void)                      /* print list of output devices */
59   {
60 <        register int  i;
60 >        int  i;
61  
62          for (i = 0; devtable[i].name; i++)
63                  printf("%-16s # %s\n", devtable[i].name, devtable[i].descrip);
# Line 148 | Line 65 | printdevices()                         /* print list of output devices */
65  
66  
67   void
68 < rview()                         /* do a view */
68 > rview(void)                             /* do a view */
69   {
70          char  buf[32];
71  
72          devopen(dvcname);               /* open device */
73 <        newimage();                     /* start image (calls fillreserves) */
73 >        newimage(NULL);                 /* start image */
74  
75          for ( ; ; ) {                   /* quit in command() */
76                  while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
77                          command("done: ");
161                while (reserve_mem == NULL)
162                        command("out of memory: ");
78                  errno = 0;
79                  if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
80                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
# Line 168 | Line 83 | rview()                                /* do a view */
83                  } else {
84                          sprintf(buf, "%d refining...\n", 1<<pdepth);
85                          (*dev->comout)(buf);
86 <                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
86 >                        refine(&ptrunk, pdepth+1);
87                  }
88 <                if (errno == ENOMEM)            /* ran out of memory */
174 <                        freereserves();
175 <                else if (dev->inpready)         /* noticed some input */
88 >                if (dev->inpready)              /* noticed some input */
89                          command(": ");
90                  else                            /* finished this depth */
91                          pdepth++;
# Line 181 | Line 94 | rview()                                /* do a view */
94  
95  
96   void
97 < fillreserves()                  /* fill memory reserves */
97 > command(                        /* get/execute command */
98 >        char  *prompt
99 > )
100   {
186        if (reserve_mem != NULL)
187                return;
188        reserve_mem = (char *)malloc(RESERVE_AMT);
189 }
190
191
192 void
193 freereserves()                  /* free memory reserves */
194 {
195        if (reserve_mem == NULL)
196                return;
197        free(reserve_mem);
198        reserve_mem = NULL;
199 }
200
201
202 void
203 command(prompt)                 /* get/execute command */
204 char  *prompt;
205 {
101   #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
102          char  inpbuf[256];
103          char  *args;
# Line 212 | Line 107 | again:
107                  ;
108          if (*args) *args++ = '\0';
109          else *++args = '\0';
110 +
111 +        if (waitrays() < 0)                     /* clear ray queue */
112 +                quit(1);
113          
114          switch (inpbuf[0]) {
115 <        case 'f':                               /* new frame (or free mem.) */
115 >        case 'f':                               /* new frame (|focus|free) */
116                  if (badcom("frame")) {
117 <                        if (badcom("free"))
118 <                                goto commerr;
119 <                        free_objmem();
117 >                        if (badcom("focus")) {
118 >                                if (badcom("free"))
119 >                                        goto commerr;
120 >                                free_objmem();
121 >                                break;
122 >                        }
123 >                        getfocus(args);
124                          break;
125                  }
126                  getframe(args);
# Line 261 | Line 163 | again:
163          case 'n':                               /* new picture */
164                  if (badcom("new"))
165                          goto commerr;
166 <                newimage();
166 >                newimage(args);
167                  break;
168          case 't':                               /* trace a ray */
169                  if (badcom("trace"))
# Line 349 | Line 251 | commerr:
251  
252  
253   void
254 < rsample()                       /* sample the image */
254 > rsample(void)                   /* sample the image */
255   {
256          int  xsiz, ysiz, y;
355        RECT  r;
257          PNODE  *p;
258 <        register RECT  *rl;
259 <        register PNODE  **pl;
359 <        register int  x;
258 >        PNODE   **pl;
259 >        int  x;
260          /*
261           *     We initialize the bottom row in the image at our current
262           * resolution.  During sampling, we check super-pixels to the
# Line 366 | Line 266 | rsample()                      /* sample the image */
266           */
267          xsiz = (((long)(pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
268          ysiz = (((long)(pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
369        rl = (RECT *)malloc(xsiz*sizeof(RECT));
370        if (rl == NULL)
371                return;
269          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
270 <        if (pl == NULL) {
374 <                free((void *)rl);
270 >        if (pl == NULL)
271                  return;
376        }
272          /*
273           * Initialize the bottom row.
274           */
275 <        rl[0].l = rl[0].d = 0;
381 <        rl[0].r = hresolu; rl[0].u = vresolu;
382 <        pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
275 >        pl[0] = findrect(pframe.l, pframe.d, &ptrunk, pdepth);
276          for (x = 1; x < xsiz; x++) {
384                rl[x].l = rl[x].d = 0;
385                rl[x].r = hresolu; rl[x].u = vresolu;
277                  pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
278 <                                pframe.d, &ptrunk, rl+x, pdepth);
278 >                                pframe.d, &ptrunk, pdepth);
279          }
280                                                  /* sample the image */
281          for (y = 0; /* y < ysiz */ ; y++) {
# Line 396 | Line 287 | rsample()                      /* sample the image */
287                           */
288                          if (pl[x] != pl[x+1] && bigdiff(pl[x]->v,
289                                          pl[x+1]->v, maxdiff)) {
290 <                                refine(pl[x], rl[x].l, rl[x].d,
291 <                                                rl[x].r, rl[x].u, 1);
401 <                                refine(pl[x+1], rl[x+1].l, rl[x+1].d,
402 <                                                rl[x+1].r, rl[x+1].u, 1);
290 >                                refine(pl[x], 1);
291 >                                refine(pl[x+1], 1);
292                          }
293                  }
294                  if (y >= ysiz-1)
# Line 410 | Line 299 | rsample()                      /* sample the image */
299                          /*
300                           * Find super-pixel at this position in next row.
301                           */
413                        r.l = r.d = 0;
414                        r.r = hresolu; r.u = vresolu;
302                          p = findrect(pframe.l+((x*hresolu)>>pdepth),
303                                  pframe.d+(((y+1)*vresolu)>>pdepth),
304 <                                        &ptrunk, &r, pdepth);
304 >                                        &ptrunk, pdepth);
305                          /*
306                           * Test super-pixel in next row.
307                           */
308                          if (pl[x] != p && bigdiff(pl[x]->v, p->v, maxdiff)) {
309 <                                refine(pl[x], rl[x].l, rl[x].d,
310 <                                                rl[x].r, rl[x].u, 1);
424 <                                refine(p, r.l, r.d, r.r, r.u, 1);
309 >                                refine(pl[x], 1);
310 >                                refine(p, 1);
311                          }
312                          /*
313                           * Copy into super-pixel array.
314                           */
429                        rl[x].l = r.l; rl[x].d = r.d;
430                        rl[x].r = r.r; rl[x].u = r.u;
315                          pl[x] = p;
316                  }
317          }
318   escape:
435        free((void *)rl);
319          free((void *)pl);
320   }
321  
322  
323   int
324 < refine(p, xmin, ymin, xmax, ymax, pd)           /* refine a node */
325 < register PNODE  *p;
326 < int  xmin, ymin, xmax, ymax;
327 < int  pd;
324 > refine(                         /* refine a node */
325 >        PNODE   *p,
326 >        int  pd
327 > )
328   {
329          int  growth;
330          int  mx, my;
# Line 453 | Line 336 | int  pd;
336          if (pd <= 0)                            /* depth limit */
337                  return(0);
338  
339 <        mx = (xmin + xmax) >> 1;
340 <        my = (ymin + ymax) >> 1;
339 >        mx = (p->xmin + p->xmax) >> 1;
340 >        my = (p->ymin + p->ymax) >> 1;
341          growth = 0;
342  
343          if (p->kid == NULL) {                   /* subdivide */
344  
345                  if ((p->kid = newptree()) == NULL)
346                          return(0);
347 +
348 +                p->kid[UR].xmin = mx;
349 +                p->kid[UR].ymin = my;
350 +                p->kid[UR].xmax = p->xmax;
351 +                p->kid[UR].ymax = p->ymax;
352 +                p->kid[UL].xmin = p->xmin;
353 +                p->kid[UL].ymin = my;
354 +                p->kid[UL].xmax = mx;
355 +                p->kid[UL].ymax = p->ymax;
356 +                p->kid[DR].xmin = mx;
357 +                p->kid[DR].ymin = p->ymin;
358 +                p->kid[DR].xmax = p->xmax;
359 +                p->kid[DR].ymax = my;
360 +                p->kid[DL].xmin = p->xmin;
361 +                p->kid[DL].ymin = p->ymin;
362 +                p->kid[DL].xmax = mx;
363 +                p->kid[DL].ymax = my;
364                  /*
365                   *  The following paint order can leave a black pixel
366                   *  if redraw() is called in (*dev->paintr)().
367                   */
368                  if (p->x >= mx && p->y >= my)
369                          pcopy(p, p->kid+UR);
370 <                else
371 <                        paint(p->kid+UR, mx, my, xmax, ymax);
370 >                else if (paint(p->kid+UR) < 0)
371 >                        quit(1);
372                  if (p->x < mx && p->y >= my)
373                          pcopy(p, p->kid+UL);
374 <                else
375 <                        paint(p->kid+UL, xmin, my, mx, ymax);
374 >                else if (paint(p->kid+UL) < 0)
375 >                        quit(1);
376                  if (p->x >= mx && p->y < my)
377                          pcopy(p, p->kid+DR);
378 <                else
379 <                        paint(p->kid+DR, mx, ymin, xmax, my);
378 >                else if (paint(p->kid+DR) < 0)
379 >                        quit(1);
380                  if (p->x < mx && p->y < my)
381                          pcopy(p, p->kid+DL);
382 <                else
383 <                        paint(p->kid+DL, xmin, ymin, mx, my);
382 >                else if (paint(p->kid+DL) < 0)
383 >                        quit(1);
384  
385                  growth++;
386          }
387                                                  /* do children */
388          if (mx > pframe.l) {
389                  if (my > pframe.d)
390 <                        growth += refine(p->kid+DL, xmin, ymin, mx, my, pd-1);
390 >                        growth += refine(p->kid+DL, pd-1);
391                  if (my < pframe.u)
392 <                        growth += refine(p->kid+UL, xmin, my, mx, ymax, pd-1);
392 >                        growth += refine(p->kid+UL, pd-1);
393          }
394          if (mx < pframe.r) {
395                  if (my > pframe.d)
396 <                        growth += refine(p->kid+DR, mx, ymin, xmax, my, pd-1);
396 >                        growth += refine(p->kid+DR, pd-1);
397                  if (my < pframe.u)
398 <                        growth += refine(p->kid+UR, mx, my, xmax, ymax, pd-1);
398 >                        growth += refine(p->kid+UR, pd-1);
399          }
400                                                  /* recompute sum */
401          if (growth) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines