9 |
|
*/ |
10 |
|
|
11 |
|
#include "rholo.h" |
12 |
+ |
#include "view.h" |
13 |
|
#include <sys/types.h> |
14 |
|
|
15 |
|
#ifndef NFRAG2CHUNK |
93 |
|
n = b->nrm; |
94 |
|
if (p == NULL) p = (PACKHEAD *)malloc(packsiz(n)); |
95 |
|
else p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
96 |
< |
if (p == NULL) |
96 |
< |
error(SYSTEM, "out of memory in dispbeam"); |
96 |
> |
CHECK(p==NULL, SYSTEM, "out of memory in dispbeam"); |
97 |
|
} |
98 |
|
/* assign packet fields */ |
99 |
|
bcopy((char *)hdbray(b), (char *)packra(p), b->nrm*sizeof(RAYVAL)); |
135 |
|
complist[i].nr += csm->nr; |
136 |
|
csm->nr = 0; |
137 |
|
break; |
138 |
+ |
case BS_MAX: /* maximum of counts */ |
139 |
+ |
if (csm->nr > complist[i].nr) |
140 |
+ |
complist[i].nr = csm->nr; |
141 |
+ |
csm->nr = 0; |
142 |
+ |
break; |
143 |
|
case BS_ADJ: /* reset count */ |
144 |
|
complist[i].nr = csm->nr; |
145 |
|
csm->nr = 0; |
173 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
174 |
|
break; |
175 |
|
case BS_ADD: /* add to computation set */ |
176 |
+ |
case BS_MAX: /* maximum of quantities */ |
177 |
|
case BS_ADJ: /* adjust set quantities */ |
178 |
|
if (nents <= 0) |
179 |
|
return; |
183 |
|
for (i = nents, csm = clist; i-- && csm->nr > csm->nc; csm++) |
184 |
|
; |
185 |
|
n = csm - clist; |
186 |
< |
if (op == BS_ADJ) { /* don't regenerate adjusted beams */ |
186 |
> |
if (op != BS_ADD) { /* don't regenerate adjusted beams */ |
187 |
|
for (++i; i-- && csm->nr > 0; csm++) |
188 |
|
; |
189 |
|
nents = csm - clist; |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
< |
init_global() /* initialize global ray computation */ |
265 |
> |
ambient_list() /* compute ambient beam list */ |
266 |
|
{ |
267 |
|
long wtotal = 0; |
268 |
|
double frac; |
269 |
|
int i; |
270 |
|
register int j, k; |
271 |
< |
/* free old list and empty queue */ |
266 |
< |
if (complen > 0) { |
267 |
< |
free((char *)complist); |
268 |
< |
done_packets(flush_queue()); |
269 |
< |
} |
270 |
< |
/* reseed random number generator */ |
271 |
< |
srandom(time(NULL)); |
272 |
< |
/* allocate beam list */ |
271 |
> |
|
272 |
|
complen = 0; |
273 |
|
for (j = 0; hdlist[j] != NULL; j++) |
274 |
|
complen += nbeams(hdlist[j]); |
275 |
|
complist = (PACKHEAD *)malloc(complen*sizeof(PACKHEAD)); |
276 |
< |
if (complist == NULL) |
278 |
< |
error(SYSTEM, "out of memory in init_global"); |
276 |
> |
CHECK(complist==NULL, SYSTEM, "out of memory in ambient_list"); |
277 |
|
/* compute beam weights */ |
278 |
|
k = 0; |
279 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
288 |
|
wtotal += complist[k++].nr; |
289 |
|
} |
290 |
|
} |
291 |
< |
/* adjust weights */ |
291 |
> |
/* adjust sample weights */ |
292 |
|
if (vdef(DISKSPACE)) |
293 |
< |
frac = 1024.*1024.*vflt(DISKSPACE) / (wtotal*sizeof(RAYVAL)); |
293 |
> |
frac = 1024.*1024.*vflt(DISKSPACE) / |
294 |
> |
(wtotal*sizeof(RAYVAL)); |
295 |
|
else |
296 |
|
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
297 |
< |
while (k--) |
298 |
< |
complist[k].nr = frac*complist[k].nr + 0.5; |
299 |
< |
listpos = 0; lastin = -1; /* perform initial sort */ |
300 |
< |
sortcomplist(); |
297 |
> |
if (frac > 1.11 || frac < 0.9) |
298 |
> |
for (k = complen; k--; ) |
299 |
> |
complist[k].nr = frac*complist[k].nr + 0.5; |
300 |
> |
listpos = 0; lastin = -1; /* flag initial sort */ |
301 |
> |
} |
302 |
> |
|
303 |
> |
|
304 |
> |
view_list(fp) /* assign beam priority from view list */ |
305 |
> |
FILE *fp; |
306 |
> |
{ |
307 |
> |
double pa = 1.; |
308 |
> |
VIEW curview; |
309 |
> |
int xr, yr; |
310 |
> |
char *err; |
311 |
> |
BEAMLIST blist; |
312 |
> |
|
313 |
> |
copystruct(&curview, &stdview); |
314 |
> |
while (nextview(&curview, fp) != EOF) { |
315 |
> |
if ((err = setview(&curview)) != NULL) { |
316 |
> |
error(WARNING, err); |
317 |
> |
continue; |
318 |
> |
} |
319 |
> |
xr = yr = 1024; |
320 |
> |
normaspect(viewaspect(&curview), &pa, &xr, &yr); |
321 |
> |
viewbeams(&curview, xr, yr, &blist); |
322 |
> |
bundle_set(BS_MAX, blist.bl, blist.nb); |
323 |
> |
free((char *)blist.bl); |
324 |
> |
} |
325 |
> |
} |
326 |
> |
|
327 |
> |
|
328 |
> |
init_global() /* initialize global ray computation */ |
329 |
> |
{ |
330 |
> |
register int k; |
331 |
> |
/* free old list and empty queue */ |
332 |
> |
if (complen > 0) { |
333 |
> |
free((char *)complist); |
334 |
> |
done_packets(flush_queue()); |
335 |
> |
} |
336 |
> |
/* reseed random number generator */ |
337 |
> |
srandom(time(NULL)); |
338 |
> |
/* allocate beam list */ |
339 |
> |
if (readinp) |
340 |
> |
view_list(stdin); |
341 |
> |
else |
342 |
> |
ambient_list(); |
343 |
|
/* no view vicinity */ |
344 |
|
myeye.rng = 0; |
345 |
|
} |
392 |
|
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
393 |
|
else if (listpos) { /* else sort and merge sublist */ |
394 |
|
list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); |
395 |
< |
if (list2 == NULL) |
355 |
< |
error(SYSTEM, "out of memory in sortcomplist"); |
395 |
> |
CHECK(list2==NULL, SYSTEM, "out of memory in sortcomplist"); |
396 |
|
bcopy((char *)complist,(char *)list2,listpos*sizeof(PACKHEAD)); |
397 |
|
qsort((char *)list2, listpos, sizeof(PACKHEAD), beamcmp); |
398 |
|
mergeclists(complist, list2, listpos, |