1 |
< |
/* Copyright (c) 1987 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1994 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) { |
90 |
|
fputs(progname, fp); |
91 |
|
fprintview(&ourview, fp); |
92 |
|
fputs(sskip(s), fp); |
93 |
< |
fputs("\n", 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; |
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 |
|
{ |
168 |
– |
extern double tan(), atan(); |
281 |
|
double zfact; |
282 |
|
VIEW nv; |
283 |
|
|
308 |
|
getrotate(s) /* rotate camera */ |
309 |
|
char *s; |
310 |
|
{ |
199 |
– |
extern double normalize(), tan(), atan(); |
311 |
|
VIEW nv; |
312 |
|
FVECT v1; |
313 |
|
double angle, elev, zfact; |
353 |
|
getexposure(s) /* get new exposure */ |
354 |
|
char *s; |
355 |
|
{ |
245 |
– |
double atof(), pow(), fabs(); |
356 |
|
char buf[128]; |
357 |
|
register char *cp; |
248 |
– |
register PNODE *p; |
358 |
|
RECT r; |
359 |
|
int x, y; |
360 |
< |
double e; |
360 |
> |
register PNODE *p = &ptrunk; |
361 |
> |
int adapt = 0; |
362 |
> |
double e = 1.0; |
363 |
|
|
364 |
|
for (cp = s; isspace(*cp); cp++) |
365 |
|
; |
366 |
+ |
if (*cp == '@') { |
367 |
+ |
adapt++; |
368 |
+ |
while (isspace(*++cp)) |
369 |
+ |
; |
370 |
+ |
} |
371 |
|
if (*cp == '\0') { /* normalize to point */ |
372 |
|
if (dev->getcur == NULL) |
373 |
|
return; |
377 |
|
r.l = r.d = 0; |
378 |
|
r.r = hresolu; r.u = vresolu; |
379 |
|
p = findrect(x, y, &ptrunk, &r, -1); |
264 |
– |
e = 1.0; |
380 |
|
} else { |
381 |
|
if (*cp == '=') { /* absolute setting */ |
382 |
|
p = NULL; |
384 |
|
for (cp++; isspace(*cp); cp++) |
385 |
|
; |
386 |
|
if (*cp == '\0') { /* interactive */ |
387 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
387 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
388 |
|
(*dev->comout)(buf); |
389 |
|
(*dev->comin)(buf, NULL); |
390 |
|
for (cp = buf; isspace(*cp); cp++) |
392 |
|
if (*cp == '\0') |
393 |
|
return; |
394 |
|
} |
280 |
– |
} else { /* normalize to average */ |
281 |
– |
p = &ptrunk; |
282 |
– |
e = 1.0; |
395 |
|
} |
396 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
397 |
|
e *= pow(2.0, atof(cp)); |
399 |
|
e *= atof(cp); |
400 |
|
} |
401 |
|
if (p != NULL) { /* relative setting */ |
402 |
< |
if (bright(p->v) <= FTINY) { |
402 |
> |
if (bright(p->v) < 1e-15) { |
403 |
|
error(COMMAND, "cannot normalize to zero"); |
404 |
|
return; |
405 |
|
} |
406 |
< |
e *= 0.5 / bright(p->v); |
406 |
> |
if (adapt) |
407 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
408 |
> |
else |
409 |
> |
e *= 0.5 / bright(p->v); |
410 |
|
} |
411 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
412 |
|
return; |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
+ |
getparam(str, dsc, typ, ptr) /* get variable from user */ |
420 |
+ |
char *str, *dsc; |
421 |
+ |
int typ; |
422 |
+ |
register union {int i; double d; COLOR C;} *ptr; |
423 |
+ |
{ |
424 |
+ |
extern char *index(); |
425 |
+ |
int i0; |
426 |
+ |
double d0, d1, d2; |
427 |
+ |
char buf[48]; |
428 |
+ |
|
429 |
+ |
switch (typ) { |
430 |
+ |
case 'i': /* integer */ |
431 |
+ |
if (sscanf(str, "%d", &i0) != 1) { |
432 |
+ |
(*dev->comout)(dsc); |
433 |
+ |
sprintf(buf, " (%d): ", ptr->i); |
434 |
+ |
(*dev->comout)(buf); |
435 |
+ |
(*dev->comin)(buf, NULL); |
436 |
+ |
if (sscanf(buf, "%d", &i0) != 1) |
437 |
+ |
return(0); |
438 |
+ |
} |
439 |
+ |
ptr->i = i0; |
440 |
+ |
return(1); |
441 |
+ |
case 'r': /* real */ |
442 |
+ |
if (sscanf(str, "%lf", &d0) != 1) { |
443 |
+ |
(*dev->comout)(dsc); |
444 |
+ |
sprintf(buf, " (%.6g): ", ptr->d); |
445 |
+ |
(*dev->comout)(buf); |
446 |
+ |
(*dev->comin)(buf, NULL); |
447 |
+ |
if (sscanf(buf, "%lf", &d0) != 1) |
448 |
+ |
return(0); |
449 |
+ |
} |
450 |
+ |
ptr->d = d0; |
451 |
+ |
return(1); |
452 |
+ |
case 'b': /* boolean */ |
453 |
+ |
if (sscanf(str, "%1s", buf) != 1) { |
454 |
+ |
(*dev->comout)(dsc); |
455 |
+ |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
456 |
+ |
(*dev->comout)(buf); |
457 |
+ |
(*dev->comin)(buf, NULL); |
458 |
+ |
if (buf[0] == '\0' || |
459 |
+ |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
460 |
+ |
return(0); |
461 |
+ |
} |
462 |
+ |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
463 |
+ |
return(1); |
464 |
+ |
case 'C': /* color */ |
465 |
+ |
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
466 |
+ |
(*dev->comout)(dsc); |
467 |
+ |
sprintf(buf, " (%.6g %.6g %.6g): ", |
468 |
+ |
colval(ptr->C,RED), |
469 |
+ |
colval(ptr->C,GRN), |
470 |
+ |
colval(ptr->C,BLU)); |
471 |
+ |
(*dev->comout)(buf); |
472 |
+ |
(*dev->comin)(buf, NULL); |
473 |
+ |
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
474 |
+ |
return(0); |
475 |
+ |
} |
476 |
+ |
setcolor(ptr->C, d0, d1, d2); |
477 |
+ |
return(1); |
478 |
+ |
} |
479 |
+ |
} |
480 |
+ |
|
481 |
+ |
|
482 |
|
setparam(s) /* get/set program parameter */ |
483 |
|
register char *s; |
484 |
|
{ |
491 |
|
extern double shadcert; |
492 |
|
extern COLOR ambval; |
493 |
|
extern double ambacc; |
316 |
– |
extern double minarad; |
494 |
|
extern int ambres; |
495 |
|
extern int ambdiv; |
496 |
|
extern int ambssamp; |
497 |
|
extern int ambounce; |
498 |
< |
int i0; |
499 |
< |
double d0, d1, d2; |
498 |
> |
extern int directvis; |
499 |
> |
extern double srcsizerat; |
500 |
> |
extern int do_irrad; |
501 |
> |
extern double specjitter; |
502 |
> |
extern double specthresh; |
503 |
> |
extern int backvis; |
504 |
|
char buf[128]; |
505 |
|
|
506 |
|
if (s[0] == '\0') { |
507 |
< |
(*dev->comout)("aa ab ad ar as av dc dj dt lr lw sp st: "); |
507 |
> |
(*dev->comout)( |
508 |
> |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st bv: "); |
509 |
|
(*dev->comin)(buf, NULL); |
510 |
|
s = buf; |
511 |
|
} |
513 |
|
case 'l': /* limit */ |
514 |
|
switch (s[1]) { |
515 |
|
case 'w': /* weight */ |
516 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
335 |
< |
sprintf(buf, "limit weight (%.6g): ", |
336 |
< |
minweight); |
337 |
< |
(*dev->comout)(buf); |
338 |
< |
(*dev->comin)(buf, NULL); |
339 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
340 |
< |
break; |
341 |
< |
} |
342 |
< |
minweight = d0; |
516 |
> |
getparam(s+2, "limit weight", 'r', &minweight); |
517 |
|
break; |
518 |
|
case 'r': /* reflection */ |
519 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
346 |
< |
sprintf(buf, "limit reflection (%d): ", |
347 |
< |
maxdepth); |
348 |
< |
(*dev->comout)(buf); |
349 |
< |
(*dev->comin)(buf, NULL); |
350 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
351 |
< |
break; |
352 |
< |
} |
353 |
< |
maxdepth = i0; |
519 |
> |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
520 |
|
break; |
521 |
|
default: |
522 |
|
goto badparam; |
525 |
|
case 'd': /* direct */ |
526 |
|
switch (s[1]) { |
527 |
|
case 'j': /* jitter */ |
528 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
363 |
< |
sprintf(buf, "direct jitter (%.6g): ", |
364 |
< |
dstrsrc); |
365 |
< |
(*dev->comout)(buf); |
366 |
< |
(*dev->comin)(buf, NULL); |
367 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
368 |
< |
break; |
369 |
< |
} |
370 |
< |
dstrsrc = d0; |
528 |
> |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
529 |
|
break; |
530 |
|
case 'c': /* certainty */ |
531 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
374 |
< |
sprintf(buf, "direct certainty (%.6g): ", |
375 |
< |
shadcert); |
376 |
< |
(*dev->comout)(buf); |
377 |
< |
(*dev->comin)(buf, NULL); |
378 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
379 |
< |
break; |
380 |
< |
} |
381 |
< |
shadcert = d0; |
531 |
> |
getparam(s+2, "direct certainty", 'r', &shadcert); |
532 |
|
break; |
533 |
|
case 't': /* threshold */ |
534 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
385 |
< |
sprintf(buf, "direct threshold (%.6g): ", |
386 |
< |
shadthresh); |
387 |
< |
(*dev->comout)(buf); |
388 |
< |
(*dev->comin)(buf, NULL); |
389 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
390 |
< |
break; |
391 |
< |
} |
392 |
< |
shadthresh = d0; |
534 |
> |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
535 |
|
break; |
536 |
+ |
case 'v': /* visibility */ |
537 |
+ |
getparam(s+2, "direct visibility", |
538 |
+ |
'b', &directvis); |
539 |
+ |
break; |
540 |
+ |
case 's': /* sampling */ |
541 |
+ |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
542 |
+ |
break; |
543 |
|
default: |
544 |
|
goto badparam; |
545 |
|
} |
546 |
|
break; |
547 |
+ |
case 'b': /* back faces or black and white */ |
548 |
+ |
switch (s[1]) { |
549 |
+ |
case 'v': /* back face visibility */ |
550 |
+ |
getparam(s+2, "back face visibility", 'b', &backvis); |
551 |
+ |
break; |
552 |
+ |
case '\0': /* black and white */ |
553 |
+ |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
554 |
+ |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
555 |
+ |
getparam(s+1, "black and white", 'b', &greyscale); |
556 |
+ |
break; |
557 |
+ |
default: |
558 |
+ |
goto badparam; |
559 |
+ |
} |
560 |
+ |
break; |
561 |
+ |
case 'i': /* irradiance */ |
562 |
+ |
getparam(s+1, "irradiance", 'b', &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) { |
402 |
< |
sprintf(buf, |
403 |
< |
"ambient value (%.6g %.6g %.6g): ", |
404 |
< |
colval(ambval,RED), |
405 |
< |
colval(ambval,GRN), |
406 |
< |
colval(ambval,BLU)); |
407 |
< |
(*dev->comout)(buf); |
408 |
< |
(*dev->comin)(buf, NULL); |
409 |
< |
if (sscanf(buf, "%lf %lf %lf", |
410 |
< |
&d0, &d1, &d2) != 3) |
411 |
< |
break; |
412 |
< |
} |
413 |
< |
setcolor(ambval, d0, d1, d2); |
567 |
> |
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
568 |
|
break; |
569 |
|
case 'a': /* accuracy */ |
570 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
571 |
< |
sprintf(buf, "ambient accuracy (%.6g): ", |
418 |
< |
ambacc); |
419 |
< |
(*dev->comout)(buf); |
420 |
< |
(*dev->comin)(buf, NULL); |
421 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
422 |
< |
break; |
423 |
< |
} |
424 |
< |
ambacc = d0; |
570 |
> |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
571 |
> |
setambacc(ambacc); |
572 |
|
break; |
573 |
|
case 'd': /* divisions */ |
574 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
428 |
< |
sprintf(buf, "ambient divisions (%d): ", |
429 |
< |
ambdiv); |
430 |
< |
(*dev->comout)(buf); |
431 |
< |
(*dev->comin)(buf, NULL); |
432 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
433 |
< |
break; |
434 |
< |
} |
435 |
< |
ambdiv = i0; |
574 |
> |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
575 |
|
break; |
576 |
|
case 's': /* samples */ |
577 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
439 |
< |
sprintf(buf, "ambient super-samples (%d): ", |
440 |
< |
ambssamp); |
441 |
< |
(*dev->comout)(buf); |
442 |
< |
(*dev->comin)(buf, NULL); |
443 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
444 |
< |
break; |
445 |
< |
} |
446 |
< |
ambssamp = i0; |
577 |
> |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
578 |
|
break; |
579 |
|
case 'b': /* bounces */ |
580 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
450 |
< |
sprintf(buf, "ambient bounces (%d): ", |
451 |
< |
ambounce); |
452 |
< |
(*dev->comout)(buf); |
453 |
< |
(*dev->comin)(buf, NULL); |
454 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
455 |
< |
break; |
456 |
< |
} |
457 |
< |
ambounce = i0; |
580 |
> |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
581 |
|
break; |
582 |
|
case 'r': |
583 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
584 |
< |
sprintf(buf, "ambient resolution (%d): ", |
462 |
< |
ambres); |
463 |
< |
(*dev->comout)(buf); |
464 |
< |
(*dev->comin)(buf, NULL); |
465 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
466 |
< |
break; |
467 |
< |
} |
468 |
< |
ambres = i0; |
469 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
583 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
584 |
> |
setambres(ambres); |
585 |
|
break; |
586 |
|
default: |
587 |
|
goto badparam; |
588 |
|
} |
589 |
|
break; |
590 |
< |
case 's': /* sample */ |
590 |
> |
case 'p': /* pixel */ |
591 |
|
switch (s[1]) { |
592 |
< |
case 'p': /* pixel */ |
593 |
< |
if (sscanf(s+2, "%d", &i0) != 1) { |
594 |
< |
sprintf(buf, "sample pixel (%d): ", psample); |
480 |
< |
(*dev->comout)(buf); |
481 |
< |
(*dev->comin)(buf, NULL); |
482 |
< |
if (sscanf(buf, "%d", &i0) != 1) |
483 |
< |
break; |
484 |
< |
} |
485 |
< |
psample = i0; |
486 |
< |
pdepth = 0; |
592 |
> |
case 's': /* sample */ |
593 |
> |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
594 |
> |
pdepth = 0; |
595 |
|
break; |
596 |
|
case 't': /* threshold */ |
597 |
< |
if (sscanf(s+2, "%lf", &d0) != 1) { |
598 |
< |
sprintf(buf, "sample threshold (%.6g): ", |
491 |
< |
maxdiff); |
492 |
< |
(*dev->comout)(buf); |
493 |
< |
(*dev->comin)(buf, NULL); |
494 |
< |
if (sscanf(buf, "%lf", &d0) != 1) |
495 |
< |
break; |
496 |
< |
} |
497 |
< |
maxdiff = d0; |
498 |
< |
pdepth = 0; |
597 |
> |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
598 |
> |
pdepth = 0; |
599 |
|
break; |
600 |
|
default: |
601 |
|
goto badparam; |
602 |
|
} |
603 |
|
break; |
604 |
+ |
case 's': /* specular */ |
605 |
+ |
switch (s[1]) { |
606 |
+ |
case 'j': /* jitter */ |
607 |
+ |
getparam(s+2, "specular jitter", 'r', &specjitter); |
608 |
+ |
break; |
609 |
+ |
case 't': /* threshold */ |
610 |
+ |
getparam(s+2, "specular threshold", 'r', &specthresh); |
611 |
+ |
break; |
612 |
+ |
default: |
613 |
+ |
goto badparam; |
614 |
+ |
} |
615 |
+ |
break; |
616 |
|
case '\0': /* nothing */ |
617 |
|
break; |
618 |
|
default:; |
619 |
|
badparam: |
620 |
+ |
*sskip(s) = '\0'; |
621 |
|
sprintf(errmsg, "%s: unknown variable", s); |
622 |
|
error(COMMAND, errmsg); |
623 |
|
break; |
632 |
|
int x, y; |
633 |
|
RAY thisray; |
634 |
|
|
635 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
523 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
524 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
635 |
> |
thisray.rmax = 0.0; |
636 |
|
|
637 |
+ |
if (!sscanvec(s, thisray.rorg) || |
638 |
+ |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
639 |
+ |
|
640 |
|
if (dev->getcur == NULL) |
641 |
|
return; |
642 |
|
(*dev->comout)("Pick ray\n"); |
643 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
644 |
|
return; |
645 |
|
|
646 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
647 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
646 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
647 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
648 |
|
error(COMMAND, "not on image"); |
649 |
|
return; |
650 |
|
} |
661 |
|
if (thisray.ro == NULL) |
662 |
|
(*dev->comout)("ray hit nothing"); |
663 |
|
else { |
664 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
665 |
< |
objptr(thisray.ro->omod)->oname, |
664 |
> |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
665 |
> |
thisray.rod < 0.0 ? "back of " : "", |
666 |
> |
thisray.ro->omod == OVOID ? VOIDID : |
667 |
> |
objptr(thisray.ro->omod)->oname, |
668 |
|
ofun[thisray.ro->otype].funame, |
669 |
|
thisray.ro->oname); |
670 |
|
(*dev->comout)(buf); |
677 |
|
(*dev->comout)(buf); |
678 |
|
} |
679 |
|
(*dev->comin)(buf, NULL); |
680 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
680 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
681 |
|
colval(thisray.rcol,RED), |
682 |
|
colval(thisray.rcol,GRN), |
683 |
< |
colval(thisray.rcol,BLU)); |
683 |
> |
colval(thisray.rcol,BLU), |
684 |
> |
luminance(thisray.rcol)); |
685 |
|
(*dev->comout)(buf); |
686 |
|
} |
687 |
|
(*dev->comin)(buf, NULL); |
697 |
|
COLR *scanline; |
698 |
|
int y; |
699 |
|
|
700 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
700 |
> |
while (isspace(*s)) |
701 |
> |
s++; |
702 |
> |
if (*s) |
703 |
> |
atos(buf, sizeof(buf), s); |
704 |
> |
else if (buf[0] == '\0') { |
705 |
|
error(COMMAND, "no file"); |
706 |
|
return; |
707 |
|
} |
711 |
|
error(COMMAND, errmsg); |
712 |
|
return; |
713 |
|
} |
714 |
+ |
#ifdef MSDOS |
715 |
+ |
setmode(fileno(fp), O_BINARY); |
716 |
+ |
#endif |
717 |
|
(*dev->comout)("writing \""); |
718 |
|
(*dev->comout)(fname); |
719 |
|
(*dev->comout)("\"...\n"); |
720 |
|
/* write header */ |
721 |
+ |
newheader("RADIANCE", fp); |
722 |
|
fputs(progname, fp); |
723 |
|
fprintview(&ourview, fp); |
724 |
< |
putc('\n', fp); |
724 |
> |
if (octname != NULL) |
725 |
> |
fprintf(fp, " %s\n", octname); |
726 |
> |
else |
727 |
> |
putc('\n', fp); |
728 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
729 |
|
if (exposure != 1.0) |
730 |
|
fputexpos(exposure, fp); |
731 |
|
if (dev->pixaspect != 1.0) |
732 |
|
fputaspect(dev->pixaspect, fp); |
733 |
|
fputformat(COLRFMT, fp); |
734 |
|
putc('\n', fp); |
735 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
735 |
> |
fprtresolu(hresolu, vresolu, fp); |
736 |
|
|
737 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
738 |
< |
if (scanline == NULL) |
739 |
< |
error(SYSTEM, "out of memory in writepict"); |
738 |
> |
if (scanline == NULL) { |
739 |
> |
error(COMMAND, "not enough memory!"); |
740 |
> |
fclose(fp); |
741 |
> |
unlink(fname); |
742 |
> |
return; |
743 |
> |
} |
744 |
|
for (y = vresolu-1; y >= 0; y--) { |
745 |
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
746 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
747 |
|
break; |
748 |
|
} |
749 |
+ |
free((char *)scanline); |
750 |
|
if (fclose(fp) < 0) |
751 |
|
error(COMMAND, "write error"); |
618 |
– |
free((char *)scanline); |
752 |
|
} |