| 1 |
– |
/* Copyright (c) 1994 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 "otypes.h" |
| 18 |
– |
|
| 18 |
|
#include "rpaint.h" |
| 19 |
|
|
| 20 |
< |
#include "resolu.h" |
| 20 |
> |
extern int psample; /* pixel sample size */ |
| 21 |
> |
extern double maxdiff; /* max. sample difference */ |
| 22 |
|
|
| 23 |
– |
#include <ctype.h> |
| 24 |
– |
|
| 23 |
|
#define CTRL(c) ((c)-'@') |
| 24 |
|
|
| 25 |
|
#ifdef SMLFLT |
| 28 |
|
#define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) |
| 29 |
|
#endif |
| 30 |
|
|
| 33 |
– |
extern char *atos(); |
| 34 |
– |
|
| 35 |
– |
extern FILE *popen(); |
| 36 |
– |
|
| 31 |
|
extern char rifname[128]; /* rad input file name */ |
| 32 |
|
|
| 39 |
– |
extern char VersionID[]; |
| 33 |
|
extern char *progname; |
| 34 |
|
extern char *octname; |
| 35 |
|
|
| 36 |
|
|
| 37 |
+ |
void |
| 38 |
|
getframe(s) /* get a new frame */ |
| 39 |
|
char *s; |
| 40 |
|
{ |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
+ |
void |
| 48 |
|
getrepaint(s) /* get area and repaint */ |
| 49 |
|
char *s; |
| 50 |
|
{ |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
+ |
void |
| 60 |
|
getview(s) /* get/show view parameters */ |
| 61 |
|
char *s; |
| 62 |
|
{ |
| 161 |
|
} |
| 162 |
|
|
| 163 |
|
|
| 164 |
+ |
void |
| 165 |
|
lastview(s) /* return to a previous view */ |
| 166 |
|
char *s; |
| 167 |
|
{ |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|
| 198 |
+ |
void |
| 199 |
|
saveview(s) /* save view to rad file */ |
| 200 |
|
char *s; |
| 201 |
|
{ |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
|
| 235 |
+ |
void |
| 236 |
|
loadview(s) /* load view from rad file */ |
| 237 |
|
char *s; |
| 238 |
|
{ |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
|
| 277 |
+ |
void |
| 278 |
|
getaim(s) /* aim camera */ |
| 279 |
|
char *s; |
| 280 |
|
{ |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
+ |
void |
| 298 |
|
getmove(s) /* move camera */ |
| 299 |
|
char *s; |
| 300 |
|
{ |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
|
| 310 |
+ |
void |
| 311 |
|
getrotate(s) /* rotate camera */ |
| 312 |
|
char *s; |
| 313 |
|
{ |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
|
| 340 |
+ |
void |
| 341 |
|
getpivot(s) /* pivot viewpoint */ |
| 342 |
|
register char *s; |
| 343 |
|
{ |
| 349 |
|
error(COMMAND, "missing angle"); |
| 350 |
|
return; |
| 351 |
|
} |
| 352 |
< |
if (getinterest(sskip(sskip(s)), 0, vc, &mag) < 0) |
| 352 |
> |
if (getinterest(sskip2(s,2), 0, vc, &mag) < 0) |
| 353 |
|
return; |
| 354 |
|
moveview(angle, elev, mag, vc); |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 358 |
+ |
void |
| 359 |
|
getexposure(s) /* get new exposure */ |
| 360 |
|
char *s; |
| 361 |
|
{ |
| 421 |
|
redraw(); |
| 422 |
|
} |
| 423 |
|
|
| 424 |
+ |
typedef union {int i; double d; COLOR C;} *MyUptr; |
| 425 |
|
|
| 426 |
< |
getparam(str, dsc, typ, ptr) /* get variable from user */ |
| 426 |
> |
int |
| 427 |
> |
getparam(str, dsc, typ, p) /* get variable from user */ |
| 428 |
|
char *str, *dsc; |
| 429 |
|
int typ; |
| 430 |
< |
register union {int i; double d; COLOR C;} *ptr; |
| 430 |
> |
void *p; |
| 431 |
|
{ |
| 432 |
< |
extern char *index(); |
| 432 |
> |
register MyUptr ptr = (MyUptr)p; |
| 433 |
|
int i0; |
| 434 |
|
double d0, d1, d2; |
| 435 |
|
char buf[48]; |
| 464 |
|
(*dev->comout)(buf); |
| 465 |
|
(*dev->comin)(buf, NULL); |
| 466 |
|
if (buf[0] == '\0' || |
| 467 |
< |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
| 467 |
> |
strchr("yY+1tTnN-0fF", buf[0]) == NULL) |
| 468 |
|
return(0); |
| 469 |
|
} |
| 470 |
< |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
| 470 |
> |
ptr->i = strchr("yY+1tT", buf[0]) != NULL; |
| 471 |
|
return(1); |
| 472 |
|
case 'C': /* color */ |
| 473 |
|
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
| 487 |
|
} |
| 488 |
|
|
| 489 |
|
|
| 490 |
+ |
void |
| 491 |
|
setparam(s) /* get/set program parameter */ |
| 492 |
|
register char *s; |
| 493 |
|
{ |
| 487 |
– |
extern int psample; |
| 488 |
– |
extern double maxdiff; |
| 489 |
– |
extern double minweight; |
| 490 |
– |
extern int maxdepth; |
| 491 |
– |
extern double dstrsrc; |
| 492 |
– |
extern double shadthresh; |
| 493 |
– |
extern double shadcert; |
| 494 |
– |
extern COLOR ambval; |
| 495 |
– |
extern double ambacc; |
| 496 |
– |
extern int ambres; |
| 497 |
– |
extern int ambdiv; |
| 498 |
– |
extern int ambssamp; |
| 499 |
– |
extern int ambounce; |
| 500 |
– |
extern int directvis; |
| 501 |
– |
extern double srcsizerat; |
| 502 |
– |
extern int do_irrad; |
| 503 |
– |
extern double specjitter; |
| 504 |
– |
extern double specthresh; |
| 505 |
– |
extern int backvis; |
| 494 |
|
char buf[128]; |
| 495 |
|
|
| 496 |
|
if (s[0] == '\0') { |
| 497 |
|
(*dev->comout)( |
| 498 |
< |
"aa ab ad ar as av b dc di dj ds dt i lr lw ps pt sj st bv: "); |
| 498 |
> |
"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: "); |
| 499 |
|
(*dev->comin)(buf, NULL); |
| 500 |
|
s = buf; |
| 501 |
|
} |
| 503 |
|
case 'l': /* limit */ |
| 504 |
|
switch (s[1]) { |
| 505 |
|
case 'w': /* weight */ |
| 506 |
< |
getparam(s+2, "limit weight", 'r', &minweight); |
| 506 |
> |
getparam(s+2, "limit weight", 'r', |
| 507 |
> |
(void *)&minweight); |
| 508 |
|
break; |
| 509 |
|
case 'r': /* reflection */ |
| 510 |
< |
getparam(s+2, "limit reflection", 'i', &maxdepth); |
| 510 |
> |
getparam(s+2, "limit reflection", 'i', |
| 511 |
> |
(void *)&maxdepth); |
| 512 |
|
break; |
| 513 |
|
default: |
| 514 |
|
goto badparam; |
| 517 |
|
case 'd': /* direct */ |
| 518 |
|
switch (s[1]) { |
| 519 |
|
case 'j': /* jitter */ |
| 520 |
< |
getparam(s+2, "direct jitter", 'r', &dstrsrc); |
| 520 |
> |
getparam(s+2, "direct jitter", 'r', |
| 521 |
> |
(void *)&dstrsrc); |
| 522 |
|
break; |
| 523 |
|
case 'c': /* certainty */ |
| 524 |
< |
getparam(s+2, "direct certainty", 'r', &shadcert); |
| 524 |
> |
getparam(s+2, "direct certainty", 'r', |
| 525 |
> |
(void *)&shadcert); |
| 526 |
|
break; |
| 527 |
|
case 't': /* threshold */ |
| 528 |
< |
getparam(s+2, "direct threshold", 'r', &shadthresh); |
| 528 |
> |
getparam(s+2, "direct threshold", 'r', |
| 529 |
> |
(void *)&shadthresh); |
| 530 |
|
break; |
| 531 |
|
case 'v': /* visibility */ |
| 532 |
< |
getparam(s+2, "direct visibility", |
| 533 |
< |
'b', &directvis); |
| 532 |
> |
getparam(s+2, "direct visibility", 'b', |
| 533 |
> |
(void *)&directvis); |
| 534 |
|
break; |
| 535 |
|
case 's': /* sampling */ |
| 536 |
< |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
| 536 |
> |
getparam(s+2, "direct sampling", 'r', |
| 537 |
> |
(void *)&srcsizerat); |
| 538 |
|
break; |
| 539 |
|
default: |
| 540 |
|
goto badparam; |
| 543 |
|
case 'b': /* back faces or black and white */ |
| 544 |
|
switch (s[1]) { |
| 545 |
|
case 'v': /* back face visibility */ |
| 546 |
< |
getparam(s+2, "back face visibility", 'b', &backvis); |
| 546 |
> |
getparam(s+2, "back face visibility", 'b', |
| 547 |
> |
(void *)&backvis); |
| 548 |
|
break; |
| 549 |
|
case '\0': /* black and white */ |
| 550 |
|
case ' ': |
| 551 |
|
case 'y': case 'Y': case 't': case 'T': case '1': case '+': |
| 552 |
|
case 'n': case 'N': case 'f': case 'F': case '0': case '-': |
| 553 |
< |
getparam(s+1, "black and white", 'b', &greyscale); |
| 553 |
> |
getparam(s+1, "black and white", 'b', |
| 554 |
> |
(void *)&greyscale); |
| 555 |
|
break; |
| 556 |
|
default: |
| 557 |
|
goto badparam; |
| 558 |
|
} |
| 559 |
|
break; |
| 560 |
|
case 'i': /* irradiance */ |
| 561 |
< |
getparam(s+1, "irradiance", 'b', &do_irrad); |
| 561 |
> |
getparam(s+1, "irradiance", 'b', |
| 562 |
> |
(void *)&do_irrad); |
| 563 |
|
break; |
| 564 |
|
case 'a': /* ambient */ |
| 565 |
|
switch (s[1]) { |
| 566 |
|
case 'v': /* value */ |
| 567 |
< |
getparam(s+2, "ambient value", 'C', (COLOR *)ambval); |
| 567 |
> |
getparam(s+2, "ambient value", 'C', |
| 568 |
> |
(void *)ambval); |
| 569 |
|
break; |
| 570 |
+ |
case 'w': /* weight */ |
| 571 |
+ |
getparam(s+2, "ambient value weight", 'i', |
| 572 |
+ |
(void *)&ambvwt); |
| 573 |
+ |
break; |
| 574 |
|
case 'a': /* accuracy */ |
| 575 |
< |
if (getparam(s+2, "ambient accuracy", 'r', &ambacc)) |
| 575 |
> |
if (getparam(s+2, "ambient accuracy", 'r', |
| 576 |
> |
(void *)&ambacc)) |
| 577 |
|
setambacc(ambacc); |
| 578 |
|
break; |
| 579 |
|
case 'd': /* divisions */ |
| 580 |
< |
getparam(s+2, "ambient divisions", 'i', &ambdiv); |
| 580 |
> |
getparam(s+2, "ambient divisions", 'i', |
| 581 |
> |
(void *)&ambdiv); |
| 582 |
|
break; |
| 583 |
|
case 's': /* samples */ |
| 584 |
< |
getparam(s+2, "ambient super-samples", 'i', &ambssamp); |
| 584 |
> |
getparam(s+2, "ambient super-samples", 'i', |
| 585 |
> |
(void *)&ambssamp); |
| 586 |
|
break; |
| 587 |
|
case 'b': /* bounces */ |
| 588 |
< |
getparam(s+2, "ambient bounces", 'i', &ambounce); |
| 588 |
> |
getparam(s+2, "ambient bounces", 'i', |
| 589 |
> |
(void *)&ambounce); |
| 590 |
|
break; |
| 591 |
|
case 'r': |
| 592 |
< |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
| 592 |
> |
if (getparam(s+2, "ambient resolution", 'i', |
| 593 |
> |
(void *)&ambres)) |
| 594 |
|
setambres(ambres); |
| 595 |
|
break; |
| 596 |
|
default: |
| 597 |
|
goto badparam; |
| 598 |
|
} |
| 599 |
|
break; |
| 600 |
+ |
case 'm': /* medium */ |
| 601 |
+ |
switch (s[1]) { |
| 602 |
+ |
case 'e': /* extinction coefficient */ |
| 603 |
+ |
getparam(s+2, "extinction coefficient", 'C', |
| 604 |
+ |
(void *)cextinction); |
| 605 |
+ |
break; |
| 606 |
+ |
case 'a': /* scattering albedo */ |
| 607 |
+ |
getparam(s+2, "scattering albedo", 'C', |
| 608 |
+ |
(void *)salbedo); |
| 609 |
+ |
break; |
| 610 |
+ |
case 'g': /* scattering eccentricity */ |
| 611 |
+ |
getparam(s+2, "scattering eccentricity", 'r', |
| 612 |
+ |
(void *)&seccg); |
| 613 |
+ |
break; |
| 614 |
+ |
case 's': /* sampling distance */ |
| 615 |
+ |
getparam(s+2, "mist sampling distance", 'r', |
| 616 |
+ |
(void *)&ssampdist); |
| 617 |
+ |
break; |
| 618 |
+ |
default: |
| 619 |
+ |
goto badparam; |
| 620 |
+ |
} |
| 621 |
+ |
break; |
| 622 |
|
case 'p': /* pixel */ |
| 623 |
|
switch (s[1]) { |
| 624 |
|
case 's': /* sample */ |
| 625 |
< |
if (getparam(s+2, "pixel sample", 'i', &psample)) |
| 625 |
> |
if (getparam(s+2, "pixel sample", 'i', |
| 626 |
> |
(void *)&psample)) |
| 627 |
|
pdepth = 0; |
| 628 |
|
break; |
| 629 |
|
case 't': /* threshold */ |
| 630 |
< |
if (getparam(s+2, "pixel threshold", 'r', &maxdiff)) |
| 630 |
> |
if (getparam(s+2, "pixel threshold", 'r', |
| 631 |
> |
(void *)&maxdiff)) |
| 632 |
|
pdepth = 0; |
| 633 |
|
break; |
| 634 |
|
default: |
| 638 |
|
case 's': /* specular */ |
| 639 |
|
switch (s[1]) { |
| 640 |
|
case 'j': /* jitter */ |
| 641 |
< |
getparam(s+2, "specular jitter", 'r', &specjitter); |
| 641 |
> |
getparam(s+2, "specular jitter", 'r', |
| 642 |
> |
(void *)&specjitter); |
| 643 |
|
break; |
| 644 |
|
case 't': /* threshold */ |
| 645 |
< |
getparam(s+2, "specular threshold", 'r', &specthresh); |
| 645 |
> |
getparam(s+2, "specular threshold", 'r', |
| 646 |
> |
(void *)&specthresh); |
| 647 |
|
break; |
| 648 |
|
default: |
| 649 |
|
goto badparam; |
| 661 |
|
} |
| 662 |
|
|
| 663 |
|
|
| 664 |
+ |
void |
| 665 |
|
traceray(s) /* trace a single ray */ |
| 666 |
|
char *s; |
| 667 |
|
{ |
| 668 |
|
char buf[128]; |
| 669 |
|
int x, y; |
| 670 |
+ |
OBJREC *ino; |
| 671 |
|
RAY thisray; |
| 672 |
|
|
| 673 |
|
thisray.rmax = 0.0; |
| 674 |
|
|
| 675 |
|
if (!sscanvec(s, thisray.rorg) || |
| 676 |
< |
!sscanvec(sskip(sskip(sskip(s))), thisray.rdir)) { |
| 676 |
> |
!sscanvec(sskip2(s,3), thisray.rdir)) { |
| 677 |
|
|
| 678 |
|
if (dev->getcur == NULL) |
| 679 |
|
return; |
| 705 |
|
objptr(thisray.ro->omod)->oname, |
| 706 |
|
ofun[thisray.ro->otype].funame, |
| 707 |
|
thisray.ro->oname); |
| 708 |
+ |
if ((ino = objptr(thisray.robj)) != thisray.ro) |
| 709 |
+ |
sprintf(buf+strlen(buf), " in %s \"%s\"", |
| 710 |
+ |
ofun[ino->otype].funame, ino->oname); |
| 711 |
|
(*dev->comout)(buf); |
| 712 |
|
(*dev->comin)(buf, NULL); |
| 713 |
|
if (thisray.rot >= FHUGE) |
| 714 |
|
(*dev->comout)("at infinity"); |
| 715 |
|
else { |
| 716 |
< |
sprintf(buf, "at (%.6g %.6g %.6g)", thisray.rop[0], |
| 717 |
< |
thisray.rop[1], thisray.rop[2]); |
| 716 |
> |
sprintf(buf, "at (%.6g %.6g %.6g) (%.6g)", |
| 717 |
> |
thisray.rop[0], thisray.rop[1], |
| 718 |
> |
thisray.rop[2], thisray.rt); |
| 719 |
|
(*dev->comout)(buf); |
| 720 |
|
} |
| 721 |
|
(*dev->comin)(buf, NULL); |
| 722 |
< |
sprintf(buf, "value (%.5g %.5g %.5g) (%.1fL)", |
| 722 |
> |
sprintf(buf, "value (%.5g %.5g %.5g) (%.3gL)", |
| 723 |
|
colval(thisray.rcol,RED), |
| 724 |
|
colval(thisray.rcol,GRN), |
| 725 |
|
colval(thisray.rcol,BLU), |
| 730 |
|
} |
| 731 |
|
|
| 732 |
|
|
| 733 |
+ |
void |
| 734 |
|
writepict(s) /* write the picture to a file */ |
| 735 |
|
char *s; |
| 736 |
|
{ |
| 754 |
|
error(COMMAND, errmsg); |
| 755 |
|
return; |
| 756 |
|
} |
| 757 |
< |
#ifdef MSDOS |
| 718 |
< |
setmode(fileno(fp), O_BINARY); |
| 719 |
< |
#endif |
| 757 |
> |
SET_FILE_BINARY(fp); |
| 758 |
|
(*dev->comout)("writing \""); |
| 759 |
|
(*dev->comout)(fname); |
| 760 |
|
(*dev->comout)("\"...\n"); |
| 767 |
|
else |
| 768 |
|
putc('\n', fp); |
| 769 |
|
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
| 770 |
+ |
fputnow(fp); |
| 771 |
|
if (exposure != 1.0) |
| 772 |
|
fputexpos(exposure, fp); |
| 773 |
|
if (dev->pixaspect != 1.0) |
| 788 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
| 789 |
|
break; |
| 790 |
|
} |
| 791 |
< |
free((char *)scanline); |
| 791 |
> |
free((void *)scanline); |
| 792 |
|
if (fclose(fp) < 0) |
| 793 |
|
error(COMMAND, "write error"); |
| 794 |
|
} |