int limnEnvMapCheck(Nrrd *envMap) { char me[]="limnEnvMapCheck", err[BIFF_STRLEN]; if (nrrdCheck(envMap)) { sprintf(err, "%s: basic nrrd validity check failed", me); biffMove(LIMN, err, NRRD); return 1; } if (!(nrrdTypeFloat == envMap->type)) { sprintf(err, "%s: type should be %s, not %s", me, airEnumStr(nrrdType, nrrdTypeFloat), airEnumStr(nrrdType, envMap->type)); biffAdd(LIMN, err); return 1; } if (!(3 == envMap->dim)) { sprintf(err, "%s: dimension should be 3, not %d", me, envMap->dim); biffAdd(LIMN, err); return 1; } if (!(3 == envMap->axis[0].size && 256 == envMap->axis[1].size && 256 == envMap->axis[2].size)) { sprintf(err, "%s: dimension should be 3x256x256, not " _AIR_SIZE_T_CNV "x" _AIR_SIZE_T_CNV "x" _AIR_SIZE_T_CNV, me, envMap->axis[0].size, envMap->axis[1].size, envMap->axis[2].size); biffAdd(LIMN, err); return 1; } return 0; }
int rvaLattSpecConvert(rvaLattSpec *dst, int latt, const rvaLattSpec *src) { static const char me[]="rvaLattSpecConvert"; int nocando; if (!(dst && src)) { biffAddf(RVA, "%s: got NULL pointer", me); return 1; } if (airEnumValCheck(rvaLatt, latt)) { biffAddf(RVA, "%s: %d not valid %s", me, latt, rvaLatt->name); return 1; } if (latt == src->latt) { rvaLattSpecCopy(dst, src); return 0; } /* else have work to do */ if (lattConv(latt, dst->parm, src->latt, src->parm)) { dst->latt = rvaLattUnknown; biffAddf(RVA, "%s: %s -> %s conversion not implemented", me, airEnumStr(rvaLatt, src->latt), airEnumStr(rvaLatt, latt)); return 1; } /* else no error; we're done */ dst->latt = latt; return 0; }
int ell_Nm_check(Nrrd *mat, int doNrrdCheck) { static const char me[]="ell_Nm_check"; if (doNrrdCheck) { if (nrrdCheck(mat)) { biffMovef(ELL, NRRD, "%s: basic nrrd validity check failed", me); return 1; } } else { if (!mat) { biffAddf(ELL, "%s: got NULL pointer", me); return 1; } } if (!( 2 == mat->dim )) { biffAddf(ELL, "%s: nrrd must be 2-D (not %d-D)", me, mat->dim); return 1; } if (!( nrrdTypeDouble == mat->type )) { biffAddf(ELL, "%s: nrrd must be type %s (not %s)", me, airEnumStr(nrrdType, nrrdTypeDouble), airEnumStr(nrrdType, mat->type)); return 1; } return 0; }
/* ** _nrrdResampleCheckInfo() ** ** checks validity of given NrrdResampleInfo *info: ** - all required parameters exist ** - both min[d] and max[d] for all axes d */ int _nrrdResampleCheckInfo(const Nrrd *nin, const NrrdResampleInfo *info) { char me[] = "_nrrdResampleCheckInfo", err[BIFF_STRLEN]; const NrrdKernel *k; int center, p, np; unsigned int ai, minsmp; if (nrrdTypeBlock == nin->type || nrrdTypeBlock == info->type) { sprintf(err, "%s: can't resample to or from type %s", me, airEnumStr(nrrdType, nrrdTypeBlock)); biffAdd(NRRD, err); return 1; } if (nrrdBoundaryUnknown == info->boundary) { sprintf(err, "%s: didn't set boundary behavior\n", me); biffAdd(NRRD, err); return 1; } if (nrrdBoundaryPad == info->boundary && !AIR_EXISTS(info->padValue)) { sprintf(err, "%s: asked for boundary padding, but no pad value set\n", me); biffAdd(NRRD, err); return 1; } for (ai=0; ai<nin->dim; ai++) { k = info->kernel[ai]; /* we only care about the axes being resampled */ if (!k) continue; if (!(info->samples[ai] > 0)) { sprintf(err, "%s: axis %d # samples (" _AIR_SIZE_T_CNV ") invalid", me, ai, info->samples[ai]); biffAdd(NRRD, err); return 1; } if (!( AIR_EXISTS(nin->axis[ai].min) && AIR_EXISTS(nin->axis[ai].max) )) { sprintf(err, "%s: input nrrd's axis %d min,max have not both been set", me, ai); biffAdd(NRRD, err); return 1; } if (!( AIR_EXISTS(info->min[ai]) && AIR_EXISTS(info->max[ai]) )) { sprintf(err, "%s: info's axis %d min,max not both set", me, ai); biffAdd(NRRD, err); return 1; } np = k->numParm; for (p=0; p<np; p++) { if (!AIR_EXISTS(info->parm[ai][p])) { sprintf(err, "%s: didn't set parameter %d (of %d) for axis %d\n", me, p, np, ai); biffAdd(NRRD, err); return 1; } } center = _nrrdCenter(nin->axis[ai].center); minsmp = nrrdCenterCell == center ? 1 : 2; if (!( nin->axis[ai].size >= minsmp && info->samples[ai] >= minsmp )) { sprintf(err, "%s: axis %d # input samples (" _AIR_SIZE_T_CNV ") or output samples (" _AIR_SIZE_T_CNV ") " " invalid for %s centering", me, ai, nin->axis[ai].size, info->samples[ai], airEnumStr(nrrdCenter, center)); biffAdd(NRRD, err); return 1; } } return 0; }
int _pullContextCheck(pullContext *pctx) { char me[]="_pullContextCheck", err[BIFF_STRLEN]; unsigned int ii, sclvi; int gotIspec, gotConstr; if (!pctx) { sprintf(err, "%s: got NULL pointer", me); biffAdd(PULL, err); return 1; } if (pctx->npos) { if (nrrdCheck(pctx->npos)) { sprintf(err, "%s: got a broken npos", me); biffMove(PULL, err, NRRD); return 1; } if (!( 2 == pctx->npos->dim && 4 == pctx->npos->axis[0].size && (nrrdTypeDouble == pctx->npos->type || nrrdTypeFloat == pctx->npos->type) )) { sprintf(err, "%s: npos not a 2-D 4-by-N array of %s or %s" "(got %u-D %u-by-X of %s)", me, airEnumStr(nrrdType, nrrdTypeFloat), airEnumStr(nrrdType, nrrdTypeDouble), pctx->npos->dim, AIR_CAST(unsigned int, pctx->npos->axis[0].size), airEnumStr(nrrdType, pctx->npos->type)); biffAdd(PULL, err); return 1; } } else {
void _unrrdu_envBool(FILE *file, const char *envKey, int currVal, const char *varName, const char *desc, int columns) { int val, ret; char *envVal; fprintf(file, "%s (bool): ", envKey); ret = nrrdGetenvBool(&val, &envVal, envKey); switch(ret) { case -1: fprintf(file, "not set\n"); break; case AIR_TRUE: fprintf(file, "set to \"%s\"\n", envVal); break; case AIR_FALSE: fprintf(file, "set to \"%s\"? (invalid) \n", envVal); break; } switch(ret) { case -1: case AIR_FALSE: fprintf(file, " (%s == %s; unchanged)\n", varName, airEnumStr(airBool, currVal)); break; case AIR_TRUE: fprintf(file, " ==> %s = %s **********************\n", varName, airEnumStr(airBool, currVal)); break; } _hestPrintStr(file, 0, 0, columns, desc, AIR_FALSE); fprintf(file, "\n"); }
int mrendUserCheck(mrendUser *uu) { char me[]="mrendUserCheck", err[BIFF_STRLEN]; if (3 + uu->kind->baseDim != uu->nin->dim) { sprintf(err, "%s: input nrrd needs %d dimensions, not %d", me, + uu->kind->baseDim, uu->nin->dim); biffAdd(MREND, err); return 1; } if (!( uu->nin->axis[0].center == uu->nin->axis[1].center && uu->nin->axis[0].center == uu->nin->axis[2].center )) { sprintf(err, "%s: axes 0,1,2 centerings (%s,%s,%s) not equal", me, airEnumStr(nrrdCenter, uu->nin->axis[0].center), airEnumStr(nrrdCenter, uu->nin->axis[1].center), airEnumStr(nrrdCenter, uu->nin->axis[2].center)); biffAdd(MREND, err); return 1; } if (1 != uu->kind->table[uu->whatq].answerLength) { sprintf(err, "%s: quantity %s (in %s volumes) isn't a scalar; " "can't render it", me, airEnumStr(uu->kind->enm, uu->whatq), uu->kind->name); biffAdd(MREND, err); return 1; } return 0; }
int tenGradientCheck(const Nrrd *ngrad, int type, unsigned int minnum) { static const char me[]="tenGradientCheck"; if (nrrdCheck(ngrad)) { biffMovef(TEN, NRRD, "%s: basic validity check failed", me); return 1; } if (!( 3 == ngrad->axis[0].size && 2 == ngrad->dim )) { char stmp[AIR_STRLEN_SMALL]; biffAddf(TEN, "%s: need a 3xN 2-D array (not a %sx? %u-D array)", me, airSprintSize_t(stmp, ngrad->axis[0].size), ngrad->dim); return 1; } if (nrrdTypeDefault != type && type != ngrad->type) { biffAddf(TEN, "%s: requested type %s but got type %s", me, airEnumStr(nrrdType, type), airEnumStr(nrrdType, ngrad->type)); return 1; } if (nrrdTypeBlock == ngrad->type) { biffAddf(TEN, "%s: sorry, can't use %s type", me, airEnumStr(nrrdType, nrrdTypeBlock)); return 1; } if (!( minnum <= ngrad->axis[1].size )) { char stmp[AIR_STRLEN_SMALL]; biffAddf(TEN, "%s: have only %s gradients, need at least %d", me, airSprintSize_t(stmp, ngrad->axis[1].size), minnum); return 1; } return 0; }
/* ******** nrrd1DIrregAclCheck() ** ** returns zero only on valid accelerators for 1D irregular mappings */ int nrrd1DIrregAclCheck(const Nrrd *nacl) { char me[]="nrrd1DIrregAclCheck", err[BIFF_STRLEN]; if (!nacl) { sprintf(err, "%s: got NULL pointer", me); biffAdd(NRRD, err); return 1; } if (nrrdCheck(nacl)) { sprintf(err, "%s: ", me); biffAdd(NRRD, err); return 1; } if (nrrdTypeUShort != nacl->type) { sprintf(err, "%s: type should be %s, not %s", me, airEnumStr(nrrdType, nrrdTypeUShort), airEnumStr(nrrdType, nacl->type)); biffAdd(NRRD, err); return 1; } if (2 != nacl->dim) { sprintf(err, "%s: dimension should be 2, not %d", me, nacl->dim); biffAdd(NRRD, err); return 1; } if (!( nacl->axis[0].size == 2 && nacl->axis[1].size >= 2 )) { sprintf(err, "%s: sizes (" _AIR_SIZE_T_CNV "," _AIR_SIZE_T_CNV ") " "not (2,>=2)", me, nacl->axis[0].size, nacl->axis[1].size); biffAdd(NRRD, err); return 1; } return 0; }
int _pullInitParmCheck(pullInitParm *iparm) { static const char me[]="_pullInitParmCheck"; if (!AIR_IN_OP(pullInitMethodUnknown, iparm->method, pullInitMethodLast)) { biffAddf(PULL, "%s: init method %d not valid", me, iparm->method); return 1; } CHECK(jitter, 0.0, 2.0); switch (iparm->method) { case pullInitMethodGivenPos: if (nrrdCheck(iparm->npos)) { biffMovef(PULL, NRRD, "%s: got a broken npos", me); return 1; } if (!( 2 == iparm->npos->dim && 4 == iparm->npos->axis[0].size && (nrrdTypeDouble == iparm->npos->type || nrrdTypeFloat == iparm->npos->type) )) { biffAddf(PULL, "%s: npos not a 2-D 4-by-N array of %s or %s" "(got %u-D %u-by-X of %s)", me, airEnumStr(nrrdType, nrrdTypeFloat), airEnumStr(nrrdType, nrrdTypeDouble), iparm->npos->dim, AIR_CAST(unsigned int, iparm->npos->axis[0].size), airEnumStr(nrrdType, iparm->npos->type)); return 1; } break; case pullInitMethodPointPerVoxel: if (iparm->pointPerVoxel < -3001 || iparm->pointPerVoxel > 10) { biffAddf(PULL, "%s: pointPerVoxel %d unreasonable", me, iparm->pointPerVoxel); return 1; } if (-1 == iparm->pointPerVoxel) { biffAddf(PULL, "%s: pointPerVoxel should be < -1 or >= 1", me); return 1; } if (0 == iparm->jitter && 1 < iparm->pointPerVoxel) { biffAddf(PULL, "%s: must have jitter > 0 if pointPerVoxel (%d) > 1", me, iparm->pointPerVoxel); return 1; } break; case pullInitMethodRandom: case pullInitMethodHalton: if (!( iparm->numInitial >= 1 )) { biffAddf(PULL, "%s: iparm->numInitial (%d) not >= 1\n", me, iparm->numInitial); return 1; } break; /* no check needed on haltonStartIndex */ default: biffAddf(PULL, "%s: init method %d valid but not handled?", me, iparm->method); return 1; }
/* ******** gageShapeEqual ** ** shapes not being equal is a biffable error, ** returning 0 signifies this "error" ** returning 1 means no error, they ARE equal */ int gageShapeEqual(const gageShape *shape1, const char *_name1, const gageShape *shape2, const char *_name2) { static const char me[]="gageShapeEqual"; const char *name1, *name2, what[] = "???"; if (!( shape1 && shape2 )) { biffAddf(GAGE, "%s: can't judge equality w/ NULL pointer", me); return 0; } name1 = _name1 ? _name1 : what; name2 = _name2 ? _name2 : what; if (!( shape1->fromOrientation == shape2->fromOrientation )) { biffAddf(GAGE, "%s: fromOrientation of %s (%s) != %s's (%s)", me, name1, shape1->fromOrientation ? "true" : "false", name2, shape2->fromOrientation ? "true" : "false"); return 0; } if (!( shape1->size[0] == shape2->size[0] && shape1->size[1] == shape2->size[1] && shape1->size[2] == shape2->size[2] )) { biffAddf(GAGE, "%s: dimensions of %s (%u,%u,%u) != %s's (%u,%u,%u)", me, name1, shape1->size[0], shape1->size[1], shape1->size[2], name2, shape2->size[0], shape2->size[1], shape2->size[2]); return 0; } if (shape1->fromOrientation) { if (!( ELL_4M_EQUAL(shape1->ItoW, shape2->ItoW) )) { biffAddf(GAGE, "%s: ItoW matrices of %s and %s not the same", me, name1, name2); return 0; } } else { if (!( shape1->spacing[0] == shape2->spacing[0] && shape1->spacing[1] == shape2->spacing[1] && shape1->spacing[2] == shape2->spacing[2] )) { biffAddf(GAGE, "%s: spacings of %s (%g,%g,%g) != %s's (%g,%g,%g)", me, name1, shape1->spacing[0], shape1->spacing[1], shape1->spacing[2], name2, shape2->spacing[0], shape2->spacing[1], shape2->spacing[2]); return 0; } if (!( shape1->center == shape2->center )) { biffAddf(GAGE, "%s: centering of %s (%s) != %s's (%s)", me, name1, airEnumStr(nrrdCenter, shape1->center), name2, airEnumStr(nrrdCenter, shape2->center)); return 0; } } return 1; }
int _nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, NrrdIoState *nio) { static const char me[]="_nrrdEncodingAscii_read"; char numbStr[AIR_STRLEN_HUGE]; /* HEY: fix this */ char *nstr; size_t I; char *data; int tmp; AIR_UNUSED(nio); if (nrrdTypeBlock == nrrd->type) { biffAddf(NRRD, "%s: can't read nrrd type %s from %s", me, airEnumStr(nrrdType, nrrdTypeBlock), nrrdEncodingAscii->name); return 1; } data = (char*)_data; I = 0; while (I < elNum) { if (1 != fscanf(file, "%s", numbStr)) { biffAddf(NRRD, "%s: couldn't parse element " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV, me, I+1, elNum); return 1; } if (!strcmp(",", numbStr)) { /* its an isolated comma, not a value, pass over this */ continue; } /* get past any commas prefixing a number (without space) */ nstr = numbStr + strspn(numbStr, ","); if (nrrd->type >= nrrdTypeInt) { /* sscanf supports putting value directly into this type */ if (1 != airSingleSscanf(nstr, nrrdTypePrintfStr[nrrd->type], (void*)(data + I*nrrdElementSize(nrrd)))) { biffAddf(NRRD, "%s: couln't parse %s " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV " (\"%s\")", me, airEnumStr(nrrdType, nrrd->type), I+1, elNum, nstr); return 1; } } else { /* sscanf value into an int first */ if (1 != airSingleSscanf(nstr, "%d", &tmp)) { biffAddf(NRRD, "%s: couln't parse element " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV " (\"%s\")", me, I+1, elNum, nstr); return 1; } nrrdIInsert[nrrd->type](data, I, tmp); } I++; } return 0; }
/* ******** nrrdDescribe ** ** writes verbose description of nrrd to given file */ void nrrdDescribe(FILE *file, const Nrrd *nrrd) { unsigned int ai; char stmp[AIR_STRLEN_SMALL]; if (file && nrrd) { fprintf(file, "Nrrd at 0x%p:\n", AIR_CVOIDP(nrrd)); fprintf(file, "Data at 0x%p is %s elements of type %s.\n", nrrd->data, airSprintSize_t(stmp, nrrdElementNumber(nrrd)), airEnumStr(nrrdType, nrrd->type)); if (nrrdTypeBlock == nrrd->type) { fprintf(file, "The blocks have size %s\n", airSprintSize_t(stmp, nrrd->blockSize)); } if (airStrlen(nrrd->content)) { fprintf(file, "Content = \"%s\"\n", nrrd->content); } fprintf(file, "%d-dimensional array, with axes:\n", nrrd->dim); for (ai=0; ai<nrrd->dim; ai++) { if (airStrlen(nrrd->axis[ai].label)) { fprintf(file, "%d: (\"%s\") ", ai, nrrd->axis[ai].label); } else { fprintf(file, "%d: ", ai); } fprintf(file, "%s-centered, size=%s, ", airEnumStr(nrrdCenter, nrrd->axis[ai].center), airSprintSize_t(stmp, nrrd->axis[ai].size)); airSinglePrintf(file, NULL, "spacing=%lg, \n", nrrd->axis[ai].spacing); airSinglePrintf(file, NULL, "thickness=%lg, \n", nrrd->axis[ai].thickness); airSinglePrintf(file, NULL, " axis(Min,Max) = (%lg,", nrrd->axis[ai].min); airSinglePrintf(file, NULL, "%lg)\n", nrrd->axis[ai].max); if (airStrlen(nrrd->axis[ai].units)) { fprintf(file, "units=%s, \n", nrrd->axis[ai].units); } } /* airSinglePrintf(file, NULL, "The min, max values are %lg", nrrd->min); airSinglePrintf(file, NULL, ", %lg\n", nrrd->max); */ airSinglePrintf(file, NULL, "The old min, old max values are %lg", nrrd->oldMin); airSinglePrintf(file, NULL, ", %lg\n", nrrd->oldMax); /* fprintf(file, "hasNonExist = %d\n", nrrd->hasNonExist); */ if (nrrd->cmtArr->len) { fprintf(file, "Comments:\n"); for (ai=0; ai<nrrd->cmtArr->len; ai++) { fprintf(file, "%s\n", nrrd->cmt[ai]); } } fprintf(file, "\n"); } }
int pullScaleTracePlotAdd(pullContext *pctx, Nrrd *nwild, Nrrd *nccd, Nrrd *nmask, double mth, airArray *insideArr, double velHalf, pullTrace *pts) { static const char me[]="pullScaleTracePlotAdd"; double ssr[2], *pos, *velo, *wild, *ccd, *mask; unsigned int pnum, pidx, sizeS, sizeV; if (!(pctx && nwild && nccd && pts)) { biffAddf(PULL, "%s: got NULL pointer", me); return 1; } if (!nrrdSameSize(nwild, nccd, AIR_TRUE)) { biffMovef(PULL, NRRD, "%s: nwild not same size as nccd", me); return 1; } if (nmask || insideArr) { if (!insideArr) { biffAddf(PULL, "%s: got nmask but not insideArr", me); return 1; } if (!nmask) { biffAddf(PULL, "%s: got insideArr but not nmask", me); return 1; } if (nrrdTypeDouble != nmask->type) { biffAddf(PULL, "%s: nmask has type %s but want %s", me, airEnumStr(nrrdType, nmask->type), airEnumStr(nrrdType, nrrdTypeDouble)); return 1; } if (!nrrdSameSize(nwild, nmask, AIR_TRUE)) { biffMovef(PULL, NRRD, "%s: nwild not same size as nmask", me); return 1; } if (!nrrdSameSize(nccd, nmask, AIR_TRUE)) { biffMovef(PULL, NRRD, "%s: nccd not same size as nmask", me); return 1; } if (!AIR_EXISTS(mth)) { biffAddf(PULL, "%s: got non-existent mask thresh %g", me, mth); return 1; } } ssr[0] = nwild->axis[0].min; ssr[1] = nwild->axis[0].max; sizeS = AIR_CAST(unsigned int, nwild->axis[0].size); sizeV = AIR_CAST(unsigned int, nwild->axis[1].size); wild = AIR_CAST(double *, nwild->data); ccd = AIR_CAST(double *, nccd->data); if (nmask) { mask = AIR_CAST(double *, nmask->data); } else {
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; int *itype, itypeNum, ii; double src[3], last[3], dst[3]; char space[] = " "; me = argv[0]; hestOptAdd(&hopt, NULL, "v1 v2 v3", airTypeDouble, 3, 3, src, NULL, "source triple"); hestOptAdd(&hopt, "t", "type", airTypeEnum, 2, -1, &itype, NULL, "sequence of triple types to convert through", &itypeNum, tenTripleType); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); printf("%s", space + strlen(airEnumStr(tenTripleType, itype[0]))); printf("%s", airEnumStr(tenTripleType, itype[0])); ell_3v_print_d(stdout, src); ELL_3V_COPY(last, src); for (ii=1; ii<itypeNum; ii++) { tenTripleConvertSingle_d(dst, itype[ii], src, itype[ii-1]); printf("%s", space + strlen(airEnumStr(tenTripleType, itype[ii]))); printf("%s", airEnumStr(tenTripleType, itype[ii])); ell_3v_print_d(stdout, dst); ELL_3V_COPY(src, dst); } /* tenTripleConvert_d(dst, dstType, src, srcType); tenTripleConvert_d(tst, srcType, dst, dstType); */ /* printf("%s: %s %s --> %s --> %s\n", me, tenTriple->name, airEnumStr(tenTriple, srcType), airEnumStr(tenTriple, dstType), airEnumStr(tenTriple, srcType)); ell_3v_print_d(stdout, src); ell_3v_print_d(stdout, dst); ell_3v_print_d(stdout, tst); */ airMopOkay(mop); return 0; }
/* ** ctx's ksp[] & needK --> radius ** */ int _gageRadiusUpdate(gageContext *ctx) { static const char me[]="_gageRadiusUpdate"; unsigned int kernIdx, radius; double maxRad, rad; NrrdKernelSpec *ksp; if (ctx->verbose) fprintf(stderr, "%s: hello\n", me); maxRad = 0; for (kernIdx=gageKernelUnknown+1; kernIdx<gageKernelLast; kernIdx++) { if (ctx->needK[kernIdx]) { ksp = ctx->ksp[kernIdx]; if (!ksp) { biffAddf(GAGE, "%s: need kernel %s but it hasn't been set", me, airEnumStr(gageKernel, kernIdx)); return 1; } rad = ksp->kernel->support(ksp->parm); maxRad = AIR_MAX(maxRad, rad); if (ctx->verbose) { fprintf(stderr, "%s: k[%s]=%s -> rad = %g -> maxRad = %g\n", me, airEnumStr(gageKernel, kernIdx), ksp->kernel->name, rad, maxRad); } } } radius = AIR_ROUNDUP(maxRad); /* In case either kernels have tiny supports (less than 0.5), or if we in fact don't need any kernels, then we need to do this to ensure that we generate a valid radius */ radius = AIR_MAX(radius, 1); if (ctx->parm.stackUse && (nrrdKernelHermiteScaleSpaceFlag == ctx->ksp[gageKernelStack]->kernel)) { if (ctx->verbose) { fprintf(stderr, "%s: hermite on stack: bumping radius %d --> %d\n", me, radius, radius+1); } radius += 1; } if (radius != ctx->radius) { if (ctx->verbose) { fprintf(stderr, "%s: changing radius from %d to %d\n", me, ctx->radius, radius); } ctx->radius = radius; ctx->flag[gageCtxFlagRadius] = AIR_TRUE; } if (ctx->verbose) fprintf(stderr, "%s: bye\n", me); return 0; }
int gageShapeEqual(gageShape *shape1, char *_name1, gageShape *shape2, char *_name2) { char me[]="_gageShapeEqual", err[BIFF_STRLEN], *name1, *name2, what[] = "???"; name1 = _name1 ? _name1 : what; name2 = _name2 ? _name2 : what; if (!( shape1->fromOrientation == shape2->fromOrientation )) { sprintf(err, "%s: fromOrientation of %s (%s) != %s's (%s)", me, name1, shape1->fromOrientation ? "true" : "false", name2, shape2->fromOrientation ? "true" : "false"); biffAdd(GAGE, err); return 0; } if (!( shape1->size[0] == shape2->size[0] && shape1->size[1] == shape2->size[1] && shape1->size[2] == shape2->size[2] )) { sprintf(err, "%s: dimensions of %s (%u,%u,%u) != %s's (%u,%u,%u)", me, name1, shape1->size[0], shape1->size[1], shape1->size[2], name2, shape2->size[0], shape2->size[1], shape2->size[2]); biffAdd(GAGE, err); return 0; } if (shape1->fromOrientation) { if (!( ELL_4M_EQUAL(shape1->ItoW, shape2->ItoW) )) { sprintf(err, "%s: ItoW matrices of %s and %s not the same", me, name1, name2); biffAdd(GAGE, err); return 0; } } else { if (!( shape1->spacing[0] == shape2->spacing[0] && shape1->spacing[1] == shape2->spacing[1] && shape1->spacing[2] == shape2->spacing[2] )) { sprintf(err, "%s: spacings of %s (%g,%g,%g) != %s's (%g,%g,%g)", me, name1, shape1->spacing[0], shape1->spacing[1], shape1->spacing[2], name2, shape2->spacing[0], shape2->spacing[1], shape2->spacing[2]); biffAdd(GAGE, err); return 0; } if (!( shape1->center == shape2->center )) { sprintf(err, "%s: centering of %s (%s) != %s's (%s)", me, name1, airEnumStr(nrrdCenter, shape1->center), name2, airEnumStr(nrrdCenter, shape2->center)); biffAdd(GAGE, err); return 0; } } return 1; }
int _miteNtxfCopy(miteRender *mrr, miteUser *muu) { static const char me[]="_miteNtxfCopy"; int ni, E; mrr->ntxf = AIR_CALLOC(muu->ntxfNum, Nrrd *); if (!mrr->ntxf) { biffAddf(MITE, "%s: couldn't calloc %d ntxf pointers", me, muu->ntxfNum); return 1; } mrr->ntxfNum = muu->ntxfNum; airMopAdd(mrr->rmop, mrr->ntxf, airFree, airMopAlways); E = 0; for (ni=0; ni<mrr->ntxfNum; ni++) { mrr->ntxf[ni] = nrrdNew(); if (!E) airMopAdd(mrr->rmop, mrr->ntxf[ni], (airMopper)nrrdNuke, airMopAlways); if (!( nrrdTypeUChar == muu->ntxf[ni]->type || nrrdTypeFloat == muu->ntxf[ni]->type || nrrdTypeDouble == muu->ntxf[ni]->type )) { biffAddf(MITE, "%s: sorry, can't handle txf of type %s (only %s, %s, %s)", me, airEnumStr(nrrdType, muu->ntxf[ni]->type), airEnumStr(nrrdType, nrrdTypeUChar), airEnumStr(nrrdType, nrrdTypeFloat), airEnumStr(nrrdType, nrrdTypeDouble)); return 1; } /* note that key/values need to be copied for the sake of identifying a non-default miteStageOp */ switch(muu->ntxf[ni]->type) { case nrrdTypeUChar: if (!E) E |= nrrdUnquantize(mrr->ntxf[ni], muu->ntxf[ni], nrrdTypeUChar); if (!E) E |= nrrdKeyValueCopy(mrr->ntxf[ni], muu->ntxf[ni]); break; case mite_nt: if (!E) E |= nrrdCopy(mrr->ntxf[ni], muu->ntxf[ni]); break; default: /* will be either float or double (whatever mite_nt isn't) */ if (!E) E |= nrrdConvert(mrr->ntxf[ni], muu->ntxf[ni], mite_nt); if (!E) E |= nrrdKeyValueCopy(mrr->ntxf[ni], muu->ntxf[ni]); break; } } if (E) { biffMovef(MITE, NRRD, "%s: troubling copying/converting all ntxfs", me); return 1; } return 0; }
/* ******** nrrdPad_va() ** ** strictly for padding */ int nrrdPad_va(Nrrd *nout, const Nrrd *nin, const ptrdiff_t *min, const ptrdiff_t *max, int boundary, ...) { static const char me[]="nrrdPad_va", func[]="pad"; char buff1[NRRD_DIM_MAX*30], buff2[AIR_STRLEN_MED]; double padValue=AIR_NAN; int outside; /* whether current sample in output has any coordinates that are outside the input volume (this is per-sample, not per-axis) */ unsigned int ai; ptrdiff_t cIn[NRRD_DIM_MAX]; /* coords for line start, in input */ size_t typeSize, idxIn, idxOut, /* linear indices for input and output */ numOut, /* number of elements in output nrrd */ szIn[NRRD_DIM_MAX], szOut[NRRD_DIM_MAX], cOut[NRRD_DIM_MAX]; /* coords for line start, in output */ va_list ap; char *dataIn, *dataOut; char stmp[2][AIR_STRLEN_SMALL]; if (!(nout && nin && min && max)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (nout == nin) { biffAddf(NRRD, "%s: nout==nin disallowed", me); return 1; } if (!AIR_IN_OP(nrrdBoundaryUnknown, boundary, nrrdBoundaryLast)) { biffAddf(NRRD, "%s: boundary behavior %d invalid", me, boundary); return 1; } if (nrrdBoundaryWeight == boundary) { biffAddf(NRRD, "%s: boundary strategy %s not applicable here", me, airEnumStr(nrrdBoundary, boundary)); return 1; } if (nrrdTypeBlock == nin->type && nrrdBoundaryPad == boundary) { biffAddf(NRRD, "%s: with nrrd type %s, boundary %s not valid", me, airEnumStr(nrrdType, nrrdTypeBlock), airEnumStr(nrrdBoundary, nrrdBoundaryPad)); return 1; } va_start(ap, boundary); if (nrrdBoundaryPad == boundary) { padValue = va_arg(ap, double); }
int unrrdu_cksumDoit(const char *me, char *inS, int endian, int printendian, FILE *fout) { Nrrd *nrrd; airArray *mop; unsigned int crc; char stmp[AIR_STRLEN_SMALL], ends[AIR_STRLEN_SMALL]; size_t nn; mop = airMopNew(); airMopAdd(mop, nrrd=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); if (nrrdLoad(nrrd, inS, NULL)) { biffMovef(me, NRRD, "%s: trouble loading \"%s\"", me, inS); airMopError(mop); return 1; } crc = nrrdCRC32(nrrd, endian); nn = nrrdElementNumber(nrrd)*nrrdElementSize(nrrd); sprintf(ends, "(%s)", airEnumStr(airEndian, endian)); fprintf(fout, "%u%s %s%s%s\n", crc, printendian ? ends : "", airSprintSize_t(stmp, nn), strcmp("-", inS) ? " " : "", strcmp("-", inS) ? inS : ""); airMopOkay(mop); return 0; }
int nrrdHistoCheck(const Nrrd *nhist) { static const char me[]="nrrdHistoCheck"; if (!nhist) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (nrrdTypeBlock == nhist->type) { biffAddf(NRRD, "%s: has non-scalar %s type", me, airEnumStr(nrrdType, nrrdTypeBlock)); return 1; } if (nrrdHasNonExist(nhist)) { biffAddf(NRRD, "%s: has non-existent values", me); return 1; } if (1 != nhist->dim) { biffAddf(NRRD, "%s: dim == %u != 1", me, nhist->dim); return 1; } if (!(nhist->axis[0].size > 1)) { biffAddf(NRRD, "%s: has single sample along sole axis", me); return 1; } return 0; }
void airEnumPrint(FILE *file, const airEnum *enm) { int ii; /* this should arguable be unsigned int, but airEnum values were kept as "int", even after the great unsigned conversion */ if (!(file && enm)) { return; } if (airStrlen(enm->name)) { fprintf(file, "airEnum \"%s\":\n", enm->name); } else { fprintf(file, "airEnum (NO NAME!):\n"); } fprintf(file, "(%s case sensitive)\n", (enm->sense ? "yes, is" : "is not")); if (enm->val) { fprintf(file, "Values (%u valid) given explicitly\n", enm->M); fprintf(file, "--- (0) %d: \"%s\"\n", enm->val[0], enm->str[0]); for (ii=1; ii<=AIR_CAST(int, enm->M); ii++) { fprintf(file, "--- (%d) %d: \"%s\" == \"%s\"\n", ii, enm->val[ii], enm->str[ii], airEnumStr(enm, enm->val[ii])); _enumPrintVal(file, enm, ii); } } else {
int _nrrdCheck(const Nrrd *nrrd, int checkData, int useBiff) { char me[]="_nrrdCheck", err[BIFF_STRLEN]; int fi; if (!nrrd) { sprintf(err, "%s: got NULL pointer", me); biffMaybeAdd(NRRD, err, useBiff); return 1; } if (checkData) { if (!(nrrd->data)) { sprintf(err, "%s: nrrd has NULL data pointer", me); biffMaybeAdd(NRRD, err, useBiff); return 1; } } for (fi=nrrdField_unknown+1; fi<nrrdField_last; fi++) { /* yes, this will call _nrrdFieldCheckSpaceInfo() many many times */ if (_nrrdFieldCheck[fi](nrrd, AIR_TRUE)) { sprintf(err, "%s: trouble with %s field", me, airEnumStr(nrrdField, fi)); biffMaybeAdd(NRRD, err, useBiff); return 1; } } return 0; }
int _nrrdCheck(const Nrrd *nrrd, int checkData, int useBiff) { static const char me[]="_nrrdCheck"; int fi; if (!nrrd) { biffMaybeAddf(useBiff, NRRD, "%s: got NULL pointer", me); return 1; } if (checkData) { if (!(nrrd->data)) { biffMaybeAddf(useBiff, NRRD, "%s: nrrd %p has NULL data pointer", me, AIR_CVOIDP(nrrd)); return 1; } } for (fi=nrrdField_unknown+1; fi<nrrdField_last; fi++) { /* yes, this will call _nrrdFieldCheckSpaceInfo() many many times */ if (_nrrdFieldCheck[fi](nrrd, AIR_TRUE)) { biffMaybeAddf(useBiff, NRRD, "%s: trouble with %s field", me, airEnumStr(nrrdField, fi)); return 1; } } return 0; }
static int _nrrdFieldCheck_kinds(const Nrrd *nrrd, int useBiff) { static const char me[]="_nrrdFieldCheck_kinds"; int val[NRRD_DIM_MAX]; unsigned int wantLen, ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoKind, val); for (ai=0; ai<nrrd->dim; ai++) { if (!( nrrdKindUnknown == val[ai] || !airEnumValCheck(nrrdKind, val[ai]) )) { biffMaybeAddf(useBiff, NRRD, "%s: axis %d kind %d invalid", me, ai, val[ai]); return 1; } wantLen = nrrdKindSize(val[ai]); if (wantLen && wantLen != nrrd->axis[ai].size) { char stmp[AIR_STRLEN_SMALL]; biffMaybeAddf(useBiff, NRRD, "%s: axis %d kind %s requires size %u, but have %s", me, ai, airEnumStr(nrrdKind, val[ai]), wantLen, airSprintSize_t(stmp, nrrd->axis[ai].size)); return 1; } } return 0; }
/* HEY this was written in a hurry; ** needs to be checked against parsing code */ int pullInfoSpecSprint(char str[AIR_STRLEN_LARGE], const pullContext *pctx, const pullInfoSpec *ispec) { static const char me[]="pullInfoSpecSprint"; const pullVolume *pvol; char stmp[AIR_STRLEN_LARGE]; if (!( str && pctx && ispec )) { biffAddf(PULL, "%s: got NULL pointer", me); return 1; } strcpy(str, ""); /* HEY: no bounds checking! */ strcat(str, airEnumStr(pullInfo, ispec->info)); if (ispec->constraint) { strcat(str, "-c"); } strcat(str, ":"); if (pullSourceGage == ispec->source) { if (UINT_MAX == ispec->volIdx) { biffAddf(PULL, "%s: never learned volIdx for \"%s\"", me, ispec->volName); return 1; } strcat(str, ispec->volName); strcat(str, ":"); pvol = pctx->vol[ispec->volIdx]; strcat(str, airEnumStr(pvol->kind->enm, ispec->item)); } else if (pullSourceProp == ispec->source) { strcat(str, airEnumStr(pullProp, ispec->prop)); } else { biffAddf(PULL, "%s: unexplained source %d", me, ispec->source); return 1; } if ( (pullSourceGage == ispec->source && 1 == pullInfoLen(ispec->info)) || (pullSourceProp == ispec->source && 1 == pullPropLen(ispec->prop)) ) { sprintf(stmp, "%g", ispec->zero); strcat(str, stmp); strcat(str, ":"); sprintf(stmp, "%g", ispec->scale); strcat(str, stmp); } return 0; }
int _nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum, Nrrd *nrrd, NrrdIoState *nio) { char me[]="_nrrdEncodingAscii_read", err[BIFF_STRLEN], numbStr[AIR_STRLEN_HUGE]; /* HEY: fix this */ size_t I; char *data; int tmp; AIR_UNUSED(nio); if (nrrdTypeBlock == nrrd->type) { sprintf(err, "%s: can't read nrrd type %s from %s", me, airEnumStr(nrrdType, nrrdTypeBlock), nrrdEncodingAscii->name); biffAdd(NRRD, err); return 1; } data = (char*)_data; for (I=0; I<elNum; I++) { if (1 != fscanf(file, "%s", numbStr)) { sprintf(err, "%s: couldn't parse element " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV, me, I+1, elNum); biffAdd(NRRD, err); return 1; } if (nrrd->type >= nrrdTypeInt) { /* sscanf supports putting value directly into this type */ if (1 != airSingleSscanf(numbStr, nrrdTypePrintfStr[nrrd->type], (void*)(data + I*nrrdElementSize(nrrd)))) { sprintf(err, "%s: couln't parse %s " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV " (\"%s\")", me, airEnumStr(nrrdType, nrrd->type), I+1, elNum, numbStr); biffAdd(NRRD, err); return 1; } } else { /* sscanf value into an int first */ if (1 != airSingleSscanf(numbStr, "%d", &tmp)) { sprintf(err, "%s: couln't parse element " _AIR_SIZE_T_CNV " of " _AIR_SIZE_T_CNV " (\"%s\")", me, I+1, elNum, numbStr); biffAdd(NRRD, err); return 1; } nrrdIInsert[nrrd->type](data, I, tmp); } } return 0; }
int nrrdArithUnaryOp(Nrrd *nout, int op, const Nrrd *nin) { static const char me[]="nrrdArithUnaryOp"; size_t N, I; int size[NRRD_DIM_MAX]; double (*insert)(void *v, size_t I, double d), (*lookup)(const void *v, size_t I), (*uop)(double), val; if (!(nout && nin)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (nrrdTypeBlock == nin->type) { biffAddf(NRRD, "%s: can't operate on type %s", me, airEnumStr(nrrdType, nrrdTypeBlock)); return 1; } if (airEnumValCheck(nrrdUnaryOp, op)) { biffAddf(NRRD, "%s: unary op %d invalid", me, op); return 1; } if (nout != nin) { if (nrrdCopy(nout, nin)) { biffAddf(NRRD, "%s:", me); return 1; } } nrrdAxisInfoGet_nva(nin, nrrdAxisInfoSize, size); uop = _nrrdUnaryOp[op]; N = nrrdElementNumber(nin); lookup = nrrdDLookup[nin->type]; insert = nrrdDInsert[nin->type]; for (I=0; I<N; I++) { val = lookup(nin->data, I); insert(nout->data, I, uop(val)); } if (nrrdContentSet_va(nout, airEnumStr(nrrdUnaryOp, op), nin, "")) { biffAddf(NRRD, "%s:", me); return 1; } nrrdBasicInfoInit(nout, NRRD_BASIC_INFO_ALL ^ (NRRD_BASIC_INFO_OLDMIN_BIT | NRRD_BASIC_INFO_OLDMAX_BIT)); return 0; }
void demoIO(char *filename) { char me[]="demoIO", newname[]="foo.nrrd", *err, *key, *val; int kvn, kvi; Nrrd *nin; /* create a nrrd; at this point this is just an empty container */ nin = nrrdNew(); /* read in the nrrd from file */ if (nrrdLoad(nin, filename, NULL)) { err = biffGetDone(NRRD); fprintf(stderr, "%s: trouble reading \"%s\":\n%s", me, filename, err); free(err); return; } /* say something about the array */ printf("%s: \"%s\" is a %d-dimensional nrrd of type %d (%s)\n", me, filename, nin->dim, nin->type, airEnumStr(nrrdType, nin->type)); printf("%s: the array contains %d elements, each %d bytes in size\n", me, (int)nrrdElementNumber(nin), (int)nrrdElementSize(nin)); /* print out the key/value pairs present */ kvn = nrrdKeyValueSize(nin); if (kvn) { for (kvi=0; kvi<kvn; kvi++) { nrrdKeyValueIndex(nin, &key, &val, kvi); printf("%s: key:value %d = %s:%s\n", me, kvi, key, val); free(key); free(val); key = val = NULL; } } /* modify key/value pairs, and write out the nrrd to a different file */ nrrdKeyValueClear(nin); nrrdKeyValueAdd(nin, "new key", "precious value"); if (nrrdSave(newname, nin, NULL)) { err = biffGetDone(NRRD); fprintf(stderr, "%s: trouble writing \"%s\":\n%s", me, newname, err); free(err); return; } /* blow away both the Nrrd struct *and* the memory at nin->data (nrrdNix() frees the struct but not the data, nrrdEmpty() frees the data but not the struct) */ nrrdNuke(nin); return; }
/* ** returns the *dimension* (not codimension) of the constraint manifold: ** 0 for points ** 1 for lines ** 2 for surfaces ** ** a -1 return value represents a biff-able error */ int _pullConstraintDim(const pullContext *pctx) { static const char me[]="_pullConstraintDim"; int ret, t1, t2, nt1, nt2; switch (pctx->constraint) { case pullInfoHeightLaplacian: /* zero-crossing edges */ ret = 2; break; case pullInfoIsovalue: ret = 2; break; case pullInfoHeight: t1 = !!pctx->ispec[pullInfoTangent1]; t2 = !!pctx->ispec[pullInfoTangent2]; nt1 = !!pctx->ispec[pullInfoNegativeTangent1]; nt2 = !!pctx->ispec[pullInfoNegativeTangent2]; switch (t1 + t2 + nt1 + nt2) { case 0: case 3: ret = 0; break; case 1: ret = 2; break; case 2: ret = 1; break; default: biffAddf(PULL, "%s: can't simultaneously use all tangents " "(%s,%s,%s,%s) as this implies co-dimension of -1", me, airEnumStr(pullInfo, pullInfoTangent1), airEnumStr(pullInfo, pullInfoTangent2), airEnumStr(pullInfo, pullInfoNegativeTangent1), airEnumStr(pullInfo, pullInfoNegativeTangent2)); return -1; } break; default: biffAddf(PULL, "%s: constraint on %s (%d) unimplemented", me, airEnumStr(pullInfo, pctx->constraint), pctx->constraint); return -1; } return ret; }