ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rv2.c
(Generate patch)

Comparing ray/src/rt/rv2.c (file contents):
Revision 1.11 by greg, Wed Sep 13 13:40:13 1989 UTC vs.
Revision 2.25 by greg, Tue Jul 12 15:24:28 1994 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 FILE  *popen();
36 +
37 + extern char  rifname[128];              /* rad input file name */
38 +
39 + extern char  VersionID[];
40   extern char  *progname;
41 + extern char  *octname;
42  
43  
44   getframe(s)                             /* get a new frame */
45   char  *s;
46   {
47 <        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;
47 >        if (getrect(s, &pframe) < 0)
48                  return;
39        }
40        if (sscanf(s, "%d %d %d %d", &x0, &y0, &x1, &y1) != 4) {
41                if (dev->getcur == NULL)
42                        return;
43                (*dev->comout)("Pick first corner\n");
44                if ((*dev->getcur)(&x0, &y0) == ABORT)
45                        return;
46                (*dev->comout)("Pick second corner\n");
47                if ((*dev->getcur)(&x1, &y1) == ABORT)
48                        return;
49        }
50        if (x0 < x1) {
51                pframe.l = x0;
52                pframe.r = x1;
53        } else {
54                pframe.l = x1;
55                pframe.r = x0;
56        }
57        if (y0 < y1) {
58                pframe.d = y0;
59                pframe.u = y1;
60        } else {
61                pframe.d = y1;
62                pframe.u = y0;
63        }
64        if (pframe.l < 0) pframe.l = 0;
65        if (pframe.d < 0) pframe.d = 0;
66        if (pframe.r > ourview.hresolu) pframe.r = ourview.hresolu;
67        if (pframe.u > ourview.vresolu) pframe.u = ourview.vresolu;
68        if (pframe.l > pframe.r) pframe.l = pframe.r;
69        if (pframe.d > pframe.u) pframe.d = pframe.u;
49          pdepth = 0;
50   }
51  
52  
53 + getrepaint(s)                           /* get area and repaint */
54 + char  *s;
55 + {
56 +        RECT  box;
57 +
58 +        if (getrect(s, &box) < 0)
59 +                return;
60 +        paintrect(&ptrunk, 0, 0, hresolu, vresolu, &box);
61 + }
62 +
63 +
64   getview(s)                              /* get/show view parameters */
65   char  *s;
66   {
# Line 80 | Line 70 | char  *s;
70          int  change = 0;
71          VIEW  nv;
72  
73 +        while (isspace(*s))
74 +                s++;
75 +        if (*s == '-') {                        /* command line parameters */
76 +                copystruct(&nv, &ourview);
77 +                if (sscanview(&nv, s))
78 +                        newview(&nv);
79 +                else
80 +                        error(COMMAND, "bad view option(s)");
81 +                return;
82 +        }
83          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
84                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
85                                  (fp = fopen(fname, "a")) == NULL) {
# Line 89 | Line 89 | char  *s;
89                  }
90                  fputs(progname, fp);
91                  fprintview(&ourview, fp);
92 <                fputs("\n", fp);
92 >                fputs(sskip(s), fp);
93 >                putc('\n', fp);
94                  fclose(fp);
95                  return;
96          }
97          sprintf(buf, "view type (%c): ", ourview.type);
98          (*dev->comout)(buf);
99 <        (*dev->comin)(buf);
100 <        if (buf[0] == CTRL(C)) return;
99 >        (*dev->comin)(buf, NULL);
100 >        if (buf[0] == CTRL('C')) return;
101          if (buf[0] && buf[0] != ourview.type) {
102                  nv.type = buf[0];
103                  change++;
# Line 105 | Line 106 | char  *s;
106          sprintf(buf, "view point (%.6g %.6g %.6g): ",
107                          ourview.vp[0], ourview.vp[1], ourview.vp[2]);
108          (*dev->comout)(buf);
109 <        (*dev->comin)(buf);
110 <        if (buf[0] == CTRL(C)) return;
111 <        if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3)
109 >        (*dev->comin)(buf, NULL);
110 >        if (buf[0] == CTRL('C')) return;
111 >        if (sscanvec(buf, nv.vp))
112                  change++;
113          else
114                  VCOPY(nv.vp, ourview.vp);
115          sprintf(buf, "view direction (%.6g %.6g %.6g): ",
116                          ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]);
117          (*dev->comout)(buf);
118 <        (*dev->comin)(buf);
119 <        if (buf[0] == CTRL(C)) return;
120 <        if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3)
118 >        (*dev->comin)(buf, NULL);
119 >        if (buf[0] == CTRL('C')) return;
120 >        if (sscanvec(buf, nv.vdir))
121                  change++;
122          else
123                  VCOPY(nv.vdir, ourview.vdir);
124          sprintf(buf, "view up (%.6g %.6g %.6g): ",
125                          ourview.vup[0], ourview.vup[1], ourview.vup[2]);
126          (*dev->comout)(buf);
127 <        (*dev->comin)(buf);
128 <        if (buf[0] == CTRL(C)) return;
129 <        if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3)
127 >        (*dev->comin)(buf, NULL);
128 >        if (buf[0] == CTRL('C')) return;
129 >        if (sscanvec(buf, nv.vup))
130                  change++;
131          else
132                  VCOPY(nv.vup, ourview.vup);
133          sprintf(buf, "view horiz and vert size (%.6g %.6g): ",
134                          ourview.horiz, ourview.vert);
135          (*dev->comout)(buf);
136 <        (*dev->comin)(buf);
137 <        if (buf[0] == CTRL(C)) return;
136 >        (*dev->comin)(buf, NULL);
137 >        if (buf[0] == CTRL('C')) return;
138          if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
139                  change++;
140          else {
141                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
142          }
143 <        sprintf(buf, "x and y resolution (%d %d): ",
144 <                        ourview.hresolu, ourview.vresolu);
143 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
144 >                        ourview.hoff, ourview.voff);
145          (*dev->comout)(buf);
146 <        (*dev->comin)(buf);
147 <        if (buf[0] == CTRL(C)) return;
148 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) == 2)
146 >        (*dev->comin)(buf, NULL);
147 >        if (buf[0] == CTRL('C')) return;
148 >        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
149                  change++;
150          else {
151 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
151 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
152          }
153          if (change)
154                  newview(&nv);
# Line 163 | Line 164 | char  *s;
164          VIEW  nv;
165  
166          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
167 <                bcopy(&stdview, &nv, sizeof(VIEW));
168 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
169 <                                (success = viewfile(fname, &nv)) == -1) {
167 >                copystruct(&nv, &stdview);
168 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
169 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
170                          sprintf(errmsg, "cannot open \"%s\"", buf);
171                          error(COMMAND, errmsg);
172                          return;
# Line 176 | Line 177 | char  *s;
177                          newview(&nv);
178                  return;
179          }
180 <        if (oldview.hresolu == 0) {     /* no old view! */
180 >        if (oldview.type == 0) {        /* no old view! */
181                  error(COMMAND, "no previous view");
182                  return;
183          }
184 <        bcopy(&ourview, &nv, sizeof(VIEW));
185 <        bcopy(&oldview, &ourview, sizeof(VIEW));
186 <        bcopy(&nv, &oldview, sizeof(VIEW));
184 >        copystruct(&nv, &ourview);
185 >        copystruct(&ourview, &oldview);
186 >        copystruct(&oldview, &nv);
187          newimage();
188   }
189  
190  
191 < getinterest(s, direc, vec, mp)          /* get area of interest */
191 > saveview(s)                             /* save view to rad file */
192   char  *s;
192 int  direc;
193 FVECT  vec;
194 double  *mp;
193   {
194 <        int  x, y;
195 <        RAY  thisray;
196 <        register int  i;
194 >        char  view[64];
195 >        char  *fname;
196 >        FILE  *fp;
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;
204 <        else if (*mp <= FTINY) {        /* too small */
205 <                error(COMMAND, "illegal magnification");
206 <                return(-1);
207 <        }
208 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
209 <                if (dev->getcur == NULL)
210 <                        return(-1);
211 <                (*dev->comout)("Pick view center\n");
212 <                if ((*dev->getcur)(&x, &y) == ABORT)
213 <                        return(-1);
214 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
215 <                if (!direc || ourview.type == VT_PAR) {
216 <                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
217 <                        if (!localhit(&thisray, &thescene)) {
218 <                                error(COMMAND, "not a local object");
219 <                                return(-1);
220 <                        }
198 >        if (*atos(view, sizeof(view), s)) {
199 >                if (isint(view)) {
200 >                        error(COMMAND, "cannot write view by number");
201 >                        return;
202                  }
203 <                if (direc)
204 <                        if (ourview.type == VT_PAR)
205 <                                for (i = 0; i < 3; i++)
206 <                                        vec[i] = thisray.rop[i] - ourview.vp[i];
207 <                        else
208 <                                VCOPY(vec, thisray.rdir);
209 <                else
210 <                        VCOPY(vec, thisray.rop);
211 <        } else if (direc)
212 <                        for (i = 0; i < 3; i++)
213 <                                vec[i] -= ourview.vp[i];
214 <        return(0);
203 >                s = sskip(s);
204 >        }
205 >        while (isspace(*s))
206 >                s++;
207 >        if (*s)
208 >                atos(rifname, sizeof(rifname), s);
209 >        else if (rifname[0] == '\0') {
210 >                error(COMMAND, "no previous rad file");
211 >                return;
212 >        }
213 >        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
214 >                        (fp = fopen(fname, "a")) == NULL) {
215 >                sprintf(errmsg, "cannot open \"%s\"", rifname);
216 >                error(COMMAND, errmsg);
217 >                return;
218 >        }
219 >        fputs("view= ", fp);
220 >        fputs(view, fp);
221 >        fprintview(&ourview, fp);
222 >        putc('\n', fp);
223 >        fclose(fp);
224   }
225  
226  
227 + loadview(s)                             /* load view from rad file */
228 + char  *s;
229 + {
230 +        char  buf[512];
231 +        char  *fname;
232 +        FILE  *fp;
233 +        VIEW  nv;
234 +
235 +        strcpy(buf, "rad -n -s -V -v ");
236 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
237 +                s = sskip(s);
238 +        else
239 +                strcat(buf, "1");
240 +        if (*s)
241 +                atos(rifname, sizeof(rifname), s);
242 +        else if (rifname[0] == '\0') {
243 +                error(COMMAND, "no previous rad file");
244 +                return;
245 +        }
246 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
247 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
248 +                error(COMMAND, errmsg);
249 +                return;
250 +        }
251 +        sprintf(buf+strlen(buf), " %s", fname);
252 +        if ((fp = popen(buf, "r")) == NULL) {
253 +                error(COMMAND, "cannot run rad");
254 +                return;
255 +        }
256 +        buf[0] = '\0';
257 +        fgets(buf, sizeof(buf), fp);
258 +        pclose(fp);
259 +        copystruct(&nv, &stdview);
260 +        if (!sscanview(&nv, buf)) {
261 +                error(COMMAND, "rad error -- no such view?");
262 +                return;
263 +        }
264 +        newview(&nv);
265 + }
266 +
267 +
268   getaim(s)                               /* aim camera */
269   char  *s;
270   {
240        extern double  tan(), atan();
271          double  zfact;
272          VIEW  nv;
273  
274          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
275                  return;
276 +        nv.type = ourview.type;
277          VCOPY(nv.vp, ourview.vp);
278          VCOPY(nv.vup, ourview.vup);
279 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
280 <        if ((nv.type = ourview.type) == VT_PAR) {
281 <                nv.horiz = ourview.horiz / zfact;
251 <                nv.vert = ourview.vert / zfact;
252 <        } else {
253 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
254 <                                (PI/180./2.);
255 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
256 <                                (PI/180./2.);
257 <        }
279 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
280 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
281 >        zoomview(&nv, zfact);
282          newview(&nv);
283   }
284  
# Line 274 | Line 298 | char  *s;
298   getrotate(s)                            /* rotate camera */
299   char  *s;
300   {
277        extern double  normalize(), tan(), atan();
301          VIEW  nv;
302          FVECT  v1;
303          double  angle, elev, zfact;
# Line 284 | Line 307 | char  *s;
307                  error(COMMAND, "missing angle");
308                  return;
309          }
310 +        nv.type = ourview.type;
311          VCOPY(nv.vp, ourview.vp);
312          VCOPY(nv.vup, ourview.vup);
313 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
313 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
314          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
315          if (elev != 0.0) {
316                  fcross(v1, nv.vdir, ourview.vup);
317                  normalize(v1);
318                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
319          }
320 <        if ((nv.type = ourview.type) == VT_PAR) {
321 <                nv.horiz = ourview.horiz / zfact;
298 <                nv.vert = ourview.vert / zfact;
299 <        } else {
300 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
301 <                                (PI/180./2.);
302 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
303 <                                (PI/180./2.);
304 <        }
320 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
321 >        zoomview(&nv, zfact);
322          newview(&nv);
323   }
324  
# Line 326 | Line 343 | register char  *s;
343   getexposure(s)                          /* get new exposure */
344   char  *s;
345   {
329        double  atof(), pow(), fabs();
346          char  buf[128];
347          register char  *cp;
332        register PNODE  *p;
348          RECT  r;
349          int  x, y;
350 <        double  e;
350 >        register PNODE  *p = &ptrunk;
351 >        int  adapt = 0;
352 >        double  e = 1.0;
353  
354          for (cp = s; isspace(*cp); cp++)
355                  ;
356 +        if (*cp == '@') {
357 +                adapt++;
358 +                while (isspace(*++cp))
359 +                        ;
360 +        }
361          if (*cp == '\0') {              /* normalize to point */
362                  if (dev->getcur == NULL)
363                          return;
# Line 343 | Line 365 | char  *s;
365                  if ((*dev->getcur)(&x, &y) == ABORT)
366                          return;
367                  r.l = r.d = 0;
368 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
368 >                r.r = hresolu; r.u = vresolu;
369                  p = findrect(x, y, &ptrunk, &r, -1);
348                e = 1.0;
370          } else {
371                  if (*cp == '=') {       /* absolute setting */
372                          p = NULL;
# Line 353 | Line 374 | char  *s;
374                          for (cp++; isspace(*cp); cp++)
375                                  ;
376                          if (*cp == '\0') {      /* interactive */
377 <                                sprintf(buf, "exposure (%lf): ", exposure);
377 >                                sprintf(buf, "exposure (%f): ", exposure);
378                                  (*dev->comout)(buf);
379 <                                (*dev->comin)(buf);
379 >                                (*dev->comin)(buf, NULL);
380                                  for (cp = buf; isspace(*cp); cp++)
381                                          ;
382                                  if (*cp == '\0')
383                                          return;
384                          }
364                } else {                /* normalize to average */
365                        p = &ptrunk;
366                        e = 1.0;
385                  }
386                  if (*cp == '+' || *cp == '-')   /* f-stops */
387                          e *= pow(2.0, atof(cp));
# Line 371 | Line 389 | char  *s;
389                          e *= atof(cp);
390          }
391          if (p != NULL) {                /* relative setting */
392 <                if (bright(p->v) <= FTINY) {
392 >                if (bright(p->v) < 1e-15) {
393                          error(COMMAND, "cannot normalize to zero");
394                          return;
395                  }
396 <                e *= 0.5 / bright(p->v);
396 >                if (adapt)
397 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
398 >                else
399 >                        e *= 0.5 / bright(p->v);
400          }
401          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
402                  return;
# Line 385 | Line 406 | char  *s;
406   }
407  
408  
409 + getparam(str, dsc, typ, ptr)            /* get variable from user */
410 + char  *str, *dsc;
411 + int  typ;
412 + register union {int i; double d; COLOR C;}  *ptr;
413 + {
414 +        extern char  *index();
415 +        int  i0;
416 +        double  d0, d1, d2;
417 +        char  buf[48];
418 +
419 +        switch (typ) {
420 +        case 'i':                       /* integer */
421 +                if (sscanf(str, "%d", &i0) != 1) {
422 +                        (*dev->comout)(dsc);
423 +                        sprintf(buf, " (%d): ", ptr->i);
424 +                        (*dev->comout)(buf);
425 +                        (*dev->comin)(buf, NULL);
426 +                        if (sscanf(buf, "%d", &i0) != 1)
427 +                                return(0);
428 +                }
429 +                ptr->i = i0;
430 +                return(1);
431 +        case 'r':                       /* real */
432 +                if (sscanf(str, "%lf", &d0) != 1) {
433 +                        (*dev->comout)(dsc);
434 +                        sprintf(buf, " (%.6g): ", ptr->d);
435 +                        (*dev->comout)(buf);
436 +                        (*dev->comin)(buf, NULL);
437 +                        if (sscanf(buf, "%lf", &d0) != 1)
438 +                                return(0);
439 +                }
440 +                ptr->d = d0;
441 +                return(1);
442 +        case 'b':                       /* boolean */
443 +                if (sscanf(str, "%1s", buf) != 1) {
444 +                        (*dev->comout)(dsc);
445 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
446 +                        (*dev->comout)(buf);
447 +                        (*dev->comin)(buf, NULL);
448 +                        if (buf[0] == '\0' ||
449 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
450 +                                return(0);
451 +                }
452 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
453 +                return(1);
454 +        case 'C':                       /* color */
455 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
456 +                        (*dev->comout)(dsc);
457 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
458 +                                        colval(ptr->C,RED),
459 +                                        colval(ptr->C,GRN),
460 +                                        colval(ptr->C,BLU));
461 +                        (*dev->comout)(buf);
462 +                        (*dev->comin)(buf, NULL);
463 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
464 +                                return(0);
465 +                }
466 +                setcolor(ptr->C, d0, d1, d2);
467 +                return(1);
468 +        }
469 + }
470 +
471 +
472   setparam(s)                             /* get/set program parameter */
473   register char  *s;
474   {
# Line 397 | Line 481 | register char  *s;
481          extern double  shadcert;
482          extern COLOR  ambval;
483          extern double  ambacc;
400        extern double  minarad;
484          extern int  ambres;
485          extern int  ambdiv;
486          extern int  ambssamp;
487          extern int  ambounce;
488 <        int  i0;
489 <        double  d0, d1, d2;
488 >        extern int  directvis;
489 >        extern double  srcsizerat;
490 >        extern int  do_irrad;
491 >        extern double  specjitter;
492 >        extern double  specthresh;
493          char  buf[128];
494          
495          if (s[0] == '\0') {
496 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
497 <                (*dev->comin)(buf);
496 >                (*dev->comout)(
497 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
498 >                (*dev->comin)(buf, NULL);
499                  s = buf;
500          }
501          switch (s[0]) {
502          case 'l':                       /* limit */
503                  switch (s[1]) {
504                  case 'w':                       /* weight */
505 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
419 <                                sprintf(buf, "limit weight (%.6g): ",
420 <                                                minweight);
421 <                                (*dev->comout)(buf);
422 <                                (*dev->comin)(buf);
423 <                                if (sscanf(buf, "%lf", &d0) != 1)
424 <                                        break;
425 <                        }
426 <                        minweight = d0;
505 >                        getparam(s+2, "limit weight", 'r', &minweight);
506                          break;
507                  case 'r':                       /* reflection */
508 <                        if (sscanf(s+2, "%d", &i0) != 1) {
430 <                                sprintf(buf, "limit reflection (%d): ",
431 <                                                maxdepth);
432 <                                (*dev->comout)(buf);
433 <                                (*dev->comin)(buf);
434 <                                if (sscanf(buf, "%d", &i0) != 1)
435 <                                        break;
436 <                        }
437 <                        maxdepth = i0;
508 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
509                          break;
510                  default:
511                          goto badparam;
# Line 443 | Line 514 | register char  *s;
514          case 'd':                       /* direct */
515                  switch (s[1]) {
516                  case 'j':                       /* jitter */
517 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
447 <                                sprintf(buf, "direct jitter (%.6g): ",
448 <                                                dstrsrc);
449 <                                (*dev->comout)(buf);
450 <                                (*dev->comin)(buf);
451 <                                if (sscanf(buf, "%lf", &d0) != 1)
452 <                                        break;
453 <                        }
454 <                        dstrsrc = d0;
517 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
518                          break;
519                  case 'c':                       /* certainty */
520 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
458 <                                sprintf(buf, "direct certainty (%.6g): ",
459 <                                                shadcert);
460 <                                (*dev->comout)(buf);
461 <                                (*dev->comin)(buf);
462 <                                if (sscanf(buf, "%lf", &d0) != 1)
463 <                                        break;
464 <                        }
465 <                        shadcert = d0;
520 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
521                          break;
522                  case 't':                       /* threshold */
523 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
469 <                                sprintf(buf, "direct threshold (%.6g): ",
470 <                                                shadthresh);
471 <                                (*dev->comout)(buf);
472 <                                (*dev->comin)(buf);
473 <                                if (sscanf(buf, "%lf", &d0) != 1)
474 <                                        break;
475 <                        }
476 <                        shadthresh = d0;
523 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
524                          break;
525 +                case 'v':                       /* visibility */
526 +                        getparam(s+2, "direct visibility",
527 +                                        'b', &directvis);
528 +                        break;
529 +                case 's':                       /* sampling */
530 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
531 +                        break;
532                  default:
533                          goto badparam;
534                  }
535                  break;
536 +        case 'b':                       /* black and white */
537 +                getparam(s+1, "black and white", 'b', &greyscale);
538 +                break;
539 +        case 'i':                       /* irradiance */
540 +                getparam(s+1, "irradiance", 'b', &do_irrad);
541 +                break;
542          case 'a':                       /* ambient */
543                  switch (s[1]) {
544                  case 'v':                       /* value */
545 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
486 <                                sprintf(buf,
487 <                                        "ambient value (%.6g %.6g %.6g): ",
488 <                                                colval(ambval,RED),
489 <                                                colval(ambval,GRN),
490 <                                                colval(ambval,BLU));
491 <                                (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
493 <                                if (sscanf(buf, "%lf %lf %lf",
494 <                                                &d0, &d1, &d2) != 3)
495 <                                        break;
496 <                        }
497 <                        setcolor(ambval, d0, d1, d2);
545 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
546                          break;
547                  case 'a':                       /* accuracy */
548 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
549 <                                sprintf(buf, "ambient accuracy (%.6g): ",
502 <                                                ambacc);
503 <                                (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
505 <                                if (sscanf(buf, "%lf", &d0) != 1)
506 <                                        break;
507 <                        }
508 <                        ambacc = d0;
548 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
549 >                                setambacc(ambacc);
550                          break;
551                  case 'd':                       /* divisions */
552 <                        if (sscanf(s+2, "%d", &i0) != 1) {
512 <                                sprintf(buf, "ambient divisions (%d): ",
513 <                                                ambdiv);
514 <                                (*dev->comout)(buf);
515 <                                (*dev->comin)(buf);
516 <                                if (sscanf(buf, "%d", &i0) != 1)
517 <                                        break;
518 <                        }
519 <                        ambdiv = i0;
552 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
553                          break;
554                  case 's':                       /* samples */
555 <                        if (sscanf(s+2, "%d", &i0) != 1) {
523 <                                sprintf(buf, "ambient super-samples (%d): ",
524 <                                                ambssamp);
525 <                                (*dev->comout)(buf);
526 <                                (*dev->comin)(buf);
527 <                                if (sscanf(buf, "%d", &i0) != 1)
528 <                                        break;
529 <                        }
530 <                        ambssamp = i0;
555 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
556                          break;
557                  case 'b':                       /* bounces */
558 <                        if (sscanf(s+2, "%d", &i0) != 1) {
534 <                                sprintf(buf, "ambient bounces (%d): ",
535 <                                                ambounce);
536 <                                (*dev->comout)(buf);
537 <                                (*dev->comin)(buf);
538 <                                if (sscanf(buf, "%d", &i0) != 1)
539 <                                        break;
540 <                        }
541 <                        ambounce = i0;
558 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
559                          break;
560                  case 'r':
561 <                        if (sscanf(s+2, "%d", &i0) != 1) {
562 <                                sprintf(buf, "ambient resolution (%d): ",
546 <                                                ambres);
547 <                                (*dev->comout)(buf);
548 <                                (*dev->comin)(buf);
549 <                                if (sscanf(buf, "%d", &i0) != 1)
550 <                                        break;
551 <                        }
552 <                        ambres = i0;
553 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
561 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
562 >                                setambres(ambres);
563                          break;
564                  default:
565                          goto badparam;
566                  }
567                  break;
568 <        case 's':                       /* sample */
568 >        case 'p':                       /* pixel */
569                  switch (s[1]) {
570 <                case 'p':                       /* pixel */
571 <                        if (sscanf(s+2, "%d", &i0) != 1) {
572 <                                sprintf(buf, "sample pixel (%d): ", psample);
564 <                                (*dev->comout)(buf);
565 <                                (*dev->comin)(buf);
566 <                                if (sscanf(buf, "%d", &i0) != 1)
567 <                                        break;
568 <                        }
569 <                        psample = i0;
570 <                        pdepth = 0;
570 >                case 's':                       /* sample */
571 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
572 >                                pdepth = 0;
573                          break;
574                  case 't':                       /* threshold */
575 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
576 <                                sprintf(buf, "sample threshold (%.6g): ",
575 <                                                maxdiff);
576 <                                (*dev->comout)(buf);
577 <                                (*dev->comin)(buf);
578 <                                if (sscanf(buf, "%lf", &d0) != 1)
579 <                                        break;
580 <                        }
581 <                        maxdiff = d0;
582 <                        pdepth = 0;
575 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
576 >                                pdepth = 0;
577                          break;
578                  default:
579                          goto badparam;
580                  }
581                  break;
582 +        case 's':                       /* specular */
583 +                switch (s[1]) {
584 +                case 'j':                       /* jitter */
585 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
586 +                        break;
587 +                case 't':                       /* threshold */
588 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
589 +                        break;
590 +                default:
591 +                        goto badparam;
592 +                }
593 +                break;
594          case '\0':                      /* nothing */
595                  break;
596          default:;
597   badparam:
598 +                *sskip(s) = '\0';
599                  sprintf(errmsg, "%s: unknown variable", s);
600                  error(COMMAND, errmsg);
601                  break;
# Line 603 | Line 610 | char  *s;
610          int  x, y;
611          RAY  thisray;
612  
613 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
614 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
608 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
613 >        if (!sscanvec(s, thisray.rorg) ||
614 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
615  
616                  if (dev->getcur == NULL)
617                          return;
# Line 613 | Line 619 | char  *s;
619                  if ((*dev->getcur)(&x, &y) == ABORT)
620                          return;
621  
622 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
623 <                
622 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
623 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
624 >                        error(COMMAND, "not on image");
625 >                        return;
626 >                }
627 >
628          } else if (normalize(thisray.rdir) == 0.0) {
629                  error(COMMAND, "zero ray direction");
630                  return;
# Line 627 | Line 637 | char  *s;
637          if (thisray.ro == NULL)
638                  (*dev->comout)("ray hit nothing");
639          else {
640 <                sprintf(buf, "ray hit %s %s \"%s\"",
641 <                                objptr(thisray.ro->omod)->oname,
640 >                sprintf(buf, "ray hit %s%s %s \"%s\"",
641 >                                thisray.rod < 0.0 ? "back of " : "",
642 >                                thisray.ro->omod == OVOID ? VOIDID :
643 >                                        objptr(thisray.ro->omod)->oname,
644                                  ofun[thisray.ro->otype].funame,
645                                  thisray.ro->oname);
646                  (*dev->comout)(buf);
647 <                (*dev->comin)(buf);
647 >                (*dev->comin)(buf, NULL);
648                  if (thisray.rot >= FHUGE)
649                          (*dev->comout)("at infinity");
650                  else {
# Line 640 | Line 652 | char  *s;
652                                          thisray.rop[1], thisray.rop[2]);
653                          (*dev->comout)(buf);
654                  }
655 <                (*dev->comin)(buf);
656 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
655 >                (*dev->comin)(buf, NULL);
656 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
657                                  colval(thisray.rcol,RED),
658                                  colval(thisray.rcol,GRN),
659 <                                colval(thisray.rcol,BLU));
659 >                                colval(thisray.rcol,BLU),
660 >                                luminance(thisray.rcol));
661                  (*dev->comout)(buf);
662          }
663 <        (*dev->comin)(buf);
663 >        (*dev->comin)(buf, NULL);
664   }
665  
666  
# Line 660 | Line 673 | char  *s;
673          COLR  *scanline;
674          int  y;
675  
676 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
676 >        while (isspace(*s))
677 >                s++;
678 >        if (*s)
679 >                atos(buf, sizeof(buf), s);
680 >        else if (buf[0] == '\0') {
681                  error(COMMAND, "no file");
682                  return;
683          }
# Line 670 | Line 687 | char  *s;
687                  error(COMMAND, errmsg);
688                  return;
689          }
690 + #ifdef MSDOS
691 +        setmode(fileno(fp), O_BINARY);
692 + #endif
693          (*dev->comout)("writing \"");
694          (*dev->comout)(fname);
695          (*dev->comout)("\"...\n");
696                                                  /* write header */
697 +        newheader("RADIANCE", fp);
698          fputs(progname, fp);
699          fprintview(&ourview, fp);
700 <        putc('\n', fp);
700 >        if (octname != NULL)
701 >                fprintf(fp, " %s\n", octname);
702 >        else
703 >                putc('\n', fp);
704 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
705          if (exposure != 1.0)
706 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
706 >                fputexpos(exposure, fp);
707 >        if (dev->pixaspect != 1.0)
708 >                fputaspect(dev->pixaspect, fp);
709 >        fputformat(COLRFMT, fp);
710          putc('\n', fp);
711 <        fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, fp);
711 >        fprtresolu(hresolu, vresolu, fp);
712  
713 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
714 <        if (scanline == NULL)
715 <                error(SYSTEM, "out of memory in writepict");
716 <        for (y = ourview.vresolu-1; y >= 0; y--) {
717 <                getpictcolrs(y, scanline, &ptrunk,
718 <                                ourview.hresolu, ourview.vresolu);
719 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
713 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
714 >        if (scanline == NULL) {
715 >                error(COMMAND, "not enough memory!");
716 >                fclose(fp);
717 >                unlink(fname);
718 >                return;
719 >        }
720 >        for (y = vresolu-1; y >= 0; y--) {
721 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
722 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
723                          break;
724          }
725 +        free((char *)scanline);
726          if (fclose(fp) < 0)
727                  error(COMMAND, "write error");
696        free((char *)scanline);
728   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines