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 |
+ |
int dimlist[MAXDIM]; /* sampling dimensions */ |
34 |
+ |
int ndims = 0; /* number of sampling dimensions */ |
35 |
+ |
int samplendx = 0; /* index for this sample */ |
36 |
+ |
|
37 |
+ |
int imm_irrad = 0; /* compute immediate irradiance? */ |
38 |
+ |
|
39 |
|
int inform = 'a'; /* input format */ |
40 |
|
int outform = 'a'; /* output format */ |
41 |
|
char *outvals = "v"; /* output specification */ |
46 |
|
double dstrsrc = 0.0; /* square source distribution */ |
47 |
|
double shadthresh = .05; /* shadow threshold */ |
48 |
|
double shadcert = .5; /* shadow certainty */ |
49 |
+ |
int directrelay = 0; /* number of source relays */ |
50 |
|
|
51 |
|
int maxdepth = 6; /* maximum recursion depth */ |
52 |
|
double minweight = 4e-3; /* minimum ray weight */ |
60 |
|
char *amblist[128]; /* ambient include/exclude list */ |
61 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
62 |
|
|
63 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
64 |
+ |
|
65 |
|
static RAY thisray; /* for our convenience */ |
66 |
|
|
67 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
67 |
> |
static int oputo(), oputd(), oputv(), oputl(), |
68 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
69 |
|
|
70 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
71 |
+ |
static int castonly; |
72 |
|
|
73 |
< |
extern int puta(), putf(), putd(); |
73 |
> |
static int puta(), putf(), putd(); |
74 |
|
|
75 |
|
static int (*putreal)(); |
76 |
|
|
111 |
|
fflush(stdout); |
112 |
|
continue; |
113 |
|
} |
114 |
+ |
samplendx++; |
115 |
|
/* compute and print */ |
116 |
< |
if (outvals[0] == 'i') |
116 |
> |
if (imm_irrad) |
117 |
|
irrad(orig, direc); |
118 |
|
else |
119 |
< |
radiance(orig, direc); |
119 |
> |
traceray(orig, direc); |
120 |
|
/* flush if time */ |
121 |
|
if (--nextflush == 0) { |
122 |
|
fflush(stdout); |
139 |
|
extern int ourtrace(), (*trace)(); |
140 |
|
register int (**table)() = ray_out; |
141 |
|
|
142 |
+ |
castonly = 1; |
143 |
|
while (*vs) |
144 |
|
switch (*vs++) { |
145 |
|
case 't': /* trace */ |
146 |
|
*table = NULL; |
147 |
|
table = every_out; |
148 |
|
trace = ourtrace; |
149 |
+ |
castonly = 0; |
150 |
|
break; |
151 |
|
case 'o': /* origin */ |
152 |
|
*table++ = oputo; |
156 |
|
break; |
157 |
|
case 'v': /* value */ |
158 |
|
*table++ = oputv; |
159 |
+ |
castonly = 0; |
160 |
|
break; |
161 |
|
case 'l': /* length */ |
162 |
|
*table++ = oputl; |
163 |
+ |
castonly = 0; |
164 |
|
break; |
165 |
|
case 'p': /* point */ |
166 |
|
*table++ = oputp; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
< |
radiance(org, dir) /* compute radiance value */ |
185 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
186 |
|
FVECT org, dir; |
187 |
|
{ |
188 |
|
register int (**tp)(); |
190 |
|
VCOPY(thisray.rorg, org); |
191 |
|
VCOPY(thisray.rdir, dir); |
192 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
193 |
< |
rayvalue(&thisray); |
193 |
> |
if (castonly) |
194 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
195 |
> |
else |
196 |
> |
rayvalue(&thisray); |
197 |
|
|
198 |
|
if (ray_out[0] == NULL) |
199 |
|
return; |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
< |
irrad(org, dir) /* compute irradiance value */ |
207 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
208 |
|
FVECT org, dir; |
209 |
|
{ |
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 |
– |
}; |
210 |
|
register int i; |
211 |
|
|
212 |
|
for (i = 0; i < 3; i++) { |
241 |
|
return(-1); |
242 |
|
break; |
243 |
|
case 'f': /* binary float */ |
244 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
244 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
245 |
|
return(-1); |
246 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
247 |
|
break; |
248 |
|
case 'd': /* binary double */ |
249 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
249 |
> |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
250 |
|
return(-1); |
251 |
|
break; |
252 |
|
} |
314 |
|
oputl(r) /* print length */ |
315 |
|
register RAY *r; |
316 |
|
{ |
317 |
< |
if (r->rot < FHUGE) |
303 |
< |
(*putreal)(r->rot); |
304 |
< |
else |
305 |
< |
(*putreal)(0.0); |
317 |
> |
(*putreal)(r->rt); |
318 |
|
} |
319 |
|
|
320 |
|
|
394 |
|
putd(v) /* print binary double */ |
395 |
|
double v; |
396 |
|
{ |
397 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
397 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
398 |
|
} |
399 |
|
|
400 |
|
|
404 |
|
{ |
405 |
|
float f = v; |
406 |
|
|
407 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
407 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
408 |
|
} |