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.13 by greg, Fri May 3 15:43:32 1991 UTC vs.
Revision 2.2 by greg, Mon Nov 25 10:11:01 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  
21 #include  <setjmp.h>
22
19   #include  <ctype.h>
20  
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 33 | 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 */
# Line 57 | Line 61 | PNODE  ptrunk;                         /* the base of our image */
61   RECT  pframe;                           /* current frame boundaries */
62   int  pdepth;                            /* image depth in current frame */
63  
60 static jmp_buf  mainloop;               /* longjmp back to main loop */
64   static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
65  
66 < #define RESERVE_AMT     8192            /* amount of memory to reserve */
66 > #define RESERVE_AMT     32768           /* amount of memory to reserve */
67  
68   #define  CTRL(c)        ('c'-'@')
69  
# Line 119 | Line 122 | rview()                                /* do a view */
122          char  buf[32];
123  
124          devopen(devname);               /* open device */
125 <        newimage();                     /* set up image */
126 <        setjmp(mainloop);
125 >        newimage();                     /* start image (calls fillreserves) */
126 >
127          for ( ; ; ) {                   /* quit in command() */
128 <                while (hresolu <= 1<<pdepth &&
126 <                                vresolu <= 1<<pdepth)
128 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
129                          command("done: ");
130 <
131 <                if (hresolu <= psample<<pdepth &&
132 <                                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();
# Line 136 | Line 139 | rview()                                /* do a view */
139                          (*dev->comout)(buf);
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 < memreserve()                    /* fill memory reserves */
152 > fillreserves()                  /* fill memory reserves */
153   {
154          if (reserve_mem != NULL)
155 <                return;                 /* got some already */
155 >                return;
156          reserve_mem = malloc(RESERVE_AMT);
157   }
158  
159  
160 < memerror(detail)                /* try and rescue a memory error */
156 < char    *detail;
160 > freereserves()                  /* free memory reserves */
161   {
162 <        if (reserve_mem == NULL) {
163 <                sprintf(errmsg, "out of memory %s", detail);
160 <                error(SYSTEM, errmsg);
161 <        }
162 >        if (reserve_mem == NULL)
163 >                return;
164          free(reserve_mem);
165          reserve_mem = NULL;
164        do
165                command("out of memory: ");
166        while (reserve_mem == NULL);
167        longjmp(mainloop, 1);
166   }
167  
168  
# Line 225 | Line 223 | again:
223                  break;
224          case 'm':                               /* move camera */
225                  if (badcom("move"))
226 + #ifdef  MSTATS
227 +                {
228 +                        if (badcom("memory"))
229 +                                goto commerr;
230 +                        printmemstats(stderr);
231 +                        break;
232 +                }
233 + #else
234                          goto commerr;
235 + #endif
236                  getmove(args);
237                  break;
238          case 'r':                               /* rotate/repaint */
# Line 300 | Line 307 | rsample()                      /* sample the image */
307          ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
308          rl = (RECT *)malloc(xsiz*sizeof(RECT));
309          if (rl == NULL)
310 <                memerror("in rsample");
310 >                return;
311          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
312          if (pl == NULL)
313 <                memerror("in rsample");
313 >                return;
314          /*
315           * Initialize the bottom row.
316           */
# Line 319 | Line 326 | rsample()                      /* sample the image */
326                                                  /* sample the image */
327          for (y = 0; /* y < ysiz */ ; y++) {
328                  for (x = 0; x < xsiz-1; x++) {
329 <                        if (dev->inpready)
329 >                        if (dev->inpready || errno == ENOMEM)
330                                  goto escape;
331                          /*
332                           * Test super-pixel to the right.
# Line 335 | Line 342 | rsample()                      /* sample the image */
342                  if (y >= ysiz-1)
343                          break;
344                  for (x = 0; x < xsiz; x++) {
345 <                        if (dev->inpready)
345 >                        if (dev->inpready || errno == ENOMEM)
346                                  goto escape;
347                          /*
348                           * Find super-pixel at this position in next row.
# Line 390 | Line 397 | int  pd;
397          if (p->kid == NULL) {                   /* subdivide */
398  
399                  if ((p->kid = newptree()) == NULL)
400 <                        memerror("in refine");
400 >                        return(0);
401                  /*
402                   *  The following paint order can leave a black pixel
403                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines