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.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 <        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;
43 >        if (getrect(s, &pframe) < 0)
44                  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;
45          pdepth = 0;
46   }
47  
48  
49 < getview(s)                              /* get/show view parameters */
50 < char  *s;
49 > extern void
50 > getrepaint(                             /* get area and repaint */
51 >        char  *s
52 > )
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 + extern void
63 + getview(                                /* get/show view parameters */
64 +        char  *s
65 + )
66 + {
67          FILE  *fp;
68          char  buf[128];
69 <        char  *fname, *getpath();
69 >        char  *fname;
70 >        int  change = 0;
71          VIEW  nv;
72  
73 +        while (isspace(*s))
74 +                s++;
75 +        if (*s == '-') {                        /* command line parameters */
76 +                nv = ourview;
77 +                if (sscanview(&nv, s))
78 +                        newview(&nv);
79 +                else
80 +                        error(COMMAND, "bad view option(s)");
81 +                return;
82 +        }
83          if (sscanf(s, "%s", buf) == 1) {        /* write parameters to a file */
84 <                if ((fname = getpath(buf, NULL)) == NULL ||
84 >                if ((fname = getpath(buf, NULL, 0)) == NULL ||
85                                  (fp = fopen(fname, "a")) == NULL) {
86                          sprintf(errmsg, "cannot open \"%s\"", buf);
87                          error(COMMAND, errmsg);
# Line 86 | 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;
101 <        if (buf[0])
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 <        else
103 >                change++;
104 >        } else
105                  nv.type = ourview.type;
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;
138 <        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) != 2) {
136 >        (*dev->comin)(buf, NULL);
137 >        if (buf[0] == CTRL('C')) return;
138 >        if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2)
139 >                change++;
140 >        else {
141                  nv.horiz = ourview.horiz; nv.vert = ourview.vert;
142          }
143 <        sprintf(buf, "x and y resolution (%d %d): ",
144 <                        ourview.hresolu, ourview.vresolu);
143 >        sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ",
144 >                        ourview.vfore, ourview.vaft);
145          (*dev->comout)(buf);
146 <        (*dev->comin)(buf);
147 <        if (buf[0] == CTRL(C)) return;
148 <        if (sscanf(buf, "%d %d", &nv.hresolu, &nv.vresolu) != 2) {
149 <                nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
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 <        newview(&nv);
153 >        sprintf(buf, "view shift and lift (%.6g %.6g): ",
154 >                        ourview.hoff, ourview.voff);
155 >        (*dev->comout)(buf);
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 {
161 >                nv.hoff = ourview.hoff; nv.voff = ourview.voff;
162 >        }
163 >        if (change)
164 >                newview(&nv);
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, *getpath();
174 >        char  *fname;
175          int  success;
176          VIEW  nv;
177  
178          if (sscanf(s, "%s", buf) == 1) {        /* get parameters from a file */
179 <                bcopy(&stdview, &nv, sizeof(VIEW));
180 <                if ((fname = getpath(buf, NULL)) == 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 161 | Line 189 | char  *s;
189                          newview(&nv);
190                  return;
191          }
192 <        if (oldview.hresolu == 0) {     /* no old view! */
192 >        if (oldview.type == 0) {        /* no old view! */
193                  error(COMMAND, "no previous view");
194                  return;
195          }
196 <        bcopy(&ourview, &nv, sizeof(VIEW));
197 <        bcopy(&oldview, &ourview, sizeof(VIEW));
198 <        bcopy(&nv, &oldview, sizeof(VIEW));
196 >        nv = ourview;
197 >        ourview = oldview;
198 >        oldview = nv;
199          newimage();
200   }
201  
202  
203 < getinterest(s, direc, vec, mp)          /* get area of interest */
204 < char  *s;
205 < int  direc;
206 < FVECT  vec;
179 < double  *mp;
203 > extern void
204 > saveview(                               /* save view to rad file */
205 >        char  *s
206 > )
207   {
208 <        int  x, y;
209 <        RAY  thisray;
210 <        register int  i;
208 >        char  view[64];
209 >        char  *fname;
210 >        FILE  *fp;
211  
212 <        if (sscanf(s, "%lf", mp) != 1)
213 <                *mp = 1.0;
214 <        else if (*mp < -FTINY)          /* negative zoom is reduction */
215 <                *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 <                        }
212 >        if (*atos(view, sizeof(view), s)) {
213 >                if (isint(view)) {
214 >                        error(COMMAND, "cannot write view by number");
215 >                        return;
216                  }
217 <                if (direc)
218 <                        if (ourview.type == VT_PAR)
219 <                                for (i = 0; i < 3; i++)
220 <                                        vec[i] = thisray.rop[i] - ourview.vp[i];
221 <                        else
222 <                                VCOPY(vec, thisray.rdir);
223 <                else
224 <                        VCOPY(vec, thisray.rop);
225 <        } else if (direc)
226 <                        for (i = 0; i < 3; i++)
227 <                                vec[i] -= ourview.vp[i];
228 <        return(0);
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 < getaim(s)                               /* aim camera */
242 < char  *s;
241 > extern void
242 > loadview(                               /* load view from rad file */
243 >        char  *s
244 > )
245   {
246 <        extern double  tan(), atan();
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.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
298 <        if ((nv.type = ourview.type) == VT_PAR) {
299 <                nv.horiz = ourview.horiz / zfact;
300 <                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 <        }
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 >        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;
312  
313          if (getinterest(s, 0, vc, &mag) < 0)
314                  return;
315 <        moveview(0.0, mag, vc);
315 >        moveview(0.0, 0.0, mag, vc);
316   }
317  
318  
319 < getrotate(s)                            /* rotate camera */
320 < char  *s;
319 > extern void
320 > getrotate(                              /* rotate camera */
321 >        char  *s
322 > )
323   {
262        extern double  normalize();
324          VIEW  nv;
325          FVECT  v1;
326 <        double  angle, elev;
326 >        double  angle, elev, zfact;
327          
328 <        elev = 0.0;
329 <        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
328 >        elev = 0.0; zfact = 1.0;
329 >        if (sscanf(s, "%lf %lf %lf", &angle, &elev, &zfact) < 1) {
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.horiz = ourview.horiz; nv.vert = ourview.vert;
337 <        nv.hresolu = ourview.hresolu; nv.vresolu = ourview.vresolu;
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 +        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, mag;
356 >        double  angle, elev, mag;
357  
358 <        if (sscanf(s, "%lf", &angle) != 1) {
358 >        elev = 0.0;
359 >        if (sscanf(s, "%lf %lf", &angle, &elev) < 1) {
360                  error(COMMAND, "missing angle");
361                  return;
362          }
363 <        if (getinterest(sskip(s), 0, vc, &mag) < 0)
363 >        if (getinterest(sskip2(s,2), 0, vc, &mag) < 0)
364                  return;
365 <        moveview(angle, mag, vc);
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   {
306        double  atof(), pow(), fabs();
374          char  buf[128];
375          register char  *cp;
309        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 320 | Line 393 | char  *s;
393                  if ((*dev->getcur)(&x, &y) == ABORT)
394                          return;
395                  r.l = r.d = 0;
396 <                r.r = ourview.hresolu; r.u = ourview.vresolu;
396 >                r.r = hresolu; r.u = vresolu;
397                  p = findrect(x, y, &ptrunk, &r, -1);
325                e = 1.0;
398          } else {
399                  if (*cp == '=') {       /* absolute setting */
400                          p = NULL;
# Line 330 | 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                          }
341                } else {                /* normalize to average */
342                        p = &ptrunk;
343                        e = 1.0;
413                  }
414                  if (*cp == '+' || *cp == '-')   /* f-stops */
415                          e *= pow(2.0, atof(cp));
# Line 348 | Line 417 | char  *s;
417                          e *= atof(cp);
418          }
419          if (p != NULL) {                /* relative setting */
420 <                if (intens(p->v) <= FTINY) {
420 >                if (bright(p->v) < 1e-15) {
421                          error(COMMAND, "cannot normalize to zero");
422                          return;
423                  }
424 <                e *= 0.5 / intens(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 361 | 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;
369 <        extern double  maxdiff;
370 <        extern double  minweight;
371 <        extern int  maxdepth;
372 <        extern double  dstrsrc;
373 <        extern COLOR  ambval;
374 <        extern double  ambacc;
375 <        extern double  minarad;
376 <        extern int  ambres;
377 <        extern int  ambdiv;
378 <        extern int  ambssamp;
379 <        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 ds lr lw sd sp: ");
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): ",
395 <                                                minweight);
396 <                                (*dev->comout)(buf);
397 <                                (*dev->comin)(buf);
398 <                                if (sscanf(buf, "%lf", &d0) != 1)
399 <                                        break;
400 <                        }
401 <                        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): ",
406 <                                                maxdepth);
407 <                                (*dev->comout)(buf);
408 <                                (*dev->comin)(buf);
409 <                                if (sscanf(buf, "%d", &i0) != 1)
410 <                                        break;
411 <                        }
412 <                        maxdepth = i0;
526 >                        getparam(s+2, "limit reflection", 'i',
527 >                                        (void *)&maxdepth);
528                          break;
529                  default:
530                          goto badparam;
531                  }
532                  break;
533 <        case 'd':                       /* distribute source */
534 <                if (s[1] != 's')
533 >        case 'd':                       /* direct */
534 >                switch (s[1]) {
535 >                case 'j':                       /* jitter */
536 >                        getparam(s+2, "direct jitter", 'r',
537 >                                        (void *)&dstrsrc);
538 >                        break;
539 >                case 'c':                       /* certainty */
540 >                        getparam(s+2, "direct certainty", 'r',
541 >                                        (void *)&shadcert);
542 >                        break;
543 >                case 't':                       /* threshold */
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;
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;
557                  }
428                dstrsrc = d0;
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,
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);
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);
451 <                                (*dev->comout)(buf);
452 <                                (*dev->comin)(buf);
453 <                                if (sscanf(buf, "%lf", &d0) != 1)
454 <                                        break;
455 <                        }
456 <                        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): ",
461 <                                                ambdiv);
462 <                                (*dev->comout)(buf);
463 <                                (*dev->comin)(buf);
464 <                                if (sscanf(buf, "%d", &i0) != 1)
465 <                                        break;
466 <                        }
467 <                        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): ",
472 <                                                ambssamp);
473 <                                (*dev->comout)(buf);
474 <                                (*dev->comin)(buf);
475 <                                if (sscanf(buf, "%d", &i0) != 1)
476 <                                        break;
477 <                        }
478 <                        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): ",
483 <                                                ambounce);
484 <                                (*dev->comout)(buf);
485 <                                (*dev->comin)(buf);
486 <                                if (sscanf(buf, "%d", &i0) != 1)
487 <                                        break;
488 <                        }
489 <                        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);
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;
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);
512 <                                (*dev->comout)(buf);
513 <                                (*dev->comin)(buf);
514 <                                if (sscanf(buf, "%d", &i0) != 1)
515 <                                        break;
516 <                        }
517 <                        psample = i0;
518 <                        pdepth = 0;
618 >                case 'e':                       /* extinction coefficient */
619 >                        getparam(s+2, "extinction coefficient", 'C',
620 >                                        (void *)cextinction);
621                          break;
622 <                case 'd':                       /* difference */
623 <                        if (sscanf(s+2, "%lf", &d0) != 1) {
624 <                                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;
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 (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 544 | 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",
555 <                &thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2],
556 <                &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 <                rayview(thisray.rorg, thisray.rdir, &ourview, x+.5, y+.5);
701 <                
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 575 | 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   {
753          static char  buf[128];
754 <        char  *fname, *getpath();
754 >        char  *fname;
755          FILE  *fp;
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          }
767 <        if ((fname = getpath(buf, NULL)) == NULL ||
767 >        if ((fname = getpath(buf, NULL, 0)) == NULL ||
768                          (fp = fopen(fname, "w")) == NULL) {
769                  sprintf(errmsg, "cannot open \"%s\"", buf);
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 <        fputs("\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 <                fprintf(fp, "EXPOSURE=%e\n", exposure);
789 <        fprintf(fp, "\n-Y %d +X %d\n", ourview.vresolu, ourview.hresolu);
788 >                fputexpos(exposure, fp);
789 >        if (dev->pixaspect != 1.0)
790 >                fputaspect(dev->pixaspect, fp);
791 >        fputformat(COLRFMT, fp);
792 >        putc('\n', fp);
793 >        fprtresolu(hresolu, vresolu, fp);
794  
795 <        scanline = (COLR *)malloc(ourview.hresolu*sizeof(COLR));
796 <        if (scanline == NULL)
797 <                error(SYSTEM, "out of memory in writepict");
798 <        for (y = ourview.vresolu-1; y >= 0; y--) {
799 <                getpictcolrs(y, scanline, &ptrunk,
800 <                                ourview.hresolu, ourview.vresolu);
801 <                if (fwritecolrs(scanline, ourview.hresolu, fp) < 0)
795 >        scanline = (COLR *)malloc(hresolu*sizeof(COLR));
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");
643        free((char *)scanline);
810   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines