1 |
< |
/* Copyright (c) 1987 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
18 |
|
|
19 |
|
#include "rpaint.h" |
20 |
|
|
21 |
+ |
#include "resolu.h" |
22 |
+ |
|
23 |
|
#include <ctype.h> |
24 |
|
|
25 |
< |
#define CTRL(c) ('c'-'@') |
25 |
> |
#define CTRL(c) ((c)-'@') |
26 |
|
|
27 |
+ |
#ifdef SMLFLT |
28 |
+ |
#define sscanvec(s,v) (sscanf(s,"%f %f %f",v,v+1,v+2)==3) |
29 |
+ |
#else |
30 |
+ |
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
31 |
+ |
#endif |
32 |
+ |
|
33 |
+ |
extern char *atos(); |
34 |
+ |
|
35 |
+ |
extern FILE *popen(); |
36 |
+ |
|
37 |
+ |
extern char rifname[128]; /* rad input file name */ |
38 |
+ |
|
39 |
+ |
extern char VersionID[]; |
40 |
|
extern char *progname; |
41 |
+ |
extern char *octname; |
42 |
|
|
43 |
|
|
44 |
|
getframe(s) /* get a new frame */ |
70 |
|
int change = 0; |
71 |
|
VIEW nv; |
72 |
|
|
73 |
+ |
while (isspace(*s)) |
74 |
+ |
s++; |
75 |
+ |
if (*s == '-') { /* command line parameters */ |
76 |
+ |
copystruct(&nv, &ourview); |
77 |
+ |
if (sscanview(&nv, s)) |
78 |
+ |
newview(&nv); |
79 |
+ |
else |
80 |
+ |
error(COMMAND, "bad view option(s)"); |
81 |
+ |
return; |
82 |
+ |
} |
83 |
|
if (sscanf(s, "%s", buf) == 1) { /* write parameters to a file */ |
84 |
|
if ((fname = getpath(buf, NULL, 0)) == NULL || |
85 |
|
(fp = fopen(fname, "a")) == NULL) { |
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, NULL); |
100 |
< |
if (buf[0] == CTRL(C)) return; |
100 |
> |
if (buf[0] == CTRL('C')) return; |
101 |
|
if (buf[0] && buf[0] != ourview.type) { |
102 |
|
nv.type = buf[0]; |
103 |
|
change++; |
107 |
|
ourview.vp[0], ourview.vp[1], ourview.vp[2]); |
108 |
|
(*dev->comout)(buf); |
109 |
|
(*dev->comin)(buf, NULL); |
110 |
< |
if (buf[0] == CTRL(C)) return; |
111 |
< |
if (sscanf(buf, "%lf %lf %lf", &nv.vp[0], &nv.vp[1], &nv.vp[2]) == 3) |
110 |
> |
if (buf[0] == CTRL('C')) return; |
111 |
> |
if (sscanvec(buf, nv.vp)) |
112 |
|
change++; |
113 |
|
else |
114 |
|
VCOPY(nv.vp, ourview.vp); |
116 |
|
ourview.vdir[0], ourview.vdir[1], ourview.vdir[2]); |
117 |
|
(*dev->comout)(buf); |
118 |
|
(*dev->comin)(buf, NULL); |
119 |
< |
if (buf[0] == CTRL(C)) return; |
120 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vdir[0],&nv.vdir[1],&nv.vdir[2]) == 3) |
119 |
> |
if (buf[0] == CTRL('C')) return; |
120 |
> |
if (sscanvec(buf, nv.vdir)) |
121 |
|
change++; |
122 |
|
else |
123 |
|
VCOPY(nv.vdir, ourview.vdir); |
125 |
|
ourview.vup[0], ourview.vup[1], ourview.vup[2]); |
126 |
|
(*dev->comout)(buf); |
127 |
|
(*dev->comin)(buf, NULL); |
128 |
< |
if (buf[0] == CTRL(C)) return; |
129 |
< |
if (sscanf(buf,"%lf %lf %lf",&nv.vup[0],&nv.vup[1],&nv.vup[2]) == 3) |
128 |
> |
if (buf[0] == CTRL('C')) return; |
129 |
> |
if (sscanvec(buf, nv.vup)) |
130 |
|
change++; |
131 |
|
else |
132 |
|
VCOPY(nv.vup, ourview.vup); |
134 |
|
ourview.horiz, ourview.vert); |
135 |
|
(*dev->comout)(buf); |
136 |
|
(*dev->comin)(buf, NULL); |
137 |
< |
if (buf[0] == CTRL(C)) return; |
137 |
> |
if (buf[0] == CTRL('C')) return; |
138 |
|
if (sscanf(buf, "%lf %lf", &nv.horiz, &nv.vert) == 2) |
139 |
|
change++; |
140 |
|
else { |
141 |
|
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
142 |
|
} |
143 |
+ |
sprintf(buf, "fore and aft clipping plane (%.6g %.6g): ", |
144 |
+ |
ourview.vfore, ourview.vaft); |
145 |
+ |
(*dev->comout)(buf); |
146 |
+ |
(*dev->comin)(buf, NULL); |
147 |
+ |
if (buf[0] == CTRL('C')) return; |
148 |
+ |
if (sscanf(buf, "%lf %lf", &nv.vfore, &nv.vaft) == 2) |
149 |
+ |
change++; |
150 |
+ |
else { |
151 |
+ |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
152 |
+ |
} |
153 |
|
sprintf(buf, "view shift and lift (%.6g %.6g): ", |
154 |
|
ourview.hoff, ourview.voff); |
155 |
|
(*dev->comout)(buf); |
156 |
|
(*dev->comin)(buf, NULL); |
157 |
< |
if (buf[0] == CTRL(C)) return; |
157 |
> |
if (buf[0] == CTRL('C')) return; |
158 |
|
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
159 |
|
change++; |
160 |
|
else { |
175 |
|
|
176 |
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
177 |
|
copystruct(&nv, &stdview); |
178 |
< |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
179 |
< |
(success = viewfile(fname, &nv, 0, 0)) == -1) { |
178 |
> |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
179 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
180 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
181 |
|
error(COMMAND, errmsg); |
182 |
|
return; |
187 |
|
newview(&nv); |
188 |
|
return; |
189 |
|
} |
190 |
< |
if (oldview.horiz == 0) { /* no old view! */ |
190 |
> |
if (oldview.type == 0) { /* no old view! */ |
191 |
|
error(COMMAND, "no previous view"); |
192 |
|
return; |
193 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
+ |
saveview(s) /* save view to rad file */ |
202 |
+ |
char *s; |
203 |
+ |
{ |
204 |
+ |
char view[64]; |
205 |
+ |
char *fname; |
206 |
+ |
FILE *fp; |
207 |
+ |
|
208 |
+ |
if (*atos(view, sizeof(view), s)) { |
209 |
+ |
if (isint(view)) { |
210 |
+ |
error(COMMAND, "cannot write view by number"); |
211 |
+ |
return; |
212 |
+ |
} |
213 |
+ |
s = sskip(s); |
214 |
+ |
} |
215 |
+ |
while (isspace(*s)) |
216 |
+ |
s++; |
217 |
+ |
if (*s) |
218 |
+ |
atos(rifname, sizeof(rifname), s); |
219 |
+ |
else if (rifname[0] == '\0') { |
220 |
+ |
error(COMMAND, "no previous rad file"); |
221 |
+ |
return; |
222 |
+ |
} |
223 |
+ |
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
224 |
+ |
(fp = fopen(fname, "a")) == NULL) { |
225 |
+ |
sprintf(errmsg, "cannot open \"%s\"", rifname); |
226 |
+ |
error(COMMAND, errmsg); |
227 |
+ |
return; |
228 |
+ |
} |
229 |
+ |
fputs("view= ", fp); |
230 |
+ |
fputs(view, fp); |
231 |
+ |
fprintview(&ourview, fp); |
232 |
+ |
putc('\n', fp); |
233 |
+ |
fclose(fp); |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
|
237 |
+ |
loadview(s) /* load view from rad file */ |
238 |
+ |
char *s; |
239 |
+ |
{ |
240 |
+ |
char buf[512]; |
241 |
+ |
char *fname; |
242 |
+ |
FILE *fp; |
243 |
+ |
VIEW nv; |
244 |
+ |
|
245 |
+ |
strcpy(buf, "rad -n -s -V -v "); |
246 |
+ |
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
247 |
+ |
s = sskip(s); |
248 |
+ |
else |
249 |
+ |
strcat(buf, "1"); |
250 |
+ |
if (*s) |
251 |
+ |
atos(rifname, sizeof(rifname), s); |
252 |
+ |
else if (rifname[0] == '\0') { |
253 |
+ |
error(COMMAND, "no previous rad file"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
+ |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
257 |
+ |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
258 |
+ |
error(COMMAND, errmsg); |
259 |
+ |
return; |
260 |
+ |
} |
261 |
+ |
sprintf(buf+strlen(buf), " %s", fname); |
262 |
+ |
if ((fp = popen(buf, "r")) == NULL) { |
263 |
+ |
error(COMMAND, "cannot run rad"); |
264 |
+ |
return; |
265 |
+ |
} |
266 |
+ |
buf[0] = '\0'; |
267 |
+ |
fgets(buf, sizeof(buf), fp); |
268 |
+ |
pclose(fp); |
269 |
+ |
copystruct(&nv, &stdview); |
270 |
+ |
if (!sscanview(&nv, buf)) { |
271 |
+ |
error(COMMAND, "rad error -- no such view?"); |
272 |
+ |
return; |
273 |
+ |
} |
274 |
+ |
newview(&nv); |
275 |
+ |
} |
276 |
+ |
|
277 |
+ |
|
278 |
|
getaim(s) /* aim camera */ |
279 |
|
char *s; |
280 |
|
{ |
167 |
– |
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.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 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
177 |
< |
nv.horiz = ourview.horiz / zfact; |
178 |
< |
nv.vert = ourview.vert / zfact; |
179 |
< |
} else { |
180 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
181 |
< |
(PI/180./2.); |
182 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
183 |
< |
(PI/180./2.); |
184 |
< |
} |
292 |
> |
zoomview(&nv, zfact); |
293 |
|
newview(&nv); |
294 |
|
} |
295 |
|
|
309 |
|
getrotate(s) /* rotate camera */ |
310 |
|
char *s; |
311 |
|
{ |
204 |
– |
extern double normalize(), tan(), atan(); |
312 |
|
VIEW nv; |
313 |
|
FVECT v1; |
314 |
|
double angle, elev, zfact; |
318 |
|
error(COMMAND, "missing angle"); |
319 |
|
return; |
320 |
|
} |
321 |
+ |
nv.type = ourview.type; |
322 |
|
VCOPY(nv.vp, ourview.vp); |
323 |
|
VCOPY(nv.vup, ourview.vup); |
324 |
|
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
325 |
+ |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
326 |
|
spinvector(nv.vdir, ourview.vdir, ourview.vup, angle*(PI/180.)); |
327 |
|
if (elev != 0.0) { |
328 |
|
fcross(v1, nv.vdir, ourview.vup); |
329 |
|
normalize(v1); |
330 |
|
spinvector(nv.vdir, nv.vdir, v1, elev*(PI/180.)); |
331 |
|
} |
332 |
< |
if ((nv.type = ourview.type) == VT_PAR) { |
333 |
< |
nv.horiz = ourview.horiz / zfact; |
225 |
< |
nv.vert = ourview.vert / zfact; |
226 |
< |
} else { |
227 |
< |
nv.horiz = atan(tan(ourview.horiz*(PI/180./2.))/zfact) / |
228 |
< |
(PI/180./2.); |
229 |
< |
nv.vert = atan(tan(ourview.vert*(PI/180./2.))/zfact) / |
230 |
< |
(PI/180./2.); |
231 |
< |
} |
332 |
> |
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
333 |
> |
zoomview(&nv, zfact); |
334 |
|
newview(&nv); |
335 |
|
} |
336 |
|
|
355 |
|
getexposure(s) /* get new exposure */ |
356 |
|
char *s; |
357 |
|
{ |
256 |
– |
double atof(), pow(), fabs(); |
358 |
|
char buf[128]; |
359 |
|
register char *cp; |
259 |
– |
register PNODE *p; |
360 |
|
RECT r; |
361 |
|
int x, y; |
362 |
< |
double e; |
362 |
> |
register PNODE *p = &ptrunk; |
363 |
> |
int adapt = 0; |
364 |
> |
double e = 1.0; |
365 |
|
|
366 |
|
for (cp = s; isspace(*cp); cp++) |
367 |
|
; |
368 |
+ |
if (*cp == '@') { |
369 |
+ |
adapt++; |
370 |
+ |
while (isspace(*++cp)) |
371 |
+ |
; |
372 |
+ |
} |
373 |
|
if (*cp == '\0') { /* normalize to point */ |
374 |
|
if (dev->getcur == NULL) |
375 |
|
return; |
379 |
|
r.l = r.d = 0; |
380 |
|
r.r = hresolu; r.u = vresolu; |
381 |
|
p = findrect(x, y, &ptrunk, &r, -1); |
275 |
– |
e = 1.0; |
382 |
|
} else { |
383 |
|
if (*cp == '=') { /* absolute setting */ |
384 |
|
p = NULL; |
386 |
|
for (cp++; isspace(*cp); cp++) |
387 |
|
; |
388 |
|
if (*cp == '\0') { /* interactive */ |
389 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
389 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
390 |
|
(*dev->comout)(buf); |
391 |
|
(*dev->comin)(buf, NULL); |
392 |
|
for (cp = buf; isspace(*cp); cp++) |
394 |
|
if (*cp == '\0') |
395 |
|
return; |
396 |
|
} |
291 |
– |
} else { /* normalize to average */ |
292 |
– |
p = &ptrunk; |
293 |
– |
e = 1.0; |
397 |
|
} |
398 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
399 |
|
e *= pow(2.0, atof(cp)); |
401 |
|
e *= atof(cp); |
402 |
|
} |
403 |
|
if (p != NULL) { /* relative setting */ |
404 |
< |
if (bright(p->v) <= FTINY) { |
404 |
> |
if (bright(p->v) < 1e-15) { |
405 |
|
error(COMMAND, "cannot normalize to zero"); |
406 |
|
return; |
407 |
|
} |
408 |
< |
e *= 0.5 / bright(p->v); |
408 |
> |
if (adapt) |
409 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
410 |
> |
else |
411 |
> |
e *= 0.5 / bright(p->v); |
412 |
|
} |
413 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
414 |
|
return; |
418 |
|
} |
419 |
|
|
420 |
|
|
421 |
+ |
getparam(str, dsc, typ, ptr) /* get variable from user */ |
422 |
+ |
char *str, *dsc; |
423 |
+ |
int typ; |
424 |
+ |
register union {int i; double d; COLOR C;} *ptr; |
425 |
+ |
{ |
426 |
+ |
extern char *index(); |
427 |
+ |
int i0; |
428 |
+ |
double d0, d1, d2; |
429 |
+ |
char buf[48]; |
430 |
+ |
|
431 |
+ |
switch (typ) { |
432 |
+ |
case 'i': /* integer */ |
433 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
434 |
+ |
(*dev->comout)(dsc); |
435 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
436 |
+ |
(*dev->comout)(buf); |
437 |
+ |
(*dev->comin)(buf, NULL); |
438 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
439 |
+ |
return(0); |
440 |
+ |
} |
441 |
+ |
ptr->i = i0; |
442 |
+ |
return(1); |
443 |
+ |
case 'r': /* real */ |
444 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
445 |
+ |
(*dev->comout)(dsc); |
446 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
447 |
+ |
(*dev->comout)(buf); |
448 |
+ |
(*dev->comin)(buf, NULL); |
449 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
450 |
+ |
return(0); |
451 |
+ |
} |
452 |
+ |
ptr->d = d0; |
453 |
+ |
return(1); |
454 |
+ |
case 'b': /* boolean */ |
455 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
456 |
+ |
(*dev->comout)(dsc); |
457 |
+ |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
458 |
+ |
(*dev->comout)(buf); |
459 |
+ |
(*dev->comin)(buf, NULL); |
460 |
+ |
if (buf[0] == '\0' || |
461 |
+ |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
462 |
+ |
return(0); |
463 |
+ |
} |
464 |
+ |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
465 |
+ |
return(1); |
466 |
+ |
case 'C': /* color */ |
467 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
468 |
+ |
(*dev->comout)(dsc); |
469 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
470 |
+ |
colval(ptr->C,RED), |
471 |
+ |
colval(ptr->C,GRN), |
472 |
+ |
colval(ptr->C,BLU)); |
473 |
+ |
(*dev->comout)(buf); |
474 |
+ |
(*dev->comin)(buf, NULL); |
475 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
476 |
+ |
return(0); |
477 |
+ |
} |
478 |
+ |
setcolor(ptr->C, d0, d1, d2); |
479 |
+ |
return(1); |
480 |
+ |
} |
481 |
+ |
} |
482 |
+ |
|
483 |
+ |
|
484 |
|
setparam(s) /* get/set program parameter */ |
485 |
|
register char *s; |
486 |
|
{ |
493 |
|
extern double shadcert; |
494 |
|
extern COLOR ambval; |
495 |
|
extern double ambacc; |
327 |
– |
extern double minarad; |
496 |
|
extern int ambres; |
497 |
|
extern int ambdiv; |
498 |
|
extern int ambssamp; |
499 |
|
extern int ambounce; |
500 |
< |
int i0; |
501 |
< |
double d0, d1, d2; |
500 |
> |
extern COLOR cextinction; |
501 |
> |
extern double salbedo; |
502 |
> |
extern double seccg; |
503 |
> |
extern double ssampdist; |
504 |
> |
extern int directvis; |
505 |
> |
extern double srcsizerat; |
506 |
> |
extern int do_irrad; |
507 |
> |
extern double specjitter; |
508 |
> |
extern double specthresh; |
509 |
> |
extern int backvis; |
510 |
|
char buf[128]; |
511 |
|
|
512 |
|
if (s[0] == '\0') { |
513 |
< |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
513 |
> |
(*dev->comout)( |
514 |
> |
"aa ab ad ar as av 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 |
|
} |
519 |
|
case 'l': /* limit */ |
520 |
|
switch (s[1]) { |
521 |
|
case 'w': /* weight */ |
522 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
346 |
< |
sprintf(buf, "limit weight (%.6g): ", |
347 |
< |
minweight); |
348 |
< |
(*dev->comout)(buf); |
349 |
< |
(*dev->comin)(buf, NULL); |
350 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
351 |
< |
break; |
352 |
< |
} |
353 |
< |
minweight = d0; |
522 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
523 |
|
break; |
524 |
|
case 'r': /* reflection */ |
525 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
357 |
< |
sprintf(buf, "limit reflection (%d): ", |
358 |
< |
maxdepth); |
359 |
< |
(*dev->comout)(buf); |
360 |
< |
(*dev->comin)(buf, NULL); |
361 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
362 |
< |
break; |
363 |
< |
} |
364 |
< |
maxdepth = i0; |
525 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
526 |
|
break; |
527 |
|
default: |
528 |
|
goto badparam; |
531 |
|
case 'd': /* direct */ |
532 |
|
switch (s[1]) { |
533 |
|
case 'j': /* jitter */ |
534 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
374 |
< |
sprintf(buf, "direct jitter (%.6g): ", |
375 |
< |
dstrsrc); |
376 |
< |
(*dev->comout)(buf); |
377 |
< |
(*dev->comin)(buf, NULL); |
378 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
379 |
< |
break; |
380 |
< |
} |
381 |
< |
dstrsrc = d0; |
534 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
535 |
|
break; |
536 |
|
case 'c': /* certainty */ |
537 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
385 |
< |
sprintf(buf, "direct certainty (%.6g): ", |
386 |
< |
shadcert); |
387 |
< |
(*dev->comout)(buf); |
388 |
< |
(*dev->comin)(buf, NULL); |
389 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
390 |
< |
break; |
391 |
< |
} |
392 |
< |
shadcert = d0; |
537 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
538 |
|
break; |
539 |
|
case 't': /* threshold */ |
540 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
396 |
< |
sprintf(buf, "direct threshold (%.6g): ", |
397 |
< |
shadthresh); |
398 |
< |
(*dev->comout)(buf); |
399 |
< |
(*dev->comin)(buf, NULL); |
400 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
401 |
< |
break; |
402 |
< |
} |
403 |
< |
shadthresh = d0; |
540 |
> |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
541 |
|
break; |
542 |
+ |
case 'v': /* visibility */ |
543 |
+ |
getparam(s+2, "direct visibility", |
544 |
+ |
'b', &directvis); |
545 |
+ |
break; |
546 |
+ |
case 's': /* sampling */ |
547 |
+ |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
548 |
+ |
break; |
549 |
|
default: |
550 |
|
goto badparam; |
551 |
|
} |
552 |
|
break; |
553 |
+ |
case 'b': /* back faces or black and white */ |
554 |
+ |
switch (s[1]) { |
555 |
+ |
case 'v': /* back face visibility */ |
556 |
+ |
getparam(s+2, "back face visibility", 'b', &backvis); |
557 |
+ |
break; |
558 |
+ |
case '\0': /* black and white */ |
559 |
+ |
case ' ': |
560 |
+ |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
561 |
+ |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
562 |
+ |
getparam(s+1, "black and white", 'b', &greyscale); |
563 |
+ |
break; |
564 |
+ |
default: |
565 |
+ |
goto badparam; |
566 |
+ |
} |
567 |
+ |
break; |
568 |
+ |
case 'i': /* irradiance */ |
569 |
+ |
getparam(s+1, "irradiance", 'b', &do_irrad); |
570 |
+ |
break; |
571 |
|
case 'a': /* ambient */ |
572 |
|
switch (s[1]) { |
573 |
|
case 'v': /* value */ |
574 |
< |
if (sscanf(s+2, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
413 |
< |
sprintf(buf, |
414 |
< |
"ambient value (%.6g %.6g %.6g): ", |
415 |
< |
colval(ambval,RED), |
416 |
< |
colval(ambval,GRN), |
417 |
< |
colval(ambval,BLU)); |
418 |
< |
(*dev->comout)(buf); |
419 |
< |
(*dev->comin)(buf, NULL); |
420 |
< |
if (sscanf(buf, "%lf %lf %lf", |
421 |
< |
&d0, &d1, &d2) != 3) |
422 |
< |
break; |
423 |
< |
} |
424 |
< |
setcolor(ambval, d0, d1, d2); |
574 |
> |
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
575 |
|
break; |
576 |
|
case 'a': /* accuracy */ |
577 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
578 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
429 |
< |
ambacc); |
430 |
< |
(*dev->comout)(buf); |
431 |
< |
(*dev->comin)(buf, NULL); |
432 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
433 |
< |
break; |
434 |
< |
} |
435 |
< |
ambacc = d0; |
577 |
> |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
578 |
> |
setambacc(ambacc); |
579 |
|
break; |
580 |
|
case 'd': /* divisions */ |
581 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
439 |
< |
sprintf(buf, "ambient divisions (%d): ", |
440 |
< |
ambdiv); |
441 |
< |
(*dev->comout)(buf); |
442 |
< |
(*dev->comin)(buf, NULL); |
443 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
444 |
< |
break; |
445 |
< |
} |
446 |
< |
ambdiv = i0; |
581 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
582 |
|
break; |
583 |
|
case 's': /* samples */ |
584 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
450 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
451 |
< |
ambssamp); |
452 |
< |
(*dev->comout)(buf); |
453 |
< |
(*dev->comin)(buf, NULL); |
454 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
455 |
< |
break; |
456 |
< |
} |
457 |
< |
ambssamp = i0; |
584 |
> |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
585 |
|
break; |
586 |
|
case 'b': /* bounces */ |
587 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
461 |
< |
sprintf(buf, "ambient bounces (%d): ", |
462 |
< |
ambounce); |
463 |
< |
(*dev->comout)(buf); |
464 |
< |
(*dev->comin)(buf, NULL); |
465 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
466 |
< |
break; |
467 |
< |
} |
468 |
< |
ambounce = i0; |
587 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
588 |
|
break; |
589 |
|
case 'r': |
590 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
591 |
< |
sprintf(buf, "ambient resolution (%d): ", |
473 |
< |
ambres); |
474 |
< |
(*dev->comout)(buf); |
475 |
< |
(*dev->comin)(buf, NULL); |
476 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
477 |
< |
break; |
478 |
< |
} |
479 |
< |
ambres = i0; |
480 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
590 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
591 |
> |
setambres(ambres); |
592 |
|
break; |
593 |
|
default: |
594 |
|
goto badparam; |
595 |
|
} |
596 |
|
break; |
597 |
< |
case 's': /* sample */ |
597 |
> |
case 'm': /* medium */ |
598 |
|
switch (s[1]) { |
599 |
< |
case 'p': /* pixel */ |
600 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
601 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
491 |
< |
(*dev->comout)(buf); |
492 |
< |
(*dev->comin)(buf, NULL); |
493 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
494 |
< |
break; |
495 |
< |
} |
496 |
< |
psample = i0; |
497 |
< |
pdepth = 0; |
599 |
> |
case 'e': /* extinction coefficient */ |
600 |
> |
getparam(s+2, "extinction coefficient", 'C', |
601 |
> |
(COLOR *)cextinction); |
602 |
|
break; |
603 |
+ |
case 'a': /* scattering albedo */ |
604 |
+ |
getparam(s+2, "scattering albedo", 'r', &salbedo); |
605 |
+ |
break; |
606 |
+ |
case 'g': /* scattering eccentricity */ |
607 |
+ |
getparam(s+2, "scattering eccentricity", 'r', &seccg); |
608 |
+ |
break; |
609 |
+ |
case 's': /* sampling distance */ |
610 |
+ |
getparam(s+2, "mist sampling distance", 'r', |
611 |
+ |
&ssampdist); |
612 |
+ |
break; |
613 |
+ |
default: |
614 |
+ |
goto badparam; |
615 |
+ |
} |
616 |
+ |
break; |
617 |
+ |
case 'p': /* pixel */ |
618 |
+ |
switch (s[1]) { |
619 |
+ |
case 's': /* sample */ |
620 |
+ |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
621 |
+ |
pdepth = 0; |
622 |
+ |
break; |
623 |
|
case 't': /* threshold */ |
624 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
625 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
502 |
< |
maxdiff); |
503 |
< |
(*dev->comout)(buf); |
504 |
< |
(*dev->comin)(buf, NULL); |
505 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
506 |
< |
break; |
507 |
< |
} |
508 |
< |
maxdiff = d0; |
509 |
< |
pdepth = 0; |
624 |
> |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
625 |
> |
pdepth = 0; |
626 |
|
break; |
627 |
|
default: |
628 |
|
goto badparam; |
629 |
|
} |
630 |
|
break; |
631 |
+ |
case 's': /* specular */ |
632 |
+ |
switch (s[1]) { |
633 |
+ |
case 'j': /* jitter */ |
634 |
+ |
getparam(s+2, "specular jitter", 'r', &specjitter); |
635 |
+ |
break; |
636 |
+ |
case 't': /* threshold */ |
637 |
+ |
getparam(s+2, "specular threshold", 'r', &specthresh); |
638 |
+ |
break; |
639 |
+ |
default: |
640 |
+ |
goto badparam; |
641 |
+ |
} |
642 |
+ |
break; |
643 |
|
case '\0': /* nothing */ |
644 |
|
break; |
645 |
|
default:; |
646 |
|
badparam: |
647 |
+ |
*sskip(s) = '\0'; |
648 |
|
sprintf(errmsg, "%s: unknown variable", s); |
649 |
|
error(COMMAND, errmsg); |
650 |
|
break; |
659 |
|
int x, y; |
660 |
|
RAY thisray; |
661 |
|
|
662 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
534 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
535 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
662 |
> |
thisray.rmax = 0.0; |
663 |
|
|
664 |
+ |
if (!sscanvec(s, thisray.rorg) || |
665 |
+ |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
666 |
+ |
|
667 |
|
if (dev->getcur == NULL) |
668 |
|
return; |
669 |
|
(*dev->comout)("Pick ray\n"); |
670 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
671 |
|
return; |
672 |
|
|
673 |
< |
viewray(thisray.rorg, thisray.rdir, &ourview, |
674 |
< |
(x+.5)/hresolu, (y+.5)/vresolu); |
675 |
< |
|
673 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
674 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
675 |
> |
error(COMMAND, "not on image"); |
676 |
> |
return; |
677 |
> |
} |
678 |
> |
|
679 |
|
} else if (normalize(thisray.rdir) == 0.0) { |
680 |
|
error(COMMAND, "zero ray direction"); |
681 |
|
return; |
688 |
|
if (thisray.ro == NULL) |
689 |
|
(*dev->comout)("ray hit nothing"); |
690 |
|
else { |
691 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
692 |
< |
objptr(thisray.ro->omod)->oname, |
691 |
> |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
692 |
> |
thisray.rod < 0.0 ? "back of " : "", |
693 |
> |
thisray.ro->omod == OVOID ? VOIDID : |
694 |
> |
objptr(thisray.ro->omod)->oname, |
695 |
|
ofun[thisray.ro->otype].funame, |
696 |
|
thisray.ro->oname); |
697 |
|
(*dev->comout)(buf); |
699 |
|
if (thisray.rot >= FHUGE) |
700 |
|
(*dev->comout)("at infinity"); |
701 |
|
else { |
702 |
< |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
703 |
< |
thisray.rop[1], thisray.rop[2]); |
702 |
> |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
703 |
> |
thisray.rop[0], thisray.rop[1], |
704 |
> |
thisray.rop[2], thisray.rt); |
705 |
|
(*dev->comout)(buf); |
706 |
|
} |
707 |
|
(*dev->comin)(buf, NULL); |
708 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
708 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
709 |
|
colval(thisray.rcol,RED), |
710 |
|
colval(thisray.rcol,GRN), |
711 |
< |
colval(thisray.rcol,BLU)); |
711 |
> |
colval(thisray.rcol,BLU), |
712 |
> |
luminance(thisray.rcol)); |
713 |
|
(*dev->comout)(buf); |
714 |
|
} |
715 |
|
(*dev->comin)(buf, NULL); |
725 |
|
COLR *scanline; |
726 |
|
int y; |
727 |
|
|
728 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
728 |
> |
while (isspace(*s)) |
729 |
> |
s++; |
730 |
> |
if (*s) |
731 |
> |
atos(buf, sizeof(buf), s); |
732 |
> |
else if (buf[0] == '\0') { |
733 |
|
error(COMMAND, "no file"); |
734 |
|
return; |
735 |
|
} |
739 |
|
error(COMMAND, errmsg); |
740 |
|
return; |
741 |
|
} |
742 |
+ |
#ifdef MSDOS |
743 |
+ |
setmode(fileno(fp), O_BINARY); |
744 |
+ |
#endif |
745 |
|
(*dev->comout)("writing \""); |
746 |
|
(*dev->comout)(fname); |
747 |
|
(*dev->comout)("\"...\n"); |
748 |
|
/* write header */ |
749 |
+ |
newheader("RADIANCE", fp); |
750 |
|
fputs(progname, fp); |
751 |
|
fprintview(&ourview, fp); |
752 |
< |
putc('\n', fp); |
752 |
> |
if (octname != NULL) |
753 |
> |
fprintf(fp, " %s\n", octname); |
754 |
> |
else |
755 |
> |
putc('\n', fp); |
756 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
757 |
|
if (exposure != 1.0) |
758 |
|
fputexpos(exposure, fp); |
759 |
|
if (dev->pixaspect != 1.0) |
760 |
|
fputaspect(dev->pixaspect, fp); |
761 |
+ |
fputformat(COLRFMT, fp); |
762 |
|
putc('\n', fp); |
763 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
763 |
> |
fprtresolu(hresolu, vresolu, fp); |
764 |
|
|
765 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
766 |
< |
if (scanline == NULL) |
767 |
< |
error(SYSTEM, "out of memory in writepict"); |
766 |
> |
if (scanline == NULL) { |
767 |
> |
error(COMMAND, "not enough memory!"); |
768 |
> |
fclose(fp); |
769 |
> |
unlink(fname); |
770 |
> |
return; |
771 |
> |
} |
772 |
|
for (y = vresolu-1; y >= 0; y--) { |
773 |
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
774 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
775 |
|
break; |
776 |
|
} |
777 |
+ |
free((char *)scanline); |
778 |
|
if (fclose(fp) < 0) |
779 |
|
error(COMMAND, "write error"); |
625 |
– |
free((char *)scanline); |
780 |
|
} |