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.11 by greg, Wed Sep 13 13:40:13 1989 UTC vs.
Revision 1.33 by greg, Mon Nov 11 17:42:19 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'-'@')
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;
68        if (pframe.l > pframe.r) pframe.l = pframe.r;
69        if (pframe.d > pframe.u) pframe.d = pframe.u;
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   {
# Line 89 | 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);
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];
# Line 105 | 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);
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++;
# Line 114 | 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);
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++;
# Line 123 | 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);
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++;
# Line 132 | 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);
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);
124 >        (*dev->comin)(buf, NULL);
125          if (buf[0] == CTRL(C)) return;
126 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
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 163 | Line 142 | char  *s;
142          VIEW  nv;
143  
144          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
145 <                bcopy(&stdview, &nv, sizeof(VIEW));
145 >                copystruct(&nv, &stdview);
146                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
147 <                                (success = viewfile(fname, &nv)) == -1) {
147 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
148                          sprintf(errmsg, "cannot open \"%s\"", buf);
149                          error(COMMAND, errmsg);
150                          return;
# Line 176 | 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  
190 getinterest(s, direc, vec, mp)          /* get area of interest */
191 char  *s;
192 int  direc;
193 FVECT  vec;
194 double  *mp;
195 {
196        int  x, y;
197        RAY  thisray;
198        register int  i;
199
200        if (sscanf(s, "%lf", mp) != 1)
201                *mp = 1.0;
202        else if (*mp < -FTINY)          /* negative zoom is reduction */
203                *mp = -1.0 / *mp;
204        else if (*mp <= FTINY) {        /* too small */
205                error(COMMAND, "illegal magnification");
206                return(-1);
207        }
208        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
209                if (dev->getcur == NULL)
210                        return(-1);
211                (*dev->comout)("Pick view center\n");
212                if ((*dev->getcur)(&x, &y) == ABORT)
213                        return(-1);
214                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
215                if (!direc || ourview.type == VT_PAR) {
216                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
217                        if (!localhit(&thisray, &thescene)) {
218                                error(COMMAND, "not a local object");
219                                return(-1);
220                        }
221                }
222                if (direc)
223                        if (ourview.type == VT_PAR)
224                                for (i = 0; i < 3; i++)
225                                        vec[i] = thisray.rop[i] - ourview.vp[i];
226                        else
227                                VCOPY(vec, thisray.rdir);
228                else
229                        VCOPY(vec, thisray.rop);
230        } else if (direc)
231                        for (i = 0; i < 3; i++)
232                                vec[i] -= ourview.vp[i];
233        return(0);
234 }
235
236
169   getaim(s)                               /* aim camera */
170   char  *s;
171   {
# Line 243 | 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;
251 <                nv.vert = ourview.vert / zfact;
252 <        } else {
253 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
254 <                                (PI/180./2.);
255 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
256 <                                (PI/180./2.);
257 <        }
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 284 | Line 210 | char  *s;
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.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 <        if ((nv.type = ourview.type) == VT_PAR) {
224 <                nv.horiz = ourview.horiz / zfact;
298 <                nv.vert = ourview.vert / zfact;
299 <        } else {
300 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
301 <                                (PI/180./2.);
302 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
303 <                                (PI/180./2.);
304 <        }
223 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
224 >        zoomview(&nv, zfact);
225          newview(&nv);
226   }
227  
# Line 343 | Line 263 | char  *s;
263                  if ((*dev->getcur)(&x, &y) == ABORT)
264                          return;
265                  r.l = r.d = 0;
266 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
266 >                r.r = hresolu; r.u = vresolu;
267                  p = findrect(x, y, &ptrunk, &r, -1);
268                  e = 1.0;
269          } else {
# Line 355 | Line 275 | char  *s;
275                          if (*cp == '\0') {      /* interactive */
276                                  sprintf(buf, "exposure (%lf): ", exposure);
277                                  (*dev->comout)(buf);
278 <                                (*dev->comin)(buf);
278 >                                (*dev->comin)(buf, NULL);
279                                  for (cp = buf; isspace(*cp); cp++)
280                                          ;
281                                  if (*cp == '\0')
# Line 385 | Line 305 | char  *s;
305   }
306  
307  
308 + getparam(str, dsc, typ, ptr)            /* get variable from user */
309 + char  *str, *dsc;
310 + int  typ;
311 + register union {int i; double d; COLOR C;}  *ptr;
312 + {
313 +        extern char  *index();
314 +        int  i0;
315 +        double  d0, d1, d2;
316 +        char  buf[48];
317 +
318 +        switch (typ) {
319 +        case 'i':                       /* integer */
320 +                if (sscanf(str, "%d", &i0) != 1) {
321 +                        (*dev->comout)(dsc);
322 +                        sprintf(buf, " (%d): ", ptr->i);
323 +                        (*dev->comout)(buf);
324 +                        (*dev->comin)(buf, NULL);
325 +                        if (sscanf(buf, "%d", &i0) != 1)
326 +                                return(0);
327 +                }
328 +                ptr->i = i0;
329 +                return(1);
330 +        case 'r':                       /* real */
331 +                if (sscanf(str, "%lf", &d0) != 1) {
332 +                        (*dev->comout)(dsc);
333 +                        sprintf(buf, " (%.6g): ", ptr->d);
334 +                        (*dev->comout)(buf);
335 +                        (*dev->comin)(buf, NULL);
336 +                        if (sscanf(buf, "%lf", &d0) != 1)
337 +                                return(0);
338 +                }
339 +                ptr->d = d0;
340 +                return(1);
341 +        case 'b':                       /* boolean */
342 +                if (sscanf(str, "%1s", buf) != 1) {
343 +                        (*dev->comout)(dsc);
344 +                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
345 +                        (*dev->comout)(buf);
346 +                        (*dev->comin)(buf, NULL);
347 +                        if (buf[0] == '\0' ||
348 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
349 +                                return(0);
350 +                }
351 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
352 +                return(1);
353 +        case 'C':                       /* color */
354 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
355 +                        (*dev->comout)(dsc);
356 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
357 +                                        colval(ptr->C,RED),
358 +                                        colval(ptr->C,GRN),
359 +                                        colval(ptr->C,BLU));
360 +                        (*dev->comout)(buf);
361 +                        (*dev->comin)(buf, NULL);
362 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
363 +                                return(0);
364 +                }
365 +                setcolor(ptr->C, d0, d1, d2);
366 +                return(1);
367 +        }
368 + }
369 +
370 +
371   setparam(s)                             /* get/set program parameter */
372   register char  *s;
373   {
# Line 402 | Line 385 | register char  *s;
385          extern int  ambdiv;
386          extern int  ambssamp;
387          extern int  ambounce;
388 <        int  i0;
389 <        double  d0, d1, d2;
388 >        extern int  directinvis;
389 >        extern double  srcsizerat;
390 >        extern int  do_irrad;
391          char  buf[128];
392          
393          if (s[0] == '\0') {
394 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
395 <                (*dev->comin)(buf);
394 >                (*dev->comout)(
395 >                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
396 >                (*dev->comin)(buf, NULL);
397                  s = buf;
398          }
399          switch (s[0]) {
400          case 'l':                       /* limit */
401                  switch (s[1]) {
402                  case 'w':                       /* weight */
403 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
419 <                                sprintf(buf, "limit weight (%.6g): ",
420 <                                                minweight);
421 <                                (*dev->comout)(buf);
422 <                                (*dev->comin)(buf);
423 <                                if (sscanf(buf, "%lf", &d0) != 1)
424 <                                        break;
425 <                        }
426 <                        minweight = d0;
403 >                        getparam(s+2, "limit weight", 'r', &minweight);
404                          break;
405                  case 'r':                       /* reflection */
406 <                        if (sscanf(s+2, "%d", &i0) != 1) {
430 <                                sprintf(buf, "limit reflection (%d): ",
431 <                                                maxdepth);
432 <                                (*dev->comout)(buf);
433 <                                (*dev->comin)(buf);
434 <                                if (sscanf(buf, "%d", &i0) != 1)
435 <                                        break;
436 <                        }
437 <                        maxdepth = i0;
406 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
407                          break;
408                  default:
409                          goto badparam;
# Line 443 | Line 412 | register char  *s;
412          case 'd':                       /* direct */
413                  switch (s[1]) {
414                  case 'j':                       /* jitter */
415 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
447 <                                sprintf(buf, "direct jitter (%.6g): ",
448 <                                                dstrsrc);
449 <                                (*dev->comout)(buf);
450 <                                (*dev->comin)(buf);
451 <                                if (sscanf(buf, "%lf", &d0) != 1)
452 <                                        break;
453 <                        }
454 <                        dstrsrc = d0;
415 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
416                          break;
417                  case 'c':                       /* certainty */
418 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
458 <                                sprintf(buf, "direct certainty (%.6g): ",
459 <                                                shadcert);
460 <                                (*dev->comout)(buf);
461 <                                (*dev->comin)(buf);
462 <                                if (sscanf(buf, "%lf", &d0) != 1)
463 <                                        break;
464 <                        }
465 <                        shadcert = d0;
418 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
419                          break;
420                  case 't':                       /* threshold */
421 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
469 <                                sprintf(buf, "direct threshold (%.6g): ",
470 <                                                shadthresh);
471 <                                (*dev->comout)(buf);
472 <                                (*dev->comin)(buf);
473 <                                if (sscanf(buf, "%lf", &d0) != 1)
474 <                                        break;
475 <                        }
476 <                        shadthresh = d0;
421 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
422                          break;
423 +                case 'i':                       /* invisibility */
424 +                        getparam(s+2, "direct invisibility",
425 +                                        'b', &directinvis);
426 +                        break;
427 +                case 's':                       /* sampling */
428 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
429 +                        break;
430                  default:
431                          goto badparam;
432                  }
433                  break;
434 +        case 'b':                       /* black and white */
435 +                getparam(s+1, "black and white", 'b', &greyscale);
436 +                break;
437 +        case 'i':                       /* irradiance */
438 +                getparam(s+1, "irradiance", 'b', &do_irrad);
439 +                break;
440          case 'a':                       /* ambient */
441                  switch (s[1]) {
442                  case 'v':                       /* value */
443 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
486 <                                sprintf(buf,
487 <                                        "ambient value (%.6g %.6g %.6g): ",
488 <                                                colval(ambval,RED),
489 <                                                colval(ambval,GRN),
490 <                                                colval(ambval,BLU));
491 <                                (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
493 <                                if (sscanf(buf, "%lf %lf %lf",
494 <                                                &d0, &d1, &d2) != 3)
495 <                                        break;
496 <                        }
497 <                        setcolor(ambval, d0, d1, d2);
443 >                        getparam(s+2, "ambient value", 'C', ambval);
444                          break;
445                  case 'a':                       /* accuracy */
446 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
501 <                                sprintf(buf, "ambient accuracy (%.6g): ",
502 <                                                ambacc);
503 <                                (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
505 <                                if (sscanf(buf, "%lf", &d0) != 1)
506 <                                        break;
507 <                        }
508 <                        ambacc = d0;
446 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
447                          break;
448                  case 'd':                       /* divisions */
449 <                        if (sscanf(s+2, "%d", &i0) != 1) {
512 <                                sprintf(buf, "ambient divisions (%d): ",
513 <                                                ambdiv);
514 <                                (*dev->comout)(buf);
515 <                                (*dev->comin)(buf);
516 <                                if (sscanf(buf, "%d", &i0) != 1)
517 <                                        break;
518 <                        }
519 <                        ambdiv = i0;
449 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
450                          break;
451                  case 's':                       /* samples */
452 <                        if (sscanf(s+2, "%d", &i0) != 1) {
523 <                                sprintf(buf, "ambient super-samples (%d): ",
524 <                                                ambssamp);
525 <                                (*dev->comout)(buf);
526 <                                (*dev->comin)(buf);
527 <                                if (sscanf(buf, "%d", &i0) != 1)
528 <                                        break;
529 <                        }
530 <                        ambssamp = i0;
452 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
453                          break;
454                  case 'b':                       /* bounces */
455 <                        if (sscanf(s+2, "%d", &i0) != 1) {
534 <                                sprintf(buf, "ambient bounces (%d): ",
535 <                                                ambounce);
536 <                                (*dev->comout)(buf);
537 <                                (*dev->comin)(buf);
538 <                                if (sscanf(buf, "%d", &i0) != 1)
539 <                                        break;
540 <                        }
541 <                        ambounce = i0;
455 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
456                          break;
457                  case 'r':
458 <                        if (sscanf(s+2, "%d", &i0) != 1) {
459 <                                sprintf(buf, "ambient resolution (%d): ",
460 <                                                ambres);
547 <                                (*dev->comout)(buf);
548 <                                (*dev->comin)(buf);
549 <                                if (sscanf(buf, "%d", &i0) != 1)
550 <                                        break;
551 <                        }
552 <                        ambres = i0;
553 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
458 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
459 >                                minarad = ambres > 0 ?
460 >                                                thescene.cusize/ambres : 0.0;
461                          break;
462                  default:
463                          goto badparam;
# Line 559 | Line 466 | register char  *s;
466          case 's':                       /* sample */
467                  switch (s[1]) {
468                  case 'p':                       /* pixel */
469 <                        if (sscanf(s+2, "%d", &i0) != 1) {
470 <                                sprintf(buf, "sample pixel (%d): ", psample);
564 <                                (*dev->comout)(buf);
565 <                                (*dev->comin)(buf);
566 <                                if (sscanf(buf, "%d", &i0) != 1)
567 <                                        break;
568 <                        }
569 <                        psample = i0;
570 <                        pdepth = 0;
469 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
470 >                                pdepth = 0;
471                          break;
472                  case 't':                       /* threshold */
473 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
474 <                                sprintf(buf, "sample threshold (%.6g): ",
575 <                                                maxdiff);
576 <                                (*dev->comout)(buf);
577 <                                (*dev->comin)(buf);
578 <                                if (sscanf(buf, "%lf", &d0) != 1)
579 <                                        break;
580 <                        }
581 <                        maxdiff = d0;
582 <                        pdepth = 0;
473 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
474 >                                pdepth = 0;
475                          break;
476                  default:
477                          goto badparam;
# Line 589 | Line 481 | register char  *s;
481                  break;
482          default:;
483   badparam:
484 +                *sskip(s) = '\0';
485                  sprintf(errmsg, "%s: unknown variable", s);
486                  error(COMMAND, errmsg);
487                  break;
# Line 613 | Line 506 | char  *s;
506                  if ((*dev->getcur)(&x, &y) == ABORT)
507                          return;
508  
509 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
510 <                
509 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
510 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
511 >                        error(COMMAND, "not on image");
512 >                        return;
513 >                }
514 >
515          } else if (normalize(thisray.rdir) == 0.0) {
516                  error(COMMAND, "zero ray direction");
517                  return;
# Line 632 | Line 529 | char  *s;
529                                  ofun[thisray.ro->otype].funame,
530                                  thisray.ro->oname);
531                  (*dev->comout)(buf);
532 <                (*dev->comin)(buf);
532 >                (*dev->comin)(buf, NULL);
533                  if (thisray.rot >= FHUGE)
534                          (*dev->comout)("at infinity");
535                  else {
# Line 640 | Line 537 | char  *s;
537                                          thisray.rop[1], thisray.rop[2]);
538                          (*dev->comout)(buf);
539                  }
540 <                (*dev->comin)(buf);
541 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
540 >                (*dev->comin)(buf, NULL);
541 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
542                                  colval(thisray.rcol,RED),
543                                  colval(thisray.rcol,GRN),
544 <                                colval(thisray.rcol,BLU));
544 >                                colval(thisray.rcol,BLU),
545 >                                luminance(thisray.rcol));
546                  (*dev->comout)(buf);
547          }
548 <        (*dev->comin)(buf);
548 >        (*dev->comin)(buf, NULL);
549   }
550  
551  
# Line 676 | Line 574 | char  *s;
574                                                  /* write header */
575          fputs(progname, fp);
576          fprintview(&ourview, fp);
577 <        putc('\n', fp);
577 >        if (octname != NULL)
578 >                fprintf(fp, " %s\n", octname);
579 >        else
580 >                putc('\n', fp);
581 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
582          if (exposure != 1.0)
583 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
583 >                fputexpos(exposure, fp);
584 >        if (dev->pixaspect != 1.0)
585 >                fputaspect(dev->pixaspect, fp);
586 >        fputformat(COLRFMT, fp);
587          putc('\n', fp);
588 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, fp);
588 >        fprtresolu(hresolu, vresolu, fp);
589  
590 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
591 <        if (scanline == NULL)
592 <                error(SYSTEM, "out of memory in writepict");
593 <        for (y = ourview.vresolu-1; y >= 0; y--) {
594 <                getpictcolrs(y, scanline, &ptrunk,
595 <                                ourview.hresolu, ourview.vresolu);
596 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
590 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
591 >        if (scanline == NULL) {
592 >                error(COMMAND, "not enough memory!");
593 >                fclose(fp);
594 >                unlink(fname);
595 >                return;
596 >        }
597 >        for (y = vresolu-1; y >= 0; y--) {
598 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
599 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
600                          break;
601          }
602 +        free((char *)scanline);
603          if (fclose(fp) < 0)
604                  error(COMMAND, "write error");
696        free((char *)scanline);
605   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines