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.10 by greg, Thu Jul 27 22:58:26 1989 UTC vs.
Revision 1.32 by greg, Tue Oct 29 12:06:44 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 22 | Line 22 | static char SCCSid[] = "$SunId$ LBL";
22  
23   #define  CTRL(c)        ('c'-'@')
24  
25 + extern char  VersionID[];
26   extern char  *progname;
27 + extern char  *octname;
28  
29  
30   getframe(s)                             /* get a new frame */
31   char  *s;
32   {
33 <        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;
33 >        if (getrect(s, &pframe) < 0)
34                  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;
35          pdepth = 0;
36   }
37  
38  
39 + getrepaint(s)                           /* get area and repaint */
40 + char  *s;
41 + {
42 +        RECT  box;
43 +
44 +        if (getrect(s, &box) < 0)
45 +                return;
46 +        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
47 + }
48 +
49 +
50   getview(s)                              /* get/show view parameters */
51   char  *s;
52   {
# Line 89 | Line 65 | char  *s;
65                  }
66                  fputs(progname, fp);
67                  fprintview(&ourview, fp);
68 +                fputs(sskip(s), fp);
69                  fputs("\n", fp);
70                  fclose(fp);
71                  return;
72          }
73          sprintf(buf, "view type (%c): ", ourview.type);
74          (*dev->comout)(buf);
75 <        (*dev->comin)(buf);
75 >        (*dev->comin)(buf, NULL);
76          if (buf[0] == CTRL(C)) return;
77          if (buf[0] && buf[0] != ourview.type) {
78                  nv.type = buf[0];
# Line 105 | Line 82 | char  *s;
82          sprintf(buf, "view point (%.6g %.6g %.6g): ",
83                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
84          (*dev->comout)(buf);
85 <        (*dev->comin)(buf);
85 >        (*dev->comin)(buf, NULL);
86          if (buf[0] == CTRL(C)) return;
87          if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
88                  change++;
# Line 114 | Line 91 | char  *s;
91          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
92                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
93          (*dev->comout)(buf);
94 <        (*dev->comin)(buf);
94 >        (*dev->comin)(buf, NULL);
95          if (buf[0] == CTRL(C)) return;
96          if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
97                  change++;
# Line 123 | Line 100 | char  *s;
100          sprintf(buf, "view up (%.6g %.6g %.6g): ",
101                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
102          (*dev->comout)(buf);
103 <        (*dev->comin)(buf);
103 >        (*dev->comin)(buf, NULL);
104          if (buf[0] == CTRL(C)) return;
105          if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
106                  change++;
# Line 132 | Line 109 | char  *s;
109          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
110                          ourview.horiz, ourview.vert);
111          (*dev->comout)(buf);
112 <        (*dev->comin)(buf);
112 >        (*dev->comin)(buf, NULL);
113          if (buf[0] == CTRL(C)) return;
114          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
115                  change++;
116          else {
117                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
118          }
119 <        sprintf(buf, "x and y resolution (%d %d): ",
120 <                        ourview.hresolu, ourview.vresolu);
119 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
120 >                        ourview.hoff, ourview.voff);
121          (*dev->comout)(buf);
122 <        (*dev->comin)(buf);
122 >        (*dev->comin)(buf, NULL);
123          if (buf[0] == CTRL(C)) return;
124 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
124 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
125                  change++;
126          else {
127 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
127 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
128          }
129          if (change)
130                  newview(&nv);
# Line 163 | Line 140 | char  *s;
140          VIEW  nv;
141  
142          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
143 <                bcopy(&stdview, &nv, sizeof(VIEW));
143 >                copystruct(&nv, &stdview);
144                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
145 <                                (success = viewfile(fname, &nv)) == -1) {
145 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
146                          sprintf(errmsg, "cannot open \"%s\"", buf);
147                          error(COMMAND, errmsg);
148                          return;
# Line 176 | Line 153 | char  *s;
153                          newview(&nv);
154                  return;
155          }
156 <        if (oldview.hresolu == 0) {     /* no old view! */
156 >        if (oldview.type == 0) {        /* no old view! */
157                  error(COMMAND, "no previous view");
158                  return;
159          }
160 <        bcopy(&ourview, &nv, sizeof(VIEW));
161 <        bcopy(&oldview, &ourview, sizeof(VIEW));
162 <        bcopy(&nv, &oldview, sizeof(VIEW));
160 >        copystruct(&nv, &ourview);
161 >        copystruct(&ourview, &oldview);
162 >        copystruct(&oldview, &nv);
163          newimage();
164   }
165  
166  
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
167   getaim(s)                               /* aim camera */
168   char  *s;
169   {
# Line 243 | Line 173 | char  *s;
173  
174          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
175                  return;
176 +        nv.type = ourview.type;
177          VCOPY(nv.vp, ourview.vp);
178          VCOPY(nv.vup, ourview.vup);
179 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
180 <        if ((nv.type = ourview.type) == VT_PAR) {
181 <                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 <        }
179 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
180 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
181 >        zoomview(&nv, zfact);
182          newview(&nv);
183   }
184  
# Line 284 | Line 208 | char  *s;
208                  error(COMMAND, "missing angle");
209                  return;
210          }
211 +        nv.type = ourview.type;
212          VCOPY(nv.vp, ourview.vp);
213          VCOPY(nv.vup, ourview.vup);
214 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
214 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
215          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
216          if (elev != 0.0) {
217                  fcross(v1, nv.vdir, ourview.vup);
218                  normalize(v1);
219                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
220          }
221 <        if ((nv.type = ourview.type) == VT_PAR) {
222 <                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 <        }
221 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
222 >        zoomview(&nv, zfact);
223          newview(&nv);
224   }
225  
# Line 343 | Line 261 | char  *s;
261                  if ((*dev->getcur)(&x, &y) == ABORT)
262                          return;
263                  r.l = r.d = 0;
264 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
264 >                r.r = hresolu; r.u = vresolu;
265                  p = findrect(x, y, &ptrunk, &r, -1);
266                  e = 1.0;
267          } else {
# Line 355 | Line 273 | char  *s;
273                          if (*cp == '\0') {      /* interactive */
274                                  sprintf(buf, "exposure (%lf): ", exposure);
275                                  (*dev->comout)(buf);
276 <                                (*dev->comin)(buf);
276 >                                (*dev->comin)(buf, NULL);
277                                  for (cp = buf; isspace(*cp); cp++)
278                                          ;
279                                  if (*cp == '\0')
# Line 385 | Line 303 | char  *s;
303   }
304  
305  
306 + getparam(str, dsc, typ, ptr)            /* get variable from user */
307 + char  *str, *dsc;
308 + int  typ;
309 + register union {int i; double d; COLOR C;}  *ptr;
310 + {
311 +        extern char  *index();
312 +        int  i0;
313 +        double  d0, d1, d2;
314 +        char  buf[48];
315 +
316 +        switch (typ) {
317 +        case 'i':                       /* integer */
318 +                if (sscanf(str, "%d", &i0) != 1) {
319 +                        (*dev->comout)(dsc);
320 +                        sprintf(buf, " (%d): ", ptr->i);
321 +                        (*dev->comout)(buf);
322 +                        (*dev->comin)(buf, NULL);
323 +                        if (sscanf(buf, "%d", &i0) != 1)
324 +                                return(0);
325 +                }
326 +                ptr->i = i0;
327 +                return(1);
328 +        case 'r':                       /* real */
329 +                if (sscanf(str, "%lf", &d0) != 1) {
330 +                        (*dev->comout)(dsc);
331 +                        sprintf(buf, " (%.6g): ", ptr->d);
332 +                        (*dev->comout)(buf);
333 +                        (*dev->comin)(buf, NULL);
334 +                        if (sscanf(buf, "%lf", &d0) != 1)
335 +                                return(0);
336 +                }
337 +                ptr->d = d0;
338 +                return(1);
339 +        case 'b':                       /* boolean */
340 +                if (sscanf(str, "%1s", buf) != 1) {
341 +                        (*dev->comout)(dsc);
342 +                        sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n');
343 +                        (*dev->comout)(buf);
344 +                        (*dev->comin)(buf, NULL);
345 +                        if (buf[0] == '\0' ||
346 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
347 +                                return(0);
348 +                }
349 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
350 +                return(1);
351 +        case 'C':                       /* color */
352 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
353 +                        (*dev->comout)(dsc);
354 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
355 +                                        colval(ptr->C,RED),
356 +                                        colval(ptr->C,GRN),
357 +                                        colval(ptr->C,BLU));
358 +                        (*dev->comout)(buf);
359 +                        (*dev->comin)(buf, NULL);
360 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
361 +                                return(0);
362 +                }
363 +                setcolor(ptr->C, d0, d1, d2);
364 +                return(1);
365 +        }
366 + }
367 +
368 +
369   setparam(s)                             /* get/set program parameter */
370   register char  *s;
371   {
# Line 402 | Line 383 | register char  *s;
383          extern int  ambdiv;
384          extern int  ambssamp;
385          extern int  ambounce;
386 <        int  i0;
387 <        double  d0, d1, d2;
386 >        extern int  directinvis;
387 >        extern double  srcsizerat;
388 >        extern int  do_irrad;
389          char  buf[128];
390          
391          if (s[0] == '\0') {
392 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
393 <                (*dev->comin)(buf);
392 >                (*dev->comout)(
393 >                        "aa ab ad ar as av b dc di dj ds dt i lr lw sp st: ");
394 >                (*dev->comin)(buf, NULL);
395                  s = buf;
396          }
397          switch (s[0]) {
398          case 'l':                       /* limit */
399                  switch (s[1]) {
400                  case 'w':                       /* weight */
401 <                        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;
401 >                        getparam(s+2, "limit weight", 'r', &minweight);
402                          break;
403                  case 'r':                       /* reflection */
404 <                        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;
404 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
405                          break;
406                  default:
407                          goto badparam;
# Line 443 | Line 410 | register char  *s;
410          case 'd':                       /* direct */
411                  switch (s[1]) {
412                  case 'j':                       /* jitter */
413 <                        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;
413 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
414                          break;
415                  case 'c':                       /* certainty */
416 <                        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;
416 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
417                          break;
418                  case 't':                       /* threshold */
419 <                        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;
419 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
420                          break;
421 +                case 'i':                       /* invisibility */
422 +                        getparam(s+2, "direct invisibility",
423 +                                        'b', &directinvis);
424 +                        break;
425 +                case 's':                       /* sampling */
426 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
427 +                        break;
428                  default:
429                          goto badparam;
430                  }
431                  break;
432 +        case 'b':                       /* black and white */
433 +                getparam(s+1, "black and white", 'b', &greyscale);
434 +                break;
435 +        case 'i':                       /* irradiance */
436 +                getparam(s+1, "irradiance", 'b', &do_irrad);
437 +                break;
438          case 'a':                       /* ambient */
439                  switch (s[1]) {
440                  case 'v':                       /* value */
441 <                        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);
441 >                        getparam(s+2, "ambient value", 'C', ambval);
442                          break;
443                  case 'a':                       /* accuracy */
444 <                        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;
444 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
445                          break;
446                  case 'd':                       /* divisions */
447 <                        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;
447 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
448                          break;
449                  case 's':                       /* samples */
450 <                        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;
450 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
451                          break;
452                  case 'b':                       /* bounces */
453 <                        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;
453 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
454                          break;
455                  case 'r':
456 <                        if (sscanf(s+2, "%d", &i0) != 1) {
457 <                                sprintf(buf, "ambient resolution (%d): ",
458 <                                                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;
456 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
457 >                                minarad = ambres > 0 ?
458 >                                                thescene.cusize/ambres : 0.0;
459                          break;
460                  default:
461                          goto badparam;
# Line 559 | Line 464 | register char  *s;
464          case 's':                       /* sample */
465                  switch (s[1]) {
466                  case 'p':                       /* pixel */
467 <                        if (sscanf(s+2, "%d", &i0) != 1) {
468 <                                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;
467 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
468 >                                pdepth = 0;
469                          break;
470                  case 't':                       /* threshold */
471 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
472 <                                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;
471 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
472 >                                pdepth = 0;
473                          break;
474                  default:
475                          goto badparam;
# Line 589 | Line 479 | register char  *s;
479                  break;
480          default:;
481   badparam:
482 +                *sskip(s) = '\0';
483                  sprintf(errmsg, "%s: unknown variable", s);
484                  error(COMMAND, errmsg);
485                  break;
# Line 613 | Line 504 | char  *s;
504                  if ((*dev->getcur)(&x, &y) == ABORT)
505                          return;
506  
507 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
508 <                
507 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
508 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
509 >                        error(COMMAND, "not on image");
510 >                        return;
511 >                }
512 >
513          } else if (normalize(thisray.rdir) == 0.0) {
514                  error(COMMAND, "zero ray direction");
515                  return;
# Line 632 | Line 527 | char  *s;
527                                  ofun[thisray.ro->otype].funame,
528                                  thisray.ro->oname);
529                  (*dev->comout)(buf);
530 <                (*dev->comin)(buf);
530 >                (*dev->comin)(buf, NULL);
531                  if (thisray.rot >= FHUGE)
532                          (*dev->comout)("at infinity");
533                  else {
# Line 640 | Line 535 | char  *s;
535                                          thisray.rop[1], thisray.rop[2]);
536                          (*dev->comout)(buf);
537                  }
538 <                (*dev->comin)(buf);
539 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
538 >                (*dev->comin)(buf, NULL);
539 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
540                                  colval(thisray.rcol,RED),
541                                  colval(thisray.rcol,GRN),
542 <                                colval(thisray.rcol,BLU));
542 >                                colval(thisray.rcol,BLU),
543 >                                luminance(thisray.rcol));
544                  (*dev->comout)(buf);
545          }
546 <        (*dev->comin)(buf);
546 >        (*dev->comin)(buf, NULL);
547   }
548  
549  
# Line 676 | Line 572 | char  *s;
572                                                  /* write header */
573          fputs(progname, fp);
574          fprintview(&ourview, fp);
575 <        fputs("\n", fp);
575 >        if (octname != NULL)
576 >                fprintf(fp, " %s\n", octname);
577 >        else
578 >                putc('\n', fp);
579 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
580          if (exposure != 1.0)
581 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
582 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
581 >                fputexpos(exposure, fp);
582 >        if (dev->pixaspect != 1.0)
583 >                fputaspect(dev->pixaspect, fp);
584 >        fputformat(COLRFMT, fp);
585 >        putc('\n', fp);
586 >        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
587  
588 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
589 <        if (scanline == NULL)
590 <                error(SYSTEM, "out of memory in writepict");
591 <        for (y = ourview.vresolu-1; y >= 0; y--) {
592 <                getpictcolrs(y, scanline, &ptrunk,
593 <                                ourview.hresolu, ourview.vresolu);
594 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
588 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
589 >        if (scanline == NULL) {
590 >                error(COMMAND, "not enough memory!");
591 >                fclose(fp);
592 >                unlink(fname);
593 >                return;
594 >        }
595 >        for (y = vresolu-1; y >= 0; y--) {
596 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
597 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
598                          break;
599          }
600 +        free((char *)scanline);
601          if (fclose(fp) < 0)
602                  error(COMMAND, "write error");
695        free((char *)scanline);
603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines