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.12 by greg, Fri Oct 27 11:48:19 1989 UTC vs.
Revision 2.18 by greg, Wed Aug 25 14:13:51 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 41 | Line 55 | char  *s;
55  
56          if (getrect(s, &box) < 0)
57                  return;
58 <        paintrect(&ptrunk, 0, 0, ourview.hresolu, ourview.vresolu, &box);
58 >        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
59   }
60  
61  
# 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 {
139                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
140          }
141 <        sprintf(buf, "x and y resolution (%d %d): ",
142 <                        ourview.hresolu, ourview.vresolu);
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;
146 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
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 {
149 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
149 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
150          }
151          if (change)
152                  newview(&nv);
# Line 137 | Line 162 | char  *s;
162          VIEW  nv;
163  
164          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
165 <                bcopy(&stdview, &nv, sizeof(VIEW));
165 >                copystruct(&nv, &stdview);
166                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
167 <                                (success = viewfile(fname, &nv)) == -1) {
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.hresolu == 0) {     /* no old view! */
178 >        if (oldview.type == 0) {        /* no old view! */
179                  error(COMMAND, "no previous view");
180                  return;
181          }
182 <        bcopy(&ourview, &nv, sizeof(VIEW));
183 <        bcopy(&oldview, &ourview, sizeof(VIEW));
184 <        bcopy(&nv, &oldview, sizeof(VIEW));
182 >        copystruct(&nv, &ourview);
183 >        copystruct(&ourview, &oldview);
184 >        copystruct(&oldview, &nv);
185          newimage();
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 +                s = sskip(s);
198 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
199 +                error(COMMAND, "no previous rad file");
200 +                return;
201 +        }
202 +        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
203 +                        (fp = fopen(fname, "a")) == NULL) {
204 +                sprintf(errmsg, "cannot open \"%s\"", rifname);
205 +                error(COMMAND, errmsg);
206 +                return;
207 +        }
208 +        fputs("view= ", fp);
209 +        fputs(view, fp);
210 +        fprintview(&ourview, fp);
211 +        putc('\n', fp);
212 +        fclose(fp);
213 + }
214 +
215 +
216 + loadview(s)                             /* load view from rad file */
217 + char  *s;
218 + {
219 +        char  buf[512];
220 +        char  *fname;
221 +        FILE  *fp;
222 +        VIEW  nv;
223 +
224 +        strcpy(buf, "rad -n -s -V -v ");
225 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
226 +                s = sskip(s);
227 +        else
228 +                strcat(buf, "1");
229 +        if (sscanf(s, "%s", rifname) != 1 && rifname[0] == '\0') {
230 +                error(COMMAND, "no previous rad file");
231 +                return;
232 +        }
233 +        fname = getpath(rifname, NULL, 0);
234 +        if (fname == NULL || access(fname, R_OK) == -1) {
235 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
236 +                error(COMMAND, errmsg);
237 +                return;
238 +        }
239 +        sprintf(buf+strlen(buf), " %s", fname);
240 +        if ((fp = popen(buf, "r")) == NULL) {
241 +                error(COMMAND, "cannot run rad");
242 +                return;
243 +        }
244 +        buf[0] = '\0';
245 +        fgets(buf, sizeof(buf), fp);
246 +        pclose(fp);
247 +        copystruct(&nv, &stdview);
248 +        if (!sscanview(&nv, buf)) {
249 +                error(COMMAND, "rad error -- no such view?");
250 +                return;
251 +        }
252 +        newview(&nv);
253 + }
254 +
255 +
256   getaim(s)                               /* aim camera */
257   char  *s;
258   {
167        extern double  tan(), atan();
259          double  zfact;
260          VIEW  nv;
261  
262          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
263                  return;
264 +        nv.type = ourview.type;
265          VCOPY(nv.vp, ourview.vp);
266          VCOPY(nv.vup, ourview.vup);
267 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
268 <        if ((nv.type = ourview.type) == VT_PAR) {
269 <                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 <        }
267 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
268 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
269 >        zoomview(&nv, zfact);
270          newview(&nv);
271   }
272  
# Line 201 | Line 286 | char  *s;
286   getrotate(s)                            /* rotate camera */
287   char  *s;
288   {
204        extern double  normalize(), tan(), atan();
289          VIEW  nv;
290          FVECT  v1;
291          double  angle, elev, zfact;
# Line 211 | Line 295 | char  *s;
295                  error(COMMAND, "missing angle");
296                  return;
297          }
298 +        nv.type = ourview.type;
299          VCOPY(nv.vp, ourview.vp);
300          VCOPY(nv.vup, ourview.vup);
301 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
301 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
302          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
303          if (elev != 0.0) {
304                  fcross(v1, nv.vdir, ourview.vup);
305                  normalize(v1);
306                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
307          }
308 <        if ((nv.type = ourview.type) == VT_PAR) {
309 <                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 <        }
308 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
309 >        zoomview(&nv, zfact);
310          newview(&nv);
311   }
312  
# Line 253 | Line 331 | register char  *s;
331   getexposure(s)                          /* get new exposure */
332   char  *s;
333   {
256        double  atof(), pow(), fabs();
334          char  buf[128];
335          register char  *cp;
259        register PNODE  *p;
336          RECT  r;
337          int  x, y;
338 <        double  e;
339 <
338 >        register PNODE  *p = &ptrunk;
339 >        int  adapt = 0;
340 >        double  e = 1.0;
341 > start:
342          for (cp = s; isspace(*cp); cp++)
343                  ;
344 +        if (*cp == '@') {
345 +                adapt++;
346 +                goto start;
347 +        }
348          if (*cp == '\0') {              /* normalize to point */
349                  if (dev->getcur == NULL)
350                          return;
# Line 270 | Line 352 | char  *s;
352                  if ((*dev->getcur)(&x, &y) == ABORT)
353                          return;
354                  r.l = r.d = 0;
355 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
355 >                r.r = hresolu; r.u = vresolu;
356                  p = findrect(x, y, &ptrunk, &r, -1);
275                e = 1.0;
357          } else {
358                  if (*cp == '=') {       /* absolute setting */
359                          p = NULL;
# Line 280 | Line 361 | char  *s;
361                          for (cp++; isspace(*cp); cp++)
362                                  ;
363                          if (*cp == '\0') {      /* interactive */
364 <                                sprintf(buf, "exposure (%lf): ", exposure);
364 >                                sprintf(buf, "exposure (%f): ", exposure);
365                                  (*dev->comout)(buf);
366 <                                (*dev->comin)(buf);
366 >                                (*dev->comin)(buf, NULL);
367                                  for (cp = buf; isspace(*cp); cp++)
368                                          ;
369                                  if (*cp == '\0')
370                                          return;
371                          }
291                } else {                /* normalize to average */
292                        p = &ptrunk;
293                        e = 1.0;
372                  }
373                  if (*cp == '+' || *cp == '-')   /* f-stops */
374                          e *= pow(2.0, atof(cp));
# Line 298 | Line 376 | char  *s;
376                          e *= atof(cp);
377          }
378          if (p != NULL) {                /* relative setting */
379 <                if (bright(p->v) <= FTINY) {
379 >                if (bright(p->v) < 1e-15) {
380                          error(COMMAND, "cannot normalize to zero");
381                          return;
382                  }
383 <                e *= 0.5 / bright(p->v);
383 >                if (adapt)
384 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
385 >                else
386 >                        e *= 0.5 / bright(p->v);
387          }
388          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
389                  return;
# Line 312 | Line 393 | char  *s;
393   }
394  
395  
396 + getparam(str, dsc, typ, ptr)            /* get variable from user */
397 + char  *str, *dsc;
398 + int  typ;
399 + register union {int i; double d; COLOR C;}  *ptr;
400 + {
401 +        extern char  *index();
402 +        int  i0;
403 +        double  d0, d1, d2;
404 +        char  buf[48];
405 +
406 +        switch (typ) {
407 +        case 'i':                       /* integer */
408 +                if (sscanf(str, "%d", &i0) != 1) {
409 +                        (*dev->comout)(dsc);
410 +                        sprintf(buf, " (%d): ", ptr->i);
411 +                        (*dev->comout)(buf);
412 +                        (*dev->comin)(buf, NULL);
413 +                        if (sscanf(buf, "%d", &i0) != 1)
414 +                                return(0);
415 +                }
416 +                ptr->i = i0;
417 +                return(1);
418 +        case 'r':                       /* real */
419 +                if (sscanf(str, "%lf", &d0) != 1) {
420 +                        (*dev->comout)(dsc);
421 +                        sprintf(buf, " (%.6g): ", ptr->d);
422 +                        (*dev->comout)(buf);
423 +                        (*dev->comin)(buf, NULL);
424 +                        if (sscanf(buf, "%lf", &d0) != 1)
425 +                                return(0);
426 +                }
427 +                ptr->d = d0;
428 +                return(1);
429 +        case 'b':                       /* boolean */
430 +                if (sscanf(str, "%1s", buf) != 1) {
431 +                        (*dev->comout)(dsc);
432 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
433 +                        (*dev->comout)(buf);
434 +                        (*dev->comin)(buf, NULL);
435 +                        if (buf[0] == '\0' ||
436 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
437 +                                return(0);
438 +                }
439 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
440 +                return(1);
441 +        case 'C':                       /* color */
442 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
443 +                        (*dev->comout)(dsc);
444 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
445 +                                        colval(ptr->C,RED),
446 +                                        colval(ptr->C,GRN),
447 +                                        colval(ptr->C,BLU));
448 +                        (*dev->comout)(buf);
449 +                        (*dev->comin)(buf, NULL);
450 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
451 +                                return(0);
452 +                }
453 +                setcolor(ptr->C, d0, d1, d2);
454 +                return(1);
455 +        }
456 + }
457 +
458 +
459   setparam(s)                             /* get/set program parameter */
460   register char  *s;
461   {
# Line 324 | Line 468 | register char  *s;
468          extern double  shadcert;
469          extern COLOR  ambval;
470          extern double  ambacc;
327        extern double  minarad;
471          extern int  ambres;
472          extern int  ambdiv;
473          extern int  ambssamp;
474          extern int  ambounce;
475 <        int  i0;
476 <        double  d0, d1, d2;
475 >        extern int  directvis;
476 >        extern double  srcsizerat;
477 >        extern int  do_irrad;
478 >        extern double  specjitter;
479 >        extern double  specthresh;
480          char  buf[128];
481          
482          if (s[0] == '\0') {
483 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
484 <                (*dev->comin)(buf);
483 >                (*dev->comout)(
484 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
485 >                (*dev->comin)(buf, NULL);
486                  s = buf;
487          }
488          switch (s[0]) {
489          case 'l':                       /* limit */
490                  switch (s[1]) {
491                  case 'w':                       /* weight */
492 <                        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;
492 >                        getparam(s+2, "limit weight", 'r', &minweight);
493                          break;
494                  case 'r':                       /* reflection */
495 <                        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;
495 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
496                          break;
497                  default:
498                          goto badparam;
# Line 370 | Line 501 | register char  *s;
501          case 'd':                       /* direct */
502                  switch (s[1]) {
503                  case 'j':                       /* jitter */
504 <                        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;
504 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
505                          break;
506                  case 'c':                       /* certainty */
507 <                        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;
507 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
508                          break;
509                  case 't':                       /* threshold */
510 <                        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;
510 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
511                          break;
512 +                case 'v':                       /* visibility */
513 +                        getparam(s+2, "direct visibility",
514 +                                        'b', &directvis);
515 +                        break;
516 +                case 's':                       /* sampling */
517 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
518 +                        break;
519                  default:
520                          goto badparam;
521                  }
522                  break;
523 +        case 'b':                       /* black and white */
524 +                getparam(s+1, "black and white", 'b', &greyscale);
525 +                break;
526 +        case 'i':                       /* irradiance */
527 +                getparam(s+1, "irradiance", 'b', &do_irrad);
528 +                break;
529          case 'a':                       /* ambient */
530                  switch (s[1]) {
531                  case 'v':                       /* value */
532 <                        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);
532 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
533                          break;
534                  case 'a':                       /* accuracy */
535 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
536 <                                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;
535 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
536 >                                setambacc(ambacc);
537                          break;
538                  case 'd':                       /* divisions */
539 <                        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;
539 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
540                          break;
541                  case 's':                       /* samples */
542 <                        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;
542 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
543                          break;
544                  case 'b':                       /* bounces */
545 <                        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;
545 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
546                          break;
547                  case 'r':
548 <                        if (sscanf(s+2, "%d", &i0) != 1) {
549 <                                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;
548 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
549 >                                setambres(ambres);
550                          break;
551                  default:
552                          goto badparam;
553                  }
554                  break;
555 <        case 's':                       /* sample */
555 >        case 'p':                       /* pixel */
556                  switch (s[1]) {
557 <                case 'p':                       /* pixel */
558 <                        if (sscanf(s+2, "%d", &i0) != 1) {
559 <                                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;
557 >                case 's':                       /* sample */
558 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
559 >                                pdepth = 0;
560                          break;
561                  case 't':                       /* threshold */
562 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
563 <                                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;
562 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
563 >                                pdepth = 0;
564                          break;
565                  default:
566                          goto badparam;
567                  }
568                  break;
569 +        case 's':                       /* specular */
570 +                switch (s[1]) {
571 +                case 'j':                       /* jitter */
572 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
573 +                        break;
574 +                case 't':                       /* threshold */
575 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
576 +                        break;
577 +                default:
578 +                        goto badparam;
579 +                }
580 +                break;
581          case '\0':                      /* nothing */
582                  break;
583          default:;
584   badparam:
585 +                *sskip(s) = '\0';
586                  sprintf(errmsg, "%s: unknown variable", s);
587                  error(COMMAND, errmsg);
588                  break;
# Line 530 | Line 597 | char  *s;
597          int  x, y;
598          RAY  thisray;
599  
600 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
601 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
535 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
600 >        if (!sscanvec(s, thisray.rorg) ||
601 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
602  
603                  if (dev->getcur == NULL)
604                          return;
# Line 540 | Line 606 | char  *s;
606                  if ((*dev->getcur)(&x, &y) == ABORT)
607                          return;
608  
609 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
610 <                
609 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
610 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
611 >                        error(COMMAND, "not on image");
612 >                        return;
613 >                }
614 >
615          } else if (normalize(thisray.rdir) == 0.0) {
616                  error(COMMAND, "zero ray direction");
617                  return;
# Line 559 | Line 629 | char  *s;
629                                  ofun[thisray.ro->otype].funame,
630                                  thisray.ro->oname);
631                  (*dev->comout)(buf);
632 <                (*dev->comin)(buf);
632 >                (*dev->comin)(buf, NULL);
633                  if (thisray.rot >= FHUGE)
634                          (*dev->comout)("at infinity");
635                  else {
# Line 567 | Line 637 | char  *s;
637                                          thisray.rop[1], thisray.rop[2]);
638                          (*dev->comout)(buf);
639                  }
640 <                (*dev->comin)(buf);
641 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
640 >                (*dev->comin)(buf, NULL);
641 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
642                                  colval(thisray.rcol,RED),
643                                  colval(thisray.rcol,GRN),
644 <                                colval(thisray.rcol,BLU));
644 >                                colval(thisray.rcol,BLU),
645 >                                luminance(thisray.rcol));
646                  (*dev->comout)(buf);
647          }
648 <        (*dev->comin)(buf);
648 >        (*dev->comin)(buf, NULL);
649   }
650  
651  
# Line 597 | Line 668 | char  *s;
668                  error(COMMAND, errmsg);
669                  return;
670          }
671 + #ifdef MSDOS
672 +        setmode(fileno(fp), O_BINARY);
673 + #endif
674          (*dev->comout)("writing \"");
675          (*dev->comout)(fname);
676          (*dev->comout)("\"...\n");
677                                                  /* write header */
678          fputs(progname, fp);
679          fprintview(&ourview, fp);
680 <        putc('\n', fp);
680 >        if (octname != NULL)
681 >                fprintf(fp, " %s\n", octname);
682 >        else
683 >                putc('\n', fp);
684 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
685          if (exposure != 1.0)
686 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
686 >                fputexpos(exposure, fp);
687 >        if (dev->pixaspect != 1.0)
688 >                fputaspect(dev->pixaspect, fp);
689 >        fputformat(COLRFMT, fp);
690          putc('\n', fp);
691 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, fp);
691 >        fprtresolu(hresolu, vresolu, fp);
692  
693 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
694 <        if (scanline == NULL)
695 <                error(SYSTEM, "out of memory in writepict");
696 <        for (y = ourview.vresolu-1; y >= 0; y--) {
697 <                getpictcolrs(y, scanline, &ptrunk,
698 <                                ourview.hresolu, ourview.vresolu);
699 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
693 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
694 >        if (scanline == NULL) {
695 >                error(COMMAND, "not enough memory!");
696 >                fclose(fp);
697 >                unlink(fname);
698 >                return;
699 >        }
700 >        for (y = vresolu-1; y >= 0; y--) {
701 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
702 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
703                          break;
704          }
705 +        free((char *)scanline);
706          if (fclose(fp) < 0)
707                  error(COMMAND, "write error");
623        free((char *)scanline);
708   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines