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 |
|
* Convert Radiance scene description to MGF |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
8 |
> |
#include "standard.h" |
9 |
> |
#include <ctype.h> |
10 |
|
#include <string.h> |
11 |
< |
#include "fvect.h" |
11 |
> |
#include <stdio.h> |
12 |
> |
|
13 |
> |
#include "platform.h" |
14 |
|
#include "object.h" |
15 |
|
#include "color.h" |
16 |
|
#include "lookup.h" |
17 |
|
|
18 |
< |
#define PI 3.14159265358979323846 |
18 |
> |
#define C_1SIDEDTHICK 0.005 |
19 |
|
|
20 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
21 |
< |
int o_instance(), o_source(), o_illum(); |
22 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
21 |
> |
int o_instance(), o_illum(); |
22 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
23 |
> |
o_mirror(), o_trans(), o_light(); |
24 |
|
|
24 |
– |
extern void free(); |
25 |
– |
extern char *malloc(); |
26 |
– |
|
25 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
26 |
|
|
27 |
|
LUTAB rdispatch = LU_SINIT(NULL,NULL); /* function dispatch table */ |
37 |
|
* Stuff for tracking and reusing vertices: |
38 |
|
*/ |
39 |
|
|
40 |
< |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
40 |
> |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
41 |
|
#define VKLEN 64 |
42 |
|
|
43 |
|
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
44 |
|
|
45 |
|
#define NVERTS 256 |
46 |
|
|
47 |
< |
long clock; /* incremented at each vertex request */ |
47 |
> |
long vclock; /* incremented at each vertex request */ |
48 |
|
|
49 |
|
struct vert { |
50 |
|
long lused; /* when last used (0 if unassigned) */ |
188 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
189 |
|
exit(1); |
190 |
|
} |
191 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
192 |
< |
newmat(id, mod); |
191 |
> |
} else { /* unsupported */ |
192 |
> |
o_unsupported(mod, typ, id, fa); |
193 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
194 |
> |
newmat(id, mod); |
195 |
> |
} |
196 |
|
} |
197 |
|
|
198 |
|
|
257 |
|
if (end == NULL) |
258 |
|
end = cp; |
259 |
|
/* copy to current object */ |
260 |
< |
for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) |
260 |
> |
cp2 = curobj; |
261 |
> |
if (!isalpha(*id)) { /* start with letter */ |
262 |
> |
diff = *cp2 != 'O'; |
263 |
> |
*cp2++ = 'O'; |
264 |
> |
} |
265 |
> |
for (cp = id; cp < end; *cp2++ = *cp++) { |
266 |
> |
if (*cp < '!' | *cp > '~') /* limit to visible chars */ |
267 |
> |
*cp = '?'; |
268 |
|
diff += *cp != *cp2; |
269 |
+ |
} |
270 |
|
if (!diff && !*cp2) |
271 |
|
return; |
272 |
|
*cp2 = '\0'; |
293 |
|
add2dispatch("metal", o_metal); |
294 |
|
add2dispatch("metal2", o_metal); |
295 |
|
add2dispatch("glass", o_glass); |
296 |
+ |
add2dispatch("dielectric", o_dielectric); |
297 |
|
add2dispatch("trans", o_trans); |
298 |
|
add2dispatch("trans2", o_trans); |
299 |
|
add2dispatch("mirror", o_mirror); |
301 |
|
add2dispatch("spotlight", o_light); |
302 |
|
add2dispatch("glow", o_light); |
303 |
|
add2dispatch("illum", o_illum); |
304 |
< |
puts("# The following was converted from Radiance scene input"); |
304 |
> |
puts("# The following was converted from RADIANCE scene input"); |
305 |
|
if (hasmult) |
306 |
|
printf("xf -s %.4e\n", unit_mult); |
307 |
|
printf("o %s\n", curobj); |
313 |
|
puts("o"); |
314 |
|
if (hasmult) |
315 |
|
puts("xf"); |
316 |
< |
puts("# End of data converted from Radiance scene input"); |
316 |
> |
puts("# End of data converted from RADIANCE scene input"); |
317 |
|
lu_done(&rdispatch); |
318 |
|
lu_done(&rmats); |
319 |
|
lu_done(&vertab); |
353 |
|
char *vname; |
354 |
|
FVECT vp; |
355 |
|
{ |
356 |
< |
char vkey[VKLEN]; |
356 |
> |
static char vkey[VKLEN]; |
357 |
|
register LUENT *lp; |
358 |
|
register int i, vndx; |
359 |
|
|
360 |
< |
clock++; /* increment counter */ |
360 |
> |
vclock++; /* increment counter */ |
361 |
|
mkvkey(vkey, vp); |
362 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
363 |
|
goto memerr; |
383 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
384 |
|
} else |
385 |
|
vndx = (struct vert *)lp->data - vert; |
386 |
< |
vert[vndx].lused = clock; /* record this use */ |
386 |
> |
vert[vndx].lused = vclock; /* record this use */ |
387 |
|
sprintf(vname, "v%d", vndx); |
388 |
|
return(vname); |
389 |
|
memerr: |
393 |
|
|
394 |
|
|
395 |
|
int |
396 |
+ |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
397 |
+ |
char *mod, *typ, *id; |
398 |
+ |
FUNARGS *fa; |
399 |
+ |
{ |
400 |
+ |
register int i; |
401 |
+ |
|
402 |
+ |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
403 |
+ |
printf("# %s %s %s", mod, typ, id); |
404 |
+ |
printf("\n# %d", fa->nsargs); |
405 |
+ |
for (i = 0; i < fa->nsargs; i++) |
406 |
+ |
printf(" %s", fa->sarg[i]); |
407 |
+ |
#ifdef IARGS |
408 |
+ |
printf("\n# %d", fa->niargs); |
409 |
+ |
for (i = 0; i < fa->niargs; i++) |
410 |
+ |
printf(" %ld", fa->iarg[i]); |
411 |
+ |
#else |
412 |
+ |
fputs("\n# 0", stdout); |
413 |
+ |
#endif |
414 |
+ |
printf("\n# %d", fa->nfargs); |
415 |
+ |
for (i = 0; i < fa->nfargs; i++) |
416 |
+ |
printf(" %g", fa->farg[i]); |
417 |
+ |
fputs("\n\n", stdout); |
418 |
+ |
return(0); |
419 |
+ |
} |
420 |
+ |
|
421 |
+ |
|
422 |
+ |
int |
423 |
|
o_face(mod, typ, id, fa) /* print out a polygon */ |
424 |
|
char *mod, *typ, *id; |
425 |
|
FUNARGS *fa; |
426 |
|
{ |
427 |
< |
char entbuf[512]; |
427 |
> |
char entbuf[2048], *linestart; |
428 |
|
register char *cp; |
429 |
|
register int i; |
430 |
|
|
432 |
|
return(-1); |
433 |
|
setmat(mod); |
434 |
|
setobj(id); |
435 |
< |
cp = entbuf; |
435 |
> |
cp = linestart = entbuf; |
436 |
|
*cp++ = 'f'; |
437 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
438 |
|
*cp++ = ' '; |
439 |
+ |
if (cp - linestart > 72) { |
440 |
+ |
*cp++ = '\\'; *cp++ = '\n'; |
441 |
+ |
linestart = cp; |
442 |
+ |
*cp++ = ' '; *cp++ = ' '; |
443 |
+ |
} |
444 |
|
getvertid(cp, fa->farg + i); |
445 |
|
while (*cp) |
446 |
|
cp++; |
574 |
|
|
575 |
|
|
576 |
|
int |
535 |
– |
o_source(mod, typ, id, fa) /* convert a source */ |
536 |
– |
char *mod, *typ, *id; |
537 |
– |
FUNARGS *fa; |
538 |
– |
{ |
539 |
– |
return(0); /* there is no MGF equivalent! */ |
540 |
– |
} |
541 |
– |
|
542 |
– |
|
543 |
– |
int |
577 |
|
o_illum(mod, typ, id, fa) /* convert an illum material */ |
578 |
|
char *mod, *typ, *id; |
579 |
|
FUNARGS *fa; |
657 |
|
newmat(id, NULL); |
658 |
|
if (fa->nfargs == 4) |
659 |
|
nrfr = fa->farg[3]; |
660 |
+ |
printf("\tir %f 0\n", nrfr); |
661 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
662 |
|
F *= F; |
663 |
|
for (i = 0; i < 3; i++) { |
672 |
|
if (d > FTINY) |
673 |
|
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
674 |
|
printf("\trs %.4f 0\n", cxyz[1]); |
675 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
676 |
+ |
puts("\tc"); |
677 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
678 |
+ |
if (d > FTINY) |
679 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
680 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
681 |
+ |
return(0); |
682 |
+ |
} |
683 |
+ |
|
684 |
+ |
|
685 |
+ |
int |
686 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
687 |
+ |
char *mod, *typ, *id; |
688 |
+ |
register FUNARGS *fa; |
689 |
+ |
{ |
690 |
+ |
COLOR cxyz, trgb; |
691 |
+ |
double F, d; |
692 |
+ |
register int i; |
693 |
+ |
|
694 |
+ |
if (fa->nfargs != 5) |
695 |
+ |
return(-1); |
696 |
+ |
newmat(id, NULL); |
697 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
698 |
+ |
F *= F; |
699 |
+ |
for (i = 0; i < 3; i++) |
700 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
701 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
702 |
+ |
printf("\tsides 1\n"); |
703 |
+ |
puts("\tc"); /* put reflected component */ |
704 |
+ |
printf("\trs %.4f 0\n", F); |
705 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
706 |
|
puts("\tc"); |
707 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |