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 |
|
|
27 |
|
#include "ray.h" |
28 |
|
|
29 |
+ |
#include "octree.h" |
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 directinvis = 0; /* sources invisible? */ |
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 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
75 |
> |
static int oputo(), oputd(), oputv(), oputl(), oputL(), |
76 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
77 |
|
|
78 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
79 |
+ |
static int castonly; |
80 |
|
|
81 |
< |
extern int puta(), putf(), putd(); |
81 |
> |
static int puta(), putf(), putd(); |
82 |
|
|
83 |
|
static int (*putreal)(); |
84 |
|
|
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
+ |
char * |
94 |
+ |
formstr(f) /* return format identifier */ |
95 |
+ |
int f; |
96 |
+ |
{ |
97 |
+ |
switch (f) { |
98 |
+ |
case 'a': return("ascii"); |
99 |
+ |
case 'f': return("float"); |
100 |
+ |
case 'd': return("double"); |
101 |
+ |
case 'c': return(COLRFMT); |
102 |
+ |
} |
103 |
+ |
return("unknown"); |
104 |
+ |
} |
105 |
+ |
|
106 |
+ |
|
107 |
|
rtrace(fname) /* trace rays from file */ |
108 |
|
char *fname; |
109 |
|
{ |
124 |
|
case 'a': putreal = puta; break; |
125 |
|
case 'f': putreal = putf; break; |
126 |
|
case 'd': putreal = putd; break; |
127 |
+ |
case 'c': |
128 |
+ |
if (strcmp(outvals, "v")) |
129 |
+ |
error(USER, "color format with value output only"); |
130 |
+ |
break; |
131 |
+ |
default: |
132 |
+ |
error(CONSISTENCY, "botched output format"); |
133 |
|
} |
134 |
+ |
if (hresolu > 0 && vresolu > 0) |
135 |
+ |
fprtresolu(hresolu, vresolu, stdout); |
136 |
|
/* process file */ |
137 |
|
while (getvec(orig, inform, fp) == 0 && |
138 |
|
getvec(direc, inform, fp) == 0) { |
141 |
|
fflush(stdout); |
142 |
|
continue; |
143 |
|
} |
144 |
+ |
samplendx++; |
145 |
|
/* compute and print */ |
146 |
< |
if (outvals[0] == 'i') |
146 |
> |
if (imm_irrad) |
147 |
|
irrad(orig, direc); |
148 |
|
else |
149 |
< |
radiance(orig, direc); |
149 |
> |
traceray(orig, direc); |
150 |
|
/* flush if time */ |
151 |
|
if (--nextflush == 0) { |
152 |
|
fflush(stdout); |
169 |
|
extern int ourtrace(), (*trace)(); |
170 |
|
register int (**table)() = ray_out; |
171 |
|
|
172 |
+ |
castonly = 1; |
173 |
|
while (*vs) |
174 |
|
switch (*vs++) { |
175 |
|
case 't': /* trace */ |
176 |
|
*table = NULL; |
177 |
|
table = every_out; |
178 |
|
trace = ourtrace; |
179 |
+ |
castonly = 0; |
180 |
|
break; |
181 |
|
case 'o': /* origin */ |
182 |
|
*table++ = oputo; |
186 |
|
break; |
187 |
|
case 'v': /* value */ |
188 |
|
*table++ = oputv; |
189 |
+ |
castonly = 0; |
190 |
|
break; |
191 |
< |
case 'l': /* length */ |
191 |
> |
case 'l': /* effective distance */ |
192 |
|
*table++ = oputl; |
193 |
+ |
castonly = 0; |
194 |
|
break; |
195 |
+ |
case 'L': /* single ray length */ |
196 |
+ |
*table++ = oputL; |
197 |
+ |
break; |
198 |
|
case 'p': /* point */ |
199 |
|
*table++ = oputp; |
200 |
|
break; |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
< |
radiance(org, dir) /* compute radiance value */ |
218 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
219 |
|
FVECT org, dir; |
220 |
|
{ |
221 |
|
register int (**tp)(); |
223 |
|
VCOPY(thisray.rorg, org); |
224 |
|
VCOPY(thisray.rdir, dir); |
225 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
226 |
< |
rayvalue(&thisray); |
226 |
> |
if (castonly) |
227 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
228 |
> |
else |
229 |
> |
rayvalue(&thisray); |
230 |
|
|
231 |
|
if (ray_out[0] == NULL) |
232 |
|
return; |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
< |
irrad(org, dir) /* compute irradiance value */ |
240 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
241 |
|
FVECT org, dir; |
242 |
|
{ |
190 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
191 |
– |
static OBJREC Lamb = { |
192 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
193 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
194 |
– |
}; |
243 |
|
register int i; |
244 |
|
|
245 |
|
for (i = 0; i < 3; i++) { |
266 |
|
int fmt; |
267 |
|
FILE *fp; |
268 |
|
{ |
269 |
+ |
extern char *fgetword(); |
270 |
|
static float vf[3]; |
271 |
+ |
static double vd[3]; |
272 |
+ |
char buf[32]; |
273 |
+ |
register int i; |
274 |
|
|
275 |
|
switch (fmt) { |
276 |
|
case 'a': /* ascii */ |
277 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
278 |
< |
return(-1); |
277 |
> |
for (i = 0; i < 3; i++) { |
278 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
279 |
> |
!isflt(buf)) |
280 |
> |
return(-1); |
281 |
> |
vec[i] = atof(buf); |
282 |
> |
} |
283 |
|
break; |
284 |
|
case 'f': /* binary float */ |
285 |
|
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
287 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
288 |
|
break; |
289 |
|
case 'd': /* binary double */ |
290 |
< |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
290 |
> |
if (fread((char *)vd, sizeof(double), 3, fp) != 3) |
291 |
|
return(-1); |
292 |
+ |
vec[0] = vd[0]; vec[1] = vd[1]; vec[2] = vd[2]; |
293 |
|
break; |
294 |
+ |
default: |
295 |
+ |
error(CONSISTENCY, "botched input format"); |
296 |
|
} |
297 |
|
return(0); |
298 |
|
} |
348 |
|
oputv(r) /* print value */ |
349 |
|
register RAY *r; |
350 |
|
{ |
351 |
+ |
COLR cout; |
352 |
+ |
|
353 |
+ |
if (outform == 'c') { |
354 |
+ |
setcolr(cout, colval(r->rcol,RED), |
355 |
+ |
colval(r->rcol,GRN), |
356 |
+ |
colval(r->rcol,BLU)); |
357 |
+ |
fwrite((char *)cout, sizeof(cout), 1, stdout); |
358 |
+ |
return; |
359 |
+ |
} |
360 |
|
(*putreal)(colval(r->rcol,RED)); |
361 |
|
(*putreal)(colval(r->rcol,GRN)); |
362 |
|
(*putreal)(colval(r->rcol,BLU)); |
364 |
|
|
365 |
|
|
366 |
|
static |
367 |
< |
oputl(r) /* print length */ |
367 |
> |
oputl(r) /* print effective distance */ |
368 |
|
register RAY *r; |
369 |
|
{ |
370 |
< |
if (r->rot < FHUGE) |
371 |
< |
(*putreal)(r->rot); |
372 |
< |
else |
373 |
< |
(*putreal)(0.0); |
370 |
> |
(*putreal)(r->rt); |
371 |
> |
} |
372 |
> |
|
373 |
> |
|
374 |
> |
static |
375 |
> |
oputL(r) /* print single ray length */ |
376 |
> |
register RAY *r; |
377 |
> |
{ |
378 |
> |
(*putreal)(r->rot); |
379 |
|
} |
380 |
|
|
381 |
|
|