1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.23 |
static const char RCSid[] = "$Id: mkillum.c,v 2.22 2004/10/23 18:55:52 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Make illum sources for optimizing rendering process |
6 |
|
|
*/ |
7 |
|
|
|
8 |
greg |
1.3 |
#include <signal.h> |
9 |
schorsch |
2.13 |
#include <ctype.h> |
10 |
greg |
1.3 |
|
11 |
greg |
2.18 |
#include "platform.h" |
12 |
schorsch |
2.22 |
#include "rtprocess.h" |
13 |
greg |
2.15 |
#include "mkillum.h" |
14 |
schorsch |
2.19 |
#include "random.h" |
15 |
greg |
1.1 |
|
16 |
|
|
/* default parameters */ |
17 |
greg |
1.8 |
#define SAMPDENS 48 /* points per projected steradian */ |
18 |
greg |
1.1 |
#define NSAMPS 32 /* samples per point */ |
19 |
|
|
#define DFLMAT "illum_mat" /* material name */ |
20 |
greg |
1.10 |
#define DFLDAT "illum" /* data file name */ |
21 |
greg |
1.1 |
/* selection options */ |
22 |
|
|
#define S_NONE 0 /* select none */ |
23 |
|
|
#define S_ELEM 1 /* select specified element */ |
24 |
|
|
#define S_COMPL 2 /* select all but element */ |
25 |
|
|
#define S_ALL 3 /* select all */ |
26 |
|
|
|
27 |
|
|
/* rtrace command and defaults */ |
28 |
greg |
2.5 |
char *rtargv[64] = { "rtrace", "-dj", ".25", "-dr", "3", "-dv-", |
29 |
greg |
2.17 |
"-ab", "2", "-ad", "1024", "-as", "512", "-aa", ".1", }; |
30 |
greg |
1.4 |
int rtargc = 14; |
31 |
greg |
1.1 |
/* overriding rtrace options */ |
32 |
gregl |
2.10 |
char *myrtopts[] = { "-I-", "-i-", "-ld-", "-ov", "-h-", |
33 |
|
|
"-fff", "-y", "0", NULL }; |
34 |
greg |
1.1 |
|
35 |
greg |
2.20 |
struct rtproc rt0; /* head of rtrace process list */ |
36 |
greg |
1.1 |
|
37 |
greg |
1.2 |
struct illum_args thisillum = { /* our illum and default values */ |
38 |
|
|
0, |
39 |
|
|
DFLMAT, |
40 |
greg |
1.10 |
DFLDAT, |
41 |
greg |
1.2 |
0, |
42 |
|
|
VOIDID, |
43 |
greg |
1.3 |
SAMPDENS, |
44 |
greg |
1.2 |
NSAMPS, |
45 |
greg |
1.12 |
0., |
46 |
greg |
1.2 |
}; |
47 |
greg |
1.1 |
|
48 |
|
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
49 |
|
|
int matselect = S_ALL; /* selection criterion */ |
50 |
|
|
|
51 |
greg |
1.2 |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* object types */ |
52 |
greg |
1.1 |
|
53 |
greg |
2.20 |
char persistfn[] = "pfXXXXXX"; /* persist file name */ |
54 |
|
|
|
55 |
greg |
1.1 |
int gargc; /* global argc */ |
56 |
|
|
char **gargv; /* global argv */ |
57 |
|
|
#define progname gargv[0] |
58 |
|
|
|
59 |
|
|
int doneheader = 0; /* printed header yet? */ |
60 |
greg |
1.2 |
#define checkhead() if (!doneheader++) printhead(gargc,gargv) |
61 |
greg |
1.1 |
|
62 |
greg |
1.2 |
int warnings = 1; /* print warnings? */ |
63 |
|
|
|
64 |
greg |
2.23 |
int done_rprocs(struct rtproc *rtp); |
65 |
greg |
2.20 |
void init(int np); |
66 |
schorsch |
2.19 |
void filter(register FILE *infp, char *name); |
67 |
|
|
void xoptions(char *s, char *nm); |
68 |
|
|
void printopts(void); |
69 |
|
|
void printhead(register int ac, register char **av); |
70 |
|
|
void xobject(FILE *fp, char *nm); |
71 |
greg |
1.1 |
|
72 |
schorsch |
2.19 |
|
73 |
|
|
int |
74 |
|
|
main( /* compute illum distributions using rtrace */ |
75 |
|
|
int argc, |
76 |
|
|
char *argv[] |
77 |
|
|
) |
78 |
greg |
1.1 |
{ |
79 |
greg |
2.20 |
int nprocs = 1; |
80 |
greg |
1.1 |
char *rtpath; |
81 |
greg |
1.3 |
FILE *fp; |
82 |
greg |
1.1 |
register int i; |
83 |
|
|
/* set global arguments */ |
84 |
greg |
1.3 |
gargv = argv; |
85 |
greg |
2.20 |
/* check for -n option */ |
86 |
|
|
if (!strcmp(argv[1], "-n")) { |
87 |
|
|
nprocs = atoi(argv[2]); |
88 |
|
|
if (nprocs <= 0) |
89 |
|
|
error(USER, "illegal number of processes"); |
90 |
|
|
i = 3; |
91 |
|
|
} else |
92 |
|
|
i = 1; |
93 |
greg |
1.1 |
/* set up rtrace command */ |
94 |
greg |
2.20 |
for ( ; i < argc; i++) { |
95 |
greg |
2.6 |
if (argv[i][0] == '<' && argv[i][1] == '\0') |
96 |
greg |
1.3 |
break; |
97 |
greg |
1.1 |
rtargv[rtargc++] = argv[i]; |
98 |
greg |
1.2 |
if (argv[i][0] == '-' && argv[i][1] == 'w') |
99 |
greg |
2.6 |
switch (argv[i][2]) { |
100 |
|
|
case '\0': |
101 |
|
|
warnings = !warnings; |
102 |
|
|
break; |
103 |
|
|
case '+': |
104 |
|
|
case 'T': case 't': |
105 |
|
|
case 'Y': case 'y': |
106 |
|
|
case '1': |
107 |
|
|
warnings = 1; |
108 |
|
|
break; |
109 |
|
|
case '-': |
110 |
|
|
case 'F': case 'f': |
111 |
|
|
case 'N': case 'n': |
112 |
|
|
case '0': |
113 |
|
|
warnings = 0; |
114 |
|
|
break; |
115 |
|
|
} |
116 |
greg |
1.2 |
} |
117 |
greg |
2.3 |
gargc = i; |
118 |
greg |
2.20 |
if (!strcmp(rtargv[--rtargc], "-defaults")) |
119 |
|
|
nprocs = 0; |
120 |
|
|
if (nprocs > 1) { /* add persist file if parallel invocation */ |
121 |
|
|
rtargv[rtargc++] = "-PP"; |
122 |
|
|
rtargv[rtargc++] = mktemp(persistfn); |
123 |
|
|
} |
124 |
|
|
/* add "mandatory" rtrace options */ |
125 |
greg |
1.1 |
for (i = 0; myrtopts[i] != NULL; i++) |
126 |
|
|
rtargv[rtargc++] = myrtopts[i]; |
127 |
greg |
2.20 |
/* finally, put back final argument */ |
128 |
greg |
1.3 |
rtargv[rtargc++] = argv[gargc-1]; |
129 |
greg |
1.1 |
rtargv[rtargc] = NULL; |
130 |
greg |
2.20 |
if (!nprocs) { /* just asking for defaults? */ |
131 |
greg |
1.9 |
printopts(); fflush(stdout); |
132 |
greg |
1.1 |
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
133 |
|
|
if (rtpath == NULL) { |
134 |
|
|
eputs(rtargv[0]); |
135 |
|
|
eputs(": command not found\n"); |
136 |
|
|
exit(1); |
137 |
|
|
} |
138 |
|
|
execv(rtpath, rtargv); |
139 |
greg |
2.20 |
perror(rtpath); /* execv() should not return */ |
140 |
greg |
1.1 |
exit(1); |
141 |
|
|
} |
142 |
greg |
2.3 |
if (gargc < 2 || argv[gargc-1][0] == '-') |
143 |
|
|
error(USER, "missing octree argument"); |
144 |
greg |
1.1 |
/* else initialize and run our calculation */ |
145 |
greg |
2.20 |
init(nprocs); |
146 |
greg |
1.3 |
if (gargc+1 < argc) |
147 |
|
|
for (i = gargc+1; i < argc; i++) { |
148 |
greg |
1.5 |
if ((fp = fopen(argv[i], "r")) == NULL) { |
149 |
greg |
1.3 |
sprintf(errmsg, |
150 |
|
|
"cannot open scene file \"%s\"", argv[i]); |
151 |
|
|
error(SYSTEM, errmsg); |
152 |
|
|
} |
153 |
|
|
filter(fp, argv[i]); |
154 |
|
|
fclose(fp); |
155 |
|
|
} |
156 |
|
|
else |
157 |
|
|
filter(stdin, "standard input"); |
158 |
greg |
2.20 |
quit(0); |
159 |
greg |
1.1 |
} |
160 |
|
|
|
161 |
greg |
2.20 |
static void |
162 |
greg |
2.21 |
killpersist(void) /* kill persistent rtrace process */ |
163 |
greg |
2.20 |
{ |
164 |
|
|
FILE *fp = fopen(persistfn, "r"); |
165 |
|
|
int pid; |
166 |
|
|
|
167 |
|
|
if (fp == NULL) |
168 |
|
|
return; |
169 |
|
|
if (fscanf(fp, "%*s %d", &pid) != 1 || kill(pid, SIGALRM) < 0) |
170 |
|
|
unlink(persistfn); |
171 |
|
|
fclose(fp); |
172 |
|
|
} |
173 |
greg |
1.1 |
|
174 |
greg |
2.23 |
int |
175 |
|
|
done_rprocs(struct rtproc *rtp) |
176 |
|
|
{ |
177 |
|
|
int st0, st1 = 0; |
178 |
|
|
|
179 |
|
|
if (rtp->next != NULL) { /* close last opened first! */ |
180 |
|
|
st1 = done_rprocs(rtp->next); |
181 |
|
|
free((void *)rtp->next); |
182 |
|
|
rtp->next = NULL; |
183 |
|
|
} |
184 |
|
|
st0 = close_process(&rtp->pd); |
185 |
|
|
if (st0 < 0) |
186 |
|
|
error(WARNING, "unknown return status from rtrace process"); |
187 |
|
|
else if (st0 > 0) |
188 |
|
|
return(st0); |
189 |
|
|
return(st1); |
190 |
|
|
} |
191 |
|
|
|
192 |
greg |
2.11 |
void |
193 |
greg |
2.20 |
quit(int status) /* exit with status */ |
194 |
greg |
1.3 |
{ |
195 |
|
|
int rtstat; |
196 |
|
|
|
197 |
greg |
2.20 |
if (rt0.next != NULL) /* terminate persistent rtrace */ |
198 |
|
|
killpersist(); |
199 |
|
|
/* clean up rtrace process(es) */ |
200 |
greg |
2.23 |
rtstat = done_rprocs(&rt0); |
201 |
|
|
if (status == 0) |
202 |
|
|
status = rtstat; |
203 |
greg |
1.3 |
exit(status); |
204 |
|
|
} |
205 |
|
|
|
206 |
schorsch |
2.19 |
void |
207 |
greg |
2.20 |
init(int np) /* start rtrace and set up buffers */ |
208 |
greg |
1.1 |
{ |
209 |
greg |
2.20 |
struct rtproc *rtp; |
210 |
|
|
int i; |
211 |
greg |
1.1 |
int maxbytes; |
212 |
greg |
1.3 |
/* set up object functions */ |
213 |
|
|
ofun[OBJ_FACE].funp = o_face; |
214 |
greg |
1.4 |
ofun[OBJ_SPHERE].funp = o_sphere; |
215 |
greg |
1.3 |
ofun[OBJ_RING].funp = o_ring; |
216 |
|
|
/* set up signal handling */ |
217 |
schorsch |
2.14 |
#ifdef SIGPIPE /* not present on Windows */ |
218 |
greg |
1.3 |
signal(SIGPIPE, quit); |
219 |
schorsch |
2.13 |
#endif |
220 |
greg |
2.20 |
rtp = &rt0; /* start rtrace process(es) */ |
221 |
|
|
for (i = 0; i++ < np; ) { |
222 |
|
|
errno = 0; |
223 |
|
|
maxbytes = open_process(&rtp->pd, rtargv); |
224 |
|
|
if (maxbytes == 0) { |
225 |
|
|
eputs(rtargv[0]); |
226 |
|
|
eputs(": command not found\n"); |
227 |
|
|
exit(1); |
228 |
|
|
} |
229 |
|
|
if (maxbytes < 0) |
230 |
|
|
error(SYSTEM, "cannot start rtrace process"); |
231 |
|
|
if (!i && np > 1) |
232 |
|
|
sleep(2); /* wait for persist file */ |
233 |
|
|
rtp->bsiz = maxbytes/(6*sizeof(float)); |
234 |
|
|
rtp->buf = (float *)malloc(6*sizeof(float)*rtp->bsiz--); |
235 |
|
|
rtp->dest = (float **)calloc(rtp->bsiz, sizeof(float *)); |
236 |
|
|
if (rtp->buf == NULL || rtp->dest == NULL) |
237 |
|
|
error(SYSTEM, "out of memory in init"); |
238 |
|
|
rtp->nrays = 0; |
239 |
|
|
if (i == np) /* last process? */ |
240 |
|
|
break; |
241 |
|
|
rtp->next = (struct rtproc *)malloc(sizeof(struct rtproc)); |
242 |
|
|
if (rtp->next == NULL) |
243 |
|
|
error(SYSTEM, "out of memory in init"); |
244 |
|
|
rtp = rtp->next; |
245 |
greg |
1.1 |
} |
246 |
greg |
2.20 |
rtp->next = NULL; |
247 |
greg |
1.6 |
/* set up urand */ |
248 |
greg |
2.7 |
initurand(16384); |
249 |
greg |
1.1 |
} |
250 |
|
|
|
251 |
|
|
|
252 |
greg |
2.11 |
void |
253 |
schorsch |
2.19 |
eputs( /* put string to stderr */ |
254 |
|
|
register char *s |
255 |
|
|
) |
256 |
greg |
1.1 |
{ |
257 |
|
|
static int midline = 0; |
258 |
|
|
|
259 |
|
|
if (!*s) return; |
260 |
|
|
if (!midline) { |
261 |
|
|
fputs(progname, stderr); |
262 |
|
|
fputs(": ", stderr); |
263 |
|
|
} |
264 |
|
|
fputs(s, stderr); |
265 |
|
|
midline = s[strlen(s)-1] != '\n'; |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
|
269 |
greg |
2.11 |
void |
270 |
greg |
1.2 |
wputs(s) /* print warning if enabled */ |
271 |
|
|
char *s; |
272 |
|
|
{ |
273 |
|
|
if (warnings) |
274 |
|
|
eputs(s); |
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
|
278 |
schorsch |
2.19 |
void |
279 |
|
|
filter( /* process stream */ |
280 |
|
|
register FILE *infp, |
281 |
|
|
char *name |
282 |
|
|
) |
283 |
greg |
1.1 |
{ |
284 |
|
|
char buf[512]; |
285 |
|
|
FILE *pfp; |
286 |
|
|
register int c; |
287 |
|
|
|
288 |
|
|
while ((c = getc(infp)) != EOF) { |
289 |
|
|
if (isspace(c)) |
290 |
|
|
continue; |
291 |
|
|
if (c == '#') { /* comment/options */ |
292 |
|
|
buf[0] = c; |
293 |
|
|
fgets(buf+1, sizeof(buf)-1, infp); |
294 |
greg |
1.2 |
xoptions(buf, name); |
295 |
greg |
1.1 |
} else if (c == '!') { /* command */ |
296 |
|
|
buf[0] = c; |
297 |
|
|
fgetline(buf+1, sizeof(buf)-1, infp); |
298 |
|
|
if ((pfp = popen(buf+1, "r")) == NULL) { |
299 |
|
|
sprintf(errmsg, "cannot execute \"%s\"", buf); |
300 |
|
|
error(SYSTEM, errmsg); |
301 |
|
|
} |
302 |
greg |
1.2 |
filter(pfp, buf); |
303 |
greg |
1.1 |
pclose(pfp); |
304 |
|
|
} else { /* object */ |
305 |
|
|
ungetc(c, infp); |
306 |
|
|
xobject(infp, name); |
307 |
|
|
} |
308 |
|
|
} |
309 |
|
|
} |
310 |
|
|
|
311 |
|
|
|
312 |
schorsch |
2.19 |
void |
313 |
|
|
xoptions( /* process options in string s */ |
314 |
|
|
char *s, |
315 |
|
|
char *nm |
316 |
|
|
) |
317 |
greg |
1.1 |
{ |
318 |
|
|
extern FILE *freopen(); |
319 |
|
|
char buf[64]; |
320 |
|
|
int nerrs = 0; |
321 |
|
|
register char *cp; |
322 |
|
|
|
323 |
greg |
1.2 |
if (strncmp(s, "#@mkillum", 9) || !isspace(s[9])) { |
324 |
|
|
fputs(s, stdout); /* not for us */ |
325 |
greg |
1.1 |
return; |
326 |
greg |
1.2 |
} |
327 |
greg |
1.1 |
cp = s+10; |
328 |
|
|
while (*cp) { |
329 |
|
|
switch (*cp) { |
330 |
|
|
case ' ': |
331 |
|
|
case '\t': |
332 |
|
|
case '\n': |
333 |
greg |
2.11 |
case '\r': |
334 |
|
|
case '\f': |
335 |
greg |
1.1 |
cp++; |
336 |
|
|
continue; |
337 |
|
|
case 'm': /* material name */ |
338 |
greg |
1.2 |
if (*++cp != '=') |
339 |
greg |
1.1 |
break; |
340 |
greg |
2.8 |
if (!*++cp || isspace(*cp)) |
341 |
greg |
1.2 |
break; |
342 |
greg |
1.1 |
atos(thisillum.matname, MAXSTR, cp); |
343 |
|
|
cp = sskip(cp); |
344 |
|
|
if (!(thisillum.flags & IL_DATCLB)) { |
345 |
|
|
strcpy(thisillum.datafile, thisillum.matname); |
346 |
|
|
thisillum.dfnum = 0; |
347 |
|
|
} |
348 |
|
|
continue; |
349 |
|
|
case 'f': /* data file name */ |
350 |
greg |
1.2 |
if (*++cp != '=') |
351 |
greg |
1.1 |
break; |
352 |
greg |
2.8 |
if (!*++cp || isspace(*cp)) { |
353 |
greg |
1.6 |
strcpy(thisillum.datafile,thisillum.matname); |
354 |
greg |
1.10 |
thisillum.dfnum = 0; |
355 |
greg |
1.1 |
thisillum.flags &= ~IL_DATCLB; |
356 |
|
|
continue; |
357 |
|
|
} |
358 |
|
|
atos(thisillum.datafile, MAXSTR, cp); |
359 |
|
|
cp = sskip(cp); |
360 |
|
|
thisillum.dfnum = 0; |
361 |
|
|
thisillum.flags |= IL_DATCLB; |
362 |
|
|
continue; |
363 |
|
|
case 'i': /* include material */ |
364 |
|
|
case 'e': /* exclude material */ |
365 |
greg |
1.6 |
if (cp[1] != '=') |
366 |
greg |
1.1 |
break; |
367 |
greg |
1.7 |
matselect = (*cp == 'i') ? S_ELEM : S_COMPL; |
368 |
|
|
cp += 2; |
369 |
|
|
atos(matcheck, MAXSTR, cp); |
370 |
greg |
1.1 |
cp = sskip(cp); |
371 |
|
|
continue; |
372 |
|
|
case 'a': /* use everything */ |
373 |
|
|
cp = sskip(cp); |
374 |
|
|
matselect = S_ALL; |
375 |
|
|
continue; |
376 |
|
|
case 'n': /* use nothing (passive) */ |
377 |
|
|
cp = sskip(cp); |
378 |
|
|
matselect = S_NONE; |
379 |
|
|
continue; |
380 |
|
|
case 'c': /* color calculation */ |
381 |
greg |
1.2 |
if (*++cp != '=') |
382 |
greg |
1.1 |
break; |
383 |
greg |
1.2 |
switch (*++cp) { |
384 |
greg |
1.1 |
case 'a': /* average */ |
385 |
greg |
1.6 |
thisillum.flags = (thisillum.flags|IL_COLAVG) |
386 |
|
|
& ~IL_COLDST; |
387 |
greg |
1.1 |
break; |
388 |
|
|
case 'd': /* distribution */ |
389 |
greg |
1.5 |
thisillum.flags |= (IL_COLDST|IL_COLAVG); |
390 |
greg |
1.1 |
break; |
391 |
|
|
case 'n': /* none */ |
392 |
|
|
thisillum.flags &= ~(IL_COLAVG|IL_COLDST); |
393 |
|
|
break; |
394 |
|
|
default: |
395 |
|
|
goto opterr; |
396 |
|
|
} |
397 |
|
|
cp = sskip(cp); |
398 |
|
|
continue; |
399 |
|
|
case 'd': /* point sample density */ |
400 |
greg |
1.2 |
if (*++cp != '=') |
401 |
greg |
1.1 |
break; |
402 |
greg |
2.11 |
if (!isintd(++cp, " \t\n\r")) |
403 |
greg |
1.1 |
break; |
404 |
greg |
1.3 |
thisillum.sampdens = atoi(cp); |
405 |
greg |
1.1 |
cp = sskip(cp); |
406 |
|
|
continue; |
407 |
|
|
case 's': /* point super-samples */ |
408 |
greg |
1.2 |
if (*++cp != '=') |
409 |
greg |
1.1 |
break; |
410 |
greg |
2.11 |
if (!isintd(++cp, " \t\n\r")) |
411 |
greg |
1.1 |
break; |
412 |
|
|
thisillum.nsamps = atoi(cp); |
413 |
|
|
cp = sskip(cp); |
414 |
|
|
continue; |
415 |
greg |
1.3 |
case 'l': /* light sources */ |
416 |
greg |
1.4 |
cp++; |
417 |
|
|
if (*cp == '+') |
418 |
greg |
1.3 |
thisillum.flags |= IL_LIGHT; |
419 |
greg |
1.4 |
else if (*cp == '-') |
420 |
|
|
thisillum.flags &= ~IL_LIGHT; |
421 |
greg |
1.3 |
else |
422 |
greg |
1.4 |
break; |
423 |
|
|
cp++; |
424 |
greg |
1.3 |
continue; |
425 |
greg |
1.12 |
case 'b': /* brightness */ |
426 |
|
|
if (*++cp != '=') |
427 |
|
|
break; |
428 |
greg |
2.11 |
if (!isfltd(++cp, " \t\n\r")) |
429 |
greg |
1.12 |
break; |
430 |
|
|
thisillum.minbrt = atof(cp); |
431 |
greg |
1.13 |
if (thisillum.minbrt < 0.) |
432 |
|
|
thisillum.minbrt = 0.; |
433 |
greg |
1.12 |
cp = sskip(cp); |
434 |
|
|
continue; |
435 |
greg |
1.1 |
case 'o': /* output file */ |
436 |
greg |
1.2 |
if (*++cp != '=') |
437 |
greg |
1.1 |
break; |
438 |
greg |
2.8 |
if (!*++cp || isspace(*cp)) |
439 |
greg |
1.2 |
break; |
440 |
greg |
1.1 |
atos(buf, sizeof(buf), cp); |
441 |
|
|
cp = sskip(cp); |
442 |
|
|
if (freopen(buf, "w", stdout) == NULL) { |
443 |
|
|
sprintf(errmsg, |
444 |
|
|
"cannot open output file \"%s\"", buf); |
445 |
|
|
error(SYSTEM, errmsg); |
446 |
|
|
} |
447 |
|
|
doneheader = 0; |
448 |
|
|
continue; |
449 |
greg |
1.6 |
case '!': /* processed file! */ |
450 |
greg |
1.7 |
sprintf(errmsg, "(%s): already processed!", nm); |
451 |
greg |
1.6 |
error(WARNING, errmsg); |
452 |
greg |
1.7 |
matselect = S_NONE; |
453 |
greg |
1.6 |
return; |
454 |
greg |
1.1 |
} |
455 |
|
|
opterr: /* skip faulty option */ |
456 |
greg |
2.9 |
while (*cp && !isspace(*cp)) |
457 |
|
|
cp++; |
458 |
greg |
1.1 |
nerrs++; |
459 |
|
|
} |
460 |
greg |
1.2 |
/* print header? */ |
461 |
|
|
checkhead(); |
462 |
|
|
/* issue warnings? */ |
463 |
greg |
1.1 |
if (nerrs) { |
464 |
|
|
sprintf(errmsg, "(%s): %d error(s) in option line:", |
465 |
|
|
nm, nerrs); |
466 |
|
|
error(WARNING, errmsg); |
467 |
greg |
1.2 |
wputs(s); |
468 |
|
|
printf("# %s: the following option line has %d error(s):\n", |
469 |
|
|
progname, nerrs); |
470 |
greg |
1.1 |
} |
471 |
greg |
1.2 |
/* print pure comment */ |
472 |
greg |
1.4 |
printf("# %s", s+2); |
473 |
greg |
1.9 |
} |
474 |
|
|
|
475 |
schorsch |
2.19 |
void |
476 |
|
|
printopts(void) /* print out option default values */ |
477 |
greg |
1.9 |
{ |
478 |
greg |
1.11 |
printf("m=%-15s\t\t# material name\n", thisillum.matname); |
479 |
|
|
printf("f=%-15s\t\t# data file name\n", thisillum.datafile); |
480 |
greg |
2.2 |
if (thisillum.flags & IL_COLAVG) |
481 |
|
|
if (thisillum.flags & IL_COLDST) |
482 |
|
|
printf("c=d\t\t\t\t# color distribution\n"); |
483 |
|
|
else |
484 |
|
|
printf("c=a\t\t\t\t# color average\n"); |
485 |
|
|
else |
486 |
|
|
printf("c=n\t\t\t\t# color none\n"); |
487 |
|
|
if (thisillum.flags & IL_LIGHT) |
488 |
|
|
printf("l+\t\t\t\t# light type on\n"); |
489 |
|
|
else |
490 |
|
|
printf("l-\t\t\t\t# light type off\n"); |
491 |
greg |
1.9 |
printf("d=%d\t\t\t\t# density of points\n", thisillum.sampdens); |
492 |
|
|
printf("s=%d\t\t\t\t# samples per point\n", thisillum.nsamps); |
493 |
greg |
1.12 |
printf("b=%f\t\t\t# minimum average brightness\n", thisillum.minbrt); |
494 |
greg |
1.1 |
} |
495 |
greg |
1.2 |
|
496 |
|
|
|
497 |
schorsch |
2.19 |
void |
498 |
|
|
printhead( /* print out header */ |
499 |
|
|
register int ac, |
500 |
|
|
register char **av |
501 |
|
|
) |
502 |
greg |
1.2 |
{ |
503 |
|
|
putchar('#'); |
504 |
|
|
while (ac-- > 0) { |
505 |
|
|
putchar(' '); |
506 |
|
|
fputs(*av++, stdout); |
507 |
|
|
} |
508 |
greg |
1.6 |
fputs("\n#@mkillum !\n", stdout); |
509 |
greg |
1.2 |
} |
510 |
|
|
|
511 |
|
|
|
512 |
schorsch |
2.19 |
void |
513 |
|
|
xobject( /* translate an object from fp */ |
514 |
|
|
FILE *fp, |
515 |
|
|
char *nm |
516 |
|
|
) |
517 |
greg |
1.2 |
{ |
518 |
|
|
OBJREC thisobj; |
519 |
|
|
char str[MAXSTR]; |
520 |
|
|
int doit; |
521 |
|
|
/* read the object */ |
522 |
|
|
if (fgetword(thisillum.altmat, MAXSTR, fp) == NULL) |
523 |
|
|
goto readerr; |
524 |
|
|
if (fgetword(str, MAXSTR, fp) == NULL) |
525 |
|
|
goto readerr; |
526 |
|
|
/* is it an alias? */ |
527 |
greg |
2.12 |
if (!strcmp(str, ALIASKEY)) { |
528 |
greg |
1.2 |
if (fgetword(str, MAXSTR, fp) == NULL) |
529 |
|
|
goto readerr; |
530 |
greg |
2.12 |
printf("\n%s %s %s", thisillum.altmat, ALIASKEY, str); |
531 |
greg |
1.2 |
if (fgetword(str, MAXSTR, fp) == NULL) |
532 |
|
|
goto readerr; |
533 |
greg |
1.4 |
printf("\t%s\n", str); |
534 |
greg |
1.2 |
return; |
535 |
|
|
} |
536 |
greg |
1.4 |
thisobj.omod = OVOID; /* unused field */ |
537 |
greg |
1.2 |
if ((thisobj.otype = otype(str)) < 0) { |
538 |
|
|
sprintf(errmsg, "(%s): unknown type \"%s\"", nm, str); |
539 |
|
|
error(USER, errmsg); |
540 |
|
|
} |
541 |
|
|
if (fgetword(str, MAXSTR, fp) == NULL) |
542 |
|
|
goto readerr; |
543 |
|
|
thisobj.oname = str; |
544 |
|
|
if (readfargs(&thisobj.oargs, fp) != 1) |
545 |
|
|
goto readerr; |
546 |
|
|
thisobj.os = NULL; |
547 |
|
|
/* check for translation */ |
548 |
|
|
switch (matselect) { |
549 |
|
|
case S_NONE: |
550 |
|
|
doit = 0; |
551 |
|
|
break; |
552 |
|
|
case S_ALL: |
553 |
greg |
1.4 |
doit = 1; |
554 |
greg |
1.2 |
break; |
555 |
|
|
case S_ELEM: |
556 |
|
|
doit = !strcmp(thisillum.altmat, matcheck); |
557 |
|
|
break; |
558 |
|
|
case S_COMPL: |
559 |
|
|
doit = strcmp(thisillum.altmat, matcheck); |
560 |
|
|
break; |
561 |
|
|
} |
562 |
greg |
1.4 |
doit = doit && issurface(thisobj.otype); |
563 |
greg |
1.2 |
/* print header? */ |
564 |
|
|
checkhead(); |
565 |
|
|
/* process object */ |
566 |
|
|
if (doit) |
567 |
greg |
2.20 |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt0, nm); |
568 |
greg |
1.2 |
else |
569 |
|
|
printobj(thisillum.altmat, &thisobj); |
570 |
|
|
/* free arguments */ |
571 |
|
|
freefargs(&thisobj.oargs); |
572 |
|
|
return; |
573 |
|
|
readerr: |
574 |
|
|
sprintf(errmsg, "(%s): error reading scene", nm); |
575 |
|
|
error(USER, errmsg); |
576 |
|
|
} |