ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rv2.c
(Generate patch)

Comparing ray/src/rt/rv2.c (file contents):
Revision 1.3 by greg, Fri Mar 3 18:34:33 1989 UTC vs.
Revision 2.4 by greg, Mon Dec 23 23:18:31 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "rpaint.h"
20  
21 + #include  "resolu.h"
22 +
23   #include  <ctype.h>
24  
25 < #define  CTRL(c)        ('c'-'@')
25 > #define  CTRL(c)        ((c)-'@')
26  
27 + extern char  VersionID[];
28   extern char  *progname;
29 + extern char  *octname;
30  
31  
32   getframe(s)                             /* get a new frame */
33   char  *s;
34   {
35 <        int  x0, y0, x1, y1;
32 <
33 <        if (!strcmp("all", s)) {
34 <                pframe.l = pframe.d = 0;
35 <                pframe.r = ourview.hresolu;
36 <                pframe.u = ourview.vresolu;
37 <                pdepth = 0;
35 >        if (getrect(s, &pframe) < 0)
36                  return;
39        }
40        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
41                if (dev->getcur == NULL)
42                        return;
43                (*dev->comout)("Pick first corner\n");
44                if ((*dev->getcur)(&x0, &y0) == ABORT)
45                        return;
46                (*dev->comout)("Pick second corner\n");
47                if ((*dev->getcur)(&x1, &y1) == ABORT)
48                        return;
49        }
50        if (x0 < x1) {
51                pframe.l = x0;
52                pframe.r = x1;
53        } else {
54                pframe.l = x1;
55                pframe.r = x0;
56        }
57        if (y0 < y1) {
58                pframe.d = y0;
59                pframe.u = y1;
60        } else {
61                pframe.d = y1;
62                pframe.u = y0;
63        }
64        if (pframe.l < 0) pframe.l = 0;
65        if (pframe.d < 0) pframe.d = 0;
66        if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu;
67        if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu;
37          pdepth = 0;
38   }
39  
40  
41 + getrepaint(s)                           /* get area and repaint */
42 + char  *s;
43 + {
44 +        RECT  box;
45 +
46 +        if (getrect(s, &box) < 0)
47 +                return;
48 +        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
49 + }
50 +
51 +
52   getview(s)                              /* get/show view parameters */
53   char  *s;
54   {
55          FILE  *fp;
56          char  buf[128];
57 <        char  *fname, *getpath();
57 >        char  *fname;
58          int  change = 0;
59          VIEW  nv;
60  
61          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
62 <                if ((fname = getpath(buf, NULL)) == NULL ||
62 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
63                                  (fp = fopen(fname, "a")) == NULL) {
64                          sprintf(errmsg, "cannot open \"%s\"", buf);
65                          error(COMMAND, errmsg);
# Line 87 | Line 67 | char  *s;
67                  }
68                  fputs(progname, fp);
69                  fprintview(&ourview, fp);
70 +                fputs(sskip(s), fp);
71                  fputs("\n", fp);
72                  fclose(fp);
73                  return;
74          }
75          sprintf(buf, "view type (%c): ", ourview.type);
76          (*dev->comout)(buf);
77 <        (*dev->comin)(buf);
78 <        if (buf[0] == CTRL(C)) return;
77 >        (*dev->comin)(buf, NULL);
78 >        if (buf[0] == CTRL('C')) return;
79          if (buf[0] && buf[0] != ourview.type) {
80                  nv.type = buf[0];
81                  change++;
# Line 103 | Line 84 | char  *s;
84          sprintf(buf, "view point (%.6g %.6g %.6g): ",
85                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
86          (*dev->comout)(buf);
87 <        (*dev->comin)(buf);
88 <        if (buf[0] == CTRL(C)) return;
87 >        (*dev->comin)(buf, NULL);
88 >        if (buf[0] == CTRL('C')) return;
89          if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
90                  change++;
91          else
# Line 112 | Line 93 | char  *s;
93          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
94                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
95          (*dev->comout)(buf);
96 <        (*dev->comin)(buf);
97 <        if (buf[0] == CTRL(C)) return;
96 >        (*dev->comin)(buf, NULL);
97 >        if (buf[0] == CTRL('C')) return;
98          if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
99                  change++;
100          else
# Line 121 | Line 102 | char  *s;
102          sprintf(buf, "view up (%.6g %.6g %.6g): ",
103                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
104          (*dev->comout)(buf);
105 <        (*dev->comin)(buf);
106 <        if (buf[0] == CTRL(C)) return;
105 >        (*dev->comin)(buf, NULL);
106 >        if (buf[0] == CTRL('C')) return;
107          if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
108                  change++;
109          else
# Line 130 | Line 111 | char  *s;
111          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
112                          ourview.horiz, ourview.vert);
113          (*dev->comout)(buf);
114 <        (*dev->comin)(buf);
115 <        if (buf[0] == CTRL(C)) return;
114 >        (*dev->comin)(buf, NULL);
115 >        if (buf[0] == CTRL('C')) return;
116          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
117                  change++;
118          else {
119                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
120          }
121 <        sprintf(buf, "x and y resolution (%d %d): ",
122 <                        ourview.hresolu, ourview.vresolu);
121 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
122 >                        ourview.hoff, ourview.voff);
123          (*dev->comout)(buf);
124 <        (*dev->comin)(buf);
125 <        if (buf[0] == CTRL(C)) return;
126 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
124 >        (*dev->comin)(buf, NULL);
125 >        if (buf[0] == CTRL('C')) return;
126 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
127                  change++;
128          else {
129 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
129 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
130          }
131          if (change)
132                  newview(&nv);
# Line 156 | Line 137 | lastview(s)                            /* return to a previous view */
137   char  *s;
138   {
139          char  buf[128];
140 <        char  *fname, *getpath();
140 >        char  *fname;
141          int  success;
142          VIEW  nv;
143  
144          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
145 <                bcopy(&stdview, &nv, sizeof(VIEW));
146 <                if ((fname = getpath(buf, NULL)) == NULL ||
147 <                                (success = viewfile(fname, &nv)) == -1) {
145 >                copystruct(&nv, &stdview);
146 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
147 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
148                          sprintf(errmsg, "cannot open \"%s\"", buf);
149                          error(COMMAND, errmsg);
150                          return;
# Line 174 | Line 155 | char  *s;
155                          newview(&nv);
156                  return;
157          }
158 <        if (oldview.hresolu == 0) {     /* no old view! */
158 >        if (oldview.type == 0) {        /* no old view! */
159                  error(COMMAND, "no previous view");
160                  return;
161          }
162 <        bcopy(&ourview, &nv, sizeof(VIEW));
163 <        bcopy(&oldview, &ourview, sizeof(VIEW));
164 <        bcopy(&nv, &oldview, sizeof(VIEW));
162 >        copystruct(&nv, &ourview);
163 >        copystruct(&ourview, &oldview);
164 >        copystruct(&oldview, &nv);
165          newimage();
166   }
167  
168  
188 getinterest(s, direc, vec, mp)          /* get area of interest */
189 char  *s;
190 int  direc;
191 FVECT  vec;
192 double  *mp;
193 {
194        int  x, y;
195        RAY  thisray;
196        register int  i;
197
198        if (sscanf(s, "%lf", mp) != 1)
199                *mp = 1.0;
200        else if (*mp < -FTINY)          /* negative zoom is reduction */
201                *mp = -1.0 / *mp;
202        else if (*mp <= FTINY) {        /* too small */
203                error(COMMAND, "illegal magnification");
204                return(-1);
205        }
206        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
207                if (dev->getcur == NULL)
208                        return(-1);
209                (*dev->comout)("Pick view center\n");
210                if ((*dev->getcur)(&x, &y) == ABORT)
211                        return(-1);
212                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
213                if (!direc || ourview.type == VT_PAR) {
214                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
215                        if (!localhit(&thisray, &thescene)) {
216                                error(COMMAND, "not a local object");
217                                return(-1);
218                        }
219                }
220                if (direc)
221                        if (ourview.type == VT_PAR)
222                                for (i = 0; i < 3; i++)
223                                        vec[i] = thisray.rop[i] - ourview.vp[i];
224                        else
225                                VCOPY(vec, thisray.rdir);
226                else
227                        VCOPY(vec, thisray.rop);
228        } else if (direc)
229                        for (i = 0; i < 3; i++)
230                                vec[i] -= ourview.vp[i];
231        return(0);
232 }
233
234
169   getaim(s)                               /* aim camera */
170   char  *s;
171   {
# Line 241 | Line 175 | char  *s;
175  
176          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
177                  return;
178 +        nv.type = ourview.type;
179          VCOPY(nv.vp, ourview.vp);
180          VCOPY(nv.vup, ourview.vup);
181 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
182 <        if ((nv.type = ourview.type) == VT_PAR) {
183 <                nv.horiz = ourview.horiz / zfact;
249 <                nv.vert = ourview.vert / zfact;
250 <        } else {
251 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
252 <                                (PI/180./2.);
253 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
254 <                                (PI/180./2.);
255 <        }
181 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
182 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
183 >        zoomview(&nv, zfact);
184          newview(&nv);
185   }
186  
# Line 265 | Line 193 | char  *s;
193  
194          if (getinterest(s, 0, vc, &mag) < 0)
195                  return;
196 <        moveview(0.0, mag, vc);
196 >        moveview(0.0, 0.0, mag, vc);
197   }
198  
199  
200   getrotate(s)                            /* rotate camera */
201   char  *s;
202   {
203 <        extern double  normalize();
203 >        extern double  normalize(), tan(), atan();
204          VIEW  nv;
205          FVECT  v1;
206 <        double  angle, elev;
206 >        double  angle, elev, zfact;
207          
208 <        elev = 0.0;
209 <        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
208 >        elev = 0.0; zfact = 1.0;
209 >        if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) {
210                  error(COMMAND, "missing angle");
211                  return;
212          }
213          nv.type = ourview.type;
214          VCOPY(nv.vp, ourview.vp);
215          VCOPY(nv.vup, ourview.vup);
216 <        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
289 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
216 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
217          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
218          if (elev != 0.0) {
219                  fcross(v1, nv.vdir, ourview.vup);
220                  normalize(v1);
221                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
222          }
223 +        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
224 +        zoomview(&nv, zfact);
225          newview(&nv);
226   }
227  
# Line 301 | Line 230 | getpivot(s)                            /* pivot viewpoint */
230   register char  *s;
231   {
232          FVECT  vc;
233 <        double  angle, mag;
233 >        double  angle, elev, mag;
234  
235 <        if (sscanf(s, "%lf", &angle) != 1) {
235 >        elev = 0.0;
236 >        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
237                  error(COMMAND, "missing angle");
238                  return;
239          }
240 <        if (getinterest(sskip(s), 0, vc, &mag) < 0)
240 >        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
241                  return;
242 <        moveview(angle, mag, vc);
242 >        moveview(angle, elev, mag, vc);
243   }
244  
245  
246   getexposure(s)                          /* get new exposure */
247   char  *s;
248   {
319        double  atof(), pow(), fabs();
249          char  buf[128];
250          register char  *cp;
251          register PNODE  *p;
# Line 333 | Line 262 | char  *s;
262                  if ((*dev->getcur)(&x, &y) == ABORT)
263                          return;
264                  r.l = r.d = 0;
265 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
265 >                r.r = hresolu; r.u = vresolu;
266                  p = findrect(x, y, &ptrunk, &r, -1);
267                  e = 1.0;
268          } else {
# Line 345 | Line 274 | char  *s;
274                          if (*cp == '\0') {      /* interactive */
275                                  sprintf(buf, "exposure (%lf): ", exposure);
276                                  (*dev->comout)(buf);
277 <                                (*dev->comin)(buf);
277 >                                (*dev->comin)(buf, NULL);
278                                  for (cp = buf; isspace(*cp); cp++)
279                                          ;
280                                  if (*cp == '\0')
# Line 361 | Line 290 | char  *s;
290                          e *= atof(cp);
291          }
292          if (p != NULL) {                /* relative setting */
293 <                if (intens(p->v) <= FTINY) {
293 >                if (bright(p->v) <= FTINY) {
294                          error(COMMAND, "cannot normalize to zero");
295                          return;
296                  }
297 <                e *= 0.5 / intens(p->v);
297 >                e *= 0.5 / bright(p->v);
298          }
299          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
300                  return;
# Line 375 | Line 304 | char  *s;
304   }
305  
306  
307 + getparam(str, dsc, typ, ptr)            /* get variable from user */
308 + char  *str, *dsc;
309 + int  typ;
310 + register union {int i; double d; COLOR C;}  *ptr;
311 + {
312 +        extern char  *index();
313 +        int  i0;
314 +        double  d0, d1, d2;
315 +        char  buf[48];
316 +
317 +        switch (typ) {
318 +        case 'i':                       /* integer */
319 +                if (sscanf(str, "%d", &i0) != 1) {
320 +                        (*dev->comout)(dsc);
321 +                        sprintf(buf, " (%d): ", ptr->i);
322 +                        (*dev->comout)(buf);
323 +                        (*dev->comin)(buf, NULL);
324 +                        if (sscanf(buf, "%d", &i0) != 1)
325 +                                return(0);
326 +                }
327 +                ptr->i = i0;
328 +                return(1);
329 +        case 'r':                       /* real */
330 +                if (sscanf(str, "%lf", &d0) != 1) {
331 +                        (*dev->comout)(dsc);
332 +                        sprintf(buf, " (%.6g): ", ptr->d);
333 +                        (*dev->comout)(buf);
334 +                        (*dev->comin)(buf, NULL);
335 +                        if (sscanf(buf, "%lf", &d0) != 1)
336 +                                return(0);
337 +                }
338 +                ptr->d = d0;
339 +                return(1);
340 +        case 'b':                       /* boolean */
341 +                if (sscanf(str, "%1s", buf) != 1) {
342 +                        (*dev->comout)(dsc);
343 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
344 +                        (*dev->comout)(buf);
345 +                        (*dev->comin)(buf, NULL);
346 +                        if (buf[0] == '\0' ||
347 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
348 +                                return(0);
349 +                }
350 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
351 +                return(1);
352 +        case 'C':                       /* color */
353 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
354 +                        (*dev->comout)(dsc);
355 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
356 +                                        colval(ptr->C,RED),
357 +                                        colval(ptr->C,GRN),
358 +                                        colval(ptr->C,BLU));
359 +                        (*dev->comout)(buf);
360 +                        (*dev->comin)(buf, NULL);
361 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
362 +                                return(0);
363 +                }
364 +                setcolor(ptr->C, d0, d1, d2);
365 +                return(1);
366 +        }
367 + }
368 +
369 +
370   setparam(s)                             /* get/set program parameter */
371   register char  *s;
372   {
# Line 383 | Line 375 | register char  *s;
375          extern double  minweight;
376          extern int  maxdepth;
377          extern double  dstrsrc;
378 +        extern double  shadthresh;
379 +        extern double  shadcert;
380          extern COLOR  ambval;
381          extern double  ambacc;
382          extern double  minarad;
# Line 390 | Line 384 | register char  *s;
384          extern int  ambdiv;
385          extern int  ambssamp;
386          extern int  ambounce;
387 <        int  i0;
388 <        double  d0, d1, d2;
387 >        extern int  directinvis;
388 >        extern double  srcsizerat;
389 >        extern int  do_irrad;
390          char  buf[128];
391          
392          if (s[0] == '\0') {
393 <                (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: ");
394 <                (*dev->comin)(buf);
393 >                (*dev->comout)(
394 >                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
395 >                (*dev->comin)(buf, NULL);
396                  s = buf;
397          }
398          switch (s[0]) {
399          case 'l':                       /* limit */
400                  switch (s[1]) {
401                  case 'w':                       /* weight */
402 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
407 <                                sprintf(buf, "limit weight (%.6g): ",
408 <                                                minweight);
409 <                                (*dev->comout)(buf);
410 <                                (*dev->comin)(buf);
411 <                                if (sscanf(buf, "%lf", &d0) != 1)
412 <                                        break;
413 <                        }
414 <                        minweight = d0;
402 >                        getparam(s+2, "limit weight", 'r', &minweight);
403                          break;
404                  case 'r':                       /* reflection */
405 <                        if (sscanf(s+2, "%d", &i0) != 1) {
418 <                                sprintf(buf, "limit reflection (%d): ",
419 <                                                maxdepth);
420 <                                (*dev->comout)(buf);
421 <                                (*dev->comin)(buf);
422 <                                if (sscanf(buf, "%d", &i0) != 1)
423 <                                        break;
424 <                        }
425 <                        maxdepth = i0;
405 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
406                          break;
407                  default:
408                          goto badparam;
409                  }
410                  break;
411 <        case 'd':                       /* distribute source */
412 <                if (s[1] != 's')
411 >        case 'd':                       /* direct */
412 >                switch (s[1]) {
413 >                case 'j':                       /* jitter */
414 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
415 >                        break;
416 >                case 'c':                       /* certainty */
417 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
418 >                        break;
419 >                case 't':                       /* threshold */
420 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
421 >                        break;
422 >                case 'i':                       /* invisibility */
423 >                        getparam(s+2, "direct invisibility",
424 >                                        'b', &directinvis);
425 >                        break;
426 >                case 's':                       /* sampling */
427 >                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
428 >                        break;
429 >                default:
430                          goto badparam;
434                if (sscanf(s+2, "%lf", &d0) != 1) {
435                        sprintf(buf, "distribute source (%.6g): ", dstrsrc);
436                        (*dev->comout)(buf);
437                        (*dev->comin)(buf);
438                        if (sscanf(buf, "%lf", &d0) != 1)
439                                break;
431                  }
441                dstrsrc = d0;
432                  break;
433 +        case 'b':                       /* black and white */
434 +                getparam(s+1, "black and white", 'b', &greyscale);
435 +                break;
436 +        case 'i':                       /* irradiance */
437 +                getparam(s+1, "irradiance", 'b', &do_irrad);
438 +                break;
439          case 'a':                       /* ambient */
440                  switch (s[1]) {
441                  case 'v':                       /* value */
442 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
447 <                                sprintf(buf,
448 <                                        "ambient value (%.6g %.6g %.6g): ",
449 <                                                colval(ambval,RED),
450 <                                                colval(ambval,GRN),
451 <                                                colval(ambval,BLU));
452 <                                (*dev->comout)(buf);
453 <                                (*dev->comin)(buf);
454 <                                if (sscanf(buf, "%lf %lf %lf",
455 <                                                &d0, &d1, &d2) != 3)
456 <                                        break;
457 <                        }
458 <                        setcolor(ambval, d0, d1, d2);
442 >                        getparam(s+2, "ambient value", 'C', ambval);
443                          break;
444                  case 'a':                       /* accuracy */
445 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
462 <                                sprintf(buf, "ambient accuracy (%.6g): ",
463 <                                                ambacc);
464 <                                (*dev->comout)(buf);
465 <                                (*dev->comin)(buf);
466 <                                if (sscanf(buf, "%lf", &d0) != 1)
467 <                                        break;
468 <                        }
469 <                        ambacc = d0;
445 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
446                          break;
447                  case 'd':                       /* divisions */
448 <                        if (sscanf(s+2, "%d", &i0) != 1) {
473 <                                sprintf(buf, "ambient divisions (%d): ",
474 <                                                ambdiv);
475 <                                (*dev->comout)(buf);
476 <                                (*dev->comin)(buf);
477 <                                if (sscanf(buf, "%d", &i0) != 1)
478 <                                        break;
479 <                        }
480 <                        ambdiv = i0;
448 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
449                          break;
450                  case 's':                       /* samples */
451 <                        if (sscanf(s+2, "%d", &i0) != 1) {
484 <                                sprintf(buf, "ambient super-samples (%d): ",
485 <                                                ambssamp);
486 <                                (*dev->comout)(buf);
487 <                                (*dev->comin)(buf);
488 <                                if (sscanf(buf, "%d", &i0) != 1)
489 <                                        break;
490 <                        }
491 <                        ambssamp = i0;
451 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
452                          break;
453                  case 'b':                       /* bounces */
454 <                        if (sscanf(s+2, "%d", &i0) != 1) {
495 <                                sprintf(buf, "ambient bounces (%d): ",
496 <                                                ambounce);
497 <                                (*dev->comout)(buf);
498 <                                (*dev->comin)(buf);
499 <                                if (sscanf(buf, "%d", &i0) != 1)
500 <                                        break;
501 <                        }
502 <                        ambounce = i0;
454 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
455                          break;
456                  case 'r':
457 <                        if (sscanf(s+2, "%d", &i0) != 1) {
458 <                                sprintf(buf, "ambient resolution (%d): ",
459 <                                                ambres);
508 <                                (*dev->comout)(buf);
509 <                                (*dev->comin)(buf);
510 <                                if (sscanf(buf, "%d", &i0) != 1)
511 <                                        break;
512 <                        }
513 <                        ambres = i0;
514 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
457 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
458 >                                minarad = ambres > 0 ?
459 >                                                thescene.cusize/ambres : 0.0;
460                          break;
461                  default:
462                          goto badparam;
# Line 520 | Line 465 | register char  *s;
465          case 's':                       /* sample */
466                  switch (s[1]) {
467                  case 'p':                       /* pixel */
468 <                        if (sscanf(s+2, "%d", &i0) != 1) {
469 <                                sprintf(buf, "sample pixel (%d): ", psample);
525 <                                (*dev->comout)(buf);
526 <                                (*dev->comin)(buf);
527 <                                if (sscanf(buf, "%d", &i0) != 1)
528 <                                        break;
529 <                        }
530 <                        psample = i0;
531 <                        pdepth = 0;
468 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
469 >                                pdepth = 0;
470                          break;
471 <                case 'd':                       /* difference */
472 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
473 <                                sprintf(buf, "sample difference (%.6g): ",
536 <                                                maxdiff);
537 <                                (*dev->comout)(buf);
538 <                                (*dev->comin)(buf);
539 <                                if (sscanf(buf, "%lf", &d0) != 1)
540 <                                        break;
541 <                        }
542 <                        maxdiff = d0;
543 <                        pdepth = 0;
471 >                case 't':                       /* threshold */
472 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
473 >                                pdepth = 0;
474                          break;
475                  default:
476                          goto badparam;
# Line 550 | Line 480 | register char  *s;
480                  break;
481          default:;
482   badparam:
483 +                *sskip(s) = '\0';
484                  sprintf(errmsg, "%s: unknown variable", s);
485                  error(COMMAND, errmsg);
486                  break;
# Line 574 | Line 505 | char  *s;
505                  if ((*dev->getcur)(&x, &y) == ABORT)
506                          return;
507  
508 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
509 <                
508 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
509 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
510 >                        error(COMMAND, "not on image");
511 >                        return;
512 >                }
513 >
514          } else if (normalize(thisray.rdir) == 0.0) {
515                  error(COMMAND, "zero ray direction");
516                  return;
# Line 593 | Line 528 | char  *s;
528                                  ofun[thisray.ro->otype].funame,
529                                  thisray.ro->oname);
530                  (*dev->comout)(buf);
531 <                (*dev->comin)(buf);
531 >                (*dev->comin)(buf, NULL);
532                  if (thisray.rot >= FHUGE)
533                          (*dev->comout)("at infinity");
534                  else {
# Line 601 | Line 536 | char  *s;
536                                          thisray.rop[1], thisray.rop[2]);
537                          (*dev->comout)(buf);
538                  }
539 <                (*dev->comin)(buf);
540 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
539 >                (*dev->comin)(buf, NULL);
540 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
541                                  colval(thisray.rcol,RED),
542                                  colval(thisray.rcol,GRN),
543 <                                colval(thisray.rcol,BLU));
543 >                                colval(thisray.rcol,BLU),
544 >                                luminance(thisray.rcol));
545                  (*dev->comout)(buf);
546          }
547 <        (*dev->comin)(buf);
547 >        (*dev->comin)(buf, NULL);
548   }
549  
550  
# Line 616 | Line 552 | writepict(s)                           /* write the picture to a file */
552   char  *s;
553   {
554          static char  buf[128];
555 <        char  *fname, *getpath();
555 >        char  *fname;
556          FILE  *fp;
557          COLR  *scanline;
558          int  y;
# Line 625 | Line 561 | char  *s;
561                  error(COMMAND, "no file");
562                  return;
563          }
564 <        if ((fname = getpath(buf, NULL)) == NULL ||
564 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
565                          (fp = fopen(fname, "w")) == NULL) {
566                  sprintf(errmsg, "cannot open \"%s\"", buf);
567                  error(COMMAND, errmsg);
# Line 637 | Line 573 | char  *s;
573                                                  /* write header */
574          fputs(progname, fp);
575          fprintview(&ourview, fp);
576 <        fputs("\n", fp);
576 >        if (octname != NULL)
577 >                fprintf(fp, " %s\n", octname);
578 >        else
579 >                putc('\n', fp);
580 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
581          if (exposure != 1.0)
582 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
583 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
582 >                fputexpos(exposure, fp);
583 >        if (dev->pixaspect != 1.0)
584 >                fputaspect(dev->pixaspect, fp);
585 >        fputformat(COLRFMT, fp);
586 >        putc('\n', fp);
587 >        fprtresolu(hresolu, vresolu, fp);
588  
589 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
590 <        if (scanline == NULL)
591 <                error(SYSTEM, "out of memory in writepict");
592 <        for (y = ourview.vresolu-1; y >= 0; y--) {
593 <                getpictcolrs(y, scanline, &ptrunk,
594 <                                ourview.hresolu, ourview.vresolu);
595 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
589 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
590 >        if (scanline == NULL) {
591 >                error(COMMAND, "not enough memory!");
592 >                fclose(fp);
593 >                unlink(fname);
594 >                return;
595 >        }
596 >        for (y = vresolu-1; y >= 0; y--) {
597 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
598 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
599                          break;
600          }
601 +        free((char *)scanline);
602          if (fclose(fp) < 0)
603                  error(COMMAND, "write error");
656        free((char *)scanline);
604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines