1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
42 |
|
int outform = 'a'; /* output format */ |
43 |
|
char *outvals = "v"; /* output specification */ |
44 |
|
|
45 |
+ |
char *tralist[128]; /* list of modifers to trace (or no) */ |
46 |
+ |
int traincl = -1; /* include == 1, exclude == 0 */ |
47 |
+ |
#define MAXTSET 511 /* maximum number in trace set */ |
48 |
+ |
OBJECT traset[MAXTSET+1]={0}; /* trace include/exclude set */ |
49 |
+ |
|
50 |
|
int hresolu = 0; /* horizontal (scan) size */ |
51 |
|
int vresolu = 0; /* vertical resolution */ |
52 |
|
|
55 |
|
double shadcert = .5; /* shadow certainty */ |
56 |
|
int directrelay = 1; /* number of source relays */ |
57 |
|
int vspretest = 512; /* virtual source pretest density */ |
58 |
< |
int directinvis = 0; /* sources invisible? */ |
58 |
> |
int directvis = 1; /* sources visible? */ |
59 |
|
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
60 |
|
|
61 |
|
double specthresh = .15; /* specular sampling threshold */ |
78 |
|
static RAY thisray; /* for our convenience */ |
79 |
|
|
80 |
|
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
81 |
< |
oputp(), oputn(), oputs(), oputw(), oputm(); |
81 |
> |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
82 |
|
|
83 |
< |
static int (*ray_out[10])(), (*every_out[10])(); |
84 |
< |
static int castonly; |
83 |
> |
static int ourtrace(), tabin(); |
84 |
> |
static int (*ray_out[16])(), (*every_out[16])(); |
85 |
> |
static int castonly = 0; |
86 |
|
|
87 |
|
static int puta(), putf(), putd(); |
88 |
|
|
92 |
|
quit(code) /* quit program */ |
93 |
|
int code; |
94 |
|
{ |
95 |
+ |
#ifndef NIX |
96 |
+ |
headclean(); /* delete header file */ |
97 |
+ |
pfclean(); /* clean up persist files */ |
98 |
+ |
#endif |
99 |
|
exit(code); |
100 |
|
} |
101 |
|
|
145 |
|
default: |
146 |
|
error(CONSISTENCY, "botched output format"); |
147 |
|
} |
148 |
< |
if (hresolu > 0 && vresolu > 0) |
149 |
< |
fprtresolu(hresolu, vresolu, stdout); |
148 |
> |
if (hresolu > 0) { |
149 |
> |
if (vresolu > 0) |
150 |
> |
fprtresolu(hresolu, vresolu, stdout); |
151 |
> |
fflush(stdout); |
152 |
> |
} |
153 |
|
/* process file */ |
154 |
|
while (getvec(orig, inform, fp) == 0 && |
155 |
|
getvec(direc, inform, fp) == 0) { |
163 |
|
if (imm_irrad) |
164 |
|
irrad(orig, direc); |
165 |
|
else |
166 |
< |
traceray(orig, direc); |
166 |
> |
rad(orig, direc); |
167 |
|
/* flush if time */ |
168 |
|
if (--nextflush == 0) { |
169 |
|
fflush(stdout); |
174 |
|
if (--vcount == 0) /* check for end */ |
175 |
|
break; |
176 |
|
} |
177 |
+ |
fflush(stdout); |
178 |
|
if (vcount > 0) |
179 |
|
error(USER, "read error"); |
180 |
< |
fclose(fp); |
180 |
> |
if (fname != NULL) |
181 |
> |
fclose(fp); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
setoutput(vs) /* set up output tables */ |
186 |
|
register char *vs; |
187 |
|
{ |
188 |
< |
extern int ourtrace(), (*trace)(); |
188 |
> |
extern int (*trace)(); |
189 |
|
register int (**table)() = ray_out; |
190 |
|
|
191 |
|
castonly = 1; |
217 |
|
case 'p': /* point */ |
218 |
|
*table++ = oputp; |
219 |
|
break; |
220 |
< |
case 'n': /* normal */ |
220 |
> |
case 'n': /* perturbed normal */ |
221 |
|
*table++ = oputn; |
222 |
+ |
castonly = 0; |
223 |
|
break; |
224 |
+ |
case 'N': /* unperturbed normal */ |
225 |
+ |
*table++ = oputN; |
226 |
+ |
break; |
227 |
|
case 's': /* surface */ |
228 |
|
*table++ = oputs; |
229 |
|
break; |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
< |
traceray(org, dir) /* compute and print ray value(s) */ |
241 |
> |
rad(org, dir) /* compute and print ray value(s) */ |
242 |
|
FVECT org, dir; |
243 |
|
{ |
225 |
– |
register int (**tp)(); |
226 |
– |
|
244 |
|
VCOPY(thisray.rorg, org); |
245 |
|
VCOPY(thisray.rdir, dir); |
246 |
+ |
thisray.rmax = 0.0; |
247 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
248 |
|
if (castonly) |
249 |
|
localhit(&thisray, &thescene) || sourcehit(&thisray); |
250 |
|
else |
251 |
|
rayvalue(&thisray); |
252 |
< |
|
235 |
< |
if (ray_out[0] == NULL) |
236 |
< |
return; |
237 |
< |
for (tp = ray_out; *tp != NULL; tp++) |
238 |
< |
(**tp)(&thisray); |
239 |
< |
if (outform == 'a') |
240 |
< |
putchar('\n'); |
252 |
> |
printvals(&thisray); |
253 |
|
} |
254 |
|
|
255 |
|
|
264 |
|
} |
265 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
266 |
|
/* pretend we hit surface */ |
267 |
< |
thisray.rot = 1.0; |
267 |
> |
thisray.rot = 1.0-1e-4; |
268 |
|
thisray.rod = 1.0; |
269 |
|
VCOPY(thisray.ron, dir); |
270 |
|
for (i = 0; i < 3; i++) /* fudge factor */ |
271 |
|
thisray.rop[i] = org[i] + 1e-4*dir[i]; |
272 |
|
/* compute and print */ |
273 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
274 |
< |
oputv(&thisray); |
274 |
> |
printvals(&thisray); |
275 |
> |
} |
276 |
> |
|
277 |
> |
|
278 |
> |
printvals(r) /* print requested ray values */ |
279 |
> |
RAY *r; |
280 |
> |
{ |
281 |
> |
register int (**tp)(); |
282 |
> |
|
283 |
> |
if (ray_out[0] == NULL) |
284 |
> |
return; |
285 |
> |
for (tp = ray_out; *tp != NULL; tp++) |
286 |
> |
(**tp)(r); |
287 |
|
if (outform == 'a') |
288 |
|
putchar('\n'); |
289 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
+ |
tranotify(obj) /* record new modifier */ |
330 |
+ |
OBJECT obj; |
331 |
+ |
{ |
332 |
+ |
static int hitlimit = 0; |
333 |
+ |
register OBJREC *o = objptr(obj); |
334 |
+ |
register char **tralp; |
335 |
+ |
|
336 |
+ |
if (hitlimit || !ismodifier(o->otype)) |
337 |
+ |
return; |
338 |
+ |
for (tralp = tralist; *tralp != NULL; tralp++) |
339 |
+ |
if (!strcmp(o->oname, *tralp)) { |
340 |
+ |
if (traset[0] >= MAXTSET) { |
341 |
+ |
error(WARNING, "too many modifiers in trace list"); |
342 |
+ |
hitlimit++; |
343 |
+ |
return; /* should this be fatal? */ |
344 |
+ |
} |
345 |
+ |
insertelem(traset, obj); |
346 |
+ |
return; |
347 |
+ |
} |
348 |
+ |
} |
349 |
+ |
|
350 |
+ |
|
351 |
|
static |
352 |
|
ourtrace(r) /* print ray values */ |
353 |
|
RAY *r; |
356 |
|
|
357 |
|
if (every_out[0] == NULL) |
358 |
|
return; |
359 |
+ |
if (r->ro == NULL) { |
360 |
+ |
if (traincl == 1) |
361 |
+ |
return; |
362 |
+ |
} else if (traincl != -1 && traincl != inset(traset, r->ro->omod)) |
363 |
+ |
return; |
364 |
|
tabin(r); |
365 |
|
for (tp = every_out; *tp != NULL; tp++) |
366 |
|
(**tp)(r); |
451 |
|
|
452 |
|
|
453 |
|
static |
454 |
< |
oputn(r) /* print normal */ |
454 |
> |
oputN(r) /* print unperturbed normal */ |
455 |
|
register RAY *r; |
456 |
|
{ |
457 |
|
if (r->rot < FHUGE) { |
463 |
|
(*putreal)(0.0); |
464 |
|
(*putreal)(0.0); |
465 |
|
} |
466 |
+ |
} |
467 |
+ |
|
468 |
+ |
|
469 |
+ |
static |
470 |
+ |
oputn(r) /* print perturbed normal */ |
471 |
+ |
RAY *r; |
472 |
+ |
{ |
473 |
+ |
FVECT pnorm; |
474 |
+ |
|
475 |
+ |
if (r->rot >= FHUGE) { |
476 |
+ |
(*putreal)(0.0); |
477 |
+ |
(*putreal)(0.0); |
478 |
+ |
(*putreal)(0.0); |
479 |
+ |
return; |
480 |
+ |
} |
481 |
+ |
raynormal(pnorm, r); |
482 |
+ |
(*putreal)(pnorm[0]); |
483 |
+ |
(*putreal)(pnorm[1]); |
484 |
+ |
(*putreal)(pnorm[2]); |
485 |
|
} |
486 |
|
|
487 |
|
|