1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
13 |
|
#include "random.h" |
14 |
|
|
15 |
|
|
16 |
+ |
VIEWPOINT myeye; /* target view position */ |
17 |
+ |
|
18 |
+ |
|
19 |
|
packrays(rod, p) /* pack ray origins and directions */ |
20 |
|
register float *rod; |
21 |
|
register PACKET *p; |
22 |
|
{ |
23 |
< |
static FVECT ro, rd; |
23 |
> |
short packord[RPACKSIZ]; |
24 |
> |
float packdc2[RPACKSIZ]; |
25 |
> |
int iterleft = 3*p->nr; |
26 |
> |
BYTE rpos[2][2]; |
27 |
> |
FVECT ro, rd, rp1; |
28 |
|
GCOORD gc[2]; |
29 |
< |
int ila[2], hsh; |
30 |
< |
double d, sl[4]; |
31 |
< |
register int i; |
29 |
> |
double d, dc2, md2, td2; |
30 |
> |
int i; |
31 |
> |
register int ii; |
32 |
|
|
33 |
|
if (!hdbcoord(gc, hdlist[p->hd], p->bi)) |
34 |
|
error(CONSISTENCY, "bad beam index in packrays"); |
35 |
< |
ila[0] = p->hd; ila[1] = p->bi; |
36 |
< |
hsh = ilhash(ila,2) + p->nc; |
37 |
< |
for (i = 0; i < p->nr; i++) { |
38 |
< |
multisamp(sl, 4, urand(hsh+i)); |
39 |
< |
p->ra[i].r[0][0] = sl[0] * 256.; |
40 |
< |
p->ra[i].r[0][1] = sl[1] * 256.; |
41 |
< |
p->ra[i].r[1][0] = sl[2] * 256.; |
42 |
< |
p->ra[i].r[1][1] = sl[3] * 256.; |
43 |
< |
d = hdray(ro, rd, hdlist[p->hd], gc, p->ra[i].r); |
35 |
> |
td2 = (myeye.rng+FTINY)*(myeye.rng+FTINY); |
36 |
> |
for (i = 0, md2 = 0.; i < p->nr || md2 > td2; ) { |
37 |
> |
rpos[0][0] = frandom() * 256.; |
38 |
> |
rpos[0][1] = frandom() * 256.; |
39 |
> |
rpos[1][0] = frandom() * 256.; |
40 |
> |
rpos[1][1] = frandom() * 256.; |
41 |
> |
d = hdray(ro, rd, hdlist[p->hd], gc, rpos); |
42 |
> |
if (myeye.rng > FTINY) { /* check eyepoint */ |
43 |
> |
register int nexti; |
44 |
> |
|
45 |
> |
VSUM(rp1, ro, rd, d); |
46 |
> |
dc2 = dist2line(myeye.vpt, ro, rp1); |
47 |
> |
dc2 /= (double)(p->nr*p->nr); |
48 |
> |
if (i == p->nr) { /* packet full */ |
49 |
> |
nexti = packord[i-1]; |
50 |
> |
if (!iterleft--) |
51 |
> |
break; /* tried enough! */ |
52 |
> |
if (dc2 >= packdc2[nexti]) |
53 |
> |
continue; /* worse than worst */ |
54 |
> |
md2 -= packdc2[nexti]; |
55 |
> |
} else |
56 |
> |
nexti = i++; |
57 |
> |
md2 += packdc2[nexti] = dc2; /* new distance */ |
58 |
> |
for (ii = i; --ii; ) { /* insertion sort */ |
59 |
> |
if (dc2 > packdc2[packord[ii-1]]) |
60 |
> |
break; |
61 |
> |
packord[ii] = packord[ii-1]; |
62 |
> |
} |
63 |
> |
packord[ii] = nexti; |
64 |
> |
ii = nexti; /* put it here */ |
65 |
> |
} else |
66 |
> |
ii = i++; |
67 |
|
if (p->offset != NULL) { |
68 |
< |
VSUM(ro, ro, rd, d); /* exterior only */ |
69 |
< |
p->offset[i] = d; |
68 |
> |
if (!vdef(OBSTRUCTIONS)) |
69 |
> |
d *= frandom(); /* random offset */ |
70 |
> |
VSUM(ro, ro, rd, d); /* advance ray */ |
71 |
> |
p->offset[ii] = d; |
72 |
|
} |
73 |
< |
VCOPY(rod, ro); |
74 |
< |
rod += 3; |
75 |
< |
VCOPY(rod, rd); |
76 |
< |
rod += 3; |
73 |
> |
p->ra[ii].r[0][0] = rpos[0][0]; |
74 |
> |
p->ra[ii].r[0][1] = rpos[0][1]; |
75 |
> |
p->ra[ii].r[1][0] = rpos[1][0]; |
76 |
> |
p->ra[ii].r[1][1] = rpos[1][1]; |
77 |
> |
VCOPY(rod+6*ii, ro); |
78 |
> |
VCOPY(rod+6*ii+3, rd); |
79 |
|
} |
80 |
+ |
#ifdef DEBUG |
81 |
+ |
fprintf(stderr, "%f mean distance for target %f (%d iterations left)\n", |
82 |
+ |
sqrt(md2), myeye.rng, iterleft); |
83 |
+ |
#endif |
84 |
|
} |
85 |
|
|
86 |
|
|
110 |
|
/* already closed? */ |
111 |
|
if (!nprocs) |
112 |
|
return; |
75 |
– |
wputs("closing rtrace process...\n"); |
113 |
|
/* flush beam queue */ |
114 |
|
done_packets(flush_queue()); |
115 |
|
/* sync holodeck */ |
117 |
|
/* close rtrace */ |
118 |
|
if ((status = end_rtrace())) |
119 |
|
error(WARNING, "bad exit status from rtrace"); |
120 |
< |
if (vdef(REPORT)) /* report time */ |
120 |
> |
if (vdef(REPORT)) { /* report time */ |
121 |
> |
eputs("rtrace process closed\n"); |
122 |
|
report(0); |
123 |
+ |
} |
124 |
|
return(status); /* return status */ |
125 |
|
} |
126 |
|
|
131 |
|
|
132 |
|
if (nprocs > 0) /* already running? */ |
133 |
|
return; |
95 |
– |
wputs("restarting rtrace process...\n"); |
134 |
|
starttime = time(NULL); /* reset start time and counts */ |
135 |
|
npacksdone = nraysdone = 0L; |
136 |
|
if (vdef(TIME)) /* reset end time */ |
142 |
|
} |
143 |
|
if (start_rtrace() < 1) /* start rtrace */ |
144 |
|
error(WARNING, "cannot restart rtrace"); |
145 |
< |
else if (vdef(REPORT)) |
145 |
> |
else if (vdef(REPORT)) { |
146 |
> |
eputs("rtrace process restarted\n"); |
147 |
|
report(0); |
148 |
+ |
} |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
getradfile() /* run rad and get needed variables */ |
153 |
|
{ |
154 |
< |
static short mvar[] = {OCTREE,-1}; |
154 |
> |
static short mvar[] = {OCTREE,EYESEP,-1}; |
155 |
|
static char tf1[] = TEMPLATE; |
156 |
|
char tf2[64]; |
157 |
|
char combuf[256]; |
160 |
|
register char *cp; |
161 |
|
/* check if rad file specified */ |
162 |
|
if (!vdef(RIF)) |
163 |
< |
return; |
163 |
> |
return(0); |
164 |
|
/* create rad command */ |
165 |
|
mktemp(tf1); |
166 |
|
sprintf(tf2, "%s.rif", tf1); |
183 |
|
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
184 |
|
else |
185 |
|
sprintf(cp, ")[ \t]*=' > %s", tf2); |
186 |
< |
if (system(combuf)) { |
187 |
< |
unlink(tf2); /* clean up */ |
188 |
< |
unlink(tf1); |
189 |
< |
error(SYSTEM, "cannot execute rad command"); |
150 |
< |
} |
186 |
> |
#ifdef DEBUG |
187 |
> |
wputs(combuf); wputs("\n"); |
188 |
> |
#endif |
189 |
> |
system(combuf); /* ignore exit code */ |
190 |
|
if (pippt == NULL) { |
191 |
|
loadvars(tf2); /* load variables */ |
192 |
|
unlink(tf2); |
193 |
|
} |
194 |
|
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
195 |
|
unlink(tf1); /* clean up */ |
196 |
+ |
return(1); |
197 |
|
} |
198 |
|
|
199 |
|
|