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.4 by greg, Tue May 30 09:57:13 1989 UTC vs.
Revision 2.19 by greg, Thu Aug 26 11:24:04 1993 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines