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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines