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.5 by greg, Wed Jun 7 08:35:26 1989 UTC vs.
Revision 2.22 by greg, Wed Dec 15 16:59:14 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 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;
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 87 | 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 103 | 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 156 | Line 159 | lastview(s)                            /* return to a previous view */
159   char  *s;
160   {
161          char  buf[128];
162 <        char  *fname, *getpath();
162 >        char  *fname;
163          int  success;
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)) == 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 174 | 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;
190 int  direc;
191 FVECT  vec;
192 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;
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 <                        }
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   {
238        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;
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 <        }
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 272 | Line 298 | char  *s;
298   getrotate(s)                            /* rotate camera */
299   char  *s;
300   {
275        extern double  normalize(), tan(), atan();
301          VIEW  nv;
302          FVECT  v1;
303          double  angle, elev, zfact;
# Line 282 | 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;
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 <        }
320 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
321 >        zoomview(&nv, zfact);
322          newview(&nv);
323   }
324  
# Line 324 | Line 343 | register char  *s;
343   getexposure(s)                          /* get new exposure */
344   char  *s;
345   {
327        double  atof(), pow(), fabs();
346          char  buf[128];
347          register char  *cp;
330        register PNODE  *p;
348          RECT  r;
349          int  x, y;
350 <        double  e;
351 <
350 >        register PNODE  *p = &ptrunk;
351 >        int  adapt = 0;
352 >        double  e = 1.0;
353 > start:
354          for (cp = s; isspace(*cp); cp++)
355                  ;
356 +        if (*cp == '@') {
357 +                adapt++;
358 +                goto start;
359 +        }
360          if (*cp == '\0') {              /* normalize to point */
361                  if (dev->getcur == NULL)
362                          return;
# Line 341 | Line 364 | char  *s;
364                  if ((*dev->getcur)(&x, &y) == ABORT)
365                          return;
366                  r.l = r.d = 0;
367 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
367 >                r.r = hresolu; r.u = vresolu;
368                  p = findrect(x, y, &ptrunk, &r, -1);
346                e = 1.0;
369          } else {
370                  if (*cp == '=') {       /* absolute setting */
371                          p = NULL;
# Line 351 | Line 373 | char  *s;
373                          for (cp++; isspace(*cp); cp++)
374                                  ;
375                          if (*cp == '\0') {      /* interactive */
376 <                                sprintf(buf, "exposure (%lf): ", exposure);
376 >                                sprintf(buf, "exposure (%f): ", exposure);
377                                  (*dev->comout)(buf);
378 <                                (*dev->comin)(buf);
378 >                                (*dev->comin)(buf, NULL);
379                                  for (cp = buf; isspace(*cp); cp++)
380                                          ;
381                                  if (*cp == '\0')
382                                          return;
383                          }
362                } else {                /* normalize to average */
363                        p = &ptrunk;
364                        e = 1.0;
384                  }
385                  if (*cp == '+' || *cp == '-')   /* f-stops */
386                          e *= pow(2.0, atof(cp));
# Line 369 | Line 388 | char  *s;
388                          e *= atof(cp);
389          }
390          if (p != NULL) {                /* relative setting */
391 <                if (intens(p->v) <= FTINY) {
391 >                if (bright(p->v) < 1e-15) {
392                          error(COMMAND, "cannot normalize to zero");
393                          return;
394                  }
395 <                e *= 0.5 / intens(p->v);
395 >                if (adapt)
396 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
397 >                else
398 >                        e *= 0.5 / bright(p->v);
399          }
400          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
401                  return;
# Line 383 | Line 405 | char  *s;
405   }
406  
407  
408 + getparam(str, dsc, typ, ptr)            /* get variable from user */
409 + char  *str, *dsc;
410 + int  typ;
411 + register union {int i; double d; COLOR C;}  *ptr;
412 + {
413 +        extern char  *index();
414 +        int  i0;
415 +        double  d0, d1, d2;
416 +        char  buf[48];
417 +
418 +        switch (typ) {
419 +        case 'i':                       /* integer */
420 +                if (sscanf(str, "%d", &i0) != 1) {
421 +                        (*dev->comout)(dsc);
422 +                        sprintf(buf, " (%d): ", ptr->i);
423 +                        (*dev->comout)(buf);
424 +                        (*dev->comin)(buf, NULL);
425 +                        if (sscanf(buf, "%d", &i0) != 1)
426 +                                return(0);
427 +                }
428 +                ptr->i = i0;
429 +                return(1);
430 +        case 'r':                       /* real */
431 +                if (sscanf(str, "%lf", &d0) != 1) {
432 +                        (*dev->comout)(dsc);
433 +                        sprintf(buf, " (%.6g): ", ptr->d);
434 +                        (*dev->comout)(buf);
435 +                        (*dev->comin)(buf, NULL);
436 +                        if (sscanf(buf, "%lf", &d0) != 1)
437 +                                return(0);
438 +                }
439 +                ptr->d = d0;
440 +                return(1);
441 +        case 'b':                       /* boolean */
442 +                if (sscanf(str, "%1s", buf) != 1) {
443 +                        (*dev->comout)(dsc);
444 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
445 +                        (*dev->comout)(buf);
446 +                        (*dev->comin)(buf, NULL);
447 +                        if (buf[0] == '\0' ||
448 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
449 +                                return(0);
450 +                }
451 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
452 +                return(1);
453 +        case 'C':                       /* color */
454 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
455 +                        (*dev->comout)(dsc);
456 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
457 +                                        colval(ptr->C,RED),
458 +                                        colval(ptr->C,GRN),
459 +                                        colval(ptr->C,BLU));
460 +                        (*dev->comout)(buf);
461 +                        (*dev->comin)(buf, NULL);
462 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
463 +                                return(0);
464 +                }
465 +                setcolor(ptr->C, d0, d1, d2);
466 +                return(1);
467 +        }
468 + }
469 +
470 +
471   setparam(s)                             /* get/set program parameter */
472   register char  *s;
473   {
# Line 392 | Line 477 | register char  *s;
477          extern int  maxdepth;
478          extern double  dstrsrc;
479          extern double  shadthresh;
480 +        extern double  shadcert;
481          extern COLOR  ambval;
482          extern double  ambacc;
397        extern double  minarad;
483          extern int  ambres;
484          extern int  ambdiv;
485          extern int  ambssamp;
486          extern int  ambounce;
487 <        int  i0;
488 <        double  d0, d1, d2;
487 >        extern int  directvis;
488 >        extern double  srcsizerat;
489 >        extern int  do_irrad;
490 >        extern double  specjitter;
491 >        extern double  specthresh;
492          char  buf[128];
493          
494          if (s[0] == '\0') {
495 <                (*dev->comout)("aa ab ad ar as av dj dt lr lw sd sp: ");
496 <                (*dev->comin)(buf);
495 >                (*dev->comout)(
496 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
497 >                (*dev->comin)(buf, NULL);
498                  s = buf;
499          }
500          switch (s[0]) {
501          case 'l':                       /* limit */
502                  switch (s[1]) {
503                  case 'w':                       /* weight */
504 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
416 <                                sprintf(buf, "limit weight (%.6g): ",
417 <                                                minweight);
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf", &d0) != 1)
421 <                                        break;
422 <                        }
423 <                        minweight = d0;
504 >                        getparam(s+2, "limit weight", 'r', &minweight);
505                          break;
506                  case 'r':                       /* reflection */
507 <                        if (sscanf(s+2, "%d", &i0) != 1) {
427 <                                sprintf(buf, "limit reflection (%d): ",
428 <                                                maxdepth);
429 <                                (*dev->comout)(buf);
430 <                                (*dev->comin)(buf);
431 <                                if (sscanf(buf, "%d", &i0) != 1)
432 <                                        break;
433 <                        }
434 <                        maxdepth = i0;
507 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
508                          break;
509                  default:
510                          goto badparam;
# Line 440 | Line 513 | register char  *s;
513          case 'd':                       /* direct */
514                  switch (s[1]) {
515                  case 'j':                       /* jitter */
516 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
444 <                                sprintf(buf, "direct jitter (%.6g): ",
445 <                                                dstrsrc);
446 <                                (*dev->comout)(buf);
447 <                                (*dev->comin)(buf);
448 <                                if (sscanf(buf, "%lf", &d0) != 1)
449 <                                        break;
450 <                        }
451 <                        dstrsrc = d0;
516 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
517                          break;
518 +                case 'c':                       /* certainty */
519 +                        getparam(s+2, "direct certainty", 'r', &shadcert);
520 +                        break;
521                  case 't':                       /* threshold */
522 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
455 <                                sprintf(buf, "direct threshold (%.6g): ",
456 <                                                shadthresh);
457 <                                (*dev->comout)(buf);
458 <                                (*dev->comin)(buf);
459 <                                if (sscanf(buf, "%lf", &d0) != 1)
460 <                                        break;
461 <                        }
462 <                        shadthresh = d0;
522 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
523                          break;
524 +                case 'v':                       /* visibility */
525 +                        getparam(s+2, "direct visibility",
526 +                                        'b', &directvis);
527 +                        break;
528 +                case 's':                       /* sampling */
529 +                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
530 +                        break;
531                  default:
532                          goto badparam;
533                  }
534                  break;
535 +        case 'b':                       /* black and white */
536 +                getparam(s+1, "black and white", 'b', &greyscale);
537 +                break;
538 +        case 'i':                       /* irradiance */
539 +                getparam(s+1, "irradiance", 'b', &do_irrad);
540 +                break;
541          case 'a':                       /* ambient */
542                  switch (s[1]) {
543                  case 'v':                       /* value */
544 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
472 <                                sprintf(buf,
473 <                                        "ambient value (%.6g %.6g %.6g): ",
474 <                                                colval(ambval,RED),
475 <                                                colval(ambval,GRN),
476 <                                                colval(ambval,BLU));
477 <                                (*dev->comout)(buf);
478 <                                (*dev->comin)(buf);
479 <                                if (sscanf(buf, "%lf %lf %lf",
480 <                                                &d0, &d1, &d2) != 3)
481 <                                        break;
482 <                        }
483 <                        setcolor(ambval, d0, d1, d2);
544 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
545                          break;
546                  case 'a':                       /* accuracy */
547 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
548 <                                sprintf(buf, "ambient accuracy (%.6g): ",
488 <                                                ambacc);
489 <                                (*dev->comout)(buf);
490 <                                (*dev->comin)(buf);
491 <                                if (sscanf(buf, "%lf", &d0) != 1)
492 <                                        break;
493 <                        }
494 <                        ambacc = d0;
547 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
548 >                                setambacc(ambacc);
549                          break;
550                  case 'd':                       /* divisions */
551 <                        if (sscanf(s+2, "%d", &i0) != 1) {
498 <                                sprintf(buf, "ambient divisions (%d): ",
499 <                                                ambdiv);
500 <                                (*dev->comout)(buf);
501 <                                (*dev->comin)(buf);
502 <                                if (sscanf(buf, "%d", &i0) != 1)
503 <                                        break;
504 <                        }
505 <                        ambdiv = i0;
551 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
552                          break;
553                  case 's':                       /* samples */
554 <                        if (sscanf(s+2, "%d", &i0) != 1) {
509 <                                sprintf(buf, "ambient super-samples (%d): ",
510 <                                                ambssamp);
511 <                                (*dev->comout)(buf);
512 <                                (*dev->comin)(buf);
513 <                                if (sscanf(buf, "%d", &i0) != 1)
514 <                                        break;
515 <                        }
516 <                        ambssamp = i0;
554 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
555                          break;
556                  case 'b':                       /* bounces */
557 <                        if (sscanf(s+2, "%d", &i0) != 1) {
520 <                                sprintf(buf, "ambient bounces (%d): ",
521 <                                                ambounce);
522 <                                (*dev->comout)(buf);
523 <                                (*dev->comin)(buf);
524 <                                if (sscanf(buf, "%d", &i0) != 1)
525 <                                        break;
526 <                        }
527 <                        ambounce = i0;
557 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
558                          break;
559                  case 'r':
560 <                        if (sscanf(s+2, "%d", &i0) != 1) {
561 <                                sprintf(buf, "ambient resolution (%d): ",
532 <                                                ambres);
533 <                                (*dev->comout)(buf);
534 <                                (*dev->comin)(buf);
535 <                                if (sscanf(buf, "%d", &i0) != 1)
536 <                                        break;
537 <                        }
538 <                        ambres = i0;
539 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
560 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
561 >                                setambres(ambres);
562                          break;
563                  default:
564                          goto badparam;
565                  }
566                  break;
567 <        case 's':                       /* sample */
567 >        case 'p':                       /* pixel */
568                  switch (s[1]) {
569 <                case 'p':                       /* pixel */
570 <                        if (sscanf(s+2, "%d", &i0) != 1) {
571 <                                sprintf(buf, "sample pixel (%d): ", psample);
550 <                                (*dev->comout)(buf);
551 <                                (*dev->comin)(buf);
552 <                                if (sscanf(buf, "%d", &i0) != 1)
553 <                                        break;
554 <                        }
555 <                        psample = i0;
556 <                        pdepth = 0;
569 >                case 's':                       /* sample */
570 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
571 >                                pdepth = 0;
572                          break;
573 <                case 'd':                       /* difference */
574 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
575 <                                sprintf(buf, "sample difference (%.6g): ",
561 <                                                maxdiff);
562 <                                (*dev->comout)(buf);
563 <                                (*dev->comin)(buf);
564 <                                if (sscanf(buf, "%lf", &d0) != 1)
565 <                                        break;
566 <                        }
567 <                        maxdiff = d0;
568 <                        pdepth = 0;
573 >                case 't':                       /* threshold */
574 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
575 >                                pdepth = 0;
576                          break;
577                  default:
578                          goto badparam;
579                  }
580                  break;
581 +        case 's':                       /* specular */
582 +                switch (s[1]) {
583 +                case 'j':                       /* jitter */
584 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
585 +                        break;
586 +                case 't':                       /* threshold */
587 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
588 +                        break;
589 +                default:
590 +                        goto badparam;
591 +                }
592 +                break;
593          case '\0':                      /* nothing */
594                  break;
595          default:;
596   badparam:
597 +                *sskip(s) = '\0';
598                  sprintf(errmsg, "%s: unknown variable", s);
599                  error(COMMAND, errmsg);
600                  break;
# Line 589 | Line 609 | char  *s;
609          int  x, y;
610          RAY  thisray;
611  
612 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
613 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
594 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
612 >        if (!sscanvec(s, thisray.rorg) ||
613 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
614  
615                  if (dev->getcur == NULL)
616                          return;
# Line 599 | Line 618 | char  *s;
618                  if ((*dev->getcur)(&x, &y) == ABORT)
619                          return;
620  
621 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
622 <                
621 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
622 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
623 >                        error(COMMAND, "not on image");
624 >                        return;
625 >                }
626 >
627          } else if (normalize(thisray.rdir) == 0.0) {
628                  error(COMMAND, "zero ray direction");
629                  return;
# Line 614 | Line 637 | char  *s;
637                  (*dev->comout)("ray hit nothing");
638          else {
639                  sprintf(buf, "ray hit %s %s \"%s\"",
640 <                                objptr(thisray.ro->omod)->oname,
640 >                                thisray.ro->omod == OVOID ? VOIDID :
641 >                                        objptr(thisray.ro->omod)->oname,
642                                  ofun[thisray.ro->otype].funame,
643                                  thisray.ro->oname);
644                  (*dev->comout)(buf);
645 <                (*dev->comin)(buf);
645 >                (*dev->comin)(buf, NULL);
646                  if (thisray.rot >= FHUGE)
647                          (*dev->comout)("at infinity");
648                  else {
# Line 626 | Line 650 | char  *s;
650                                          thisray.rop[1], thisray.rop[2]);
651                          (*dev->comout)(buf);
652                  }
653 <                (*dev->comin)(buf);
654 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
653 >                (*dev->comin)(buf, NULL);
654 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
655                                  colval(thisray.rcol,RED),
656                                  colval(thisray.rcol,GRN),
657 <                                colval(thisray.rcol,BLU));
657 >                                colval(thisray.rcol,BLU),
658 >                                luminance(thisray.rcol));
659                  (*dev->comout)(buf);
660          }
661 <        (*dev->comin)(buf);
661 >        (*dev->comin)(buf, NULL);
662   }
663  
664  
# Line 641 | Line 666 | writepict(s)                           /* write the picture to a file */
666   char  *s;
667   {
668          static char  buf[128];
669 <        char  *fname, *getpath();
669 >        char  *fname;
670          FILE  *fp;
671          COLR  *scanline;
672          int  y;
673  
674 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
674 >        while (isspace(*s))
675 >                s++;
676 >        if (*s)
677 >                atos(buf, sizeof(buf), s);
678 >        else if (buf[0] == '\0') {
679                  error(COMMAND, "no file");
680                  return;
681          }
682 <        if ((fname = getpath(buf, NULL)) == NULL ||
682 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
683                          (fp = fopen(fname, "w")) == NULL) {
684                  sprintf(errmsg, "cannot open \"%s\"", buf);
685                  error(COMMAND, errmsg);
686                  return;
687          }
688 + #ifdef MSDOS
689 +        setmode(fileno(fp), O_BINARY);
690 + #endif
691          (*dev->comout)("writing \"");
692          (*dev->comout)(fname);
693          (*dev->comout)("\"...\n");
694                                                  /* write header */
695          fputs(progname, fp);
696          fprintview(&ourview, fp);
697 <        fputs("\n", fp);
697 >        if (octname != NULL)
698 >                fprintf(fp, " %s\n", octname);
699 >        else
700 >                putc('\n', fp);
701 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
702          if (exposure != 1.0)
703 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
704 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
703 >                fputexpos(exposure, fp);
704 >        if (dev->pixaspect != 1.0)
705 >                fputaspect(dev->pixaspect, fp);
706 >        fputformat(COLRFMT, fp);
707 >        putc('\n', fp);
708 >        fprtresolu(hresolu, vresolu, fp);
709  
710 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
711 <        if (scanline == NULL)
712 <                error(SYSTEM, "out of memory in writepict");
713 <        for (y = ourview.vresolu-1; y >= 0; y--) {
714 <                getpictcolrs(y, scanline, &ptrunk,
715 <                                ourview.hresolu, ourview.vresolu);
716 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
710 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
711 >        if (scanline == NULL) {
712 >                error(COMMAND, "not enough memory!");
713 >                fclose(fp);
714 >                unlink(fname);
715 >                return;
716 >        }
717 >        for (y = vresolu-1; y >= 0; y--) {
718 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
719 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
720                          break;
721          }
722 +        free((char *)scanline);
723          if (fclose(fp) < 0)
724                  error(COMMAND, "write error");
681        free((char *)scanline);
725   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines