| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 11 |
|
#include "rholo.h" |
| 12 |
|
#include "rhdisp.h" |
| 13 |
|
#include "rhdriver.h" |
| 14 |
+ |
#include "random.h" |
| 15 |
|
|
| 16 |
|
#ifndef MAXDIST |
| 17 |
< |
#define MAXDIST 13 /* maximum distance outside section */ |
| 17 |
> |
#define MAXDIST 42 /* maximum distance outside section */ |
| 18 |
|
#endif |
| 19 |
+ |
#ifndef NVSAMPS |
| 20 |
+ |
#define NVSAMPS 16384 /* number of ray samples per view */ |
| 21 |
+ |
#endif |
| 22 |
+ |
#ifndef MEYERNG |
| 23 |
+ |
#define MEYERNG 0.1 /* target mean eye range (rel. to grid) */ |
| 24 |
+ |
#endif |
| 25 |
+ |
#ifndef MAXTODO |
| 26 |
+ |
#define MAXTODO 3 /* maximum sections to look at */ |
| 27 |
+ |
#endif |
| 28 |
+ |
#ifndef MAXDRAT |
| 29 |
+ |
#define MAXDRAT 3.0 /* maximum distance ratio btwn. cand. sect. */ |
| 30 |
+ |
#endif |
| 31 |
|
|
| 19 |
– |
extern GCOORD *getviewcells(); |
| 20 |
– |
|
| 21 |
– |
static VIEW dvw; /* current view corresponding to beam list */ |
| 22 |
– |
|
| 23 |
– |
typedef struct { |
| 24 |
– |
int hd; /* holodeck section number (-1 if inactive) */ |
| 25 |
– |
int i[3]; /* voxel index (may be outside section) */ |
| 26 |
– |
} VOXL; /* a voxel */ |
| 27 |
– |
|
| 28 |
– |
static VOXL voxel[8] = { /* current voxel list */ |
| 29 |
– |
{-1}, {-1}, {-1}, {-1}, |
| 30 |
– |
{-1}, {-1}, {-1}, {-1} |
| 31 |
– |
}; |
| 32 |
– |
|
| 32 |
|
#define CBEAMBLK 1024 /* cbeam allocation block size */ |
| 33 |
|
|
| 34 |
|
static struct beamcomp { |
| 35 |
< |
short wants; /* flags telling which voxels want us */ |
| 37 |
< |
short hd; /* holodeck section number */ |
| 35 |
> |
int hd; /* holodeck section number */ |
| 36 |
|
int bi; /* beam index */ |
| 37 |
+ |
int4 nr; /* number of samples desired */ |
| 38 |
|
} *cbeam = NULL; /* current beam list */ |
| 39 |
|
|
| 40 |
+ |
VIEWPOINT cureye; /* current eye position */ |
| 41 |
+ |
|
| 42 |
|
static int ncbeams = 0; /* number of sorted beams in cbeam */ |
| 43 |
|
static int xcbeams = 0; /* extra (unregistered) beams past ncbeams */ |
| 44 |
|
static int maxcbeam = 0; /* size of cbeam array */ |
| 45 |
|
|
| 45 |
– |
struct cellact { |
| 46 |
– |
short vi; /* voxel index */ |
| 47 |
– |
short add; /* zero means delete */ |
| 48 |
– |
short rev; /* reverse ray direction? */ |
| 49 |
– |
}; /* action for cell */ |
| 46 |
|
|
| 51 |
– |
struct beamact { |
| 52 |
– |
struct cellact ca; /* cell action */ |
| 53 |
– |
GCOORD gc; /* grid coordinate */ |
| 54 |
– |
}; /* beam origin and action */ |
| 55 |
– |
|
| 56 |
– |
|
| 47 |
|
int |
| 48 |
|
newcbeam() /* allocate new entry at end of cbeam array */ |
| 49 |
|
{ |
| 82 |
|
{ |
| 83 |
|
register int c; |
| 84 |
|
|
| 85 |
< |
if (!cb1->wants) /* put orphans at the end, unsorted */ |
| 86 |
< |
return(cb2->wants); |
| 85 |
> |
if (!cb1->nr) /* put orphans at the end, unsorted */ |
| 86 |
> |
return(cb2->nr); |
| 87 |
> |
if (!cb2->nr) |
| 88 |
> |
return(-1); |
| 89 |
|
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
| 90 |
|
return(c); |
| 91 |
|
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
| 101 |
|
|
| 102 |
|
if (ncbeams <= 0) |
| 103 |
|
return(-1); |
| 104 |
< |
cb.wants = 0; cb.hd = hd; cb.bi = bi; |
| 104 |
> |
cb.hd = hd; cb.bi = bi; cb.nr = 0; |
| 105 |
|
p = (struct beamcomp *)bsearch((char *)&cb, (char *)cbeam, ncbeams, |
| 106 |
|
sizeof(struct beamcomp), cbeamcmp); |
| 107 |
|
if (p == NULL) |
| 129 |
|
if (bi < 1 | bi > nbeams(hdlist[hd])) |
| 130 |
|
error(INTERNAL, "illegal beam index in getcbeam"); |
| 131 |
|
n = newcbeam(); /* allocate and assign */ |
| 132 |
< |
cbeam[n].wants = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; |
| 132 |
> |
cbeam[n].nr = 0; cbeam[n].hd = hd; cbeam[n].bi = bi; |
| 133 |
|
return(n); |
| 134 |
|
} |
| 135 |
|
|
| 147 |
|
if (adopt) |
| 148 |
|
return; |
| 149 |
|
for (i = ncbeams; i--; ) /* identify orphans */ |
| 150 |
< |
if (cbeam[i].wants) |
| 150 |
> |
if (cbeam[i].nr) |
| 151 |
|
break; |
| 152 |
|
xcbeams = ncbeams - ++i; /* put orphans after ncbeams */ |
| 153 |
|
ncbeams = i; |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
|
| 157 |
< |
cbeamadj(v, hr, vr) /* adjust our beam list */ |
| 166 |
< |
VIEW *v; |
| 167 |
< |
int hr, vr; |
| 168 |
< |
{ |
| 169 |
< |
register PACKHEAD *pa; |
| 170 |
< |
register int i; |
| 171 |
< |
int n; |
| 172 |
< |
/* first handle additions */ |
| 173 |
< |
pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); |
| 174 |
< |
if (xcbeams && pa == NULL) |
| 175 |
< |
goto memerr; |
| 176 |
< |
for (i = xcbeams; i--; ) { |
| 177 |
< |
pa[i].hd = cbeam[ncbeams+i].hd; |
| 178 |
< |
pa[i].bi = cbeam[ncbeams+i].bi; |
| 179 |
< |
pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi) + 1; |
| 180 |
< |
} |
| 181 |
< |
n = xcbeams; /* now sort list for deletions */ |
| 182 |
< |
cbeamsort(0); |
| 183 |
< |
pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD)); |
| 184 |
< |
if (n+xcbeams && pa == NULL) |
| 185 |
< |
goto memerr; |
| 186 |
< |
for (i = xcbeams; i--; ) { |
| 187 |
< |
pa[n+i].hd = cbeam[ncbeams+i].hd; |
| 188 |
< |
pa[n+i].bi = cbeam[ncbeams+i].bi; |
| 189 |
< |
pa[n+i].nr = 0; |
| 190 |
< |
} |
| 191 |
< |
n += xcbeams; |
| 192 |
< |
xcbeams = 0; /* delete orphans */ |
| 193 |
< |
serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); |
| 194 |
< |
free((char *)pa); |
| 195 |
< |
return; |
| 196 |
< |
memerr: |
| 197 |
< |
error(SYSTEM, "out of memory in cbeamadj"); |
| 198 |
< |
} |
| 199 |
< |
|
| 200 |
< |
|
| 201 |
< |
cbeamop(op, bl, n, v, hr, vr) /* update beams on server list */ |
| 157 |
> |
cbeamop(op, bl, n) /* update beams on server list */ |
| 158 |
|
int op; |
| 159 |
|
register struct beamcomp *bl; |
| 160 |
|
int n; |
| 205 |
– |
VIEW *v; |
| 206 |
– |
int hr, vr; |
| 161 |
|
{ |
| 162 |
|
register PACKHEAD *pa; |
| 163 |
|
register int i; |
| 166 |
|
return; |
| 167 |
|
pa = (PACKHEAD *)malloc(n*sizeof(PACKHEAD)); |
| 168 |
|
if (pa == NULL) |
| 169 |
< |
error(SYSTEM, "out of memory in cbeamadd"); |
| 169 |
> |
error(SYSTEM, "out of memory in cbeamop"); |
| 170 |
|
for (i = 0; i < n; i++) { |
| 171 |
|
pa[i].hd = bl[i].hd; |
| 172 |
|
pa[i].bi = bl[i].bi; |
| 173 |
< |
pa[i].nr = v==NULL ? 0 : |
| 174 |
< |
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
| 173 |
> |
pa[i].nr = bl[i].nr; |
| 174 |
> |
pa[i].nc = 0; |
| 175 |
|
} |
| 176 |
|
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
| 177 |
|
free((char *)pa); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
< |
int |
| 182 |
< |
set_voxels(vl, n) /* set new voxel array */ |
| 183 |
< |
VOXL vl[8]; |
| 184 |
< |
int n; |
| 181 |
> |
static int |
| 182 |
> |
comptodo(tdl, vw) /* compute holodeck sections in view */ |
| 183 |
> |
int tdl[MAXTODO+1]; |
| 184 |
> |
VIEW *vw; |
| 185 |
|
{ |
| 232 |
– |
short wmap[256]; |
| 233 |
– |
int vmap[8]; |
| 234 |
– |
int comn = 0; |
| 235 |
– |
int no; |
| 236 |
– |
register int i, j; |
| 237 |
– |
/* find common voxels */ |
| 238 |
– |
for (j = 0; j < 8 && voxel[j].hd >= 0; j++) { |
| 239 |
– |
vmap[j] = -1; |
| 240 |
– |
for (i = n; i--; ) |
| 241 |
– |
if (!bcmp((char *)(vl+i), (char *)(voxel+j), |
| 242 |
– |
sizeof(VOXL))) { |
| 243 |
– |
vmap[j] = i; |
| 244 |
– |
comn |= 1<<i; |
| 245 |
– |
break; |
| 246 |
– |
} |
| 247 |
– |
} |
| 248 |
– |
no = comn ? j : 0; /* compute flag mapping */ |
| 249 |
– |
for (i = 256; i--; ) { |
| 250 |
– |
wmap[i] = 0; |
| 251 |
– |
for (j = no; j--; ) |
| 252 |
– |
if (vmap[j] >= 0 && i & 1<<j) |
| 253 |
– |
wmap[i] |= 1<<vmap[j]; |
| 254 |
– |
} |
| 255 |
– |
/* fix cbeam flags */ |
| 256 |
– |
for (i = ncbeams; i--; ) |
| 257 |
– |
cbeam[i].wants = wmap[cbeam[i].wants]; |
| 258 |
– |
/* update our voxel list */ |
| 259 |
– |
bcopy((char *)vl, (char *)voxel, n*sizeof(VOXL)); |
| 260 |
– |
for (j = n; j < 8; j++) |
| 261 |
– |
voxel[j].hd = -1; |
| 262 |
– |
return(comn); /* return bit array of common voxels */ |
| 263 |
– |
} |
| 264 |
– |
|
| 265 |
– |
|
| 266 |
– |
int |
| 267 |
– |
get_voxels(vl, vp) /* find voxels corresponding to view point */ |
| 268 |
– |
VOXL vl[8]; |
| 269 |
– |
FVECT vp; |
| 270 |
– |
{ |
| 271 |
– |
static int lastn = 0, lastd = -1; |
| 186 |
|
int n = 0; |
| 187 |
< |
FVECT gp; |
| 188 |
< |
double d; |
| 189 |
< |
int dist, bestd = 0x7fff; |
| 190 |
< |
VOXL vox; |
| 191 |
< |
register int i, j, k; |
| 192 |
< |
/* find closest voxels */ |
| 193 |
< |
for (i = 0; n < 8 && hdlist[i]; i++) { |
| 194 |
< |
hdgrid(gp, hdlist[i], vp); |
| 195 |
< |
for (j = 0; n < 8 && j < 8; j++) { |
| 196 |
< |
dist = 0; |
| 197 |
< |
for (k = 0; k < 3; k++) { |
| 198 |
< |
d = gp[k] - .5 + (j>>k & 1); |
| 199 |
< |
if (d < 0.) |
| 200 |
< |
dist += -(vox.i[k] = (int)d - 1); |
| 201 |
< |
else if ((vox.i[k] = d) >= hdlist[i]->grid[k]) |
| 202 |
< |
dist += vox.i[k] - |
| 203 |
< |
hdlist[i]->grid[k] + 1; |
| 290 |
< |
} |
| 291 |
< |
if (dist > bestd) /* others were closer */ |
| 292 |
< |
continue; |
| 293 |
< |
if (dist < bestd) { /* start closer list */ |
| 294 |
< |
n = 0; |
| 295 |
< |
bestd = dist; |
| 296 |
< |
} |
| 297 |
< |
vox.hd = i; /* add this voxel */ |
| 298 |
< |
copystruct(&vl[n], &vox); |
| 299 |
< |
n++; |
| 187 |
> |
FVECT gp, dv; |
| 188 |
> |
double dist2[MAXTODO+1], thisdist2; |
| 189 |
> |
register int i, j; |
| 190 |
> |
/* find closest MAXTODO sections */ |
| 191 |
> |
for (i = 0; hdlist[i]; i++) { |
| 192 |
> |
hdgrid(gp, hdlist[i], vw->vp); |
| 193 |
> |
for (j = 0; j < 3; j++) |
| 194 |
> |
if (gp[j] < 0.) |
| 195 |
> |
dv[j] = -gp[j]; |
| 196 |
> |
else if (gp[j] > hdlist[i]->grid[j]) |
| 197 |
> |
dv[j] = gp[j] - hdlist[i]->grid[j]; |
| 198 |
> |
else |
| 199 |
> |
dv[j] = 0.; |
| 200 |
> |
thisdist2 = DOT(dv,dv); |
| 201 |
> |
for (j = n; j > 0 && thisdist2 < dist2[j-1]; j--) { |
| 202 |
> |
tdl[j] = tdl[j-1]; |
| 203 |
> |
dist2[j] = dist2[j-1]; |
| 204 |
|
} |
| 205 |
+ |
tdl[j] = i; |
| 206 |
+ |
dist2[j] = thisdist2; |
| 207 |
+ |
if (n < MAXTODO) |
| 208 |
+ |
n++; |
| 209 |
|
} |
| 210 |
< |
/* check for really stupid move */ |
| 211 |
< |
if (bestd > MAXDIST) { |
| 210 |
> |
/* watch for bad move */ |
| 211 |
> |
if (n && dist2[0] > MAXDIST*MAXDIST) { |
| 212 |
|
error(COMMAND, "move past outer limits"); |
| 213 |
|
return(0); |
| 214 |
|
} |
| 215 |
< |
/* warn of dangerous moves */ |
| 216 |
< |
if (n < lastn && bestd >= lastd) |
| 217 |
< |
error(WARNING, "moving outside holodeck section"); |
| 218 |
< |
else if (n > lastn && bestd <= lastd) |
| 219 |
< |
error(WARNING, "moving inside holodeck section"); |
| 220 |
< |
lastd = bestd; |
| 313 |
< |
return(lastn = n); |
| 215 |
> |
/* avoid big differences */ |
| 216 |
> |
for (j = 1; j < n; j++) |
| 217 |
> |
if (dist2[j] > MAXDRAT*MAXDRAT*dist2[j-1]) |
| 218 |
> |
n = j; |
| 219 |
> |
tdl[n] = -1; |
| 220 |
> |
return(n); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
int |
| 225 |
< |
dobeam(gcp, bp) /* express interest or disintrest in a beam */ |
| 226 |
< |
GCOORD *gcp; |
| 227 |
< |
register struct beamact *bp; |
| 225 |
> |
addview(hd, vw, hres, vres) /* add view for section */ |
| 226 |
> |
int hd; |
| 227 |
> |
VIEW *vw; |
| 228 |
> |
int hres, vres; |
| 229 |
|
{ |
| 230 |
+ |
int sampquant, samptot = 0; |
| 231 |
+ |
int h, v, shr, svr; |
| 232 |
|
GCOORD gc[2]; |
| 233 |
< |
int bi, i; |
| 234 |
< |
/* compute beam index */ |
| 235 |
< |
if (bp->ca.rev) { |
| 236 |
< |
copystruct(gc, &bp->gc); |
| 237 |
< |
copystruct(gc+1, gcp); |
| 233 |
> |
FVECT rorg, rdir; |
| 234 |
> |
/* compute sampling grid */ |
| 235 |
> |
if (hres|vres && hres*vres <= NVSAMPS) { |
| 236 |
> |
shr = hres; svr = vres; |
| 237 |
> |
sampquant = 1; |
| 238 |
|
} else { |
| 239 |
< |
copystruct(gc, gcp); |
| 240 |
< |
copystruct(gc+1, &bp->gc); |
| 239 |
> |
shr = sqrt(NVSAMPS/viewaspect(vw)) + .5; |
| 240 |
> |
svr = (NVSAMPS + shr/2)/shr; |
| 241 |
> |
sampquant = (hres*vres + shr*svr/2)/(shr*svr); |
| 242 |
|
} |
| 243 |
< |
if ((bi = hdbindex(hdlist[voxel[bp->ca.vi].hd], gc)) <= 0) |
| 244 |
< |
error(CONSISTENCY, "bad grid coordinate in dobeam"); |
| 245 |
< |
if (bp->ca.add) { /* add it in */ |
| 246 |
< |
i = getcbeam(voxel[bp->ca.vi].hd, bi); |
| 247 |
< |
cbeam[i].wants |= 1<<bp->ca.vi; /* say we want it */ |
| 248 |
< |
return(i == ncbeams+xcbeams-1); /* return 1 if totally new */ |
| 249 |
< |
} |
| 250 |
< |
/* else delete it */ |
| 251 |
< |
i = findcbeam(voxel[bp->ca.vi].hd, bi); |
| 252 |
< |
if (i >= 0 && cbeam[i].wants & 1<<bp->ca.vi) { |
| 253 |
< |
cbeam[i].wants &= ~(1<<bp->ca.vi); /* we don't want it */ |
| 254 |
< |
return(1); /* indicate change */ |
| 255 |
< |
} |
| 256 |
< |
return(0); |
| 243 |
> |
/* intersect sample rays with section */ |
| 244 |
> |
for (v = svr; v--; ) |
| 245 |
> |
for (h = shr; h--; ) { |
| 246 |
> |
if (viewray(rorg, rdir, vw, (v+frandom())/svr, |
| 247 |
> |
(h+frandom())/shr) < -FTINY) |
| 248 |
> |
continue; |
| 249 |
> |
if (hdinter(gc, NULL, NULL, hdlist[hd], rorg, rdir) |
| 250 |
> |
>= FHUGE) |
| 251 |
> |
continue; |
| 252 |
> |
cbeam[getcbeam(hd,hdbindex(hdlist[hd],gc))].nr += |
| 253 |
> |
sampquant; |
| 254 |
> |
samptot += sampquant; |
| 255 |
> |
} |
| 256 |
> |
return(samptot); |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|
| 260 |
< |
|
| 261 |
< |
int |
| 351 |
< |
docell(gcp, cap) /* find beams corresponding to cell and voxel */ |
| 352 |
< |
GCOORD *gcp; |
| 353 |
< |
register struct cellact *cap; |
| 260 |
> |
beam_init(fresh) /* clear beam list for new view(s) */ |
| 261 |
> |
int fresh; |
| 262 |
|
{ |
| 355 |
– |
register HOLO *hp = hdlist[voxel[cap->vi].hd]; |
| 356 |
– |
FVECT org, dir[4]; |
| 357 |
– |
FVECT vgp, cgp, vc; |
| 358 |
– |
FVECT v1, v2; |
| 359 |
– |
struct beamact bo; |
| 360 |
– |
int axmax, j; |
| 361 |
– |
double d, avmax; |
| 263 |
|
register int i; |
| 363 |
– |
/* compute cell center */ |
| 364 |
– |
cgp[gcp->w>>1] = gcp->w&1 ? hp->grid[gcp->w>>1] : 0 ; |
| 365 |
– |
cgp[((gcp->w>>1)+1)%3] = gcp->i[0] + .5; |
| 366 |
– |
cgp[((gcp->w>>1)+2)%3] = gcp->i[1] + .5; |
| 367 |
– |
hdworld(org, hp, cgp); |
| 368 |
– |
/* compute direction to voxel center */ |
| 369 |
– |
for (i = 3; i--; ) |
| 370 |
– |
vgp[i] = voxel[cap->vi].i[i] + .5; |
| 371 |
– |
hdworld(vc, hp, vgp); |
| 372 |
– |
for (i = 3; i--; ) |
| 373 |
– |
vc[i] -= org[i]; |
| 374 |
– |
/* compute maximum area axis */ |
| 375 |
– |
axmax = -1; avmax = 0; |
| 376 |
– |
for (i = 3; i--; ) { |
| 377 |
– |
d = vgp[i] - cgp[i]; |
| 378 |
– |
if (d < 0.) d = -d; |
| 379 |
– |
if (d > avmax) { |
| 380 |
– |
avmax = d; |
| 381 |
– |
axmax = i; |
| 382 |
– |
} |
| 383 |
– |
} |
| 384 |
– |
#ifdef DEBUG |
| 385 |
– |
if (axmax < 0.) |
| 386 |
– |
error(CONSISTENCY, "botched axis computation in docell"); |
| 387 |
– |
#endif |
| 388 |
– |
/* compute offset vectors */ |
| 389 |
– |
d = 0.5/hp->grid[j=(axmax+1)%3]; |
| 390 |
– |
for (i = 3; i--; ) |
| 391 |
– |
v1[i] = hp->xv[j][i] * d; |
| 392 |
– |
d = 0.5/hp->grid[j=(axmax+2)%3]; |
| 393 |
– |
if (DOT(hp->wn[axmax], vc) < 0.) |
| 394 |
– |
d = -d; /* reverse vertex ordering */ |
| 395 |
– |
for (i = 3; i--; ) |
| 396 |
– |
v2[i] = hp->xv[j][i] * d; |
| 397 |
– |
/* compute voxel pyramid */ |
| 398 |
– |
for (i = 3; i--; ) { |
| 399 |
– |
dir[0][i] = vc[i] - v1[i] - v2[i]; |
| 400 |
– |
dir[1][i] = vc[i] + v1[i] - v2[i]; |
| 401 |
– |
dir[2][i] = vc[i] + v1[i] + v2[i]; |
| 402 |
– |
dir[3][i] = vc[i] - v1[i] + v2[i]; |
| 403 |
– |
} |
| 404 |
– |
/* visit beams for opposite cells */ |
| 405 |
– |
copystruct(&bo.ca, cap); |
| 406 |
– |
copystruct(&bo.gc, gcp); |
| 407 |
– |
return(visit_cells(org, dir, hp, dobeam, &bo)); |
| 408 |
– |
} |
| 264 |
|
|
| 265 |
< |
|
| 266 |
< |
int |
| 267 |
< |
doview(cap, vp) /* visit cells for a given view */ |
| 268 |
< |
struct cellact *cap; |
| 269 |
< |
VIEW *vp; |
| 270 |
< |
{ |
| 416 |
< |
int orient; |
| 417 |
< |
FVECT org, dir[4]; |
| 418 |
< |
/* compute view pyramid */ |
| 419 |
< |
orient = viewpyramid(org, dir, hdlist[voxel[cap->vi].hd], vp); |
| 420 |
< |
if (!orient) |
| 421 |
< |
error(INTERNAL, "unusable view in doview"); |
| 422 |
< |
cap->rev = orient < 0; |
| 423 |
< |
/* visit cells within pyramid */ |
| 424 |
< |
return(visit_cells(org, dir, hdlist[voxel[cap->vi].hd], docell, cap)); |
| 265 |
> |
if (fresh) /* discard old beams? */ |
| 266 |
> |
ncbeams = xcbeams = 0; |
| 267 |
> |
else /* else clear sample requests */ |
| 268 |
> |
for (i = ncbeams+xcbeams; i--; ) |
| 269 |
> |
cbeam[i].nr = 0; |
| 270 |
> |
cureye.rng = 0.; |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
|
| 274 |
< |
mvview(voxi, vold, vnew) /* move view for a voxel */ |
| 275 |
< |
int voxi; |
| 276 |
< |
VIEW *vold, *vnew; |
| 274 |
> |
int * |
| 275 |
> |
beam_view(vn, hr, vr) /* add beam view (if advisable) */ |
| 276 |
> |
VIEW *vn; |
| 277 |
> |
int hr, vr; |
| 278 |
|
{ |
| 279 |
< |
int netchange = 0; |
| 280 |
< |
struct cellact oca, nca; |
| 281 |
< |
int ocnt, ncnt; |
| 282 |
< |
int c; |
| 283 |
< |
GCOORD *ogcl, *ngcl; |
| 284 |
< |
register GCOORD *ogcp, *ngcp; |
| 285 |
< |
/* get old and new cell lists */ |
| 286 |
< |
ogcp = ogcl = getviewcells(&ocnt, hdlist[voxel[voxi].hd], vold); |
| 287 |
< |
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
| 288 |
< |
/* set up actions */ |
| 289 |
< |
oca.vi = nca.vi = voxi; |
| 290 |
< |
oca.add = 0; nca.add = 1; |
| 291 |
< |
if ((oca.rev = ocnt < 0)) |
| 292 |
< |
ocnt = -ocnt; |
| 293 |
< |
if ((nca.rev = ncnt < 0)) |
| 294 |
< |
ncnt = -ncnt; |
| 295 |
< |
if (nca.rev == oca.rev) /* add and delete cells in order */ |
| 296 |
< |
while (ocnt > 0 & ncnt > 0) |
| 297 |
< |
if ((c = cellcmp(ogcp, ngcp)) > 0) { /* new cell */ |
| 298 |
< |
netchange += docell(ngcp++, &nca); |
| 299 |
< |
ncnt--; |
| 300 |
< |
} else if (c < 0) { /* old cell */ |
| 301 |
< |
netchange -= docell(ogcp++, &oca); |
| 302 |
< |
ocnt--; |
| 303 |
< |
} else { /* same cell */ |
| 304 |
< |
ogcp++; ocnt--; |
| 305 |
< |
ngcp++; ncnt--; |
| 306 |
< |
} |
| 307 |
< |
/* take care of list tails */ |
| 308 |
< |
for ( ; ncnt > 0; ncnt--) |
| 309 |
< |
netchange += docell(ngcp++, &nca); |
| 310 |
< |
for ( ; ocnt > 0; ocnt--) |
| 311 |
< |
netchange -= docell(ogcp++, &oca); |
| 312 |
< |
/* clean up */ |
| 313 |
< |
if (ogcl != NULL) free((char *)ogcl); |
| 314 |
< |
if (ngcl != NULL) free((char *)ngcl); |
| 315 |
< |
return(netchange); |
| 279 |
> |
static int todo[MAXTODO+1]; |
| 280 |
> |
int n; |
| 281 |
> |
double hdgsiz, d; |
| 282 |
> |
register HOLO *hp; |
| 283 |
> |
register int i; |
| 284 |
> |
/* find nearby sections */ |
| 285 |
> |
if (!(n = comptodo(todo, vn))) |
| 286 |
> |
return(NULL); |
| 287 |
> |
/* sort our list */ |
| 288 |
> |
cbeamsort(1); |
| 289 |
> |
/* add view to flagged sections */ |
| 290 |
> |
for (i = 0; i < n; i++) |
| 291 |
> |
if (!addview(todo[i], vn, hr, vr)) { /* whoops! */ |
| 292 |
> |
register int j; |
| 293 |
> |
n--; /* delete from list */ |
| 294 |
> |
for (j = i--; j <= n; j++) |
| 295 |
> |
todo[j] = todo[j+1]; |
| 296 |
> |
} |
| 297 |
> |
if (!n || MEYERNG <= FTINY || vn->type == VT_PAR) |
| 298 |
> |
return(todo); |
| 299 |
> |
hdgsiz = 0.; /* compute mean grid size */ |
| 300 |
> |
for (i = 0; i < n; i++) { |
| 301 |
> |
hp = hdlist[todo[i]]; |
| 302 |
> |
hdgsiz += 1./3. / VLEN(hp->wg[0]) + |
| 303 |
> |
1./3. / VLEN(hp->wg[1]) + |
| 304 |
> |
1./3. / VLEN(hp->wg[2]) ; |
| 305 |
> |
} |
| 306 |
> |
hdgsiz /= (double)n; |
| 307 |
> |
/* add to current eye position */ |
| 308 |
> |
if (cureye.rng <= FTINY) { |
| 309 |
> |
VCOPY(cureye.vpt, vn->vp); |
| 310 |
> |
cureye.rng = MEYERNG * hdgsiz; |
| 311 |
> |
} else if ((d = sqrt(dist2(vn->vp,cureye.vpt))) + MEYERNG*hdgsiz > |
| 312 |
> |
cureye.rng) { |
| 313 |
> |
for (i = 3; i--; ) |
| 314 |
> |
cureye.vpt[i] = 0.5*(cureye.vpt[i] + vn->vp[i]); |
| 315 |
> |
cureye.rng = 0.5*(cureye.rng + MEYERNG*hdgsiz + d); |
| 316 |
> |
} |
| 317 |
> |
return(todo); |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
|
int |
| 322 |
< |
beam_sync() /* synchronize beams on server */ |
| 322 |
> |
beam_sync(all) /* update beam list on server */ |
| 323 |
> |
int all; |
| 324 |
|
{ |
| 325 |
< |
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
| 326 |
< |
return(ncbeams); |
| 327 |
< |
} |
| 328 |
< |
|
| 329 |
< |
|
| 330 |
< |
beam_view(vn) /* change beam view (if advisable) */ |
| 331 |
< |
VIEW *vn; |
| 332 |
< |
{ |
| 333 |
< |
struct cellact ca; |
| 484 |
< |
VOXL vlnew[8]; |
| 485 |
< |
int n, comn; |
| 486 |
< |
|
| 487 |
< |
if (vn == NULL || !vn->type) { /* clear our beam list */ |
| 488 |
< |
set_voxels(vlnew, 0); |
| 489 |
< |
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
| 490 |
< |
ncbeams = 0; |
| 491 |
< |
dvw.type = 0; |
| 492 |
< |
return(1); |
| 493 |
< |
} |
| 494 |
< |
/* find our new voxels */ |
| 495 |
< |
n = get_voxels(vlnew, vn->vp); |
| 496 |
< |
if (dvw.type && !n) { |
| 497 |
< |
copystruct(vn, &dvw); /* cancel move */ |
| 498 |
< |
return(0); |
| 499 |
< |
} |
| 500 |
< |
/* set the new voxels */ |
| 501 |
< |
comn = set_voxels(vlnew, n); |
| 502 |
< |
if (!dvw.type) |
| 503 |
< |
comn = 0; |
| 504 |
< |
ca.add = 1; /* update our beam list */ |
| 505 |
< |
for (ca.vi = n; ca.vi--; ) |
| 506 |
< |
if (comn & 1<<ca.vi) /* change which cells we see */ |
| 507 |
< |
mvview(ca.vi, &dvw, vn); |
| 508 |
< |
else /* else add all new cells */ |
| 509 |
< |
doview(&ca, vn); |
| 510 |
< |
#if 1 |
| 511 |
< |
cbeamadj(vn, odev.hres, odev.vres); |
| 512 |
< |
#else |
| 513 |
< |
/* inform server of new beams */ |
| 514 |
< |
cbeamop(DR_ADDSET, cbeam+ncbeams, xcbeams, vn, odev.hres, odev.vres); |
| 515 |
< |
/* sort list to put orphans at end */ |
| 516 |
< |
cbeamsort(0); |
| 517 |
< |
/* tell server to delete orphans */ |
| 518 |
< |
cbeamop(DR_DELSET, cbeam+ncbeams, xcbeams, NULL, 0, 0); |
| 325 |
> |
/* set new eye position */ |
| 326 |
> |
serv_request(DR_VIEWPOINT, sizeof(VIEWPOINT), (char *)&cureye); |
| 327 |
> |
/* sort list (put orphans at end) */ |
| 328 |
> |
cbeamsort(all < 0); |
| 329 |
> |
/* send beam request */ |
| 330 |
> |
if (all) |
| 331 |
> |
cbeamop(DR_NEWSET, cbeam, ncbeams); |
| 332 |
> |
else |
| 333 |
> |
cbeamop(DR_ADJSET, cbeam, ncbeams+xcbeams); |
| 334 |
|
xcbeams = 0; /* truncate our list */ |
| 335 |
< |
#endif |
| 521 |
< |
copystruct(&dvw, vn); /* record new view */ |
| 522 |
< |
return(1); |
| 335 |
> |
return(ncbeams); |
| 336 |
|
} |