129 |
|
float *vptr = st->u.v; |
130 |
|
int i; |
131 |
|
|
132 |
< |
for (i = st->ndim; i--; skipsiz <<= st->log2GR) |
133 |
< |
if (1<<i & n) |
132 |
> |
for (i = 0; i < st->ndim; skipsiz <<= st->log2GR) |
133 |
> |
if (1<<i++ & n) |
134 |
|
vptr += skipsiz >> 1; |
135 |
|
return vptr; |
136 |
|
} |
151 |
|
return NULL; /* propogate error up call stack */ |
152 |
|
match &= (st->u.t[n]->log2GR == st->u.t[0]->log2GR); |
153 |
|
} |
154 |
< |
if (match && st->u.t[0]->log2GR >= 0) { |
155 |
< |
SDNode *stn = SDnewNode(st->ndim, st->u.t[0]->log2GR + 1); |
154 |
> |
if (match && (match = st->u.t[0]->log2GR) >= 0) { |
155 |
> |
SDNode *stn = SDnewNode(st->ndim, match + 1); |
156 |
|
if (stn == NULL) /* out of memory? */ |
157 |
|
return st; |
158 |
|
/* transfer values to new grid */ |
159 |
|
for (n = 1 << st->ndim; n--; ) |
160 |
|
fill_grid_branch(grid_branch_start(stn, n), |
161 |
< |
st->u.t[n]->u.v, st->ndim, st->log2GR); |
161 |
> |
st->u.t[n]->u.v, stn->ndim, stn->log2GR); |
162 |
|
SDfreeTre(st); /* free old tree */ |
163 |
|
st = stn; /* return new one */ |
164 |
|
} |
187 |
|
static double |
188 |
|
SDiterSum(const float *va, int nd, int shft, const int *imin, const int *imax) |
189 |
|
{ |
190 |
< |
const unsigned skipsiz = 1 << nd*shft; |
190 |
> |
const unsigned skipsiz = 1 << --nd*shft; |
191 |
|
double sum = .0; |
192 |
|
int i; |
193 |
|
|
196 |
|
sum += va[i]; |
197 |
|
else |
198 |
|
for (i = *imin; i < *imax; i++) |
199 |
< |
sum += SDiterSum(va + i*skipsiz, |
200 |
< |
nd-1, shft, imin+1, imax+1); |
199 |
> |
sum += SDiterSum(va + i*skipsiz, nd, shft, imin+1, imax+1); |
200 |
|
return sum; |
201 |
|
} |
202 |
|
|
483 |
|
/* find Hilbert entry index */ |
484 |
|
bmin[0] = cmin[0]*(double)iwmax + .5; |
485 |
|
bmin[1] = cmin[1]*(double)iwmax + .5; |
486 |
< |
bmax[0] = bmin[0] + wid; |
487 |
< |
bmax[1] = bmin[1] + wid; |
486 |
> |
bmax[0] = bmin[0] + wid-1; |
487 |
> |
bmax[1] = bmin[1] + wid-1; |
488 |
|
hilbert_box_vtx(2, sizeof(bitmask_t), iwbits, 1, bmin, bmax); |
489 |
|
sp->darr[sp->alen].hent = hilbert_c2i(2, iwbits, bmin); |
490 |
|
sp->darr[sp->alen].wid = wid; |
497 |
|
static int |
498 |
|
sscmp(const void *p1, const void *p2) |
499 |
|
{ |
500 |
< |
return (int)((*(const struct outdir_s *)p1).hent - |
501 |
< |
(*(const struct outdir_s *)p2).hent); |
500 |
> |
unsigned h1 = (*(const struct outdir_s *)p1).hent; |
501 |
> |
unsigned h2 = (*(const struct outdir_s *)p2).hent; |
502 |
> |
|
503 |
> |
if (h1 > h2) |
504 |
> |
return 1; |
505 |
> |
if (h1 < h2) |
506 |
> |
return -1; |
507 |
> |
return 0; |
508 |
|
} |
509 |
|
|
510 |
|
/* Create a new cumulative distribution for the given input direction */ |
717 |
|
return **spp; |
718 |
|
} |
719 |
|
|
720 |
+ |
#define eat_token(spp,c) (next_token(spp)==(c) ? *(*(spp))++ : 0) |
721 |
+ |
|
722 |
|
/* Count words from this point in string to '}' */ |
723 |
|
static int |
724 |
|
count_values(char *cp) |
725 |
|
{ |
726 |
|
int n = 0; |
727 |
|
|
728 |
< |
while (next_token(&cp) != '}') { |
729 |
< |
if (*cp == '{') |
730 |
< |
return -1; |
731 |
< |
while (*cp && !isspace(*cp)) |
725 |
< |
++cp; |
728 |
> |
while (next_token(&cp) != '}' && *cp) { |
729 |
> |
while (!isspace(*cp) & (*cp != ',') & (*cp != '}')) |
730 |
> |
if (!*++cp) |
731 |
> |
break; |
732 |
|
++n; |
733 |
< |
cp += (next_token(&cp) == ','); |
733 |
> |
eat_token(&cp, ','); |
734 |
|
} |
735 |
|
return n; |
736 |
|
} |
745 |
|
while (n-- > 0 && (svnext = fskip(*spp)) != NULL) { |
746 |
|
*v++ = atof(*spp); |
747 |
|
*spp = svnext; |
748 |
< |
*spp += (next_token(spp) == ','); |
748 |
> |
eat_token(spp, ','); |
749 |
|
} |
750 |
|
return v - va; |
751 |
|
} |
757 |
|
SDNode *st; |
758 |
|
int n; |
759 |
|
|
760 |
< |
if (next_token(spp) != '{') { |
760 |
> |
if (!eat_token(spp, '{')) { |
761 |
|
strcpy(SDerrorDetail, "Missing '{' in tensor tree"); |
762 |
|
return NULL; |
763 |
|
} |
758 |
– |
++*spp; /* in tree, now */ |
764 |
|
if (next_token(spp) == '{') { /* tree branches */ |
765 |
|
st = SDnewNode(nd, -1); |
766 |
|
if (st == NULL) |
773 |
|
} else { /* else load value grid */ |
774 |
|
int bsiz; |
775 |
|
n = count_values(*spp); /* see how big the grid is */ |
771 |
– |
if (n <= 0) { |
772 |
– |
strcpy(SDerrorDetail, "Bad tensor tree data"); |
773 |
– |
return NULL; |
774 |
– |
} |
776 |
|
for (bsiz = 0; bsiz < 8*sizeof(size_t)-1; bsiz += nd) |
777 |
|
if (1<<bsiz == n) |
778 |
|
break; |
789 |
|
return NULL; |
790 |
|
} |
791 |
|
} |
792 |
< |
if (next_token(spp) != '}') { |
792 |
> |
if (!eat_token(spp, '}')) { |
793 |
|
strcpy(SDerrorDetail, "Missing '}' in tensor tree"); |
794 |
|
SDfreeTre(st); |
795 |
|
return NULL; |
796 |
|
} |
797 |
< |
++*spp; /* walk past close and return */ |
797 |
< |
*spp += (next_token(spp) == ','); |
797 |
> |
eat_token(spp, ','); |
798 |
|
return st; |
799 |
|
} |
800 |
|
|
922 |
|
static float |
923 |
|
SDgetTreMin(const SDNode *st) |
924 |
|
{ |
925 |
< |
float vmin = 1./M_PI; |
925 |
> |
float vmin = FHUGE; |
926 |
|
int n; |
927 |
|
|
928 |
|
if (st->log2GR < 0) { |
960 |
|
{ |
961 |
|
float vmin; |
962 |
|
/* be sure to skip unused portion */ |
963 |
< |
if ((st->ndim == 3) & (st->log2GR < 0)) { |
964 |
< |
float v; |
965 |
< |
int i; |
963 |
> |
if (st->ndim == 3) { |
964 |
> |
int n; |
965 |
|
vmin = 1./M_PI; |
966 |
< |
for (i = 0; i < 4; i++) { |
967 |
< |
v = SDgetTreMin(st->u.t[i]); |
968 |
< |
if (v < vmin) |
969 |
< |
vmin = v; |
970 |
< |
} |
966 |
> |
if (st->log2GR < 0) { |
967 |
> |
for (n = 0; n < 4; n++) { |
968 |
> |
float v = SDgetTreMin(st->u.t[n]); |
969 |
> |
if (v < vmin) |
970 |
> |
vmin = v; |
971 |
> |
} |
972 |
> |
} else if (st->log2GR) { |
973 |
> |
for (n = 1 << (3*st->log2GR - 1); n--; ) |
974 |
> |
if (st->u.v[n] < vmin) |
975 |
> |
vmin = st->u.v[n]; |
976 |
> |
} else |
977 |
> |
vmin = st->u.v[0]; |
978 |
|
} else /* anisotropic covers entire tree */ |
979 |
|
vmin = SDgetTreMin(st); |
980 |
|
|
998 |
|
return; |
999 |
|
} |
1000 |
|
dv->spec = df->comp[0].cspec[0]; |
1001 |
< |
dv->cieY = subtract_min((*(SDTre *)df->comp[n].dist).st); |
1001 |
> |
dv->cieY = subtract_min((*(SDTre *)df->comp[0].dist).st); |
1002 |
|
/* in case of multiple components */ |
1003 |
|
for (n = df->ncomp; --n; ) { |
1004 |
|
double ymin = subtract_min((*(SDTre *)df->comp[n].dist).st); |