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.12 by greg, Fri May 3 15:22:24 1991 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines