102 |
|
char *rtargv[256+2*MAXMODLIST] = { "rtrace", |
103 |
|
"-dj", ".5", "-dr", "3", |
104 |
|
"-ab", "1", "-ad", "128", }; |
105 |
+ |
|
106 |
|
int rtargc = 9; |
107 |
|
/* overriding rtrace options */ |
108 |
< |
char *myrtopts[] = { "-o~~TmWdp", "-h-", "-x", "1", "-y", "0", |
108 |
> |
char *myrtopts[] = { "-h-", "-x", "1", "-y", "0", |
109 |
|
"-dt", "0", "-as", "0", "-aa", "0", NULL }; |
110 |
|
|
111 |
+ |
#define RTCOEFF "-o~~TmWdp" /* compute coefficients only */ |
112 |
+ |
#define RTCONTRIB "-o~~TmVdp" /* compute ray contributions */ |
113 |
+ |
|
114 |
|
struct rtproc rt0; /* head of rtrace process list */ |
115 |
|
|
116 |
|
struct rtproc *rt_unproc = NULL; /* unprocessed ray trees */ |
212 |
|
int |
213 |
|
main(int argc, char *argv[]) |
214 |
|
{ |
215 |
+ |
int contrib = 0; |
216 |
|
int nprocs = 1; |
217 |
|
int recover = 0; |
218 |
|
char *curout = NULL; |
223 |
|
/* need at least one argument */ |
224 |
|
if (argc < 2) { |
225 |
|
fprintf(stderr, |
226 |
< |
"Usage: %s [-n nprocs][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", |
226 |
> |
"Usage: %s [-n nprocs][-V][-r][-e expr][-f source][-o ospec][-b binv] {-m mod | -M file} [rtrace options] octree\n", |
227 |
|
argv[0]); |
228 |
|
exit(1); |
229 |
|
} |
245 |
|
} |
246 |
|
if (argv[i][0] == '-') |
247 |
|
switch (argv[i][1]) { |
243 |
– |
case 'r': /* recover output */ |
244 |
– |
if (argv[i][2]) break; |
245 |
– |
recover++; |
246 |
– |
continue; |
248 |
|
case 'n': /* number of processes */ |
249 |
|
if (argv[i][2] || i >= argc-2) break; |
250 |
|
nprocs = atoi(argv[++i]); |
251 |
|
if (nprocs <= 0) |
252 |
|
error(USER, "illegal number of processes"); |
253 |
|
continue; |
254 |
+ |
case 'V': /* output contributions */ |
255 |
+ |
switch (argv[i][2]) { |
256 |
+ |
case '\0': |
257 |
+ |
contrib = !contrib; |
258 |
+ |
continue; |
259 |
+ |
case '+': case '1': |
260 |
+ |
case 'T': case 't': |
261 |
+ |
case 'Y': case 'y': |
262 |
+ |
contrib = 1; |
263 |
+ |
continue; |
264 |
+ |
case '-': case '0': |
265 |
+ |
case 'F': case 'f': |
266 |
+ |
case 'N': case 'n': |
267 |
+ |
contrib = 0; |
268 |
+ |
continue; |
269 |
+ |
} |
270 |
+ |
break; |
271 |
+ |
case 'r': /* recover output */ |
272 |
+ |
if (argv[i][2]) break; |
273 |
+ |
recover++; |
274 |
+ |
continue; |
275 |
|
case 'h': /* output header? */ |
276 |
|
switch (argv[i][2]) { |
277 |
|
case '\0': |
347 |
|
rtargv[rtargc++] = argv[++i]; |
348 |
|
addmodfile(argv[i], curout, binval, bincnt); |
349 |
|
continue; |
350 |
+ |
case 'P': /* persist file */ |
351 |
+ |
error(USER, "persist file is automatic"); |
352 |
+ |
break; |
353 |
|
} |
354 |
|
rtargv[rtargc++] = argv[i]; /* assume rtrace option */ |
355 |
|
} |
358 |
|
/* add "mandatory" rtrace settings */ |
359 |
|
for (j = 0; myrtopts[j] != NULL; j++) |
360 |
|
rtargv[rtargc++] = myrtopts[j]; |
361 |
+ |
rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF; |
362 |
|
/* just asking for defaults? */ |
363 |
|
if (!strcmp(argv[i], "-defaults")) { |
364 |
|
char sxres[16], syres[16]; |
365 |
|
char *rtpath; |
366 |
|
printf("-n %-2d\t\t\t\t# number of processes\n", nprocs); |
367 |
+ |
printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-', |
368 |
+ |
contrib ? "contributions" : "coefficients"); |
369 |
|
fflush(stdout); /* report OUR options */ |
370 |
|
rtargv[rtargc++] = header ? "-h+" : "-h-"; |
371 |
|
sprintf(fmt, "-f%c%c", inpfmt, outfmt); |
376 |
|
rtargv[rtargc++] = "-y"; |
377 |
|
sprintf(syres, "%d", yres); |
378 |
|
rtargv[rtargc++] = syres; |
351 |
– |
rtargv[rtargc++] = "-oTW"; |
379 |
|
rtargv[rtargc++] = "-defaults"; |
380 |
|
rtargv[rtargc] = NULL; |
381 |
|
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
787 |
|
int |
788 |
|
getinp(char *buf, FILE *fp) |
789 |
|
{ |
790 |
+ |
double dv[3]; |
791 |
+ |
float fv[3]; |
792 |
|
char *cp; |
793 |
|
int i; |
794 |
|
|
797 |
|
cp = buf; /* make sure we get 6 floats */ |
798 |
|
for (i = 0; i < 6; i++) { |
799 |
|
if (fgetword(cp, buf+127-cp, fp) == NULL) |
800 |
< |
return 0; |
800 |
> |
return -1; |
801 |
> |
if (i >= 3) |
802 |
> |
dv[i-3] = atof(cp); |
803 |
|
if ((cp = fskip(cp)) == NULL || *cp) |
804 |
< |
return 0; |
804 |
> |
return -1; |
805 |
|
*cp++ = ' '; |
806 |
|
} |
807 |
|
getc(fp); /* get/put eol */ |
808 |
|
*cp-- = '\0'; *cp = '\n'; |
809 |
+ |
if (DOT(dv,dv) <= FTINY*FTINY) |
810 |
+ |
return 0; /* dummy ray */ |
811 |
|
return strlen(buf); |
812 |
|
case 'f': |
813 |
|
if (fread(buf, sizeof(float), 6, fp) < 6) |
814 |
< |
return 0; |
814 |
> |
return -1; |
815 |
> |
memcpy(fv, buf+3*sizeof(float), 3*sizeof(float)); |
816 |
> |
if (DOT(fv,fv) <= FTINY*FTINY) |
817 |
> |
return 0; /* dummy ray */ |
818 |
|
return sizeof(float)*6; |
819 |
|
case 'd': |
820 |
|
if (fread(buf, sizeof(double), 6, fp) < 6) |
821 |
< |
return 0; |
821 |
> |
return -1; |
822 |
> |
memcpy(dv, buf+3*sizeof(double), 3*sizeof(double)); |
823 |
> |
if (DOT(dv,dv) <= FTINY*FTINY) |
824 |
> |
return 0; /* dummy ray */ |
825 |
|
return sizeof(double)*6; |
826 |
|
} |
827 |
|
error(INTERNAL, "botched input format"); |
828 |
< |
return 0; /* pro forma return */ |
828 |
> |
return -1; /* pro forma return */ |
829 |
|
} |
830 |
|
|
831 |
|
static float rparams[9]; /* traced ray parameters */ |
985 |
|
if (!n || !(isalpha(*cp) | (*cp == '_'))) |
986 |
|
error(USER, "bad modifier name from rtrace"); |
987 |
|
/* get modifier name */ |
988 |
< |
while (n > 0 && *cp != '\t') { |
988 |
> |
while (n > 1 && *cp != '\t') { |
989 |
> |
if (mnp - modname >= sizeof(modname)-2) |
990 |
> |
error(INTERNAL, "modifier name too long"); |
991 |
|
*mnp++ = *cp++; n--; |
992 |
|
} |
993 |
|
*mnp = '\0'; |
1001 |
|
} |
1002 |
|
done_contrib(); /* sum up contributions & output */ |
1003 |
|
lastdone = rtp->raynum; |
1004 |
< |
free(rtp->buf); /* free up buffer space */ |
1004 |
> |
if (rtp->buf != NULL) /* free up buffer space */ |
1005 |
> |
free(rtp->buf); |
1006 |
|
rt_unproc = rtp->next; |
1007 |
|
free(rtp); /* done with this ray tree */ |
1008 |
|
} |
1090 |
|
int iblen; |
1091 |
|
struct rtproc *rtp; |
1092 |
|
/* loop over input */ |
1093 |
< |
while ((iblen = getinp(inpbuf, fin)) > 0) { |
1094 |
< |
if (lastray+1 < lastray || /* need reset? */ |
1095 |
< |
queue_length() > 10*nrtprocs()) { |
1093 |
> |
while ((iblen = getinp(inpbuf, fin)) >= 0) { |
1094 |
> |
if (!iblen || /* need reset? */ |
1095 |
> |
queue_length() > 10*nrtprocs() || |
1096 |
> |
lastray+1 < lastray) { |
1097 |
|
while (wait_rproc() != NULL) |
1098 |
|
process_queue(); |
1099 |
|
if (lastray+1 < lastray) |
1100 |
|
lastdone = lastray = 0; |
1101 |
|
} |
1102 |
|
rtp = get_rproc(); /* get avail. rtrace process */ |
1103 |
< |
rtp->raynum = ++lastray; /* assign ray to it */ |
1104 |
< |
writebuf(rtp->pd.w, inpbuf, iblen); |
1105 |
< |
if (raysleft && !--raysleft) |
1106 |
< |
break; |
1103 |
> |
rtp->raynum = ++lastray; /* assign ray */ |
1104 |
> |
if (iblen) { /* trace ray if valid */ |
1105 |
> |
writebuf(rtp->pd.w, inpbuf, iblen); |
1106 |
> |
} else { /* else bypass dummy ray */ |
1107 |
> |
queue_raytree(rtp); /* empty tree */ |
1108 |
> |
if ((yres <= 0) | (waitflush > 1)) |
1109 |
> |
waitflush = 1; /* flush after this */ |
1110 |
> |
} |
1111 |
|
process_queue(); /* catch up with results */ |
1112 |
+ |
if (raysleft && !--raysleft) |
1113 |
+ |
break; /* preemptive EOI */ |
1114 |
|
} |
1115 |
|
while (wait_rproc() != NULL) /* process outstanding rays */ |
1116 |
|
process_queue(); |
1268 |
|
lu_doall(&ofiletab, myseeko, &nvals); |
1269 |
|
/* skip repeated input */ |
1270 |
|
for (nvals = 0; nvals < lastout; nvals++) |
1271 |
< |
if (getinp(oname, fin) <= 0) |
1271 |
> |
if (getinp(oname, fin) < 0) |
1272 |
|
error(USER, "unexpected EOF on input"); |
1273 |
|
lastray = lastdone = (unsigned long)lastout; |
1274 |
|
if (raysleft) |