1 |
< |
/* Copyright (c) 1994 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"; |
9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#include <math.h> |
13 |
+ |
#include <ctype.h> |
14 |
|
#include <string.h> |
15 |
|
#include "fvect.h" |
16 |
|
#include "object.h" |
17 |
|
#include "color.h" |
18 |
|
#include "lookup.h" |
19 |
|
|
20 |
+ |
#define PI 3.14159265358979323846 |
21 |
+ |
|
22 |
+ |
#define C_1SIDEDTHICK 0.005 |
23 |
+ |
|
24 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
25 |
< |
int o_instance(), o_source(), o_illum(); |
26 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
25 |
> |
int o_instance(), o_illum(); |
26 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
27 |
> |
o_mirror(), o_trans(), o_light(); |
28 |
|
|
29 |
|
extern void free(); |
30 |
|
extern char *malloc(); |
40 |
|
|
41 |
|
#define hasmult (unit_mult < .999 || unit_mult > 1.001) |
42 |
|
|
43 |
+ |
/* |
44 |
+ |
* Stuff for tracking and reusing vertices: |
45 |
+ |
*/ |
46 |
|
|
47 |
+ |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
48 |
+ |
#define VKLEN 64 |
49 |
+ |
|
50 |
+ |
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
51 |
+ |
|
52 |
+ |
#define NVERTS 256 |
53 |
+ |
|
54 |
+ |
long vclock; /* incremented at each vertex request */ |
55 |
+ |
|
56 |
+ |
struct vert { |
57 |
+ |
long lused; /* when last used (0 if unassigned) */ |
58 |
+ |
FVECT p; /* track point position only */ |
59 |
+ |
} vert[NVERTS]; /* our vertex cache */ |
60 |
+ |
|
61 |
+ |
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
62 |
+ |
|
63 |
+ |
|
64 |
|
main(argc, argv) |
65 |
|
int argc; |
66 |
|
char **argv; |
87 |
|
goto unkopt; |
88 |
|
} |
89 |
|
break; |
90 |
+ |
default: |
91 |
+ |
goto unkopt; |
92 |
|
} |
93 |
|
init(); |
94 |
|
if (i >= argc) |
195 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
196 |
|
exit(1); |
197 |
|
} |
198 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
199 |
< |
newmat(id, mod); |
198 |
> |
} else { /* unsupported */ |
199 |
> |
o_unsupported(mod, typ, id, fa); |
200 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
201 |
> |
newmat(id, mod); |
202 |
> |
} |
203 |
|
} |
204 |
|
|
205 |
|
|
264 |
|
if (end == NULL) |
265 |
|
end = cp; |
266 |
|
/* copy to current object */ |
267 |
< |
for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) |
267 |
> |
cp2 = curobj; |
268 |
> |
if (!isalpha(*id)) { /* start with letter */ |
269 |
> |
diff = *cp2 != 'O'; |
270 |
> |
*cp2++ = 'O'; |
271 |
> |
} |
272 |
> |
for (cp = id; cp < end; *cp2++ = *cp++) { |
273 |
> |
if (*cp < '!' | *cp > '~') /* limit to visible chars */ |
274 |
> |
*cp = '?'; |
275 |
|
diff += *cp != *cp2; |
276 |
+ |
} |
277 |
|
if (!diff && !*cp2) |
278 |
|
return; |
279 |
|
*cp2 = '\0'; |
284 |
|
|
285 |
|
init() /* initialize dispatch table and output */ |
286 |
|
{ |
287 |
+ |
lu_init(&vertab, NVERTS); |
288 |
|
lu_init(&rdispatch, 22); |
289 |
|
add2dispatch("polygon", o_face); |
290 |
|
add2dispatch("cone", o_cone); |
300 |
|
add2dispatch("metal", o_metal); |
301 |
|
add2dispatch("metal2", o_metal); |
302 |
|
add2dispatch("glass", o_glass); |
303 |
+ |
add2dispatch("dielectric", o_dielectric); |
304 |
|
add2dispatch("trans", o_trans); |
305 |
|
add2dispatch("trans2", o_trans); |
306 |
|
add2dispatch("mirror", o_mirror); |
308 |
|
add2dispatch("spotlight", o_light); |
309 |
|
add2dispatch("glow", o_light); |
310 |
|
add2dispatch("illum", o_illum); |
311 |
< |
puts("# The following was converted from Radiance scene input"); |
311 |
> |
puts("# The following was converted from RADIANCE scene input"); |
312 |
|
if (hasmult) |
313 |
|
printf("xf -s %.4e\n", unit_mult); |
314 |
|
printf("o %s\n", curobj); |
320 |
|
puts("o"); |
321 |
|
if (hasmult) |
322 |
|
puts("xf"); |
323 |
< |
puts("# End of data converted from Radiance scene input"); |
323 |
> |
puts("# End of data converted from RADIANCE scene input"); |
324 |
|
lu_done(&rdispatch); |
325 |
|
lu_done(&rmats); |
326 |
+ |
lu_done(&vertab); |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
+ |
clrverts() /* clear vertex table */ |
331 |
+ |
{ |
332 |
+ |
register int i; |
333 |
+ |
|
334 |
+ |
lu_done(&vertab); |
335 |
+ |
for (i = 0; i < NVERTS; i++) |
336 |
+ |
vert[i].lused = 0; |
337 |
+ |
lu_init(&vertab, NVERTS); |
338 |
+ |
} |
339 |
+ |
|
340 |
+ |
|
341 |
|
add2dispatch(name, func) /* add function to dispatch table */ |
342 |
|
char *name; |
343 |
|
int (*func)(); |
355 |
|
} |
356 |
|
|
357 |
|
|
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 |
– |
|
358 |
|
char * |
359 |
|
getvertid(vname, vp) /* get/set vertex ID for this point */ |
360 |
|
char *vname; |
361 |
|
FVECT vp; |
362 |
|
{ |
363 |
< |
char vkey[VKLEN]; |
363 |
> |
static char vkey[VKLEN]; |
364 |
|
register LUENT *lp; |
365 |
|
register int i, vndx; |
366 |
|
|
367 |
< |
if (!vertab.tsiz && !lu_init(&vertab, NVERTS)) |
335 |
< |
goto memerr; |
336 |
< |
clock++; /* increment counter */ |
367 |
> |
vclock++; /* increment counter */ |
368 |
|
mkvkey(vkey, vp); |
369 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
370 |
|
goto memerr; |
384 |
|
mkvkey(vkey, vert[vndx].p); |
385 |
|
lu_delete(&vertab, vkey); |
386 |
|
} |
387 |
< |
vert[vndx].lused = clock; /* assign it */ |
357 |
< |
VCOPY(vert[vndx].p, vp); |
387 |
> |
VCOPY(vert[vndx].p, vp); /* assign it */ |
388 |
|
printf("v v%d =\n\tp %.15g %.15g %.15g\n", /* print it */ |
389 |
|
vndx, vp[0], vp[1], vp[2]); |
390 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
391 |
|
} else |
392 |
|
vndx = (struct vert *)lp->data - vert; |
393 |
+ |
vert[vndx].lused = vclock; /* record this use */ |
394 |
|
sprintf(vname, "v%d", vndx); |
395 |
|
return(vname); |
396 |
|
memerr: |
400 |
|
|
401 |
|
|
402 |
|
int |
403 |
+ |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
404 |
+ |
char *mod, *typ, *id; |
405 |
+ |
FUNARGS *fa; |
406 |
+ |
{ |
407 |
+ |
register int i; |
408 |
+ |
|
409 |
+ |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
410 |
+ |
printf("# %s %s %s", mod, typ, id); |
411 |
+ |
printf("\n# %d", fa->nsargs); |
412 |
+ |
for (i = 0; i < fa->nsargs; i++) |
413 |
+ |
printf(" %s", fa->sarg[i]); |
414 |
+ |
#ifdef IARGS |
415 |
+ |
printf("\n# %d", fa->niargs); |
416 |
+ |
for (i = 0; i < fa->niargs; i++) |
417 |
+ |
printf(" %ld", fa->iarg[i]); |
418 |
+ |
#else |
419 |
+ |
fputs("\n# 0", stdout); |
420 |
+ |
#endif |
421 |
+ |
printf("\n# %d", fa->nfargs); |
422 |
+ |
for (i = 0; i < fa->nfargs; i++) |
423 |
+ |
printf(" %g", fa->farg[i]); |
424 |
+ |
fputs("\n\n", stdout); |
425 |
+ |
return(0); |
426 |
+ |
} |
427 |
+ |
|
428 |
+ |
|
429 |
+ |
int |
430 |
|
o_face(mod, typ, id, fa) /* print out a polygon */ |
431 |
|
char *mod, *typ, *id; |
432 |
|
FUNARGS *fa; |
433 |
|
{ |
434 |
< |
char entbuf[512]; |
434 |
> |
char entbuf[2048]; |
435 |
|
register char *cp; |
436 |
|
register int i; |
437 |
|
|
570 |
|
fputs(fa->sarg[i], stdout); |
571 |
|
} |
572 |
|
putchar('\n'); |
573 |
+ |
clrverts(); /* vertex id's no longer reliable */ |
574 |
|
return(0); |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
|
int |
520 |
– |
o_source(mod, typ, id, fa) /* convert a source */ |
521 |
– |
char *mod, *typ, *id; |
522 |
– |
FUNARGS *fa; |
523 |
– |
{ |
524 |
– |
return(0); /* there is no MGF equivalent! */ |
525 |
– |
} |
526 |
– |
|
527 |
– |
|
528 |
– |
int |
579 |
|
o_illum(mod, typ, id, fa) /* convert an illum material */ |
580 |
|
char *mod, *typ, *id; |
581 |
|
FUNARGS *fa; |
659 |
|
newmat(id, NULL); |
660 |
|
if (fa->nfargs == 4) |
661 |
|
nrfr = fa->farg[3]; |
662 |
+ |
printf("\tir %f 0\n", nrfr); |
663 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
664 |
|
F *= F; |
665 |
|
for (i = 0; i < 3; i++) { |
685 |
|
|
686 |
|
|
687 |
|
int |
688 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
689 |
+ |
char *mod, *typ, *id; |
690 |
+ |
register FUNARGS *fa; |
691 |
+ |
{ |
692 |
+ |
COLOR cxyz, trgb; |
693 |
+ |
double F, d; |
694 |
+ |
register int i; |
695 |
+ |
|
696 |
+ |
if (fa->nfargs != 5) |
697 |
+ |
return(-1); |
698 |
+ |
newmat(id, NULL); |
699 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
700 |
+ |
F *= F; |
701 |
+ |
for (i = 0; i < 3; i++) |
702 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
703 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
704 |
+ |
printf("\tsides 1\n"); |
705 |
+ |
puts("\tc"); /* put reflected component */ |
706 |
+ |
printf("\trs %.4f 0\n", F); |
707 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
708 |
+ |
puts("\tc"); |
709 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
710 |
+ |
if (d > FTINY) |
711 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
712 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
713 |
+ |
return(0); |
714 |
+ |
} |
715 |
+ |
|
716 |
+ |
|
717 |
+ |
int |
718 |
|
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
719 |
|
char *mod, *typ, *id; |
720 |
|
register FUNARGS *fa; |
796 |
|
puts("\tc"); |
797 |
|
if (d > FTINY) |
798 |
|
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
799 |
< |
printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); |
799 |
> |
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
800 |
|
return(0); |
801 |
|
} |