int unrrdu_untileMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; unsigned int axes[3]; int pret; size_t size[2]; airArray *mop; hestOptAdd(&opt, "a,axis", "axMerge ax0 ax1", airTypeUInt, 3, 3, axes, NULL, "the slow parts of axes ax0 and ax1 are merged into a (new) " "axis axMerge, with the axis ax0 part being faster than ax1."); hestOptAdd(&opt, "s,size", "size0 size1", airTypeSize_t, 2, 2, size, NULL, "the slow parts of axes ax0 and ax1 are taken to have size " "size0 and size1, respectively, and axis axMerge will have " "size size0*size1."); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_untileInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdUntile2D(nout, nin, axes[1], axes[2], axes[0], size[0], size[1])) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error tiling nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int unrrdu_permuteMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; unsigned int *perm, permLen; int pret; airArray *mop; hestOptAdd(&opt, "p,permute", "ax0 ax1", airTypeUInt, 1, -1, &perm, NULL, "new axis ordering", &permLen); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_permuteInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (!( permLen == nin->dim )) { fprintf(stderr,"%s: # axes in permutation (%u) != nrrd dim (%d)\n", me, permLen, nin->dim); airMopError(mop); return 1; } if (nrrdAxesPermute(nout, nin, perm)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error permuting nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int unrrdu_projectMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; unsigned int axis; int measr, pret, type; airArray *mop; OPT_ADD_AXIS(axis, "axis to project along"); hestOptAdd(&opt, "m,measure", "measr", airTypeEnum, 1, 1, &measr, NULL, "How to \"measure\" a scanline, by summarizing all its values " "with a single scalar. " NRRD_MEASURE_DESC, NULL, nrrdMeasure); hestOptAdd(&opt, "t,type", "type", airTypeOther, 1, 1, &type, "default", "type to use for output. By default (not using this option), " "the output type is determined auto-magically", NULL, NULL, &unrrduHestMaybeTypeCB); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_projectInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdProject(nout, nin, axis, measr, type)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error projecting nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_sliceMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; char *outS; int axis, pos, dim; Nrrd *nin, *nout; hestOptAdd(&hopt, "a", "axis", airTypeInt, 1, 1, &axis, NULL, "axis along which to slice"); hestOptAdd(&hopt, "p", "pos", airTypeInt, 1, 1, &pos, NULL, "position to slice at"); hestOptAdd(&hopt, "d", "dim", airTypeInt, 1, 1, &dim, "3", "dimension of desired tensor output, can be either 2 or 3"); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output tensor slice"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_sliceInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); airMopAdd(mop, nout=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); if (tenSlice(nout, nin, axis, pos, dim)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int rva_gridMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *hopt = NULL; char *err; airArray *mop; rvaLattSpec *lsp; double radius; char *outStr; Nrrd *nout; mop = airMopNew(); hopt = NULL; hestOptAdd(&hopt, NULL, "latt", airTypeOther, 1, 1, &lsp, NULL, "lattice definition", NULL, NULL, rvaHestLattSpec); hestOptAdd(&hopt, "r", "radius", airTypeDouble, 1, 1, &radius, "1", "radius limit"); hestOptAdd(&hopt, "o", "fname", airTypeString, 1, 1, &outStr, "-", "output filename"); hestParseOrDie(hopt, argc, argv, hparm, me, longInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (rvaGrid(nout, lsp, radius)) { airMopAdd(mop, err=biffGetDone(RVA), airFree, airMopAlways); fprintf(stderr, "%s: problem:\n%s", me, err); airMopError(mop); return 1; } if (nrrdSave(outStr, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem saving:\n%s", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_convertMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int type, pret, E, doClamp; airArray *mop; OPT_ADD_TYPE(type, "type to convert to", NULL); OPT_ADD_NIN(nin, "input nrrd"); hestOptAdd(&opt, "clamp", NULL, airTypeInt, 0, 0, &doClamp, NULL, "clamp input values to representable range of values of " "output type, to avoid wrap-around problems"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_convertInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (doClamp) { E = nrrdClampConvert(nout, nin, type); } else { E = nrrdConvert(nout, nin, type); } if (E) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error converting nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_tconvMain(int argc, const char **argv, const char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; int ttype[2]; Nrrd *nin, *nout; char *outS; hestOptAdd(&hopt, "t", "inType outType", airTypeEnum, 2, 2, ttype, NULL, "given input and desired output type of triples", NULL, tenTripleType); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", "input array of triples", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output array"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_tconvInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenTripleConvert(nout, ttype[1], nin, ttype[0])) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble converting:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int tend_unmfMain(int argc, const char **argv, const char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; Nrrd *nin, *nout; char *outS; hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL, "input diffusion tensor volume " "(sorry, can't use usual default of \"-\" for stdin " "because of hest quirk)", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output tensor volume"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_unmfInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenMeasurementFrameReduce(nout, nin)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_axinsertMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err, *label; Nrrd *nin, *nout; int pret; unsigned int axis; airArray *mop; OPT_ADD_AXIS(axis, "dimension (axis index) at which to insert the new axis"); hestOptAdd(&opt, "l,label", "label", airTypeString, 1, 1, &label, "", "label to associate with new axis"); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_axinsertInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdAxesInsert(nout, nin, axis)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error inserting axis:\n%s", me, err); airMopError(mop); return 1; } if (strlen(label)) { nout->axis[axis].label = (char *)airFree(nout->axis[axis].label); nout->axis[axis].label = airStrdup(label); } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int unrrdu_tileMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret; size_t size[2]; unsigned int axes[3]; airArray *mop; hestOptAdd(&opt, "a,axis", "axSplit ax0 ax1", airTypeUInt, 3, 3, axes, NULL, "axSplit is divided and merged with ax0 and ax1"); hestOptAdd(&opt, "s,size", "fast slow", airTypeSize_t, 2, 2, size, NULL, "fast and slow axis sizes to produce as result of splitting " "the axSplit axis."); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_tileInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdTile2D(nout, nin, axes[1], axes[2], axes[0], size[0], size[1])) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error tiling nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int unrrdu_axsplitMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret; size_t size[2]; unsigned int axis; airArray *mop; OPT_ADD_AXIS(axis, "dimension (axis index) to split at"); hestOptAdd(&opt, "s,size", "fast, slow sizes", airTypeSize_t, 2, 2, size, NULL, "fast and slow axis sizes to produce as result of splitting " "given axis."); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_axsplitInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdAxesSplit(nout, nin, axis, size[0], size[1])) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error splitting axis:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
void airMopMem(airArray *arr, void *_ptrP, int when) { void **ptrP; if (!(arr && _ptrP)) { return; } ptrP = (void **)_ptrP; airMopAdd(arr, ptrP, (airMopper)airSetNull, when); airMopAdd(arr, *ptrP, airFree, when); /* printf("airMopMem(0x%p): will free() 0x%p\n", (void*)arr, (void*)(*ptrP)); printf("airMopMem(0x%p): will set 0x%p to NULL\n", (void*)arr, (void*)ptrP); */ return; }
int limnpu_ccfindMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *hopt = NULL; char *err, *perr; airArray *mop; int pret; limnPolyData *pld; Nrrd *nmeas; char *out; hestOptAdd(&hopt, NULL, "input", airTypeOther, 1, 1, &pld, NULL, "input polydata filename", NULL, NULL, limnHestPolyDataLMPD); hestOptAdd(&hopt, NULL, "output", airTypeString, 1, 1, &out, NULL, "output polydata filename"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(myinfo); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nmeas = nrrdNew(); airMopAdd(mop, nmeas, (airMopper)nrrdNuke, airMopAlways); if (limnPolyDataCCFind(pld) || limnPolyDataPrimitiveArea(nmeas, pld) || limnPolyDataPrimitiveSort(pld, nmeas) || limnPolyDataSave(out, pld)) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *outS, *err; hestOpt *hopt; hestParm *hparm; airArray *mop; Nrrd *_ninA, *_ninB, *ninA, *ninB, *nmul; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, NULL, "matrix", airTypeOther, 1, 1, &_ninA, NULL, "first matrix", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, NULL, "matrix", airTypeOther, 1, 1, &_ninB, NULL, "first matrix", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, mulInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); ninA = nrrdNew(); airMopAdd(mop, ninA, (airMopper)nrrdNuke, airMopAlways); ninB = nrrdNew(); airMopAdd(mop, ninB, (airMopper)nrrdNuke, airMopAlways); nmul = nrrdNew(); airMopAdd(mop, nmul, (airMopper)nrrdNuke, airMopAlways); nrrdConvert(ninA, _ninA, nrrdTypeDouble); nrrdConvert(ninB, _ninB, nrrdTypeDouble); if (ell_Nm_mul(nmul, ninA, ninB)) { airMopAdd(mop, err = biffGetDone(ELL), airFree, airMopAlways); fprintf(stderr, "%s: problem inverting:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nmul, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: problem saving output:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); exit(0); }
int unrrdu_minmaxMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *err, **inS; airArray *mop; int pret, blind8BitRange; unsigned int ni, ninLen; mop = airMopNew(); hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, "false", /* NOTE: not using nrrdStateBlind8BitRange here for consistency with previous behavior */ "whether to know the range of 8-bit data blindly " "(uchar is always [0,255], signed char is [-128,127])"); hestOptAdd(&opt, NULL, "nin1", airTypeString, 1, -1, &inS, NULL, "input nrrd(s)", &ninLen); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_minmaxInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); for (ni=0; ni<ninLen; ni++) { if (ninLen > 1) { fprintf(stdout, "==> %s <==\n", inS[ni]); } if (unrrdu_minmaxDoit(me, inS[ni], blind8BitRange, stdout)) { airMopAdd(mop, err = biffGetDone(me), airFree, airMopAlways); fprintf(stderr, "%s: trouble with \"%s\":\n%s", me, inS[ni], err); /* continue working on the remaining files */ } if (ninLen > 1 && ni < ninLen-1) { fprintf(stdout, "\n"); } } airMopOkay(mop); return 0; }
int unrrdu_unblockMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int type, pret; size_t blockSize; airArray *mop; OPT_ADD_TYPE(type, "type to unblock to", NULL); hestOptAdd(&opt, "bs", "blocksize", airTypeSize_t, 1, 1, &blockSize, "0", "Useful only if *output* type is also block: the size of " "blocks in output nrrd"); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_unblockInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); nout->blockSize = blockSize; airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdUnblock(nout, nin, type)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error unblocking nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_shrinkMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; Nrrd *nin, *nout; char *outS; hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", "input diffusion tensor volume, with 9 matrix components " "per sample", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, NULL, "output tensor volume, with the 7 values per sample"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_shrinkInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenShrink(nout, NULL, nin)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble shrinking tensors:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_ccadjMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; airArray *mop; int pret; unsigned int conny; hestOptAdd(&opt, "c,connect", "connectivity", airTypeUInt, 1, 1, &conny, NULL, "what kind of connectivity to use: the number of coordinates " "that vary in order to traverse the neighborhood of a given " "sample. In 2D: \"1\": 4-connected, \"2\": 8-connected"); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_ccadjInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdCCAdjacency(nout, nin, conny)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error finding adjacencies:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_evalpowMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; Nrrd *nin, *nout; char *outS; float expo; hestOptAdd(&hopt, "p", "power", airTypeFloat, 1, 1, &expo, NULL, "Power to which to raise all the eigenvalues."); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output tensor volume"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_evalpowInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenEigenvaluePower(nout, nin, expo)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
mrendUser * mrendUserNew() { mrendUser *uu; int i; uu = (mrendUser *)calloc(1, sizeof(mrendUser)); uu->nin = NULL; uu->kind = NULL; uu->rayStep = 0.0; uu->whatq = gageSclUnknown; uu->measr = nrrdMeasureUnknown; for (i=gageKernelUnknown+1; i<gageKernelLast; i++) { uu->ksp[i] = NULL; } uu->gctx0 = gageContextNew(); uu->hctx = hooverContextNew(); uu->outS = NULL; uu->mrmop = airMopNew(); airMopAdd(uu->mrmop, uu->gctx0, (airMopper)gageContextNix, airMopAlways); airMopAdd(uu->mrmop, uu->hctx, (airMopper)hooverContextNix, airMopAlways); return uu; }
int limnpu_vertsMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *hopt = NULL; char *err, *perr; airArray *mop; int pret; limnPolyData *pld; Nrrd *nout; char *out; hestOptAdd(&hopt, NULL, "input", airTypeOther, 1, 1, &pld, NULL, "input polydata filename", NULL, NULL, limnHestPolyDataLMPD); hestOptAdd(&hopt, NULL, "output", airTypeString, 1, 1, &out, NULL, "output nrrd filename"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(myinfo); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNix, airMopAlways); /* NOT nrrdNuke */ if (nrrdWrap_va(nout, pld->xyzw, nrrdTypeFloat, 2, 4, pld->xyzwNum) || nrrdSave(out, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble:%s", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_i2wMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; airArray *mop; int pret; char *err; int center; double minPos, maxPos, pos, indx, size; mop = airMopNew(); hestOptAdd(&opt, NULL, "center", airTypeEnum, 1, 1, ¢er, NULL, "which centering applies to the quantized position.\n " "Possibilities are:\n " "\b\bo \"cell\": for histogram bins, quantized values, and " "pixels-as-squares\n " "\b\bo \"node\": for non-trivially interpolated " "sample points", NULL, nrrdCenter); hestOptAdd(&opt, NULL, "minPos", airTypeDouble, 1, 1, &minPos, NULL, "smallest position associated with index 0"); hestOptAdd(&opt, NULL, "maxPos", airTypeDouble, 1, 1, &maxPos, NULL, "highest position associated with highest index"); hestOptAdd(&opt, NULL, "num", airTypeDouble, 1, 1, &size, NULL, "number of intervals into which position has been quantized"); hestOptAdd(&opt, NULL, "index", airTypeDouble, 1, 1, &indx, NULL, "the input index position, to be converted to world"); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_i2wInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); pos = NRRD_POS(center, minPos, maxPos, size, indx); printf("%g\n", pos); airMopOkay(mop); return 0; }
int tend_evecrgbMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; tenEvecRGBParm *rgbp; Nrrd *nin, *nout; char *outS; mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); rgbp = tenEvecRGBParmNew(); airMopAdd(mop, rgbp, AIR_CAST(airMopper, tenEvecRGBParmNix), airMopAlways); hestOptAdd(&hopt, "c", "evec index", airTypeUInt, 1, 1, &(rgbp->which), NULL, "which eigenvector will be colored. \"0\" for the " "principal, \"1\" for the middle, \"2\" for the minor"); hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1, &(rgbp->aniso), NULL, "Which anisotropy to use for modulating the saturation " "of the colors. " TEN_ANISO_DESC, NULL, tenAniso); hestOptAdd(&hopt, "t", "thresh", airTypeDouble, 1, 1, &(rgbp->confThresh), "0.5", "confidence threshold"); hestOptAdd(&hopt, "bg", "background", airTypeDouble, 1, 1, &(rgbp->bgGray), "0", "gray level to use for voxels who's confidence is zero "); hestOptAdd(&hopt, "gr", "gray", airTypeDouble, 1, 1, &(rgbp->isoGray), "0", "the gray level to desaturate towards as anisotropy " "decreases (while confidence remains 1.0)"); hestOptAdd(&hopt, "gam", "gamma", airTypeDouble, 1, 1, &(rgbp->gamma), "1", "gamma to use on color components"); hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output image (floating point)"); USAGE(_tend_evecrgbInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenEvecRGB(nout, nin, rgbp)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble doing colormapping:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int tend_makeMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; Nrrd *nin[3], *nout; char *outS; hestOptAdd(&hopt, "i", "conf evals evecs", airTypeOther, 3, 3, nin, NULL, "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output image (floating point)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_makeInfoL); JUSTPARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenMake(nout, nin[0], nin[1], nin[2])) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble making tensor volume:\n%s\n", me, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int _nrrdReadNrrdParse_kinds (FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { char me[]="_nrrdReadNrrdParse_kinds", err[BIFF_STRLEN]; unsigned int ai; char *info, *tok, *last; airArray *mop; AIR_UNUSED(file); mop = airMopNew(); info = airStrdup(nio->line + nio->pos); airMopAdd(mop, info, airFree, airMopAlways); _CHECK_HAVE_DIM; for (ai=0; ai<nrrd->dim; ai++) { tok = airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last); if (!tok) { sprintf(err, "%s: couldn't extract string for kind %d of %d", me, ai+1, nrrd->dim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } if (!strcmp(tok, NRRD_UNKNOWN)) { nrrd->axis[ai].kind = nrrdKindUnknown; continue; } if (!strcmp(tok, NRRD_NONE)) { nrrd->axis[ai].center = nrrdKindUnknown; continue; } if (!(nrrd->axis[ai].kind = airEnumVal(nrrdKind, tok))) { sprintf(err, "%s: couldn't parse \"%s\" kind %d of %d", me, tok, ai+1, nrrd->dim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } if (airStrtok(!ai ? info : NULL, _nrrdFieldSep, &last)) { sprintf(err, "%s: seem to have more than expected %d kinds", me, nrrd->dim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* can't run this now because kinds can come before sizes, in which case the kind/size check in _nrrdFieldCheck_kinds will incorrectly flag an error ... if (_nrrdFieldCheck[nrrdField_kinds](nrrd, useBiff)) { sprintf(err, "%s: trouble", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } */ airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me, *err; hestOpt *hopt=NULL; airArray *mop; char *outS; Nrrd *_ncov, *ncov, *_nten[2], *nten[2], *nout; double *cc, *t0, *t1, *out, ww[21]; size_t nn, ii; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "i4", "volume", airTypeOther, 1, 1, &_ncov, NULL, "4th-order tensor volume", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "i2", "v0 v1", airTypeOther, 2, 2, _nten, NULL, "two 2nd-order tensor volumes", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "o", "filename", airTypeString, 1, 1, &outS, "-", "file to write output nrrd to"); hestParseOrDie(hopt, argc-1, argv+1, NULL, me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); if (tenTensorCheck(_nten[0], nrrdTypeDefault, AIR_TRUE, AIR_TRUE) || tenTensorCheck(_nten[1], nrrdTypeDefault, AIR_TRUE, AIR_TRUE)) { airMopAdd(mop, err = biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: didn't like input:\n%s\n", me, err); airMopError(mop); return 1; } if (!(4 == _ncov->dim && 21 == _ncov->axis[0].size)) { fprintf(stderr, "%s: didn't get a 4-D 21-by-X volume (got %u-D %u-by-X)\n", me, _ncov->dim, AIR_CAST(unsigned int, _ncov->axis[0].size)); airMopError(mop); return 1; }
int unrrdu_swapMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret; unsigned int ax[2]; airArray *mop; hestOptAdd(&opt, "a,axis", "axisA axisB", airTypeUInt, 2, 2, ax, NULL, "the two axes to switch (0-based numbering)"); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_swapInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdAxesSwap(nout, nin, ax[0], ax[1])) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error swapping nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int unrrdu_reshapeMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret; size_t *size; unsigned int sizeLen; airArray *mop; hestOptAdd(&opt, "s,size", "sz0 sz1 ", airTypeSize_t, 1, -1, &size, NULL, "new axes sizes", &sizeLen); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_reshapeInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdReshape_nva(nout, nin, sizeLen, size)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error reshaping nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt; hestParm *hparm; airArray *mop; char *err; Nrrd *nhist; double thresh, expo; me = argv[0]; mop = airMopNew(); hparm = hestParmNew(); hopt = NULL; airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways); hestOptAdd(&hopt, "i", "nhist", airTypeOther, 1, 1, &nhist, NULL, "input histogram", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "e", "expo", airTypeDouble, 1, 1, &expo, "2.0", "exponent to use for variance calculation"); hestParseOrDie(hopt, argc-1, argv+1, hparm, me, otsuInfo, AIR_TRUE, AIR_TRUE, AIR_TRUE); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); if (nrrdHistoThresholdOtsu(&thresh, nhist, expo)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s", me, err); airMopError(mop); return 1; } fprintf(stderr, "%s: threshold = %g\n", me, thresh); airMopOkay(mop); exit(0); }
int unrrdu_substMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; int pret; Nrrd *nin, *nsubst, *nout; airArray *mop; hestOptAdd(&opt, "s,subst", "subst", airTypeOther, 1, 1, &nsubst, NULL, "substition table to map input nrrd through", NULL, NULL, nrrdHestNrrd); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_substInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdApply1DSubstitution(nout, nin, nsubst)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble applying SUBST:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }