示例#1
0
int
_alanPerIteration(alanContext *actx, int iter) {
  char me[]="_alanPerIteration", fname[AIR_STRLEN_MED];
  Nrrd *nslc, *nimg;
  
  if (!(actx->saveInterval || actx->frameInterval)) {
    if (actx->verbose && !(iter % 100)) {
      fprintf(stderr, "%s: iter = %d, averageChange = %g\n",
              me, iter, actx->averageChange);
    }
  }
  if (actx->saveInterval && !(iter % actx->saveInterval)) {
    sprintf(fname, "%06d.nrrd", actx->constFilename ? 0 : iter);
    nrrdSave(fname, actx->_nlev[(iter+1) % 2], NULL);
    fprintf(stderr, "%s: iter = %d, averageChange = %g, saved %s\n",
            me, iter, actx->averageChange, fname);
  }
  if (actx->frameInterval && !(iter % actx->frameInterval)) {
    nrrdSlice(nslc=nrrdNew(), actx->_nlev[(iter+1) % 2], 0, 0);
    nrrdQuantize(nimg=nrrdNew(), nslc, NULL, 8);
    sprintf(fname, (2 == actx->dim ? "%06d.png" : "%06d.nrrd"),
            actx->constFilename ? 0 : iter);
    nrrdSave(fname, nimg, NULL);
    fprintf(stderr, "%s: iter = %d, averageChange = %g, saved %s\n",
            me, iter, actx->averageChange, fname);
    nrrdNuke(nslc);
    nrrdNuke(nimg);
  }
  return 0;
}
示例#2
0
void WriteFile(Nrrd *nData, int type, char *Outfile){
    if(type == 0){
        if(nrrdSave(Outfile, nData, NULL)) {
            exit(1);
        }
    }
    else{
        Nrrd *ntmp = nrrdNew();
        nrrdQuantize(ntmp, nData, NULL, 8);
        nrrdSave(Outfile, ntmp, NULL);
    }
    nrrdNuke(nData);
    return;
}
示例#3
0
int
main(int argc, char *argv[]) {
  char *me, *ninName, *noutName, *err;
  Nrrd *nin;

  me = argv[0];
  if (3 != argc) {
    /*                       0   1     2   (3) */
    fprintf(stderr, "usage: %s <nin> <nout>\n", me);
    exit(1);
  }
  ninName = argv[1];
  noutName = argv[2];
  if (nrrdLoad(nin=nrrdNew(), ninName, NULL)) {
    fprintf(stderr, "%s: couldn't open nrrd \"%s\":\n%s", me, ninName,
            err = biffGetDone(NRRD));
    free(err); exit(1);
  }
  if (nrrdSave(noutName, nin, NULL)) {
    fprintf(stderr, "%s: trouble saving nrrd to \"%s\":\n%s", me, noutName,
            err = biffGetDone(NRRD));
    free(err); exit(1);
  }
  nrrdNuke(nin);
  exit(0);
}
示例#4
0
文件: tinfo.c 项目: rblake/seg3d2
int
main(int argc, char *argv[]) {
  Nrrd *hvol, *info;
  char *iStr, *dStr, *oStr;
  int dim;

  me = argv[0];
  if (argc != 4)
    usage();
  iStr = argv[1];
  dStr = argv[2];
  oStr = argv[3];

  if (nrrdLoad(hvol=nrrdNew(), iStr, NULL)) {
    fprintf(stderr, "%s: trouble reading hvol:\n%s\n", me, biffGet(NRRD));
    usage();
  }
  if (1 != sscanf(dStr, "%d", &dim)) {
    fprintf(stderr, "%s: trouble parsing %s as an int\n", me, dStr);
    usage();
  }
  if (baneOpacInfo(info = nrrdNew(), hvol, dim, nrrdMeasureHistoMean)) {
    fprintf(stderr, "%s: trouble calculting %d-D opacity info:\n%s\n",
            me, dim, biffGet(BANE));
    exit(1);
  }
  if (nrrdSave(oStr, info, NULL)) {
    fprintf(stderr, "%s: trouble saving nrrd to %s:\n%s\n", me, oStr,
            biffGet(NRRD));
    exit(1);
  }
  nrrdNuke(hvol);
  nrrdNuke(info);
  exit(0);
}
示例#5
0
int
main(int argc, char *argv[]) {
  Nrrd *map, *ppm;
  NrrdRange *range;

  AIR_UNUSED(argc);
  me = argv[0];

  if (limnEnvMapFill(map=nrrdNew(), cb, limnQN16checker, NULL)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(LIMN));
    exit(1);
  }
  range = nrrdRangeNew(0, 1);
  if (nrrdQuantize(ppm=nrrdNew(), map, range, 8)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(NRRD));
    exit(1);
  }
  if (nrrdSave("map.ppm", ppm, NULL)) {
    fprintf(stderr, "%s: trouble:\n%s", me, biffGet(NRRD));
    exit(1);
  }

  nrrdNuke(map);
  nrrdNuke(ppm);
  nrrdRangeNix(range);
  exit(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;
}
示例#7
0
void
demoIO(char *filename)
{
  char me[]="demoIO", newname[]="foo.nrrd", *err, *key, *val;
  int kvn, kvi;
  Nrrd *nin;

  /* create a nrrd; at this point this is just an empty container */
  nin = nrrdNew();

  /* read in the nrrd from file */
  if (nrrdLoad(nin, filename, NULL))
  {
    err = biffGetDone(NRRD);
    fprintf(stderr, "%s: trouble reading \"%s\":\n%s", me, filename, err);
    free(err);
    return;
  }

  /* say something about the array */
  printf("%s: \"%s\" is a %d-dimensional nrrd of type %d (%s)\n",
         me, filename, nin->dim, nin->type,
         airEnumStr(nrrdType, nin->type));
  printf("%s: the array contains %d elements, each %d bytes in size\n",
         me, (int)nrrdElementNumber(nin), (int)nrrdElementSize(nin));

  /* print out the key/value pairs present */
  kvn = nrrdKeyValueSize(nin);
  if (kvn)
  {
    for (kvi=0; kvi<kvn; kvi++)
    {
      nrrdKeyValueIndex(nin, &key, &val, kvi);
      printf("%s: key:value %d = %s:%s\n", me, kvi, key, val);
      free(key);
      free(val);
      key = val = NULL;
    }
  }

  /* modify key/value pairs, and write out the nrrd to a different file */
  nrrdKeyValueClear(nin);
  nrrdKeyValueAdd(nin, "new key", "precious value");
  if (nrrdSave(newname, nin, NULL))
  {
    err = biffGetDone(NRRD);
    fprintf(stderr, "%s: trouble writing \"%s\":\n%s", me, newname, err);
    free(err);
    return;
  }

  /* blow away both the Nrrd struct *and* the memory at nin->data
     (nrrdNix() frees the struct but not the data,
     nrrdEmpty() frees the data but not the struct) */
  nrrdNuke(nin);

  return;
}
示例#8
0
void mexFunction(int nlhs, mxArray *plhs[],
  int nrhs, const mxArray *prhs[])
{
  char me[]="nrrdSave", *filename, *errPtr, errBuff[AIR_STRLEN_MED];
  int filenameLen, ntype;
  size_t sizeZ[NRRD_DIM_MAX];
  unsigned int dim, axIdx;
  Nrrd *nrrd;
  airArray *mop;
  const mxArray *filenameMx, *arrayMx;
  
  if (!(2 == nrhs && mxIsChar(prhs[0]) )) {
    sprintf(errBuff, "%s: requires two args: one string, one array", me);
    mexErrMsgTxt(errBuff);
  }
  filenameMx = prhs[0];
  arrayMx = prhs[1];

  if (mxIsComplex(arrayMx)) {
    sprintf(errBuff, "%s: sorry, array must be real", me);
    mexErrMsgTxt(errBuff);
  }
  ntype = typeMtoN(mxGetClassID(arrayMx));
  if (nrrdTypeUnknown == ntype) {
    sprintf(errBuff, "%s: sorry, can't handle type %s",
            me, mxGetClassName(arrayMx));
    mexErrMsgTxt(errBuff);
  }
  dim = mxGetNumberOfDimensions(arrayMx);
  if (!( 1 <= dim && dim <= NRRD_DIM_MAX )) {
    sprintf(errBuff, "%s: number of array dimensions %d outside range [1,%d]",
            me, dim, NRRD_DIM_MAX);
    mexErrMsgTxt(errBuff);
  }
  
  filenameLen = mxGetM(filenameMx)*mxGetN(filenameMx)+1;
  filename = mxCalloc(filenameLen, sizeof(mxChar));    /* managed by Matlab */
  mxGetString(filenameMx, filename, filenameLen);
  
  for (axIdx=0; axIdx<dim; axIdx++) {
    sizeZ[axIdx] = mxGetDimensions(arrayMx)[axIdx];
  }
  nrrd = nrrdNew();
  mop = airMopNew();
  airMopAdd(mop, nrrd, (airMopper)nrrdNix, airMopAlways);
  if (nrrdWrap_nva(nrrd, mxGetPr(arrayMx), ntype, dim, sizeZ)
      || nrrdSave(filename, nrrd, NULL)) {
    errPtr = biffGetDone(NRRD);
    airMopAdd(mop, errPtr, airFree, airMopAlways);
    sprintf(errBuff, "%s: error saving NRRD:\n%s", me, errPtr);
    airMopError(mop);
    mexErrMsgTxt(errBuff);
  }

  airMopOkay(mop);
  return;
}
示例#9
0
int
main(int argc, const char *argv[]) {
  hestOpt *hopt=NULL;
  airArray *mop;
  const char *me;
  char *outS, *err;
  Nrrd *nin, *nout;
  NrrdIoState *nio;
  float heqamount;

  me = argv[0];
  mop = airMopNew();

  hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, NULL,
             "input nrrd to project.  Must be three dimensional.",
             NULL, NULL, nrrdHestNrrd);
  hestOptAdd(&hopt, "amt", "heq", airTypeFloat, 1, 1, &heqamount, "0.5",
             "how much to apply histogram equalization to projection images");
  hestOptAdd(&hopt, "o", "img out", airTypeString, 1, 1, &outS,
             NULL, "output image to save to.  Will try to use whatever "
             "format is implied by extension, but will fall back to PPM.");
  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);

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

  nrrdStateDisableContent = AIR_TRUE;

  if (doit(nout, nin, 1, heqamount)) {
    err=biffGetDone(NINSPECT);
    airMopAdd(mop, err, airFree, airMopAlways);
    fprintf(stderr, "%s: trouble creating output:\n%s", me, err);
    airMopError(mop); return 1;
  }

  if (nrrdFormatPNG->nameLooksLike(outS)
      && !nrrdFormatPNG->available()) {
    fprintf(stderr, "(%s: using PPM format for output)\n", me);
    nio->format = nrrdFormatPNM;
  }
  if (nrrdSave(outS, nout, nio)) {
    err=biffGetDone(NRRD);
    airMopAdd(mop, err, airFree, airMopAlways);
    fprintf(stderr, "%s: trouble saving output image \"%s\":\n%s",
            me, outS, err);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
示例#10
0
int
limnpu_rastMain(int argc, const char **argv, const char *me,
                hestParm *hparm) {
  hestOpt *hopt = NULL;
  char *err, *perr;
  airArray *mop;
  int pret;

  limnPolyData *pld;
  double min[3], max[3];
  Nrrd *nout;
  char *out;
  int type;
  size_t size[NRRD_DIM_MAX];

  hestOptAdd(&hopt, "min", "min", airTypeDouble, 3, 3, min, NULL,
             "bottom corner");
  hestOptAdd(&hopt, "max", "max", airTypeDouble, 3, 3, max, NULL,
             "top corner");
  hestOptAdd(&hopt, "s", "size", airTypeSize_t, 3, 3, size, NULL,
             "number of samples along each axis");
  hestOptAdd(&hopt, "t", "type", airTypeEnum, 1, 1, &type, "uchar",
             "type of output nrrd",
             NULL, nrrdType);
  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)nrrdNuke, airMopAlways);

  if (limnPolyDataRasterize(nout, pld, min, max, size, type)) {
    airMopAdd(mop, err = biffGetDone(LIMN), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble:%s", me, err);
    airMopError(mop);
    return 1;
  }
  if (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;
}
示例#11
0
文件: texp.c 项目: CIBC-Internal/teem
int
main(int argc, char *argv[]) {
  char *me;
  unsigned int ii, NN;
  double min, max, *out;
  Nrrd *nout;

  me = argv[0];
  if (5 != argc) {
    usage(me);
  }
  if (3 != (sscanf(argv[2], "%u", &NN)
            + sscanf(argv[1], "%lf", &min)
            + sscanf(argv[3], "%lf", &max))) {
    fprintf(stderr, "%s: couldn't parse %s %s %s double uint double",
            me, argv[1], argv[2], argv[3]);
    usage(me);
  }
  nout = nrrdNew();
  if (nrrdAlloc_va(nout, nrrdTypeDouble, 2,
                   AIR_CAST(size_t, 5),
                   AIR_CAST(size_t, NN))) {
    fprintf(stderr, "%s: trouble allocating:\n%s", me,
            biffGetDone(NRRD));
    exit(1);
  }
  out = AIR_CAST(double *, nout->data);
  for (ii=0; ii<NN; ii++) {
    double xx, rr, ff, gg;
    xx = AIR_AFFINE(0, ii, NN-1, min, max);
    rr = exp(xx);
    ff = airFastExp(xx);
    gg = airExp(xx);
    if (rr < 0 || ff < 0 || gg < 0
        || !AIR_EXISTS(rr) || !AIR_EXISTS(ff) || !AIR_EXISTS(gg)) {
      fprintf(stderr, "%s: problem: %f -> real %f, approx %f %f\n",
              me, xx, rr, ff, gg);
      exit(1);
    }
    out[0] = rr;
    out[1] = ff;
    out[2] = (ff-rr)/rr;
    out[3] = gg;
    out[4] = (gg-rr)/rr;
    out += 5;
  }

  if (nrrdSave(argv[4], nout, NULL)) {
    fprintf(stderr, "%s: trouble saving:\n%s", me,
            biffGetDone(NRRD));
    exit(1);
  }
  exit(0);
}
示例#12
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;
}
示例#13
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;
}
示例#14
0
int
main(int argc, char **argv) {
  char *me, *err;
  Nrrd *nrrd;
  NrrdIoState *nio;
  char hstr[] = "NRRD0001\n"
    "# Complete NRRD file format specification at:\n"
    "# http://teem.sourceforge.net/nrrd/format.html\n"
    "# one comment\n"
    "# two comment\n"
    "# three comment\n"
    "type: float\n"
    "dimension: 2\n"
    "sizes: 91 114\n"
    "centerings: node node\n"
    "endian: big\n"
    "encoding: raw\n"
    "bingo:=bob\n"
    "foo:=super duper fancy bar with corona\n"
    /* "data file: tmp.raw\n" */;
  char *wstr;
  AIR_UNUSED(argc);
  me = argv[0];

  nrrdStateVerboseIO = 10;

  nio = nrrdIoStateNew();
  nrrd = nrrdNew();

  nio->path = airStrdup(".");
  if (nrrdStringRead(nrrd, hstr, nio)) {
    fprintf(stderr, "%s: trouble reading string:\n%s", 
            me, err = biffGet(NRRD));
    free(err);
    exit(1);
  }
  fprintf(stderr, "%s: nrrd->data = %p\n", me, nrrd->data);

  nrrdSave("out.nrrd", nrrd, NULL);
  if (nrrdStringWrite(&wstr, nrrd, NULL)) {
    fprintf(stderr, "%s: trouble writing string:\n%s", 
            me, err = biffGet(NRRD));
    free(err);
    exit(1);
  }
  fprintf(stderr, "%s: |%s|\n", me, wstr);

  free(wstr);
  nrrdIoStateNix(nio);
  nrrdNuke(nrrd);

  exit(0);
}
示例#15
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;
}
示例#16
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);
}
示例#17
0
文件: gkmsMite.c 项目: BRAINSia/teem
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;
}
示例#18
0
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;
}
示例#19
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;
}
示例#21
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;
}
示例#22
0
int
limnpu_measMain(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)nrrdNuke, airMopAlways);

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

  if (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
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;
}
示例#24
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;
}
示例#25
0
文件: tendTconv.c 项目: BRAINSia/teem
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;
}
示例#26
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;
}
示例#27
0
/* *************************************************************** */
void reg_io_writeNRRDfile(Nrrd *image, const char *filename)
{
    // Set the encoding to gziped as it is compiled as part of the NiftyReg project
    NrrdIoState *nio=nrrdIoStateNew();
    if (nrrdEncodingGzip->available()){
        nrrdIoStateEncodingSet(nio, nrrdEncodingGzip);
        nrrdIoStateSet(nio, nrrdIoStateZlibLevel, 9);
    }
    else{
        fprintf(stderr, "[NiftyReg ERROR] Can not compress the file: \"%s\"\n", filename);
    }

    char *err;
    if (nrrdSave(filename, image, nio)){
        err = biffGetDone(NRRD);
        fprintf(stderr, "[NiftyReg ERROR] Can not write the file \"%s\":\n%s\n", filename, err);
        free(err);
        exit(1);
    }
    return;
}
示例#28
0
void NRRDWriter::Save(wstring filename, int mode)
{
   if (!m_data)
      return;

   if (m_use_spacings &&
         m_data->dim == 3)
   {
      nrrdAxisInfoSet(m_data, nrrdAxisInfoSpacing, m_spcx, m_spcy, m_spcz);
      nrrdAxisInfoSet(m_data, nrrdAxisInfoMax,
            m_spcx*m_data->axis[0].size,
            m_spcy*m_data->axis[1].size,
            m_spcz*m_data->axis[2].size);
   }

   string str;
   str.assign(filename.length(), 0);
   for (int i=0; i<(int)filename.length(); i++)
      str[i] = (char)filename[i];
   nrrdSave(str.c_str(), m_data, NULL);
}
示例#29
0
int
main(int argc, char *argv[]) {
  Nrrd *info, *pos;
  float sigma, gthresh;
  char *iStr, *oStr, *sigStr, *gthStr;

  me = argv[0];
  if (argc != 5) {
    usage();
  }
  iStr = argv[1];
  sigStr = argv[2];
  gthStr = argv[3];
  oStr = argv[4];

  if (1 != sscanf(sigStr, "%g", &sigma) ||
      1 != sscanf(gthStr, "%g", &gthresh)) {
    fprintf(stderr, "%s: couldn't parse %s and %s as floats\n", me, 
            sigStr, gthStr);
    usage();
  }

  if (nrrdLoad(info=nrrdNew(), iStr, NULL)) {
    fprintf(stderr, "%s: trouble reading \"%s\" :\n%s\n", me, 
            iStr, biffGet(NRRD));
    exit(1);
  }
  if (banePosCalc(pos = nrrdNew(), sigma, gthresh, info)) {
    fprintf(stderr, "%s: trouble calculating %s:\n%s\n", me,
            2 == info->dim ? "p(v,g)" : "p(v)", biffGet(BANE));
    exit(1);
  }
  if (nrrdSave(oStr, pos, NULL)) {
    fprintf(stderr, "%s: trouble writing output to \"%s\"\n", me, oStr);
    exit(1);
  }
  nrrdNuke(info);
  nrrdNuke(pos);
  exit(0);
}
示例#30
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;
}