| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include <stdio.h> |
| 12 |
+ |
#include <math.h> |
| 13 |
|
#include <string.h> |
| 14 |
|
#include "fvect.h" |
| 15 |
|
#include "object.h" |
| 16 |
|
#include "color.h" |
| 17 |
|
#include "lookup.h" |
| 18 |
|
|
| 19 |
+ |
#define PI 3.14159265358979323846 |
| 20 |
+ |
|
| 21 |
+ |
#define C_1SIDEDTHICK 0.005 |
| 22 |
+ |
|
| 23 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
| 24 |
|
int o_instance(), o_source(), o_illum(); |
| 25 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
| 25 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
| 26 |
> |
o_mirror(), o_trans(), o_light(); |
| 27 |
|
|
| 28 |
|
extern void free(); |
| 29 |
|
extern char *malloc(); |
| 39 |
|
|
| 40 |
|
#define hasmult (unit_mult < .999 || unit_mult > 1.001) |
| 41 |
|
|
| 42 |
+ |
/* |
| 43 |
+ |
* Stuff for tracking and reusing vertices: |
| 44 |
+ |
*/ |
| 45 |
|
|
| 46 |
+ |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
| 47 |
+ |
#define VKLEN 64 |
| 48 |
+ |
|
| 49 |
+ |
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
| 50 |
+ |
|
| 51 |
+ |
#define NVERTS 256 |
| 52 |
+ |
|
| 53 |
+ |
long vclock; /* incremented at each vertex request */ |
| 54 |
+ |
|
| 55 |
+ |
struct vert { |
| 56 |
+ |
long lused; /* when last used (0 if unassigned) */ |
| 57 |
+ |
FVECT p; /* track point position only */ |
| 58 |
+ |
} vert[NVERTS]; /* our vertex cache */ |
| 59 |
+ |
|
| 60 |
+ |
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
| 61 |
+ |
|
| 62 |
+ |
|
| 63 |
|
main(argc, argv) |
| 64 |
|
int argc; |
| 65 |
|
char **argv; |
| 86 |
|
goto unkopt; |
| 87 |
|
} |
| 88 |
|
break; |
| 89 |
+ |
default: |
| 90 |
+ |
goto unkopt; |
| 91 |
|
} |
| 92 |
|
init(); |
| 93 |
|
if (i >= argc) |
| 272 |
|
|
| 273 |
|
init() /* initialize dispatch table and output */ |
| 274 |
|
{ |
| 275 |
+ |
lu_init(&vertab, NVERTS); |
| 276 |
|
lu_init(&rdispatch, 22); |
| 277 |
|
add2dispatch("polygon", o_face); |
| 278 |
|
add2dispatch("cone", o_cone); |
| 288 |
|
add2dispatch("metal", o_metal); |
| 289 |
|
add2dispatch("metal2", o_metal); |
| 290 |
|
add2dispatch("glass", o_glass); |
| 291 |
+ |
add2dispatch("dielectric", o_dielectric); |
| 292 |
|
add2dispatch("trans", o_trans); |
| 293 |
|
add2dispatch("trans2", o_trans); |
| 294 |
|
add2dispatch("mirror", o_mirror); |
| 311 |
|
puts("# End of data converted from Radiance scene input"); |
| 312 |
|
lu_done(&rdispatch); |
| 313 |
|
lu_done(&rmats); |
| 314 |
+ |
lu_done(&vertab); |
| 315 |
|
} |
| 316 |
|
|
| 317 |
|
|
| 318 |
+ |
clrverts() /* clear vertex table */ |
| 319 |
+ |
{ |
| 320 |
+ |
register int i; |
| 321 |
+ |
|
| 322 |
+ |
lu_done(&vertab); |
| 323 |
+ |
for (i = 0; i < NVERTS; i++) |
| 324 |
+ |
vert[i].lused = 0; |
| 325 |
+ |
lu_init(&vertab, NVERTS); |
| 326 |
+ |
} |
| 327 |
+ |
|
| 328 |
+ |
|
| 329 |
|
add2dispatch(name, func) /* add function to dispatch table */ |
| 330 |
|
char *name; |
| 331 |
|
int (*func)(); |
| 343 |
|
} |
| 344 |
|
|
| 345 |
|
|
| 304 |
– |
/* |
| 305 |
– |
* Stuff for tracking and reusing vertices: |
| 306 |
– |
*/ |
| 307 |
– |
|
| 308 |
– |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
| 309 |
– |
#define VKLEN 64 |
| 310 |
– |
|
| 311 |
– |
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
| 312 |
– |
|
| 313 |
– |
#define NVERTS 256 |
| 314 |
– |
|
| 315 |
– |
long clock; /* incremented at each vertex request */ |
| 316 |
– |
|
| 317 |
– |
struct vert { |
| 318 |
– |
long lused; /* when last used (0 if unassigned) */ |
| 319 |
– |
FVECT p; /* track point position only */ |
| 320 |
– |
} vert[NVERTS]; |
| 321 |
– |
|
| 322 |
– |
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
| 323 |
– |
|
| 324 |
– |
|
| 346 |
|
char * |
| 347 |
|
getvertid(vname, vp) /* get/set vertex ID for this point */ |
| 348 |
|
char *vname; |
| 349 |
|
FVECT vp; |
| 350 |
|
{ |
| 351 |
< |
char vkey[VKLEN]; |
| 351 |
> |
static char vkey[VKLEN]; |
| 352 |
|
register LUENT *lp; |
| 353 |
|
register int i, vndx; |
| 354 |
|
|
| 355 |
< |
if (!vertab.tsiz && !lu_init(&vertab, NVERTS)) |
| 335 |
< |
goto memerr; |
| 336 |
< |
clock++; /* increment counter */ |
| 355 |
> |
vclock++; /* increment counter */ |
| 356 |
|
mkvkey(vkey, vp); |
| 357 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
| 358 |
|
goto memerr; |
| 372 |
|
mkvkey(vkey, vert[vndx].p); |
| 373 |
|
lu_delete(&vertab, vkey); |
| 374 |
|
} |
| 375 |
< |
vert[vndx].lused = clock; /* assign it */ |
| 357 |
< |
VCOPY(vert[vndx].p, vp); |
| 375 |
> |
VCOPY(vert[vndx].p, vp); /* assign it */ |
| 376 |
|
printf("v v%d =\n\tp %.15g %.15g %.15g\n", /* print it */ |
| 377 |
|
vndx, vp[0], vp[1], vp[2]); |
| 378 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
| 379 |
|
} else |
| 380 |
|
vndx = (struct vert *)lp->data - vert; |
| 381 |
+ |
vert[vndx].lused = vclock; /* record this use */ |
| 382 |
|
sprintf(vname, "v%d", vndx); |
| 383 |
|
return(vname); |
| 384 |
|
memerr: |
| 531 |
|
fputs(fa->sarg[i], stdout); |
| 532 |
|
} |
| 533 |
|
putchar('\n'); |
| 534 |
+ |
clrverts(); /* vertex id's no longer reliable */ |
| 535 |
|
return(0); |
| 536 |
|
} |
| 537 |
|
|
| 629 |
|
newmat(id, NULL); |
| 630 |
|
if (fa->nfargs == 4) |
| 631 |
|
nrfr = fa->farg[3]; |
| 632 |
+ |
printf("\tir %f 0\n", nrfr); |
| 633 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
| 634 |
|
F *= F; |
| 635 |
|
for (i = 0; i < 3; i++) { |
| 655 |
|
|
| 656 |
|
|
| 657 |
|
int |
| 658 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
| 659 |
+ |
char *mod, *typ, *id; |
| 660 |
+ |
register FUNARGS *fa; |
| 661 |
+ |
{ |
| 662 |
+ |
COLOR cxyz, trgb; |
| 663 |
+ |
double F, d; |
| 664 |
+ |
register int i; |
| 665 |
+ |
|
| 666 |
+ |
if (fa->nfargs != 5) |
| 667 |
+ |
return(-1); |
| 668 |
+ |
newmat(id, NULL); |
| 669 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
| 670 |
+ |
F *= F; |
| 671 |
+ |
for (i = 0; i < 3; i++) |
| 672 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
| 673 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
| 674 |
+ |
printf("\tsides 1\n"); |
| 675 |
+ |
puts("\tc"); /* put reflected component */ |
| 676 |
+ |
printf("\trs %.4f 0\n", F); |
| 677 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
| 678 |
+ |
puts("\tc"); |
| 679 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
| 680 |
+ |
if (d > FTINY) |
| 681 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
| 682 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
| 683 |
+ |
return(0); |
| 684 |
+ |
} |
| 685 |
+ |
|
| 686 |
+ |
|
| 687 |
+ |
int |
| 688 |
|
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
| 689 |
|
char *mod, *typ, *id; |
| 690 |
|
register FUNARGS *fa; |
| 766 |
|
puts("\tc"); |
| 767 |
|
if (d > FTINY) |
| 768 |
|
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
| 769 |
< |
printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); |
| 769 |
> |
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
| 770 |
|
return(0); |
| 771 |
|
} |