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.9 by greg, Tue Jun 13 10:57:45 1989 UTC vs.
Revision 2.26 by greg, Tue Dec 20 20:18:37 1994 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1987 Regents of the University of California */
1 > /* Copyright (c) 1994 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   {
67          FILE  *fp;
68          char  buf[128];
69 <        char  *fname, *getpath();
69 >        char  *fname;
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)) == NULL ||
84 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
85                                  (fp = fopen(fname, "a")) == NULL) {
86                          sprintf(errmsg, "cannot open \"%s\"", buf);
87                          error(COMMAND, errmsg);
# 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, "fore and aft clipping plane (%.6g %.6g): ",
144 >                        ourview.vfore, ourview.vaft);
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.vfore, &nv.vaft) == 2)
149                  change++;
150          else {
151 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
151 >                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
152          }
153 +        sprintf(buf, "view shift and lift (%.6g %.6g): ",
154 +                        ourview.hoff, ourview.voff);
155 +        (*dev->comout)(buf);
156 +        (*dev->comin)(buf, NULL);
157 +        if (buf[0] == CTRL('C')) return;
158 +        if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
159 +                change++;
160 +        else {
161 +                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
162 +        }
163          if (change)
164                  newview(&nv);
165   }
# Line 158 | Line 169 | lastview(s)                            /* return to a previous view */
169   char  *s;
170   {
171          char  buf[128];
172 <        char  *fname, *getpath();
172 >        char  *fname;
173          int  success;
174          VIEW  nv;
175  
176          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
177 <                bcopy(&stdview, &nv, sizeof(VIEW));
178 <                if ((fname = getpath(buf, NULL)) == NULL ||
179 <                                (success = viewfile(fname, &nv)) == -1) {
177 >                copystruct(&nv, &stdview);
178 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
179 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
180                          sprintf(errmsg, "cannot open \"%s\"", buf);
181                          error(COMMAND, errmsg);
182                          return;
# Line 176 | Line 187 | char  *s;
187                          newview(&nv);
188                  return;
189          }
190 <        if (oldview.hresolu == 0) {     /* no old view! */
190 >        if (oldview.type == 0) {        /* no old view! */
191                  error(COMMAND, "no previous view");
192                  return;
193          }
194 <        bcopy(&ourview, &nv, sizeof(VIEW));
195 <        bcopy(&oldview, &ourview, sizeof(VIEW));
196 <        bcopy(&nv, &oldview, sizeof(VIEW));
194 >        copystruct(&nv, &ourview);
195 >        copystruct(&ourview, &oldview);
196 >        copystruct(&oldview, &nv);
197          newimage();
198   }
199  
200  
201 < getinterest(s, direc, vec, mp)          /* get area of interest */
201 > saveview(s)                             /* save view to rad file */
202   char  *s;
192 int  direc;
193 FVECT  vec;
194 double  *mp;
203   {
204 <        int  x, y;
205 <        RAY  thisray;
206 <        register int  i;
204 >        char  view[64];
205 >        char  *fname;
206 >        FILE  *fp;
207  
208 <        if (sscanf(s, "%lf", mp) != 1)
209 <                *mp = 1.0;
210 <        else if (*mp < -FTINY)          /* negative zoom is reduction */
211 <                *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 <                        }
208 >        if (*atos(view, sizeof(view), s)) {
209 >                if (isint(view)) {
210 >                        error(COMMAND, "cannot write view by number");
211 >                        return;
212                  }
213 <                if (direc)
214 <                        if (ourview.type == VT_PAR)
215 <                                for (i = 0; i < 3; i++)
216 <                                        vec[i] = thisray.rop[i] - ourview.vp[i];
217 <                        else
218 <                                VCOPY(vec, thisray.rdir);
219 <                else
220 <                        VCOPY(vec, thisray.rop);
221 <        } else if (direc)
222 <                        for (i = 0; i < 3; i++)
223 <                                vec[i] -= ourview.vp[i];
224 <        return(0);
213 >                s = sskip(s);
214 >        }
215 >        while (isspace(*s))
216 >                s++;
217 >        if (*s)
218 >                atos(rifname, sizeof(rifname), s);
219 >        else if (rifname[0] == '\0') {
220 >                error(COMMAND, "no previous rad file");
221 >                return;
222 >        }
223 >        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
224 >                        (fp = fopen(fname, "a")) == NULL) {
225 >                sprintf(errmsg, "cannot open \"%s\"", rifname);
226 >                error(COMMAND, errmsg);
227 >                return;
228 >        }
229 >        fputs("view= ", fp);
230 >        fputs(view, fp);
231 >        fprintview(&ourview, fp);
232 >        putc('\n', fp);
233 >        fclose(fp);
234   }
235  
236  
237 + loadview(s)                             /* load view from rad file */
238 + char  *s;
239 + {
240 +        char  buf[512];
241 +        char  *fname;
242 +        FILE  *fp;
243 +        VIEW  nv;
244 +
245 +        strcpy(buf, "rad -n -s -V -v ");
246 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
247 +                s = sskip(s);
248 +        else
249 +                strcat(buf, "1");
250 +        if (*s)
251 +                atos(rifname, sizeof(rifname), s);
252 +        else if (rifname[0] == '\0') {
253 +                error(COMMAND, "no previous rad file");
254 +                return;
255 +        }
256 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
257 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
258 +                error(COMMAND, errmsg);
259 +                return;
260 +        }
261 +        sprintf(buf+strlen(buf), " %s", fname);
262 +        if ((fp = popen(buf, "r")) == NULL) {
263 +                error(COMMAND, "cannot run rad");
264 +                return;
265 +        }
266 +        buf[0] = '\0';
267 +        fgets(buf, sizeof(buf), fp);
268 +        pclose(fp);
269 +        copystruct(&nv, &stdview);
270 +        if (!sscanview(&nv, buf)) {
271 +                error(COMMAND, "rad error -- no such view?");
272 +                return;
273 +        }
274 +        newview(&nv);
275 + }
276 +
277 +
278   getaim(s)                               /* aim camera */
279   char  *s;
280   {
240        extern double  tan(), atan();
281          double  zfact;
282          VIEW  nv;
283  
284          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
285                  return;
286 +        nv.type = ourview.type;
287          VCOPY(nv.vp, ourview.vp);
288          VCOPY(nv.vup, ourview.vup);
289 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
290 <        if ((nv.type = ourview.type) == VT_PAR) {
291 <                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 <        }
289 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
290 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
291 >        zoomview(&nv, zfact);
292          newview(&nv);
293   }
294  
# Line 274 | Line 308 | char  *s;
308   getrotate(s)                            /* rotate camera */
309   char  *s;
310   {
277        extern double  normalize(), tan(), atan();
311          VIEW  nv;
312          FVECT  v1;
313          double  angle, elev, zfact;
# Line 284 | Line 317 | char  *s;
317                  error(COMMAND, "missing angle");
318                  return;
319          }
320 +        nv.type = ourview.type;
321          VCOPY(nv.vp, ourview.vp);
322          VCOPY(nv.vup, ourview.vup);
323 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
323 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
324          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
325          if (elev != 0.0) {
326                  fcross(v1, nv.vdir, ourview.vup);
327                  normalize(v1);
328                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
329          }
330 <        if ((nv.type = ourview.type) == VT_PAR) {
331 <                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 <        }
330 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
331 >        zoomview(&nv, zfact);
332          newview(&nv);
333   }
334  
# Line 326 | Line 353 | register char  *s;
353   getexposure(s)                          /* get new exposure */
354   char  *s;
355   {
329        double  atof(), pow(), fabs();
356          char  buf[128];
357          register char  *cp;
332        register PNODE  *p;
358          RECT  r;
359          int  x, y;
360 <        double  e;
360 >        register PNODE  *p = &ptrunk;
361 >        int  adapt = 0;
362 >        double  e = 1.0;
363  
364          for (cp = s; isspace(*cp); cp++)
365                  ;
366 +        if (*cp == '@') {
367 +                adapt++;
368 +                while (isspace(*++cp))
369 +                        ;
370 +        }
371          if (*cp == '\0') {              /* normalize to point */
372                  if (dev->getcur == NULL)
373                          return;
# Line 343 | Line 375 | char  *s;
375                  if ((*dev->getcur)(&x, &y) == ABORT)
376                          return;
377                  r.l = r.d = 0;
378 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
378 >                r.r = hresolu; r.u = vresolu;
379                  p = findrect(x, y, &ptrunk, &r, -1);
348                e = 1.0;
380          } else {
381                  if (*cp == '=') {       /* absolute setting */
382                          p = NULL;
# Line 353 | Line 384 | char  *s;
384                          for (cp++; isspace(*cp); cp++)
385                                  ;
386                          if (*cp == '\0') {      /* interactive */
387 <                                sprintf(buf, "exposure (%lf): ", exposure);
387 >                                sprintf(buf, "exposure (%f): ", exposure);
388                                  (*dev->comout)(buf);
389 <                                (*dev->comin)(buf);
389 >                                (*dev->comin)(buf, NULL);
390                                  for (cp = buf; isspace(*cp); cp++)
391                                          ;
392                                  if (*cp == '\0')
393                                          return;
394                          }
364                } else {                /* normalize to average */
365                        p = &ptrunk;
366                        e = 1.0;
395                  }
396                  if (*cp == '+' || *cp == '-')   /* f-stops */
397                          e *= pow(2.0, atof(cp));
# Line 371 | Line 399 | char  *s;
399                          e *= atof(cp);
400          }
401          if (p != NULL) {                /* relative setting */
402 <                if (bright(p->v) <= FTINY) {
402 >                if (bright(p->v) < 1e-15) {
403                          error(COMMAND, "cannot normalize to zero");
404                          return;
405                  }
406 <                e *= 0.5 / bright(p->v);
406 >                if (adapt)
407 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
408 >                else
409 >                        e *= 0.5 / bright(p->v);
410          }
411          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
412                  return;
# Line 385 | Line 416 | char  *s;
416   }
417  
418  
419 + getparam(str, dsc, typ, ptr)            /* get variable from user */
420 + char  *str, *dsc;
421 + int  typ;
422 + register union {int i; double d; COLOR C;}  *ptr;
423 + {
424 +        extern char  *index();
425 +        int  i0;
426 +        double  d0, d1, d2;
427 +        char  buf[48];
428 +
429 +        switch (typ) {
430 +        case 'i':                       /* integer */
431 +                if (sscanf(str, "%d", &i0) != 1) {
432 +                        (*dev->comout)(dsc);
433 +                        sprintf(buf, " (%d): ", ptr->i);
434 +                        (*dev->comout)(buf);
435 +                        (*dev->comin)(buf, NULL);
436 +                        if (sscanf(buf, "%d", &i0) != 1)
437 +                                return(0);
438 +                }
439 +                ptr->i = i0;
440 +                return(1);
441 +        case 'r':                       /* real */
442 +                if (sscanf(str, "%lf", &d0) != 1) {
443 +                        (*dev->comout)(dsc);
444 +                        sprintf(buf, " (%.6g): ", ptr->d);
445 +                        (*dev->comout)(buf);
446 +                        (*dev->comin)(buf, NULL);
447 +                        if (sscanf(buf, "%lf", &d0) != 1)
448 +                                return(0);
449 +                }
450 +                ptr->d = d0;
451 +                return(1);
452 +        case 'b':                       /* boolean */
453 +                if (sscanf(str, "%1s", buf) != 1) {
454 +                        (*dev->comout)(dsc);
455 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
456 +                        (*dev->comout)(buf);
457 +                        (*dev->comin)(buf, NULL);
458 +                        if (buf[0] == '\0' ||
459 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
460 +                                return(0);
461 +                }
462 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
463 +                return(1);
464 +        case 'C':                       /* color */
465 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
466 +                        (*dev->comout)(dsc);
467 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
468 +                                        colval(ptr->C,RED),
469 +                                        colval(ptr->C,GRN),
470 +                                        colval(ptr->C,BLU));
471 +                        (*dev->comout)(buf);
472 +                        (*dev->comin)(buf, NULL);
473 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
474 +                                return(0);
475 +                }
476 +                setcolor(ptr->C, d0, d1, d2);
477 +                return(1);
478 +        }
479 + }
480 +
481 +
482   setparam(s)                             /* get/set program parameter */
483   register char  *s;
484   {
# Line 397 | Line 491 | register char  *s;
491          extern double  shadcert;
492          extern COLOR  ambval;
493          extern double  ambacc;
400        extern double  minarad;
494          extern int  ambres;
495          extern int  ambdiv;
496          extern int  ambssamp;
497          extern int  ambounce;
498 <        int  i0;
499 <        double  d0, d1, d2;
498 >        extern int  directvis;
499 >        extern double  srcsizerat;
500 >        extern int  do_irrad;
501 >        extern double  specjitter;
502 >        extern double  specthresh;
503          char  buf[128];
504          
505          if (s[0] == '\0') {
506 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
507 <                (*dev->comin)(buf);
506 >                (*dev->comout)(
507 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
508 >                (*dev->comin)(buf, NULL);
509                  s = buf;
510          }
511          switch (s[0]) {
512          case 'l':                       /* limit */
513                  switch (s[1]) {
514                  case 'w':                       /* weight */
515 <                        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;
515 >                        getparam(s+2, "limit weight", 'r', &minweight);
516                          break;
517                  case 'r':                       /* reflection */
518 <                        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;
518 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
519                          break;
520                  default:
521                          goto badparam;
# Line 443 | Line 524 | register char  *s;
524          case 'd':                       /* direct */
525                  switch (s[1]) {
526                  case 'j':                       /* jitter */
527 <                        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;
527 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
528                          break;
529                  case 'c':                       /* certainty */
530 <                        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;
530 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
531                          break;
532                  case 't':                       /* threshold */
533 <                        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;
533 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
534                          break;
535 +                case 'v':                       /* visibility */
536 +                        getparam(s+2, "direct visibility",
537 +                                        'b', &directvis);
538 +                        break;
539 +                case 's':                       /* sampling */
540 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
541 +                        break;
542                  default:
543                          goto badparam;
544                  }
545                  break;
546 +        case 'b':                       /* black and white */
547 +                getparam(s+1, "black and white", 'b', &greyscale);
548 +                break;
549 +        case 'i':                       /* irradiance */
550 +                getparam(s+1, "irradiance", 'b', &do_irrad);
551 +                break;
552          case 'a':                       /* ambient */
553                  switch (s[1]) {
554                  case 'v':                       /* value */
555 <                        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);
555 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
556                          break;
557                  case 'a':                       /* accuracy */
558 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
559 <                                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;
558 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
559 >                                setambacc(ambacc);
560                          break;
561                  case 'd':                       /* divisions */
562 <                        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;
562 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
563                          break;
564                  case 's':                       /* samples */
565 <                        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;
565 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
566                          break;
567                  case 'b':                       /* bounces */
568 <                        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;
568 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
569                          break;
570                  case 'r':
571 <                        if (sscanf(s+2, "%d", &i0) != 1) {
572 <                                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;
571 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
572 >                                setambres(ambres);
573                          break;
574                  default:
575                          goto badparam;
576                  }
577                  break;
578 <        case 's':                       /* sample */
578 >        case 'p':                       /* pixel */
579                  switch (s[1]) {
580 <                case 'p':                       /* pixel */
581 <                        if (sscanf(s+2, "%d", &i0) != 1) {
582 <                                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;
580 >                case 's':                       /* sample */
581 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
582 >                                pdepth = 0;
583                          break;
584                  case 't':                       /* threshold */
585 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
586 <                                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;
585 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
586 >                                pdepth = 0;
587                          break;
588                  default:
589                          goto badparam;
590                  }
591                  break;
592 +        case 's':                       /* specular */
593 +                switch (s[1]) {
594 +                case 'j':                       /* jitter */
595 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
596 +                        break;
597 +                case 't':                       /* threshold */
598 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
599 +                        break;
600 +                default:
601 +                        goto badparam;
602 +                }
603 +                break;
604          case '\0':                      /* nothing */
605                  break;
606          default:;
607   badparam:
608 +                *sskip(s) = '\0';
609                  sprintf(errmsg, "%s: unknown variable", s);
610                  error(COMMAND, errmsg);
611                  break;
# Line 603 | Line 620 | char  *s;
620          int  x, y;
621          RAY  thisray;
622  
623 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
607 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
608 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
623 >        thisray.rmax = 0.0;
624  
625 +        if (!sscanvec(s, thisray.rorg) ||
626 +                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
627 +
628                  if (dev->getcur == NULL)
629                          return;
630                  (*dev->comout)("Pick ray\n");
631                  if ((*dev->getcur)(&x, &y) == ABORT)
632                          return;
633  
634 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
635 <                
634 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
635 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
636 >                        error(COMMAND, "not on image");
637 >                        return;
638 >                }
639 >
640          } else if (normalize(thisray.rdir) == 0.0) {
641                  error(COMMAND, "zero ray direction");
642                  return;
# Line 627 | Line 649 | char  *s;
649          if (thisray.ro == NULL)
650                  (*dev->comout)("ray hit nothing");
651          else {
652 <                sprintf(buf, "ray hit %s %s \"%s\"",
653 <                                objptr(thisray.ro->omod)->oname,
652 >                sprintf(buf, "ray hit %s%s %s \"%s\"",
653 >                                thisray.rod < 0.0 ? "back of " : "",
654 >                                thisray.ro->omod == OVOID ? VOIDID :
655 >                                        objptr(thisray.ro->omod)->oname,
656                                  ofun[thisray.ro->otype].funame,
657                                  thisray.ro->oname);
658                  (*dev->comout)(buf);
659 <                (*dev->comin)(buf);
659 >                (*dev->comin)(buf, NULL);
660                  if (thisray.rot >= FHUGE)
661                          (*dev->comout)("at infinity");
662                  else {
# Line 640 | Line 664 | char  *s;
664                                          thisray.rop[1], thisray.rop[2]);
665                          (*dev->comout)(buf);
666                  }
667 <                (*dev->comin)(buf);
668 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
667 >                (*dev->comin)(buf, NULL);
668 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
669                                  colval(thisray.rcol,RED),
670                                  colval(thisray.rcol,GRN),
671 <                                colval(thisray.rcol,BLU));
671 >                                colval(thisray.rcol,BLU),
672 >                                luminance(thisray.rcol));
673                  (*dev->comout)(buf);
674          }
675 <        (*dev->comin)(buf);
675 >        (*dev->comin)(buf, NULL);
676   }
677  
678  
# Line 655 | Line 680 | writepict(s)                           /* write the picture to a file */
680   char  *s;
681   {
682          static char  buf[128];
683 <        char  *fname, *getpath();
683 >        char  *fname;
684          FILE  *fp;
685          COLR  *scanline;
686          int  y;
687  
688 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
688 >        while (isspace(*s))
689 >                s++;
690 >        if (*s)
691 >                atos(buf, sizeof(buf), s);
692 >        else if (buf[0] == '\0') {
693                  error(COMMAND, "no file");
694                  return;
695          }
696 <        if ((fname = getpath(buf, NULL)) == NULL ||
696 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
697                          (fp = fopen(fname, "w")) == NULL) {
698                  sprintf(errmsg, "cannot open \"%s\"", buf);
699                  error(COMMAND, errmsg);
700                  return;
701          }
702 + #ifdef MSDOS
703 +        setmode(fileno(fp), O_BINARY);
704 + #endif
705          (*dev->comout)("writing \"");
706          (*dev->comout)(fname);
707          (*dev->comout)("\"...\n");
708                                                  /* write header */
709 +        newheader("RADIANCE", fp);
710          fputs(progname, fp);
711          fprintview(&ourview, fp);
712 <        fputs("\n", fp);
712 >        if (octname != NULL)
713 >                fprintf(fp, " %s\n", octname);
714 >        else
715 >                putc('\n', fp);
716 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
717          if (exposure != 1.0)
718 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
719 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
718 >                fputexpos(exposure, fp);
719 >        if (dev->pixaspect != 1.0)
720 >                fputaspect(dev->pixaspect, fp);
721 >        fputformat(COLRFMT, fp);
722 >        putc('\n', fp);
723 >        fprtresolu(hresolu, vresolu, fp);
724  
725 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
726 <        if (scanline == NULL)
727 <                error(SYSTEM, "out of memory in writepict");
728 <        for (y = ourview.vresolu-1; y >= 0; y--) {
729 <                getpictcolrs(y, scanline, &ptrunk,
730 <                                ourview.hresolu, ourview.vresolu);
731 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
725 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
726 >        if (scanline == NULL) {
727 >                error(COMMAND, "not enough memory!");
728 >                fclose(fp);
729 >                unlink(fname);
730 >                return;
731 >        }
732 >        for (y = vresolu-1; y >= 0; y--) {
733 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
734 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
735                          break;
736          }
737 +        free((char *)scanline);
738          if (fclose(fp) < 0)
739                  error(COMMAND, "write error");
695        free((char *)scanline);
740   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines