15 |
|
#include <ctype.h> |
16 |
|
|
17 |
|
/* default parameters */ |
18 |
< |
#define SAMPDENS 128 /* points per projected steradian */ |
18 |
> |
#define SAMPDENS 48 /* points per projected steradian */ |
19 |
|
#define NSAMPS 32 /* samples per point */ |
20 |
|
#define DFLMAT "illum_mat" /* material name */ |
21 |
|
/* selection options */ |
25 |
|
#define S_ALL 3 /* select all */ |
26 |
|
|
27 |
|
/* rtrace command and defaults */ |
28 |
< |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-ab", "2", |
29 |
< |
"-ad", "256", "-as", "128", "-aa", ".15" }; |
30 |
< |
int rtargc = 13; |
28 |
> |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+", |
29 |
> |
"-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; |
30 |
> |
int rtargc = 14; |
31 |
|
/* overriding rtrace options */ |
32 |
< |
char *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL }; |
32 |
> |
char *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL }; |
33 |
|
|
34 |
|
struct rtproc rt; /* our rtrace process */ |
35 |
|
|
58 |
|
int warnings = 1; /* print warnings? */ |
59 |
|
|
60 |
|
extern char *fgetline(), *fgetword(), *sskip(), |
61 |
< |
*atos(), *iskip(), *fskip(); |
61 |
> |
*atos(), *iskip(), *fskip(), *strcpy(); |
62 |
|
extern FILE *popen(); |
63 |
|
|
64 |
|
|
89 |
|
rtargv[rtargc] = NULL; |
90 |
|
/* just asking for defaults? */ |
91 |
|
if (!strcmp(argv[gargc-1], "-defaults")) { |
92 |
+ |
printopts(); fflush(stdout); |
93 |
|
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
94 |
|
if (rtpath == NULL) { |
95 |
|
eputs(rtargv[0]); |
104 |
|
init(); |
105 |
|
if (gargc+1 < argc) |
106 |
|
for (i = gargc+1; i < argc; i++) { |
107 |
< |
if ((fp = fopen(argv[i], "r")) == NULL { |
107 |
> |
if ((fp = fopen(argv[i], "r")) == NULL) { |
108 |
|
sprintf(errmsg, |
109 |
|
"cannot open scene file \"%s\"", argv[i]); |
110 |
|
error(SYSTEM, errmsg); |
136 |
|
|
137 |
|
init() /* start rtrace and set up buffers */ |
138 |
|
{ |
139 |
< |
extern int o_face(), o_ring(); |
139 |
> |
extern int o_face(), o_sphere(), o_ring(); |
140 |
|
int maxbytes; |
141 |
|
/* set up object functions */ |
142 |
|
ofun[OBJ_FACE].funp = o_face; |
143 |
+ |
ofun[OBJ_SPHERE].funp = o_sphere; |
144 |
|
ofun[OBJ_RING].funp = o_ring; |
145 |
|
/* set up signal handling */ |
146 |
|
signal(SIGPIPE, quit); |
154 |
|
if (maxbytes < 0) |
155 |
|
error(SYSTEM, "cannot start rtrace process"); |
156 |
|
rt.bsiz = maxbytes/(6*sizeof(float)); |
157 |
< |
rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float))); |
158 |
< |
if (rt.buf == NULL) |
157 |
> |
rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--); |
158 |
> |
rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz); |
159 |
> |
if (rt.buf == NULL || rt.dest == NULL) |
160 |
|
error(SYSTEM, "out of memory in init"); |
158 |
– |
rt.bsiz--; /* allow for flush ray */ |
161 |
|
rt.nrays = 0; |
162 |
+ |
/* set up urand */ |
163 |
+ |
initurand(2048); |
164 |
|
} |
165 |
|
|
166 |
|
|
256 |
|
if (*++cp != '=') |
257 |
|
break; |
258 |
|
if (!*++cp) { |
259 |
+ |
strcpy(thisillum.datafile,thisillum.matname); |
260 |
|
thisillum.flags &= ~IL_DATCLB; |
261 |
|
continue; |
262 |
|
} |
267 |
|
continue; |
268 |
|
case 'i': /* include material */ |
269 |
|
case 'e': /* exclude material */ |
270 |
< |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
266 |
< |
if (*++cp != '=') |
270 |
> |
if (cp[1] != '=') |
271 |
|
break; |
272 |
< |
atos(matcheck, MAXSTR, ++cp); |
272 |
> |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
273 |
> |
cp += 2; |
274 |
> |
atos(matcheck, MAXSTR, cp); |
275 |
|
cp = sskip(cp); |
276 |
|
continue; |
277 |
|
case 'a': /* use everything */ |
287 |
|
break; |
288 |
|
switch (*++cp) { |
289 |
|
case 'a': /* average */ |
290 |
< |
thisillum.flags |= IL_COLAVG; |
291 |
< |
thisillum.flags &= ~IL_COLDST; |
290 |
> |
thisillum.flags = (thisillum.flags|IL_COLAVG) |
291 |
> |
& ~IL_COLDST; |
292 |
|
break; |
293 |
|
case 'd': /* distribution */ |
294 |
< |
thisillum.flags |= IL_COLDST; |
289 |
< |
thisillum.flags &= ~IL_COLAVG; |
294 |
> |
thisillum.flags |= (IL_COLDST|IL_COLAVG); |
295 |
|
break; |
296 |
|
case 'n': /* none */ |
297 |
|
thisillum.flags &= ~(IL_COLAVG|IL_COLDST); |
318 |
|
cp = sskip(cp); |
319 |
|
continue; |
320 |
|
case 'l': /* light sources */ |
321 |
< |
if (*++cp != '+' && *cp != '-') |
322 |
< |
break; |
318 |
< |
if (*cp++ == '+') |
321 |
> |
cp++; |
322 |
> |
if (*cp == '+') |
323 |
|
thisillum.flags |= IL_LIGHT; |
324 |
< |
else |
324 |
> |
else if (*cp == '-') |
325 |
|
thisillum.flags &= ~IL_LIGHT; |
326 |
+ |
else |
327 |
+ |
break; |
328 |
+ |
cp++; |
329 |
|
continue; |
330 |
|
case 'o': /* output file */ |
331 |
|
if (*++cp != '=') |
341 |
|
} |
342 |
|
doneheader = 0; |
343 |
|
continue; |
344 |
+ |
case '!': /* processed file! */ |
345 |
+ |
sprintf(errmsg, "(%s): already processed!", nm); |
346 |
+ |
error(WARNING, errmsg); |
347 |
+ |
matselect = S_NONE; |
348 |
+ |
return; |
349 |
|
} |
350 |
|
opterr: /* skip faulty option */ |
351 |
|
cp = sskip(cp); |
363 |
|
progname, nerrs); |
364 |
|
} |
365 |
|
/* print pure comment */ |
366 |
< |
putchar('#'); putchar(' '); fputs(s+2, stdout); |
366 |
> |
printf("# %s", s+2); |
367 |
|
} |
368 |
|
|
369 |
|
|
370 |
+ |
printopts() /* print out option default values */ |
371 |
+ |
{ |
372 |
+ |
printf("m=%s\t\t\t# material name\n", thisillum.matname); |
373 |
+ |
printf("f=%s\t\t\t# data file name\n", thisillum.datafile); |
374 |
+ |
printf("c=n\t\t\t\t# color none\n"); |
375 |
+ |
printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); |
376 |
+ |
printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
|
380 |
|
printhead(ac, av) /* print out header */ |
381 |
|
register int ac; |
382 |
|
register char **av; |
386 |
|
putchar(' '); |
387 |
|
fputs(*av++, stdout); |
388 |
|
} |
389 |
< |
putchar('\n'); |
389 |
> |
fputs("\n#@mkillum !\n", stdout); |
390 |
|
} |
391 |
|
|
392 |
|
|
409 |
|
printf("\n%s %s %s", thisillum.altmat, ALIASID, str); |
410 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
411 |
|
goto readerr; |
412 |
< |
printf(" %s\n", str); |
412 |
> |
printf("\t%s\n", str); |
413 |
|
return; |
414 |
|
} |
415 |
< |
thisobj.omod = OVOID; |
415 |
> |
thisobj.omod = OVOID; /* unused field */ |
416 |
|
if ((thisobj.otype = otype(str)) < 0) { |
417 |
|
sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str); |
418 |
|
error(USER, errmsg); |
429 |
|
doit = 0; |
430 |
|
break; |
431 |
|
case S_ALL: |
432 |
< |
doit = issurface(thisobj.otype); |
432 |
> |
doit = 1; |
433 |
|
break; |
434 |
|
case S_ELEM: |
435 |
|
doit = !strcmp(thisillum.altmat, matcheck); |
438 |
|
doit = strcmp(thisillum.altmat, matcheck); |
439 |
|
break; |
440 |
|
} |
441 |
< |
if (doit && ofun[thisobj.otype].funp == o_default) { |
420 |
< |
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
421 |
< |
nm, ofun[thisobj.otype].funame, thisobj.oname); |
422 |
< |
error(WARNING, errmsg); |
423 |
< |
doit = 0; |
424 |
< |
} |
441 |
> |
doit = doit && issurface(thisobj.otype); |
442 |
|
/* print header? */ |
443 |
|
checkhead(); |
444 |
|
/* process object */ |
445 |
|
if (doit) |
446 |
< |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt); |
446 |
> |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); |
447 |
|
else |
448 |
|
printobj(thisillum.altmat, &thisobj); |
449 |
|
/* free arguments */ |
453 |
|
sprintf(errmsg, "(%s): error reading scene", nm); |
454 |
|
error(USER, errmsg); |
455 |
|
} |
439 |
– |
|
440 |
– |
|
441 |
– |
int |
442 |
– |
otype(ofname) /* get object function number from its name */ |
443 |
– |
char *ofname; |
444 |
– |
{ |
445 |
– |
register int i; |
446 |
– |
|
447 |
– |
for (i = 0; i < NUMOTYPE; i++) |
448 |
– |
if (!strcmp(ofun[i].funame, ofname)) |
449 |
– |
return(i); |
450 |
– |
|
451 |
– |
return(-1); /* not found */ |
452 |
– |
} |
453 |
– |
|
454 |
– |
|
455 |
– |
o_default() {} |