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.14 by greg, Mon Jan 8 13:38:05 1990 UTC vs.
Revision 2.43 by schorsch, Tue Mar 30 16:13:01 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1987 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  rv2.c - command routines used in tracing a view.
6   *
7 < *     3/24/87
7 > *  External symbols declared in rpaint.h
8   */
9  
10 < #include  "ray.h"
10 > #include "copyright.h"
11  
12 < #include  "octree.h"
12 > #include  <ctype.h>
13 > #include  <string.h>
14  
15 + #include  "platform.h"
16 + #include  "ray.h"
17 + #include  "ambient.h"
18   #include  "otypes.h"
18
19   #include  "rpaint.h"
20  
21 < #include  <ctype.h>
21 > extern int  psample;                    /* pixel sample size */
22 > extern double  maxdiff;                 /* max. sample difference */
23  
24 < #define  CTRL(c)        ('c'-'@')
24 > #define  CTRL(c)        ((c)-'@')
25  
26 + #ifdef  SMLFLT
27 + #define  sscanvec(s,v)  (sscanf(s,"%f %f %f",v,v+1,v+2)==3)
28 + #else
29 + #define  sscanvec(s,v)  (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3)
30 + #endif
31 +
32 + extern char  rifname[128];              /* rad input file name */
33 +
34   extern char  *progname;
35 + extern char  *octname;
36  
37  
38 < getframe(s)                             /* get a new frame */
39 < char  *s;
38 > extern void
39 > getframe(                               /* get a new frame */
40 >        char  *s
41 > )
42   {
43          if (getrect(s, &pframe) < 0)
44                  return;
# Line 34 | Line 46 | char  *s;
46   }
47  
48  
49 < getrepaint(s)                           /* get area and repaint */
50 < char  *s;
49 > extern void
50 > getrepaint(                             /* get area and repaint */
51 >        char  *s
52 > )
53   {
54          RECT  box;
55  
# Line 45 | Line 59 | char  *s;
59   }
60  
61  
62 < getview(s)                              /* get/show view parameters */
63 < char  *s;
62 > extern void
63 > getview(                                /* get/show view parameters */
64 >        char  *s
65 > )
66   {
67          FILE  *fp;
68          char  buf[128];
# Line 54 | Line 70 | char  *s;
70          int  change = 0;
71          VIEW  nv;
72  
73 +        while (isspace(*s))
74 +                s++;
75 +        if (*s == '-') {                        /* command line parameters */
76 +                nv = ourview;
77 +                if (sscanview(&nv, s))
78 +                        newview(&nv);
79 +                else
80 +                        error(COMMAND, "bad view option(s)");
81 +                return;
82 +        }
83          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
84                  if ((fname = getpath(buf, NULL, 0)) == NULL ||
85                                  (fp = fopen(fname, "a")) == NULL) {
# Line 63 | 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 79 | 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, "fore and aft clipping plane (%.6g %.6g): ",
144 +                        ourview.vfore, ourview.vaft);
145 +        (*dev->comout)(buf);
146 +        (*dev->comin)(buf, NULL);
147 +        if (buf[0] == CTRL('C')) return;
148 +        if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2)
149 +                change++;
150 +        else {
151 +                nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
152 +        }
153          sprintf(buf, "view shift and lift (%.6g %.6g): ",
154                          ourview.hoff, ourview.voff);
155          (*dev->comout)(buf);
156 <        (*dev->comin)(buf);
157 <        if (buf[0] == CTRL(C)) return;
156 >        (*dev->comin)(buf, NULL);
157 >        if (buf[0] == CTRL('C')) return;
158          if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2)
159                  change++;
160          else {
# Line 128 | Line 165 | char  *s;
165   }
166  
167  
168 < lastview(s)                             /* return to a previous view */
169 < char  *s;
168 > extern void
169 > lastview(                               /* return to a previous view */
170 >        char  *s
171 > )
172   {
173          char  buf[128];
174          char  *fname;
# Line 137 | Line 176 | char  *s;
176          VIEW  nv;
177  
178          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
179 <                copyview(&nv, &stdview);
180 <                if ((fname = getpath(buf, NULL, 0)) == NULL ||
181 <                                (success = viewfile(fname, &nv)) == -1) {
179 >                nv = stdview;
180 >                if ((fname = getpath(buf, "", R_OK)) == NULL ||
181 >                                (success = viewfile(fname, &nv, NULL)) == -1) {
182                          sprintf(errmsg, "cannot open \"%s\"", buf);
183                          error(COMMAND, errmsg);
184                          return;
# Line 150 | Line 189 | char  *s;
189                          newview(&nv);
190                  return;
191          }
192 <        if (oldview.horiz == 0) {       /* no old view! */
192 >        if (oldview.type == 0) {        /* no old view! */
193                  error(COMMAND, "no previous view");
194                  return;
195          }
196 <        copyview(&nv, &ourview);
197 <        copyview(&ourview, &oldview);
198 <        copyview(&oldview, &nv);
196 >        nv = ourview;
197 >        ourview = oldview;
198 >        oldview = nv;
199          newimage();
200   }
201  
202  
203 < getaim(s)                               /* aim camera */
204 < char  *s;
203 > extern void
204 > saveview(                               /* save view to rad file */
205 >        char  *s
206 > )
207   {
208 <        extern double  tan(), atan();
208 >        char  view[64];
209 >        char  *fname;
210 >        FILE  *fp;
211 >
212 >        if (*atos(view, sizeof(view), s)) {
213 >                if (isint(view)) {
214 >                        error(COMMAND, "cannot write view by number");
215 >                        return;
216 >                }
217 >                s = sskip(s);
218 >        }
219 >        while (isspace(*s))
220 >                s++;
221 >        if (*s)
222 >                atos(rifname, sizeof(rifname), s);
223 >        else if (rifname[0] == '\0') {
224 >                error(COMMAND, "no previous rad file");
225 >                return;
226 >        }
227 >        if ((fname = getpath(rifname, NULL, 0)) == NULL ||
228 >                        (fp = fopen(fname, "a")) == NULL) {
229 >                sprintf(errmsg, "cannot open \"%s\"", rifname);
230 >                error(COMMAND, errmsg);
231 >                return;
232 >        }
233 >        fputs("view= ", fp);
234 >        fputs(view, fp);
235 >        fprintview(&ourview, fp);
236 >        putc('\n', fp);
237 >        fclose(fp);
238 > }
239 >
240 >
241 > extern void
242 > loadview(                               /* load view from rad file */
243 >        char  *s
244 > )
245 > {
246 >        char  buf[512];
247 >        char  *fname;
248 >        FILE  *fp;
249 >        VIEW  nv;
250 >
251 >        strcpy(buf, "rad -n -s -V -v ");
252 >        if (sscanf(s, "%s", buf+strlen(buf)) == 1)
253 >                s = sskip(s);
254 >        else
255 >                strcat(buf, "1");
256 >        if (*s)
257 >                atos(rifname, sizeof(rifname), s);
258 >        else if (rifname[0] == '\0') {
259 >                error(COMMAND, "no previous rad file");
260 >                return;
261 >        }
262 >        if ((fname = getpath(rifname, "", R_OK)) == NULL) {
263 >                sprintf(errmsg, "cannot access \"%s\"", rifname);
264 >                error(COMMAND, errmsg);
265 >                return;
266 >        }
267 >        sprintf(buf+strlen(buf), " %s", fname);
268 >        if ((fp = popen(buf, "r")) == NULL) {
269 >                error(COMMAND, "cannot run rad");
270 >                return;
271 >        }
272 >        buf[0] = '\0';
273 >        fgets(buf, sizeof(buf), fp);
274 >        pclose(fp);
275 >        nv = stdview;
276 >        if (!sscanview(&nv, buf)) {
277 >                error(COMMAND, "rad error -- no such view?");
278 >                return;
279 >        }
280 >        newview(&nv);
281 > }
282 >
283 >
284 > extern void
285 > getaim(                         /* aim camera */
286 >        char  *s
287 > )
288 > {
289          double  zfact;
290          VIEW  nv;
291  
292          if (getinterest(s, 1, nv.vdir, &zfact) < 0)
293                  return;
294 +        nv.type = ourview.type;
295          VCOPY(nv.vp, ourview.vp);
296          VCOPY(nv.vup, ourview.vup);
297 +        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
298 +        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
299          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
300 <        if ((nv.type = ourview.type) == VT_PAR) {
177 <                nv.horiz = ourview.horiz / zfact;
178 <                nv.vert = ourview.vert / zfact;
179 <        } else {
180 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
181 <                                (PI/180./2.);
182 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
183 <                                (PI/180./2.);
184 <        }
300 >        zoomview(&nv, zfact);
301          newview(&nv);
302   }
303  
304  
305 < getmove(s)                              /* move camera */
306 < char  *s;
305 > extern void
306 > getmove(                                /* move camera */
307 >        char  *s
308 > )
309   {
310          FVECT  vc;
311          double  mag;
# Line 198 | Line 316 | char  *s;
316   }
317  
318  
319 < getrotate(s)                            /* rotate camera */
320 < char  *s;
319 > extern void
320 > getrotate(                              /* rotate camera */
321 >        char  *s
322 > )
323   {
204        extern double  normalize(), tan(), atan();
324          VIEW  nv;
325          FVECT  v1;
326          double  angle, elev, zfact;
# Line 211 | Line 330 | char  *s;
330                  error(COMMAND, "missing angle");
331                  return;
332          }
333 +        nv.type = ourview.type;
334          VCOPY(nv.vp, ourview.vp);
335          VCOPY(nv.vup, ourview.vup);
336          nv.hoff = ourview.hoff; nv.voff = ourview.voff;
337 +        nv.vfore = ourview.vfore; nv.vaft = ourview.vaft;
338          spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.));
339          if (elev != 0.0) {
340                  fcross(v1, nv.vdir, ourview.vup);
341                  normalize(v1);
342                  spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.));
343          }
344 <        if ((nv.type = ourview.type) == VT_PAR) {
345 <                nv.horiz = ourview.horiz / zfact;
225 <                nv.vert = ourview.vert / zfact;
226 <        } else {
227 <                nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) /
228 <                                (PI/180./2.);
229 <                nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) /
230 <                                (PI/180./2.);
231 <        }
344 >        nv.horiz = ourview.horiz; nv.vert = ourview.vert;
345 >        zoomview(&nv, zfact);
346          newview(&nv);
347   }
348  
349  
350 < getpivot(s)                             /* pivot viewpoint */
351 < register char  *s;
350 > extern void
351 > getpivot(                               /* pivot viewpoint */
352 >        register char  *s
353 > )
354   {
355          FVECT  vc;
356          double  angle, elev, mag;
# Line 244 | Line 360 | register char  *s;
360                  error(COMMAND, "missing angle");
361                  return;
362          }
363 <        if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0)
363 >        if (getinterest(sskip2(s,2), 0, vc, &mag) < 0)
364                  return;
365          moveview(angle, elev, mag, vc);
366   }
367  
368  
369 < getexposure(s)                          /* get new exposure */
370 < char  *s;
369 > extern void
370 > getexposure(                            /* get new exposure */
371 >        char  *s
372 > )
373   {
256        double  atof(), pow(), fabs();
374          char  buf[128];
375          register char  *cp;
259        register PNODE  *p;
376          RECT  r;
377          int  x, y;
378 <        double  e;
378 >        register PNODE  *p = &ptrunk;
379 >        int  adapt = 0;
380 >        double  e = 1.0;
381  
382          for (cp = s; isspace(*cp); cp++)
383                  ;
384 +        if (*cp == '@') {
385 +                adapt++;
386 +                while (isspace(*++cp))
387 +                        ;
388 +        }
389          if (*cp == '\0') {              /* normalize to point */
390                  if (dev->getcur == NULL)
391                          return;
# Line 272 | Line 395 | char  *s;
395                  r.l = r.d = 0;
396                  r.r = hresolu; r.u = vresolu;
397                  p = findrect(x, y, &ptrunk, &r, -1);
275                e = 1.0;
398          } else {
399                  if (*cp == '=') {       /* absolute setting */
400                          p = NULL;
# Line 280 | Line 402 | char  *s;
402                          for (cp++; isspace(*cp); cp++)
403                                  ;
404                          if (*cp == '\0') {      /* interactive */
405 <                                sprintf(buf, "exposure (%lf): ", exposure);
405 >                                sprintf(buf, "exposure (%f): ", exposure);
406                                  (*dev->comout)(buf);
407 <                                (*dev->comin)(buf);
407 >                                (*dev->comin)(buf, NULL);
408                                  for (cp = buf; isspace(*cp); cp++)
409                                          ;
410                                  if (*cp == '\0')
411                                          return;
412                          }
291                } else {                /* normalize to average */
292                        p = &ptrunk;
293                        e = 1.0;
413                  }
414                  if (*cp == '+' || *cp == '-')   /* f-stops */
415                          e *= pow(2.0, atof(cp));
# Line 298 | Line 417 | char  *s;
417                          e *= atof(cp);
418          }
419          if (p != NULL) {                /* relative setting */
420 <                if (bright(p->v) <= FTINY) {
420 >                if (bright(p->v) < 1e-15) {
421                          error(COMMAND, "cannot normalize to zero");
422                          return;
423                  }
424 <                e *= 0.5 / bright(p->v);
424 >                if (adapt)
425 >                        e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure;
426 >                else
427 >                        e *= 0.5 / bright(p->v);
428          }
429          if (e <= FTINY || fabs(1.0 - e) <= FTINY)
430                  return;
# Line 311 | Line 433 | char  *s;
433          redraw();
434   }
435  
436 + typedef union {int i; double d; COLOR C;}       *MyUptr;
437  
438 < setparam(s)                             /* get/set program parameter */
439 < register char  *s;
438 > extern int
439 > getparam(               /* get variable from user */
440 >        char  *str,
441 >        char  *dsc,
442 >        int  typ,
443 >        void  *p
444 > )
445   {
446 <        extern int  psample;
319 <        extern double  maxdiff;
320 <        extern double  minweight;
321 <        extern int  maxdepth;
322 <        extern double  dstrsrc;
323 <        extern double  shadthresh;
324 <        extern double  shadcert;
325 <        extern COLOR  ambval;
326 <        extern double  ambacc;
327 <        extern double  minarad;
328 <        extern int  ambres;
329 <        extern int  ambdiv;
330 <        extern int  ambssamp;
331 <        extern int  ambounce;
446 >        register MyUptr  ptr = (MyUptr)p;
447          int  i0;
448          double  d0, d1, d2;
449 +        char  buf[48];
450 +
451 +        switch (typ) {
452 +        case 'i':                       /* integer */
453 +                if (sscanf(str, "%d", &i0) != 1) {
454 +                        (*dev->comout)(dsc);
455 +                        sprintf(buf, " (%d): ", ptr->i);
456 +                        (*dev->comout)(buf);
457 +                        (*dev->comin)(buf, NULL);
458 +                        if (sscanf(buf, "%d", &i0) != 1)
459 +                                return(0);
460 +                }
461 +                ptr->i = i0;
462 +                return(1);
463 +        case 'r':                       /* real */
464 +                if (sscanf(str, "%lf", &d0) != 1) {
465 +                        (*dev->comout)(dsc);
466 +                        sprintf(buf, " (%.6g): ", ptr->d);
467 +                        (*dev->comout)(buf);
468 +                        (*dev->comin)(buf, NULL);
469 +                        if (sscanf(buf, "%lf", &d0) != 1)
470 +                                return(0);
471 +                }
472 +                ptr->d = d0;
473 +                return(1);
474 +        case 'b':                       /* boolean */
475 +                if (sscanf(str, "%1s", buf) != 1) {
476 +                        (*dev->comout)(dsc);
477 +                        sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n');
478 +                        (*dev->comout)(buf);
479 +                        (*dev->comin)(buf, NULL);
480 +                        if (buf[0] == '\0' ||
481 +                                        strchr("yY+1tTnN-0fF", buf[0]) == NULL)
482 +                                return(0);
483 +                }
484 +                ptr->i = strchr("yY+1tT", buf[0]) != NULL;
485 +                return(1);
486 +        case 'C':                       /* color */
487 +                if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
488 +                        (*dev->comout)(dsc);
489 +                        sprintf(buf, " (%.6g %.6g %.6g): ",
490 +                                        colval(ptr->C,RED),
491 +                                        colval(ptr->C,GRN),
492 +                                        colval(ptr->C,BLU));
493 +                        (*dev->comout)(buf);
494 +                        (*dev->comin)(buf, NULL);
495 +                        if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3)
496 +                                return(0);
497 +                }
498 +                setcolor(ptr->C, d0, d1, d2);
499 +                return(1);
500 +        }
501 +        return 0; /* nothing matched */
502 + }
503 +
504 +
505 + extern void
506 + setparam(                               /* get/set program parameter */
507 +        register char  *s
508 + )
509 + {
510          char  buf[128];
511          
512          if (s[0] == '\0') {
513 <                (*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: ");
514 <                (*dev->comin)(buf);
513 >                (*dev->comout)(
514 >                "aa ab ad ar as av aw b dc dv dj ds dt i lr lw me ma mg ms ps pt sj st bv: ");
515 >                (*dev->comin)(buf, NULL);
516                  s = buf;
517          }
518          switch (s[0]) {
519          case 'l':                       /* limit */
520                  switch (s[1]) {
521                  case 'w':                       /* weight */
522 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
523 <                                sprintf(buf, "limit weight (%.6g): ",
347 <                                                minweight);
348 <                                (*dev->comout)(buf);
349 <                                (*dev->comin)(buf);
350 <                                if (sscanf(buf, "%lf", &d0) != 1)
351 <                                        break;
352 <                        }
353 <                        minweight = d0;
522 >                        getparam(s+2, "limit weight", 'r',
523 >                                        (void *)&minweight);
524                          break;
525                  case 'r':                       /* reflection */
526 <                        if (sscanf(s+2, "%d", &i0) != 1) {
527 <                                sprintf(buf, "limit reflection (%d): ",
358 <                                                maxdepth);
359 <                                (*dev->comout)(buf);
360 <                                (*dev->comin)(buf);
361 <                                if (sscanf(buf, "%d", &i0) != 1)
362 <                                        break;
363 <                        }
364 <                        maxdepth = i0;
526 >                        getparam(s+2, "limit reflection", 'i',
527 >                                        (void *)&maxdepth);
528                          break;
529                  default:
530                          goto badparam;
# Line 370 | Line 533 | register char  *s;
533          case 'd':                       /* direct */
534                  switch (s[1]) {
535                  case 'j':                       /* jitter */
536 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
537 <                                sprintf(buf, "direct jitter (%.6g): ",
375 <                                                dstrsrc);
376 <                                (*dev->comout)(buf);
377 <                                (*dev->comin)(buf);
378 <                                if (sscanf(buf, "%lf", &d0) != 1)
379 <                                        break;
380 <                        }
381 <                        dstrsrc = d0;
536 >                        getparam(s+2, "direct jitter", 'r',
537 >                                        (void *)&dstrsrc);
538                          break;
539                  case 'c':                       /* certainty */
540 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
541 <                                sprintf(buf, "direct certainty (%.6g): ",
386 <                                                shadcert);
387 <                                (*dev->comout)(buf);
388 <                                (*dev->comin)(buf);
389 <                                if (sscanf(buf, "%lf", &d0) != 1)
390 <                                        break;
391 <                        }
392 <                        shadcert = d0;
540 >                        getparam(s+2, "direct certainty", 'r',
541 >                                        (void *)&shadcert);
542                          break;
543                  case 't':                       /* threshold */
544 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
545 <                                sprintf(buf, "direct threshold (%.6g): ",
397 <                                                shadthresh);
398 <                                (*dev->comout)(buf);
399 <                                (*dev->comin)(buf);
400 <                                if (sscanf(buf, "%lf", &d0) != 1)
401 <                                        break;
402 <                        }
403 <                        shadthresh = d0;
544 >                        getparam(s+2, "direct threshold", 'r',
545 >                                        (void *)&shadthresh);
546                          break;
547 +                case 'v':                       /* visibility */
548 +                        getparam(s+2, "direct visibility", 'b',
549 +                                        (void *)&directvis);
550 +                        break;
551 +                case 's':                       /* sampling */
552 +                        getparam(s+2, "direct sampling", 'r',
553 +                                        (void *)&srcsizerat);
554 +                        break;
555                  default:
556                          goto badparam;
557                  }
558                  break;
559 +        case 'b':                       /* back faces or black and white */
560 +                switch (s[1]) {
561 +                case 'v':                       /* back face visibility */
562 +                        getparam(s+2, "back face visibility", 'b',
563 +                                        (void *)&backvis);
564 +                        break;
565 +                case '\0':                      /* black and white */
566 +                case ' ':
567 +                case 'y': case 'Y': case 't': case 'T': case '1': case '+':
568 +                case 'n': case 'N': case 'f': case 'F': case '0': case '-':
569 +                        getparam(s+1, "black and white", 'b',
570 +                                        (void *)&greyscale);
571 +                        break;
572 +                default:
573 +                        goto badparam;
574 +                }
575 +                break;
576 +        case 'i':                       /* irradiance */
577 +                getparam(s+1, "irradiance", 'b',
578 +                                (void *)&do_irrad);
579 +                break;
580          case 'a':                       /* ambient */
581                  switch (s[1]) {
582                  case 'v':                       /* value */
583 <                        if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) {
584 <                                sprintf(buf,
414 <                                        "ambient value (%.6g %.6g %.6g): ",
415 <                                                colval(ambval,RED),
416 <                                                colval(ambval,GRN),
417 <                                                colval(ambval,BLU));
418 <                                (*dev->comout)(buf);
419 <                                (*dev->comin)(buf);
420 <                                if (sscanf(buf, "%lf %lf %lf",
421 <                                                &d0, &d1, &d2) != 3)
422 <                                        break;
423 <                        }
424 <                        setcolor(ambval, d0, d1, d2);
583 >                        getparam(s+2, "ambient value", 'C',
584 >                                        (void *)ambval);
585                          break;
586 +                case 'w':                       /* weight */
587 +                        getparam(s+2, "ambient value weight", 'i',
588 +                                        (void *)&ambvwt);
589 +                        break;
590                  case 'a':                       /* accuracy */
591 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
592 <                                sprintf(buf, "ambient accuracy (%.6g): ",
593 <                                                ambacc);
430 <                                (*dev->comout)(buf);
431 <                                (*dev->comin)(buf);
432 <                                if (sscanf(buf, "%lf", &d0) != 1)
433 <                                        break;
434 <                        }
435 <                        ambacc = d0;
591 >                        if (getparam(s+2, "ambient accuracy", 'r',
592 >                                        (void *)&ambacc))
593 >                                setambacc(ambacc);
594                          break;
595                  case 'd':                       /* divisions */
596 <                        if (sscanf(s+2, "%d", &i0) != 1) {
597 <                                sprintf(buf, "ambient divisions (%d): ",
440 <                                                ambdiv);
441 <                                (*dev->comout)(buf);
442 <                                (*dev->comin)(buf);
443 <                                if (sscanf(buf, "%d", &i0) != 1)
444 <                                        break;
445 <                        }
446 <                        ambdiv = i0;
596 >                        getparam(s+2, "ambient divisions", 'i',
597 >                                        (void *)&ambdiv);
598                          break;
599                  case 's':                       /* samples */
600 <                        if (sscanf(s+2, "%d", &i0) != 1) {
601 <                                sprintf(buf, "ambient super-samples (%d): ",
451 <                                                ambssamp);
452 <                                (*dev->comout)(buf);
453 <                                (*dev->comin)(buf);
454 <                                if (sscanf(buf, "%d", &i0) != 1)
455 <                                        break;
456 <                        }
457 <                        ambssamp = i0;
600 >                        getparam(s+2, "ambient super-samples", 'i',
601 >                                        (void *)&ambssamp);
602                          break;
603                  case 'b':                       /* bounces */
604 <                        if (sscanf(s+2, "%d", &i0) != 1) {
605 <                                sprintf(buf, "ambient bounces (%d): ",
462 <                                                ambounce);
463 <                                (*dev->comout)(buf);
464 <                                (*dev->comin)(buf);
465 <                                if (sscanf(buf, "%d", &i0) != 1)
466 <                                        break;
467 <                        }
468 <                        ambounce = i0;
604 >                        getparam(s+2, "ambient bounces", 'i',
605 >                                        (void *)&ambounce);
606                          break;
607                  case 'r':
608 <                        if (sscanf(s+2, "%d", &i0) != 1) {
609 <                                sprintf(buf, "ambient resolution (%d): ",
610 <                                                ambres);
474 <                                (*dev->comout)(buf);
475 <                                (*dev->comin)(buf);
476 <                                if (sscanf(buf, "%d", &i0) != 1)
477 <                                        break;
478 <                        }
479 <                        ambres = i0;
480 <                        minarad = ambres > 0 ? thescene.cusize/ambres : 0.0;
608 >                        if (getparam(s+2, "ambient resolution", 'i',
609 >                                        (void *)&ambres))
610 >                                setambres(ambres);
611                          break;
612                  default:
613                          goto badparam;
614                  }
615                  break;
616 <        case 's':                       /* sample */
616 >        case 'm':                       /* medium */
617                  switch (s[1]) {
618 <                case 'p':                       /* pixel */
619 <                        if (sscanf(s+2, "%d", &i0) != 1) {
620 <                                sprintf(buf, "sample pixel (%d): ", psample);
491 <                                (*dev->comout)(buf);
492 <                                (*dev->comin)(buf);
493 <                                if (sscanf(buf, "%d", &i0) != 1)
494 <                                        break;
495 <                        }
496 <                        psample = i0;
497 <                        pdepth = 0;
618 >                case 'e':                       /* extinction coefficient */
619 >                        getparam(s+2, "extinction coefficient", 'C',
620 >                                        (void *)cextinction);
621                          break;
622 +                case 'a':                       /* scattering albedo */
623 +                        getparam(s+2, "scattering albedo", 'C',
624 +                                        (void *)salbedo);
625 +                        break;
626 +                case 'g':                       /* scattering eccentricity */
627 +                        getparam(s+2, "scattering eccentricity", 'r',
628 +                                        (void *)&seccg);
629 +                        break;
630 +                case 's':                       /* sampling distance */
631 +                        getparam(s+2, "mist sampling distance", 'r',
632 +                                        (void *)&ssampdist);
633 +                        break;
634 +                default:
635 +                        goto badparam;
636 +                }
637 +                break;
638 +        case 'p':                       /* pixel */
639 +                switch (s[1]) {
640 +                case 's':                       /* sample */
641 +                        if (getparam(s+2, "pixel sample", 'i',
642 +                                        (void *)&psample))
643 +                                pdepth = 0;
644 +                        break;
645                  case 't':                       /* threshold */
646 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
647 <                                sprintf(buf, "sample threshold (%.6g): ",
648 <                                                maxdiff);
503 <                                (*dev->comout)(buf);
504 <                                (*dev->comin)(buf);
505 <                                if (sscanf(buf, "%lf", &d0) != 1)
506 <                                        break;
507 <                        }
508 <                        maxdiff = d0;
509 <                        pdepth = 0;
646 >                        if (getparam(s+2, "pixel threshold", 'r',
647 >                                        (void *)&maxdiff))
648 >                                pdepth = 0;
649                          break;
650                  default:
651                          goto badparam;
652                  }
653                  break;
654 +        case 's':                       /* specular */
655 +                switch (s[1]) {
656 +                case 'j':                       /* jitter */
657 +                        getparam(s+2, "specular jitter", 'r',
658 +                                        (void *)&specjitter);
659 +                        break;
660 +                case 't':                       /* threshold */
661 +                        getparam(s+2, "specular threshold", 'r',
662 +                                        (void *)&specthresh);
663 +                        break;
664 +                default:
665 +                        goto badparam;
666 +                }
667 +                break;
668          case '\0':                      /* nothing */
669                  break;
670          default:;
671   badparam:
672 +                *sskip(s) = '\0';
673                  sprintf(errmsg, "%s: unknown variable", s);
674                  error(COMMAND, errmsg);
675                  break;
# Line 523 | Line 677 | badparam:
677   }
678  
679  
680 + extern void
681   traceray(s)                             /* trace a single ray */
682   char  *s;
683   {
684          char  buf[128];
685          int  x, y;
686 +        OBJREC  *ino;
687          RAY  thisray;
688  
689 <        if (sscanf(s, "%lf %lf %lf %lf %lf %lf",
534 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
535 <                &thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) {
689 >        thisray.rmax = 0.0;
690  
691 +        if (!sscanvec(s, thisray.rorg) ||
692 +                        !sscanvec(sskip2(s,3), thisray.rdir)) {
693 +
694                  if (dev->getcur == NULL)
695                          return;
696                  (*dev->comout)("Pick ray\n");
697                  if ((*dev->getcur)(&x, &y) == ABORT)
698                          return;
699  
700 <                viewray(thisray.rorg, thisray.rdir, &ourview,
701 <                                (x+.5)/hresolu, (y+.5)/vresolu);
702 <                
700 >                if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
701 >                        &ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) {
702 >                        error(COMMAND, "not on image");
703 >                        return;
704 >                }
705 >
706          } else if (normalize(thisray.rdir) == 0.0) {
707                  error(COMMAND, "zero ray direction");
708                  return;
# Line 555 | Line 715 | char  *s;
715          if (thisray.ro == NULL)
716                  (*dev->comout)("ray hit nothing");
717          else {
718 <                sprintf(buf, "ray hit %s %s \"%s\"",
719 <                                objptr(thisray.ro->omod)->oname,
718 >                sprintf(buf, "ray hit %s%s %s \"%s\"",
719 >                                thisray.rod < 0.0 ? "back of " : "",
720 >                                thisray.ro->omod == OVOID ? VOIDID :
721 >                                        objptr(thisray.ro->omod)->oname,
722                                  ofun[thisray.ro->otype].funame,
723                                  thisray.ro->oname);
724 +                if ((ino = objptr(thisray.robj)) != thisray.ro)
725 +                        sprintf(buf+strlen(buf), " in %s \"%s\"",
726 +                                        ofun[ino->otype].funame, ino->oname);
727                  (*dev->comout)(buf);
728 <                (*dev->comin)(buf);
728 >                (*dev->comin)(buf, NULL);
729                  if (thisray.rot >= FHUGE)
730                          (*dev->comout)("at infinity");
731                  else {
732 <                        sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0],
733 <                                        thisray.rop[1], thisray.rop[2]);
732 >                        sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)",
733 >                                        thisray.rop[0], thisray.rop[1],
734 >                                        thisray.rop[2], thisray.rt);
735                          (*dev->comout)(buf);
736                  }
737 <                (*dev->comin)(buf);
738 <                sprintf(buf, "with value (%.6g %.6g %.6g)",
737 >                (*dev->comin)(buf, NULL);
738 >                sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)",
739                                  colval(thisray.rcol,RED),
740                                  colval(thisray.rcol,GRN),
741 <                                colval(thisray.rcol,BLU));
741 >                                colval(thisray.rcol,BLU),
742 >                                luminance(thisray.rcol));
743                  (*dev->comout)(buf);
744          }
745 <        (*dev->comin)(buf);
745 >        (*dev->comin)(buf, NULL);
746   }
747  
748  
749 + extern void
750   writepict(s)                            /* write the picture to a file */
751   char  *s;
752   {
# Line 588 | Line 756 | char  *s;
756          COLR  *scanline;
757          int  y;
758  
759 <        if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') {
759 >        while (isspace(*s))
760 >                s++;
761 >        if (*s)
762 >                atos(buf, sizeof(buf), s);
763 >        else if (buf[0] == '\0') {
764                  error(COMMAND, "no file");
765                  return;
766          }
# Line 598 | Line 770 | char  *s;
770                  error(COMMAND, errmsg);
771                  return;
772          }
773 +        SET_FILE_BINARY(fp);
774          (*dev->comout)("writing \"");
775          (*dev->comout)(fname);
776          (*dev->comout)("\"...\n");
777                                                  /* write header */
778 +        newheader("RADIANCE", fp);
779          fputs(progname, fp);
780          fprintview(&ourview, fp);
781 <        putc('\n', fp);
781 >        if (octname != NULL)
782 >                fprintf(fp, " %s\n", octname);
783 >        else
784 >                putc('\n', fp);
785 >        fprintf(fp, "SOFTWARE= %s\n", VersionID);
786 >        fputnow(fp);
787          if (exposure != 1.0)
788                  fputexpos(exposure, fp);
789 +        if (dev->pixaspect != 1.0)
790 +                fputaspect(dev->pixaspect, fp);
791 +        fputformat(COLRFMT, fp);
792          putc('\n', fp);
793 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp);
793 >        fprtresolu(hresolu, vresolu, fp);
794  
795          scanline = (COLR *)malloc(hresolu*sizeof(COLR));
796 <        if (scanline == NULL)
797 <                error(SYSTEM, "out of memory in writepict");
796 >        if (scanline == NULL) {
797 >                error(COMMAND, "not enough memory!");
798 >                fclose(fp);
799 >                unlink(fname);
800 >                return;
801 >        }
802          for (y = vresolu-1; y >= 0; y--) {
803                  getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu);
804                  if (fwritecolrs(scanline, hresolu, fp) < 0)
805                          break;
806          }
807 +        free((void *)scanline);
808          if (fclose(fp) < 0)
809                  error(COMMAND, "write error");
623        free((char *)scanline);
810   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines