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.16 by greg, Wed Jun 19 16:36:39 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  
38   int  maxdepth = 4;                      /* maximum recursion depth */
39   double  minweight = 1e-2;               /* minimum ray weight */
# Line 44 | Line 48 | char  *amblist[128];                   /* ambient include/exclude list
48   int  ambincl = -1;                      /* include == 1, exclude == 0 */
49  
50   int  greyscale = 0;                     /* map colors to brightness? */
51 < char  *devname = "X";                   /* output device name */
51 > char  *devname = dev_default;           /* output device name */
52  
53   struct driver  *dev = NULL;             /* driver functions */
54  
# Line 54 | Line 58 | PNODE  ptrunk;                         /* the base of our image */
58   RECT  pframe;                           /* current frame boundaries */
59   int  pdepth;                            /* image depth in current frame */
60  
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 111 | Line 119 | rview()                                /* do a view */
119          char  buf[32];
120  
121          devopen(devname);               /* open device */
122 <        newimage();                     /* set up image */
122 >        newimage();                     /* start image (calls fillreserves) */
123  
124          for ( ; ; ) {                   /* quit in command() */
125 <                while (ourview.hresolu <= 1<<pdepth &&
118 <                                ourview.vresolu <= 1<<pdepth)
125 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
126                          command("done: ");
127 <
128 <                if (ourview.hresolu <= psample<<pdepth &&
129 <                                ourview.vresolu <= psample<<pdepth) {
127 >                while (reserve_mem == NULL)
128 >                        command("out of memory: ");
129 >                errno = 0;
130 >                if (hresolu <= psample<<pdepth && 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)
139 >                if (errno == ENOMEM)            /* ran out of memory */
140 >                        freereserves();
141 >                else if (dev->inpready)         /* noticed some input */
142                          command(": ");
143 <                else
143 >                else                            /* finished this depth */
144                          pdepth++;
145          }
146   }
147  
148  
149 + fillreserves()                  /* fill memory reserves */
150 + {
151 +        if (reserve_mem != NULL)
152 +                return;
153 +        reserve_mem = malloc(RESERVE_AMT);
154 + }
155 +
156 +
157 + freereserves()                  /* free memory reserves */
158 + {
159 +        if (reserve_mem == NULL)
160 +                return;
161 +        free(reserve_mem);
162 +        reserve_mem = NULL;
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 +                return;
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 >                return;
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 >                        return(growth);
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