1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
20 |
|
* All values default to ascii representation of real |
21 |
|
* numbers. Binary representations can be selected |
22 |
|
* with '-ff' for float or '-fd' for double. By default, |
23 |
< |
* radiance is computed. The '-i' option indicates that |
23 |
> |
* radiance is computed. The '-i' or '-I' options indicate that |
24 |
|
* irradiance values are desired. |
25 |
|
*/ |
26 |
|
|
30 |
|
|
31 |
|
#include "otypes.h" |
32 |
|
|
33 |
+ |
#include "resolu.h" |
34 |
+ |
|
35 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
36 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
37 |
+ |
int samplendx = 0; /* index for this sample */ |
38 |
+ |
|
39 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
40 |
+ |
|
41 |
|
int inform = 'a'; /* input format */ |
42 |
|
int outform = 'a'; /* output format */ |
43 |
|
char *outvals = "v"; /* output specification */ |
48 |
|
double dstrsrc = 0.0; /* square source distribution */ |
49 |
|
double shadthresh = .05; /* shadow threshold */ |
50 |
|
double shadcert = .5; /* shadow certainty */ |
51 |
+ |
int directrelay = 1; /* number of source relays */ |
52 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
53 |
+ |
int directvis = 1; /* sources visible? */ |
54 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
55 |
|
|
56 |
+ |
double specthresh = .15; /* specular sampling threshold */ |
57 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
58 |
+ |
|
59 |
|
int maxdepth = 6; /* maximum recursion depth */ |
60 |
|
double minweight = 4e-3; /* minimum ray weight */ |
61 |
|
|
68 |
|
char *amblist[128]; /* ambient include/exclude list */ |
69 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
70 |
|
|
71 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
72 |
+ |
|
73 |
|
static RAY thisray; /* for our convenience */ |
74 |
|
|
75 |
< |
static int oputo(), oputd(), oputv(), oputl(), |
76 |
< |
oputp(), oputn(), oputs(), oputw(), oputm(); |
75 |
> |
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
76 |
> |
oputp(), oputn(), oputN(), oputs(), oputw(), oputm(); |
77 |
|
|
78 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
79 |
|
static int castonly; |
86 |
|
quit(code) /* quit program */ |
87 |
|
int code; |
88 |
|
{ |
89 |
+ |
#ifndef NIX |
90 |
+ |
headclean(); /* delete header file */ |
91 |
+ |
pfclean(); /* clean up persist files */ |
92 |
+ |
#endif |
93 |
|
exit(code); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
+ |
char * |
98 |
+ |
formstr(f) /* return format identifier */ |
99 |
+ |
int f; |
100 |
+ |
{ |
101 |
+ |
switch (f) { |
102 |
+ |
case 'a': return("ascii"); |
103 |
+ |
case 'f': return("float"); |
104 |
+ |
case 'd': return("double"); |
105 |
+ |
case 'c': return(COLRFMT); |
106 |
+ |
} |
107 |
+ |
return("unknown"); |
108 |
+ |
} |
109 |
+ |
|
110 |
+ |
|
111 |
|
rtrace(fname) /* trace rays from file */ |
112 |
|
char *fname; |
113 |
|
{ |
122 |
|
sprintf(errmsg, "cannot open input file \"%s\"", fname); |
123 |
|
error(SYSTEM, errmsg); |
124 |
|
} |
125 |
+ |
#ifdef MSDOS |
126 |
+ |
if (inform != 'a') |
127 |
+ |
setmode(fileno(fp), O_BINARY); |
128 |
+ |
#endif |
129 |
|
/* set up output */ |
130 |
|
setoutput(outvals); |
131 |
|
switch (outform) { |
132 |
|
case 'a': putreal = puta; break; |
133 |
|
case 'f': putreal = putf; break; |
134 |
|
case 'd': putreal = putd; break; |
135 |
+ |
case 'c': |
136 |
+ |
if (strcmp(outvals, "v")) |
137 |
+ |
error(USER, "color format with value output only"); |
138 |
+ |
break; |
139 |
+ |
default: |
140 |
+ |
error(CONSISTENCY, "botched output format"); |
141 |
|
} |
142 |
+ |
if (hresolu > 0) { |
143 |
+ |
if (vresolu > 0) |
144 |
+ |
fprtresolu(hresolu, vresolu, stdout); |
145 |
+ |
fflush(stdout); |
146 |
+ |
} |
147 |
|
/* process file */ |
148 |
|
while (getvec(orig, inform, fp) == 0 && |
149 |
|
getvec(direc, inform, fp) == 0) { |
152 |
|
fflush(stdout); |
153 |
|
continue; |
154 |
|
} |
155 |
+ |
samplendx++; |
156 |
|
/* compute and print */ |
157 |
< |
if (outvals[0] == 'i') |
157 |
> |
if (imm_irrad) |
158 |
|
irrad(orig, direc); |
159 |
|
else |
160 |
< |
radiance(orig, direc); |
160 |
> |
traceray(orig, direc); |
161 |
|
/* flush if time */ |
162 |
|
if (--nextflush == 0) { |
163 |
|
fflush(stdout); |
168 |
|
if (--vcount == 0) /* check for end */ |
169 |
|
break; |
170 |
|
} |
171 |
+ |
fflush(stdout); |
172 |
|
if (vcount > 0) |
173 |
|
error(USER, "read error"); |
174 |
< |
fclose(fp); |
174 |
> |
if (fname != NULL) |
175 |
> |
fclose(fp); |
176 |
|
} |
177 |
|
|
178 |
|
|
201 |
|
*table++ = oputv; |
202 |
|
castonly = 0; |
203 |
|
break; |
204 |
< |
case 'l': /* length */ |
204 |
> |
case 'l': /* effective distance */ |
205 |
|
*table++ = oputl; |
206 |
|
castonly = 0; |
207 |
|
break; |
208 |
+ |
case 'L': /* single ray length */ |
209 |
+ |
*table++ = oputL; |
210 |
+ |
break; |
211 |
|
case 'p': /* point */ |
212 |
|
*table++ = oputp; |
213 |
|
break; |
214 |
< |
case 'n': /* normal */ |
214 |
> |
case 'n': /* perturbed normal */ |
215 |
|
*table++ = oputn; |
216 |
+ |
castonly = 0; |
217 |
|
break; |
218 |
+ |
case 'N': /* unperturbed normal */ |
219 |
+ |
*table++ = oputN; |
220 |
+ |
break; |
221 |
|
case 's': /* surface */ |
222 |
|
*table++ = oputs; |
223 |
|
break; |
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
< |
radiance(org, dir) /* compute radiance value */ |
235 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
236 |
|
FVECT org, dir; |
237 |
|
{ |
238 |
|
register int (**tp)(); |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
< |
irrad(org, dir) /* compute irradiance value */ |
257 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
258 |
|
FVECT org, dir; |
259 |
|
{ |
200 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
201 |
– |
static OBJREC Lamb = { |
202 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
203 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
204 |
– |
}; |
260 |
|
register int i; |
261 |
|
|
262 |
|
for (i = 0; i < 3; i++) { |
283 |
|
int fmt; |
284 |
|
FILE *fp; |
285 |
|
{ |
286 |
+ |
extern char *fgetword(); |
287 |
|
static float vf[3]; |
288 |
+ |
static double vd[3]; |
289 |
+ |
char buf[32]; |
290 |
+ |
register int i; |
291 |
|
|
292 |
|
switch (fmt) { |
293 |
|
case 'a': /* ascii */ |
294 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
295 |
< |
return(-1); |
294 |
> |
for (i = 0; i < 3; i++) { |
295 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
296 |
> |
!isflt(buf)) |
297 |
> |
return(-1); |
298 |
> |
vec[i] = atof(buf); |
299 |
> |
} |
300 |
|
break; |
301 |
|
case 'f': /* binary float */ |
302 |
|
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
304 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
305 |
|
break; |
306 |
|
case 'd': /* binary double */ |
307 |
< |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
307 |
> |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
308 |
|
return(-1); |
309 |
+ |
vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; |
310 |
|
break; |
311 |
+ |
default: |
312 |
+ |
error(CONSISTENCY, "botched input format"); |
313 |
|
} |
314 |
|
return(0); |
315 |
|
} |
365 |
|
oputv(r) /* print value */ |
366 |
|
register RAY *r; |
367 |
|
{ |
368 |
+ |
COLR cout; |
369 |
+ |
|
370 |
+ |
if (outform == 'c') { |
371 |
+ |
setcolr(cout, colval(r->rcol,RED), |
372 |
+ |
colval(r->rcol,GRN), |
373 |
+ |
colval(r->rcol,BLU)); |
374 |
+ |
fwrite((char *)cout, sizeof(cout), 1, stdout); |
375 |
+ |
return; |
376 |
+ |
} |
377 |
|
(*putreal)(colval(r->rcol,RED)); |
378 |
|
(*putreal)(colval(r->rcol,GRN)); |
379 |
|
(*putreal)(colval(r->rcol,BLU)); |
381 |
|
|
382 |
|
|
383 |
|
static |
384 |
< |
oputl(r) /* print length */ |
384 |
> |
oputl(r) /* print effective distance */ |
385 |
|
register RAY *r; |
386 |
|
{ |
387 |
|
(*putreal)(r->rt); |
389 |
|
|
390 |
|
|
391 |
|
static |
392 |
+ |
oputL(r) /* print single ray length */ |
393 |
+ |
register RAY *r; |
394 |
+ |
{ |
395 |
+ |
(*putreal)(r->rot); |
396 |
+ |
} |
397 |
+ |
|
398 |
+ |
|
399 |
+ |
static |
400 |
|
oputp(r) /* print point */ |
401 |
|
register RAY *r; |
402 |
|
{ |
413 |
|
|
414 |
|
|
415 |
|
static |
416 |
< |
oputn(r) /* print normal */ |
416 |
> |
oputN(r) /* print unperturbed normal */ |
417 |
|
register RAY *r; |
418 |
|
{ |
419 |
|
if (r->rot < FHUGE) { |
425 |
|
(*putreal)(0.0); |
426 |
|
(*putreal)(0.0); |
427 |
|
} |
428 |
+ |
} |
429 |
+ |
|
430 |
+ |
|
431 |
+ |
static |
432 |
+ |
oputn(r) /* print perturbed normal */ |
433 |
+ |
RAY *r; |
434 |
+ |
{ |
435 |
+ |
FVECT pnorm; |
436 |
+ |
|
437 |
+ |
if (r->rot >= FHUGE) { |
438 |
+ |
(*putreal)(0.0); |
439 |
+ |
(*putreal)(0.0); |
440 |
+ |
(*putreal)(0.0); |
441 |
+ |
return; |
442 |
+ |
} |
443 |
+ |
raynormal(pnorm, r); |
444 |
+ |
(*putreal)(pnorm[0]); |
445 |
+ |
(*putreal)(pnorm[1]); |
446 |
+ |
(*putreal)(pnorm[2]); |
447 |
|
} |
448 |
|
|
449 |
|
|