1 |
< |
/* Copyright (c) 1992 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"; |
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; |
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 |
|
} |
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); |
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 || |
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); |
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 |
|
{ |
286 |
|
nv.type = ourview.type; |
287 |
|
VCOPY(nv.vp, ourview.vp); |
288 |
|
VCOPY(nv.vup, ourview.vup); |
197 |
– |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
289 |
|
nv.horiz = ourview.horiz; nv.vert = ourview.vert; |
290 |
+ |
nv.vfore = ourview.vfore; nv.vaft = ourview.vaft; |
291 |
+ |
nv.hoff = ourview.hoff; nv.voff = ourview.voff; |
292 |
|
zoomview(&nv, zfact); |
293 |
|
newview(&nv); |
294 |
|
} |
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); |
346 |
|
error(COMMAND, "missing angle"); |
347 |
|
return; |
348 |
|
} |
349 |
< |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
349 |
> |
if (getinterest(sskip2(s,2), 0, vc, &mag) < 0) |
350 |
|
return; |
351 |
|
moveview(angle, elev, mag, vc); |
352 |
|
} |
357 |
|
{ |
358 |
|
char buf[128]; |
359 |
|
register char *cp; |
266 |
– |
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); |
282 |
– |
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 |
|
} |
298 |
– |
} else { /* normalize to average */ |
299 |
– |
p = &ptrunk; |
300 |
– |
e = 1.0; |
397 |
|
} |
398 |
|
if (*cp == '+' || *cp == '-') /* f-stops */ |
399 |
|
e *= pow(2.0, atof(cp)); |
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; |
492 |
|
extern double shadthresh; |
493 |
|
extern double shadcert; |
494 |
|
extern COLOR ambval; |
495 |
+ |
extern int ambvwt; |
496 |
|
extern double ambacc; |
497 |
|
extern int ambres; |
498 |
|
extern int ambdiv; |
499 |
|
extern int ambssamp; |
500 |
|
extern int ambounce; |
501 |
+ |
extern COLOR cextinction; |
502 |
+ |
extern double salbedo; |
503 |
+ |
extern double seccg; |
504 |
+ |
extern double ssampdist; |
505 |
|
extern int directvis; |
506 |
|
extern double srcsizerat; |
507 |
|
extern int do_irrad; |
508 |
|
extern double specjitter; |
509 |
|
extern double specthresh; |
510 |
+ |
extern int backvis; |
511 |
|
char buf[128]; |
512 |
|
|
513 |
|
if (s[0] == '\0') { |
514 |
|
(*dev->comout)( |
515 |
< |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st: "); |
515 |
> |
"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: "); |
516 |
|
(*dev->comin)(buf, NULL); |
517 |
|
s = buf; |
518 |
|
} |
551 |
|
goto badparam; |
552 |
|
} |
553 |
|
break; |
554 |
< |
case 'b': /* black and white */ |
555 |
< |
getparam(s+1, "black and white", 'b', &greyscale); |
554 |
> |
case 'b': /* back faces or black and white */ |
555 |
> |
switch (s[1]) { |
556 |
> |
case 'v': /* back face visibility */ |
557 |
> |
getparam(s+2, "back face visibility", 'b', &backvis); |
558 |
> |
break; |
559 |
> |
case '\0': /* black and white */ |
560 |
> |
case ' ': |
561 |
> |
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
562 |
> |
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
563 |
> |
getparam(s+1, "black and white", 'b', &greyscale); |
564 |
> |
break; |
565 |
> |
default: |
566 |
> |
goto badparam; |
567 |
> |
} |
568 |
|
break; |
569 |
|
case 'i': /* irradiance */ |
570 |
|
getparam(s+1, "irradiance", 'b', &do_irrad); |
574 |
|
case 'v': /* value */ |
575 |
|
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
576 |
|
break; |
577 |
+ |
case 'w': /* weight */ |
578 |
+ |
getparam(s+2, "ambient value weight", 'i', &ambvwt); |
579 |
+ |
break; |
580 |
|
case 'a': /* accuracy */ |
581 |
< |
getparam(s+2, "ambient accuracy", 'r', &ambacc); |
581 |
> |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
582 |
> |
setambacc(ambacc); |
583 |
|
break; |
584 |
|
case 'd': /* divisions */ |
585 |
|
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
598 |
|
goto badparam; |
599 |
|
} |
600 |
|
break; |
601 |
+ |
case 'm': /* medium */ |
602 |
+ |
switch (s[1]) { |
603 |
+ |
case 'e': /* extinction coefficient */ |
604 |
+ |
getparam(s+2, "extinction coefficient", 'C', |
605 |
+ |
(COLOR *)cextinction); |
606 |
+ |
break; |
607 |
+ |
case 'a': /* scattering albedo */ |
608 |
+ |
getparam(s+2, "scattering albedo", 'r', &salbedo); |
609 |
+ |
break; |
610 |
+ |
case 'g': /* scattering eccentricity */ |
611 |
+ |
getparam(s+2, "scattering eccentricity", 'r', &seccg); |
612 |
+ |
break; |
613 |
+ |
case 's': /* sampling distance */ |
614 |
+ |
getparam(s+2, "mist sampling distance", 'r', |
615 |
+ |
&ssampdist); |
616 |
+ |
break; |
617 |
+ |
default: |
618 |
+ |
goto badparam; |
619 |
+ |
} |
620 |
+ |
break; |
621 |
|
case 'p': /* pixel */ |
622 |
|
switch (s[1]) { |
623 |
|
case 's': /* sample */ |
663 |
|
int x, y; |
664 |
|
RAY thisray; |
665 |
|
|
666 |
+ |
thisray.rmax = 0.0; |
667 |
+ |
|
668 |
|
if (!sscanvec(s, thisray.rorg) || |
669 |
< |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
669 |
> |
!sscanvec(sskip2(s,3), thisray.rdir)) { |
670 |
|
|
671 |
|
if (dev->getcur == NULL) |
672 |
|
return; |
674 |
|
if ((*dev->getcur)(&x, &y) == ABORT) |
675 |
|
return; |
676 |
|
|
677 |
< |
if (viewray(thisray.rorg, thisray.rdir, &ourview, |
678 |
< |
(x+.5)/hresolu, (y+.5)/vresolu) < 0) { |
677 |
> |
if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, |
678 |
> |
&ourview, (x+.5)/hresolu, (y+.5)/vresolu)) < -FTINY) { |
679 |
|
error(COMMAND, "not on image"); |
680 |
|
return; |
681 |
|
} |
692 |
|
if (thisray.ro == NULL) |
693 |
|
(*dev->comout)("ray hit nothing"); |
694 |
|
else { |
695 |
< |
sprintf(buf, "ray hit %s %s \"%s\"", |
696 |
< |
objptr(thisray.ro->omod)->oname, |
695 |
> |
sprintf(buf, "ray hit %s%s %s \"%s\"", |
696 |
> |
thisray.rod < 0.0 ? "back of " : "", |
697 |
> |
thisray.ro->omod == OVOID ? VOIDID : |
698 |
> |
objptr(thisray.ro->omod)->oname, |
699 |
|
ofun[thisray.ro->otype].funame, |
700 |
|
thisray.ro->oname); |
701 |
|
(*dev->comout)(buf); |
703 |
|
if (thisray.rot >= FHUGE) |
704 |
|
(*dev->comout)("at infinity"); |
705 |
|
else { |
706 |
< |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
707 |
< |
thisray.rop[1], thisray.rop[2]); |
706 |
> |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
707 |
> |
thisray.rop[0], thisray.rop[1], |
708 |
> |
thisray.rop[2], thisray.rt); |
709 |
|
(*dev->comout)(buf); |
710 |
|
} |
711 |
|
(*dev->comin)(buf, NULL); |
729 |
|
COLR *scanline; |
730 |
|
int y; |
731 |
|
|
732 |
< |
if (sscanf(s, "%s", buf) != 1 && buf[0] == '\0') { |
732 |
> |
while (isspace(*s)) |
733 |
> |
s++; |
734 |
> |
if (*s) |
735 |
> |
atos(buf, sizeof(buf), s); |
736 |
> |
else if (buf[0] == '\0') { |
737 |
|
error(COMMAND, "no file"); |
738 |
|
return; |
739 |
|
} |
750 |
|
(*dev->comout)(fname); |
751 |
|
(*dev->comout)("\"...\n"); |
752 |
|
/* write header */ |
753 |
+ |
newheader("RADIANCE", fp); |
754 |
|
fputs(progname, fp); |
755 |
|
fprintview(&ourview, fp); |
756 |
|
if (octname != NULL) |