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.17 by greg, Fri Jan 19 00:00:29 1990 UTC vs.
Revision 2.19 by greg, Thu Aug 26 11:24:04 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1993 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  "rpaint.h"
20  
21 + #include  "resolu.h"
22 +
23   #include  <ctype.h>
24  
25 < #define  CTRL(c)        ('c'-'@')
25 > #define  CTRL(c)        ((c)-'@')
26  
27 + #ifdef  SMLFLT
28 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
29 + #else
30 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
31 + #endif
32 +
33 + extern char  *atos();
34 +
35 + extern char  rifname[];                 /* rad input file name */
36 +
37 + extern char  VersionID[];
38   extern char  *progname;
39 + extern char  *octname;
40  
41  
42   getframe(s)                             /* get a new frame */
# Line 54 | Line 68 | char  *s;
68          int  change = 0;
69          VIEW  nv;
70  
71 +        while (isspace(*s))
72 +                s++;
73 +        if (*s == '-') {                        /* command line parameters */
74 +                copystruct(&nv, &ourview);
75 +                if (sscanview(&nv, s))
76 +                        newview(&nv);
77 +                else
78 +                        error(COMMAND, "bad view option(s)");
79 +                return;
80 +        }
81          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
82                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
83                                  (fp = fopen(fname, "a")) == NULL) {
# Line 63 | Line 87 | char  *s;
87                  }
88                  fputs(progname, fp);
89                  fprintview(&ourview, fp);
90 <                fputs("\n", fp);
90 >                fputs(sskip(s), fp);
91 >                putc('\n', fp);
92                  fclose(fp);
93                  return;
94          }
95          sprintf(buf, "view type (%c): ", ourview.type);
96          (*dev->comout)(buf);
97 <        (*dev->comin)(buf);
98 <        if (buf[0] == CTRL(C)) return;
97 >        (*dev->comin)(buf, NULL);
98 >        if (buf[0] == CTRL('C')) return;
99          if (buf[0] && buf[0] != ourview.type) {
100                  nv.type = buf[0];
101                  change++;
# Line 79 | Line 104 | char  *s;
104          sprintf(buf, "view point (%.6g %.6g %.6g): ",
105                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
106          (*dev->comout)(buf);
107 <        (*dev->comin)(buf);
108 <        if (buf[0] == CTRL(C)) return;
109 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
107 >        (*dev->comin)(buf, NULL);
108 >        if (buf[0] == CTRL('C')) return;
109 >        if (sscanvec(buf, nv.vp))
110                  change++;
111          else
112                  VCOPY(nv.vp, ourview.vp);
113          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
114                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
115          (*dev->comout)(buf);
116 <        (*dev->comin)(buf);
117 <        if (buf[0] == CTRL(C)) return;
118 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
116 >        (*dev->comin)(buf, NULL);
117 >        if (buf[0] == CTRL('C')) return;
118 >        if (sscanvec(buf, nv.vdir))
119                  change++;
120          else
121                  VCOPY(nv.vdir, ourview.vdir);
122          sprintf(buf, "view up (%.6g %.6g %.6g): ",
123                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
124          (*dev->comout)(buf);
125 <        (*dev->comin)(buf);
126 <        if (buf[0] == CTRL(C)) return;
127 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
125 >        (*dev->comin)(buf, NULL);
126 >        if (buf[0] == CTRL('C')) return;
127 >        if (sscanvec(buf, nv.vup))
128                  change++;
129          else
130                  VCOPY(nv.vup, ourview.vup);
131          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
132                          ourview.horiz, ourview.vert);
133          (*dev->comout)(buf);
134 <        (*dev->comin)(buf);
135 <        if (buf[0] == CTRL(C)) return;
134 >        (*dev->comin)(buf, NULL);
135 >        if (buf[0] == CTRL('C')) return;
136          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
137                  change++;
138          else {
# Line 116 | Line 141 | char  *s;
141          sprintf(buf, "view shift and lift (%.6g %.6g): ",
142                          ourview.hoff, ourview.voff);
143          (*dev->comout)(buf);
144 <        (*dev->comin)(buf);
145 <        if (buf[0] == CTRL(C)) return;
144 >        (*dev->comin)(buf, NULL);
145 >        if (buf[0] == CTRL('C')) return;
146          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
147                  change++;
148          else {
# Line 138 | Line 163 | char  *s;
163  
164          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
165                  copystruct(&nv, &stdview);
166 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
167 <                                (success = viewfile(fname, &nv, 0, 0)) == -1) {
166 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
167 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
168                          sprintf(errmsg, "cannot open \"%s\"", buf);
169                          error(COMMAND, errmsg);
170                          return;
# Line 150 | Line 175 | char  *s;
175                          newview(&nv);
176                  return;
177          }
178 <        if (oldview.horiz == 0) {       /* no old view! */
178 >        if (oldview.type == 0) {        /* no old view! */
179                  error(COMMAND, "no previous view");
180                  return;
181          }
# Line 161 | Line 186 | char  *s;
186   }
187  
188  
189 + saveview(s)                             /* save view to rad file */
190 + char  *s;
191 + {
192 +        char  view[64];
193 +        char  *fname;
194 +        FILE  *fp;
195 +
196 +        if (*atos(view, sizeof(view), s)) {
197 +                if (isint(view)) {
198 +                        error(COMMAND, "cannot write view by number");
199 +                        return;
200 +                }
201 +                s = sskip(s);
202 +        }
203 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
204 +                error(COMMAND, "no previous rad file");
205 +                return;
206 +        }
207 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
208 +                        (fp = fopen(fname, "a")) == NULL) {
209 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
210 +                error(COMMAND, errmsg);
211 +                return;
212 +        }
213 +        fputs("view= ", fp);
214 +        fputs(view, fp);
215 +        fprintview(&ourview, fp);
216 +        putc('\n', fp);
217 +        fclose(fp);
218 + }
219 +
220 +
221 + loadview(s)                             /* load view from rad file */
222 + char  *s;
223 + {
224 +        char  buf[512];
225 +        char  *fname;
226 +        FILE  *fp;
227 +        VIEW  nv;
228 +
229 +        strcpy(buf, "rad -n -s -V -v ");
230 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
231 +                s = sskip(s);
232 +        else
233 +                strcat(buf, "1");
234 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
235 +                error(COMMAND, "no previous rad file");
236 +                return;
237 +        }
238 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
239 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
240 +                error(COMMAND, errmsg);
241 +                return;
242 +        }
243 +        sprintf(buf+strlen(buf), " %s", fname);
244 +        if ((fp = popen(buf, "r")) == NULL) {
245 +                error(COMMAND, "cannot run rad");
246 +                return;
247 +        }
248 +        buf[0] = '\0';
249 +        fgets(buf, sizeof(buf), fp);
250 +        pclose(fp);
251 +        copystruct(&nv, &stdview);
252 +        if (!sscanview(&nv, buf)) {
253 +                error(COMMAND, "rad error -- no such view?");
254 +                return;
255 +        }
256 +        newview(&nv);
257 + }
258 +
259 +
260   getaim(s)                               /* aim camera */
261   char  *s;
262   {
167        extern double  tan(), atan();
263          double  zfact;
264          VIEW  nv;
265  
266          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
267                  return;
268 +        nv.type = ourview.type;
269          VCOPY(nv.vp, ourview.vp);
270          VCOPY(nv.vup, ourview.vup);
271          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
272 <        if ((nv.type = ourview.type) == VT_PAR) {
273 <                nv.horiz = ourview.horiz / zfact;
178 <                nv.vert = ourview.vert / zfact;
179 <        } else {
180 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
181 <                                (PI/180./2.);
182 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
183 <                                (PI/180./2.);
184 <        }
272 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
273 >        zoomview(&nv, zfact);
274          newview(&nv);
275   }
276  
# Line 201 | Line 290 | char  *s;
290   getrotate(s)                            /* rotate camera */
291   char  *s;
292   {
204        extern double  normalize(), tan(), atan();
293          VIEW  nv;
294          FVECT  v1;
295          double  angle, elev, zfact;
# Line 211 | Line 299 | char  *s;
299                  error(COMMAND, "missing angle");
300                  return;
301          }
302 +        nv.type = ourview.type;
303          VCOPY(nv.vp, ourview.vp);
304          VCOPY(nv.vup, ourview.vup);
305          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
# Line 220 | Line 309 | char  *s;
309                  normalize(v1);
310                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
311          }
312 <        if ((nv.type = ourview.type) == VT_PAR) {
313 <                nv.horiz = ourview.horiz / zfact;
225 <                nv.vert = ourview.vert / zfact;
226 <        } else {
227 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
228 <                                (PI/180./2.);
229 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
230 <                                (PI/180./2.);
231 <        }
312 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
313 >        zoomview(&nv, zfact);
314          newview(&nv);
315   }
316  
# Line 253 | Line 335 | register char  *s;
335   getexposure(s)                          /* get new exposure */
336   char  *s;
337   {
256        double  atof(), pow(), fabs();
338          char  buf[128];
339          register char  *cp;
259        register PNODE  *p;
340          RECT  r;
341          int  x, y;
342 <        double  e;
343 <
342 >        register PNODE  *p = &ptrunk;
343 >        int  adapt = 0;
344 >        double  e = 1.0;
345 > start:
346          for (cp = s; isspace(*cp); cp++)
347                  ;
348 +        if (*cp == '@') {
349 +                adapt++;
350 +                goto start;
351 +        }
352          if (*cp == '\0') {              /* normalize to point */
353                  if (dev->getcur == NULL)
354                          return;
# Line 272 | Line 358 | char  *s;
358                  r.l = r.d = 0;
359                  r.r = hresolu; r.u = vresolu;
360                  p = findrect(x, y, &ptrunk, &r, -1);
275                e = 1.0;
361          } else {
362                  if (*cp == '=') {       /* absolute setting */
363                          p = NULL;
# Line 280 | Line 365 | char  *s;
365                          for (cp++; isspace(*cp); cp++)
366                                  ;
367                          if (*cp == '\0') {      /* interactive */
368 <                                sprintf(buf, "exposure (%lf): ", exposure);
368 >                                sprintf(buf, "exposure (%f): ", exposure);
369                                  (*dev->comout)(buf);
370 <                                (*dev->comin)(buf);
370 >                                (*dev->comin)(buf, NULL);
371                                  for (cp = buf; isspace(*cp); cp++)
372                                          ;
373                                  if (*cp == '\0')
374                                          return;
375                          }
291                } else {                /* normalize to average */
292                        p = &ptrunk;
293                        e = 1.0;
376                  }
377                  if (*cp == '+' || *cp == '-')   /* f-stops */
378                          e *= pow(2.0, atof(cp));
# Line 298 | Line 380 | char  *s;
380                          e *= atof(cp);
381          }
382          if (p != NULL) {                /* relative setting */
383 <                if (bright(p->v) <= FTINY) {
383 >                if (bright(p->v) < 1e-15) {
384                          error(COMMAND, "cannot normalize to zero");
385                          return;
386                  }
387 <                e *= 0.5 / bright(p->v);
387 >                if (adapt)
388 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
389 >                else
390 >                        e *= 0.5 / bright(p->v);
391          }
392          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
393                  return;
# Line 312 | Line 397 | char  *s;
397   }
398  
399  
400 + getparam(str, dsc, typ, ptr)            /* get variable from user */
401 + char  *str, *dsc;
402 + int  typ;
403 + register union {int i; double d; COLOR C;}  *ptr;
404 + {
405 +        extern char  *index();
406 +        int  i0;
407 +        double  d0, d1, d2;
408 +        char  buf[48];
409 +
410 +        switch (typ) {
411 +        case 'i':                       /* integer */
412 +                if (sscanf(str, "%d", &i0) != 1) {
413 +                        (*dev->comout)(dsc);
414 +                        sprintf(buf, " (%d): ", ptr->i);
415 +                        (*dev->comout)(buf);
416 +                        (*dev->comin)(buf, NULL);
417 +                        if (sscanf(buf, "%d", &i0) != 1)
418 +                                return(0);
419 +                }
420 +                ptr->i = i0;
421 +                return(1);
422 +        case 'r':                       /* real */
423 +                if (sscanf(str, "%lf", &d0) != 1) {
424 +                        (*dev->comout)(dsc);
425 +                        sprintf(buf, " (%.6g): ", ptr->d);
426 +                        (*dev->comout)(buf);
427 +                        (*dev->comin)(buf, NULL);
428 +                        if (sscanf(buf, "%lf", &d0) != 1)
429 +                                return(0);
430 +                }
431 +                ptr->d = d0;
432 +                return(1);
433 +        case 'b':                       /* boolean */
434 +                if (sscanf(str, "%1s", buf) != 1) {
435 +                        (*dev->comout)(dsc);
436 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
437 +                        (*dev->comout)(buf);
438 +                        (*dev->comin)(buf, NULL);
439 +                        if (buf[0] == '\0' ||
440 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
441 +                                return(0);
442 +                }
443 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
444 +                return(1);
445 +        case 'C':                       /* color */
446 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
447 +                        (*dev->comout)(dsc);
448 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
449 +                                        colval(ptr->C,RED),
450 +                                        colval(ptr->C,GRN),
451 +                                        colval(ptr->C,BLU));
452 +                        (*dev->comout)(buf);
453 +                        (*dev->comin)(buf, NULL);
454 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
455 +                                return(0);
456 +                }
457 +                setcolor(ptr->C, d0, d1, d2);
458 +                return(1);
459 +        }
460 + }
461 +
462 +
463   setparam(s)                             /* get/set program parameter */
464   register char  *s;
465   {
# Line 324 | Line 472 | register char  *s;
472          extern double  shadcert;
473          extern COLOR  ambval;
474          extern double  ambacc;
327        extern double  minarad;
475          extern int  ambres;
476          extern int  ambdiv;
477          extern int  ambssamp;
478          extern int  ambounce;
479 <        int  i0;
480 <        double  d0, d1, d2;
479 >        extern int  directvis;
480 >        extern double  srcsizerat;
481 >        extern int  do_irrad;
482 >        extern double  specjitter;
483 >        extern double  specthresh;
484          char  buf[128];
485          
486          if (s[0] == '\0') {
487 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
488 <                (*dev->comin)(buf);
487 >                (*dev->comout)(
488 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
489 >                (*dev->comin)(buf, NULL);
490                  s = buf;
491          }
492          switch (s[0]) {
493          case 'l':                       /* limit */
494                  switch (s[1]) {
495                  case 'w':                       /* weight */
496 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
346 <                                sprintf(buf, "limit weight (%.6g): ",
347 <                                                minweight);
348 <                                (*dev->comout)(buf);
349 <                                (*dev->comin)(buf);
350 <                                if (sscanf(buf, "%lf", &d0) != 1)
351 <                                        break;
352 <                        }
353 <                        minweight = d0;
496 >                        getparam(s+2, "limit weight", 'r', &minweight);
497                          break;
498                  case 'r':                       /* reflection */
499 <                        if (sscanf(s+2, "%d", &i0) != 1) {
357 <                                sprintf(buf, "limit reflection (%d): ",
358 <                                                maxdepth);
359 <                                (*dev->comout)(buf);
360 <                                (*dev->comin)(buf);
361 <                                if (sscanf(buf, "%d", &i0) != 1)
362 <                                        break;
363 <                        }
364 <                        maxdepth = i0;
499 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
500                          break;
501                  default:
502                          goto badparam;
# Line 370 | Line 505 | register char  *s;
505          case 'd':                       /* direct */
506                  switch (s[1]) {
507                  case 'j':                       /* jitter */
508 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
374 <                                sprintf(buf, "direct jitter (%.6g): ",
375 <                                                dstrsrc);
376 <                                (*dev->comout)(buf);
377 <                                (*dev->comin)(buf);
378 <                                if (sscanf(buf, "%lf", &d0) != 1)
379 <                                        break;
380 <                        }
381 <                        dstrsrc = d0;
508 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
509                          break;
510                  case 'c':                       /* certainty */
511 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
385 <                                sprintf(buf, "direct certainty (%.6g): ",
386 <                                                shadcert);
387 <                                (*dev->comout)(buf);
388 <                                (*dev->comin)(buf);
389 <                                if (sscanf(buf, "%lf", &d0) != 1)
390 <                                        break;
391 <                        }
392 <                        shadcert = d0;
511 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
512                          break;
513                  case 't':                       /* threshold */
514 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
396 <                                sprintf(buf, "direct threshold (%.6g): ",
397 <                                                shadthresh);
398 <                                (*dev->comout)(buf);
399 <                                (*dev->comin)(buf);
400 <                                if (sscanf(buf, "%lf", &d0) != 1)
401 <                                        break;
402 <                        }
403 <                        shadthresh = d0;
514 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
515                          break;
516 +                case 'v':                       /* visibility */
517 +                        getparam(s+2, "direct visibility",
518 +                                        'b', &directvis);
519 +                        break;
520 +                case 's':                       /* sampling */
521 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
522 +                        break;
523                  default:
524                          goto badparam;
525                  }
526                  break;
527 +        case 'b':                       /* black and white */
528 +                getparam(s+1, "black and white", 'b', &greyscale);
529 +                break;
530 +        case 'i':                       /* irradiance */
531 +                getparam(s+1, "irradiance", 'b', &do_irrad);
532 +                break;
533          case 'a':                       /* ambient */
534                  switch (s[1]) {
535                  case 'v':                       /* value */
536 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
413 <                                sprintf(buf,
414 <                                        "ambient value (%.6g %.6g %.6g): ",
415 <                                                colval(ambval,RED),
416 <                                                colval(ambval,GRN),
417 <                                                colval(ambval,BLU));
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf %lf %lf",
421 <                                                &d0, &d1, &d2) != 3)
422 <                                        break;
423 <                        }
424 <                        setcolor(ambval, d0, d1, d2);
536 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
537                          break;
538                  case 'a':                       /* accuracy */
539 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
540 <                                sprintf(buf, "ambient accuracy (%.6g): ",
429 <                                                ambacc);
430 <                                (*dev->comout)(buf);
431 <                                (*dev->comin)(buf);
432 <                                if (sscanf(buf, "%lf", &d0) != 1)
433 <                                        break;
434 <                        }
435 <                        ambacc = d0;
539 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
540 >                                setambacc(ambacc);
541                          break;
542                  case 'd':                       /* divisions */
543 <                        if (sscanf(s+2, "%d", &i0) != 1) {
439 <                                sprintf(buf, "ambient divisions (%d): ",
440 <                                                ambdiv);
441 <                                (*dev->comout)(buf);
442 <                                (*dev->comin)(buf);
443 <                                if (sscanf(buf, "%d", &i0) != 1)
444 <                                        break;
445 <                        }
446 <                        ambdiv = i0;
543 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
544                          break;
545                  case 's':                       /* samples */
546 <                        if (sscanf(s+2, "%d", &i0) != 1) {
450 <                                sprintf(buf, "ambient super-samples (%d): ",
451 <                                                ambssamp);
452 <                                (*dev->comout)(buf);
453 <                                (*dev->comin)(buf);
454 <                                if (sscanf(buf, "%d", &i0) != 1)
455 <                                        break;
456 <                        }
457 <                        ambssamp = i0;
546 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
547                          break;
548                  case 'b':                       /* bounces */
549 <                        if (sscanf(s+2, "%d", &i0) != 1) {
461 <                                sprintf(buf, "ambient bounces (%d): ",
462 <                                                ambounce);
463 <                                (*dev->comout)(buf);
464 <                                (*dev->comin)(buf);
465 <                                if (sscanf(buf, "%d", &i0) != 1)
466 <                                        break;
467 <                        }
468 <                        ambounce = i0;
549 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
550                          break;
551                  case 'r':
552 <                        if (sscanf(s+2, "%d", &i0) != 1) {
553 <                                sprintf(buf, "ambient resolution (%d): ",
473 <                                                ambres);
474 <                                (*dev->comout)(buf);
475 <                                (*dev->comin)(buf);
476 <                                if (sscanf(buf, "%d", &i0) != 1)
477 <                                        break;
478 <                        }
479 <                        ambres = i0;
480 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
552 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
553 >                                setambres(ambres);
554                          break;
555                  default:
556                          goto badparam;
557                  }
558                  break;
559 <        case 's':                       /* sample */
559 >        case 'p':                       /* pixel */
560                  switch (s[1]) {
561 <                case 'p':                       /* pixel */
562 <                        if (sscanf(s+2, "%d", &i0) != 1) {
563 <                                sprintf(buf, "sample pixel (%d): ", psample);
491 <                                (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
493 <                                if (sscanf(buf, "%d", &i0) != 1)
494 <                                        break;
495 <                        }
496 <                        psample = i0;
497 <                        pdepth = 0;
561 >                case 's':                       /* sample */
562 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
563 >                                pdepth = 0;
564                          break;
565                  case 't':                       /* threshold */
566 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
567 <                                sprintf(buf, "sample threshold (%.6g): ",
502 <                                                maxdiff);
503 <                                (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
505 <                                if (sscanf(buf, "%lf", &d0) != 1)
506 <                                        break;
507 <                        }
508 <                        maxdiff = d0;
509 <                        pdepth = 0;
566 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
567 >                                pdepth = 0;
568                          break;
569                  default:
570                          goto badparam;
571                  }
572                  break;
573 +        case 's':                       /* specular */
574 +                switch (s[1]) {
575 +                case 'j':                       /* jitter */
576 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
577 +                        break;
578 +                case 't':                       /* threshold */
579 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
580 +                        break;
581 +                default:
582 +                        goto badparam;
583 +                }
584 +                break;
585          case '\0':                      /* nothing */
586                  break;
587          default:;
588   badparam:
589 +                *sskip(s) = '\0';
590                  sprintf(errmsg, "%s: unknown variable", s);
591                  error(COMMAND, errmsg);
592                  break;
# Line 530 | Line 601 | char  *s;
601          int  x, y;
602          RAY  thisray;
603  
604 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
605 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
535 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
604 >        if (!sscanvec(s, thisray.rorg) ||
605 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
606  
607                  if (dev->getcur == NULL)
608                          return;
# Line 540 | Line 610 | char  *s;
610                  if ((*dev->getcur)(&x, &y) == ABORT)
611                          return;
612  
613 <                viewray(thisray.rorg, thisray.rdir, &ourview,
614 <                                (x+.5)/hresolu, (y+.5)/vresolu);
615 <                
613 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
614 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
615 >                        error(COMMAND, "not on image");
616 >                        return;
617 >                }
618 >
619          } else if (normalize(thisray.rdir) == 0.0) {
620                  error(COMMAND, "zero ray direction");
621                  return;
# Line 560 | Line 633 | char  *s;
633                                  ofun[thisray.ro->otype].funame,
634                                  thisray.ro->oname);
635                  (*dev->comout)(buf);
636 <                (*dev->comin)(buf);
636 >                (*dev->comin)(buf, NULL);
637                  if (thisray.rot >= FHUGE)
638                          (*dev->comout)("at infinity");
639                  else {
# Line 568 | Line 641 | char  *s;
641                                          thisray.rop[1], thisray.rop[2]);
642                          (*dev->comout)(buf);
643                  }
644 <                (*dev->comin)(buf);
645 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
644 >                (*dev->comin)(buf, NULL);
645 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
646                                  colval(thisray.rcol,RED),
647                                  colval(thisray.rcol,GRN),
648 <                                colval(thisray.rcol,BLU));
648 >                                colval(thisray.rcol,BLU),
649 >                                luminance(thisray.rcol));
650                  (*dev->comout)(buf);
651          }
652 <        (*dev->comin)(buf);
652 >        (*dev->comin)(buf, NULL);
653   }
654  
655  
# Line 598 | Line 672 | char  *s;
672                  error(COMMAND, errmsg);
673                  return;
674          }
675 + #ifdef MSDOS
676 +        setmode(fileno(fp), O_BINARY);
677 + #endif
678          (*dev->comout)("writing \"");
679          (*dev->comout)(fname);
680          (*dev->comout)("\"...\n");
681                                                  /* write header */
682          fputs(progname, fp);
683          fprintview(&ourview, fp);
684 <        putc('\n', fp);
684 >        if (octname != NULL)
685 >                fprintf(fp, " %s\n", octname);
686 >        else
687 >                putc('\n', fp);
688 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
689          if (exposure != 1.0)
690                  fputexpos(exposure, fp);
691          if (dev->pixaspect != 1.0)
692                  fputaspect(dev->pixaspect, fp);
693 +        fputformat(COLRFMT, fp);
694          putc('\n', fp);
695 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
695 >        fprtresolu(hresolu, vresolu, fp);
696  
697          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
698 <        if (scanline == NULL)
699 <                error(SYSTEM, "out of memory in writepict");
698 >        if (scanline == NULL) {
699 >                error(COMMAND, "not enough memory!");
700 >                fclose(fp);
701 >                unlink(fname);
702 >                return;
703 >        }
704          for (y = vresolu-1; y >= 0; y--) {
705                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
706                  if (fwritecolrs(scanline, hresolu, fp) < 0)
707                          break;
708          }
709 +        free((char *)scanline);
710          if (fclose(fp) < 0)
711                  error(COMMAND, "write error");
625        free((char *)scanline);
712   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines