10 |
|
|
11 |
|
#include "mkillum.h" |
12 |
|
|
13 |
+ |
#include <signal.h> |
14 |
+ |
|
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 |
|
|
43 |
– |
int sampdens = SAMPDENS; /* sample point density */ |
48 |
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
49 |
|
int matselect = S_ALL; /* selection criterion */ |
50 |
|
|
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 |
|
|
70 |
|
{ |
71 |
|
extern char *getenv(), *getpath(); |
72 |
|
char *rtpath; |
73 |
+ |
FILE *fp; |
74 |
|
register int i; |
75 |
|
/* set global arguments */ |
76 |
< |
gargc = argc; gargv = argv; |
76 |
> |
gargv = argv; |
77 |
|
/* set up rtrace command */ |
78 |
< |
if (argc < 2) |
79 |
< |
error(USER, "too few arguments"); |
80 |
< |
for (i = 1; i < argc-1; i++) { |
78 |
> |
for (i = 1; i < argc; i++) { |
79 |
> |
if (argv[i][0] == '<' && !argv[i][1]) |
80 |
> |
break; |
81 |
|
rtargv[rtargc++] = argv[i]; |
82 |
|
if (argv[i][0] == '-' && argv[i][1] == 'w') |
83 |
|
warnings = !warnings; |
84 |
|
} |
85 |
+ |
gargc = i; |
86 |
+ |
rtargc--; |
87 |
|
for (i = 0; myrtopts[i] != NULL; i++) |
88 |
|
rtargv[rtargc++] = myrtopts[i]; |
89 |
< |
rtargv[rtargc++] = argv[argc-1]; |
89 |
> |
rtargv[rtargc++] = argv[gargc-1]; |
90 |
|
rtargv[rtargc] = NULL; |
91 |
|
/* just asking for defaults? */ |
92 |
< |
if (!strcmp(argv[argc-1], "-defaults")) { |
92 |
> |
if (!strcmp(argv[gargc-1], "-defaults")) { |
93 |
> |
printopts(); fflush(stdout); |
94 |
|
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
95 |
|
if (rtpath == NULL) { |
96 |
|
eputs(rtargv[0]); |
101 |
|
perror(rtpath); |
102 |
|
exit(1); |
103 |
|
} |
104 |
+ |
if (gargc < 2 || argv[gargc-1][0] == '-') |
105 |
+ |
error(USER, "missing octree argument"); |
106 |
|
/* else initialize and run our calculation */ |
107 |
|
init(); |
108 |
< |
filter(stdin, "standard input"); |
108 |
> |
if (gargc+1 < argc) |
109 |
> |
for (i = gargc+1; i < argc; i++) { |
110 |
> |
if ((fp = fopen(argv[i], "r")) == NULL) { |
111 |
> |
sprintf(errmsg, |
112 |
> |
"cannot open scene file \"%s\"", argv[i]); |
113 |
> |
error(SYSTEM, errmsg); |
114 |
> |
} |
115 |
> |
filter(fp, argv[i]); |
116 |
> |
fclose(fp); |
117 |
> |
} |
118 |
> |
else |
119 |
> |
filter(stdin, "standard input"); |
120 |
|
quit(0); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
+ |
quit(status) /* exit with status */ |
125 |
+ |
int status; |
126 |
+ |
{ |
127 |
+ |
int rtstat; |
128 |
+ |
|
129 |
+ |
rtstat = close_process(rt.pd); |
130 |
+ |
if (status == 0) |
131 |
+ |
if (rtstat < 0) |
132 |
+ |
error(WARNING, |
133 |
+ |
"unknown return status from rtrace process"); |
134 |
+ |
else |
135 |
+ |
status = rtstat; |
136 |
+ |
exit(status); |
137 |
+ |
} |
138 |
+ |
|
139 |
+ |
|
140 |
|
init() /* start rtrace and set up buffers */ |
141 |
|
{ |
142 |
+ |
extern int o_face(), o_sphere(), o_ring(); |
143 |
|
int maxbytes; |
144 |
< |
|
144 |
> |
/* set up object functions */ |
145 |
> |
ofun[OBJ_FACE].funp = o_face; |
146 |
> |
ofun[OBJ_SPHERE].funp = o_sphere; |
147 |
> |
ofun[OBJ_RING].funp = o_ring; |
148 |
> |
/* set up signal handling */ |
149 |
> |
signal(SIGPIPE, quit); |
150 |
> |
/* start rtrace process */ |
151 |
> |
errno = 0; |
152 |
|
maxbytes = open_process(rt.pd, rtargv); |
153 |
|
if (maxbytes == 0) { |
154 |
|
eputs(rtargv[0]); |
158 |
|
if (maxbytes < 0) |
159 |
|
error(SYSTEM, "cannot start rtrace process"); |
160 |
|
rt.bsiz = maxbytes/(6*sizeof(float)); |
161 |
< |
rt.buf = (float *)malloc(rt.bsiz*(6*sizeof(float))); |
162 |
< |
if (rt.buf == NULL) |
161 |
> |
rt.buf = (float *)malloc(6*sizeof(float)*rt.bsiz--); |
162 |
> |
rt.dest = (float **)malloc(sizeof(float *)*rt.bsiz); |
163 |
> |
if (rt.buf == NULL || rt.dest == NULL) |
164 |
|
error(SYSTEM, "out of memory in init"); |
119 |
– |
rt.bsiz--; /* allow for flush ray */ |
165 |
|
rt.nrays = 0; |
166 |
+ |
/* set up urand */ |
167 |
+ |
initurand(2048); |
168 |
|
} |
169 |
|
|
170 |
|
|
124 |
– |
quit(status) /* exit with status */ |
125 |
– |
int status; |
126 |
– |
{ |
127 |
– |
int rtstat; |
128 |
– |
|
129 |
– |
rtstat = close_process(rt.pd); |
130 |
– |
if (status == 0) |
131 |
– |
if (rtstat < 0) |
132 |
– |
error(WARNING, |
133 |
– |
"unknown return status from rtrace process"); |
134 |
– |
else |
135 |
– |
status = rtstat; |
136 |
– |
exit(status); |
137 |
– |
} |
138 |
– |
|
139 |
– |
|
171 |
|
eputs(s) /* put string to stderr */ |
172 |
|
register char *s; |
173 |
|
{ |
260 |
|
if (*++cp != '=') |
261 |
|
break; |
262 |
|
if (!*++cp) { |
263 |
+ |
strcpy(thisillum.datafile,thisillum.matname); |
264 |
+ |
thisillum.dfnum = 0; |
265 |
|
thisillum.flags &= ~IL_DATCLB; |
266 |
|
continue; |
267 |
|
} |
272 |
|
continue; |
273 |
|
case 'i': /* include material */ |
274 |
|
case 'e': /* exclude material */ |
275 |
< |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
243 |
< |
if (*++cp != '=') |
275 |
> |
if (cp[1] != '=') |
276 |
|
break; |
277 |
< |
atos(matcheck, MAXSTR, ++cp); |
277 |
> |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
278 |
> |
cp += 2; |
279 |
> |
atos(matcheck, MAXSTR, cp); |
280 |
|
cp = sskip(cp); |
281 |
|
continue; |
282 |
|
case 'a': /* use everything */ |
292 |
|
break; |
293 |
|
switch (*++cp) { |
294 |
|
case 'a': /* average */ |
295 |
< |
thisillum.flags |= IL_COLAVG; |
296 |
< |
thisillum.flags &= ~IL_COLDST; |
295 |
> |
thisillum.flags = (thisillum.flags|IL_COLAVG) |
296 |
> |
& ~IL_COLDST; |
297 |
|
break; |
298 |
|
case 'd': /* distribution */ |
299 |
< |
thisillum.flags |= IL_COLDST; |
266 |
< |
thisillum.flags &= ~IL_COLAVG; |
299 |
> |
thisillum.flags |= (IL_COLDST|IL_COLAVG); |
300 |
|
break; |
301 |
|
case 'n': /* none */ |
302 |
|
thisillum.flags &= ~(IL_COLAVG|IL_COLDST); |
311 |
|
break; |
312 |
|
if (!isintd(++cp, " \t\n")) |
313 |
|
break; |
314 |
< |
sampdens = atoi(cp); |
314 |
> |
thisillum.sampdens = atoi(cp); |
315 |
|
cp = sskip(cp); |
316 |
|
continue; |
317 |
|
case 's': /* point super-samples */ |
322 |
|
thisillum.nsamps = atoi(cp); |
323 |
|
cp = sskip(cp); |
324 |
|
continue; |
325 |
+ |
case 'l': /* light sources */ |
326 |
+ |
cp++; |
327 |
+ |
if (*cp == '+') |
328 |
+ |
thisillum.flags |= IL_LIGHT; |
329 |
+ |
else if (*cp == '-') |
330 |
+ |
thisillum.flags &= ~IL_LIGHT; |
331 |
+ |
else |
332 |
+ |
break; |
333 |
+ |
cp++; |
334 |
+ |
continue; |
335 |
+ |
case 'b': /* brightness */ |
336 |
+ |
if (*++cp != '=') |
337 |
+ |
break; |
338 |
+ |
if (!isfltd(++cp, " \t\n")) |
339 |
+ |
break; |
340 |
+ |
thisillum.minbrt = atof(cp); |
341 |
+ |
if (thisillum.minbrt < 0.) |
342 |
+ |
thisillum.minbrt = 0.; |
343 |
+ |
cp = sskip(cp); |
344 |
+ |
continue; |
345 |
|
case 'o': /* output file */ |
346 |
|
if (*++cp != '=') |
347 |
|
break; |
356 |
|
} |
357 |
|
doneheader = 0; |
358 |
|
continue; |
359 |
+ |
case '!': /* processed file! */ |
360 |
+ |
sprintf(errmsg, "(%s): already processed!", nm); |
361 |
+ |
error(WARNING, errmsg); |
362 |
+ |
matselect = S_NONE; |
363 |
+ |
return; |
364 |
|
} |
365 |
|
opterr: /* skip faulty option */ |
366 |
|
cp = sskip(cp); |
378 |
|
progname, nerrs); |
379 |
|
} |
380 |
|
/* print pure comment */ |
381 |
< |
putchar('#'); putchar(' '); fputs(s+2, stdout); |
381 |
> |
printf("# %s", s+2); |
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
+ |
printopts() /* print out option default values */ |
386 |
+ |
{ |
387 |
+ |
printf("m=%-15s\t\t# material name\n", thisillum.matname); |
388 |
+ |
printf("f=%-15s\t\t# data file name\n", thisillum.datafile); |
389 |
+ |
if (thisillum.flags & IL_COLAVG) |
390 |
+ |
if (thisillum.flags & IL_COLDST) |
391 |
+ |
printf("c=d\t\t\t\t# color distribution\n"); |
392 |
+ |
else |
393 |
+ |
printf("c=a\t\t\t\t# color average\n"); |
394 |
+ |
else |
395 |
+ |
printf("c=n\t\t\t\t# color none\n"); |
396 |
+ |
if (thisillum.flags & IL_LIGHT) |
397 |
+ |
printf("l+\t\t\t\t# light type on\n"); |
398 |
+ |
else |
399 |
+ |
printf("l-\t\t\t\t# light type off\n"); |
400 |
+ |
printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); |
401 |
+ |
printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); |
402 |
+ |
printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); |
403 |
+ |
} |
404 |
+ |
|
405 |
+ |
|
406 |
|
printhead(ac, av) /* print out header */ |
407 |
|
register int ac; |
408 |
|
register char **av; |
412 |
|
putchar(' '); |
413 |
|
fputs(*av++, stdout); |
414 |
|
} |
415 |
< |
putchar('\n'); |
415 |
> |
fputs("\n#@mkillum !\n", stdout); |
416 |
|
} |
417 |
|
|
418 |
|
|
435 |
|
printf("\n%s %s %s", thisillum.altmat, ALIASID, str); |
436 |
|
if (fgetword(str, MAXSTR, fp) == NULL) |
437 |
|
goto readerr; |
438 |
< |
printf(" %s\n", str); |
438 |
> |
printf("\t%s\n", str); |
439 |
|
return; |
440 |
|
} |
441 |
< |
thisobj.omod = OVOID; |
441 |
> |
thisobj.omod = OVOID; /* unused field */ |
442 |
|
if ((thisobj.otype = otype(str)) < 0) { |
443 |
|
sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str); |
444 |
|
error(USER, errmsg); |
455 |
|
doit = 0; |
456 |
|
break; |
457 |
|
case S_ALL: |
458 |
< |
doit = issurface(thisobj.otype); |
458 |
> |
doit = 1; |
459 |
|
break; |
460 |
|
case S_ELEM: |
461 |
|
doit = !strcmp(thisillum.altmat, matcheck); |
464 |
|
doit = strcmp(thisillum.altmat, matcheck); |
465 |
|
break; |
466 |
|
} |
467 |
< |
if (doit) /* make sure we can do it */ |
389 |
< |
switch (thisobj.otype) { |
390 |
< |
case OBJ_SPHERE: |
391 |
< |
case OBJ_FACE: |
392 |
< |
case OBJ_RING: |
393 |
< |
break; |
394 |
< |
default: |
395 |
< |
sprintf(errmsg, |
396 |
< |
"(%s): cannot make illum for %s \"%s\"", |
397 |
< |
nm, ofun[thisobj.otype].funame, |
398 |
< |
thisobj.oname); |
399 |
< |
error(WARNING, errmsg); |
400 |
< |
doit = 0; |
401 |
< |
break; |
402 |
< |
} |
467 |
> |
doit = doit && issurface(thisobj.otype); |
468 |
|
/* print header? */ |
469 |
|
checkhead(); |
470 |
|
/* process object */ |
471 |
|
if (doit) |
472 |
< |
mkillum(&thisobj, &thisillum, &rt); |
472 |
> |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt, nm); |
473 |
|
else |
474 |
|
printobj(thisillum.altmat, &thisobj); |
475 |
|
/* free arguments */ |
479 |
|
sprintf(errmsg, "(%s): error reading scene", nm); |
480 |
|
error(USER, errmsg); |
481 |
|
} |
417 |
– |
|
418 |
– |
|
419 |
– |
int |
420 |
– |
otype(ofname) /* get object function number from its name */ |
421 |
– |
char *ofname; |
422 |
– |
{ |
423 |
– |
register int i; |
424 |
– |
|
425 |
– |
for (i = 0; i < NUMOTYPE; i++) |
426 |
– |
if (!strcmp(ofun[i].funame, ofname)) |
427 |
– |
return(i); |
428 |
– |
|
429 |
– |
return(-1); /* not found */ |
430 |
– |
} |
431 |
– |
|
432 |
– |
|
433 |
– |
o_default() {} |