int main(int argc, const char *argv[]) { const char *me; char *err, *outS; hestOpt *hopt=NULL; airArray *mop; limnPolyData *pld; FILE *file; Nrrd *nin; double thresh; int bitflag; me = argv[0]; hestOptAdd(&hopt, "vi", "nin", airTypeOther, 1, 1, &nin, NULL, "input values", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "pi", "lpld", airTypeOther, 1, 1, &pld, NULL, "input polydata", NULL, NULL, limnHestPolyDataLMPD); hestOptAdd(&hopt, "th", "thresh", airTypeDouble, 1, 1, &thresh, NULL, "threshold value"); hestOptAdd(&hopt, "o", "output LMPD", airTypeString, 1, 1, &outS, "out.lmpd", "output file to save LMPD into"); 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); bitflag = limnPolyDataInfoBitFlag(pld); fprintf(stderr, "!%s: bitflag = %d\n", me, bitflag); fprintf(stderr, "!%s: rgba %d, norm %d, tex2 %d\n", me, (1 << limnPolyDataInfoRGBA) & bitflag, (1 << limnPolyDataInfoNorm) & bitflag, (1 << limnPolyDataInfoTex2) & bitflag); file = airFopen(outS, stdout, "w"); if (!file) { fprintf(stderr, "%s: couldn't open \"%s\" for writing", me, outS); airMopError(mop); return 1; } airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (limnPolyDataClip(pld, nin, thresh) || limnPolyDataWriteLMPD(file, pld)) { airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways); fprintf(stderr, "%s: trouble:\n%s\n", me, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_histaxMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int type, bins, pret, blind8BitRange; unsigned int axis; double min, max; airArray *mop; NrrdRange *range; OPT_ADD_AXIS(axis, "axis to histogram along"); hestOptAdd(&opt, "b,bin", "bins", airTypeInt, 1, 1, &bins, NULL, "# of bins in histogram"); OPT_ADD_TYPE(type, "output type", "uchar"); hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan", "Value at low end of histogram. Defaults to lowest value " "found in input nrrd."); hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan", "Value at high end of histogram. Defaults to highest value " "found in input nrrd."); hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, nrrdStateBlind8BitRange ? "true" : "false", "Whether to know the range of 8-bit data blindly " "(uchar is always [0,255], signed char is [-128,127])."); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_histaxInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); range = nrrdRangeNew(min, max); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); nrrdRangeSafeSet(range, nin, blind8BitRange); if (nrrdHistoAxis(nout, nin, range, axis, bins, type)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error doing axis histogramming:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_anplotMain(int argc, const char **argv, const char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; int res, aniso, whole, nanout, hflip; Nrrd *nout; char *outS; hestOptAdd(&hopt, "r", "res", airTypeInt, 1, 1, &res, "256", "resolution of anisotropy plot"); hestOptAdd(&hopt, "w", NULL, airTypeInt, 0, 0, &whole, NULL, "sample the whole triangle of constant trace, " "instead of just the " "sixth of it in which the eigenvalues have the " "traditional sorted order. "); hestOptAdd(&hopt, "hflip", NULL, airTypeInt, 0, 0, &hflip, NULL, "flip the two bottom corners (swapping the place of " "linear and planar)"); hestOptAdd(&hopt, "nan", NULL, airTypeInt, 0, 0, &nanout, NULL, "set the pixel values outside the triangle to be NaN, " "instead of 0"); hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1, &aniso, NULL, "Which anisotropy metric to plot. " TEN_ANISO_DESC, NULL, tenAniso); hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", "output image (floating point)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_anplotInfoL); JUSTPARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenAnisoPlot(nout, aniso, res, hflip, whole, nanout)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble making plot:\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_anhistMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; int version, res, right; Nrrd *nin, *nout, *nwght; char *outS; hestOptAdd(&hopt, "v", "westin version", airTypeInt, 1, 1, &version, "1", "Which version of Westin's anisotropy metric triple " "to use, either \"1\" or \"2\""); hestOptAdd(&hopt, "w", "nweight", airTypeOther, 1, 1, &nwght, "", "how to weigh contributions to histogram. By default " "(not using this option), the increment is one bin count per " "sample, but by giving a nrrd, the value in the nrrd at the " "corresponding location will be the bin count increment ", NULL, NULL, nrrdHestNrrd); hestOptAdd(&hopt, "r", "res", airTypeInt, 1, 1, &res, NULL, "resolution of anisotropy plot"); hestOptAdd(&hopt, "right", NULL, airTypeInt, 0, 0, &right, NULL, "sample a right-triangle-shaped region, instead of " "a roughly equilateral triangle. "); 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)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_anhistInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenAnisoHistogram(nout, nin, nwght, right, version, res)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble making histogram:\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; }
unsigned int airParseStrS(char **out, const char *_s, const char *ct, unsigned int n, ...) { unsigned int i; int greedy; char *tmp, *s, *last; airArray *mop; va_list ap; /* grab "greedy" every time, prior to error checking */ va_start(ap, n); greedy = va_arg(ap, int); va_end(ap); /* if we got NULL, there's nothing to do */ if (!(out && _s && ct)) return 0; mop = airMopNew(); /* copy the input so that we don't change it */ s = airStrdup(_s); airMopMem(mop, &s, airMopAlways); /* keep calling airStrtok() until we have everything */ for (i=0; i<n; i++) { /* if n == 1, then with greediness, the whole string is used, and without greediness, we use airStrtok() to get only the first part of it */ if (n > 1 || !greedy) { tmp = airStrtok(i ? NULL : s, ct, &last); } else { tmp = s; } if (!tmp) { airMopError(mop); return i; } out[i] = airStrdup(tmp); if (!out[i]) { airMopError(mop); return i; } airMopMem(mop, out+i, airMopOnError); } airMopOkay(mop); return n; }
int unrrdu_axmergeMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout[2]; int *axes, pret, ni; unsigned int ii, jj, axesLen; airArray *mop; hestOptAdd(&opt, "a,axis", "ax0", airTypeInt, 1, -1, &axes, NULL, "axis (or axes) to merge. Each axis index identified is the " "lower of the pair of axes that will be merged. Saying \"-a 2\" " "means to merge axis 2 and axis 3 into axis 2. If multiple " "merges are to be done, the indices listed here are for " "the axes prior to any merging.", &axesLen); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_axmergeInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); airMopAdd(mop, nout[0]=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nout[1]=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); if (axesLen > 1) { /* sort merge axes into ascending order */ qsort(axes, axesLen, sizeof(*axes), nrrdValCompare[nrrdTypeInt]); } ni = 0; for (ii=0; ii<axesLen; ii++) { if (nrrdAxesMerge(nout[ni], !ii ? nin : nout[1-ni], axes[ii])) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error merging axes:\n%s", me, err); airMopError(mop); return 1; } for (jj=ii+1; jj<axesLen; jj++) { axes[jj] -= 1; } ni = 1-ni; } SAVE(out, nout[1-ni], NULL); airMopOkay(mop); return 0; }
int unrrdu_dhistoMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret, nolog, notick; unsigned int size; airArray *mop; double max; hestOptAdd(&opt, "h,height", "height", airTypeUInt, 1, 1, &size, NULL, "height of output image (horizontal size is determined by " "number of bins in input histogram)."); hestOptAdd(&opt, "nolog", NULL, airTypeInt, 0, 0, &nolog, NULL, "do not show the log-scaled histogram with decade tick-marks"); hestOptAdd(&opt, "notick", NULL, airTypeInt, 0, 0, ¬ick, NULL, "do not draw the log decade tick marks"); hestOptAdd(&opt, "max,maximum", "max # hits", airTypeDouble, 1, 1, &max, "nan", "constrain the top of the drawn histogram to be at this " "number of hits. This will either scale the drawn histogram " "downward or clip its top, depending on whether the given max " "is higher or lower than the actual maximum bin count. By " "not using this option (the default), the actual maximum bin " "count is used"); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_dhistoInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdHistoDraw(nout, nin, size, nolog ? AIR_FALSE : (notick ? 2 : AIR_TRUE), max)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error drawing histogram nrrd:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int ninspect_proj(Nrrd *nout, Nrrd *nin, int axis, int smart, float amount) { char me[]="ninspect_proj", err[BIFF_STRLEN]; airArray *mop; Nrrd *ntmpA, *ntmpB, *nrgb[3]; int bins; if (!(nout && nin)) { sprintf(err, "%s: got NULL pointer", me); biffAdd(NINSPECT, err); return 1; } if (!( AIR_IN_CL(0, axis, 2) )) { sprintf(err, "%s: given axis %d outside valid range [0,1,2]", me, axis); biffAdd(NINSPECT, err); return 1; } /* allocate a bunch of nrrds to use as basically temp variables */ mop = airMopNew(); airMopAdd(mop, ntmpA = nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, ntmpB = nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nrgb[0] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nrgb[1] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways); airMopAdd(mop, nrgb[2] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways); /* these arguments to nrrdHistoEq will control its behavior */ bins = 3000; /* equalization will use a histogram with this many bins */ /* the following idiom is one way of handling the fact that any non-trivial nrrd call can fail, and if it does, then any subsequent nrrd calls should be avoided (to be perfectly safe), so that you can get the error message from biff. Because of the left-to-right ordering ensured for logical expressions, this will all be called in sequence until one of them has a non-zero return. If he had exception handling, we'd put all the nrrd calls in one "try" block. */ if (nrrdProject(ntmpA, nin, axis, nrrdMeasureSum, nrrdTypeDefault) || nrrdHistoEq(ntmpB, ntmpA, NULL, bins, smart, amount) || nrrdQuantize(nrgb[0], ntmpB, NULL, 8) || nrrdProject(ntmpA, nin, axis, nrrdMeasureVariance, nrrdTypeDefault) || nrrdHistoEq(ntmpB, ntmpA, NULL, bins, smart, amount) || nrrdQuantize(nrgb[1], ntmpB, NULL, 8) || nrrdProject(ntmpA, nin, axis, nrrdMeasureMax, nrrdTypeDefault) || nrrdQuantize(nrgb[2], ntmpA, NULL, 8) || nrrdJoin(nout, (const Nrrd**)nrgb, 3, 0, AIR_TRUE)) { sprintf(err, "%s: trouble with nrrd operations", me); biffMove(NINSPECT, err, NRRD); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int _mossHestTransformParse (void *ptr, char *_str, char err[AIR_STRLEN_HUGE]) { char me[]="_mossHestTransformParse", *str; double **matP, tx, ty, sx, sy, angle, mat[6], shf, sha; airArray *mop; if (!(ptr && _str)) { sprintf(err, "%s: got NULL pointer", me); return 1; } matP = (double **)ptr; mop = airMopNew(); *matP = (double *)calloc(6, sizeof(double)); airMopMem(mop, matP, airMopOnError); str = airToLower(airStrdup(_str)); airMopMem(mop, &str, airMopAlways); if (!strcmp("identity", str)) { mossMatIdentitySet(*matP); } else if (1 == sscanf(str, "flip:%lf", &angle)) { mossMatFlipSet(*matP, angle); } else if (2 == sscanf(str, "translate:%lf,%lf", &tx, &ty)) { mossMatTranslateSet(*matP, tx, ty); } else if (2 == sscanf(str, "t:%lf,%lf", &tx, &ty)) { mossMatTranslateSet(*matP, tx, ty); } else if (1 == sscanf(str, "rotate:%lf", &angle)) { mossMatRotateSet(*matP, angle); } else if (1 == sscanf(str, "r:%lf", &angle)) { mossMatRotateSet(*matP, angle); } else if (2 == sscanf(str, "scale:%lf,%lf", &sx, &sy)) { mossMatScaleSet(*matP, sx, sy); } else if (2 == sscanf(str, "s:%lf,%lf", &sx, &sy)) { mossMatScaleSet(*matP, sx, sy); } else if (2 == sscanf(str, "shear:%lf,%lf", &shf, &sha)) { mossMatShearSet(*matP, shf, sha); } else if (6 == sscanf(str, "%lf,%lf,%lf,%lf,%lf,%lf", mat+0, mat+1, mat+2, mat+3, mat+4, mat+5)) { MOSS_MAT_COPY(*matP, mat); } else { sprintf(err, "%s: couldn't parse \"%s\" as a transform", me, _str); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int unrrdu_gammaMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; double min, max, gamma; airArray *mop; int pret, blind8BitRange; NrrdRange *range; hestOptAdd(&opt, "g,gamma", "gamma", airTypeDouble, 1, 1, &gamma, NULL, "gamma > 1.0 brightens; gamma < 1.0 darkens. " "Negative gammas invert values (like in xv). "); hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan", "Value to implicitly map to 0.0 prior to calling pow(). " "Defaults to lowest value found in input nrrd."); hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan", "Value to implicitly map to 1.0 prior to calling pow(). " "Defaults to highest value found in input nrrd."); hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, nrrdStateBlind8BitRange ? "true" : "false", "Whether to know the range of 8-bit data blindly " "(uchar is always [0,255], signed char is [-128,127])."); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_gammaInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); range = nrrdRangeNew(min, max); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); nrrdRangeSafeSet(range, nin, blind8BitRange); if (nrrdArithGamma(nout, nin, range, gamma)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error doing gamma:\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=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; }
int unrrdu_distMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, *nout; int pret; int E, typeOut, invert, sign; double thresh; airArray *mop; hestOptAdd(&opt, "th,thresh", "val", airTypeDouble, 1, 1, &thresh, NULL, "threshold value to separate inside from outside"); hestOptAdd(&opt, "t,type", "type", airTypeEnum, 1, 1, &typeOut, "float", "type to save output in", NULL, nrrdType); hestOptAdd(&opt, "sgn", NULL, airTypeInt, 0, 0, &sign, NULL, "also compute signed (negative) distances inside objects, " "instead of leaving them as zero"); hestOptAdd(&opt, "inv", NULL, airTypeInt, 0, 0, &invert, NULL, "values *below* threshold are considered interior to object. " "By default (not using this option), values above threshold " "are considered interior. "); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_distInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (sign) { E = nrrdDistanceL2Signed(nout, nin, typeOut, NULL, thresh, !invert); } else { E = nrrdDistanceL2(nout, nin, typeOut, NULL, thresh, !invert); } if (E) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error doing distance transform:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; }
int tend_evqMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; int which, aniso, dontScaleByAniso; Nrrd *nin, *nout; char *outS; hestOptAdd(&hopt, "c", "evec index", airTypeInt, 1, 1, &which, "0", "Which eigenvector should be quantized: \"0\" for the " "direction of fastest diffusion (eigenvector associated " "with largest eigenvalue), \"1\" or \"2\" for other two " "eigenvectors (associated with middle and smallest eigenvalue)"); hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1, &aniso, NULL, "Which anisotropy metric to scale the eigenvector " "with. " TEN_ANISO_DESC, NULL, tenAniso); hestOptAdd(&hopt, "ns", NULL, airTypeInt, 0, 0, &dontScaleByAniso, NULL, "Don't attenuate the color by anisotropy. By default (not " "using this option), regions with low or no anisotropy are " "very dark colors or black"); 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)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_evqInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenEvqVolume(nout, nin, which, aniso, !dontScaleByAniso)) { airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); fprintf(stderr, "%s: trouble quantizing eigenvectors:\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; }
/* ******** nrrdSave ** ** save a given nrrd to a given filename, with cleverness to guess ** format if not specified by the caller ** ** currently, for NRRD format files, we play the detached header game ** whenever the filename ends in NRRD_EXT_NHDR, and when we play this ** game, the data file is ALWAYS header relative. */ int nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) { static const char me[]="nrrdSave"; FILE *file; airArray *mop; if (!(nrrd && filename)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } mop = airMopNew(); if (!nio) { nio = nrrdIoStateNew(); if (!nio) { biffAddf(NRRD, "%s: couldn't alloc local NrrdIoState", me); return 1; } airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); } if (_nrrdEncodingMaybeSet(nio) || _nrrdFormatMaybeGuess(nrrd, nio, filename)) { biffAddf(NRRD, "%s: ", me); airMopError(mop); return 1; } if (nrrdFormatNRRD == nio->format && airEndsWith(filename, NRRD_EXT_NHDR)) { nio->detachedHeader = AIR_TRUE; _nrrdSplitName(&(nio->path), &(nio->base), filename); /* nix the ".nhdr" suffix */ nio->base[strlen(nio->base) - strlen(NRRD_EXT_NHDR)] = 0; /* nrrdFormatNRRD->write will do the rest */ } else { nio->detachedHeader = AIR_FALSE; } if (!( file = airFopen(filename, stdout, "wb") )) { biffAddf(NRRD, "%s: couldn't fopen(\"%s\",\"wb\"): %s", me, filename, strerror(errno)); airMopError(mop); return 1; } airMopAdd(mop, file, (airMopper)airFclose, airMopAlways); if (nrrdWrite(file, nrrd, nio)) { biffAddf(NRRD, "%s:", me); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
miteThread * miteThreadNew() { char me[]="miteThreadNew", err[BIFF_STRLEN]; miteThread *mtt; int ii; mtt = (miteThread *)calloc(1, sizeof(miteThread)); if (!mtt) { sprintf(err, "%s: couldn't calloc miteThread", me); biffAdd(MITE, err); return NULL; } mtt->rmop = airMopNew(); if (!mtt->rmop) { sprintf(err, "%s: couldn't calloc thread's mop", me); biffAdd(MITE, err); airFree(mtt); return NULL; } mtt->gctx = NULL; mtt->ansScl = mtt->ansVec = mtt->ansTen = NULL; mtt->_normal = NULL; mtt->shadeVec0 = NULL; mtt->shadeVec1 = NULL; mtt->shadeScl0 = NULL; mtt->shadeScl1 = NULL; /* were miteVal a full-fledged gageKind, the following would be done by gagePerVolumeNew */ mtt->ansMiteVal = (double *)calloc(gageKindTotalAnswerLength(miteValGageKind), sizeof(double)); mtt->directAnsMiteVal = (double **)calloc(miteValGageKind->itemMax+1, sizeof(double*)); if (!(mtt->ansMiteVal && mtt->directAnsMiteVal)) { sprintf(err, "%s: couldn't calloc miteVal answer arrays", me); biffAdd(MITE, err); return NULL; } for (ii=0; ii<=miteValGageKind->itemMax; ii++) { mtt->directAnsMiteVal[ii] = mtt->ansMiteVal + gageKindAnswerOffset(miteValGageKind, ii); } mtt->verbose = 0; mtt->skip = 0; mtt->thrid = -1; mtt->ui = mtt->vi = -1; mtt->raySample = 0; mtt->samples = 0; mtt->stage = NULL; /* mtt->range[], rayStep, V, RR, GG, BB, TT initialized in miteRayBegin or in miteSample */ return mtt; }
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, *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 baneGkms_miteMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *perr; Nrrd *nin, *nout; airArray *mop; int pret, E; hestOptAdd(&opt, "i", "opacIn", airTypeOther, 1, 1, &nin, NULL, "input opacity function (1 or 2 dimensional), from " "\"gkms opac\"", NULL, NULL, nrrdHestNrrd); hestOptAdd(&opt, "o", "opacOut", airTypeString, 1, 1, &out, NULL, "output opacity function filename"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_baneGkms_miteInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); if (1 == nin->axis[0].size && nin->axis[0].label && !strcmp("A", nin->axis[0].label)) { fprintf(stderr, "%s: already\n", me); nout = nin; } else { nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); E = 0; if (!E) E |= nrrdAxesInsert(nout, nin, 0); if (!E) E |= !(nout->axis[0].label = airStrdup("A")); if (!E) E |= !(nout->axis[1].label = airStrdup("gage(v)")); if (3 == nout->dim) { if (!E) E |= !(nout->axis[2].label = airStrdup("gage(gm)")); } if (E) { biffMovef(BANE, NRRD, "%s: trouble modifying opacity function nrrd", me); airMopError(mop); return 1; } } if (nrrdSave(out, nout, NULL)) { biffMovef(BANE, NRRD, "%s: trouble saving opacity function", me); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int main(int argc, const char *argv[]) { const char *me; char *err; limnCamera *cam; float mat[16]; hestOpt *hopt=NULL; airArray *mop; mop = airMopNew(); cam = limnCameraNew(); airMopAdd(mop, cam, (airMopper)limnCameraNix, airMopAlways); me = argv[0]; hestOptAdd(&hopt, "fr", "eye pos", airTypeDouble, 3, 3, cam->from, NULL, "camera eye point"); hestOptAdd(&hopt, "at", "at pos", airTypeDouble, 3, 3, cam->at, "0 0 0", "camera look-at point"); hestOptAdd(&hopt, "up", "up dir", airTypeDouble, 3, 3, cam->up, "0 0 1", "camera pseudo up vector"); hestOptAdd(&hopt, "rh", NULL, airTypeInt, 0, 0, &(cam->rightHanded), NULL, "use a right-handed UVN frame (V points down)"); 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); cam->neer = -1; cam->dist = 0; cam->faar = 1; cam->atRelative = AIR_TRUE; if (limnCameraUpdate(cam)) { fprintf(stderr, "%s: trouble:\n%s\n", me, err = biffGet(LIMN)); free(err); return 1; } printf("%s: W2V:\n", me); ELL_4M_COPY(mat, cam->W2V); ell_4m_print_f(stdout, mat); printf("\n"); printf("%s: V2W:\n", me); ELL_4M_COPY(mat, cam->V2W); ell_4m_print_f(stdout, mat); airMopOkay(mop); return 0; }
int unrrdu_joinMain(int argc, const char **argv, const char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err, *label; Nrrd **nin; Nrrd *nout; int incrDim, pret; unsigned int ninLen, axis; double mm[2], spc; airArray *mop; hparm->respFileEnable = AIR_TRUE; hestOptAdd(&opt, "i,input", "nin0", airTypeOther, 1, -1, &nin, NULL, "everything to be joined together", &ninLen, NULL, nrrdHestNrrd); OPT_ADD_AXIS(axis, "axis to join along"); hestOptAdd(&opt, "incr", NULL, airTypeInt, 0, 0, &incrDim, NULL, "in situations where the join axis is *not* among the existing " "axes of the input nrrds, then this flag signifies that the join " "axis should be *inserted*, and the output dimension should " "be one greater than input dimension. Without this flag, the " "nrrds are joined side-by-side, along an existing axis."); hestOptAdd(&opt, "l,label", "label", airTypeString, 1, 1, &label, "", "label to associate with join axis"); hestOptAdd(&opt, "mm,minmax", "min max", airTypeDouble, 2, 2, mm, "nan nan", "min and max values along join axis"); hestOptAdd(&opt, "sp,spacing", "spc", airTypeDouble, 1, 1, &spc, "nan", "spacing between samples along join axis"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_joinInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (nrrdJoin(nout, AIR_CAST(const Nrrd*const*, nin), ninLen, axis, incrDim)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: error joining nrrds:\n%s", me, err); airMopError(mop); return 1; }
int baneGkms_infoMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *outS, *perr, err[BIFF_STRLEN]; Nrrd *hvol, *nout; airArray *mop; int pret, one, measr; hestOptAdd(&opt, "m", "measr", airTypeEnum, 1, 1, &measr, "mean", "How to project along the 2nd derivative axis. Possibilities " "include:\n " "\b\bo \"mean\": average value\n " "\b\bo \"median\": value at 50th percentile\n " "\b\bo \"mode\": most common value\n " "\b\bo \"min\", \"max\": probably not useful", NULL, baneGkmsMeasr); hestOptAdd(&opt, "one", NULL, airTypeInt, 0, 0, &one, NULL, "Create 1-dimensional info file; default is 2-dimensional"); hestOptAdd(&opt, "i", "hvolIn", airTypeOther, 1, 1, &hvol, NULL, "input histogram volume (from \"gkms hvol\")", NULL, NULL, nrrdHestNrrd); hestOptAdd(&opt, "o", "infoOut", airTypeString, 1, 1, &outS, NULL, "output info file, used by \"gkms pvg\" and \"gkms opac\""); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_baneGkms_infoInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (baneOpacInfo(nout, hvol, one ? 1 : 2, measr)) { sprintf(err, "%s: trouble distilling histogram info", me); biffAdd(BANE, err); airMopError(mop); return 1; } if (nrrdSave(outS, nout, NULL)) { sprintf(err, "%s: trouble saving info file", me); biffMove(BANE, err, NRRD); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int tend_anscaleMain(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; float scale; int fixDet, makePositive; hestOptAdd(&hopt, "s", "scale", airTypeFloat, 1, 1, &scale, NULL, "Amount by which to scale deviatoric component of tensor."); hestOptAdd(&hopt, "fd", NULL, airTypeInt, 0, 0, &fixDet, NULL, "instead of fixing the per-sample trace (the default), fix the " "determinant (ellipsoid volume)"); hestOptAdd(&hopt, "mp", NULL, airTypeInt, 0, 0, &makePositive, NULL, "after changing the eigenvalues of the tensor, enforce their " "non-negative-ness. By default, no such constraint is imposed."); 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)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_anscaleInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenAnisoScale(nout, nin, scale, fixDet, makePositive)) { 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; }
miteUser * miteUserNew() { miteUser *muu; int i; muu = (miteUser *)calloc(1, sizeof(miteUser)); if (!muu) return NULL; muu->umop = airMopNew(); muu->nsin = NULL; muu->nvin = NULL; muu->ntin = NULL; muu->ntxf = NULL; /* managed by user (with miter: hest) */ muu->nout = NULL; /* managed by user (with miter: hest) */ muu->debug = NULL; muu->debugArr = NULL; muu->ndebug = NULL; /* not allocated until the debug pixel is rendered, see miteRayBegin */ muu->ntxfNum = 0; muu->shadeStr[0] = 0; muu->normalStr[0] = 0; for (i=0; i<MITE_RANGE_NUM; i++) { muu->rangeInit[i] = 1.0; } muu->normalSide = miteDefNormalSide; muu->refStep = miteDefRefStep; muu->rayStep = AIR_NAN; muu->opacMatters = miteDefOpacMatters; muu->opacNear1 = miteDefOpacNear1; muu->hctx = hooverContextNew(); ELL_3V_SET(muu->fakeFrom, AIR_NAN, AIR_NAN, AIR_NAN); ELL_3V_SET(muu->vectorD, 0, 0, 0); airMopAdd(muu->umop, muu->hctx, (airMopper)hooverContextNix, airMopAlways); for (i=0; i<GAGE_KERNEL_NUM; i++) { muu->ksp[i] = NULL; } muu->gctx0 = gageContextNew(); airMopAdd(muu->umop, muu->gctx0, (airMopper)gageContextNix, airMopAlways); gageParmSet(muu->gctx0, gageParmRequireAllSpacings, AIR_FALSE); muu->lit = limnLightNew(); airMopAdd(muu->umop, muu->lit, (airMopper)limnLightNix, airMopAlways); muu->normalSide = miteDefNormalSide; muu->verbUi = muu->verbVi = -1; muu->rendTime = 0; muu->sampRate = 0; return muu; }
int tend_normMain(int argc, char **argv, char *me, hestParm *hparm) { int pret; hestOpt *hopt = NULL; char *perr, *err; airArray *mop; Nrrd *nin, *nout; char *outS; float amount, target; double weight[3]; hestOptAdd(&hopt, "w", "w0 w1 w2", airTypeDouble, 3, 3, weight, NULL, "relative weights to put on major, medium, and minor " "eigenvalue when performing normalization (internally " "rescaled to have a 1.0 L1 norm). These weightings determine " "the tensors's \"size\"."); hestOptAdd(&hopt, "a", "amount", airTypeFloat, 1, 1, &amount, "1.0", "how much of the normalization to perform"); hestOptAdd(&hopt, "t", "target", airTypeFloat, 1, 1, &target, "1.0", "target size, post normalization"); 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)"); mop = airMopNew(); airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); USAGE(_tend_normInfoL); PARSE(); airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); if (tenSizeNormalize(nout, nin, weight, amount, target)) { 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 baneGkmsParseBEF(void *ptr, char *str, char err[AIR_STRLEN_HUGE]) { char me[]="baneGkmsParseBEF", mesg[AIR_STRLEN_MED], *nerr; float cent, width, shape, alpha, off, *bef; Nrrd **nrrdP; airArray *mop; if (!(ptr && str)) { sprintf(err, "%s: got NULL pointer", me); return 1; } mop = airMopNew(); nrrdP = (Nrrd **)ptr; airMopAdd(mop, *nrrdP=nrrdNew(), (airMopper)nrrdNuke, airMopOnError); if (4 == sscanf(str, "%g,%g,%g,%g", &shape, &width, ¢, &alpha)) { /* its a valid BEF specification, we make the nrrd ourselves */ if (nrrdMaybeAlloc_va(*nrrdP, nrrdTypeFloat, 2, AIR_CAST(size_t, 2), AIR_CAST(size_t, 6))) { airMopAdd(mop, nerr = biffGetDone(NRRD), airFree, airMopOnError); strncpy(err, nerr, AIR_STRLEN_HUGE-1); airMopError(mop); return 1; } bef = (float *)((*nrrdP)->data); off = AIR_CAST(float, AIR_AFFINE(0.0, shape, 1.0, 0.0, width/2)); /* positions */ bef[0 + 2*0] = cent - 2*width; bef[0 + 2*1] = cent - width/2 - off; bef[0 + 2*2] = cent - width/2 + off; bef[0 + 2*3] = cent + width/2 - off; bef[0 + 2*4] = cent + width/2 + off; bef[0 + 2*5] = cent + 2*width; if (bef[0 + 2*1] == bef[0 + 2*2]) bef[0 + 2*1] -= 0.001f; if (bef[0 + 2*2] == bef[0 + 2*3]) bef[0 + 2*2] -= 0.001f; if (bef[0 + 2*3] == bef[0 + 2*4]) bef[0 + 2*4] += 0.001f; /* opacities */ bef[1 + 2*0] = 0.0; bef[1 + 2*1] = 0.0; bef[1 + 2*2] = alpha; bef[1 + 2*3] = alpha; bef[1 + 2*4] = 0.0; bef[1 + 2*5] = 0.0; /* to tell gkms opac that this came from four floats */ (*nrrdP)->ptr = *nrrdP; } else { if (nrrdLoad(*nrrdP, str, NULL)) {
int _nrrdReadNrrdParse_centers (FILE *file, Nrrd *nrrd, NrrdIoState *nio, int useBiff) { char me[]="_nrrdReadNrrdParse_centers", err[BIFF_STRLEN]; unsigned int ai; char *tok, *info, *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 center %d of %d", me, ai+1, nrrd->dim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } if (!strcmp(tok, NRRD_UNKNOWN)) { nrrd->axis[ai].center = nrrdCenterUnknown; continue; } if (!strcmp(tok, NRRD_NONE)) { nrrd->axis[ai].center = nrrdCenterUnknown; continue; } if (!(nrrd->axis[ai].center = airEnumVal(nrrdCenter, tok))) { sprintf(err, "%s: couldn't parse center \"%s\" for axis %d", me, tok, ai); 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 centers", me, nrrd->dim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } if (_nrrdFieldCheck[nrrdField_centers](nrrd, useBiff)) { sprintf(err, "%s: trouble", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
/* ** note that if tgparm->insertZeroVec, there will be one sample more ** along axis 1 of nout than the requested #gradients "num" */ int tenGradientGenerate(Nrrd *nout, unsigned int num, tenGradientParm *tgparm) { static const char me[]="tenGradientGenerate"; Nrrd *nin; airArray *mop; if (!(nout && tgparm)) { biffAddf(TEN, "%s: got NULL pointer", me); return 1; } if (!( num >= 3 )) { biffAddf(TEN, "%s: can generate minimum of 3 gradient directions " "(not %d)", me, num); return 1; } mop = airMopNew(); nin = nrrdNew(); airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways); if (tenGradientRandom(nin, num, tgparm->seed) || tenGradientDistribute(nout, nin, tgparm)) { biffAddf(TEN, "%s: trouble", me); airMopError(mop); return 1; } if (tgparm->insertZeroVec) { /* this is potentially confusing: the second axis (axis 1) is going to come back one longer than the requested number of gradients! */ Nrrd *ntmp; ptrdiff_t padMin[2] = {0, -1}, padMax[2]; padMax[0] = AIR_CAST(ptrdiff_t, nout->axis[0].size-1); padMax[1] = AIR_CAST(ptrdiff_t, num-1); ntmp = nrrdNew(); airMopAdd(mop, ntmp, (airMopper)nrrdNuke, airMopAlways); if (nrrdPad_nva(ntmp, nout, padMin, padMax, nrrdBoundaryPad, 0.0) || nrrdCopy(nout, ntmp)) { biffMovef(TEN, NRRD, "%s: trouble adding zero vector", me); airMopError(mop); return 1; } } airMopOkay(mop); return 0; }
int tkwbWriteIndex(char *_index, tkwbSlide **slide, char *tag[TKWB_TAG_MAX+1]) { char me[]="tkwbWriteIndex", err[BIFF_STRLEN], *repl, *index, tmp[AIR_STRLEN_MED]; int replLen, si; airArray *mop; mop = airMopNew(); replLen = 0; replLen += strlen("<ol>\n"); for (si=0; slide[si]; si++) { replLen += (strlen("<li> <a href=\"slideXXX.html\"></a>\n") + strlen(slide[si]->title)); } replLen += strlen("</ol>\n"); if (!(repl = (char*)calloc(replLen+1, sizeof(char)))) { sprintf(err, "%s: couldn't allocate link buffer!", me); biffAdd(TKWB, err); airMopError(mop); return 1; } airMopAdd(mop, repl, airFree, airMopAlways); strcpy(repl, "<ol>\n"); for (si=0; slide[si]; si++) { sprintf(tmp, "<li> <a href=\"slide%03d.html\">%s</a>\n", si+1, slide[si]->title); strcat(repl, tmp); } strcat(repl, "</ol>"); index = airStrdup(_index); tkwbStringSubst(&index, tag[TKWB_TAG_TOC], repl); airMopAdd(mop, index, airFree, airMopAlways); if (tkwbWriteStringToFile("index.html", index)) { sprintf(err, "%s: couldn't write \"index.html\"", me); biffAdd(TKWB, err); airMopError(mop); return 1; } airMopOkay(mop); return 0; }
int nrrdSaveMulti(const char *fnameFormat, const Nrrd *const *nin, unsigned int ninLen, unsigned int numStart, NrrdIoState *nio) { static const char me[]="nrrdSaveMulti"; char *fname; airArray *mop; unsigned int nii; if (!( fnameFormat && nin )) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (!( _nrrdContainsPercentThisAndMore(fnameFormat, 'u') )) { biffAddf(NRRD, "%s: given format \"%s\" doesn't seem to " "have the \"%%u\" conversion specification to sprintf " "an unsigned int\n", me, fnameFormat); return 1; } mop = airMopNew(); /* should be big enough for the number replacing the format sequence */ fname = AIR_CAST(char *, malloc(strlen(fnameFormat) + 128)); if (!(fname)) { biffAddf(NRRD, "%s: couldn't allocate local fname buffer", me); airMopError(mop); return 1; } airMopAdd(mop, fname, airFree, airMopAlways); for (nii=0; nii<ninLen; nii++) { unsigned int num; num = numStart + nii; sprintf(fname, fnameFormat, num); if (nrrdSave(fname, nin[nii], nio)) { biffAddf(NRRD, "%s: trouble saving nin[%u] to %s", me, nii, fname); airMopError(mop); return 1; } /* HEY: GLK hopes that the nio doesn't have any state that needs resetting, but we can't call nrrdIoStateInit() because that would negate the purpose of sending in the nio for all but the first saved nrrd */ } airMopOkay(mop); return 0; }
int main(int argc, char *argv[]) { char *me; hestOpt *hopt=NULL; airArray *mop; pushEnergySpec *ensp; unsigned int pi, xi, nn; double xx, supp, del; mop = airMopNew(); me = argv[0]; hestOptAdd(&hopt, "energy", "spec", airTypeOther, 1, 1, &ensp, NULL, "specification of force function to use", NULL, NULL, pushHestEnergySpec); 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); fprintf(stderr, "%s: parsed energy \"%s\", with %u parms.\n", me, ensp->energy->name, ensp->energy->parmNum); for (pi=0; pi<ensp->energy->parmNum; pi++) { fprintf(stderr, "%u: %g\n", pi, ensp->parm[pi]); } fprintf(stderr, "\n"); nn = 600; supp = ensp->energy->support(ensp->parm); del = AIR_DELTA(0, 2, nn, 0, supp); for (xi=1; xi<nn; xi++) { double x0, x1, ee, ff, e0, e1, dummy; xx = AIR_AFFINE(0, xi, nn, 0, supp); x1 = AIR_AFFINE(0, xi+1, nn, 0, supp); x0 = AIR_AFFINE(0, xi-1, nn, 0, supp); ensp->energy->eval(&e1, &dummy, x1, ensp->parm); ensp->energy->eval(&e0, &dummy, x0, ensp->parm); ensp->energy->eval(&ee, &ff, xx, ensp->parm); printf("%g %g %g %g\n", xx, ee, ff, (e1 - e0)/del); } airMopOkay(mop); return 0; }