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); |