61 |
|
if (lg < 0) { |
62 |
|
st = (SDNode *)malloc(sizeof(SDNode) + |
63 |
|
sizeof(st->u.t[0])*((1<<nd) - 1)); |
64 |
< |
if (st != NULL) |
65 |
< |
memset(st->u.t, 0, sizeof(st->u.t[0])<<nd); |
66 |
< |
} else |
67 |
< |
st = (SDNode *)malloc(sizeof(SDNode) + |
68 |
< |
sizeof(st->u.v[0])*((1 << nd*lg) - 1)); |
69 |
< |
|
70 |
< |
if (st == NULL) { |
71 |
< |
if (lg < 0) |
64 |
> |
if (st == NULL) { |
65 |
|
sprintf(SDerrorDetail, |
66 |
|
"Cannot allocate %d branch BSDF tree", 1<<nd); |
67 |
< |
else |
67 |
> |
return NULL; |
68 |
> |
} |
69 |
> |
memset(st->u.t, 0, sizeof(st->u.t[0])<<nd); |
70 |
> |
} else { |
71 |
> |
st = (SDNode *)malloc(sizeof(SDNode) + |
72 |
> |
sizeof(st->u.v[0])*((1 << nd*lg) - 1)); |
73 |
> |
if (st == NULL) { |
74 |
|
sprintf(SDerrorDetail, |
75 |
|
"Cannot allocate %d BSDF leaves", 1 << nd*lg); |
76 |
< |
return NULL; |
76 |
> |
return NULL; |
77 |
> |
} |
78 |
|
} |
79 |
|
st->ndim = nd; |
80 |
|
st->log2GR = lg; |
85 |
|
static void |
86 |
|
SDfreeTre(SDNode *st) |
87 |
|
{ |
88 |
< |
int i; |
88 |
> |
int n; |
89 |
|
|
90 |
|
if (st == NULL) |
91 |
|
return; |
92 |
< |
for (i = (st->log2GR < 0) << st->ndim; i--; ) |
93 |
< |
SDfreeTre(st->u.t[i]); |
92 |
> |
for (n = (st->log2GR < 0) << st->ndim; n--; ) |
93 |
> |
SDfreeTre(st->u.t[n]); |
94 |
|
free((void *)st); |
95 |
|
} |
96 |
|
|
473 |
|
sp->wmax = wid; |
474 |
|
if (sp->alen >= sp->nall) { /* need more space? */ |
475 |
|
struct outdir_s *ndarr; |
476 |
< |
sp->nall += 8192; |
476 |
> |
sp->nall += 1024; |
477 |
|
ndarr = (struct outdir_s *)realloc(sp->darr, |
478 |
|
sizeof(struct outdir_s)*sp->nall); |
479 |
< |
if (ndarr == NULL) |
479 |
> |
if (ndarr == NULL) { |
480 |
> |
sprintf(SDerrorDetail, |
481 |
> |
"Cannot grow scaffold to %u entries", sp->nall); |
482 |
|
return -1; /* abort build */ |
483 |
+ |
} |
484 |
|
sp->darr = ndarr; |
485 |
|
} |
486 |
|
/* find Hilbert entry index */ |
508 |
|
if (h1 < h2) |
509 |
|
return -1; |
510 |
|
return 0; |
508 |
– |
/* |
509 |
– |
return (int)((*(const struct outdir_s *)p1).hent - |
510 |
– |
(*(const struct outdir_s *)p2).hent); |
511 |
– |
*/ |
511 |
|
} |
512 |
|
|
513 |
|
/* Create a new cumulative distribution for the given input direction */ |
524 |
|
myScaffold.wmax = 0; |
525 |
|
myScaffold.nic = sdt->st->ndim - 2; |
526 |
|
myScaffold.alen = 0; |
527 |
< |
myScaffold.nall = 8192; |
527 |
> |
myScaffold.nall = 512; |
528 |
|
myScaffold.darr = (struct outdir_s *)malloc(sizeof(struct outdir_s) * |
529 |
|
myScaffold.nall); |
530 |
|
if (myScaffold.darr == NULL) |
539 |
|
cd = (SDTreCDst *)malloc(sizeof(SDTreCDst) + |
540 |
|
sizeof(cd->carr[0])*myScaffold.alen); |
541 |
|
if (cd == NULL) { |
542 |
+ |
sprintf(SDerrorDetail, |
543 |
+ |
"Cannot allocate %u entry cumulative distribution", |
544 |
+ |
myScaffold.alen); |
545 |
|
free(myScaffold.darr); |
546 |
|
return NULL; |
547 |
|
} |
723 |
|
return **spp; |
724 |
|
} |
725 |
|
|
726 |
< |
#define eat_token(spp,c) (next_token(spp)==(c) ? *(*(spp))++ : 0) |
726 |
> |
/* Advance pointer past matching token (or any token if c==0) */ |
727 |
> |
#define eat_token(spp,c) (next_token(spp)==(c) ^ !(c) ? *(*(spp))++ : 0) |
728 |
|
|
729 |
|
/* Count words from this point in string to '}' */ |
730 |
|
static int |
733 |
|
int n = 0; |
734 |
|
|
735 |
|
while (next_token(&cp) != '}' && *cp) { |
736 |
< |
if (*cp == '{') |
737 |
< |
return -1; |
738 |
< |
while (*cp && (*cp != ',') & (*cp != '}') & !isspace(*cp)) |
736 |
< |
++cp; |
736 |
> |
while (!isspace(*cp) & (*cp != ',') & (*cp != '}')) |
737 |
> |
if (!*++cp) |
738 |
> |
break; |
739 |
|
++n; |
740 |
|
eat_token(&cp, ','); |
741 |
|
} |
780 |
|
} else { /* else load value grid */ |
781 |
|
int bsiz; |
782 |
|
n = count_values(*spp); /* see how big the grid is */ |
781 |
– |
if (n <= 0) { |
782 |
– |
strcpy(SDerrorDetail, "Bad tensor tree data"); |
783 |
– |
return NULL; |
784 |
– |
} |
783 |
|
for (bsiz = 0; bsiz < 8*sizeof(size_t)-1; bsiz += nd) |
784 |
|
if (1<<bsiz == n) |
785 |
|
break; |