1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1993 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; |
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 { |
144 |
|
ourview.hoff, ourview.voff); |
145 |
|
(*dev->comout)(buf); |
146 |
|
(*dev->comin)(buf, NULL); |
147 |
< |
if (buf[0] == CTRL(C)) return; |
147 |
> |
if (buf[0] == CTRL('C')) return; |
148 |
|
if (sscanf(buf, "%lf %lf", &nv.hoff, &nv.voff) == 2) |
149 |
|
change++; |
150 |
|
else { |
165 |
|
|
166 |
|
if (sscanf(s, "%s", buf) == 1) { /* get parameters from a file */ |
167 |
|
copystruct(&nv, &stdview); |
168 |
< |
if ((fname = getpath(buf, NULL, 0)) == NULL || |
169 |
< |
(success = viewfile(fname, &nv, 0, 0)) == -1) { |
168 |
> |
if ((fname = getpath(buf, "", R_OK)) == NULL || |
169 |
> |
(success = viewfile(fname, &nv, NULL)) == -1) { |
170 |
|
sprintf(errmsg, "cannot open \"%s\"", buf); |
171 |
|
error(COMMAND, errmsg); |
172 |
|
return; |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
+ |
saveview(s) /* save view to rad file */ |
192 |
+ |
char *s; |
193 |
+ |
{ |
194 |
+ |
char view[64]; |
195 |
+ |
char *fname; |
196 |
+ |
FILE *fp; |
197 |
+ |
|
198 |
+ |
if (*atos(view, sizeof(view), s)) { |
199 |
+ |
if (isint(view)) { |
200 |
+ |
error(COMMAND, "cannot write view by number"); |
201 |
+ |
return; |
202 |
+ |
} |
203 |
+ |
s = sskip(s); |
204 |
+ |
} |
205 |
+ |
while (isspace(*s)) |
206 |
+ |
s++; |
207 |
+ |
if (*s) |
208 |
+ |
atos(rifname, sizeof(rifname), s); |
209 |
+ |
else if (rifname[0] == '\0') { |
210 |
+ |
error(COMMAND, "no previous rad file"); |
211 |
+ |
return; |
212 |
+ |
} |
213 |
+ |
if ((fname = getpath(rifname, NULL, 0)) == NULL || |
214 |
+ |
(fp = fopen(fname, "a")) == NULL) { |
215 |
+ |
sprintf(errmsg, "cannot open \"%s\"", rifname); |
216 |
+ |
error(COMMAND, errmsg); |
217 |
+ |
return; |
218 |
+ |
} |
219 |
+ |
fputs("view= ", fp); |
220 |
+ |
fputs(view, fp); |
221 |
+ |
fprintview(&ourview, fp); |
222 |
+ |
putc('\n', fp); |
223 |
+ |
fclose(fp); |
224 |
+ |
} |
225 |
+ |
|
226 |
+ |
|
227 |
+ |
loadview(s) /* load view from rad file */ |
228 |
+ |
char *s; |
229 |
+ |
{ |
230 |
+ |
char buf[512]; |
231 |
+ |
char *fname; |
232 |
+ |
FILE *fp; |
233 |
+ |
VIEW nv; |
234 |
+ |
|
235 |
+ |
strcpy(buf, "rad -n -s -V -v "); |
236 |
+ |
if (sscanf(s, "%s", buf+strlen(buf)) == 1) |
237 |
+ |
s = sskip(s); |
238 |
+ |
else |
239 |
+ |
strcat(buf, "1"); |
240 |
+ |
if (*s) |
241 |
+ |
atos(rifname, sizeof(rifname), s); |
242 |
+ |
else if (rifname[0] == '\0') { |
243 |
+ |
error(COMMAND, "no previous rad file"); |
244 |
+ |
return; |
245 |
+ |
} |
246 |
+ |
if ((fname = getpath(rifname, "", R_OK)) == NULL) { |
247 |
+ |
sprintf(errmsg, "cannot access \"%s\"", rifname); |
248 |
+ |
error(COMMAND, errmsg); |
249 |
+ |
return; |
250 |
+ |
} |
251 |
+ |
sprintf(buf+strlen(buf), " %s", fname); |
252 |
+ |
if ((fp = popen(buf, "r")) == NULL) { |
253 |
+ |
error(COMMAND, "cannot run rad"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
+ |
buf[0] = '\0'; |
257 |
+ |
fgets(buf, sizeof(buf), fp); |
258 |
+ |
pclose(fp); |
259 |
+ |
copystruct(&nv, &stdview); |
260 |
+ |
if (!sscanview(&nv, buf)) { |
261 |
+ |
error(COMMAND, "rad error -- no such view?"); |
262 |
+ |
return; |
263 |
+ |
} |
264 |
+ |
newview(&nv); |
265 |
+ |
} |
266 |
+ |
|
267 |
+ |
|
268 |
|
getaim(s) /* aim camera */ |
269 |
|
char *s; |
270 |
|
{ |
170 |
– |
extern double tan(), atan(); |
271 |
|
double zfact; |
272 |
|
VIEW nv; |
273 |
|
|
298 |
|
getrotate(s) /* rotate camera */ |
299 |
|
char *s; |
300 |
|
{ |
201 |
– |
extern double normalize(), tan(), atan(); |
301 |
|
VIEW nv; |
302 |
|
FVECT v1; |
303 |
|
double angle, elev, zfact; |
343 |
|
getexposure(s) /* get new exposure */ |
344 |
|
char *s; |
345 |
|
{ |
247 |
– |
double atof(), pow(), fabs(); |
346 |
|
char buf[128]; |
347 |
|
register char *cp; |
250 |
– |
register PNODE *p; |
348 |
|
RECT r; |
349 |
|
int x, y; |
350 |
< |
double e; |
351 |
< |
|
350 |
> |
register PNODE *p = &ptrunk; |
351 |
> |
int adapt = 0; |
352 |
> |
double e = 1.0; |
353 |
> |
start: |
354 |
|
for (cp = s; isspace(*cp); cp++) |
355 |
|
; |
356 |
+ |
if (*cp == '@') { |
357 |
+ |
adapt++; |
358 |
+ |
goto start; |
359 |
+ |
} |
360 |
|
if (*cp == '\0') { /* normalize to point */ |
361 |
|
if (dev->getcur == NULL) |
362 |
|
return; |
366 |
|
r.l = r.d = 0; |
367 |
|
r.r = hresolu; r.u = vresolu; |
368 |
|
p = findrect(x, y, &ptrunk, &r, -1); |
266 |
– |
e = 1.0; |
369 |
|
} else { |
370 |
|
if (*cp == '=') { /* absolute setting */ |
371 |
|
p = NULL; |
373 |
|
for (cp++; isspace(*cp); cp++) |
374 |
|
; |
375 |
|
if (*cp == '\0') { /* interactive */ |
376 |
< |
sprintf(buf, "exposure (%lf): ", exposure); |
376 |
> |
sprintf(buf, "exposure (%f): ", exposure); |
377 |
|
(*dev->comout)(buf); |
378 |
|
(*dev->comin)(buf, NULL); |
379 |
|
for (cp = buf; isspace(*cp); cp++) |
381 |
|
if (*cp == '\0') |
382 |
|
return; |
383 |
|
} |
282 |
– |
} else { /* normalize to average */ |
283 |
– |
p = &ptrunk; |
284 |
– |
e = 1.0; |
384 |
|
} |
385 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
386 |
|
e *= pow(2.0, atof(cp)); |
388 |
|
e *= atof(cp); |
389 |
|
} |
390 |
|
if (p != NULL) { /* relative setting */ |
391 |
< |
if (bright(p->v) <= FTINY) { |
391 |
> |
if (bright(p->v) < 1e-15) { |
392 |
|
error(COMMAND, "cannot normalize to zero"); |
393 |
|
return; |
394 |
|
} |
395 |
< |
e *= 0.5 / bright(p->v); |
395 |
> |
if (adapt) |
396 |
> |
e *= 106./pow(1.219+pow(luminance(p->v)/exposure,.4),2.5)/exposure; |
397 |
> |
else |
398 |
> |
e *= 0.5 / bright(p->v); |
399 |
|
} |
400 |
|
if (e <= FTINY || fabs(1.0 - e) <= FTINY) |
401 |
|
return; |
423 |
|
(*dev->comout)(buf); |
424 |
|
(*dev->comin)(buf, NULL); |
425 |
|
if (sscanf(buf, "%d", &i0) != 1) |
426 |
< |
break; |
426 |
> |
return(0); |
427 |
|
} |
428 |
|
ptr->i = i0; |
429 |
< |
break; |
429 |
> |
return(1); |
430 |
|
case 'r': /* real */ |
431 |
|
if (sscanf(str, "%lf", &d0) != 1) { |
432 |
|
(*dev->comout)(dsc); |
434 |
|
(*dev->comout)(buf); |
435 |
|
(*dev->comin)(buf, NULL); |
436 |
|
if (sscanf(buf, "%lf", &d0) != 1) |
437 |
< |
break; |
437 |
> |
return(0); |
438 |
|
} |
439 |
|
ptr->d = d0; |
440 |
< |
break; |
440 |
> |
return(1); |
441 |
|
case 'b': /* boolean */ |
442 |
|
if (sscanf(str, "%1s", buf) != 1) { |
443 |
|
(*dev->comout)(dsc); |
444 |
< |
sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n'); |
444 |
> |
sprintf(buf, "? (%c): ", ptr->i ? 'y' : 'n'); |
445 |
|
(*dev->comout)(buf); |
446 |
|
(*dev->comin)(buf, NULL); |
447 |
|
if (buf[0] == '\0' || |
448 |
|
index("yY+1tTnN-0fF", buf[0]) == NULL) |
449 |
< |
break; |
449 |
> |
return(0); |
450 |
|
} |
451 |
|
ptr->i = index("yY+1tT", buf[0]) != NULL; |
452 |
< |
break; |
452 |
> |
return(1); |
453 |
|
case 'C': /* color */ |
454 |
|
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
455 |
|
(*dev->comout)(dsc); |
460 |
|
(*dev->comout)(buf); |
461 |
|
(*dev->comin)(buf, NULL); |
462 |
|
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
463 |
< |
break; |
463 |
> |
return(0); |
464 |
|
} |
465 |
|
setcolor(ptr->C, d0, d1, d2); |
466 |
< |
break; |
466 |
> |
return(1); |
467 |
|
} |
468 |
|
} |
469 |
|
|
480 |
|
extern double shadcert; |
481 |
|
extern COLOR ambval; |
482 |
|
extern double ambacc; |
381 |
– |
extern double minarad; |
483 |
|
extern int ambres; |
484 |
|
extern int ambdiv; |
485 |
|
extern int ambssamp; |
486 |
|
extern int ambounce; |
487 |
< |
extern int directinvis; |
487 |
> |
extern int directvis; |
488 |
|
extern double srcsizerat; |
489 |
|
extern int do_irrad; |
490 |
+ |
extern double specjitter; |
491 |
+ |
extern double specthresh; |
492 |
|
char buf[128]; |
493 |
|
|
494 |
|
if (s[0] == '\0') { |
495 |
|
(*dev->comout)( |
496 |
< |
"aa ab ad ar as av b dc di dj dt i lr lw sp st: "); |
496 |
> |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: "); |
497 |
|
(*dev->comin)(buf, NULL); |
498 |
|
s = buf; |
499 |
|
} |
521 |
|
case 't': /* threshold */ |
522 |
|
getparam(s+2, "direct threshold", 'r', &shadthresh); |
523 |
|
break; |
524 |
< |
case 'i': /* invisibility */ |
525 |
< |
getparam(s+2, "direct invisibility", |
526 |
< |
'b', &directinvis); |
524 |
> |
case 'v': /* visibility */ |
525 |
> |
getparam(s+2, "direct visibility", |
526 |
> |
'b', &directvis); |
527 |
|
break; |
528 |
|
case 's': /* sampling */ |
529 |
|
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
541 |
|
case 'a': /* ambient */ |
542 |
|
switch (s[1]) { |
543 |
|
case 'v': /* value */ |
544 |
< |
getparam(s+2, "ambient value", 'C', ambval); |
544 |
> |
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
545 |
|
break; |
546 |
|
case 'a': /* accuracy */ |
547 |
< |
getparam(s+2, "ambient accuracy", 'r', &ambacc); |
547 |
> |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
548 |
> |
setambacc(ambacc); |
549 |
|
break; |
550 |
|
case 'd': /* divisions */ |
551 |
|
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
557 |
|
getparam(s+2, "ambient bounces", 'i', &ambounce); |
558 |
|
break; |
559 |
|
case 'r': |
560 |
< |
getparam(s+2, "ambient resolution", 'i', &ambres); |
561 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
560 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
561 |
> |
setambres(ambres); |
562 |
|
break; |
563 |
|
default: |
564 |
|
goto badparam; |
565 |
|
} |
566 |
|
break; |
567 |
< |
case 's': /* sample */ |
567 |
> |
case 'p': /* pixel */ |
568 |
|
switch (s[1]) { |
569 |
< |
case 'p': /* pixel */ |
570 |
< |
getparam(s+2, "sample pixel", 'i', &psample); |
571 |
< |
pdepth = 0; |
569 |
> |
case 's': /* sample */ |
570 |
> |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
571 |
> |
pdepth = 0; |
572 |
|
break; |
573 |
|
case 't': /* threshold */ |
574 |
< |
getparam(s+2, "sample threshold", 'r', &maxdiff); |
575 |
< |
pdepth = 0; |
574 |
> |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
575 |
> |
pdepth = 0; |
576 |
|
break; |
577 |
|
default: |
578 |
|
goto badparam; |
579 |
|
} |
580 |
|
break; |
581 |
+ |
case 's': /* specular */ |
582 |
+ |
switch (s[1]) { |
583 |
+ |
case 'j': /* jitter */ |
584 |
+ |
getparam(s+2, "specular jitter", 'r', &specjitter); |
585 |
+ |
break; |
586 |
+ |
case 't': /* threshold */ |
587 |
+ |
getparam(s+2, "specular threshold", 'r', &specthresh); |
588 |
+ |
break; |
589 |
+ |
default: |
590 |
+ |
goto badparam; |
591 |
+ |
} |
592 |
+ |
break; |
593 |
|
case '\0': /* nothing */ |
594 |
|
break; |
595 |
|
default:; |
609 |
|
int x, y; |
610 |
|
RAY thisray; |
611 |
|
|
612 |
< |
if (sscanf(s, "%lf %lf %lf %lf %lf %lf", |
613 |
< |
&thisray.rorg[0], &thisray.rorg[1], &thisray.rorg[2], |
498 |
< |
&thisray.rdir[0], &thisray.rdir[1], &thisray.rdir[2]) != 6) { |
612 |
> |
if (!sscanvec(s, thisray.rorg) || |
613 |
> |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
614 |
|
|
615 |
|
if (dev->getcur == NULL) |
616 |
|
return; |
636 |
|
if (thisray.ro == NULL) |
637 |
|
(*dev->comout)("ray hit nothing"); |
638 |
|
else { |
639 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
640 |
< |
objptr(thisray.ro->omod)->oname, |
639 |
> |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
640 |
> |
thisray.rod < 0.0 ? "back of " : "", |
641 |
> |
thisray.ro->omod == OVOID ? VOIDID : |
642 |
> |
objptr(thisray.ro->omod)->oname, |
643 |
|
ofun[thisray.ro->otype].funame, |
644 |
|
thisray.ro->oname); |
645 |
|
(*dev->comout)(buf); |
652 |
|
(*dev->comout)(buf); |
653 |
|
} |
654 |
|
(*dev->comin)(buf, NULL); |
655 |
< |
sprintf(buf, "with value (%.6g %.6g %.6g)", |
655 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
656 |
|
colval(thisray.rcol,RED), |
657 |
|
colval(thisray.rcol,GRN), |
658 |
< |
colval(thisray.rcol,BLU)); |
658 |
> |
colval(thisray.rcol,BLU), |
659 |
> |
luminance(thisray.rcol)); |
660 |
|
(*dev->comout)(buf); |
661 |
|
} |
662 |
|
(*dev->comin)(buf, NULL); |
672 |
|
COLR *scanline; |
673 |
|
int y; |
674 |
|
|
675 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
675 |
> |
while (isspace(*s)) |
676 |
> |
s++; |
677 |
> |
if (*s) |
678 |
> |
atos(buf, sizeof(buf), s); |
679 |
> |
else if (buf[0] == '\0') { |
680 |
|
error(COMMAND, "no file"); |
681 |
|
return; |
682 |
|
} |
686 |
|
error(COMMAND, errmsg); |
687 |
|
return; |
688 |
|
} |
689 |
+ |
#ifdef MSDOS |
690 |
+ |
setmode(fileno(fp), O_BINARY); |
691 |
+ |
#endif |
692 |
|
(*dev->comout)("writing \""); |
693 |
|
(*dev->comout)(fname); |
694 |
|
(*dev->comout)("\"...\n"); |
695 |
|
/* write header */ |
696 |
+ |
newheader("RADIANCE", fp); |
697 |
|
fputs(progname, fp); |
698 |
|
fprintview(&ourview, fp); |
699 |
|
if (octname != NULL) |
707 |
|
fputaspect(dev->pixaspect, fp); |
708 |
|
fputformat(COLRFMT, fp); |
709 |
|
putc('\n', fp); |
710 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
710 |
> |
fprtresolu(hresolu, vresolu, fp); |
711 |
|
|
712 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
713 |
|
if (scanline == NULL) { |