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.4 by greg, Tue Jun 13 10:57:49 1989 UTC vs.
Revision 2.3 by greg, Thu Dec 19 14:54:46 1991 UTC

# 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 */
30  
# Line 30 | Line 33 | double  exposure = 1.0;                        /* exposure for scene */
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  directinvis = 0;                   /* sources invisible? */
39 + double  srcsizerat = 0.;                /* maximum ratio source size/dist. */
40  
41   int  maxdepth = 4;                      /* maximum recursion depth */
42   double  minweight = 1e-2;               /* minimum ray weight */
43  
44   COLOR  ambval = BLKCOLOR;               /* ambient value */
45   double  ambacc = 0.2;                   /* ambient accuracy */
46 < int  ambres = 64;                       /* ambient resolution */
46 > int  ambres = 8;                        /* ambient resolution */
47   int  ambdiv = 32;                       /* ambient divisions */
48   int  ambssamp = 0;                      /* ambient super-samples */
49   int  ambounce = 0;                      /* ambient bounces */
# Line 44 | Line 51 | char  *amblist[128];                   /* ambient include/exclude list
51   int  ambincl = -1;                      /* include == 1, exclude == 0 */
52  
53   int  greyscale = 0;                     /* map colors to brightness? */
54 < char  *devname = "X";                   /* output device name */
54 > char  *devname = dev_default;           /* output device name */
55  
56   struct driver  *dev = NULL;             /* driver functions */
57  
# Line 54 | Line 61 | PNODE  ptrunk;                         /* the base of our image */
61   RECT  pframe;                           /* current frame boundaries */
62   int  pdepth;                            /* image depth in current frame */
63  
64 + static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
65 +
66 + #define RESERVE_AMT     32768           /* amount of memory to reserve */
67 +
68   #define  CTRL(c)        ('c'-'@')
69  
70  
# Line 68 | Line 79 | int  code;
79   devopen(dname)                          /* open device driver */
80   char  *dname;
81   {
82 <        extern char  *progname;
83 <        char  *devargv[3];
82 >        extern char  *progname, *octname;
83 >        char  *id;
84          register int  i;
85 +
86 +        id = octname!=NULL ? octname : progname;
87                                                  /* check device table */
88          for (i = 0; devtable[i].name; i++)
89                  if (!strcmp(dname, devtable[i].name))
90 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
90 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
91                                  sprintf(errmsg, "cannot initialize %s", dname);
92                                  error(USER, errmsg);
93                          } else
94                                  return;
95                                                  /* not there, try exec */
96 <        devargv[0] = dname;
84 <        devargv[1] = progname;
85 <        devargv[2] = NULL;
86 <        if ((dev = comm_init(devargv)) == NULL) {
96 >        if ((dev = comm_init(dname, id)) == NULL) {
97                  sprintf(errmsg, "cannot start device \"%s\"", dname);
98                  error(USER, errmsg);
99          }
# Line 112 | Line 122 | rview()                                /* do a view */
122          char  buf[32];
123  
124          devopen(devname);               /* open device */
125 <        newimage();                     /* set up image */
125 >        newimage();                     /* start image (calls fillreserves) */
126  
127          for ( ; ; ) {                   /* quit in command() */
128 <                while (ourview.hresolu <= 1<<pdepth &&
119 <                                ourview.vresolu <= 1<<pdepth)
128 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
129                          command("done: ");
130 <
131 <                if (ourview.hresolu <= psample<<pdepth &&
132 <                                ourview.vresolu <= psample<<pdepth) {
130 >                while (reserve_mem == NULL)
131 >                        command("out of memory: ");
132 >                errno = 0;
133 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
134                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
135                          (*dev->comout)(buf);
136                          rsample();
137                  } else {
138                          sprintf(buf, "%d refining...\n", 1<<pdepth);
139                          (*dev->comout)(buf);
140 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
131 <                                        ourview.vresolu, pdepth+1);
140 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
141                  }
142 <                if (dev->inpready)
142 >                if (errno == ENOMEM)            /* ran out of memory */
143 >                        freereserves();
144 >                else if (dev->inpready)         /* noticed some input */
145                          command(": ");
146 <                else
146 >                else                            /* finished this depth */
147                          pdepth++;
148          }
149   }
150  
151  
152 + fillreserves()                  /* fill memory reserves */
153 + {
154 +        if (reserve_mem != NULL)
155 +                return;
156 +        reserve_mem = malloc(RESERVE_AMT);
157 + }
158 +
159 +
160 + freereserves()                  /* free memory reserves */
161 + {
162 +        if (reserve_mem == NULL)
163 +                return;
164 +        free(reserve_mem);
165 +        reserve_mem = NULL;
166 + }
167 +
168 +
169   command(prompt)                 /* get/execute command */
170   char  *prompt;
171   {
172   #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
145        double  atof();
173          char  inpbuf[256];
174          char  *args;
175   again:
176 <        (*dev->comout)(prompt);                 /* get command + arguments */
150 <        (*dev->comin)(inpbuf);
176 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
177          for (args = inpbuf; *args && *args != ' '; args++)
178                  ;
179          if (*args) *args++ = '\0';
# Line 196 | Line 222 | again:
222                  break;
223          case 'm':                               /* move camera */
224                  if (badcom("move"))
225 + #ifdef  MSTATS
226 +                {
227 +                        if (badcom("memory"))
228 +                                goto commerr;
229 +                        printmemstats(stderr);
230 +                        break;
231 +                }
232 + #else
233                          goto commerr;
234 + #endif
235                  getmove(args);
236                  break;
237 <        case 'r':                               /* rotate camera */
238 <                if (badcom("rotate"))
239 <                        goto commerr;
237 >        case 'r':                               /* rotate/repaint */
238 >                if (badcom("rotate")) {
239 >                        if (badcom("repaint"))
240 >                                goto commerr;
241 >                        getrepaint(args);
242 >                        break;
243 >                }
244                  getrotate(args);
245                  break;
246          case 'p':                               /* pivot view */
# Line 263 | Line 302 | rsample()                      /* sample the image */
302           * difference, we subsample the super-pixels.  The testing process
303           * includes initialization of the next row.
304           */
305 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
306 <                        ourview.hresolu;
268 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
269 <                        ourview.vresolu;
305 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
306 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
307          rl = (RECT *)malloc(xsiz*sizeof(RECT));
308 +        if (rl == NULL)
309 +                return;
310          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
311 <        if (rl == NULL || pl == NULL)
312 <                error(SYSTEM, "out of memory in rsample");
311 >        if (pl == NULL)
312 >                return;
313          /*
314           * Initialize the bottom row.
315           */
316          rl[0].l = rl[0].d = 0;
317 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
317 >        rl[0].r = hresolu; rl[0].u = vresolu;
318          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
319          for (x = 1; x < xsiz; x++) {
320                  rl[x].l = rl[x].d = 0;
321 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
322 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
321 >                rl[x].r = hresolu; rl[x].u = vresolu;
322 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
323                                  pframe.d, &ptrunk, rl+x, pdepth);
324          }
325                                                  /* sample the image */
326          for (y = 0; /* y < ysiz */ ; y++) {
327                  for (x = 0; x < xsiz-1; x++) {
328 <                        if (dev->inpready)
328 >                        if (dev->inpready || errno == ENOMEM)
329                                  goto escape;
330                          /*
331                           * Test super-pixel to the right.
# Line 302 | Line 341 | rsample()                      /* sample the image */
341                  if (y >= ysiz-1)
342                          break;
343                  for (x = 0; x < xsiz; x++) {
344 <                        if (dev->inpready)
344 >                        if (dev->inpready || errno == ENOMEM)
345                                  goto escape;
346                          /*
347                           * Find super-pixel at this position in next row.
348                           */
349                          r.l = r.d = 0;
350 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
351 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
352 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
350 >                        r.r = hresolu; r.u = vresolu;
351 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
352 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
353                                          &ptrunk, &r, pdepth);
354                          /*
355                           * Test super-pixel in next row.
# Line 357 | Line 396 | int  pd;
396          if (p->kid == NULL) {                   /* subdivide */
397  
398                  if ((p->kid = newptree()) == NULL)
399 <                        error(SYSTEM, "out of memory in refine");
399 >                        return(0);
400                  /*
401                   *  The following paint order can leave a black pixel
402                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines