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.7 by greg, Wed Oct 25 15:37:19 1989 UTC vs.
Revision 1.17 by greg, Mon Jun 24 16:10:49 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 = 32;                    /* virtual source pretest density */
38  
39   int  maxdepth = 4;                      /* maximum recursion depth */
40   double  minweight = 1e-2;               /* minimum ray weight */
# Line 44 | Line 49 | char  *amblist[128];                   /* ambient include/exclude list
49   int  ambincl = -1;                      /* include == 1, exclude == 0 */
50  
51   int  greyscale = 0;                     /* map colors to brightness? */
52 < char  *devname = "X";                   /* output device name */
52 > char  *devname = dev_default;           /* output device name */
53  
54   struct driver  *dev = NULL;             /* driver functions */
55  
# Line 54 | Line 59 | PNODE  ptrunk;                         /* the base of our image */
59   RECT  pframe;                           /* current frame boundaries */
60   int  pdepth;                            /* image depth in current frame */
61  
62 + static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
63 +
64 + #define RESERVE_AMT     8192            /* amount of memory to reserve */
65 +
66   #define  CTRL(c)        ('c'-'@')
67  
68  
# Line 111 | Line 120 | rview()                                /* do a view */
120          char  buf[32];
121  
122          devopen(devname);               /* open device */
123 <        newimage();                     /* set up image */
123 >        newimage();                     /* start image (calls fillreserves) */
124  
125          for ( ; ; ) {                   /* quit in command() */
126 <                while (ourview.hresolu <= 1<<pdepth &&
118 <                                ourview.vresolu <= 1<<pdepth)
126 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
127                          command("done: ");
128 <
129 <                if (ourview.hresolu <= psample<<pdepth &&
130 <                                ourview.vresolu <= psample<<pdepth) {
128 >                while (reserve_mem == NULL)
129 >                        command("out of memory: ");
130 >                errno = 0;
131 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
132                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
133                          (*dev->comout)(buf);
134                          rsample();
135                  } else {
136                          sprintf(buf, "%d refining...\n", 1<<pdepth);
137                          (*dev->comout)(buf);
138 <                        refine(&ptrunk, 0, 0, ourview.hresolu,
130 <                                        ourview.vresolu, pdepth+1);
138 >                        refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
139                  }
140 <                if (dev->inpready)
140 >                if (errno == ENOMEM)            /* ran out of memory */
141 >                        freereserves();
142 >                else if (dev->inpready)         /* noticed some input */
143                          command(": ");
144 <                else
144 >                else                            /* finished this depth */
145                          pdepth++;
146          }
147   }
148  
149  
150 + fillreserves()                  /* fill memory reserves */
151 + {
152 +        if (reserve_mem != NULL)
153 +                return;
154 +        reserve_mem = malloc(RESERVE_AMT);
155 + }
156 +
157 +
158 + freereserves()                  /* free memory reserves */
159 + {
160 +        if (reserve_mem == NULL)
161 +                return;
162 +        free(reserve_mem);
163 +        reserve_mem = NULL;
164 + }
165 +
166 +
167   command(prompt)                 /* get/execute command */
168   char  *prompt;
169   {
# Line 145 | Line 172 | char  *prompt;
172          char  inpbuf[256];
173          char  *args;
174   again:
175 <        (*dev->comout)(prompt);                 /* get command + arguments */
149 <        (*dev->comin)(inpbuf);
175 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
176          for (args = inpbuf; *args && *args != ' '; args++)
177                  ;
178          if (*args) *args++ = '\0';
# Line 198 | Line 224 | again:
224                          goto commerr;
225                  getmove(args);
226                  break;
227 <        case 'r':                               /* rotate camera */
228 <                if (badcom("rotate"))
229 <                        goto commerr;
227 >        case 'r':                               /* rotate/repaint */
228 >                if (badcom("rotate")) {
229 >                        if (badcom("repaint"))
230 >                                goto commerr;
231 >                        getrepaint(args);
232 >                        break;
233 >                }
234                  getrotate(args);
235                  break;
236          case 'p':                               /* pivot view */
# Line 262 | Line 292 | rsample()                      /* sample the image */
292           * difference, we subsample the super-pixels.  The testing process
293           * includes initialization of the next row.
294           */
295 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+ourview.hresolu-1) /
296 <                        ourview.hresolu;
267 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+ourview.vresolu-1) /
268 <                        ourview.vresolu;
295 >        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
296 >        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
297          rl = (RECT *)malloc(xsiz*sizeof(RECT));
298 +        if (rl == NULL)
299 +                return;
300          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
301 <        if (rl == NULL || pl == NULL)
302 <                error(SYSTEM, "out of memory in rsample");
301 >        if (pl == NULL)
302 >                return;
303          /*
304           * Initialize the bottom row.
305           */
306          rl[0].l = rl[0].d = 0;
307 <        rl[0].r = ourview.hresolu; rl[0].u = ourview.vresolu;
307 >        rl[0].r = hresolu; rl[0].u = vresolu;
308          pl[0] = findrect(pframe.l, pframe.d, &ptrunk, rl, pdepth);
309          for (x = 1; x < xsiz; x++) {
310                  rl[x].l = rl[x].d = 0;
311 <                rl[x].r = ourview.hresolu; rl[x].u = ourview.vresolu;
312 <                pl[x] = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
311 >                rl[x].r = hresolu; rl[x].u = vresolu;
312 >                pl[x] = findrect(pframe.l+((x*hresolu)>>pdepth),
313                                  pframe.d, &ptrunk, rl+x, pdepth);
314          }
315                                                  /* sample the image */
# Line 307 | Line 337 | rsample()                      /* sample the image */
337                           * Find super-pixel at this position in next row.
338                           */
339                          r.l = r.d = 0;
340 <                        r.r = ourview.hresolu; r.u = ourview.vresolu;
341 <                        p = findrect(pframe.l+((x*ourview.hresolu)>>pdepth),
342 <                                pframe.d+(((y+1)*ourview.vresolu)>>pdepth),
340 >                        r.r = hresolu; r.u = vresolu;
341 >                        p = findrect(pframe.l+((x*hresolu)>>pdepth),
342 >                                pframe.d+(((y+1)*vresolu)>>pdepth),
343                                          &ptrunk, &r, pdepth);
344                          /*
345                           * Test super-pixel in next row.
# Line 356 | Line 386 | int  pd;
386          if (p->kid == NULL) {                   /* subdivide */
387  
388                  if ((p->kid = newptree()) == NULL)
389 <                        error(SYSTEM, "out of memory in refine");
389 >                        return(growth);
390                  /*
391                   *  The following paint order can leave a black pixel
392                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines