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 |
+ |
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 |
|
return (int)((*(const struct outdir_s *)p1).hent - |
510 |
|
(*(const struct outdir_s *)p2).hent); |
511 |
+ |
*/ |
512 |
|
} |
513 |
|
|
514 |
|
/* Create a new cumulative distribution for the given input direction */ |
721 |
|
return **spp; |
722 |
|
} |
723 |
|
|
724 |
+ |
#define eat_token(spp,c) (next_token(spp)==(c) ? *(*(spp))++ : 0) |
725 |
+ |
|
726 |
|
/* Count words from this point in string to '}' */ |
727 |
|
static int |
728 |
|
count_values(char *cp) |
729 |
|
{ |
730 |
|
int n = 0; |
731 |
|
|
732 |
< |
while (next_token(&cp) != '}') { |
732 |
> |
while (next_token(&cp) != '}' && *cp) { |
733 |
|
if (*cp == '{') |
734 |
|
return -1; |
735 |
< |
while (*cp && !isspace(*cp)) |
735 |
> |
while (*cp && (*cp != ',') & (*cp != '}') & !isspace(*cp)) |
736 |
|
++cp; |
737 |
|
++n; |
738 |
< |
cp += (next_token(&cp) == ','); |
738 |
> |
eat_token(&cp, ','); |
739 |
|
} |
740 |
|
return n; |
741 |
|
} |
750 |
|
while (n-- > 0 && (svnext = fskip(*spp)) != NULL) { |
751 |
|
*v++ = atof(*spp); |
752 |
|
*spp = svnext; |
753 |
< |
*spp += (next_token(spp) == ','); |
753 |
> |
eat_token(spp, ','); |
754 |
|
} |
755 |
|
return v - va; |
756 |
|
} |
762 |
|
SDNode *st; |
763 |
|
int n; |
764 |
|
|
765 |
< |
if (next_token(spp) != '{') { |
765 |
> |
if (!eat_token(spp, '{')) { |
766 |
|
strcpy(SDerrorDetail, "Missing '{' in tensor tree"); |
767 |
|
return NULL; |
768 |
|
} |
758 |
– |
++*spp; /* in tree, now */ |
769 |
|
if (next_token(spp) == '{') { /* tree branches */ |
770 |
|
st = SDnewNode(nd, -1); |
771 |
|
if (st == NULL) |
798 |
|
return NULL; |
799 |
|
} |
800 |
|
} |
801 |
< |
if (next_token(spp) != '}') { |
801 |
> |
if (!eat_token(spp, '}')) { |
802 |
|
strcpy(SDerrorDetail, "Missing '}' in tensor tree"); |
803 |
|
SDfreeTre(st); |
804 |
|
return NULL; |
805 |
|
} |
806 |
< |
++*spp; /* walk past close and return */ |
797 |
< |
*spp += (next_token(spp) == ','); |
806 |
> |
eat_token(spp, ','); |
807 |
|
return st; |
808 |
|
} |
809 |
|
|
931 |
|
static float |
932 |
|
SDgetTreMin(const SDNode *st) |
933 |
|
{ |
934 |
< |
float vmin = 1./M_PI; |
934 |
> |
float vmin = FHUGE; |
935 |
|
int n; |
936 |
|
|
937 |
|
if (st->log2GR < 0) { |
969 |
|
{ |
970 |
|
float vmin; |
971 |
|
/* be sure to skip unused portion */ |
972 |
< |
if ((st->ndim == 3) & (st->log2GR < 0)) { |
973 |
< |
float v; |
965 |
< |
int i; |
972 |
> |
if (st->ndim == 3) { |
973 |
> |
int n; |
974 |
|
vmin = 1./M_PI; |
975 |
< |
for (i = 0; i < 4; i++) { |
976 |
< |
v = SDgetTreMin(st->u.t[i]); |
977 |
< |
if (v < vmin) |
978 |
< |
vmin = v; |
979 |
< |
} |
975 |
> |
if (st->log2GR < 0) { |
976 |
> |
for (n = 0; n < 4; n++) { |
977 |
> |
float v = SDgetTreMin(st->u.t[n]); |
978 |
> |
if (v < vmin) |
979 |
> |
vmin = v; |
980 |
> |
} |
981 |
> |
} else if (st->log2GR) { |
982 |
> |
for (n = 1 << (3*st->log2GR - 1); n--; ) |
983 |
> |
if (st->u.v[n] < vmin) |
984 |
> |
vmin = st->u.v[n]; |
985 |
> |
} else |
986 |
> |
vmin = st->u.v[0]; |
987 |
|
} else /* anisotropic covers entire tree */ |
988 |
|
vmin = SDgetTreMin(st); |
989 |
|
|
1007 |
|
return; |
1008 |
|
} |
1009 |
|
dv->spec = df->comp[0].cspec[0]; |
1010 |
< |
dv->cieY = subtract_min((*(SDTre *)df->comp[n].dist).st); |
1010 |
> |
dv->cieY = subtract_min((*(SDTre *)df->comp[0].dist).st); |
1011 |
|
/* in case of multiple components */ |
1012 |
|
for (n = df->ncomp; --n; ) { |
1013 |
|
double ymin = subtract_min((*(SDTre *)df->comp[n].dist).st); |