| 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 packdc[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, dc, meandist; |
| 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 |
> |
for (i = 0, meandist = 0.; i < p->nr || meandist > myeye.rng+FTINY; ) { |
| 36 |
> |
rpos[0][0] = frandom() * 256.; |
| 37 |
> |
rpos[0][1] = frandom() * 256.; |
| 38 |
> |
rpos[1][0] = frandom() * 256.; |
| 39 |
> |
rpos[1][1] = frandom() * 256.; |
| 40 |
> |
d = hdray(ro, rd, hdlist[p->hd], gc, rpos); |
| 41 |
> |
if (myeye.rng > FTINY) { /* check eyepoint */ |
| 42 |
> |
register int nexti; |
| 43 |
> |
|
| 44 |
> |
VSUM(rp1, ro, rd, d); |
| 45 |
> |
dc = sqrt(dist2line(myeye.vpt, ro, rp1)) / p->nr; |
| 46 |
> |
if (i == p->nr) { /* packet full */ |
| 47 |
> |
nexti = packord[i-1]; |
| 48 |
> |
if (!iterleft--) |
| 49 |
> |
break; /* tried enough! */ |
| 50 |
> |
if (dc >= packdc[nexti]) |
| 51 |
> |
continue; /* worse than worst */ |
| 52 |
> |
meandist -= packdc[nexti]; |
| 53 |
> |
} else |
| 54 |
> |
nexti = i++; |
| 55 |
> |
meandist += packdc[nexti] = dc; /* new distance */ |
| 56 |
> |
for (ii = i; --ii; ) { /* insertion sort */ |
| 57 |
> |
if (dc > packdc[packord[ii-1]]) |
| 58 |
> |
break; |
| 59 |
> |
packord[ii] = packord[ii-1]; |
| 60 |
> |
} |
| 61 |
> |
packord[ii] = nexti; |
| 62 |
> |
ii = nexti; /* put it here */ |
| 63 |
> |
} else |
| 64 |
> |
ii = i++; |
| 65 |
|
if (p->offset != NULL) { |
| 66 |
< |
VSUM(ro, ro, rd, d); /* exterior only */ |
| 67 |
< |
p->offset[i] = d; |
| 66 |
> |
if (!vdef(OBSTRUCTIONS)) |
| 67 |
> |
d *= frandom(); /* random offset */ |
| 68 |
> |
VSUM(ro, ro, rd, d); /* advance ray */ |
| 69 |
> |
p->offset[ii] = d; |
| 70 |
|
} |
| 71 |
< |
VCOPY(rod, ro); |
| 72 |
< |
rod += 3; |
| 73 |
< |
VCOPY(rod, rd); |
| 74 |
< |
rod += 3; |
| 71 |
> |
p->ra[ii].r[0][0] = rpos[0][0]; |
| 72 |
> |
p->ra[ii].r[0][1] = rpos[0][1]; |
| 73 |
> |
p->ra[ii].r[1][0] = rpos[1][0]; |
| 74 |
> |
p->ra[ii].r[1][1] = rpos[1][1]; |
| 75 |
> |
VCOPY(rod+6*ii, ro); |
| 76 |
> |
VCOPY(rod+6*ii+3, rd); |
| 77 |
|
} |
| 78 |
+ |
#ifdef DEBUG |
| 79 |
+ |
fprintf(stderr, "%f mean distance for target %f (%d iterations)\n", |
| 80 |
+ |
meandist, myeye.rng, 3*p->nr - iterleft); |
| 81 |
+ |
#endif |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
|
| 108 |
|
/* already closed? */ |
| 109 |
|
if (!nprocs) |
| 110 |
|
return; |
| 75 |
– |
wputs("closing rtrace process...\n"); |
| 111 |
|
/* flush beam queue */ |
| 112 |
|
done_packets(flush_queue()); |
| 113 |
|
/* sync holodeck */ |
| 115 |
|
/* close rtrace */ |
| 116 |
|
if ((status = end_rtrace())) |
| 117 |
|
error(WARNING, "bad exit status from rtrace"); |
| 118 |
< |
if (vdef(REPORT)) /* report time */ |
| 118 |
> |
if (vdef(REPORT)) { /* report time */ |
| 119 |
> |
eputs("rtrace process closed\n"); |
| 120 |
|
report(0); |
| 121 |
+ |
} |
| 122 |
|
return(status); /* return status */ |
| 123 |
|
} |
| 124 |
|
|
| 129 |
|
|
| 130 |
|
if (nprocs > 0) /* already running? */ |
| 131 |
|
return; |
| 95 |
– |
wputs("restarting rtrace process...\n"); |
| 132 |
|
starttime = time(NULL); /* reset start time and counts */ |
| 133 |
|
npacksdone = nraysdone = 0L; |
| 134 |
|
if (vdef(TIME)) /* reset end time */ |
| 140 |
|
} |
| 141 |
|
if (start_rtrace() < 1) /* start rtrace */ |
| 142 |
|
error(WARNING, "cannot restart rtrace"); |
| 143 |
< |
else if (vdef(REPORT)) |
| 143 |
> |
else if (vdef(REPORT)) { |
| 144 |
> |
eputs("rtrace process restarted\n"); |
| 145 |
|
report(0); |
| 146 |
+ |
} |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
getradfile() /* run rad and get needed variables */ |
| 151 |
|
{ |
| 152 |
< |
static short mvar[] = {OCTREE,-1}; |
| 152 |
> |
static short mvar[] = {OCTREE,EYESEP,-1}; |
| 153 |
|
static char tf1[] = TEMPLATE; |
| 154 |
|
char tf2[64]; |
| 155 |
|
char combuf[256]; |
| 158 |
|
register char *cp; |
| 159 |
|
/* check if rad file specified */ |
| 160 |
|
if (!vdef(RIF)) |
| 161 |
< |
return; |
| 161 |
> |
return(0); |
| 162 |
|
/* create rad command */ |
| 163 |
|
mktemp(tf1); |
| 164 |
|
sprintf(tf2, "%s.rif", tf1); |
| 181 |
|
strcpy(pippt, "> /dev/null"); /* nothing to match */ |
| 182 |
|
else |
| 183 |
|
sprintf(cp, ")[ \t]*=' > %s", tf2); |
| 184 |
< |
if (system(combuf)) { |
| 185 |
< |
unlink(tf2); /* clean up */ |
| 186 |
< |
unlink(tf1); |
| 187 |
< |
error(SYSTEM, "cannot execute rad command"); |
| 150 |
< |
} |
| 184 |
> |
#ifdef DEBUG |
| 185 |
> |
wputs(combuf); wputs("\n"); |
| 186 |
> |
#endif |
| 187 |
> |
system(combuf); /* ignore exit code */ |
| 188 |
|
if (pippt == NULL) { |
| 189 |
|
loadvars(tf2); /* load variables */ |
| 190 |
|
unlink(tf2); |
| 191 |
|
} |
| 192 |
|
rtargc += wordfile(rtargv+rtargc, tf1); /* get rtrace options */ |
| 193 |
|
unlink(tf1); /* clean up */ |
| 194 |
+ |
return(1); |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|