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.2 by greg, Wed Jun 7 08:35:29 1989 UTC vs.
Revision 1.13 by greg, Fri May 3 15:43:32 1991 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  <signal.h>
20  
21 + #include  <setjmp.h>
22 +
23   #include  <ctype.h>
24  
25 < VIEW  ourview = STDVIEW(470);           /* viewing parameters */
25 > VIEW  ourview = STDVIEW;                /* viewing parameters */
26 > int  hresolu, vresolu;                  /* image resolution */
27  
28   int  psample = 8;                       /* pixel sample size */
29   double  maxdiff = .15;                  /* max. sample difference */
# Line 28 | Line 31 | double  maxdiff = .15;                 /* max. sample difference */
31   double  exposure = 1.0;                 /* exposure for scene */
32  
33   double  dstrsrc = 0.0;                  /* square source distribution */
34 < double  shadthresh = .05;               /* shadow threshold */
34 > double  shadthresh = .1;                /* shadow threshold */
35 > double  shadcert = .25;                 /* shadow certainty */
36  
37   int  maxdepth = 4;                      /* maximum recursion depth */
38   double  minweight = 1e-2;               /* minimum ray weight */
39  
40   COLOR  ambval = BLKCOLOR;               /* ambient value */
41   double  ambacc = 0.2;                   /* ambient accuracy */
42 < int  ambres = 64;                       /* ambient resolution */
42 > int  ambres = 8;                        /* ambient resolution */
43   int  ambdiv = 32;                       /* ambient divisions */
44   int  ambssamp = 0;                      /* ambient super-samples */
45   int  ambounce = 0;                      /* ambient bounces */
# Line 43 | Line 47 | char  *amblist[128];                   /* ambient include/exclude list
47   int  ambincl = -1;                      /* include == 1, exclude == 0 */
48  
49   int  greyscale = 0;                     /* map colors to brightness? */
50 < char  *devname = "X";                   /* output device name */
50 > char  *devname = dev_default;           /* output device name */
51  
52   struct driver  *dev = NULL;             /* driver functions */
53  
# Line 53 | Line 57 | PNODE  ptrunk;                         /* the base of our image */
57   RECT  pframe;                           /* current frame boundaries */
58   int  pdepth;                            /* image depth in current frame */
59  
60 + static jmp_buf  mainloop;               /* longjmp back to main loop */
61 + static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
62 +
63 + #define RESERVE_AMT     8192            /* amount of memory to reserve */
64 +
65   #define  CTRL(c)        ('c'-'@')
66  
67  
# Line 67 | Line 76 | int  code;
76   devopen(dname)                          /* open device driver */
77   char  *dname;
78   {
79 <        extern char  *progname;
80 <        char  *devargv[3];
79 >        extern char  *progname, *octname;
80 >        char  *id;
81          register int  i;
82 +
83 +        id = octname!=NULL ? octname : progname;
84                                                  /* check device table */
85          for (i = 0; devtable[i].name; i++)
86                  if (!strcmp(dname, devtable[i].name))
87 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
87 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
88                                  sprintf(errmsg, "cannot initialize %s", dname);
89                                  error(USER, errmsg);
90                          } else
91                                  return;
92                                                  /* not there, try exec */
93 <        devargv[0] = dname;
83 <        devargv[1] = progname;
84 <        devargv[2] = NULL;
85 <        if ((dev = comm_init(devargv)) == NULL) {
93 >        if ((dev = comm_init(dname, id)) == NULL) {
94                  sprintf(errmsg, "cannot start device \"%s\"", dname);
95                  error(USER, errmsg);
96          }
# Line 112 | Line 120 | rview()                                /* do a view */
120  
121          devopen(devname);               /* open device */
122          newimage();                     /* set up image */
123 <
123 >        setjmp(mainloop);
124          for ( ; ; ) {                   /* quit in command() */
125 <                while (ourview.hresolu <= 1<<pdepth &&
126 <                                ourview.vresolu <= 1<<pdepth)
125 >                while (hresolu <= 1<<pdepth &&
126 >                                vresolu <= 1<<pdepth)
127                          command("done: ");
128  
129 <                if (ourview.hresolu <= psample<<pdepth &&
130 <                                ourview.vresolu <= psample<<pdepth) {
129 >                if (hresolu <= psample<<pdepth &&
130 >                                vresolu <= psample<<pdepth) {
131                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
132                          (*dev->comout)(buf);
133                          rsample();
134                  } else {
135                          sprintf(buf, "%d refining...\n", 1<<pdepth);
136                          (*dev->comout)(buf);
137 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
130 <                                        ourview.vresolu, pdepth+1);
137 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
138                  }
139                  if (dev->inpready)
140                          command(": ");
# Line 137 | Line 144 | rview()                                /* do a view */
144   }
145  
146  
147 + memreserve()                    /* fill memory reserves */
148 + {
149 +        if (reserve_mem != NULL)
150 +                return;                 /* got some already */
151 +        reserve_mem = malloc(RESERVE_AMT);
152 + }
153 +
154 +
155 + memerror(detail)                /* try and rescue a memory error */
156 + char    *detail;
157 + {
158 +        if (reserve_mem == NULL) {
159 +                sprintf(errmsg, "out of memory %s", detail);
160 +                error(SYSTEM, errmsg);
161 +        }
162 +        free(reserve_mem);
163 +        reserve_mem = NULL;
164 +        do
165 +                command("out of memory: ");
166 +        while (reserve_mem == NULL);
167 +        longjmp(mainloop, 1);
168 + }
169 +
170 +
171   command(prompt)                 /* get/execute command */
172   char  *prompt;
173   {
# Line 145 | Line 176 | char  *prompt;
176          char  inpbuf[256];
177          char  *args;
178   again:
179 <        (*dev->comout)(prompt);                 /* get command + arguments */
149 <        (*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 198 | Line 228 | again:
228                          goto commerr;
229                  getmove(args);
230                  break;
231 <        case 'r':                               /* rotate camera */
232 <                if (badcom("rotate"))
233 <                        goto commerr;
231 >        case 'r':                               /* rotate/repaint */
232 >                if (badcom("rotate")) {
233 >                        if (badcom("repaint"))
234 >                                goto commerr;
235 >                        getrepaint(args);
236 >                        break;
237 >                }
238                  getrotate(args);
239                  break;
240          case 'p':                               /* pivot view */
# Line 262 | Line 296 | rsample()                      /* sample the image */
296           * difference, we subsample the super-pixels.  The testing process
297           * includes initialization of the next row.
298           */
299 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
300 <                        ourview.hresolu;
267 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
268 <                        ourview.vresolu;
299 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
300 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
301          rl = (RECT *)malloc(xsiz*sizeof(RECT));
302 +        if (rl == NULL)
303 +                memerror("in rsample");
304          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
305 <        if (rl == NULL || pl == NULL)
306 <                error(SYSTEM, "out of memory in rsample");
305 >        if (pl == NULL)
306 >                memerror("in rsample");
307          /*
308           * Initialize the bottom row.
309           */
310          rl[0].l = rl[0].d = 0;
311 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
311 >        rl[0].r = hresolu; rl[0].u = vresolu;
312          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
313          for (x = 1; x < xsiz; x++) {
314                  rl[x].l = rl[x].d = 0;
315 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
316 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
315 >                rl[x].r = hresolu; rl[x].u = vresolu;
316 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
317                                  pframe.d, &ptrunk, rl+x, pdepth);
318          }
319                                                  /* sample the image */
# Line 307 | Line 341 | rsample()                      /* sample the image */
341                           * Find super-pixel at this position in next row.
342                           */
343                          r.l = r.d = 0;
344 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
345 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
346 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
344 >                        r.r = hresolu; r.u = vresolu;
345 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
346 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
347                                          &ptrunk, &r, pdepth);
348                          /*
349                           * Test super-pixel in next row.
# Line 356 | Line 390 | int  pd;
390          if (p->kid == NULL) {                   /* subdivide */
391  
392                  if ((p->kid = newptree()) == NULL)
393 <                        error(SYSTEM, "out of memory in refine");
393 >                        memerror("in refine");
394                  /*
395                   *  The following paint order can leave a black pixel
396                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines