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.5 by greg, Wed Jun 7 08:35: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;
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   {
53          FILE  *fp;
54          char  buf[128];
55 <        char  *fname, *getpath();
55 >        char  *fname;
56          int  change = 0;
57          VIEW  nv;
58  
59          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
60 <                if ((fname = getpath(buf, NULL)) == NULL ||
60 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
61                                  (fp = fopen(fname, "a")) == NULL) {
62                          sprintf(errmsg, "cannot open \"%s\"", buf);
63                          error(COMMAND, errmsg);
# Line 87 | 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 103 | 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 112 | 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 121 | 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 130 | 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 156 | Line 135 | lastview(s)                            /* return to a previous view */
135   char  *s;
136   {
137          char  buf[128];
138 <        char  *fname, *getpath();
138 >        char  *fname;
139          int  success;
140          VIEW  nv;
141  
142          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
143 <                bcopy(&stdview, &nv, sizeof(VIEW));
144 <                if ((fname = getpath(buf, NULL)) == NULL ||
145 <                                (success = viewfile(fname, &nv)) == -1) {
143 >                copystruct(&nv, &stdview);
144 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
145 >                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
146                          sprintf(errmsg, "cannot open \"%s\"", buf);
147                          error(COMMAND, errmsg);
148                          return;
# Line 174 | 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  
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
167   getaim(s)                               /* aim camera */
168   char  *s;
169   {
# Line 241 | 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;
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 <        }
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 282 | 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;
296 <                nv.vert = ourview.vert / zfact;
297 <        } else {
298 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
299 <                                (PI/180./2.);
300 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
301 <                                (PI/180./2.);
302 <        }
221 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
222 >        zoomview(&nv, zfact);
223          newview(&nv);
224   }
225  
# Line 341 | 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 353 | 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 369 | Line 289 | char  *s;
289                          e *= atof(cp);
290          }
291          if (p != NULL) {                /* relative setting */
292 <                if (intens(p->v) <= FTINY) {
292 >                if (bright(p->v) <= FTINY) {
293                          error(COMMAND, "cannot normalize to zero");
294                          return;
295                  }
296 <                e *= 0.5 / intens(p->v);
296 >                e *= 0.5 / bright(p->v);
297          }
298          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
299                  return;
# Line 383 | 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 392 | Line 375 | register char  *s;
375          extern int  maxdepth;
376          extern double  dstrsrc;
377          extern double  shadthresh;
378 +        extern double  shadcert;
379          extern COLOR  ambval;
380          extern double  ambacc;
381          extern double  minarad;
# Line 399 | 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 dj dt lr lw sd sp: ");
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) {
416 <                                sprintf(buf, "limit weight (%.6g): ",
417 <                                                minweight);
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf", &d0) != 1)
421 <                                        break;
422 <                        }
423 <                        minweight = d0;
401 >                        getparam(s+2, "limit weight", 'r', &minweight);
402                          break;
403                  case 'r':                       /* reflection */
404 <                        if (sscanf(s+2, "%d", &i0) != 1) {
427 <                                sprintf(buf, "limit reflection (%d): ",
428 <                                                maxdepth);
429 <                                (*dev->comout)(buf);
430 <                                (*dev->comin)(buf);
431 <                                if (sscanf(buf, "%d", &i0) != 1)
432 <                                        break;
433 <                        }
434 <                        maxdepth = i0;
404 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
405                          break;
406                  default:
407                          goto badparam;
# Line 440 | 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) {
444 <                                sprintf(buf, "direct jitter (%.6g): ",
445 <                                                dstrsrc);
446 <                                (*dev->comout)(buf);
447 <                                (*dev->comin)(buf);
448 <                                if (sscanf(buf, "%lf", &d0) != 1)
449 <                                        break;
450 <                        }
451 <                        dstrsrc = d0;
413 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
414                          break;
415 +                case 'c':                       /* certainty */
416 +                        getparam(s+2, "direct certainty", 'r', &shadcert);
417 +                        break;
418                  case 't':                       /* threshold */
419 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
455 <                                sprintf(buf, "direct threshold (%.6g): ",
456 <                                                shadthresh);
457 <                                (*dev->comout)(buf);
458 <                                (*dev->comin)(buf);
459 <                                if (sscanf(buf, "%lf", &d0) != 1)
460 <                                        break;
461 <                        }
462 <                        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) {
472 <                                sprintf(buf,
473 <                                        "ambient value (%.6g %.6g %.6g): ",
474 <                                                colval(ambval,RED),
475 <                                                colval(ambval,GRN),
476 <                                                colval(ambval,BLU));
477 <                                (*dev->comout)(buf);
478 <                                (*dev->comin)(buf);
479 <                                if (sscanf(buf, "%lf %lf %lf",
480 <                                                &d0, &d1, &d2) != 3)
481 <                                        break;
482 <                        }
483 <                        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) {
487 <                                sprintf(buf, "ambient accuracy (%.6g): ",
488 <                                                ambacc);
489 <                                (*dev->comout)(buf);
490 <                                (*dev->comin)(buf);
491 <                                if (sscanf(buf, "%lf", &d0) != 1)
492 <                                        break;
493 <                        }
494 <                        ambacc = d0;
444 >                        getparam(s+2, "ambient accuracy", 'r', &ambacc);
445                          break;
446                  case 'd':                       /* divisions */
447 <                        if (sscanf(s+2, "%d", &i0) != 1) {
498 <                                sprintf(buf, "ambient divisions (%d): ",
499 <                                                ambdiv);
500 <                                (*dev->comout)(buf);
501 <                                (*dev->comin)(buf);
502 <                                if (sscanf(buf, "%d", &i0) != 1)
503 <                                        break;
504 <                        }
505 <                        ambdiv = i0;
447 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
448                          break;
449                  case 's':                       /* samples */
450 <                        if (sscanf(s+2, "%d", &i0) != 1) {
509 <                                sprintf(buf, "ambient super-samples (%d): ",
510 <                                                ambssamp);
511 <                                (*dev->comout)(buf);
512 <                                (*dev->comin)(buf);
513 <                                if (sscanf(buf, "%d", &i0) != 1)
514 <                                        break;
515 <                        }
516 <                        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) {
520 <                                sprintf(buf, "ambient bounces (%d): ",
521 <                                                ambounce);
522 <                                (*dev->comout)(buf);
523 <                                (*dev->comin)(buf);
524 <                                if (sscanf(buf, "%d", &i0) != 1)
525 <                                        break;
526 <                        }
527 <                        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);
533 <                                (*dev->comout)(buf);
534 <                                (*dev->comin)(buf);
535 <                                if (sscanf(buf, "%d", &i0) != 1)
536 <                                        break;
537 <                        }
538 <                        ambres = i0;
539 <                        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 545 | 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);
550 <                                (*dev->comout)(buf);
551 <                                (*dev->comin)(buf);
552 <                                if (sscanf(buf, "%d", &i0) != 1)
553 <                                        break;
554 <                        }
555 <                        psample = i0;
556 <                        pdepth = 0;
467 >                        if (getparam(s+2, "sample pixel", 'i', &psample))
468 >                                pdepth = 0;
469                          break;
470 <                case 'd':                       /* difference */
471 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
472 <                                sprintf(buf, "sample difference (%.6g): ",
561 <                                                maxdiff);
562 <                                (*dev->comout)(buf);
563 <                                (*dev->comin)(buf);
564 <                                if (sscanf(buf, "%lf", &d0) != 1)
565 <                                        break;
566 <                        }
567 <                        maxdiff = d0;
568 <                        pdepth = 0;
470 >                case 't':                       /* threshold */
471 >                        if (getparam(s+2, "sample threshold", 'r', &maxdiff))
472 >                                pdepth = 0;
473                          break;
474                  default:
475                          goto badparam;
# Line 575 | 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 599 | 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 618 | 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 626 | 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 641 | Line 551 | writepict(s)                           /* write the picture to a file */
551   char  *s;
552   {
553          static char  buf[128];
554 <        char  *fname, *getpath();
554 >        char  *fname;
555          FILE  *fp;
556          COLR  *scanline;
557          int  y;
# Line 650 | Line 560 | char  *s;
560                  error(COMMAND, "no file");
561                  return;
562          }
563 <        if ((fname = getpath(buf, NULL)) == NULL ||
563 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
564                          (fp = fopen(fname, "w")) == NULL) {
565                  sprintf(errmsg, "cannot open \"%s\"", buf);
566                  error(COMMAND, errmsg);
# Line 662 | 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");
681        free((char *)scanline);
603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines