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 |
+ |
#define DFLDAT "illum" /* data file name */ |
22 |
|
/* selection options */ |
23 |
|
#define S_NONE 0 /* select none */ |
24 |
|
#define S_ELEM 1 /* select specified element */ |
26 |
|
#define S_ALL 3 /* select all */ |
27 |
|
|
28 |
|
/* rtrace command and defaults */ |
29 |
< |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-ab", "2", |
30 |
< |
"-ad", "256", "-as", "128", "-aa", ".15" }; |
31 |
< |
int rtargc = 13; |
29 |
> |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-di+", |
30 |
> |
"-ab", "2", "-ad", "256", "-as", "128", "-aa", ".15", }; |
31 |
> |
int rtargc = 14; |
32 |
|
/* overriding rtrace options */ |
33 |
< |
char *myrtopts[] = { "-I-", "-i-", "-di+", "-ov", "-h-", "-fff", NULL }; |
33 |
> |
char *myrtopts[] = { "-I-", "-i-", "-ov", "-h-", "-fff", NULL }; |
34 |
|
|
35 |
|
struct rtproc rt; /* our rtrace process */ |
36 |
|
|
37 |
|
struct illum_args thisillum = { /* our illum and default values */ |
38 |
|
0, |
39 |
|
DFLMAT, |
40 |
< |
DFLMAT, |
40 |
> |
DFLDAT, |
41 |
|
0, |
42 |
|
VOIDID, |
43 |
|
SAMPDENS, |
44 |
|
NSAMPS, |
45 |
+ |
0., |
46 |
|
}; |
47 |
|
|
48 |
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
60 |
|
int warnings = 1; /* print warnings? */ |
61 |
|
|
62 |
|
extern char *fgetline(), *fgetword(), *sskip(), |
63 |
< |
*atos(), *iskip(), *fskip(); |
63 |
> |
*atos(), *iskip(), *fskip(), *strcpy(); |
64 |
|
extern FILE *popen(); |
65 |
|
|
66 |
|
|
91 |
|
rtargv[rtargc] = NULL; |
92 |
|
/* just asking for defaults? */ |
93 |
|
if (!strcmp(argv[gargc-1], "-defaults")) { |
94 |
+ |
printopts(); fflush(stdout); |
95 |
|
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
96 |
|
if (rtpath == NULL) { |
97 |
|
eputs(rtargv[0]); |
106 |
|
init(); |
107 |
|
if (gargc+1 < argc) |
108 |
|
for (i = gargc+1; i < argc; i++) { |
109 |
< |
if ((fp = fopen(argv[i], "r")) == NULL { |
109 |
> |
if ((fp = fopen(argv[i], "r")) == NULL) { |
110 |
|
sprintf(errmsg, |
111 |
|
"cannot open scene file \"%s\"", argv[i]); |
112 |
|
error(SYSTEM, errmsg); |
138 |
|
|
139 |
|
init() /* start rtrace and set up buffers */ |
140 |
|
{ |
141 |
< |
extern int o_face(), o_ring(); |
141 |
> |
extern int o_face(), o_sphere(), o_ring(); |
142 |
|
int maxbytes; |
143 |
|
/* set up object functions */ |
144 |
|
ofun[OBJ_FACE].funp = o_face; |
145 |
+ |
ofun[OBJ_SPHERE].funp = o_sphere; |
146 |
|
ofun[OBJ_RING].funp = o_ring; |
147 |
|
/* set up signal handling */ |
148 |
|
signal(SIGPIPE, quit); |
149 |
|
/* start rtrace process */ |
150 |
+ |
errno = 0; |
151 |
|
maxbytes = open_process(rt.pd, rtargv); |
152 |
|
if (maxbytes == 0) { |
153 |
|
eputs(rtargv[0]); |
157 |
|
if (maxbytes < 0) |
158 |
|
error(SYSTEM, "cannot start rtrace process"); |
159 |
|
rt.bsiz = maxbytes/(6*sizeof(float)); |
160 |
< |
rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float))); |
161 |
< |
if (rt.buf == NULL) |
160 |
> |
rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--); |
161 |
> |
rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz); |
162 |
> |
if (rt.buf == NULL || rt.dest == NULL) |
163 |
|
error(SYSTEM, "out of memory in init"); |
158 |
– |
rt.bsiz--; /* allow for flush ray */ |
164 |
|
rt.nrays = 0; |
165 |
+ |
/* set up urand */ |
166 |
+ |
initurand(2048); |
167 |
|
} |
168 |
|
|
169 |
|
|
259 |
|
if (*++cp != '=') |
260 |
|
break; |
261 |
|
if (!*++cp) { |
262 |
+ |
strcpy(thisillum.datafile,thisillum.matname); |
263 |
+ |
thisillum.dfnum = 0; |
264 |
|
thisillum.flags &= ~IL_DATCLB; |
265 |
|
continue; |
266 |
|
} |
271 |
|
continue; |
272 |
|
case 'i': /* include material */ |
273 |
|
case 'e': /* exclude material */ |
274 |
< |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
266 |
< |
if (*++cp != '=') |
274 |
> |
if (cp[1] != '=') |
275 |
|
break; |
276 |
< |
atos(matcheck, MAXSTR, ++cp); |
276 |
> |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
277 |
> |
cp += 2; |
278 |
> |
atos(matcheck, MAXSTR, cp); |
279 |
|
cp = sskip(cp); |
280 |
|
continue; |
281 |
|
case 'a': /* use everything */ |
291 |
|
break; |
292 |
|
switch (*++cp) { |
293 |
|
case 'a': /* average */ |
294 |
< |
thisillum.flags |= IL_COLAVG; |
295 |
< |
thisillum.flags &= ~IL_COLDST; |
294 |
> |
thisillum.flags = (thisillum.flags|IL_COLAVG) |
295 |
> |
& ~IL_COLDST; |
296 |
|
break; |
297 |
|
case 'd': /* distribution */ |
298 |
< |
thisillum.flags |= IL_COLDST; |
289 |
< |
thisillum.flags &= ~IL_COLAVG; |
298 |
> |
thisillum.flags |= (IL_COLDST|IL_COLAVG); |
299 |
|
break; |
300 |
|
case 'n': /* none */ |
301 |
|
thisillum.flags &= ~(IL_COLAVG|IL_COLDST); |
322 |
|
cp = sskip(cp); |
323 |
|
continue; |
324 |
|
case 'l': /* light sources */ |
325 |
< |
if (*++cp != '+' && *cp != '-') |
326 |
< |
break; |
318 |
< |
if (*cp++ == '+') |
325 |
> |
cp++; |
326 |
> |
if (*cp == '+') |
327 |
|
thisillum.flags |= IL_LIGHT; |
328 |
< |
else |
328 |
> |
else if (*cp == '-') |
329 |
|
thisillum.flags &= ~IL_LIGHT; |
330 |
+ |
else |
331 |
+ |
break; |
332 |
+ |
cp++; |
333 |
|
continue; |
334 |
+ |
case 'b': /* brightness */ |
335 |
+ |
if (*++cp != '=') |
336 |
+ |
break; |
337 |
+ |
if (!isfltd(++cp, " \t\n")) |
338 |
+ |
break; |
339 |
+ |
thisillum.minbrt = atof(cp); |
340 |
+ |
if (thisillum.minbrt < 0.) |
341 |
+ |
thisillum.minbrt = 0.; |
342 |
+ |
cp = sskip(cp); |
343 |
+ |
continue; |
344 |
|
case 'o': /* output file */ |
345 |
|
if (*++cp != '=') |
346 |
|
break; |
355 |
|
} |
356 |
|
doneheader = 0; |
357 |
|
continue; |
358 |
+ |
case '!': /* processed file! */ |
359 |
+ |
sprintf(errmsg, "(%s): already processed!", nm); |
360 |
+ |
error(WARNING, errmsg); |
361 |
+ |
matselect = S_NONE; |
362 |
+ |
return; |
363 |
|
} |
364 |
|
opterr: /* skip faulty option */ |
365 |
|
cp = sskip(cp); |
377 |
|
progname, nerrs); |
378 |
|
} |
379 |
|
/* print pure comment */ |
380 |
< |
putchar('#'); putchar(' '); fputs(s+2, stdout); |
380 |
> |
printf("# %s", s+2); |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
+ |
printopts() /* print out option default values */ |
385 |
+ |
{ |
386 |
+ |
printf("m=%-15s\t\t# material name\n", thisillum.matname); |
387 |
+ |
printf("f=%-15s\t\t# data file name\n", thisillum.datafile); |
388 |
+ |
printf("c=n\t\t\t\t# color none\n"); |
389 |
+ |
printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); |
390 |
+ |
printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); |
391 |
+ |
printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); |
392 |
+ |
} |
393 |
+ |
|
394 |
+ |
|
395 |
|
printhead(ac, av) /* print out header */ |
396 |
|
register int ac; |
397 |
|
register char **av; |
401 |
|
putchar(' '); |
402 |
|
fputs(*av++, stdout); |
403 |
|
} |
404 |
< |
putchar('\n'); |
404 |
> |
fputs("\n#@mkillum !\n", stdout); |
405 |
|
} |
406 |
|
|
407 |
|
|
424 |
|
printf("\n%s %s %s", thisillum.altmat, ALIASID, str); |
425 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
426 |
|
goto readerr; |
427 |
< |
printf(" %s\n", str); |
427 |
> |
printf("\t%s\n", str); |
428 |
|
return; |
429 |
|
} |
430 |
< |
thisobj.omod = OVOID; |
430 |
> |
thisobj.omod = OVOID; /* unused field */ |
431 |
|
if ((thisobj.otype = otype(str)) < 0) { |
432 |
|
sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str); |
433 |
|
error(USER, errmsg); |
444 |
|
doit = 0; |
445 |
|
break; |
446 |
|
case S_ALL: |
447 |
< |
doit = issurface(thisobj.otype); |
447 |
> |
doit = 1; |
448 |
|
break; |
449 |
|
case S_ELEM: |
450 |
|
doit = !strcmp(thisillum.altmat, matcheck); |
453 |
|
doit = strcmp(thisillum.altmat, matcheck); |
454 |
|
break; |
455 |
|
} |
456 |
< |
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 |
< |
} |
456 |
> |
doit = doit && issurface(thisobj.otype); |
457 |
|
/* print header? */ |
458 |
|
checkhead(); |
459 |
|
/* process object */ |
460 |
|
if (doit) |
461 |
< |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt); |
461 |
> |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); |
462 |
|
else |
463 |
|
printobj(thisillum.altmat, &thisobj); |
464 |
|
/* free arguments */ |
468 |
|
sprintf(errmsg, "(%s): error reading scene", nm); |
469 |
|
error(USER, errmsg); |
470 |
|
} |
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() {} |