13 |
|
#include "rhdriver.h" |
14 |
|
|
15 |
|
#ifndef MAXDIST |
16 |
< |
#define MAXDIST 13 /* maximum distance outside section */ |
16 |
> |
#define MAXDIST 42 /* maximum distance outside section */ |
17 |
|
#endif |
18 |
|
|
19 |
|
extern GCOORD *getviewcells(); |
94 |
|
|
95 |
|
if (!cb1->wants) /* put orphans at the end, unsorted */ |
96 |
|
return(cb2->wants); |
97 |
+ |
if (!cb2->wants) |
98 |
+ |
return(-1); |
99 |
|
if ((c = cb1->bi - cb2->bi)) /* sort on beam index first */ |
100 |
|
return(c); |
101 |
|
return(cb1->hd - cb2->hd); /* use hd to resolve matches */ |
168 |
|
VIEW *v; |
169 |
|
int hr, vr; |
170 |
|
{ |
171 |
< |
register PACKHEAD *pa; |
171 |
> |
PACKHEAD *pa, *pa2; |
172 |
> |
register PACKHEAD *pp; |
173 |
> |
int n, n2; |
174 |
> |
FVECT gp; |
175 |
> |
int igp[3], vcflgs; |
176 |
|
register int i; |
177 |
< |
int n; |
178 |
< |
/* first handle additions */ |
179 |
< |
pa = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); |
180 |
< |
if (xcbeams && pa == NULL) |
177 |
> |
/* figure out center voxel(s) */ |
178 |
> |
n = -1; vcflgs = 0; |
179 |
> |
for (i = 0; i < 8 && voxel[i].hd >= 0; i++) { |
180 |
> |
if (voxel[i].hd != n) { |
181 |
> |
hdgrid(gp, hdlist[n=voxel[i].hd], v->vp); |
182 |
> |
igp[0] = gp[0]; igp[1] = gp[1]; igp[2] = gp[2]; |
183 |
> |
} |
184 |
> |
if (voxel[i].i[0] == igp[0] && voxel[i].i[1] == igp[1] && |
185 |
> |
voxel[i].i[2] == igp[2]) |
186 |
> |
vcflgs |= 1<<i; |
187 |
> |
} |
188 |
> |
/* get additions */ |
189 |
> |
pa2 = (PACKHEAD *)malloc(xcbeams*sizeof(PACKHEAD)); |
190 |
> |
if (xcbeams && pa2 == NULL) |
191 |
|
goto memerr; |
192 |
+ |
pa = pa2 + xcbeams; n2 = 0; |
193 |
|
for (i = xcbeams; i--; ) { |
194 |
< |
pa[i].hd = cbeam[ncbeams+i].hd; |
195 |
< |
pa[i].bi = cbeam[ncbeams+i].bi; |
196 |
< |
pa[i].nr = npixels(v, hr, vr, hdlist[pa[i].hd], pa[i].bi) + 1; |
194 |
> |
if (cbeam[ncbeams+i].wants & vcflgs) |
195 |
> |
pp = --pa; /* priority list */ |
196 |
> |
else |
197 |
> |
pp = pa2 + n2++; /* secondary list */ |
198 |
> |
pp->hd = cbeam[ncbeams+i].hd; |
199 |
> |
pp->bi = cbeam[ncbeams+i].bi; |
200 |
> |
pp->nr = npixels(v, hr, vr, hdlist[pp->hd], pp->bi) + 1; |
201 |
> |
pp->nc = 0; |
202 |
|
} |
203 |
< |
n = xcbeams; /* now sort list for deletions */ |
203 |
> |
n = xcbeams - n2; |
204 |
> |
/* now sort list for deletions */ |
205 |
|
cbeamsort(0); |
206 |
< |
pa = (PACKHEAD *)realloc((char *)pa, (n+xcbeams)*sizeof(PACKHEAD)); |
207 |
< |
if (n+xcbeams && pa == NULL) |
206 |
> |
pa2 = (PACKHEAD *)realloc((char *)pa2, (n+n2+xcbeams)*sizeof(PACKHEAD)); |
207 |
> |
if (n+n2+xcbeams && pa2 == NULL) |
208 |
|
goto memerr; |
209 |
+ |
pa = pa2 + n2; |
210 |
|
for (i = xcbeams; i--; ) { |
211 |
< |
pa[n+i].hd = cbeam[ncbeams+i].hd; |
212 |
< |
pa[n+i].bi = cbeam[ncbeams+i].bi; |
213 |
< |
pa[n+i].nr = 0; |
211 |
> |
pp = pa + n++; |
212 |
> |
pp->hd = cbeam[ncbeams+i].hd; |
213 |
> |
pp->bi = cbeam[ncbeams+i].bi; |
214 |
> |
pp->nr = 0; |
215 |
> |
pp->nc = 0; |
216 |
|
} |
217 |
< |
n += xcbeams; |
218 |
< |
xcbeams = 0; /* delete orphans */ |
219 |
< |
serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); |
220 |
< |
free((char *)pa); |
217 |
> |
if (n) /* adjust the set */ |
218 |
> |
serv_request(DR_ADJSET, n*sizeof(PACKHEAD), (char *)pa); |
219 |
> |
if (n2) /* make secondary additions */ |
220 |
> |
serv_request(DR_ADDSET, n2*sizeof(PACKHEAD), (char *)pa2); |
221 |
> |
xcbeams = 0; /* clean up */ |
222 |
> |
free((char *)pa2); |
223 |
|
return; |
224 |
|
memerr: |
225 |
|
error(SYSTEM, "out of memory in cbeamadj"); |
246 |
|
pa[i].bi = bl[i].bi; |
247 |
|
pa[i].nr = v==NULL ? 0 : |
248 |
|
npixels(v, hr, vr, hdlist[bl[i].hd], bl[i].bi); |
249 |
+ |
pa[i].nc = 0; |
250 |
|
} |
251 |
|
serv_request(op, n*sizeof(PACKHEAD), (char *)pa); |
252 |
|
free((char *)pa); |
396 |
|
hdworld(org, hp, cgp); |
397 |
|
/* compute direction to voxel center */ |
398 |
|
for (i = 3; i--; ) |
399 |
< |
vgp[i] = voxel[cap->vi].i[i] + 0.5; |
399 |
> |
vgp[i] = voxel[cap->vi].i[i] + .5; |
400 |
|
hdworld(vc, hp, vgp); |
401 |
|
for (i = 3; i--; ) |
402 |
|
vc[i] -= org[i]; |
404 |
|
axmax = -1; avmax = 0; |
405 |
|
for (i = 3; i--; ) { |
406 |
|
d = vgp[i] - cgp[i]; |
407 |
< |
if (d < 0) d = -d; |
407 |
> |
if (d < 0.) d = -d; |
408 |
|
if (d > avmax) { |
409 |
|
avmax = d; |
410 |
|
axmax = i; |
411 |
|
} |
412 |
|
} |
413 |
|
#ifdef DEBUG |
414 |
< |
if (axmax < 0) |
414 |
> |
if (axmax < 0.) |
415 |
|
error(CONSISTENCY, "botched axis computation in docell"); |
416 |
|
#endif |
417 |
|
/* compute offset vectors */ |
419 |
|
for (i = 3; i--; ) |
420 |
|
v1[i] = hp->xv[j][i] * d; |
421 |
|
d = 0.5/hp->grid[j=(axmax+2)%3]; |
422 |
< |
if (DOT(hp->wn[axmax], vc) < 0) |
422 |
> |
if (DOT(hp->wn[axmax], vc) < 0.) |
423 |
|
d = -d; /* reverse vertex ordering */ |
424 |
|
for (i = 3; i--; ) |
425 |
|
v2[i] = hp->xv[j][i] * d; |
469 |
|
ngcp = ngcl = getviewcells(&ncnt, hdlist[voxel[voxi].hd], vnew); |
470 |
|
/* set up actions */ |
471 |
|
oca.vi = nca.vi = voxi; |
443 |
– |
oca.rev = nca.rev = 0; |
472 |
|
oca.add = 0; nca.add = 1; |
473 |
|
if ((oca.rev = ocnt < 0)) |
474 |
|
ocnt = -ocnt; |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
+ |
int |
502 |
|
beam_sync() /* synchronize beams on server */ |
503 |
|
{ |
504 |
|
cbeamop(DR_NEWSET, cbeam, ncbeams, &odev.v, odev.hres, odev.vres); |
505 |
+ |
return(ncbeams); |
506 |
|
} |
507 |
|
|
508 |
|
|
513 |
|
VOXL vlnew[8]; |
514 |
|
int n, comn; |
515 |
|
|
516 |
< |
if (!vn->type) { /* clear our beam list */ |
516 |
> |
if (vn == NULL || !vn->type) { /* clear our beam list */ |
517 |
|
set_voxels(vlnew, 0); |
518 |
|
cbeamop(DR_DELSET, cbeam, ncbeams, NULL, 0, 0); |
519 |
|
ncbeams = 0; |
520 |
< |
copystruct(&dvw, vn); |
520 |
> |
dvw.type = 0; |
521 |
|
return(1); |
522 |
|
} |
523 |
|
/* find our new voxels */ |