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.2 by greg, Fri Feb 3 07:58:07 1989 UTC vs.
Revision 2.20 by greg, Thu Sep 9 13:47:55 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[128];              /* 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 86 | 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;
99 <        if (buf[0])
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 <        else
101 >                change++;
102 >        } else
103                  nv.type = ourview.type;
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;
136 <        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) {
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) {
147 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
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.hoff = ourview.hoff; nv.voff = ourview.voff;
150          }
151 <        newview(&nv);
151 >        if (change)
152 >                newview(&nv);
153   }
154  
155  
# Line 143 | 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 161 | 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;
177 int  direc;
178 FVECT  vec;
179 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;
189 <        else if (*mp <= FTINY) {        /* too small */
190 <                error(COMMAND, "illegal magnification");
191 <                return(-1);
192 <        }
193 <        if (sscanf(s, "%*lf %lf %lf %lf", &vec[0], &vec[1], &vec[2]) != 3) {
194 <                if (dev->getcur == NULL)
195 <                        return(-1);
196 <                (*dev->comout)("Pick view center\n");
197 <                if ((*dev->getcur)(&x, &y) == ABORT)
198 <                        return(-1);
199 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
200 <                if (!direc || ourview.type == VT_PAR) {
201 <                        rayorigin(&thisray, NULL, PRIMARY, 1.0);
202 <                        if (!localhit(&thisray, &thescene)) {
203 <                                error(COMMAND, "not a local object");
204 <                                return(-1);
205 <                        }
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 >        while (isspace(*s))
204 >                s++;
205 >        if (*s)
206 >                atos(rifname, sizeof(rifname), s);
207 >        else if (rifname[0] == '\0') {
208 >                error(COMMAND, "no previous rad file");
209 >                return;
210 >        }
211 >        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
212 >                        (fp = fopen(fname, "a")) == NULL) {
213 >                sprintf(errmsg, "cannot open \"%s\"", rifname);
214 >                error(COMMAND, errmsg);
215 >                return;
216 >        }
217 >        fputs("view= ", fp);
218 >        fputs(view, fp);
219 >        fprintview(&ourview, fp);
220 >        putc('\n', fp);
221 >        fclose(fp);
222   }
223  
224  
225 + loadview(s)                             /* load view from rad file */
226 + char  *s;
227 + {
228 +        char  buf[512];
229 +        char  *fname;
230 +        FILE  *fp;
231 +        VIEW  nv;
232 +
233 +        strcpy(buf, "rad -n -s -V -v ");
234 +        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
235 +                s = sskip(s);
236 +        else
237 +                strcat(buf, "1");
238 +        if (*s)
239 +                atos(rifname, sizeof(rifname), s);
240 +        else if (rifname[0] == '\0') {
241 +                error(COMMAND, "no previous rad file");
242 +                return;
243 +        }
244 +        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
245 +                sprintf(errmsg, "cannot access \"%s\"", rifname);
246 +                error(COMMAND, errmsg);
247 +                return;
248 +        }
249 +        sprintf(buf+strlen(buf), " %s", fname);
250 +        if ((fp = popen(buf, "r")) == NULL) {
251 +                error(COMMAND, "cannot run rad");
252 +                return;
253 +        }
254 +        buf[0] = '\0';
255 +        fgets(buf, sizeof(buf), fp);
256 +        pclose(fp);
257 +        copystruct(&nv, &stdview);
258 +        if (!sscanview(&nv, buf)) {
259 +                error(COMMAND, "rad error -- no such view?");
260 +                return;
261 +        }
262 +        newview(&nv);
263 + }
264 +
265 +
266   getaim(s)                               /* aim camera */
267   char  *s;
268   {
225        extern double  tan(), atan();
269          double  zfact;
270          VIEW  nv;
271  
272          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
273                  return;
274 +        nv.type = ourview.type;
275          VCOPY(nv.vp, ourview.vp);
276          VCOPY(nv.vup, ourview.vup);
277 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
278 <        if ((nv.type = ourview.type) == VT_PAR) {
279 <                nv.horiz = ourview.horiz / zfact;
236 <                nv.vert = ourview.vert / zfact;
237 <        } else {
238 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
239 <                                (PI/180./2.);
240 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
241 <                                (PI/180./2.);
242 <        }
277 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
278 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
279 >        zoomview(&nv, zfact);
280          newview(&nv);
281   }
282  
# Line 252 | Line 289 | char  *s;
289  
290          if (getinterest(s, 0, vc, &mag) < 0)
291                  return;
292 <        moveview(0.0, mag, vc);
292 >        moveview(0.0, 0.0, mag, vc);
293   }
294  
295  
296   getrotate(s)                            /* rotate camera */
297   char  *s;
298   {
262        extern double  normalize();
299          VIEW  nv;
300          FVECT  v1;
301 <        double  angle, elev;
301 >        double  angle, elev, zfact;
302          
303 <        elev = 0.0;
304 <        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
303 >        elev = 0.0; zfact = 1.0;
304 >        if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) {
305                  error(COMMAND, "missing angle");
306                  return;
307          }
308          nv.type = ourview.type;
309          VCOPY(nv.vp, ourview.vp);
310          VCOPY(nv.vup, ourview.vup);
311 <        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
276 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
311 >        nv.hoff = ourview.hoff; nv.voff = ourview.voff;
312          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
313          if (elev != 0.0) {
314                  fcross(v1, nv.vdir, ourview.vup);
315                  normalize(v1);
316                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
317          }
318 +        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
319 +        zoomview(&nv, zfact);
320          newview(&nv);
321   }
322  
# Line 288 | Line 325 | getpivot(s)                            /* pivot viewpoint */
325   register char  *s;
326   {
327          FVECT  vc;
328 <        double  angle, mag;
328 >        double  angle, elev, mag;
329  
330 <        if (sscanf(s, "%lf", &angle) != 1) {
330 >        elev = 0.0;
331 >        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
332                  error(COMMAND, "missing angle");
333                  return;
334          }
335 <        if (getinterest(sskip(s), 0, vc, &mag) < 0)
335 >        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
336                  return;
337 <        moveview(angle, mag, vc);
337 >        moveview(angle, elev, mag, vc);
338   }
339  
340  
341   getexposure(s)                          /* get new exposure */
342   char  *s;
343   {
306        double  atof(), pow(), fabs();
344          char  buf[128];
345          register char  *cp;
309        register PNODE  *p;
346          RECT  r;
347          int  x, y;
348 <        double  e;
349 <
348 >        register PNODE  *p = &ptrunk;
349 >        int  adapt = 0;
350 >        double  e = 1.0;
351 > start:
352          for (cp = s; isspace(*cp); cp++)
353                  ;
354 +        if (*cp == '@') {
355 +                adapt++;
356 +                goto start;
357 +        }
358          if (*cp == '\0') {              /* normalize to point */
359                  if (dev->getcur == NULL)
360                          return;
# Line 320 | Line 362 | char  *s;
362                  if ((*dev->getcur)(&x, &y) == ABORT)
363                          return;
364                  r.l = r.d = 0;
365 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
365 >                r.r = hresolu; r.u = vresolu;
366                  p = findrect(x, y, &ptrunk, &r, -1);
325                e = 1.0;
367          } else {
368                  if (*cp == '=') {       /* absolute setting */
369                          p = NULL;
# Line 330 | Line 371 | char  *s;
371                          for (cp++; isspace(*cp); cp++)
372                                  ;
373                          if (*cp == '\0') {      /* interactive */
374 <                                sprintf(buf, "exposure (%lf): ", exposure);
374 >                                sprintf(buf, "exposure (%f): ", exposure);
375                                  (*dev->comout)(buf);
376 <                                (*dev->comin)(buf);
376 >                                (*dev->comin)(buf, NULL);
377                                  for (cp = buf; isspace(*cp); cp++)
378                                          ;
379                                  if (*cp == '\0')
380                                          return;
381                          }
341                } else {                /* normalize to average */
342                        p = &ptrunk;
343                        e = 1.0;
382                  }
383                  if (*cp == '+' || *cp == '-')   /* f-stops */
384                          e *= pow(2.0, atof(cp));
# Line 348 | Line 386 | char  *s;
386                          e *= atof(cp);
387          }
388          if (p != NULL) {                /* relative setting */
389 <                if (intens(p->v) <= FTINY) {
389 >                if (bright(p->v) < 1e-15) {
390                          error(COMMAND, "cannot normalize to zero");
391                          return;
392                  }
393 <                e *= 0.5 / intens(p->v);
393 >                if (adapt)
394 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
395 >                else
396 >                        e *= 0.5 / bright(p->v);
397          }
398          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
399                  return;
# Line 362 | Line 403 | char  *s;
403   }
404  
405  
406 + getparam(str, dsc, typ, ptr)            /* get variable from user */
407 + char  *str, *dsc;
408 + int  typ;
409 + register union {int i; double d; COLOR C;}  *ptr;
410 + {
411 +        extern char  *index();
412 +        int  i0;
413 +        double  d0, d1, d2;
414 +        char  buf[48];
415 +
416 +        switch (typ) {
417 +        case 'i':                       /* integer */
418 +                if (sscanf(str, "%d", &i0) != 1) {
419 +                        (*dev->comout)(dsc);
420 +                        sprintf(buf, " (%d): ", ptr->i);
421 +                        (*dev->comout)(buf);
422 +                        (*dev->comin)(buf, NULL);
423 +                        if (sscanf(buf, "%d", &i0) != 1)
424 +                                return(0);
425 +                }
426 +                ptr->i = i0;
427 +                return(1);
428 +        case 'r':                       /* real */
429 +                if (sscanf(str, "%lf", &d0) != 1) {
430 +                        (*dev->comout)(dsc);
431 +                        sprintf(buf, " (%.6g): ", ptr->d);
432 +                        (*dev->comout)(buf);
433 +                        (*dev->comin)(buf, NULL);
434 +                        if (sscanf(buf, "%lf", &d0) != 1)
435 +                                return(0);
436 +                }
437 +                ptr->d = d0;
438 +                return(1);
439 +        case 'b':                       /* boolean */
440 +                if (sscanf(str, "%1s", buf) != 1) {
441 +                        (*dev->comout)(dsc);
442 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
443 +                        (*dev->comout)(buf);
444 +                        (*dev->comin)(buf, NULL);
445 +                        if (buf[0] == '\0' ||
446 +                                        index("yY+1tTnN-0fF", buf[0]) == NULL)
447 +                                return(0);
448 +                }
449 +                ptr->i = index("yY+1tT", buf[0]) != NULL;
450 +                return(1);
451 +        case 'C':                       /* color */
452 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
453 +                        (*dev->comout)(dsc);
454 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
455 +                                        colval(ptr->C,RED),
456 +                                        colval(ptr->C,GRN),
457 +                                        colval(ptr->C,BLU));
458 +                        (*dev->comout)(buf);
459 +                        (*dev->comin)(buf, NULL);
460 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
461 +                                return(0);
462 +                }
463 +                setcolor(ptr->C, d0, d1, d2);
464 +                return(1);
465 +        }
466 + }
467 +
468 +
469   setparam(s)                             /* get/set program parameter */
470   register char  *s;
471   {
# Line 370 | Line 474 | register char  *s;
474          extern double  minweight;
475          extern int  maxdepth;
476          extern double  dstrsrc;
477 +        extern double  shadthresh;
478 +        extern double  shadcert;
479          extern COLOR  ambval;
480          extern double  ambacc;
375        extern double  minarad;
481          extern int  ambres;
482          extern int  ambdiv;
483          extern int  ambssamp;
484          extern int  ambounce;
485 <        int  i0;
486 <        double  d0, d1, d2;
485 >        extern int  directvis;
486 >        extern double  srcsizerat;
487 >        extern int  do_irrad;
488 >        extern double  specjitter;
489 >        extern double  specthresh;
490          char  buf[128];
491          
492          if (s[0] == '\0') {
493 <                (*dev->comout)("aa ab ad ar as av ds lr lw sd sp: ");
494 <                (*dev->comin)(buf);
493 >                (*dev->comout)(
494 >                "aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: ");
495 >                (*dev->comin)(buf, NULL);
496                  s = buf;
497          }
498          switch (s[0]) {
499          case 'l':                       /* limit */
500                  switch (s[1]) {
501                  case 'w':                       /* weight */
502 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
394 <                                sprintf(buf, "limit weight (%.6g): ",
395 <                                                minweight);
396 <                                (*dev->comout)(buf);
397 <                                (*dev->comin)(buf);
398 <                                if (sscanf(buf, "%lf", &d0) != 1)
399 <                                        break;
400 <                        }
401 <                        minweight = d0;
502 >                        getparam(s+2, "limit weight", 'r', &minweight);
503                          break;
504                  case 'r':                       /* reflection */
505 <                        if (sscanf(s+2, "%d", &i0) != 1) {
405 <                                sprintf(buf, "limit reflection (%d): ",
406 <                                                maxdepth);
407 <                                (*dev->comout)(buf);
408 <                                (*dev->comin)(buf);
409 <                                if (sscanf(buf, "%d", &i0) != 1)
410 <                                        break;
411 <                        }
412 <                        maxdepth = i0;
505 >                        getparam(s+2, "limit reflection", 'i', &maxdepth);
506                          break;
507                  default:
508                          goto badparam;
509                  }
510                  break;
511 <        case 'd':                       /* distribute source */
512 <                if (s[1] != 's')
511 >        case 'd':                       /* direct */
512 >                switch (s[1]) {
513 >                case 'j':                       /* jitter */
514 >                        getparam(s+2, "direct jitter", 'r', &dstrsrc);
515 >                        break;
516 >                case 'c':                       /* certainty */
517 >                        getparam(s+2, "direct certainty", 'r', &shadcert);
518 >                        break;
519 >                case 't':                       /* threshold */
520 >                        getparam(s+2, "direct threshold", 'r', &shadthresh);
521 >                        break;
522 >                case 'v':                       /* visibility */
523 >                        getparam(s+2, "direct visibility",
524 >                                        'b', &directvis);
525 >                        break;
526 >                case 's':                       /* sampling */
527 >                        getparam(s+2, "direct sampling", 'r', &srcsizerat);
528 >                        break;
529 >                default:
530                          goto badparam;
421                if (sscanf(s+2, "%lf", &d0) != 1) {
422                        sprintf(buf, "distribute source (%.6g): ", dstrsrc);
423                        (*dev->comout)(buf);
424                        (*dev->comin)(buf);
425                        if (sscanf(buf, "%lf", &d0) != 1)
426                                break;
531                  }
428                dstrsrc = d0;
532                  break;
533 +        case 'b':                       /* black and white */
534 +                getparam(s+1, "black and white", 'b', &greyscale);
535 +                break;
536 +        case 'i':                       /* irradiance */
537 +                getparam(s+1, "irradiance", 'b', &do_irrad);
538 +                break;
539          case 'a':                       /* ambient */
540                  switch (s[1]) {
541                  case 'v':                       /* value */
542 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
434 <                                sprintf(buf,
435 <                                        "ambient value (%.6g %.6g %.6g): ",
436 <                                                colval(ambval,RED),
437 <                                                colval(ambval,GRN),
438 <                                                colval(ambval,BLU));
439 <                                (*dev->comout)(buf);
440 <                                (*dev->comin)(buf);
441 <                                if (sscanf(buf, "%lf %lf %lf",
442 <                                                &d0, &d1, &d2) != 3)
443 <                                        break;
444 <                        }
445 <                        setcolor(ambval, d0, d1, d2);
542 >                        getparam(s+2, "ambient value", 'C', (COLOR *)ambval);
543                          break;
544                  case 'a':                       /* accuracy */
545 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
546 <                                sprintf(buf, "ambient accuracy (%.6g): ",
450 <                                                ambacc);
451 <                                (*dev->comout)(buf);
452 <                                (*dev->comin)(buf);
453 <                                if (sscanf(buf, "%lf", &d0) != 1)
454 <                                        break;
455 <                        }
456 <                        ambacc = d0;
545 >                        if (getparam(s+2, "ambient accuracy", 'r', &ambacc))
546 >                                setambacc(ambacc);
547                          break;
548                  case 'd':                       /* divisions */
549 <                        if (sscanf(s+2, "%d", &i0) != 1) {
460 <                                sprintf(buf, "ambient divisions (%d): ",
461 <                                                ambdiv);
462 <                                (*dev->comout)(buf);
463 <                                (*dev->comin)(buf);
464 <                                if (sscanf(buf, "%d", &i0) != 1)
465 <                                        break;
466 <                        }
467 <                        ambdiv = i0;
549 >                        getparam(s+2, "ambient divisions", 'i', &ambdiv);
550                          break;
551                  case 's':                       /* samples */
552 <                        if (sscanf(s+2, "%d", &i0) != 1) {
471 <                                sprintf(buf, "ambient super-samples (%d): ",
472 <                                                ambssamp);
473 <                                (*dev->comout)(buf);
474 <                                (*dev->comin)(buf);
475 <                                if (sscanf(buf, "%d", &i0) != 1)
476 <                                        break;
477 <                        }
478 <                        ambssamp = i0;
552 >                        getparam(s+2, "ambient super-samples", 'i', &ambssamp);
553                          break;
554                  case 'b':                       /* bounces */
555 <                        if (sscanf(s+2, "%d", &i0) != 1) {
482 <                                sprintf(buf, "ambient bounces (%d): ",
483 <                                                ambounce);
484 <                                (*dev->comout)(buf);
485 <                                (*dev->comin)(buf);
486 <                                if (sscanf(buf, "%d", &i0) != 1)
487 <                                        break;
488 <                        }
489 <                        ambounce = i0;
555 >                        getparam(s+2, "ambient bounces", 'i', &ambounce);
556                          break;
557                  case 'r':
558 <                        if (sscanf(s+2, "%d", &i0) != 1) {
559 <                                sprintf(buf, "ambient resolution (%d): ",
494 <                                                ambres);
495 <                                (*dev->comout)(buf);
496 <                                (*dev->comin)(buf);
497 <                                if (sscanf(buf, "%d", &i0) != 1)
498 <                                        break;
499 <                        }
500 <                        ambres = i0;
501 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
558 >                        if (getparam(s+2, "ambient resolution", 'i', &ambres))
559 >                                setambres(ambres);
560                          break;
561                  default:
562                          goto badparam;
563                  }
564                  break;
565 <        case 's':                       /* sample */
565 >        case 'p':                       /* pixel */
566                  switch (s[1]) {
567 <                case 'p':                       /* pixel */
568 <                        if (sscanf(s+2, "%d", &i0) != 1) {
569 <                                sprintf(buf, "sample pixel (%d): ", psample);
512 <                                (*dev->comout)(buf);
513 <                                (*dev->comin)(buf);
514 <                                if (sscanf(buf, "%d", &i0) != 1)
515 <                                        break;
516 <                        }
517 <                        psample = i0;
518 <                        pdepth = 0;
567 >                case 's':                       /* sample */
568 >                        if (getparam(s+2, "pixel sample", 'i', &psample))
569 >                                pdepth = 0;
570                          break;
571 <                case 'd':                       /* difference */
572 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
573 <                                sprintf(buf, "sample difference (%.6g): ",
523 <                                                maxdiff);
524 <                                (*dev->comout)(buf);
525 <                                (*dev->comin)(buf);
526 <                                if (sscanf(buf, "%lf", &d0) != 1)
527 <                                        break;
528 <                        }
529 <                        maxdiff = d0;
530 <                        pdepth = 0;
571 >                case 't':                       /* threshold */
572 >                        if (getparam(s+2, "pixel threshold", 'r', &maxdiff))
573 >                                pdepth = 0;
574                          break;
575                  default:
576                          goto badparam;
577                  }
578                  break;
579 +        case 's':                       /* specular */
580 +                switch (s[1]) {
581 +                case 'j':                       /* jitter */
582 +                        getparam(s+2, "specular jitter", 'r', &specjitter);
583 +                        break;
584 +                case 't':                       /* threshold */
585 +                        getparam(s+2, "specular threshold", 'r', &specthresh);
586 +                        break;
587 +                default:
588 +                        goto badparam;
589 +                }
590 +                break;
591          case '\0':                      /* nothing */
592                  break;
593          default:;
594   badparam:
595 +                *sskip(s) = '\0';
596                  sprintf(errmsg, "%s: unknown variable", s);
597                  error(COMMAND, errmsg);
598                  break;
# Line 551 | Line 607 | char  *s;
607          int  x, y;
608          RAY  thisray;
609  
610 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
611 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
556 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
610 >        if (!sscanvec(s, thisray.rorg) ||
611 >                        !sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) {
612  
613                  if (dev->getcur == NULL)
614                          return;
# Line 561 | Line 616 | char  *s;
616                  if ((*dev->getcur)(&x, &y) == ABORT)
617                          return;
618  
619 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
620 <                
619 >                if (viewray(thisray.rorg, thisray.rdir, &ourview,
620 >                                (x+.5)/hresolu, (y+.5)/vresolu) < 0) {
621 >                        error(COMMAND, "not on image");
622 >                        return;
623 >                }
624 >
625          } else if (normalize(thisray.rdir) == 0.0) {
626                  error(COMMAND, "zero ray direction");
627                  return;
# Line 580 | Line 639 | char  *s;
639                                  ofun[thisray.ro->otype].funame,
640                                  thisray.ro->oname);
641                  (*dev->comout)(buf);
642 <                (*dev->comin)(buf);
642 >                (*dev->comin)(buf, NULL);
643                  if (thisray.rot >= FHUGE)
644                          (*dev->comout)("at infinity");
645                  else {
# Line 588 | Line 647 | char  *s;
647                                          thisray.rop[1], thisray.rop[2]);
648                          (*dev->comout)(buf);
649                  }
650 <                (*dev->comin)(buf);
651 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
650 >                (*dev->comin)(buf, NULL);
651 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)",
652                                  colval(thisray.rcol,RED),
653                                  colval(thisray.rcol,GRN),
654 <                                colval(thisray.rcol,BLU));
654 >                                colval(thisray.rcol,BLU),
655 >                                luminance(thisray.rcol));
656                  (*dev->comout)(buf);
657          }
658 <        (*dev->comin)(buf);
658 >        (*dev->comin)(buf, NULL);
659   }
660  
661  
# Line 603 | Line 663 | writepict(s)                           /* write the picture to a file */
663   char  *s;
664   {
665          static char  buf[128];
666 <        char  *fname, *getpath();
666 >        char  *fname;
667          FILE  *fp;
668          COLR  *scanline;
669          int  y;
670  
671 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
671 >        while (isspace(*s))
672 >                s++;
673 >        if (*s)
674 >                atos(buf, sizeof(buf), s);
675 >        else if (buf[0] == '\0') {
676                  error(COMMAND, "no file");
677                  return;
678          }
679 <        if ((fname = getpath(buf, NULL)) == NULL ||
679 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
680                          (fp = fopen(fname, "w")) == NULL) {
681                  sprintf(errmsg, "cannot open \"%s\"", buf);
682                  error(COMMAND, errmsg);
683                  return;
684          }
685 + #ifdef MSDOS
686 +        setmode(fileno(fp), O_BINARY);
687 + #endif
688          (*dev->comout)("writing \"");
689          (*dev->comout)(fname);
690          (*dev->comout)("\"...\n");
691                                                  /* write header */
692          fputs(progname, fp);
693          fprintview(&ourview, fp);
694 <        fputs("\n", fp);
694 >        if (octname != NULL)
695 >                fprintf(fp, " %s\n", octname);
696 >        else
697 >                putc('\n', fp);
698 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
699          if (exposure != 1.0)
700 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
701 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
700 >                fputexpos(exposure, fp);
701 >        if (dev->pixaspect != 1.0)
702 >                fputaspect(dev->pixaspect, fp);
703 >        fputformat(COLRFMT, fp);
704 >        putc('\n', fp);
705 >        fprtresolu(hresolu, vresolu, fp);
706  
707 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
708 <        if (scanline == NULL)
709 <                error(SYSTEM, "out of memory in writepict");
710 <        for (y = ourview.vresolu-1; y >= 0; y--) {
711 <                getpictcolrs(y, scanline, &ptrunk,
712 <                                ourview.hresolu, ourview.vresolu);
713 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
707 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
708 >        if (scanline == NULL) {
709 >                error(COMMAND, "not enough memory!");
710 >                fclose(fp);
711 >                unlink(fname);
712 >                return;
713 >        }
714 >        for (y = vresolu-1; y >= 0; y--) {
715 >                getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
716 >                if (fwritecolrs(scanline, hresolu, fp) < 0)
717                          break;
718          }
719 +        free((char *)scanline);
720          if (fclose(fp) < 0)
721                  error(COMMAND, "write error");
643        free((char *)scanline);
722   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines