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 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
51 |
+ |
int directinvis = 0; /* sources invisible? */ |
52 |
|
|
53 |
|
int maxdepth = 6; /* maximum recursion depth */ |
54 |
|
double minweight = 4e-3; /* minimum ray weight */ |
62 |
|
char *amblist[128]; /* ambient include/exclude list */ |
63 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
64 |
|
|
65 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
66 |
+ |
|
67 |
|
static RAY thisray; /* for our convenience */ |
68 |
|
|
69 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
69 |
> |
static int oputo(), oputd(), oputv(), oputl(), |
70 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
71 |
|
|
72 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
73 |
+ |
static int castonly; |
74 |
|
|
75 |
< |
extern int puta(), putf(), putd(); |
75 |
> |
static int puta(), putf(), putd(); |
76 |
|
|
77 |
|
static int (*putreal)(); |
78 |
|
|
113 |
|
fflush(stdout); |
114 |
|
continue; |
115 |
|
} |
116 |
+ |
samplendx++; |
117 |
|
/* compute and print */ |
118 |
< |
if (outvals[0] == 'i') |
118 |
> |
if (imm_irrad) |
119 |
|
irrad(orig, direc); |
120 |
|
else |
121 |
< |
radiance(orig, direc); |
121 |
> |
traceray(orig, direc); |
122 |
|
/* flush if time */ |
123 |
|
if (--nextflush == 0) { |
124 |
|
fflush(stdout); |
141 |
|
extern int ourtrace(), (*trace)(); |
142 |
|
register int (**table)() = ray_out; |
143 |
|
|
144 |
+ |
castonly = 1; |
145 |
|
while (*vs) |
146 |
|
switch (*vs++) { |
147 |
|
case 't': /* trace */ |
148 |
|
*table = NULL; |
149 |
|
table = every_out; |
150 |
|
trace = ourtrace; |
151 |
+ |
castonly = 0; |
152 |
|
break; |
153 |
|
case 'o': /* origin */ |
154 |
|
*table++ = oputo; |
158 |
|
break; |
159 |
|
case 'v': /* value */ |
160 |
|
*table++ = oputv; |
161 |
+ |
castonly = 0; |
162 |
|
break; |
163 |
|
case 'l': /* length */ |
164 |
|
*table++ = oputl; |
165 |
+ |
castonly = 0; |
166 |
|
break; |
167 |
|
case 'p': /* point */ |
168 |
|
*table++ = oputp; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
radiance(org, dir) /* compute radiance value */ |
187 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
188 |
|
FVECT org, dir; |
189 |
|
{ |
190 |
|
register int (**tp)(); |
192 |
|
VCOPY(thisray.rorg, org); |
193 |
|
VCOPY(thisray.rdir, dir); |
194 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
195 |
< |
rayvalue(&thisray); |
195 |
> |
if (castonly) |
196 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
197 |
> |
else |
198 |
> |
rayvalue(&thisray); |
199 |
|
|
200 |
|
if (ray_out[0] == NULL) |
201 |
|
return; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
< |
irrad(org, dir) /* compute irradiance value */ |
209 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
210 |
|
FVECT org, dir; |
211 |
|
{ |
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 |
– |
}; |
212 |
|
register int i; |
213 |
|
|
214 |
|
for (i = 0; i < 3; i++) { |
243 |
|
return(-1); |
244 |
|
break; |
245 |
|
case 'f': /* binary float */ |
246 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
246 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
247 |
|
return(-1); |
248 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
249 |
|
break; |
250 |
|
case 'd': /* binary double */ |
251 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
251 |
> |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
252 |
|
return(-1); |
253 |
|
break; |
254 |
|
} |
316 |
|
oputl(r) /* print length */ |
317 |
|
register RAY *r; |
318 |
|
{ |
319 |
< |
if (r->rot < FHUGE) |
303 |
< |
(*putreal)(r->rot); |
304 |
< |
else |
305 |
< |
(*putreal)(0.0); |
319 |
> |
(*putreal)(r->rt); |
320 |
|
} |
321 |
|
|
322 |
|
|
396 |
|
putd(v) /* print binary double */ |
397 |
|
double v; |
398 |
|
{ |
399 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
399 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
400 |
|
} |
401 |
|
|
402 |
|
|
406 |
|
{ |
407 |
|
float f = v; |
408 |
|
|
409 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
409 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
410 |
|
} |