Esempio n. 1
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;
}
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
baneGkms_miteMain(int argc, char **argv, char *me, hestParm *hparm) {
  hestOpt *opt = NULL;
  char *out, *perr, err[BIFF_STRLEN];
  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) {
      sprintf(err, "%s: trouble modifying opacity function nrrd", me);
      biffMove(BANE, err, NRRD); airMopError(mop); return 1;
    }
  }
  if (nrrdSave(out, nout, NULL)) {
    sprintf(err, "%s: trouble saving opacity function", me);
    biffMove(BANE, err, NRRD); airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Esempio n. 4
0
int
baneGkms_infoMain(int argc, const char **argv, const char *me,
                  hestParm *hparm) {
  hestOpt *opt = NULL;
  char *outS, *perr;
  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)) {
    biffAddf(BANE, "%s: trouble distilling histogram info", me);
    airMopError(mop); return 1;
  }

  if (nrrdSave(outS, nout, NULL)) {
    biffMovef(BANE, NRRD, "%s: trouble saving info file", me);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
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;
}
Esempio n. 10
0
int
limnpu_sortMain(int argc, char **argv, char *me, hestParm *hparm) {
  hestOpt *hopt = NULL;
  char *err, *perr;
  airArray *mop;
  int pret;

  limnPolyData *pld;
  Nrrd *nin;
  char *out;
  
  hestOptAdd(&hopt, NULL, "input lpld", airTypeOther, 1, 1, &pld, NULL,
             "input polydata filename",
             NULL, NULL, limnHestPolyDataLMPD);
  hestOptAdd(&hopt, NULL, "input nrrd", airTypeOther, 1, 1, &nin, NULL,
             "input nrrd filename",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, NULL, "output", airTypeString, 1, 1, &out, NULL,
             "output lpld filename");
  
  mop = airMopNew();
  airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);

  USAGE(myinfo);
  PARSE();
  airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);

  if (limnPolyDataPrimitiveSort(pld, nin)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:%s", me, err);
    airMopError(mop);
    return 1;
  }

  if (limnPolyDataSave(out, pld)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:%s", me, err);
    airMopError(mop);
    return 1;
  }
  
  airMopOkay(mop);
  return 0;
}
Esempio n. 11
0
int
unrrdu_ccsettleMain(int argc, char **argv, char *me, hestParm *hparm) {
  hestOpt *opt = NULL;
  char *out, *err, *valS;
  Nrrd *nin, *nout, *nval=NULL;
  airArray *mop;
  int pret;

  mop = airMopNew();
  hestOptAdd(&opt, "i,input", "nin", airTypeOther, 1, 1, &nin, NULL,
             "input nrrd",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&opt, "v,values", "filename", airTypeString, 1, 1, &valS, "",
             "Giving a filename here allows you to save out the mapping "
             "from new (settled) values to old values, in the form of a "
             "1-D lookup table");
  OPT_ADD_NOUT(out, "output nrrd");
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);

  USAGE(_unrrdu_ccsettleInfoL);
  PARSE();
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);

  nout = nrrdNew();
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);

  if (nrrdCCSettle(nout, airStrlen(valS) ? &nval : NULL, nin)) {
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
    fprintf(stderr, "%s: error settling connected components:\n%s", me, err);
    airMopError(mop);
    return 1;
  }
  if (nval) {
    airMopAdd(mop, nval, (airMopper)nrrdNuke, airMopAlways);
  }

  if (airStrlen(valS)) {
    SAVE(valS, nval, NULL);
  }
  SAVE(out, nout, NULL);

  airMopOkay(mop);
  return 0;
}
Esempio n. 12
0
int
unrrdu_projectMain(int argc, const char **argv, const 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;
}
Esempio n. 13
0
/*
** this is a little messy: the pvl array is allocated and filled here
** because that's the most idiomatic extension of the way that
** gagePerVolumeNew() is both the allocator and the initializer. sigh.
*/
int
gageStackPerVolumeNew(gageContext *ctx,
                      gagePerVolume ***pvlP,
                      const Nrrd *const *nblur, unsigned int blnum,
                      const gageKind *kind) {
    char me[]="gageStackPerVolumeNew", err[BIFF_STRLEN];
    gagePerVolume **pvl;
    airArray *mop;
    unsigned int blidx;

    if (!( ctx && pvlP && nblur && kind )) {
        sprintf(err, "%s: got NULL pointer", me);
        biffAdd(GAGE, err);
        return 1;
    }
    if (!blnum) {
        sprintf(err, "%s: need non-zero num", me);
        biffAdd(GAGE, err);
        return 1;
    }

    mop = airMopNew();
    pvl = *pvlP = AIR_CAST(gagePerVolume **,
                           calloc(blnum, sizeof(gagePerVolume *)));
    if (!pvl) {
        sprintf(err, "%s: couldn't allocate %u pvl pointers", me, blnum);
        biffAdd(GAGE, err);
        airMopError(mop);
        return 1;
    }
    airMopAdd(mop, pvlP, (airMopper)airSetNull, airMopOnError);
    airMopAdd(mop, pvl, (airMopper)airFree, airMopOnError);
    for (blidx=0; blidx<blnum; blidx++) {
        if (!( pvl[blidx] = gagePerVolumeNew(ctx, nblur[blidx], kind) )) {
            sprintf(err, "%s: on pvl %u of %u", me, blidx, blnum);
            biffAdd(GAGE, err);
            airMopError(mop);
            return 1;
        }
    }

    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;
}
Esempio n. 15
0
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;
}
Esempio n. 16
0
int
rvaLattSpecParse(rvaLattSpec *lsp, const char *_str) {
  static const char me[]="rvaLattSpecParse";
  char *col, *pstr, *str;
  airArray *mop;
  int smeth;
  unsigned got;

  if (!(lsp && _str)) {
    biffAddf(RVA, "%s: got NULL pointer", me);
    return 1;
  }
  if (!( str = airStrdup(_str) )) {
    biffAddf(RVA, "%s: couldn't strdup", me);
    return 1;
  }
  mop = airMopNew();
  airMopAdd(mop, str, airFree, airMopAlways);

  col = strchr(str, ':');
  if (!col) {
    biffAddf(RVA, "%s: didn't see \":\" separator in \"%s\" between "
             "lattice specification method and parameters", me, _str);
    airMopError(mop); return 1;
  }
  *col = '\0';
  lsp->latt = airEnumVal(rvaLatt, str);
  if (rvaLattUnknown == lsp->latt) {
    biffAddf(RVA, "%s: didn't recognize \"%s\" as a %s", me,
             str, rvaLatt->name);
    airMopError(mop); return 1;
  }
  pstr = col + 1;
  got = airParseStrD(lsp->parm, pstr, ",", rvaLattParmNum[lsp->latt]);
  if (got != rvaLattParmNum[lsp->latt]) {
    biffAddf(RVA, "%s: got %u (not %u) parms in \"%s\"", me,
             got, rvaLattParmNum[lsp->latt], _str);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
Esempio n. 17
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;
}
Esempio n. 18
0
int
unrrdu_cksumMain(int argc, const char **argv, const char *me,
                 hestParm *hparm) {
  hestOpt *opt = NULL;
  char *err, **inS;
  airArray *mop;
  int pret, endian, printend;
  unsigned int ni, ninLen;

  mop = airMopNew();
  hestOptAdd(&opt, "en,endian", "end", airTypeEnum, 1, 1, &endian,
             airEnumStr(airEndian, airMyEndian()),
             "Endianness in which to compute CRC; \"little\" for Intel and "
             "friends; \"big\" for everyone else. "
             "Defaults to endianness of this machine",
             NULL, airEndian);
  hestOptAdd(&opt, "pen,printendian", "bool", airTypeBool, 1, 1, &printend,
             "false",
             "whether or not to indicate after the CRC value the endianness "
             "with which the CRC was computed; doing so clarifies "
             "that the CRC result depends on endianness and may remove "
             "confusion in comparing results on platforms of different "
             "endianness");
  hestOptAdd(&opt, NULL, "nin1", airTypeString, 1, -1, &inS, NULL,
             "input nrrd(s)", &ninLen);
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);

  USAGE(_unrrdu_cksumInfoL);
  PARSE();
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);

  for (ni=0; ni<ninLen; ni++) {
    if (unrrdu_cksumDoit(me, inS[ni], endian, printend, 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 */
    }
  }

  airMopOkay(mop);
  return 0;
}
Esempio n. 19
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;
}
Esempio n. 20
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;
}
Esempio n. 21
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;
}
Esempio n. 22
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;
}
Esempio n. 23
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;
}
Esempio n. 24
0
File: tile.c Progetto: BRAINSia/teem
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;
}
Esempio n. 25
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;
}
Esempio n. 26
0
int
main(int argc, const char **argv) {
  const char *me;
  airArray *mop;

  hestParm *hparm;
  unsigned int uci;
  FILE *out;
  int ret;

  AIR_UNUSED(argc);
  out = stdout;
  me = argv[0];
  mop = airMopNew();
  hparm = hestParmNew();
  airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);

  /* This just generates all the usage information for unu itself, and then
     for all the unu sub-commands.  The purpose is to exercise hest's
     generation of usage info for all the options, and to make sure (by human
     inspection now, later by something automated) that the use of stderr vs
     stdout, and return values, is consistent across all commands */

  fprintf(out, "%s: ################### BEGIN unu\n", me);
  unrrduUsageUnu("unu", hparm);
  fprintf(out, "%s: ################### END unu\n", me);

  uci = 0;
  do {
    fprintf(out, "%s: ################### BEGIN unu %s\n",
            me, unrrduCmdList[uci]->name);
    ret = unrrduCmdList[uci]->main(0, NULL, unrrduCmdList[uci]->name, hparm);
    fprintf(out, "%s: ################### END unu %s (ret=%d)\n",
            me, unrrduCmdList[uci]->name, ret);
    uci++;
  } while (unrrduCmdList[uci]);

  airMopOkay(mop);
  return 0;
}
Esempio n. 27
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;
}
Esempio n. 28
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;
}
Esempio n. 29
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;
}
Esempio n. 30
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;
}