122 |
return 0; |
return 0; |
123 |
} |
} |
124 |
} |
} |
125 |
if (NrrdTypeInfo[nin->type].size == 0) { |
if (NrrdTypeInfo[nin->type].sizeb == 0) { |
126 |
Diderot_Error (wrld, "bogus element type %d in nrrd\n", nin->type); |
Diderot_Error (wrld, "bogus element type %d in nrrd\n", nin->type); |
127 |
return 0; |
return 0; |
128 |
} |
} |
155 |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
156 |
|
|
157 |
// initialize the sequence from the nrrd |
// initialize the sequence from the nrrd |
158 |
if (! nrrdTypeInfo[nin->type].isFloat || (nrrdTypeInfo[nin->type].size != SIZEOF_DIDEROT_REAL)) { |
if (! NrrdTypeInfo[nin->type].isFloat || (NrrdTypeInfo[nin->type].sizeb != SIZEOF_DIDEROT_REAL)) { |
159 |
// this is the slow path; we have to convert values as they are copied from the nrrd |
// this is the slow path; we have to convert values as they are copied from the nrrd |
160 |
#if defined(DIDEROT_DOUBLE_PRECISION) |
#if defined(DIDEROT_DOUBLE_PRECISION) |
161 |
double (*loadFn)(const void *) = nrrdDLoad[nin->type]; |
double (*loadFn)(const void *) = nrrdDLoad[nin->type]; |
164 |
#endif |
#endif |
165 |
Diderot_real_t *dst = (Diderot_real_t *)seq->data; |
Diderot_real_t *dst = (Diderot_real_t *)seq->data; |
166 |
char *src = (char *)nin->data; |
char *src = (char *)nin->data; |
167 |
size_t srcElemSz = NrrdTypeInfo[nin->type].size; |
size_t srcElemSz = NrrdTypeInfo[nin->type].sizeb; |
168 |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
169 |
*dst++ = loadFn(src); |
*dst++ = loadFn(src); |
170 |
src += srcElemSz; |
src += srcElemSz; |
198 |
if (nValuesPerElem == 0) |
if (nValuesPerElem == 0) |
199 |
return (Diderot_DynSeq_t *)0; |
return (Diderot_DynSeq_t *)0; |
200 |
|
|
201 |
if (nrrdTypeInfo[nin->type].isFloat) { |
if (NrrdTypeInfo[nin->type].isFloat) { |
202 |
Diderot_Error (wrld, "expected integer element type for int sequence, but found %d\n", nin->type); |
Diderot_Error (wrld, "expected integer element type for int sequence, but found %d\n", nin->type); |
203 |
return 0; |
return 0; |
204 |
} |
} |
210 |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
211 |
|
|
212 |
// initialize the sequence from the nrrd |
// initialize the sequence from the nrrd |
213 |
if (nrrdTypeInfo[nin->type].size != SIZEOF_DIDEROT_INT) { |
if (NrrdTypeInfo[nin->type].sizeb != SIZEOF_DIDEROT_INT) { |
214 |
// this is the slow path; we have to convert values as they are copied from the nrrd |
// this is the slow path; we have to convert values as they are copied from the nrrd |
215 |
int (*loadFn)(const void *) = nrrdILoad[nin->type]; |
int (*loadFn)(const void *) = nrrdILoad[nin->type]; |
216 |
Diderot_int_t *dst = (Diderot_int_t *)seq->data; |
Diderot_int_t *dst = (Diderot_int_t *)seq->data; |
217 |
char *src = (char *)nin->data; |
char *src = (char *)nin->data; |
218 |
size_t srcElemSz = NrrdTypeInfo[nin->type].size; |
size_t srcElemSz = NrrdTypeInfo[nin->type].sizeb; |
219 |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
220 |
*dst++ = loadFn(src); |
*dst++ = loadFn(src); |
221 |
src += srcElemSz; |
src += srcElemSz; |
244 |
unsigned int *dims) |
unsigned int *dims) |
245 |
{ |
{ |
246 |
unsigned int nValuesPerElem = CheckNrrd(wrld, nin, nDims, dims); |
unsigned int nValuesPerElem = CheckNrrd(wrld, nin, nDims, dims); |
247 |
size_t elemSz = SIZEOF_DIDEROT_BOOL * nValuesPerElem; |
size_t elemSz = sizeof(bool) * nValuesPerElem; |
248 |
|
|
249 |
if (nValuesPerElem == 0) |
if (nValuesPerElem == 0) |
250 |
return (Diderot_DynSeq_t *)0; |
return (Diderot_DynSeq_t *)0; |
251 |
|
|
252 |
if (nrrdTypeInfo[nin->type].isFloat) { |
if (NrrdTypeInfo[nin->type].isFloat) { |
253 |
Diderot_Error (wrld, "expected integer element type for bool sequence, but found %d\n", nin->type); |
Diderot_Error (wrld, "expected integer element type for bool sequence, but found %d\n", nin->type); |
254 |
return 0; |
return 0; |
255 |
} |
} |
261 |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
Diderot_DynSeq_t *seq = Diderot_DynSeqAlloc(elemSz, nElems); |
262 |
|
|
263 |
// initialize the sequence from the nrrd |
// initialize the sequence from the nrrd |
264 |
if (nrrdTypeInfo[nin->type].size != sizeof(bool)) { |
if (NrrdTypeInfo[nin->type].sizeb != sizeof(bool)) { |
265 |
// this is the slow path; we have to convert values as they are copied from the nrrd |
// this is the slow path; we have to convert values as they are copied from the nrrd |
266 |
int (*loadFn)(const void *) = nrrdILoad[nin->type]; |
int (*loadFn)(const void *) = nrrdILoad[nin->type]; |
267 |
bool *dst = (bool *)seq->data; |
bool *dst = (bool *)seq->data; |
268 |
char *src = (char *)nin->data; |
char *src = (char *)nin->data; |
269 |
size_t srcElemSz = NrrdTypeInfo[nin->type].size; |
size_t srcElemSz = NrrdTypeInfo[nin->type].sizeb; |
270 |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
for (size_t i = 0; i < nElems * nValuesPerElem; i++) { |
271 |
*dst++ = loadFn(src) ? true : false; |
*dst++ = loadFn(src) ? true : false; |
272 |
src += srcElemSz; |
src += srcElemSz; |