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 1.19 by greg, Thu Jul 18 14:42:58 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  
40   int  maxdepth = 4;                      /* maximum recursion depth */
41   double  minweight = 1e-2;               /* minimum ray weight */
42  
43   COLOR  ambval = BLKCOLOR;               /* ambient value */
44   double  ambacc = 0.2;                   /* ambient accuracy */
45 < int  ambres = 64;                       /* ambient resolution */
45 > int  ambres = 8;                        /* ambient resolution */
46   int  ambdiv = 32;                       /* ambient divisions */
47   int  ambssamp = 0;                      /* ambient super-samples */
48   int  ambounce = 0;                      /* ambient bounces */
# Line 44 | Line 50 | char  *amblist[128];                   /* ambient include/exclude list
50   int  ambincl = -1;                      /* include == 1, exclude == 0 */
51  
52   int  greyscale = 0;                     /* map colors to brightness? */
53 < char  *devname = "X";                   /* output device name */
53 > char  *devname = dev_default;           /* output device name */
54  
55   struct driver  *dev = NULL;             /* driver functions */
56  
# Line 54 | Line 60 | PNODE  ptrunk;                         /* the base of our image */
60   RECT  pframe;                           /* current frame boundaries */
61   int  pdepth;                            /* image depth in current frame */
62  
63 + static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
64 +
65 + #define RESERVE_AMT     8192            /* amount of memory to reserve */
66 +
67   #define  CTRL(c)        ('c'-'@')
68  
69  
# Line 68 | Line 78 | int  code;
78   devopen(dname)                          /* open device driver */
79   char  *dname;
80   {
81 <        extern char  *progname;
82 <        char  *devargv[3];
81 >        extern char  *progname, *octname;
82 >        char  *id;
83          register int  i;
84 +
85 +        id = octname!=NULL ? octname : progname;
86                                                  /* check device table */
87          for (i = 0; devtable[i].name; i++)
88                  if (!strcmp(dname, devtable[i].name))
89 <                        if ((dev = (*devtable[i].init)(progname)) == NULL) {
89 >                        if ((dev = (*devtable[i].init)(dname, id)) == NULL) {
90                                  sprintf(errmsg, "cannot initialize %s", dname);
91                                  error(USER, errmsg);
92                          } else
93                                  return;
94                                                  /* not there, try exec */
95 <        devargv[0] = dname;
84 <        devargv[1] = progname;
85 <        devargv[2] = NULL;
86 <        if ((dev = comm_init(devargv)) == NULL) {
95 >        if ((dev = comm_init(dname, id)) == NULL) {
96                  sprintf(errmsg, "cannot start device \"%s\"", dname);
97                  error(USER, errmsg);
98          }
# Line 112 | Line 121 | rview()                                /* do a view */
121          char  buf[32];
122  
123          devopen(devname);               /* open device */
124 <        newimage();                     /* set up image */
124 >        newimage();                     /* start image (calls fillreserves) */
125  
126          for ( ; ; ) {                   /* quit in command() */
127 <                while (ourview.hresolu <= 1<<pdepth &&
119 <                                ourview.vresolu <= 1<<pdepth)
127 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
128                          command("done: ");
129 <
130 <                if (ourview.hresolu <= psample<<pdepth &&
131 <                                ourview.vresolu <= psample<<pdepth) {
129 >                while (reserve_mem == NULL)
130 >                        command("out of memory: ");
131 >                errno = 0;
132 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
133                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
134                          (*dev->comout)(buf);
135                          rsample();
136                  } else {
137                          sprintf(buf, "%d refining...\n", 1<<pdepth);
138                          (*dev->comout)(buf);
139 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
131 <                                        ourview.vresolu, pdepth+1);
139 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
140                  }
141 <                if (dev->inpready)
141 >                if (errno == ENOMEM)            /* ran out of memory */
142 >                        freereserves();
143 >                else if (dev->inpready)         /* noticed some input */
144                          command(": ");
145 <                else
145 >                else                            /* finished this depth */
146                          pdepth++;
147          }
148   }
149  
150  
151 + fillreserves()                  /* fill memory reserves */
152 + {
153 +        if (reserve_mem != NULL)
154 +                return;
155 +        reserve_mem = malloc(RESERVE_AMT);
156 + }
157 +
158 +
159 + freereserves()                  /* free memory reserves */
160 + {
161 +        if (reserve_mem == NULL)
162 +                return;
163 +        free(reserve_mem);
164 +        reserve_mem = NULL;
165 + }
166 +
167 +
168   command(prompt)                 /* get/execute command */
169   char  *prompt;
170   {
# Line 146 | Line 173 | char  *prompt;
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 199 | Line 225 | again:
225                          goto commerr;
226                  getmove(args);
227                  break;
228 <        case 'r':                               /* rotate camera */
229 <                if (badcom("rotate"))
230 <                        goto commerr;
228 >        case 'r':                               /* rotate/repaint */
229 >                if (badcom("rotate")) {
230 >                        if (badcom("repaint"))
231 >                                goto commerr;
232 >                        getrepaint(args);
233 >                        break;
234 >                }
235                  getrotate(args);
236                  break;
237          case 'p':                               /* pivot view */
# Line 263 | Line 293 | rsample()                      /* sample the image */
293           * difference, we subsample the super-pixels.  The testing process
294           * includes initialization of the next row.
295           */
296 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
297 <                        ourview.hresolu;
268 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
269 <                        ourview.vresolu;
296 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
297 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
298          rl = (RECT *)malloc(xsiz*sizeof(RECT));
299 +        if (rl == NULL)
300 +                return;
301          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
302 <        if (rl == NULL || pl == NULL)
303 <                error(SYSTEM, "out of memory in rsample");
302 >        if (pl == NULL)
303 >                return;
304          /*
305           * Initialize the bottom row.
306           */
307          rl[0].l = rl[0].d = 0;
308 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
308 >        rl[0].r = hresolu; rl[0].u = vresolu;
309          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
310          for (x = 1; x < xsiz; x++) {
311                  rl[x].l = rl[x].d = 0;
312 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
313 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
312 >                rl[x].r = hresolu; rl[x].u = vresolu;
313 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
314                                  pframe.d, &ptrunk, rl+x, pdepth);
315          }
316                                                  /* sample the image */
# Line 308 | Line 338 | rsample()                      /* sample the image */
338                           * Find super-pixel at this position in next row.
339                           */
340                          r.l = r.d = 0;
341 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
342 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
343 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
341 >                        r.r = hresolu; r.u = vresolu;
342 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
343 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
344                                          &ptrunk, &r, pdepth);
345                          /*
346                           * Test super-pixel in next row.
# Line 357 | Line 387 | int  pd;
387          if (p->kid == NULL) {                   /* subdivide */
388  
389                  if ((p->kid = newptree()) == NULL)
390 <                        error(SYSTEM, "out of memory in refine");
390 >                        return(growth);
391                  /*
392                   *  The following paint order can leave a black pixel
393                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines