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.9 by greg, Mon Jan 8 13:38:12 1990 UTC vs.
Revision 2.17 by greg, Wed Apr 17 14:02:16 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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>
# Line 23 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
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 */
29 > double  maxdiff = .15;                  /* max. sample difference */
30  
31 < double  exposure = 1.0;                 /* exposure for scene */
31 > double  exposure = 1.0;                 /* exposure for scene */
32  
33 < double  dstrsrc = 0.0;                  /* square source distribution */
34 < double  shadthresh = .1;                /* shadow threshold */
35 < double  shadcert = .25;                 /* shadow certainty */
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  directvis = 1;                     /* sources visible? */
39 > double  srcsizerat = 0.;                /* maximum ratio source size/dist. */
40  
41 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
42 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
43 + double  seccg = 0.;                     /* global scattering eccentricity */
44 + double  ssampdist = 0.;                 /* scatter sampling distance */
45 +
46 + double  specthresh = .3;                /* specular sampling threshold */
47 + double  specjitter = 1.;                /* specular sampling jitter */
48 +
49 + int  backvis = 1;                       /* back face visibility */
50 +
51   int  maxdepth = 4;                      /* maximum recursion depth */
52 < double  minweight = 1e-2;               /* minimum ray weight */
52 > double  minweight = 1e-2;               /* minimum ray weight */
53  
54   COLOR  ambval = BLKCOLOR;               /* ambient value */
55 < double  ambacc = 0.2;                   /* ambient accuracy */
55 > int  ambvwt = 0;                        /* initial weight for ambient value */
56 > double  ambacc = 0.2;                   /* ambient accuracy */
57   int  ambres = 8;                        /* ambient resolution */
58   int  ambdiv = 32;                       /* ambient divisions */
59   int  ambssamp = 0;                      /* ambient super-samples */
# Line 45 | Line 62 | char  *amblist[128];                   /* ambient include/exclude list
62   int  ambincl = -1;                      /* include == 1, exclude == 0 */
63  
64   int  greyscale = 0;                     /* map colors to brightness? */
65 < char  *devname = "X";                   /* output device name */
65 > char  *devname = dev_default;           /* output device name */
66  
67   struct driver  *dev = NULL;             /* driver functions */
68  
69 + char  rifname[128];                     /* rad input file name */
70 +
71   VIEW  oldview;                          /* previous view parameters */
72  
73   PNODE  ptrunk;                          /* the base of our image */
74   RECT  pframe;                           /* current frame boundaries */
75   int  pdepth;                            /* image depth in current frame */
76  
77 < #define  CTRL(c)        ('c'-'@')
77 > static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
78  
79 + #define RESERVE_AMT     32768           /* amount of memory to reserve */
80  
81 + #define  CTRL(c)        ((c)-'@')
82 +
83 +
84   quit(code)                      /* quit program */
85   int  code;
86   {
87 + #ifdef MSTATS
88 +        if (code == 2 && errno == ENOMEM)
89 +                printmemstats(stderr);
90 + #endif
91          devclose();
92          exit(code);
93   }
# Line 82 | Line 109 | char  *dname;
109                                  error(USER, errmsg);
110                          } else
111                                  return;
112 + #ifndef NIX                                                
113                                                  /* not there, try exec */
114          if ((dev = comm_init(dname, id)) == NULL) {
115                  sprintf(errmsg, "cannot start device \"%s\"", dname);
116                  error(USER, errmsg);
117          }
118 + #endif
119   }
120  
121  
# Line 112 | Line 141 | rview()                                /* do a view */
141          char  buf[32];
142  
143          devopen(devname);               /* open device */
144 <        newimage();                     /* set up image */
144 >        newimage();                     /* start image (calls fillreserves) */
145  
146          for ( ; ; ) {                   /* quit in command() */
147 <                while (hresolu <= 1<<pdepth &&
119 <                                vresolu <= 1<<pdepth)
147 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
148                          command("done: ");
149 <
150 <                if (hresolu <= psample<<pdepth &&
151 <                                vresolu <= psample<<pdepth) {
149 >                while (reserve_mem == NULL)
150 >                        command("out of memory: ");
151 >                errno = 0;
152 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
153                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
154                          (*dev->comout)(buf);
155                          rsample();
# Line 129 | Line 158 | rview()                                /* do a view */
158                          (*dev->comout)(buf);
159                          refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
160                  }
161 <                if (dev->inpready)
161 >                if (errno == ENOMEM)            /* ran out of memory */
162 >                        freereserves();
163 >                else if (dev->inpready)         /* noticed some input */
164                          command(": ");
165 <                else
165 >                else                            /* finished this depth */
166                          pdepth++;
167          }
168   }
169  
170  
171 + fillreserves()                  /* fill memory reserves */
172 + {
173 +        if (reserve_mem != NULL)
174 +                return;
175 +        reserve_mem = malloc(RESERVE_AMT);
176 + }
177 +
178 +
179 + freereserves()                  /* free memory reserves */
180 + {
181 +        if (reserve_mem == NULL)
182 +                return;
183 +        free(reserve_mem);
184 +        reserve_mem = NULL;
185 + }
186 +
187 +
188   command(prompt)                 /* get/execute command */
189   char  *prompt;
190   {
191 < #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
144 <        double  atof();
191 > #define  badcom(s)      strncmp(s, inpbuf, args-inpbuf-1)
192          char  inpbuf[256];
193          char  *args;
194   again:
195 <        (*dev->comout)(prompt);                 /* get command + arguments */
149 <        (*dev->comin)(inpbuf);
195 >        (*dev->comin)(inpbuf, prompt);          /* get command + arguments */
196          for (args = inpbuf; *args && *args != ' '; args++)
197                  ;
198          if (*args) *args++ = '\0';
199          else *++args = '\0';
200          
201          switch (inpbuf[0]) {
202 <        case 'f':                               /* new frame */
203 <                if (badcom("frame"))
204 <                        goto commerr;
202 >        case 'f':                               /* new frame (or free mem.) */
203 >                if (badcom("frame")) {
204 >                        if (badcom("free"))
205 >                                goto commerr;
206 >                        free_objmem();
207 >                        break;
208 >                }
209                  getframe(args);
210                  break;
211          case 'v':                               /* view */
# Line 168 | Line 218 | again:
218                          goto commerr;
219                  lastview(args);
220                  break;
221 +        case 'V':                               /* save view */
222 +                if (badcom("V"))
223 +                        goto commerr;
224 +                saveview(args);
225 +                break;
226 +        case 'L':                               /* load view */
227 +                if (badcom("L"))
228 +                        goto commerr;
229 +                loadview(args);
230 +                break;
231          case 'e':                               /* exposure */
232                  if (badcom("exposure"))
233                          goto commerr;
234                  getexposure(args);
235                  break;
236          case 's':                               /* set a parameter */
237 <                if (badcom("set"))
237 >                if (badcom("set")) {
238 > #ifdef  SIGTSTP
239 >                        if (!badcom("stop"))
240 >                                goto dostop;
241 > #endif
242                          goto commerr;
243 +                }
244                  setparam(args);
245                  break;
246          case 'n':                               /* new picture */
# Line 193 | Line 258 | again:
258                          goto commerr;
259                  getaim(args);
260                  break;
261 <        case 'm':                               /* move camera */
261 >        case 'm':                               /* move camera (or memstats) */
262                  if (badcom("move"))
263 + #ifdef  MSTATS
264 +                {
265 +                        if (badcom("memory"))
266 +                                goto commerr;
267 +                        printmemstats(stderr);
268 +                        break;
269 +                }
270 + #else
271                          goto commerr;
272 + #endif
273                  getmove(args);
274                  break;
275          case 'r':                               /* rotate/repaint */
276                  if (badcom("rotate")) {
277 <                        if (badcom("repaint"))
278 <                                goto commerr;
277 >                        if (badcom("repaint")) {
278 >                                if (badcom("redraw"))
279 >                                        goto commerr;
280 >                                redraw();
281 >                                break;
282 >                        }
283                          getrepaint(args);
284                          break;
285                  }
286                  getrotate(args);
287                  break;
288          case 'p':                               /* pivot view */
289 <                if (badcom("pivot"))
290 <                        goto commerr;
289 >                if (badcom("pivot")) {
290 >                        if (badcom("pause"))
291 >                                goto commerr;
292 >                        goto again;
293 >                }
294                  getpivot(args);
295                  break;
296 <        case CTRL(R):                           /* redraw */
296 >        case CTRL('R'):                         /* redraw */
297                  redraw();
298                  break;
299          case 'w':                               /* write */
# Line 224 | Line 305 | again:
305                  if (badcom("quit"))
306                          goto commerr;
307                  quit(0);
308 <        case CTRL(C):                           /* interrupt */
308 >        case CTRL('C'):                         /* interrupt */
309                  goto again;
310 < #ifdef  SIGTSTP
311 <        case CTRL(Z):                           /* stop */
310 > #ifdef  SIGTSTP
311 >        case CTRL('Z'):;                        /* stop */
312 > dostop:
313                  devclose();
314                  kill(0, SIGTSTP);
315                  /* pc stops here */
# Line 247 | Line 329 | commerr:
329                  error(COMMAND, errmsg);
330                  break;
331          }
332 < #undef  badcom
332 > #undef  badcom
333   }
334  
335  
# Line 257 | Line 339 | rsample()                      /* sample the image */
339          RECT  r;
340          PNODE  *p;
341          register RECT  *rl;
342 <        register PNODE  **pl;
342 >        register PNODE  **pl;
343          register int  x;
344          /*
345           *     We initialize the bottom row in the image at our current
346 <         * resolution.  During sampling, we check super-pixels to the
346 >         * resolution.  During sampling, we check super-pixels to the
347           * right and above by calling bigdiff().  If there is a significant
348           * difference, we subsample the super-pixels.  The testing process
349           * includes initialization of the next row.
350           */
351 <        xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
352 <        ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
351 >        xsiz = (((long)(pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
352 >        ysiz = (((long)(pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
353          rl = (RECT *)malloc(xsiz*sizeof(RECT));
354 +        if (rl == NULL)
355 +                return;
356          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
357 <        if (rl == NULL || pl == NULL)
358 <                error(SYSTEM, "out of memory in rsample");
357 >        if (pl == NULL) {
358 >                free((char *)rl);
359 >                return;
360 >        }
361          /*
362           * Initialize the bottom row.
363           */
# Line 287 | Line 373 | rsample()                      /* sample the image */
373                                                  /* sample the image */
374          for (y = 0; /* y < ysiz */ ; y++) {
375                  for (x = 0; x < xsiz-1; x++) {
376 <                        if (dev->inpready)
376 >                        if (dev->inpready || errno == ENOMEM)
377                                  goto escape;
378                          /*
379                           * Test super-pixel to the right.
# Line 303 | Line 389 | rsample()                      /* sample the image */
389                  if (y >= ysiz-1)
390                          break;
391                  for (x = 0; x < xsiz; x++) {
392 <                        if (dev->inpready)
392 >                        if (dev->inpready || errno == ENOMEM)
393                                  goto escape;
394                          /*
395                           * Find super-pixel at this position in next row.
# Line 337 | Line 423 | escape:
423  
424   int
425   refine(p, xmin, ymin, xmax, ymax, pd)           /* refine a node */
426 < register PNODE  *p;
426 > register PNODE  *p;
427   int  xmin, ymin, xmax, ymax;
428   int  pd;
429   {
# Line 358 | Line 444 | int  pd;
444          if (p->kid == NULL) {                   /* subdivide */
445  
446                  if ((p->kid = newptree()) == NULL)
447 <                        error(SYSTEM, "out of memory in refine");
447 >                        return(0);
448                  /*
449                   *  The following paint order can leave a black pixel
450 <                 *  when redraw() is called in (*dev->paintr)().
450 >                 *  if redraw() is called in (*dev->paintr)().
451                   */
452                  if (p->x >= mx && p->y >= my)
453                          pcopy(p, p->kid+UR);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines