16 |
|
* xorg yorg zorg xdir ydir zdir |
17 |
|
* |
18 |
|
* The direction need not be normalized. Output is flexible. |
19 |
+ |
* If the direction vector is (0,0,0), then the output is flushed. |
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 = 1; /* number of source relays */ |
50 |
+ |
int vspretest = 512; /* virtual source pretest density */ |
51 |
+ |
int directinvis = 0; /* sources invisible? */ |
52 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
53 |
|
|
54 |
+ |
double specthresh = .5; /* specular sampling threshold */ |
55 |
+ |
double specjitter = 1.; /* specular sampling jitter */ |
56 |
+ |
|
57 |
|
int maxdepth = 6; /* maximum recursion depth */ |
58 |
|
double minweight = 4e-3; /* minimum ray weight */ |
59 |
|
|
66 |
|
char *amblist[128]; /* ambient include/exclude list */ |
67 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
68 |
|
|
69 |
+ |
extern OBJREC Lamb; /* a Lambertian surface */ |
70 |
+ |
|
71 |
|
static RAY thisray; /* for our convenience */ |
72 |
|
|
73 |
< |
extern int oputo(), oputd(), oputv(), oputl(), |
73 |
> |
static int oputo(), oputd(), oputv(), oputl(), |
74 |
|
oputp(), oputn(), oputs(), oputw(), oputm(); |
75 |
|
|
76 |
|
static int (*ray_out[10])(), (*every_out[10])(); |
77 |
+ |
static int castonly; |
78 |
|
|
79 |
< |
extern int puta(), putf(), putd(); |
79 |
> |
static int puta(), putf(), putd(); |
80 |
|
|
81 |
|
static int (*putreal)(); |
82 |
|
|
113 |
|
while (getvec(orig, inform, fp) == 0 && |
114 |
|
getvec(direc, inform, fp) == 0) { |
115 |
|
|
116 |
< |
if (normalize(direc) == 0.0) |
117 |
< |
error(USER, "zero direction vector"); |
116 |
> |
if (normalize(direc) == 0.0) { /* zero ==> flush */ |
117 |
> |
fflush(stdout); |
118 |
> |
continue; |
119 |
> |
} |
120 |
> |
samplendx++; |
121 |
|
/* compute and print */ |
122 |
< |
if (outvals[0] == 'i') |
122 |
> |
if (imm_irrad) |
123 |
|
irrad(orig, direc); |
124 |
|
else |
125 |
< |
radiance(orig, direc); |
126 |
< |
/* flush if requested */ |
125 |
> |
traceray(orig, direc); |
126 |
> |
/* flush if time */ |
127 |
|
if (--nextflush == 0) { |
128 |
|
fflush(stdout); |
129 |
|
nextflush = hresolu; |
145 |
|
extern int ourtrace(), (*trace)(); |
146 |
|
register int (**table)() = ray_out; |
147 |
|
|
148 |
+ |
castonly = 1; |
149 |
|
while (*vs) |
150 |
|
switch (*vs++) { |
151 |
|
case 't': /* trace */ |
152 |
|
*table = NULL; |
153 |
|
table = every_out; |
154 |
|
trace = ourtrace; |
155 |
+ |
castonly = 0; |
156 |
|
break; |
157 |
|
case 'o': /* origin */ |
158 |
|
*table++ = oputo; |
162 |
|
break; |
163 |
|
case 'v': /* value */ |
164 |
|
*table++ = oputv; |
165 |
+ |
castonly = 0; |
166 |
|
break; |
167 |
|
case 'l': /* length */ |
168 |
|
*table++ = oputl; |
169 |
+ |
castonly = 0; |
170 |
|
break; |
171 |
|
case 'p': /* point */ |
172 |
|
*table++ = oputp; |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
radiance(org, dir) /* compute radiance value */ |
191 |
> |
traceray(org, dir) /* compute and print ray value(s) */ |
192 |
|
FVECT org, dir; |
193 |
|
{ |
194 |
|
register int (**tp)(); |
196 |
|
VCOPY(thisray.rorg, org); |
197 |
|
VCOPY(thisray.rdir, dir); |
198 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
199 |
< |
rayvalue(&thisray); |
199 |
> |
if (castonly) |
200 |
> |
localhit(&thisray, &thescene) || sourcehit(&thisray); |
201 |
> |
else |
202 |
> |
rayvalue(&thisray); |
203 |
|
|
204 |
|
if (ray_out[0] == NULL) |
205 |
|
return; |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
< |
irrad(org, dir) /* compute irradiance value */ |
213 |
> |
irrad(org, dir) /* compute immediate irradiance value */ |
214 |
|
FVECT org, dir; |
215 |
|
{ |
187 |
– |
static double Lambfa[5] = {PI, PI, PI, 0.0, 0.0}; |
188 |
– |
static OBJREC Lamb = { |
189 |
– |
OVOID, MAT_PLASTIC, "Lambertian", |
190 |
– |
{0, 5, NULL, Lambfa}, NULL, -1, |
191 |
– |
}; |
216 |
|
register int i; |
217 |
|
|
218 |
|
for (i = 0; i < 3; i++) { |
239 |
|
int fmt; |
240 |
|
FILE *fp; |
241 |
|
{ |
242 |
+ |
extern char *fgetword(); |
243 |
|
static float vf[3]; |
244 |
+ |
char buf[32]; |
245 |
+ |
register int i; |
246 |
|
|
247 |
|
switch (fmt) { |
248 |
|
case 'a': /* ascii */ |
249 |
< |
if (fscanf(fp, "%lf %lf %lf", vec, vec+1, vec+2) != 3) |
250 |
< |
return(-1); |
249 |
> |
for (i = 0; i < 3; i++) { |
250 |
> |
if (fgetword(buf, sizeof(buf), fp) == NULL || |
251 |
> |
!isflt(buf)) |
252 |
> |
return(-1); |
253 |
> |
vec[i] = atof(buf); |
254 |
> |
} |
255 |
|
break; |
256 |
|
case 'f': /* binary float */ |
257 |
< |
if (fread(vf, sizeof(float), 3, fp) != 3) |
257 |
> |
if (fread((char *)vf, sizeof(float), 3, fp) != 3) |
258 |
|
return(-1); |
259 |
|
vec[0] = vf[0]; vec[1] = vf[1]; vec[2] = vf[2]; |
260 |
|
break; |
261 |
|
case 'd': /* binary double */ |
262 |
< |
if (fread(vec, sizeof(double), 3, fp) != 3) |
262 |
> |
if (fread((char *)vec, sizeof(double), 3, fp) != 3) |
263 |
|
return(-1); |
264 |
|
break; |
265 |
|
} |
327 |
|
oputl(r) /* print length */ |
328 |
|
register RAY *r; |
329 |
|
{ |
330 |
< |
if (r->rot < FHUGE) |
300 |
< |
(*putreal)(r->rot); |
301 |
< |
else |
302 |
< |
(*putreal)(0.0); |
330 |
> |
(*putreal)(r->rt); |
331 |
|
} |
332 |
|
|
333 |
|
|
407 |
|
putd(v) /* print binary double */ |
408 |
|
double v; |
409 |
|
{ |
410 |
< |
fwrite(&v, sizeof(v), 1, stdout); |
410 |
> |
fwrite((char *)&v, sizeof(v), 1, stdout); |
411 |
|
} |
412 |
|
|
413 |
|
|
417 |
|
{ |
418 |
|
float f = v; |
419 |
|
|
420 |
< |
fwrite(&f, sizeof(f), 1, stdout); |
420 |
> |
fwrite((char *)&f, sizeof(f), 1, stdout); |
421 |
|
} |